DNS:code rewrite

This commit is contained in:
Rémy GIBERT 2016-03-16 17:37:02 +01:00
parent 5a3891650f
commit bb490f0347
7 changed files with 260 additions and 199 deletions

Binary file not shown.

Binary file not shown.

View File

@ -5,6 +5,79 @@ INC 1
AUTO 6
.LIST OFF
*--------------------------------------
ARP.IN ldy #S.ARP.TPA+3
ldx #3
.1 lda (ZPFrameBase1),y
cmp IPCFG+S.IPCFG.IP,x
bne .9
dey
dex
bpl .1
ldy #S.ARP.OPERATION+1 HI byte
lda (ZPFrameBase1),y
cmp #S.ARP.OPERATION.REQ
beq ARP.IN.REQ
cmp #S.ARP.OPERATION.REP
beq ARP.IN.REP
.9 clc Discard any other ARP frames
rts
ARP.IN.REQ ldy #S.ARP.SPA+3
ldx #3
.1 lda (ZPFrameBase1),y
sta ARP.REP.TPA,x
dey
dex
bpl .1
ldy #S.ARP.SHA+5
ldx #5
.2 lda (ZPFrameBase1),y
sta ARP.REP.DSTMAC,x
sta ARP.REP.THA,x
dey
dex
bpl .2
>PUSHW L.ARP.REP
ldx #DEVMGR.NET.SEND
jsr NetDevJmp
ARP.IN.REP lda #K.ARP.TTL
sta ARP.TmpCache+S.ARPCACHE.TTL
lda /K.ARP.TTL
sta ARP.TmpCache+S.ARPCACHE.TTL+1
ldy #S.ARP.SPA+3
ldx #3
.1 lda (ZPFrameBase1),y
sta ARP.TmpCache+S.ARPCACHE.IP,x
dey
dex
bpl .1
ldy #S.ARP.SHA+5
ldx #5
.2 lda (ZPFrameBase1),y
sta ARP.TmpCache+S.ARPCACHE.MAC,x
dey
dex
bpl .2
lda #S.ARPCACHE.STATUS.RESOLVED
jsr ARP.ADD.I
clc
rts
*--------------------------------------
ARP.CLEAR ldx #K.ARPCACHE.SIZE*S.ARPCACHE
.1 dex
stz ARP.CACHE,x
@ -25,7 +98,7 @@ ARP.QUERY >PULLW ZPPtrIP IP
>PULLW ZPPtrMAC MAC
ARP.QUERY.I jsr ARP.FIND.BY.IP
bcs ARP.REQUEST
bcs .3 send an ARP request
lda (ZPCachePtr) get status...
bpl .9 Pending...
@ -38,6 +111,7 @@ ARP.QUERY.I jsr ARP.FIND.BY.IP
inc ZPCachePtr+1
.1 ldy #5
.2 lda (ZPCachePtr),y
sta (ZPPtrMAC),y
dey
@ -45,29 +119,30 @@ ARP.QUERY.I jsr ARP.FIND.BY.IP
clc
rts
.9 lda #ERR.ARPPENDING
sec
rts
*--------------------------------------
ARP.REQUEST ldy #3
.1 lda (ZPPtrIP),y
.3 ldy #3
.4 lda (ZPPtrIP),y
sta ARP.REQ.TPA,y
sta ARP.TmpCache+S.ARPCACHE.IP,y
dey
bpl .1
bpl .4
>PUSHW L.ARP.REQ
ldx #DEVMGR.NET.SEND
jsr NetDevJmp
bcs .9
bcs .99
lda #5
sta ARP.TmpCache+S.ARPCACHE.TTL
stz ARP.TmpCache+S.ARPCACHE.TTL+1
lda #S.ARPCACHE.STATUS.PENDING
jsr ARP.ADD.I ZPPtrIP still pointing IP
jsr ARP.ADD.I
lda #ERR.ARPPENDING
.9 lda #ERR.ARPPENDING
sec
.9 rts
.99 rts
*--------------------------------------
* ARP.ADD
* In:
@ -76,77 +151,37 @@ ARP.REQUEST ldy #3
*--------------------------------------
ARP.ADD >PULLW ZPPtrIP IP
>PULLW ZPPtrMAC MAC
stz ARP.TmpCache+S.ARPCACHE.TTL
stz ARP.TmpCache+S.ARPCACHE.TTL+1
ldy #3
.1 lda (ZPPtrIP),y
sta ARP.TmpCache+S.ARPCACHE.IP,y
dey
bpl .1
ldy #5
.2 lda (ZPPtrMAC),y
sta ARP.TmpCache+S.ARPCACHE.MAC,y
dey
bpl .2
lda #S.ARPCACHE.STATUS.RESOLVED+S.ARPCACHE.STATUS.STATIC
ARP.ADD.I sta ARP.TmpCache
jsr ARP.FIND.BY.IP
bcc .5
jsr DNS.FIND.FREE
bcc .1
jsr ARP.FIND.FREE
.1 lda ARP.CACHE,x get status
beq .7 empty ARP cache entry
phx
.1 ldy #S.ARPCACHE-1
.2 lda ARP.TmpCache,y
sta (ZPCachePtr),y
dey
bpl .2
ldy #0
.2 lda (ZPPtrIP),y
cmp ARP.CACHE+S.ARPCACHE.IP,x
bne .4
inx
iny
cpy #4
bne .2
plx
bra .7 same IP,update MAC
.4 pla get back index in ARP.CACHE
clc
adc #S.ARPCACHE
cmp #K.ARPCACHE.SIZE*S.ARPCACHE
beq .5 Cache is full ?
tax
bra .1
.5 bra *
ldx #K.ARPCACHE.SIZE*S.ARPCACHE-S.ARPCACHE
.6 lda ARP.CACHE+S.ARPCACHE-1,x
sta ARP.CACHE-1,x
dex
bne .6
ldx #K.ARPCACHE.SIZE*S.ARPCACHE-S.ARPCACHE
.7 lda Status
sta ARP.CACHE,x mark ARP entry Status
lda #K.ARP.TTL
sta ARP.CACHE+S.ARPCACHE.TTL,x
lda /K.ARP.TTL
sta ARP.CACHE+S.ARPCACHE.TTL+1,x
ldy #0
phx
.8 lda (ZPPtrIP),y store IP in cache
sta ARP.CACHE+S.ARPCACHE.IP,x
iny
inx
cpy #4
bne .8
plx
lda Status
bpl .82 no MAC if "pending"
ldy #0
.81 lda (ZPPtrMAC),y store MAC in cache
sta ARP.CACHE+S.ARPCACHE.MAC,x
iny
inx
cpy #6
bne .81
.82 clc
rts
*--------------------------------------
* ARP.GETCACHE
@ -212,72 +247,99 @@ ARP.RESOLVE ldy #S.IP.DST
adc /S.ETH.DSTMAC
sta ZPPtrMAC+1
*--------------------------------------
*--------------------------------------
*--------------------------------------
ARP.IN ldy #S.ARP.TPA
ldx #S.IPCFG.IP
ARP.FIND.BY.IP >LDYA L.ARP.CACHE
>STYA ZPCachePtr
lda #K.ARPCACHE.SIZE
sta TmpOffset
.1 lda (ZPFrameBase1),y
cmp IPCFG,x
bne .9
.1 lda (ZPCachePtr)
beq .7
ldy #S.ARPCACHE.IP+3
ldx #3
lda (ZPCachePtr),y
cmp (ZPPtrIP)
bne .7
ldy #S.ARPCACHE.IP+1
lda (ZPCachePtr),y
ldy #1
cmp (ZPPtrIP),y
bne .7
ldy #S.ARPCACHE.IP+2
lda (ZPCachePtr),y
ldy #2
cmp (ZPPtrIP),y
bne .7
ldy #S.ARPCACHE.IP+3
lda (ZPCachePtr),y
ldy #3
cmp (ZPPtrIP),y
bne .7
clc
rts
.7 lda ZPCachePtr
clc
adc #S.ARPCACHE
sta ZPCachePtr
bcc .8
inc ZPCachePtr+1
.8 dec TmpOffset
bne .1
sec
rts
*--------------------------------------
ARP.FIND.FREE >LDYA L.ARP.CACHE
>STYA ZPCachePtr
lda #$ff
sta TmpDWord
sta TmpDWord+1
ldx #K.ARPCACHE.SIZE
.1 lda (ZPCachePtr)
beq .8
bpl .6
ldy #S.ARPCACHE.TTL
lda (ZPCachePtr),y
sec
sbc TmpDWord
iny
inx
cpx #S.IPCFG.IP+4
lda (ZPCachePtr),y
sbc TmpDWord+1
bcc .6
lda (ZPCachePtr),y
sta TmpDWord+1
dey
lda (ZPCachePtr),y
sta TmpDWord
>LDYA ZPCachePtr
>STYA ZPTmpPtr1 save lowest TTL slot ...
.6 lda ZPCachePtr
clc
adc #S.ARPCACHE
sta ZPCachePtr
bcc .7
inc ZPCachePtr+1
.7 dex
bne .1
ldy #S.ARP.OPERATION+1 HI byte
lda (ZPFrameBase1),y
cmp #S.ARP.OPERATION.REQ
beq ARP.IN.REQ
>LDYA ZPTmpPtr1
>STYA ZPCachePtr
lda #0
sta (ZPCachePtr)
cmp #S.ARP.OPERATION.REP
beq ARP.IN.REP
.9 clc Discard any other ARP frames
rts
ARP.IN.REQ ldy #S.ETH.SRCMAC+5
ldx #5
.1 lda (ZPFrameBase1),y
sta ARP.REP.DSTMAC,x
sta ARP.REP.THA,x
dey
dex
bpl .1
ldy #S.ARP.SPA+3
ldx #3
.2 lda (ZPFrameBase1),y
sta ARP.REP.TPA,x
dey
dex
bpl .2
>PUSHW L.ARP.REP
ldx #DEVMGR.NET.SEND
jsr NetDevJmp
ARP.IN.REP lda #S.ARP.SHA
clc
adc ZPFrameBase1
sta ZPPtrMAC
lda ZPFrameBase1+1
adc /S.ARP.SHA
sta ZPPtrMAC+1
lda #S.ARP.SPA
clc
adc ZPFrameBase1
sta ZPPtrIP
lda ZPFrameBase1+1
adc /S.ARP.SPA
sta ZPPtrIP+1
lda #S.ARPCACHE.STATUS.RESOLVED
jsr ARP.ADD.I
clc
.8 clc
rts
*--------------------------------------
ARP.EXPIRE >LDYA L.ARP.CACHE
@ -286,7 +348,7 @@ ARP.EXPIRE >LDYA L.ARP.CACHE
ldx #K.ARPCACHE.SIZE
.1 lda (ZPCachePtr)
beq .7
beq .3
ldy #S.ARPCACHE.TTL
sec
@ -313,36 +375,6 @@ ARP.EXPIRE >LDYA L.ARP.CACHE
bne .1
rts
*--------------------------------------
ARP.FIND.BY.IP >LDYA L.ARP.CACHE
>STYA ZPCachePtr
lda #K.ARPCACHE.SIZE
sta TmpOffset
.1 lda (ZPCachePtr)
beq .7
ldy #S.ARPCACHE.IP
lda (ZPCachePtr),y
.7 lda ZPCachePtr
clc
adc #S.ARPCACHE
sta ZPCachePtr
bcc .8
inc ZPCachePtr+1
.8 dec TmpOffset
bne .1
sec
rts
*--------------------------------------
ARP.FIND.FREE
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.ARP
LOAD LIB/LIBTCPIP.S

