aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhpa <hpa>2004-12-27 01:50:31 +0000
committerhpa <hpa>2004-12-27 01:50:31 +0000
commit091f9b1f027ef86c7e9253486378afb1da496de0 (patch)
tree9e1ba2e4f516b20998a0ff8df04eb257a94c28c3
parent474aaa2918c2c100624902a495c50f03ea57571e (diff)
downloadsyslinux.git-091f9b1f027ef86c7e9253486378afb1da496de0.tar.gz
syslinux.git-091f9b1f027ef86c7e9253486378afb1da496de0.tar.xz
syslinux.git-091f9b1f027ef86c7e9253486378afb1da496de0.zip
More work on the DNS resolver; now just need the reply parser
-rw-r--r--dnsresolv.inc164
1 files changed, 163 insertions, 1 deletions
diff --git a/dnsresolv.inc b/dnsresolv.inc
index d8d1ff0a..e2cc8f1f 100644
--- a/dnsresolv.inc
+++ b/dnsresolv.inc
@@ -18,6 +18,12 @@
; this should be the normal thing for client-serving DNS servers.)
;
+DNS_PORT equ htons(53) ; Default DNS port
+DNS_MAX_PACKET equ 512 ; Defined by protocol
+; TFTP uses the range 49152-57343; avoid that range
+DNS_LOCAL_PORT equ htons(5353) ; All local DNS queries come from this port #
+DNS_MAX_SERVERS equ 4 ; Max no of DNS servers
+
section .text
;
@@ -27,7 +33,7 @@
; Assumes DS == ES. Change references to [bx] to [es:bx] to remove
; that assumption.
;
-mangle_dnsname:
+dns_mangle:
push ax
push bx
.nostart:
@@ -110,3 +116,159 @@ dns_skiplabel:
pop ax
ret
+; Actual resolver function
+; Points to a null-terminated string in DS:SI
+; and returns the name in EAX if it exists and can be found.
+; If EAX = 0 on exit, the lookup failed.
+
+ ; DNS header format
+ struc dnshdr
+.id: resw 1
+.flags: resw 1
+.qdcount: resw 1
+.ancount: resw 1
+.nscount: resw 1
+.arcount: resw 1
+ endstruc
+
+ ; DNS query
+ struc dnsquery
+.qtype: resw 1
+.qclass: resw 1
+ endstruc
+
+ ; DNS RR
+ struc dnsrr
+.type: resw 1
+.class: resw 1
+.ttl: resd 1
+.rdlength: resw 1
+.rdata: equ $
+ endstruc
+
+ section .bss
+ alignb 2, db 0
+DNSSendBuf resb DNS_MAX_PACKET
+DNSRecvBuf resb DNS_MAX_PACKET
+DNSServers resd DNS_MAX_SERVERS
+
+ section .data
+pxe_udp_write_pkt_dns:
+.status: dw 0 ; Status
+.sip: dd 0 ; Server IP
+.gip: dd 0 ; Gateway IP
+.lport: dw DNS_LOCAL_PORT ; Local port
+.rport: dw DNS_PORT ; Remote port
+.buffersize: dw 0 ; Size of packet
+.buffer: dw 0, DNSSendBuf ; seg:off of buffer
+
+pxe_udp_read_pkt_dns:
+.status: dw 0 ; Status
+.sip: dd 0 ; Source IP
+.dip: dd 0 ; Destination (our) IP
+.rport: dw DNS_PORT ; Remote port
+.lport: dw DNS_LOCAL_PORT ; Local port
+.buffersize: dw DNS_MAX_PACKET ; Max packet size
+.buffer: dw 0, DNSRecvBuf ; seg:off of buffer
+
+LastDNSServer dw DNSServers
+
+ section .text
+dns_resolv:
+ push di
+ push cx
+ push dx
+
+ ; Initialize...
+ mov eax,[MyIP]
+ mov [pxe_udp_read_pkt_dns.dip],eax
+
+ ; First, build query packet
+ mov di,DNSSendBuf+dnshdr.flags
+ inc word [di-2] ; New query ID
+ mov ax,htons(0100h) ; Recursion requested
+ stosw
+ mov ax,htons(1) ; One question
+ stosw
+ xor ax,ax ; No answers, NS or ARs
+ stosw
+ stosw
+ stosw
+
+ call dns_mangle ; Convert name to DNS labels
+ mov ax,htons(1)
+ stosw ; QTYPE = 1 = A
+ stosw ; QCLASS = 1 = IN
+
+ sub di,DNSSendBuf
+ mov [pxe_udp_write_pkt_dns.bufsize],di
+
+ ; Now, send it to the nameserver(s)
+ ; Outer loop: exponential backoff
+ ; Inner loop: scan the various DNS servers
+
+ mov dx,PKT_TIMEOUT
+ mov cx,PKT_RETRY
+.backoff:
+ mov di,[DNSServers]
+.servers:
+ cmp di,[LastDNSServer]
+ jae .nomoreservers
+
+ push di
+ push cx
+ push dx
+
+ mov eax,[di]
+
+ mov [pxe_udp_write_pkt_dns.status],0
+
+ mov [pxe_udp_write_pkt_dns.sip],eax
+ mov [pxe_udp_read_pkt_dns.sip],eax
+ xor eax,[MyIP]
+ and eax,[Netmask]
+ jz .nogw
+ mov eax,[Gateway]
+.nogw:
+ mov [pxe_udp_write_pkt_dns.gip],eax
+
+ mov di,pxe_udp_write_pkt_dns
+ mov bx,PXENV_UDP_WRITE
+ call pxenv
+ jc .failure
+ cmp word [pxe_udp_write_pkt.status],0
+ jne .failure
+
+ mov cx,[BIOS_timer]
+.waitrecv:
+ mov ax,[BIOS_timer]
+ sub ax,cx
+ cmp ax,dx
+ jae .timeout
+
+ mov [pxe_udp_read_pkt_dns.status],0
+ mov di,pxe_udp_read_pkt_dns
+ mov bx,PXENV_UDP_READ
+ call pxenv
+ and ax,ax
+ jnz .waitrecv
+
+ ; Got a packet, deal with it...
+ hlt
+
+.timeout:
+ pop dx
+ pop cx
+ pop di
+ add di,4
+ jmp .servers
+.nomoreservers:
+ add dx,dx ; Exponential backoff
+ loop .backoff
+
+ xor eax,eax ; Nothing...
+.done:
+ push dx
+ push cx
+ push di
+ ret