|
@@ -26,7 +26,6 @@
|
26
|
26
|
#include <byteswap.h>
|
27
|
27
|
#include <gpxe/async.h>
|
28
|
28
|
#include <gpxe/udp.h>
|
29
|
|
-#include <gpxe/dhcp.h>
|
30
|
29
|
#include <gpxe/dns.h>
|
31
|
30
|
|
32
|
31
|
/** @file
|
|
@@ -35,6 +34,9 @@
|
35
|
34
|
*
|
36
|
35
|
*/
|
37
|
36
|
|
|
37
|
+/* The DNS server */
|
|
38
|
+struct in_addr nameserver = { INADDR_NONE };
|
|
39
|
+
|
38
|
40
|
/**
|
39
|
41
|
* Compare DNS reply name against the query name from the original request
|
40
|
42
|
*
|
|
@@ -51,7 +53,7 @@ static int dns_name_cmp ( struct dns_request *dns, struct dns_header *reply,
|
51
|
53
|
|
52
|
54
|
while ( 1 ) {
|
53
|
55
|
/* Obtain next section of rname */
|
54
|
|
- while ( ( *rname ) & 0xc0 ) {
|
|
56
|
+ while ( ( *rname ) & 0xc0 ) {
|
55
|
57
|
rname = ( ( ( char * ) reply ) +
|
56
|
58
|
( ntohs( *((uint16_t *)rname) ) & ~0xc000 ));
|
57
|
59
|
}
|
|
@@ -402,16 +404,18 @@ static struct async_operations dns_async_operations = {
|
402
|
404
|
/**
|
403
|
405
|
* Resolve name using DNS
|
404
|
406
|
*
|
|
407
|
+ * @v name Host name to resolve
|
|
408
|
+ * @v sa Socket address to fill in
|
|
409
|
+ * @v parent Parent asynchronous operation
|
|
410
|
+ * @ret rc Return status code
|
405
|
411
|
*/
|
406
|
412
|
int dns_resolv ( const char *name, struct sockaddr *sa,
|
407
|
413
|
struct async *parent ) {
|
408
|
414
|
struct dns_request *dns;
|
409
|
|
- struct dhcp_option *option;
|
410
|
415
|
union {
|
411
|
416
|
struct sockaddr_tcpip st;
|
412
|
417
|
struct sockaddr_in sin;
|
413
|
|
- } nameserver;
|
414
|
|
-
|
|
418
|
+ } server;
|
415
|
419
|
int rc;
|
416
|
420
|
|
417
|
421
|
/* Allocate DNS structure */
|
|
@@ -435,20 +439,20 @@ int dns_resolv ( const char *name, struct sockaddr *sa,
|
435
|
439
|
dns->qinfo->qclass = htons ( DNS_CLASS_IN );
|
436
|
440
|
|
437
|
441
|
/* Identify nameserver */
|
438
|
|
- memset ( &nameserver, 0, sizeof ( nameserver ) );
|
439
|
|
- nameserver.sin.sin_family = AF_INET;
|
440
|
|
- nameserver.sin.sin_port = htons ( DNS_PORT );
|
441
|
|
- if ( ! ( option = find_global_dhcp_option ( DHCP_DNS_SERVERS ) ) ) {
|
|
442
|
+ memset ( &server, 0, sizeof ( server ) );
|
|
443
|
+ server.sin.sin_family = AF_INET;
|
|
444
|
+ server.sin.sin_port = htons ( DNS_PORT );
|
|
445
|
+ server.sin.sin_addr = nameserver;
|
|
446
|
+ if ( server.sin.sin_addr.s_addr == INADDR_NONE ) {
|
442
|
447
|
DBGC ( dns, "DNS %p no name servers\n", dns );
|
443
|
448
|
rc = -ENXIO;
|
444
|
449
|
goto err;
|
445
|
450
|
}
|
446
|
|
- dhcp_ipv4_option ( option, &nameserver.sin.sin_addr );
|
447
|
451
|
|
448
|
452
|
/* Open UDP connection */
|
449
|
453
|
DBGC ( dns, "DNS %p using nameserver %s\n", dns,
|
450
|
|
- inet_ntoa ( nameserver.sin.sin_addr ) );
|
451
|
|
- udp_connect ( &dns->udp, &nameserver.st );
|
|
454
|
+ inet_ntoa ( server.sin.sin_addr ) );
|
|
455
|
+ udp_connect ( &dns->udp, &server.st );
|
452
|
456
|
if ( ( rc = udp_open ( &dns->udp, 0 ) ) != 0 )
|
453
|
457
|
goto err;
|
454
|
458
|
|