LIBTCPIP:New Socket API,ARP & DNS Cache expiration enabled

This commit is contained in:
Rémy GIBERT 2016-03-27 23:06:56 +02:00
parent d9ddb088ce
commit ae16376a04
7 changed files with 109 additions and 121 deletions

View File

@ -192,7 +192,7 @@ ARP.QUERY.I jsr ARP.FIND.BY.IP
bcs .99
lda #5
lda #K.ARP.PENDING.TTL
sta ARP.TmpCache+S.ARPCACHE.TTL
stz ARP.TmpCache+S.ARPCACHE.TTL+1

View File

@ -31,12 +31,13 @@ DNS.QUERY.I jsr DNS.FIND.BY.NAME
lda ZPCachePtr
clc
adc S.DNSCACHE.IP
adc #S.DNSCACHE.IP
sta ZPCachePtr
bcc .1
inc ZPCachePtr+1
.1 ldy #3
.2 lda (ZPCachePtr),y
sta (ZPPtrIP),y
dey
@ -48,7 +49,13 @@ DNS.QUERY.I jsr DNS.FIND.BY.NAME
sec
rts
*--------------------------------------
DNS.REQUEST jsr DNS.PSTR2DNS
DNS.REQUEST lda hDNSSocket1
bne .10
lda #ERR.DNS.ERROR
sec
rts
.10 jsr DNS.PSTR2DNS
ldx #0
ldy #DNS.MSG.NAME-DNS.MSG
@ -80,15 +87,12 @@ DNS.REQUEST jsr DNS.PSTR2DNS
lda #0
sta DNS.MSG.LEN+1
lda hDNSSocket1
beq .9
>LDYA A2osX.RANDOM16
>STYA DNS.MSG.ID
>STYA DNS.TmpCache+S.DNSCACHE.ID
lda #5
lda #K.DNS.PENDING.TTL
sta DNS.TmpCache+S.DNSCACHE.TTL
stz DNS.TmpCache+S.DNSCACHE.TTL+1
stz DNS.TmpCache+S.DNSCACHE.TTL+2
@ -140,46 +144,29 @@ DNS.ADD >PULLW ZPPtrDNS Get host string
DNS.ADD.I sta DNS.TmpCache
jsr DNS.FIND.BY.NAME
bcs .1 not found, go create new
bcc .2 Found, go update...
ldy #S.DNSCACHE.hNAME
lda (ZPCachePtr),y
sta DNS.TmpCache,y
bra .20
jsr DNS.FIND.FREE
.1 jsr DNS.FIND.FREE
lda (ZPPtrDNS)
iny add 1 for len byte
lda #0
>PUSHYA push PSTR len
>PUSHBI 0 no option
>SYSCALL SYS.GetMem
>LDYA ZPPtrDNS
>SYSCALL SYS.NewPStrYA
bcs .9
>STYA ZPTmpPtr1
stx DNS.TmpCache+S.DNSCACHE.hNAME
ldy #S.DNSCACHE.hNAME
sta (ZPCachePtr),y
lda (ZPPtrDNS)
sta (ZPTmpPtr1)
tay
.2 lda DNS.TmpCache
sta (ZPCachePtr)
.2 lda (ZPPtrDNS),y
sta (ZPTmpPtr1),y
dey
bne .2
.20 ldy #S.DNSCACHE-1
ldy #S.DNSCACHE.ID
.3 lda DNS.TmpCache,y
sta (ZPCachePtr),y
dey
bpl .3
iny
cpy #S.DNSCACHE
bne .3
clc
rts
.9 sec
rts
.9 rts
*--------------------------------------
DNS.GETCACHE >LDYA L.DNS.CACHE
clc
@ -198,6 +185,7 @@ DNS.FIND.BY.NAME
ldy #S.DNSCACHE.hNAME
lda (ZPCachePtr),y
>SYSCALL SYS.GetMemPtrA
bcs *
>STYA ZPTmpPtr1
lda (ZPPtrDNS)
@ -235,6 +223,7 @@ DNS.UPDATE.BY.ID
.1 lda (ZPCachePtr)
beq .6 empty DNS cache entry?
bmi .6 resolved ?
ldy #S.DNSCACHE.ID
lda (ZPCachePtr),y
@ -245,15 +234,16 @@ DNS.UPDATE.BY.ID
cmp DNS.TmpCache+S.DNSCACHE.ID+1
bne .6
ldy #S.DNSCACHE-1
.2 lda DNS.TmpCache,y
sta (ZPCachePtr),y
dey
cpy #S.DNSCACHE.hNAME
bne .2
lda #S.DNSCACHE.STATUS.RESOLVED
sta (ZPCachePtr)
ldy #S.DNSCACHE.TTL
.2 lda DNS.TmpCache,y
sta (ZPCachePtr),y
iny
cpy #S.DNSCACHE
bne .2
clc
rts
@ -287,7 +277,7 @@ DNS.FIND.FREE >LDYA L.DNS.CACHE
ldy #S.DNSCACHE.TTL
ldx #3
sec
.2 lda TmpDWord,x is save TTL greater then actual TTL?
.2 lda TmpDWord,x is saved TTL greater then actual TTL?
sbc (ZPCachePtr),y
iny
dex
@ -382,7 +372,7 @@ DNS.DecodeMsg sta hFrame1
>SYSCALL SYS.GetMemPtrA
>STYA ZPFrameBase1
>DEBUG
* >DEBUG
ldy #S.DNS.F+1
lda (ZPFrameBase1),y
@ -391,10 +381,10 @@ DNS.DecodeMsg sta hFrame1
ldy #S.DNS.ID
lda (ZPFrameBase1),y
sta DNS.TmpCache+S.DNSCACHE.ID+1
sta DNS.TmpCache+S.DNSCACHE.ID
iny
lda (ZPFrameBase1),y
sta DNS.TmpCache+S.DNSCACHE.ID
sta DNS.TmpCache+S.DNSCACHE.ID+1
ldy #S.DNS.ANCOUNT+1
lda (ZPFrameBase1),y
@ -427,6 +417,8 @@ DNS.DecodeMsg sta hFrame1
iny Skip QTYPE & QCLASS
iny
iny next pos
.21 dex skip another QUERY ?
bne .1
@ -464,6 +456,8 @@ DNS.DecodeMsg sta hFrame1
.40 iny skip QCLASS
iny
iny next pos
ldx #3
.4 lda (ZPFrameBase1),y
sta DNS.TmpCache+S.DNSCACHE.TTL,x
@ -475,9 +469,9 @@ DNS.DecodeMsg sta hFrame1
iny
ldx #0
.5 iny
lda (ZPFrameBase1),y
.5 lda (ZPFrameBase1),y
sta DNS.TmpCache+S.DNSCACHE.IP,x
iny
inx
cpx #4
bne .5

