Try to qualify relative names in the DNS resolver using the DHCP Domain Name. For example: DHCP Domain Name: etherboot.org (Relative) Name: www yields: www.etherboot.org Names that are already qualified are not affected. --- src/include/gpxe/settings.h | 1 + src/net/udp/dns.c | 49 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletions(-) diff --git a/src/include/gpxe/settings.h b/src/include/gpxe/settings.h index 37c01b0..7505150 100644 --- a/src/include/gpxe/settings.h +++ b/src/include/gpxe/settings.h @@ -215,6 +215,7 @@ extern struct setting ip_setting __setting; extern struct setting netmask_setting __setting; extern struct setting gateway_setting __setting; extern struct setting dns_setting __setting; +extern struct setting domain_setting __setting; extern struct setting hostname_setting __setting; extern struct setting filename_setting __setting; extern struct setting root_path_setting __setting; diff --git a/src/net/udp/dns.c b/src/net/udp/dns.c index 1bcdbc7..de7ac5c 100644 --- a/src/net/udp/dns.c +++ b/src/net/udp/dns.c @@ -22,6 +22,7 @@ #include <stdint.h> #include <stdlib.h> #include <string.h> +#include <stdio.h> #include <errno.h> #include <byteswap.h> #include <gpxe/refcnt.h> @@ -180,6 +181,36 @@ static union dns_rr_info * dns_find_rr ( struct dns_request *dns, } /** + * Append DHCP domain name if available and name is not fully qualified + * + * @v string Name as a NUL-terminated string + * @ret fqdn Fully-qualified domain name, malloc''d copy + * + * The caller must free fqdn which is allocated even if the name is already + * fully qualified. + */ +static char * dns_qualify_name ( const char *string ) { + char *fqdn; + char domain[256]; /* local domain */ + + /* Already fully-qualified? */ + if ( strchr ( string, ''.'' ) ) + goto treat_as_fqdn; + + /* Get local domain DHCP option */ + if ( fetch_string_setting ( NULL, &domain_setting, + domain, sizeof domain ) <= 0 ) + goto treat_as_fqdn; + + /* Append local domain to name */ + asprintf ( &fqdn, "%s.%s", string, domain ); + return fqdn; + +treat_as_fqdn: + return strdup ( string ); +} + +/** * Convert a standard NUL-terminated string to a DNS name * * @v string Name as a NUL-terminated string @@ -452,6 +483,7 @@ static struct xfer_interface_operations dns_socket_operations = { static int dns_resolv ( struct resolv_interface *resolv, const char *name, struct sockaddr *sa ) { struct dns_request *dns; + char *fqdn = NULL; int rc; /* Fail immediately if no DNS servers */ @@ -461,6 +493,11 @@ static int dns_resolv ( struct resolv_interface *resolv, return -ENXIO; } + /* Ensure fully-qualified domain name if DHCP option was given */ + fqdn = dns_qualify_name ( name ); + if ( ! fqdn ) + return -ENOMEM; + /* Allocate DNS structure */ dns = zalloc ( sizeof ( *dns ) ); if ( ! dns ) @@ -474,7 +511,7 @@ static int dns_resolv ( struct resolv_interface *resolv, dns->query.dns.flags = htons ( DNS_FLAG_QUERY | DNS_FLAG_OPCODE_QUERY | DNS_FLAG_RD ); dns->query.dns.qdcount = htons ( 1 ); - dns->qinfo = ( void * ) dns_make_name ( name, dns->query.payload ); + dns->qinfo = ( void * ) dns_make_name ( fqdn, dns->query.payload ); dns->qinfo->qtype = htons ( DNS_TYPE_A ); dns->qinfo->qclass = htons ( DNS_CLASS_IN ); @@ -493,10 +530,12 @@ static int dns_resolv ( struct resolv_interface *resolv, /* Attach parent interface, mortalise self, and return */ resolv_plug_plug ( &dns->resolv, resolv ); ref_put ( &dns->refcnt ); + free ( fqdn ); return 0; err: ref_put ( &dns->refcnt ); + free ( fqdn ); return rc; } @@ -521,6 +560,14 @@ struct setting dns_setting __setting = { .type = &setting_type_ipv4, }; +/** Domain name setting */ +struct setting domain_setting __setting = { + .name = "domain", + .description = "Local domain", + .tag = DHCP_DOMAIN_NAME, + .type = &setting_type_string, +}; + /** * Apply nameserver setting * -- 1.5.6.5 ------=_Part_18453_5249765.1227777980812 Content-Type: text/x-diff; name=domain.diff Content-Transfer-Encoding: base64 X-Attachment-Id: f_fo17zmhd0 Content-Disposition: attachment; filename=domain.diff RnJvbSBjNzQ4OWI4NWYxYjRjMjVkOGIzOTM4OTg5MTI2OGQ2YWVjODZhYTU0IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBTdGVmYW4gSGFqbm9jemkgPHN0ZWZhbmhhQ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ICZzZXR0aW5nX3R5cGVfc3RyaW5nLAorfTsKKwogLyoqCiAgKiBBcHBs eSBuYW1lc2VydmVyIHNldHRpbmcKICAqCi0tIAoxLjUuNi41Cgo------=_Part_18453_5249765.1227777980812--