Переглянути джерело

Use struct sockaddr rather than struct sockaddr_tcpip

Tidy up code
tags/v0.9.3
Michael Brown 18 роки тому
джерело
коміт
99e58865c7
2 змінених файлів з 23 додано та 14 видалено
  1. 11
    5
      src/include/gpxe/dns.h
  2. 12
    9
      src/net/udp/dns.c

+ 11
- 5
src/include/gpxe/dns.h Переглянути файл

@@ -89,21 +89,27 @@ union dns_rr_info {
89 89
 	struct dns_rr_info_cname cname;
90 90
 };
91 91
 
92
+/** A DNS request */
92 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 98
 	struct dns_query query;
99
+	/** Length of current query packet */
98 100
 	struct dns_query_info *qinfo;
99
-
101
+	/** Recursion counter */
100 102
 	unsigned int recursion;
101 103
 
104
+	/** Asynchronous operation */
105
+	struct async async;
106
+	/** UDP connection */
102 107
 	struct udp_connection udp;
108
+	/** Retry timer */
103 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 113
 			struct async *parent );
108 114
 
109 115
 #endif /* _GPXE_DNS_H */

+ 12
- 9
src/net/udp/dns.c Переглянути файл

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

Завантаження…
Відмінити
Зберегти