Lines Matching defs:dns
38 #include <gpxe/dns.h>
42 * DNS protocol
46 FEATURE ( FEATURE_PROTOCOL, "DNS", DHCP_EB_FEATURE_DNS, 1 );
48 /** The DNS server */
56 /** A DNS request */
82 * Mark DNS request as complete
84 * @v dns DNS request
87 static void dns_done ( struct dns_request *dns, int rc ) {
90 stop_timer ( &dns->timer );
93 xfer_nullify ( &dns->socket );
94 xfer_close ( &dns->socket, rc );
97 resolv_done ( &dns->resolv, &dns->sa, rc );
101 * Compare DNS reply name against the query name from the original request
103 * @v dns DNS request
104 * @v reply DNS reply
109 static int dns_name_cmp ( struct dns_request *dns,
112 const char *qname = dns->query.payload;
136 * Skip over a (possibly compressed) DNS name
138 * @v name DNS name
139 * @ret name Next DNS name
159 * @v dns DNS request
160 * @v reply DNS reply
161 * @ret rr DNS RR, or NULL if not found
163 static union dns_rr_info * dns_find_rr ( struct dns_request *dns,
176 cmp = dns_name_cmp ( dns, reply, p );
210 * Convert a standard NUL-terminated string to a DNS name
213 * @v buf Buffer in which to place DNS name
214 * @ret next Byte following constructed DNS name
216 * DNS names consist of "<length>element" pairs.
235 * Convert an uncompressed DNS name to a NUL-terminated string
237 * @v name DNS name
240 * Produce a printable version of a DNS name. Used only for debugging.
256 * Decompress a DNS name
258 * @v reply DNS replay
259 * @v name DNS name
260 * @v buf Buffer into which to decompress DNS name
261 * @ret next Byte following decompressed DNS name
283 * Send next packet in DNS request
285 * @v dns DNS request
287 static int dns_send_packet ( struct dns_request *dns ) {
292 dns->query.dns.id = htons ( ++qid );
294 DBGC ( dns, "DNS %p sending query ID %d\n", dns, qid );
297 start_timer ( &dns->timer );
300 qlen = ( ( ( void * ) dns->qinfo ) - ( ( void * ) &dns->query )
301 + sizeof ( dns->qinfo ) );
302 return xfer_deliver_raw ( &dns->socket, &dns->query, qlen );
306 * Handle DNS retransmission timer expiry
312 struct dns_request *dns =
316 dns_done ( dns, -ETIMEDOUT );
318 dns_send_packet ( dns );
326 * @v data DNS reply
327 * @v len Length of DNS reply
332 struct dns_request *dns =
337 unsigned int qtype = dns->qinfo->qtype;
341 DBGC ( dns, "DNS %p received underlength packet length %zd\n",
342 dns, len );
347 if ( reply->id != dns->query.dns.id ) {
348 DBGC ( dns, "DNS %p received unexpected reply ID %d "
349 "(wanted %d)\n", dns, ntohs ( reply->id ),
350 ntohs ( dns->query.dns.id ) );
354 DBGC ( dns, "DNS %p received reply ID %d\n", dns, ntohs ( reply->id ));
358 * or mark the DNS operation as complete by calling
361 stop_timer ( &dns->timer );
368 while ( ( rr_info = dns_find_rr ( dns, reply ) ) ) {
374 DBGC ( dns, "DNS %p found address %s\n",
375 dns, inet_ntoa ( rr_info->a.in_addr ) );
376 sin = ( struct sockaddr_in * ) &dns->sa;
381 dns_done ( dns, 0 );
387 DBGC ( dns, "DNS %p found CNAME\n", dns );
388 dns->qinfo = ( void * ) dns_decompress_name ( reply,
390 dns->query.payload );
391 dns->qinfo->qtype = htons ( DNS_TYPE_A );
392 dns->qinfo->qclass = htons ( DNS_CLASS_IN );
395 if ( ++dns->recursion > DNS_MAX_CNAME_RECURSION ) {
396 DBGC ( dns, "DNS %p recursion exceeded\n",
397 dns );
398 dns_done ( dns, -ELOOP );
404 DBGC ( dns, "DNS %p got unknown record type %d\n",
405 dns, ntohs ( rr_info->common.type ) );
419 DBGC ( dns, "DNS %p found no A record; trying CNAME\n", dns );
420 dns->qinfo->qtype = htons ( DNS_TYPE_CNAME );
421 dns_send_packet ( dns );
429 if ( dns->qinfo->qtype == htons ( DNS_TYPE_A ) ) {
430 dns_send_packet ( dns );
433 DBGC ( dns, "DNS %p found no CNAME record\n", dns );
434 dns_done ( dns, -ENXIO );
440 dns_done ( dns, -EINVAL );
452 struct dns_request *dns =
458 dns_done ( dns, rc );
461 /** DNS socket operations */
472 * Resolve name using DNS
481 struct dns_request *dns;
485 /* Fail immediately if no DNS servers */
487 DBG ( "DNS not attempting to resolve \"%s\": "
488 "no DNS servers\n", name );
500 /* Allocate DNS structure */
501 dns = zalloc ( sizeof ( *dns ) );
502 if ( ! dns ) {
506 resolv_init ( &dns->resolv, &null_resolv_ops, &dns->refcnt );
507 xfer_init ( &dns->socket, &dns_socket_operations, &dns->refcnt );
508 dns->timer.expired = dns_timer_expired;
509 memcpy ( &dns->sa, sa, sizeof ( dns->sa ) );
512 dns->query.dns.flags = htons ( DNS_FLAG_QUERY | DNS_FLAG_OPCODE_QUERY |
514 dns->query.dns.qdcount = htons ( 1 );
515 dns->qinfo = ( void * ) dns_make_name ( fqdn, dns->query.payload );
516 dns->qinfo->qtype = htons ( DNS_TYPE_A );
517 dns->qinfo->qclass = htons ( DNS_CLASS_IN );
520 if ( ( rc = xfer_open_socket ( &dns->socket, SOCK_DGRAM,
523 DBGC ( dns, "DNS %p could not open socket: %s\n",
524 dns, strerror ( rc ) );
528 /* Send first DNS packet */
529 dns_send_packet ( dns );
532 resolv_plug_plug ( &dns->resolv, resolv );
533 ref_put ( &dns->refcnt );
539 ref_put ( &dns->refcnt );
546 /** DNS name resolver */
548 .name = "DNS",
559 /** DNS server setting */
561 .name = "dns",
562 .description = "DNS server",
576 * Apply DNS settings
588 DBG ( "DNS using nameserver %s\n",
595 DBG ( "DNS local domain %s\n", localdomain );
600 /** DNS settings applicator */