A2osX/LIB/LIBTCPIP.S.DNS.txt

541 lines
9.2 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
2019-05-05 17:15:37 +00:00
AUTO 3,1
*/--------------------------------------
* # DNS.Clear
* Clear DNS Cache
2021-05-19 12:44:47 +00:00
* **In:**
* ## RETURN VALUE
*\--------------------------------------
DNS.Clear ldx #K.DNSCACHE.SIZE*S.DNSCACHE
2019-10-06 12:50:43 +00:00
2015-03-14 21:48:35 +00:00
.1 stz DNS.CACHE-1,x
dex
bne .1
2019-10-06 12:50:43 +00:00
2015-03-14 21:48:35 +00:00
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
2021-05-19 12:44:47 +00:00
* 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
2021-05-19 12:44:47 +00:00
* CS: missed
*\--------------------------------------
DNS.Query >PULLW ZPPtrDNS Get host string
>PULLW ZPPtrIP Get IP address to fill
2019-10-03 06:25:27 +00:00
DNS.Query.I jsr DNS.FIND.BY.NAME
2016-03-15 17:16:14 +00:00
bcs DNS.REQUEST
2019-10-03 06:25:27 +00:00
2016-03-15 17:16:14 +00:00
lda (ZPCachePtr) get status...
bpl .9 Pending...
2019-10-03 06:25:27 +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
2020-09-05 13:38:04 +00:00
2016-03-15 17:16:14 +00:00
inc ZPCachePtr+1
2019-10-06 12:50:43 +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
2019-10-06 12:50:43 +00:00
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
2019-10-03 06:25:27 +00:00
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
2019-10-03 06:25:27 +00:00
sty DNS.MSG.LEN
stz DNS.MSG.LEN+1
>LDYA A2osX.RANDOM16
2016-03-15 17:16:14 +00:00
>STYA DNS.MSG.ID
>STYA DNS.TmpCache+S.DNSCACHE.ID
2019-10-03 06:25:27 +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
2019-10-03 06:25:27 +00:00
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
2019-06-05 15:34:49 +00:00
sec
.9 rts
2018-09-10 15:07:26 +00:00
*--------------------------------------
DNS.REQUEST.SEND
2018-11-06 19:26:45 +00:00
>LDYAI UDP.PORT.DNS
>STYA SA.REMOTE+S.SOCKADDR.PORT
2019-10-03 06:25:27 +00:00
2018-11-01 08:53:47 +00:00
ldy #3
2019-10-03 06:25:27 +00:00
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
2019-10-03 06:25:27 +00:00
2018-11-06 19:26:45 +00:00
jsr .4
2019-10-03 06:25:27 +00:00
2020-09-05 13:38:04 +00:00
lda IPCFG+S.IPCFG.DNS2
beq .8
2018-11-06 19:26:45 +00:00
ldy #3
2019-10-03 06:25:27 +00:00
2018-11-06 19:26:45 +00:00
.2 lda IPCFG+S.IPCFG.DNS2,y
sta SA.REMOTE+S.SOCKADDR.ADDR,y
dey
bpl .2
2018-10-08 15:41:00 +00:00
2021-05-19 12:44:47 +00:00
.4 >PUSHB hDNSSocket
2018-09-17 15:42:38 +00:00
>PUSHW L.DNS.MSG
2021-05-19 12:44:47 +00:00
>PUSHW DNS.MSG.LEN
>PUSHW L.SA.REMOTE
2018-10-08 15:41:00 +00:00
jmp SKT.SendTo
2019-10-06 12:50:43 +00:00
2018-11-06 19:26:45 +00:00
.8 clc
2019-10-03 06:25:27 +00:00
rts
2018-09-10 15:07:26 +00:00
*--------------------------------------
DNS.CSTR2DNS lda (ZPPtrDNS)
beq .9
2019-10-06 12:50:43 +00:00
2018-09-10 15:07:26 +00:00
>LDYA ZPPtrDNS
2019-05-05 17:15:37 +00:00
>SYSCALL2 strlen
2018-09-10 15:07:26 +00:00
tax
bne .9
2019-10-03 06:25:27 +00:00
2018-09-10 15:07:26 +00:00
cpy #K.DNS.MAXLEN-1
bcs .9
2020-09-05 13:38:04 +00:00
2018-09-10 15:07:26 +00:00
lda #0 Ending 0
sta DNS.MSG.NAME+1,y
phy save len for later
2020-09-05 13:38:04 +00:00
2018-09-10 15:07:26 +00:00
ldx #0
dey
2019-10-06 12:50:43 +00:00
2018-09-10 15:07:26 +00:00
.1 lda (ZPPtrDNS),y
and #$7f
cmp #'.'
2019-10-06 12:50:43 +00:00
beq .3
2018-09-10 15:07:26 +00:00
cmp #'A'
2019-10-06 12:50:43 +00:00
bcc .2
2018-09-10 15:07:26 +00:00
cmp #'Z'+1
2019-10-06 12:50:43 +00:00
bcs .2
2021-05-19 12:44:47 +00:00
2018-09-10 15:07:26 +00:00
adc #$20
2019-10-06 12:50:43 +00:00
.2 inx
bra .4
.3 txa
2018-09-10 15:07:26 +00:00
ldx #0
2019-10-06 12:50:43 +00:00
.4 sta DNS.MSG.NAME+1,y
2018-09-10 15:07:26 +00:00
dey
bpl .1
2019-10-06 12:50:43 +00:00
2018-09-10 15:07:26 +00:00
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
2019-10-06 12:50:43 +00:00
2018-09-10 15:07:26 +00:00
.9 sec
2019-10-03 06:25:27 +00:00
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
2019-10-06 12:50:43 +00:00
2016-03-16 16:37:02 +00:00
ldy #3
2020-09-05 13:38:04 +00:00
2016-03-16 16:37:02 +00:00
.1 lda (ZPPtrIP),y
sta DNS.TmpCache+S.DNSCACHE.IP,y
dey
bpl .1
2019-10-06 12:50:43 +00:00
2016-03-16 16:37:02 +00:00
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
2019-10-06 12:50:43 +00:00
2016-03-15 17:16:14 +00:00
lda #S.DNSCACHE.STATUS.RESOLVED+S.DNSCACHE.STATUS.STATIC
2019-10-06 12:50:43 +00:00
2016-03-15 17:16:14 +00:00
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
2019-05-05 17:15:37 +00:00
>SYSCALL2 strdup
2016-03-15 17:16:14 +00:00
bcs .9
2019-10-06 12:50:43 +00:00
txa
ldy #S.DNSCACHE.hNAME
sta (ZPCachePtr),y
2019-10-03 06:25:27 +00:00
.2 lda DNS.TmpCache
sta (ZPCachePtr)
2019-10-06 12:50:43 +00:00
ldy #S.DNSCACHE.ID
2019-10-06 12:50:43 +00:00
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
2019-10-06 12:50:43 +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
2019-10-06 12:50:43 +00:00
>STYA ZPCachePtr
2021-05-19 12:44:47 +00:00
2016-03-15 17:16:14 +00:00
clc
rts
*--------------------------------------
DNS.FIND.BY.NAME
2019-10-06 12:50:43 +00:00
jsr DNS.GetCAche
2021-05-19 12:44:47 +00:00
2019-05-13 15:40:37 +00:00
ldx #K.DNSCACHE.SIZE
2020-09-05 13:38:04 +00:00
2016-03-15 17:16:14 +00:00
.1 lda (ZPCachePtr)
beq .6 empty DNS cache entry?
2019-10-06 12:50:43 +00:00
2019-05-13 15:40:37 +00:00
phx
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
2019-05-05 17:15:37 +00:00
>SYSCALL2 GetMemPtr
2021-05-04 17:31:21 +00:00
>PUSHYA
2019-05-05 17:15:37 +00:00
>SYSCALL2 StrCaseCmp
2019-05-13 15:40:37 +00:00
plx
2018-01-15 16:51:44 +00:00
bcc .8
2019-10-06 12:50:43 +00:00
.6 jsr DNS.NextCache
2021-05-19 12:44:47 +00:00
2019-10-06 12:50:43 +00:00
dex
2015-10-19 20:35:00 +00:00
bne .1
2019-10-06 12:50:43 +00:00
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
2019-10-06 12:50:43 +00:00
jsr DNS.GetCAche
2021-05-19 12:44:47 +00:00
2016-03-17 07:31:11 +00:00
ldx #K.DNSCACHE.SIZE
2020-09-05 13:38:04 +00:00
2016-03-17 07:31:11 +00:00
.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
2021-05-19 12:44:47 +00:00
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
2021-05-19 12:44:47 +00:00
2016-03-17 07:31:11 +00:00
clc
rts
2019-10-06 12:50:43 +00:00
.6 jsr DNS.NextCache
dex
2016-03-17 07:31:11 +00:00
bne .1
2020-09-05 13:38:04 +00:00
2016-03-17 07:31:11 +00:00
sec
rts
*--------------------------------------
2019-10-06 12:50:43 +00:00
DNS.FIND.FREE jsr DNS.GetCAche
2016-03-15 17:16:14 +00:00
lda #$ff
sta TmpDWord
sta TmpDWord+1
sta TmpDWord+2
sta TmpDWord+3
2019-05-13 15:40:37 +00:00
ldx #K.DNSCACHE.SIZE
2016-03-15 17:16:14 +00:00
.1 lda (ZPCachePtr)
beq .8 empty DNS cache entry?
2019-05-13 15:40:37 +00:00
bit #S.DNSCACHE.STATUS.STATIC+S.DNSCACHE.STATUS.PENDING
2019-05-13 15:40:37 +00:00
bne .7 Static/Pending.....skip
phx
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
2020-09-05 13:38:04 +00:00
2016-03-15 17:16:14 +00:00
bcc .6 no,
2020-09-05 13:38:04 +00:00
2016-03-15 17:16:14 +00:00
ldy #S.DNSCACHE.TTL
2016-03-16 16:37:02 +00:00
ldx #3
2020-09-05 13:38:04 +00:00
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
2020-09-05 13:38:04 +00:00
2016-03-15 17:16:14 +00:00
>LDYA ZPCachePtr
>STYA ZPTmpPtr1 save lowest TTL slot ...
2020-09-05 13:38:04 +00:00
2019-05-13 15:40:37 +00:00
.6 plx
2019-10-06 12:50:43 +00:00
.7 jsr DNS.NextCache
dex
2016-03-15 17:16:14 +00:00
bne .1 no empty slot found, discard lowest TTL
2019-10-06 12:50:43 +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
*--------------------------------------
2019-10-06 12:50:43 +00:00
DNS.EXPIRE jsr DNS.GetCAche
2019-05-13 15:40:37 +00:00
ldx #K.DNSCACHE.SIZE
2016-03-15 17:16:14 +00:00
.1 lda (ZPCachePtr)
beq .7 empty DNS cache entry?
2019-05-13 15:40:37 +00:00
bit #S.DNSCACHE.STATUS.STATIC
bne .7
2019-05-13 15:40:37 +00:00
phx
2019-10-06 12:50:43 +00:00
2016-03-15 17:16:14 +00:00
ldy #S.DNSCACHE.TTL
2019-10-06 12:50:43 +00:00
2016-03-15 17:16:14 +00:00
ldx #4
clc
2019-10-06 12:50:43 +00:00
2016-03-15 17:16:14 +00:00
.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
2021-05-19 12:44:47 +00:00
2019-05-13 15:40:37 +00:00
bcs .6
2016-03-15 17:16:14 +00:00
jsr DNS.FREE
2019-10-03 06:25:27 +00:00
.6 plx
2019-10-06 12:50:43 +00:00
.7 jsr DNS.NextCache
2019-05-13 15:40:37 +00:00
.8 dex
2016-03-15 17:16:14 +00:00
bne .1
2019-05-13 15:40:37 +00:00
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
2020-09-05 13:38:04 +00:00
2019-05-05 17:15:37 +00:00
>SYSCALL2 FreeMem
2020-09-05 13:38:04 +00:00
.1 lda #0
2016-03-15 17:16:14 +00:00
sta (ZPCachePtr)
2019-10-03 06:25:27 +00:00
DNS.FREE.RTS rts
2015-03-14 21:48:35 +00:00
*--------------------------------------
2018-10-08 15:41:00 +00:00
DNS.POLL lda hDNSSocket
2019-06-05 15:34:49 +00:00
beq DNS.FREE.RTS
2018-10-08 15:41:00 +00:00
jsr SKT.Recv
2019-06-05 15:34:49 +00:00
bcs DNS.FREE.RTS
2018-08-08 15:13:37 +00:00
2019-06-05 15:34:49 +00:00
sta hFrameIn
2019-05-05 17:15:37 +00:00
>SYSCALL2 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
ldy #S.DNS.ANCOUNT+1
lda (ZPFrameInPtr),y
beq .9
2020-09-05 13:38:04 +00:00
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
2020-09-05 13:38:04 +00:00
.1 lda (ZPFrameInPtr),y
beq .2
bpl .11 Pointer ?
2020-09-05 13:38:04 +00:00
iny yes, skip 2 bytes
iny
bra .2
2020-09-05 13:38:04 +00:00
.11 tya
sec
adc (ZPFrameInPtr),y Skip LEN+1 bytes
tay
bra .1
2020-09-05 13:38:04 +00:00
2021-05-19 12:44:47 +00:00
.2 iny
iny
iny Skip QTYPE & QCLASS
iny
iny next pos
.21 dex skip another QUERY ?
bne .1
2020-09-05 13:38:04 +00:00
plx get back answer count
2020-09-05 13:38:04 +00:00
.3 lda (ZPFrameInPtr),y
beq .32
2021-05-19 12:44:47 +00:00
bpl .31 Pointer ?
iny yes, skip 2 bytes
2016-03-17 07:31:11 +00:00
iny
bra .32
2021-05-19 12:44:47 +00:00
.31 tya
sec
adc (ZPFrameInPtr),y Skip LEN+1 bytes
tay
bra .3
2020-09-05 13:38:04 +00:00
.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
2020-09-05 13:38:04 +00:00
.40 iny skip QCLASS
2016-03-17 07:31:11 +00:00
iny
iny next pos
2020-09-05 13:38:04 +00:00
2016-03-17 07:31:11 +00:00
ldx #3
2020-09-05 13:38:04 +00:00
.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
2020-09-05 13:38:04 +00:00
.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
2020-09-05 13:38:04 +00:00
2016-03-17 07:31:11 +00:00
jsr DNS.UPDATE.BY.ID
2021-05-19 12:44:47 +00:00
2019-11-17 14:39:55 +00:00
.9 jmp FRM.DiscardIn
*--------------------------------------
2019-10-06 12:50:43 +00:00
DNS.NextCache lda ZPCachePtr
clc
adc #S.DNSCACHE
sta ZPCachePtr
bcc .8
inc ZPCachePtr+1
2021-05-19 12:44:47 +00:00
2019-10-06 12:50:43 +00:00
.8 rts
*--------------------------------------
2015-03-14 21:48:35 +00:00
MAN
2020-06-07 08:06:51 +00:00
SAVE usr/src/lib/libtcpip.s.dns
LOAD usr/src/lib/libtcpip.s
2015-03-14 21:48:35 +00:00
ASM