View File

@ -8,7 +8,6 @@ AUTO 6
RCVD.FRAMEA sta hFrame1
>SYSCALL SYS.GetMemPtrA
>STYA ZPFrameBase1
jsr FRM.GetLen1
ldy #S.ETH.ETHERTYPE
@ -77,8 +76,11 @@ NEW.UDP.FRAME jsr NEW.IP.FRAME
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.IP.FRAME jsr NEW.ETH.FRAME
NEW.IP.FRAME >PUSHWI K.ETH.FRAME.LEN
>PUSHBI S.MEM.F.INIT0
>SYSCALL SYS.GetMem
bcs .9
>STYA ZPFrameBase1
ldy #S.ETH.ETHERTYPE
lda /S.ETH.ETHERTYPE.IP
@ -112,50 +114,6 @@ NEW.IP.FRAME jsr NEW.ETH.FRAME
clc
.9 rts
*--------------------------------------
* Out:
* Y,A = Frame PTR
* X = hMem
*--------------------------------------
NEW.ARP.FRAME jsr NEW.ETH.FRAME
bcs .9
ldy #S.ETH.ETHERTYPE
lda /S.ETH.ETHERTYPE.ARP
sta (ZPFrameBase1),y
iny
lda #S.ETH.ETHERTYPE.ARP
sta (ZPFrameBase1),y
ldy #S.ARP.HTYPE
lda #0
sta (ZPFrameBase1),y
iny
lda #1
sta (ZPFrameBase1),y
iny
lda #8
sta (ZPFrameBase1),y
iny
lda #0
sta (ZPFrameBase1),y
iny
lda #6
sta (ZPFrameBase1),y
iny
lda #4
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
clc
.9 rts
*--------------------------------------
NEW.ETH.FRAME >PUSHWI K.ETH.FRAME.LEN
>PUSHBI S.MEM.F.INIT0
>SYSCALL SYS.GetMem
bcs .9
>STYA ZPFrameBase1
clc
.9 rts
*--------------------------------------
SEND.ICMP.FRAME >PULLW ZPFrameBase1
jsr FRM.GetLen1
stz hFrame1
@ -283,11 +241,33 @@ SEND.IP.FRAME.I ldx #3
ldx #DEVMGR.NET.SEND
jsr NetDevJmp
bcs FRM.Queue
rts
lda hFrame1
beq .9
>SYSCALL SYS.FreeMemA
clc
.9 rts
*--------------------------------------
FRM.Queue ldx hFrame1 no hFrame, cannot queue for retry
FRM.Queue ldy hFrame1 no hFrame, cannot queue for retry
beq .9
ldx FRM.QUEUE.Head
inx
cpx #K.FRMQUEUE.SIZE
bne .1
ldx #0
.1 cpx FRM.QUEUE.Tail
beq .9
ldy FRM.QUEUE.Head
stx FRM.QUEUE.Head
sta FRM.QUEUE.State,y
lda #K.FRMSEND.RETRY
sta FRM.QUEUE.Retry,y
lda hFrame1
sta FRM.QUEUE.hMem,y
clc
rts
.9 sec
rts

View File