View File

@ -87,8 +87,12 @@ DNS.REQUEST jsr HST.PSTR2DNS.I
>STYA DNS.MSG.ID
>STYA DNS.TmpCache+S.DNSCACHE.ID
lda #5
sta DNS.TmpCache+S.DNSCACHE.TTL
stz DNS.TmpCache+S.DNSCACHE.TTL+1
stz DNS.TmpCache+S.DNSCACHE.TTL+2
stz DNS.TmpCache+S.DNSCACHE.TTL+3
lda #S.DNSCACHE.STATUS.PENDING
jsr DNS.ADD.I
@ -119,14 +123,31 @@ DNS.REQUEST jsr HST.PSTR2DNS.I
DNS.ADD >PULLW ZPPtrDNS Get host string
>PULLW ZPPtrIP Get host IP address
ldy #3
.1 lda (ZPPtrIP),y
sta DNS.TmpCache+S.DNSCACHE.IP,y
dey
bpl .1
stz DNS.TmpCache+S.DNSCACHE.TTL
stz DNS.TmpCache+S.DNSCACHE.TTL+1
stz DNS.TmpCache+S.DNSCACHE.TTL+2
stz DNS.TmpCache+S.DNSCACHE.TTL+3
lda #S.DNSCACHE.STATUS.RESOLVED+S.DNSCACHE.STATUS.STATIC
DNS.ADD.I sta DNS.TmpCache
jsr DNS.FIND.BY.NAME
bcc .5 Found!!! update this entry
jsr DNS.FIND.FREE
bcs .1 not found, go create new
ldy #S.DNSCACHE.hNAME
lda (ZPCachePtr),y
sta DNS.TmpCache,y
bra .20
.1 jsr DNS.FIND.FREE
lda (ZPPtrDNS)
iny add 1 for len byte
@ -143,24 +164,20 @@ DNS.ADD.I sta DNS.TmpCache
sta (ZPTmpPtr1)
tay
.1 lda (ZPPtrDNS),y
.2 lda (ZPPtrDNS),y
sta (ZPTmpPtr1),y
dey
bne .1
bne .2
ldy #S.DNSCACHE-1
.2 lda DNS.TmpCache,y
.20 ldy #S.DNSCACHE-1
.3 lda DNS.TmpCache,y
sta (ZPCachePtr),y
dey
bpl .2
bpl .3
clc
rts
.5
clc
rts
.9 sec
rts
*--------------------------------------
@ -226,24 +243,22 @@ DNS.FIND.FREE >LDYA L.DNS.CACHE
bpl .6 pending.....skip
ldy #S.DNSCACHE.TTL
ldx #0
ldx #3
sec
.2 lda TmpDWord,x is save TTL greater then actual TTL?
sbc (ZPCachePtr),y
inx
iny
cpy #S.DNSCACHE.TTL+4
bne .2
dex
bpl .2
bcc .6 no,
ldy #S.DNSCACHE.TTL
ldx #0
ldx #3
.3 lda (ZPCachePtr),y Save new lowest TTL
sta TmpDWord,x
inx
iny
cpy #S.DNSCACHE.TTL+4
bne .3
dex
bpl .3
>LDYA ZPCachePtr
>STYA ZPTmpPtr1 save lowest TTL slot ...
@ -260,7 +275,7 @@ DNS.FIND.FREE >LDYA L.DNS.CACHE
>LDYA ZPTmpPtr1
>STYA ZPCachePtr
jmp DNS.FREE
jsr DNS.FREE
.8 clc
rts
@ -305,21 +320,25 @@ DNS.FREE ldy #S.DNSCACHE.hNAME
sta (ZPCachePtr)
rts
*--------------------------------------
DNS.SKTPOLL lda hDNSSocket1
DNS.POLL lda hDNSSocket1
beq .8
jsr SKT.RCVDA
bcs .8
jsr DNS.DecodeMsg
bra *
lda hDNSSocket2
beq .8
jsr SKT.RCVDA
bcs .8
jsr DNS.DecodeMsg
.8 clc
rts
.9 sec
rts
*--------------------------------------
DNS.DecodeMsg sta hFrame1
>SYSCALL SYS.GetMemPtrA
>STYA ZPFrameBase1
ldy #S.DNS.F+1
lda (ZPFrameBase1),y
and /S.DNS.F.QR
@ -349,6 +368,10 @@ DNS.SKTPOLL lda hDNSSocket1
.3 iny skip high byte of offset
iny skip lo byte of offset
.9 lda hFrame1
>SYSCALL SYS.FreeMemA
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.DNS

View File

@ -287,9 +287,8 @@ RCVD.FRAMEA sta hFrame1
cpx /S.ETH.ETHERTYPE.IP
bne .9
jsr IP.IN
bcs .9
jmp DNS.SKTPOLL
jmp IP.IN
.9 sec
rts
*--------------------------------------

View File

@ -11,7 +11,9 @@ HST.GETBYNAME >PULLW ZPPtrDNS
bcc .1
jsr DNS.QUERY.I
bcs .9
.1 jmp ARP.REQUEST.I
>LDYA TmpBuffer256
>STYA ZPPtrMAC
.1 jmp ARP.QUERY.I
.9 rts
*--------------------------------------
HST.GETBYADDR >PULLW ZPPtrIP

View File

@ -51,6 +51,11 @@ ICMP.IN ldy #S.ICMP.TYPE
dex
bpl .4
lda #K.ARP.TTL
sta ARP.TmpCache+S.ARPCACHE.TTL
lda /K.ARP.TTL
sta ARP.TmpCache+S.ARPCACHE.TTL+1
lda #S.ARPCACHE.STATUS.RESOLVED
jsr ARP.ADD.I