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 bcs .99
lda #5 lda #K.ARP.PENDING.TTL
sta ARP.TmpCache+S.ARPCACHE.TTL sta ARP.TmpCache+S.ARPCACHE.TTL
stz ARP.TmpCache+S.ARPCACHE.TTL+1 stz ARP.TmpCache+S.ARPCACHE.TTL+1

View File

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

View File

@ -8,7 +8,6 @@ AUTO 6
RCVD.FRAMEA sta hFrame1 RCVD.FRAMEA sta hFrame1
>SYSCALL SYS.GetMemPtrA >SYSCALL SYS.GetMemPtrA
>STYA ZPFrameBase1 >STYA ZPFrameBase1
jsr FRM.GetLen1 jsr FRM.GetLen1
ldy #S.ETH.ETHERTYPE ldy #S.ETH.ETHERTYPE
@ -77,8 +76,11 @@ NEW.UDP.FRAME jsr NEW.IP.FRAME
* Y,A = Frame PTR * Y,A = Frame PTR
* X = hMem * 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 bcs .9
>STYA ZPFrameBase1
ldy #S.ETH.ETHERTYPE ldy #S.ETH.ETHERTYPE
lda /S.ETH.ETHERTYPE.IP lda /S.ETH.ETHERTYPE.IP
@ -112,50 +114,6 @@ NEW.IP.FRAME jsr NEW.ETH.FRAME
clc clc
.9 rts .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 SEND.ICMP.FRAME >PULLW ZPFrameBase1
jsr FRM.GetLen1 jsr FRM.GetLen1
stz hFrame1 stz hFrame1
@ -283,11 +241,33 @@ SEND.IP.FRAME.I ldx #3
ldx #DEVMGR.NET.SEND ldx #DEVMGR.NET.SEND
jsr NetDevJmp jsr NetDevJmp
bcs FRM.Queue bcs FRM.Queue
rts lda hFrame1
*--------------------------------------
FRM.Queue ldx hFrame1 no hFrame, cannot queue for retry
beq .9 beq .9
>SYSCALL SYS.FreeMemA
clc
.9 rts
*--------------------------------------
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 .9 sec
rts rts

View File

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

View File

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

View File

@ -39,20 +39,35 @@ UDP.IN ldy #S.IP.SRC+3
>STYA ZPPtrSKT >STYA ZPPtrSKT
ldx #0 ldx #0
.3 lda (ZPPtrSKT) .3 lda (ZPPtrSKT)
beq .7 beq .7
cmp #S.SOCKET.SOCK.DGRAM cmp #S.SOCKET.SOCK.DGRAM
bne .7 bne .7
ldy #S.SOCKET.SRC.ADDR 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 .4 lda (ZPPtrSKT),y
cmp (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 bne .7
iny iny
cpy #S.SOCKET.DST.PORT+2 cpy #S.SOCKET.DST.PORT+2
bne .4 bne .5
jsr SKT.AddToQueueD jsr SKT.AddToQueueD
bcs .99 bcs .99

View File

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