@ -59,6 +59,7 @@ ICMP.IN ldy #S.ICMP.TYPE
lda #S.ARPCACHE.STATUS.RESOLVED
jsr ARP.ADD.I
stz hFrame1 DO NOT QUEUE/DISCARD this frame,it is SOURCE frame!!!
jmp SEND.ICMP.FRAME.I
.9 sec
rts

View File

@ -197,27 +197,23 @@ SKT.SEND.UDP jsr NEW.UDP.FRAME
lda #S.UDP
clc
adc ZPFrameBase1
sta ZPFramePtr1
sta ZPTmpPtr1
lda /S.UDP
adc ZPFrameBase1+1
sta ZPFramePtr1+1
sta ZPTmpPtr1+1
ldy #0
.3 jsr DecDataLen
beq .4
lda (ZPDataPtr),y
sta (ZPFramePtr1),y
sta (ZPTmpPtr1),y
iny
bne .3
inc ZPDataPtr
inc ZPFramePtr1
inc ZPTmpPtr1
bra .3
.4 jsr SEND.UDP.FRAME.I
bcs .9
lda hFrame1
>SYSCALL SYS.FreeMemA
sec
.4 jmp SEND.UDP.FRAME.I
.9 rts
*--------------------------------------
SKT.SEND.TCP
@ -230,18 +226,21 @@ SKT.RCVDA jsr SKT.GetA
ldy #S.SOCKET.DQ.TAIL
lda (ZPPtrSKT),y
tax
ldy #S.SOCKET.DQ.HEAD
cmp (ZPPtrSKT),y
beq .99
pha
inc
cmp #S.SOCKET.DQ.MAX
bne .1
lda #0
.1 sta (ZPPtrSKT),y
pla
.1 ldy #S.SOCKET.DQ.TAIL
sta (ZPPtrSKT),y
txa
clc
adc #S.SOCKET.DQ
tay

View File

@ -46,13 +46,28 @@ UDP.IN ldy #S.IP.SRC+3
bne .7
ldy #S.SOCKET.SRC.ADDR
lda (ZPPtrSKT),y SOCKET.SRC.ADDR=0.0.0.0 ?
bne .41
ldy #S.SOCKET.SRC.PORT yes, do not check if IP match
.4 lda TmpSocket,y
cmp (ZPPtrSKT),y
.4 lda (ZPPtrSKT),y
.41 cmp TmpSocket,y
bne .7
iny
cpy #S.SOCKET.DST.ADDR
bne .4
lda (ZPPtrSKT),y SOCKET.DST.ADDR=FF.FF.FF.FF ?
cmp #$FF
bne .51
ldy #S.SOCKET.DST.PORT yes, do not check if IP match
.5 lda (ZPPtrSKT),y
.51 cmp TmpSocket,y
bne .7
iny
cpy #S.SOCKET.DST.PORT+2
bne .4
bne .5
jsr SKT.AddToQueueD
bcs .99

View File

@ -14,7 +14,7 @@ AUTO 6
*--------------------------------------
ZPFrameBase1 .EQ ZPLIB
ZPFrameLen1 .EQ ZPLIB+2
ZPFramePtr1 .EQ ZPLIB+4
*ZPFramePtr1 .EQ ZPLIB+4
ZPPtrIP .EQ ZPLIB+12
ZPPtrMAC .EQ ZPLIB+14
ZPPtrDNS .EQ ZPLIB+16
@ -50,8 +50,8 @@ CS.START cld
.DA NEW.TCP.FRAME
.DA NEW.UDP.FRAME
.DA NEW.IP.FRAME
.DA NEW.ARP.FRAME
.DA NEW.ETH.FRAME
.DA $ffff NEW.ARP.FRAME
.DA $ffff NEW.ETH.FRAME
.DA SEND.ICMP.FRAME
.DA SEND.TCP.FRAME
@ -217,7 +217,7 @@ GET.IPCFG >LDYA L.IPCFG
PULSEA asl
bpl .1
jsr ARP.EXPIRE
* jsr DNS.EXPIRE
jsr DNS.EXPIRE
.1 jmp FRM.RETRY
*--------------------------------------
ToLowerCaseA cmp #'A'
@ -267,8 +267,6 @@ NetDevJmp jmp *
*--------------------------------------
CS.END
*--------------------------------------
IPCFG .BS S.IPCFG
*--------------------------------------
ARP.REQ .DA S.ARP-2 Frame size
ARP.REQ.DSTMAC .HS FFFFFFFFFFFF
ARP.REQ.SRCMAC .BS 6
@ -335,6 +333,7 @@ DNS.MSG.ID .BS 2
.BS 6 ANCOUNT,NSCOUNT,ARCOUNT
DNS.MSG.NAME .BS K.DNS.MAXLEN+6
*--------------------------------------
IPCFG .BS S.IPCFG
ARP.CACHE .BS K.ARPCACHE.SIZE*S.ARPCACHE
DNS.CACHE .BS K.DNSCACHE.SIZE*S.DNSCACHE
SKT.TABLE .BS K.SKTTABLE.SIZE*S.SOCKET