mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-06 01:07:32 +00:00
460 lines
8.3 KiB
Plaintext
460 lines
8.3 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
DNS.CLEAR ldx #K.DNSCACHE.SIZE*S.DNSCACHE
|
||
.1 stz DNS.CACHE-1,x
|
||
dex
|
||
bne .1
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
* DNS.QUERY
|
||
* In:
|
||
* PULLW = hostname PTR to PSTR
|
||
* PULLW = PTR to IP to fill with cached data
|
||
* Out:
|
||
* CC: hit: IP filled with address
|
||
* CS: missed
|
||
*--------------------------------------
|
||
DNS.QUERY >PULLW ZPPtrDNS Get host string
|
||
>PULLW ZPPtrIP Get IP address to fill
|
||
|
||
DNS.QUERY.I jsr DNS.FIND.BY.NAME
|
||
bcs DNS.REQUEST
|
||
|
||
lda (ZPCachePtr) get status...
|
||
bpl .9 Pending...
|
||
|
||
lda ZPCachePtr
|
||
clc
|
||
adc S.DNSCACHE.IP
|
||
sta ZPCachePtr
|
||
bcc .1
|
||
inc ZPCachePtr+1
|
||
|
||
.1 ldy #3
|
||
.2 lda (ZPCachePtr),y
|
||
sta (ZPPtrIP),y
|
||
dey
|
||
bpl .2
|
||
clc
|
||
rts
|
||
|
||
.9 lda #ERR.DNSPENDING
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
DNS.REQUEST jsr HST.PSTR2DNS.I
|
||
|
||
ldx #0
|
||
ldy #DNS.MSG.NAME-DNS.MSG
|
||
|
||
.1 lda DNS.Hostname,x
|
||
sta DNS.MSG,y
|
||
beq .2
|
||
inx
|
||
iny
|
||
bne .1
|
||
|
||
.2 iny
|
||
lda /S.DNS.QTYPE.A
|
||
sta DNS.MSG,y
|
||
iny
|
||
lda #S.DNS.QTYPE.A
|
||
sta DNS.MSG,y
|
||
|
||
iny
|
||
lda /S.DNS.QCLASS.IN
|
||
sta DNS.MSG,y
|
||
iny
|
||
lda #S.DNS.QCLASS.IN
|
||
sta DNS.MSG,y
|
||
|
||
iny
|
||
tya
|
||
sta DNS.MSG.LEN
|
||
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
|
||
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
|
||
bcs .9
|
||
|
||
>PUSHW DNS.MSG.LEN
|
||
>PUSHW L.DNS.MSG
|
||
>PUSHB hDNSSocket1
|
||
jsr SKT.SEND
|
||
|
||
lda hDNSSocket2
|
||
beq .3
|
||
|
||
>PUSHW DNS.MSG.LEN
|
||
>PUSHW L.DNS.MSG
|
||
>PUSHB hDNSSocket2
|
||
jsr SKT.SEND
|
||
|
||
.3 lda #ERR.DNSPENDING
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
* DNS.ADD
|
||
* In:
|
||
* PULLW = hostname PSTR to Add
|
||
* PULLW = PTR to IP
|
||
*--------------------------------------
|
||
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
|
||
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
|
||
lda #0
|
||
>PUSHYA push PSTR len
|
||
>PUSHBI 0 no option
|
||
>SYSCALL SYS.GetMem
|
||
bcs .9
|
||
|
||
>STYA ZPTmpPtr1
|
||
stx DNS.TmpCache+S.DNSCACHE.hNAME
|
||
|
||
lda (ZPPtrDNS)
|
||
sta (ZPTmpPtr1)
|
||
tay
|
||
|
||
.2 lda (ZPPtrDNS),y
|
||
sta (ZPTmpPtr1),y
|
||
dey
|
||
bne .2
|
||
|
||
.20 ldy #S.DNSCACHE-1
|
||
.3 lda DNS.TmpCache,y
|
||
sta (ZPCachePtr),y
|
||
dey
|
||
bpl .3
|
||
|
||
clc
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
DNS.GETCACHE >LDYA L.DNS.CACHE
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
DNS.FIND.BY.NAME
|
||
>LDYA L.DNS.CACHE
|
||
>STYA ZPCachePtr
|
||
|
||
lda #K.DNSCACHE.SIZE
|
||
sta TmpOffset
|
||
|
||
.1 lda (ZPCachePtr)
|
||
beq .6 empty DNS cache entry?
|
||
|
||
ldy #S.DNSCACHE.hNAME
|
||
lda (ZPCachePtr),y
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>STYA ZPTmpPtr1
|
||
|
||
lda (ZPPtrDNS)
|
||
cmp (ZPTmpPtr1)
|
||
bne .6
|
||
|
||
tay
|
||
|
||
.2 lda (ZPPtrDNS),y
|
||
cmp (ZPTmpPtr1),y
|
||
bne .6
|
||
dey
|
||
bne .2
|
||
|
||
clc
|
||
rts
|
||
|
||
.6 lda ZPCachePtr
|
||
clc
|
||
adc #S.DNSCACHE
|
||
sta ZPCachePtr
|
||
bcc .7
|
||
inc ZPCachePtr+1
|
||
|
||
.7 dec TmpOffset
|
||
bne .1
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
DNS.UPDATE.BY.ID
|
||
>LDYA L.DNS.CACHE
|
||
>STYA ZPCachePtr
|
||
|
||
ldx #K.DNSCACHE.SIZE
|
||
|
||
.1 lda (ZPCachePtr)
|
||
beq .6 empty DNS cache entry?
|
||
|
||
ldy #S.DNSCACHE.ID
|
||
lda (ZPCachePtr),y
|
||
cmp DNS.TmpCache+S.DNSCACHE.ID
|
||
bne .6
|
||
iny
|
||
lda (ZPCachePtr),y
|
||
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)
|
||
|
||
clc
|
||
rts
|
||
|
||
.6 lda ZPCachePtr
|
||
clc
|
||
adc #S.DNSCACHE
|
||
sta ZPCachePtr
|
||
bcc .7
|
||
inc ZPCachePtr+1
|
||
|
||
.7 dex
|
||
bne .1
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
DNS.FIND.FREE >LDYA L.DNS.CACHE
|
||
>STYA ZPCachePtr
|
||
|
||
lda #K.DNSCACHE.SIZE
|
||
sta TmpOffset
|
||
lda #$ff
|
||
sta TmpDWord
|
||
sta TmpDWord+1
|
||
sta TmpDWord+2
|
||
sta TmpDWord+3
|
||
|
||
.1 lda (ZPCachePtr)
|
||
beq .8 empty DNS cache entry?
|
||
bpl .6 pending.....skip
|
||
|
||
ldy #S.DNSCACHE.TTL
|
||
ldx #3
|
||
sec
|
||
.2 lda TmpDWord,x is save TTL greater then actual TTL?
|
||
sbc (ZPCachePtr),y
|
||
iny
|
||
dex
|
||
bpl .2
|
||
bcc .6 no,
|
||
|
||
ldy #S.DNSCACHE.TTL
|
||
ldx #3
|
||
.3 lda (ZPCachePtr),y Save new lowest TTL
|
||
sta TmpDWord,x
|
||
iny
|
||
dex
|
||
bpl .3
|
||
|
||
>LDYA ZPCachePtr
|
||
>STYA ZPTmpPtr1 save lowest TTL slot ...
|
||
|
||
.6 lda ZPCachePtr
|
||
clc
|
||
adc #S.DNSCACHE
|
||
sta ZPCachePtr
|
||
bcc .7
|
||
inc ZPCachePtr+1
|
||
|
||
.7 dec TmpOffset
|
||
bne .1 no empty slot found, discard lowest TTL
|
||
|
||
>LDYA ZPTmpPtr1
|
||
>STYA ZPCachePtr
|
||
jsr DNS.FREE
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
DNS.EXPIRE >LDYA L.DNS.CACHE
|
||
>STYA ZPCachePtr
|
||
|
||
lda #K.DNSCACHE.SIZE
|
||
sta TmpOffset
|
||
|
||
.1 lda (ZPCachePtr)
|
||
beq .7 empty DNS cache entry?
|
||
|
||
ldy #S.DNSCACHE.TTL
|
||
ldx #4
|
||
clc
|
||
.2 lda (ZPCachePtr),y
|
||
sbc #0
|
||
sta (ZPCachePtr),y
|
||
iny
|
||
dex
|
||
bne .2
|
||
bcs .7
|
||
jsr DNS.FREE
|
||
|
||
.7 lda ZPCachePtr
|
||
clc
|
||
adc #S.DNSCACHE
|
||
sta ZPCachePtr
|
||
bcc .8
|
||
inc ZPCachePtr+1
|
||
|
||
.8 dec TmpOffset
|
||
bne .1
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
DNS.FREE ldy #S.DNSCACHE.hNAME
|
||
lda (ZPCachePtr),y
|
||
>SYSCALL SYS.FreeMemA
|
||
lda #0
|
||
sta (ZPCachePtr)
|
||
rts
|
||
*--------------------------------------
|
||
DNS.POLL lda hDNSSocket1
|
||
beq .8
|
||
jsr SKT.RCVDA
|
||
bcs .8
|
||
jsr DNS.DecodeMsg
|
||
|
||
lda hDNSSocket2
|
||
beq .8
|
||
jsr SKT.RCVDA
|
||
bcs .8
|
||
jsr DNS.DecodeMsg
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
DNS.DecodeMsg sta hFrame1
|
||
>SYSCALL SYS.GetMemPtrA
|
||
>STYA ZPFrameBase1
|
||
|
||
>DEBUG
|
||
|
||
ldy #S.DNS.F+1
|
||
lda (ZPFrameBase1),y
|
||
and /S.DNS.F.QR
|
||
beq .9
|
||
|
||
ldy #S.DNS.ID
|
||
lda (ZPFrameBase1),y
|
||
sta DNS.TmpCache+S.DNSCACHE.ID+1
|
||
iny
|
||
lda (ZPFrameBase1),y
|
||
sta DNS.TmpCache+S.DNSCACHE.ID
|
||
|
||
ldy #S.DNS.ANCOUNT+1
|
||
lda (ZPFrameBase1),y
|
||
beq .9
|
||
|
||
ldy #S.DNS.QDCOUNT+1
|
||
lda (ZPFrameBase1),y
|
||
tax
|
||
beq .3 no QUERY to skip
|
||
|
||
ldy #S.DNS Read query
|
||
|
||
.1 lda (ZPFrameBase1),y
|
||
beq .2
|
||
iny
|
||
bne .1
|
||
.2 tya
|
||
clc
|
||
adc #4 Skip QTYPE & QCLASS
|
||
tay
|
||
dex skip another QUERY ?
|
||
bne .1
|
||
|
||
.3 iny Skip Pointer or labels....
|
||
lda (ZPFrameBase1),y
|
||
bne .3
|
||
|
||
iny skip S.DNS.QTYPE HIGH
|
||
iny
|
||
lda (ZPFrameBase1),y
|
||
cmp #S.DNS.QTYPE.A
|
||
bne .9
|
||
iny skip QCLASS
|
||
iny
|
||
|
||
ldx #3
|
||
.4 iny
|
||
lda (ZPFrameBase1),y
|
||
sta DNS.TmpCache+S.DNSCACHE.TTL,x
|
||
dex
|
||
bpl .4
|
||
|
||
iny skip DATALEN
|
||
iny
|
||
ldx #0
|
||
|
||
.5 iny
|
||
lda (ZPFrameBase1),y
|
||
sta DNS.TmpCache+S.DNSCACHE.IP,x
|
||
inx
|
||
cpx #4
|
||
bne .5
|
||
|
||
jsr DNS.UPDATE.BY.ID
|
||
|
||
.9 lda hFrame1
|
||
>SYSCALL SYS.FreeMemA
|
||
rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE LIB/LIBTCPIP.S.DNS
|
||
LOAD LIB/LIBTCPIP.S
|
||
ASM
|