Browse Source

Use struct sockaddr rather than struct sockaddr_tcpip

Tidy up code
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
99e58865c7
2 changed files with 23 additions and 14 deletions
  1. 11
    5
      src/include/gpxe/dns.h
  2. 12
    9
      src/net/udp/dns.c

+ 11
- 5
src/include/gpxe/dns.h View File

89
 	struct dns_rr_info_cname cname;
89
 	struct dns_rr_info_cname cname;
90
 };
90
 };
91
 
91
 
92
+/** A DNS request */
92
 struct dns_request {
93
 struct dns_request {
94
+	/** Socket address to fill in with resolved address */
95
+	struct sockaddr *sa;
93
 
96
 
94
-	struct sockaddr_tcpip *st;
95
-
96
-	struct async async;
97
+	/** Current query packet */
97
 	struct dns_query query;
98
 	struct dns_query query;
99
+	/** Length of current query packet */
98
 	struct dns_query_info *qinfo;
100
 	struct dns_query_info *qinfo;
99
-
101
+	/** Recursion counter */
100
 	unsigned int recursion;
102
 	unsigned int recursion;
101
 
103
 
104
+	/** Asynchronous operation */
105
+	struct async async;
106
+	/** UDP connection */
102
 	struct udp_connection udp;
107
 	struct udp_connection udp;
108
+	/** Retry timer */
103
 	struct retry_timer timer;
109
 	struct retry_timer timer;
104
 };
110
 };
105
 
111
 
106
-extern int dns_resolv ( const char *name, struct sockaddr_tcpip *st,
112
+extern int dns_resolv ( const char *name, struct sockaddr *sa,
107
 			struct async *parent );
113
 			struct async *parent );
108
 
114
 
109
 #endif /* _GPXE_DNS_H */
115
 #endif /* _GPXE_DNS_H */

+ 12
- 9
src/net/udp/dns.c View File

308
 			/* Found the target A record */
308
 			/* Found the target A record */
309
 			DBGC ( dns, "DNS %p found address %s\n",
309
 			DBGC ( dns, "DNS %p found address %s\n",
310
 			       dns, inet_ntoa ( rr_info->a.in_addr ) );
310
 			       dns, inet_ntoa ( rr_info->a.in_addr ) );
311
-			sin = ( struct sockaddr_in * ) dns->st;
311
+			sin = ( struct sockaddr_in * ) dns->sa;
312
 			sin->sin_family = AF_INET;
312
 			sin->sin_family = AF_INET;
313
 			sin->sin_addr = rr_info->a.in_addr;
313
 			sin->sin_addr = rr_info->a.in_addr;
314
 
314
 
403
  * Resolve name using DNS
403
  * Resolve name using DNS
404
  *
404
  *
405
  */
405
  */
406
-int dns_resolv ( const char *name, struct sockaddr_tcpip *st,
406
+int dns_resolv ( const char *name, struct sockaddr *sa,
407
 		 struct async *parent ) {
407
 		 struct async *parent ) {
408
 	struct dns_request *dns;
408
 	struct dns_request *dns;
409
+	struct dhcp_option *option;
409
 	union {
410
 	union {
410
 		struct sockaddr_tcpip st;
411
 		struct sockaddr_tcpip st;
411
 		struct sockaddr_in sin;
412
 		struct sockaddr_in sin;
412
 	} nameserver;
413
 	} nameserver;
414
+
413
 	int rc;
415
 	int rc;
414
 
416
 
415
 	/* Allocate DNS structure */
417
 	/* Allocate DNS structure */
419
 		goto err;
421
 		goto err;
420
 	}
422
 	}
421
 	memset ( dns, 0, sizeof ( *dns ) );
423
 	memset ( dns, 0, sizeof ( *dns ) );
422
-	dns->st = st;
424
+	dns->sa = sa;
423
 	dns->timer.expired = dns_timer_expired;
425
 	dns->timer.expired = dns_timer_expired;
424
 	dns->udp.udp_op = &dns_udp_operations;
426
 	dns->udp.udp_op = &dns_udp_operations;
427
+	async_init ( &dns->async, &dns_async_operations, parent );
425
 
428
 
426
 	/* Create query */
429
 	/* Create query */
427
 	dns->query.dns.flags = htons ( DNS_FLAG_QUERY | DNS_FLAG_OPCODE_QUERY |
430
 	dns->query.dns.flags = htons ( DNS_FLAG_QUERY | DNS_FLAG_OPCODE_QUERY |
431
 	dns->qinfo->qtype = htons ( DNS_TYPE_A );
434
 	dns->qinfo->qtype = htons ( DNS_TYPE_A );
432
 	dns->qinfo->qclass = htons ( DNS_CLASS_IN );
435
 	dns->qinfo->qclass = htons ( DNS_CLASS_IN );
433
 
436
 
434
-	/* Open UDP connection */
437
+	/* Identify nameserver */
435
 	memset ( &nameserver, 0, sizeof ( nameserver ) );
438
 	memset ( &nameserver, 0, sizeof ( nameserver ) );
436
 	nameserver.sin.sin_family = AF_INET;
439
 	nameserver.sin.sin_family = AF_INET;
437
 	nameserver.sin.sin_port = htons ( DNS_PORT );
440
 	nameserver.sin.sin_port = htons ( DNS_PORT );
438
-#warning "DHCP-DNS hack"
439
-	struct dhcp_option *option =
440
-		find_global_dhcp_option ( DHCP_DNS_SERVERS );
441
-	if ( ! option ) {
441
+	if ( ! ( option = find_global_dhcp_option ( DHCP_DNS_SERVERS ) ) ) {
442
 		DBGC ( dns, "DNS %p no name servers\n", dns );
442
 		DBGC ( dns, "DNS %p no name servers\n", dns );
443
 		rc = -ENXIO;
443
 		rc = -ENXIO;
444
 		goto err;
444
 		goto err;
445
 	}
445
 	}
446
 	dhcp_ipv4_option ( option, &nameserver.sin.sin_addr );
446
 	dhcp_ipv4_option ( option, &nameserver.sin.sin_addr );
447
+
448
+	/* Open UDP connection */
447
 	DBGC ( dns, "DNS %p using nameserver %s\n", dns, 
449
 	DBGC ( dns, "DNS %p using nameserver %s\n", dns, 
448
 	       inet_ntoa ( nameserver.sin.sin_addr ) );
450
 	       inet_ntoa ( nameserver.sin.sin_addr ) );
449
 	udp_connect ( &dns->udp, &nameserver.st );
451
 	udp_connect ( &dns->udp, &nameserver.st );
450
 	if ( ( rc = udp_open ( &dns->udp, 0 ) ) != 0 )
452
 	if ( ( rc = udp_open ( &dns->udp, 0 ) ) != 0 )
451
 		goto err;
453
 		goto err;
452
 
454
 
455
+	/* Send first DNS packet */
453
 	dns_send_packet ( dns );
456
 	dns_send_packet ( dns );
454
 
457
 
455
-	async_init ( &dns->async, &dns_async_operations, parent );
456
 	return 0;	
458
 	return 0;	
457
 
459
 
458
  err:
460
  err:
459
 	DBGC ( dns, "DNS %p could not create request: %s\n", 
461
 	DBGC ( dns, "DNS %p could not create request: %s\n", 
460
 	       dns, strerror ( rc ) );
462
 	       dns, strerror ( rc ) );
463
+	async_uninit ( &dns->async );
461
 	free ( dns );
464
 	free ( dns );
462
 	return rc;
465
 	return rc;
463
 }
466
 }

Loading…
Cancel
Save