A2osX/LIB/LIBTCPIP.S.DNS.txt

552 lines
9.9 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
PREFIX /A2OSX.BUILD
2017-12-22 21:24:30 +00:00
AUTO 4,1
2015-03-14 21:48:35 +00:00
.LIST OFF
*/--------------------------------------
* # DNS.Clear
* Clear DNS Cache
2018-06-18 08:44:02 +00:00
* **In:**
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
*\--------------------------------------
DNS.Clear ldx #K.DNSCACHE.SIZE*S.DNSCACHE
2015-03-14 21:48:35 +00:00
.1 stz DNS.CACHE-1,x
dex
bne .1
clc
rts
*/--------------------------------------
* # DNS.Query
* Query DNS for specified host
2018-06-14 15:31:36 +00:00
* **In:**
* PUSHW = PTR to IP to fill with cached data
* PUSHW = hostname PTR to PSTR
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2015-03-14 21:48:35 +00:00
* CC: hit: IP filled with address
* CS: missed
*\--------------------------------------
DNS.Query >PULLW ZPPtrDNS Get host string
>PULLW ZPPtrIP Get IP address to fill
2015-03-14 21:48:35 +00:00
DNS.Query.I jsr DNS.FIND.BY.NAME
2016-03-15 17:16:14 +00:00
bcs DNS.REQUEST
2015-10-19 20:35:00 +00:00
2016-03-15 17:16:14 +00:00
lda (ZPCachePtr) get status...
bpl .9 Pending...
2015-03-14 21:48:35 +00:00
2016-03-15 17:16:14 +00:00
lda ZPCachePtr
clc
adc #S.DNSCACHE.IP
2016-03-15 17:16:14 +00:00
sta ZPCachePtr
bcc .1
inc ZPCachePtr+1
2015-03-14 21:48:35 +00:00
2016-03-15 17:16:14 +00:00
.1 ldy #3
2016-03-15 17:16:14 +00:00
.2 lda (ZPCachePtr),y
sta (ZPPtrIP),y
2016-03-15 17:16:14 +00:00
dey
bpl .2
2015-03-14 21:48:35 +00:00
clc
rts
.9 lda #ERR.DNS.PENDING
2016-03-15 17:16:14 +00:00
sec
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
2018-10-08 15:41:00 +00:00
DNS.REQUEST lda hDNSSocket
2018-09-10 15:07:26 +00:00
beq .99
2018-09-10 15:07:26 +00:00
jsr DNS.CSTR2DNS Y=DNS string len+0
bcs .99
2015-03-14 21:48:35 +00:00
iny
lda /S.DNS.QTYPE.A
sta DNS.MSG,y
2015-03-14 21:48:35 +00:00
iny
lda #S.DNS.QTYPE.A
sta DNS.MSG,y
2015-03-14 21:48:35 +00:00
iny
lda /S.DNS.QCLASS.IN
sta DNS.MSG,y
2015-03-14 21:48:35 +00:00
iny
lda #S.DNS.QCLASS.IN
sta DNS.MSG,y
2015-03-14 21:48:35 +00:00
iny
tya
sta DNS.MSG.LEN
lda #0
sta DNS.MSG.LEN+1
2015-03-14 21:48:35 +00:00
>LDYA A2osX.RANDOM16
2016-03-15 17:16:14 +00:00
>STYA DNS.MSG.ID
>STYA DNS.TmpCache+S.DNSCACHE.ID
2016-03-16 16:37:02 +00:00
lda #K.DNS.PENDING.TTL
2016-03-15 17:16:14 +00:00
sta DNS.TmpCache+S.DNSCACHE.TTL
2016-03-16 16:37:02 +00:00
stz DNS.TmpCache+S.DNSCACHE.TTL+1
stz DNS.TmpCache+S.DNSCACHE.TTL+2
stz DNS.TmpCache+S.DNSCACHE.TTL+3
2016-03-15 17:16:14 +00:00
lda #S.DNSCACHE.STATUS.PENDING
jsr DNS.ADD.I
bcs .9
2018-09-10 15:07:26 +00:00
jsr DNS.REQUEST.SEND
bcs .99
2018-10-08 15:41:00 +00:00
lda #ERR.DNS.PENDING
sec
rts
2018-09-10 15:07:26 +00:00
.99 lda #ERR.DNS.ERROR
.9 sec
rts
*--------------------------------------
DNS.REQUEST.SEND
2018-11-06 19:26:45 +00:00
>LDYAI UDP.PORT.DNS
>STYA SA.REMOTE+S.SOCKADDR.PORT
2018-11-01 08:53:47 +00:00
ldy #3
2018-11-06 19:26:45 +00:00
.1 lda IPCFG+S.IPCFG.DNS1,y
2018-11-01 08:53:47 +00:00
sta SA.REMOTE+S.SOCKADDR.ADDR,y
dey
bpl .1
2018-11-06 19:26:45 +00:00
jsr .4
2018-11-01 08:53:47 +00:00
2018-11-06 19:26:45 +00:00
ldy #3
.2 lda IPCFG+S.IPCFG.DNS2,y
beq .8
sta SA.REMOTE+S.SOCKADDR.ADDR,y
dey
bpl .2
2018-11-01 08:53:47 +00:00
2018-11-06 19:26:45 +00:00
.4 >PUSHW L.SA.REMOTE
2018-10-08 15:41:00 +00:00
>PUSHW DNS.MSG.LEN
2018-09-17 15:42:38 +00:00
>PUSHW L.DNS.MSG
2018-10-08 15:41:00 +00:00
lda hDNSSocket
jmp SKT.SendTo
2018-11-06 19:26:45 +00:00
.8 clc
rts
2018-09-10 15:07:26 +00:00
*--------------------------------------
DNS.CSTR2DNS lda (ZPPtrDNS)
beq .9
2015-03-14 21:48:35 +00:00
2018-09-10 15:07:26 +00:00
>LDYA ZPPtrDNS
>SYSCALL strlen
tax
bne .9
cpy #K.DNS.MAXLEN-1
bcs .9
lda #0 Ending 0
sta DNS.MSG.NAME+1,y
phy save len for later
ldx #0
dey
.1 lda (ZPPtrDNS),y
and #$7f
cmp #'.'
beq .2
cmp #'A'
bcc .10
cmp #'Z'+1
bcs .10
adc #$20
.10 inx
bra .3
.2 txa
ldx #0
.3 sta DNS.MSG.NAME+1,y
dey
bpl .1
stx DNS.MSG.NAME
2018-09-10 20:42:21 +00:00
pla Get back Len
sec +1
adc #S.DNS-S.UDP compute offset next to NAME
tay
* clc
2015-03-14 21:48:35 +00:00
rts
2018-09-10 15:07:26 +00:00
.9 sec
rts
*/--------------------------------------
* # DNS.Add
* Add a static DNS record
2018-06-14 15:31:36 +00:00
* **In:**
* PUSHW = PTR to IP
* PUSHW = hostname CSTR to Add
*\--------------------------------------
DNS.Add >PULLW ZPPtrDNS Get host string
>PULLW ZPPtrIP Get host IP address
2018-08-08 15:13:37 +00:00
2016-03-16 16:37:02 +00:00
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
2016-03-15 17:16:14 +00:00
lda #S.DNSCACHE.STATUS.RESOLVED+S.DNSCACHE.STATUS.STATIC
DNS.ADD.I sta DNS.TmpCache
jsr DNS.FIND.BY.NAME
bcc .2 Found, go update...
2016-03-16 16:37:02 +00:00
jsr DNS.FIND.FREE
>LDYA ZPPtrDNS
2018-07-23 06:28:47 +00:00
>SYSCALL newstr
2016-03-15 17:16:14 +00:00
bcs .9
txa
ldy #S.DNSCACHE.hNAME
sta (ZPCachePtr),y
.2 lda DNS.TmpCache
sta (ZPCachePtr)
2015-03-14 21:48:35 +00:00
ldy #S.DNSCACHE.ID
2016-03-16 16:37:02 +00:00
.3 lda DNS.TmpCache,y
2016-03-15 17:16:14 +00:00
sta (ZPCachePtr),y
iny
cpy #S.DNSCACHE
bne .3
2015-03-14 21:48:35 +00:00
2016-03-15 17:16:14 +00:00
clc
.9 rts
*/--------------------------------------
* # DNS.GetCAche
* Return a Ptr to DNS Cache Table
2018-06-14 15:31:36 +00:00
* **In:**
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* Y,A = PTR to DNS.CACHE
*\--------------------------------------
DNS.GetCAche >LDYA L.DNS.CACHE
2016-03-15 17:16:14 +00:00
clc
rts
*--------------------------------------
DNS.FIND.BY.NAME
>LDYA L.DNS.CACHE
>STYA ZPCachePtr
2015-10-19 20:35:00 +00:00
2016-03-15 17:16:14 +00:00
lda #K.DNSCACHE.SIZE
sta TmpOffset
2015-03-14 21:48:35 +00:00
2016-03-15 17:16:14 +00:00
.1 lda (ZPCachePtr)
beq .6 empty DNS cache entry?
2015-10-19 20:35:00 +00:00
2018-09-06 12:27:37 +00:00
>PUSHW ZPPtrDNS
2016-03-15 17:16:14 +00:00
ldy #S.DNSCACHE.hNAME
lda (ZPCachePtr),y
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
2018-09-06 12:27:37 +00:00
>SYSCALL StrCaseCmp
2018-01-15 16:51:44 +00:00
bcc .8
2016-03-15 17:16:14 +00:00
.6 lda ZPCachePtr
2015-03-14 21:48:35 +00:00
clc
adc #S.DNSCACHE
2016-03-15 17:16:14 +00:00
sta ZPCachePtr
bcc .7
inc ZPCachePtr+1
.7 dec TmpOffset
2015-10-19 20:35:00 +00:00
bne .1
2016-03-15 17:16:14 +00:00
sec
2018-01-15 16:51:44 +00:00
.8 rts
2016-03-15 17:16:14 +00:00
*--------------------------------------
2016-03-17 07:31:11 +00:00
DNS.UPDATE.BY.ID
>LDYA L.DNS.CACHE
>STYA ZPCachePtr
2018-08-08 15:13:37 +00:00
2016-03-17 07:31:11 +00:00
ldx #K.DNSCACHE.SIZE
.1 lda (ZPCachePtr)
beq .6 empty DNS cache entry?
bmi .6 resolved ?
2018-08-08 15:13:37 +00:00
2016-03-17 07:31:11 +00:00
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
lda #S.DNSCACHE.STATUS.RESOLVED
sta (ZPCachePtr)
ldy #S.DNSCACHE.TTL
2016-03-17 07:31:11 +00:00
.2 lda DNS.TmpCache,y
sta (ZPCachePtr),y
iny
cpy #S.DNSCACHE
2016-03-17 07:31:11 +00:00
bne .2
clc
rts
.6 lda ZPCachePtr
clc
adc #S.DNSCACHE
sta ZPCachePtr
bcc .7
inc ZPCachePtr+1
.7 dex
bne .1
sec
rts
*--------------------------------------
2016-03-15 17:16:14 +00:00
DNS.FIND.FREE >LDYA L.DNS.CACHE
>STYA ZPCachePtr
lda #K.DNSCACHE.SIZE
sta TmpOffset
2018-08-08 15:13:37 +00:00
2016-03-15 17:16:14 +00:00
lda #$ff
sta TmpDWord
sta TmpDWord+1
sta TmpDWord+2
sta TmpDWord+3
.1 lda (ZPCachePtr)
beq .8 empty DNS cache entry?
bit #S.DNSCACHE.STATUS.STATIC+S.DNSCACHE.STATUS.PENDING
bne .6 Static/Pending.....skip
2016-03-15 17:16:14 +00:00
ldy #S.DNSCACHE.TTL
2016-03-16 16:37:02 +00:00
ldx #3
2016-03-15 17:16:14 +00:00
sec
.2 lda TmpDWord,x is saved TTL greater then actual TTL?
2016-03-15 17:16:14 +00:00
sbc (ZPCachePtr),y
iny
2016-03-16 16:37:02 +00:00
dex
bpl .2
2016-03-15 17:16:14 +00:00
bcc .6 no,
2015-10-19 20:35:00 +00:00
2016-03-15 17:16:14 +00:00
ldy #S.DNSCACHE.TTL
2016-03-16 16:37:02 +00:00
ldx #3
2016-03-15 17:16:14 +00:00
.3 lda (ZPCachePtr),y Save new lowest TTL
sta TmpDWord,x
iny
2016-03-16 16:37:02 +00:00
dex
bpl .3
2015-03-14 21:48:35 +00:00
2016-03-15 17:16:14 +00:00
>LDYA ZPCachePtr
>STYA ZPTmpPtr1 save lowest TTL slot ...
2015-10-19 20:35:00 +00:00
2016-03-15 17:16:14 +00:00
.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
2015-03-14 21:48:35 +00:00
2016-03-15 17:16:14 +00:00
>LDYA ZPTmpPtr1
>STYA ZPCachePtr
2016-03-16 16:37:02 +00:00
jsr DNS.FREE
2015-10-19 20:35:00 +00:00
2016-03-15 17:16:14 +00:00
.8 clc
2015-03-14 21:48:35 +00:00
rts
2016-03-15 17:16:14 +00:00
*--------------------------------------
DNS.EXPIRE >LDYA L.DNS.CACHE
>STYA ZPCachePtr
2015-03-14 21:48:35 +00:00
2016-03-15 17:16:14 +00:00
lda #K.DNSCACHE.SIZE
sta TmpOffset
2015-10-19 20:35:00 +00:00
2016-03-15 17:16:14 +00:00
.1 lda (ZPCachePtr)
beq .7 empty DNS cache entry?
bit #S.DNSCACHE.STATUS.STATIC
bne .7
2016-03-15 17:16:14 +00:00
ldy #S.DNSCACHE.TTL
ldx #4
clc
.2 lda (ZPCachePtr),y
sbc #0
sta (ZPCachePtr),y
2015-03-14 21:48:35 +00:00
iny
2016-03-15 17:16:14 +00:00
dex
2015-03-14 21:48:35 +00:00
bne .2
2016-03-15 17:16:14 +00:00
bcs .7
jsr DNS.FREE
2015-03-14 21:48:35 +00:00
2016-03-15 17:16:14 +00:00
.7 lda ZPCachePtr
clc
adc #S.DNSCACHE
sta ZPCachePtr
bcc .8
inc ZPCachePtr+1
.8 dec TmpOffset
bne .1
2015-03-14 21:48:35 +00:00
clc
rts
*--------------------------------------
2016-03-15 17:16:14 +00:00
DNS.FREE ldy #S.DNSCACHE.hNAME
lda (ZPCachePtr),y
beq .1
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
.1 lda #0
2016-03-15 17:16:14 +00:00
sta (ZPCachePtr)
2015-03-14 21:48:35 +00:00
rts
*--------------------------------------
2018-10-08 15:41:00 +00:00
DNS.POLL lda hDNSSocket
beq .8
2018-10-08 15:41:00 +00:00
jsr SKT.Recv
2016-03-16 16:37:02 +00:00
bcs .8
2018-08-08 15:13:37 +00:00
2016-03-16 16:37:02 +00:00
jsr DNS.DecodeMsg
2018-10-08 15:41:00 +00:00
.8 clc
rts
*--------------------------------------
2017-01-29 21:47:19 +00:00
DNS.DecodeMsg sta hFrameIn
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
>STYA ZPFrameInPtr
2018-08-08 15:13:37 +00:00
2018-11-01 08:53:47 +00:00
ldy #S.DNS.F
lda (ZPFrameInPtr),y
and /S.DNS.F.QR
beq .9
2016-03-17 07:31:11 +00:00
ldy #S.DNS.ID
lda (ZPFrameInPtr),y
sta DNS.TmpCache+S.DNSCACHE.ID
2016-03-17 07:31:11 +00:00
iny
lda (ZPFrameInPtr),y
sta DNS.TmpCache+S.DNSCACHE.ID+1
2016-03-17 07:31:11 +00:00
ldy #S.DNS.ANCOUNT+1
lda (ZPFrameInPtr),y
beq .9
pha save Answer count...
ldy #S.DNS.QDCOUNT+1
lda (ZPFrameInPtr),y
ldy #S.DNS Point to DATA
tax
beq .3 no QUERY to skip
.1 lda (ZPFrameInPtr),y
beq .2
bpl .11 Pointer ?
iny yes, skip 2 bytes
iny
bra .2
.11 tya
sec
adc (ZPFrameInPtr),y Skip LEN+1 bytes
tay
bra .1
.2 iny
iny
iny Skip QTYPE & QCLASS
iny
iny next pos
.21 dex skip another QUERY ?
bne .1
plx get back answer count
2016-03-17 07:31:11 +00:00
.3 lda (ZPFrameInPtr),y
beq .32
bpl .31 Pointer ?
iny yes, skip 2 bytes
2016-03-17 07:31:11 +00:00
iny
bra .32
.31 tya
sec
adc (ZPFrameInPtr),y Skip LEN+1 bytes
tay
bra .3
.32 iny skip S.DNS.QTYPE HIGH
lda (ZPFrameInPtr),y
2016-03-17 07:31:11 +00:00
cmp #S.DNS.QTYPE.A
beq .40
tya
clc
adc #7 skip CLASS,TTL+DATALENHIGH
tay
sec skip DATALENLO
adc (ZPFrameInPtr),y add DATALEN
tay
dex
bne .3
bra .9
.40 iny skip QCLASS
2016-03-17 07:31:11 +00:00
iny
iny next pos
2016-03-17 07:31:11 +00:00
ldx #3
.4 lda (ZPFrameInPtr),y
2016-03-17 07:31:11 +00:00
sta DNS.TmpCache+S.DNSCACHE.TTL,x
iny
2016-03-17 07:31:11 +00:00
dex
bpl .4
iny skip DATALEN
iny
ldx #0
.5 lda (ZPFrameInPtr),y
2016-03-17 07:31:11 +00:00
sta DNS.TmpCache+S.DNSCACHE.IP,x
iny
2016-03-17 07:31:11 +00:00
inx
cpx #4
bne .5
jsr DNS.UPDATE.BY.ID
2016-03-16 16:37:02 +00:00
2017-01-29 21:47:19 +00:00
.9 lda hFrameIn
2018-09-17 15:42:38 +00:00
>SYSCALL FreeMem
2018-08-08 15:13:37 +00:00
clc
2016-03-16 16:37:02 +00:00
rts
*--------------------------------------
2015-03-14 21:48:35 +00:00
MAN
SAVE /A2OSX.SRC/LIB/LIBTCPIP.S.DNS
LOAD /A2OSX.SRC/LIB/LIBTCPIP.S
2015-03-14 21:48:35 +00:00
ASM