Module Name: src Committed By: roy Date: Fri Sep 12 20:42:13 UTC 2014
Modified Files: src/distrib/common: Makefile.dhcpcd list.dhcpcd src/usr.sbin/sysinst: net.c Removed Files: src/distrib/common: 10-resolv.conf 99-print-sysinst Log Message: Use the 20-resolv.conf hook from dhcpcd rather than the minimal one. Extract configured information from resolv.conf and hostname instead of scraping the last dhcpcd script run. This will allow the use of DHCPv6 and IPv6RA DNS details in the future. To generate a diff of this commit: cvs rdiff -u -r1.1 -r0 src/distrib/common/10-resolv.conf \ src/distrib/common/99-print-sysinst cvs rdiff -u -r1.1 -r1.2 src/distrib/common/Makefile.dhcpcd cvs rdiff -u -r1.2 -r1.3 src/distrib/common/list.dhcpcd cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/sysinst/net.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/common/Makefile.dhcpcd diff -u src/distrib/common/Makefile.dhcpcd:1.1 src/distrib/common/Makefile.dhcpcd:1.2 --- src/distrib/common/Makefile.dhcpcd:1.1 Tue Apr 7 11:49:17 2009 +++ src/distrib/common/Makefile.dhcpcd Fri Sep 12 20:42:13 2014 @@ -1,8 +1,9 @@ -# $NetBSD: Makefile.dhcpcd,v 1.1 2009/04/07 11:49:17 joerg Exp $ +# $NetBSD: Makefile.dhcpcd,v 1.2 2014/09/12 20:42:13 roy Exp $ IMAGEDEPENDS+= \ ${DESTDIR}/etc/dhcpcd.conf \ ${DESTDIR}/libexec/dhcpcd-run-hooks \ + ${DESTDIR}/libexec/dhcpcd-hooks/20-resolv.conf \ ${DESTDIR}/libexec/dhcpcd-hooks/30-hostname LISTS+= ${DISTRIBDIR}/common/list.dhcpcd Index: src/distrib/common/list.dhcpcd diff -u src/distrib/common/list.dhcpcd:1.2 src/distrib/common/list.dhcpcd:1.3 --- src/distrib/common/list.dhcpcd:1.2 Tue May 31 06:19:11 2011 +++ src/distrib/common/list.dhcpcd Fri Sep 12 20:42:13 2014 @@ -1,4 +1,4 @@ -# $NetBSD: list.dhcpcd,v 1.2 2011/05/31 06:19:11 christos Exp $ +# $NetBSD: list.dhcpcd,v 1.3 2014/09/12 20:42:13 roy Exp $ # # list file (c.f. parselist.awk) for DHCP-enabled install media. # @@ -8,7 +8,5 @@ SPECIAL dhcpcd srcdir external/bsd/dhcpc COPY ${DESTDIR}/etc/dhcpcd.conf etc/dhcpcd.conf COPY ${DESTDIR}/libexec/dhcpcd-run-hooks libexec/dhcpcd-run-hooks 555 - -COPY ${NETBSDSRCDIR}/distrib/common/10-resolv.conf libexec/dhcpcd-hooks/10-resolv.conf +COPY ${DESTDIR}/libexec/dhcpcd-hooks/20-resolv.conf libexec/dhcpcd-hooks/20-resolv.conf COPY ${DESTDIR}/libexec/dhcpcd-hooks/30-hostname libexec/dhcpcd-hooks/30-hostname -COPY ${NETBSDSRCDIR}/distrib/common/99-print-sysinst libexec/dhcpcd-hooks/99-print-sysinst Index: src/usr.sbin/sysinst/net.c diff -u src/usr.sbin/sysinst/net.c:1.5 src/usr.sbin/sysinst/net.c:1.6 --- src/usr.sbin/sysinst/net.c:1.5 Fri Sep 12 20:20:25 2014 +++ src/usr.sbin/sysinst/net.c Fri Sep 12 20:42:13 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: net.c,v 1.5 2014/09/12 20:20:25 roy Exp $ */ +/* $NetBSD: net.c,v 1.6 2014/09/12 20:42:13 roy Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -104,7 +104,6 @@ static void write_etc_hosts(FILE *f); #define DHCPCD "/sbin/dhcpcd" #include <signal.h> static int config_dhcp(char *); -static void get_dhcp_value(char *, size_t, const char *); #ifdef INET6 static int is_v6kernel (void); @@ -533,7 +532,6 @@ config_network(void) int selected_net; int i; - char dhcp_host[STRSIZE]; #ifdef INET6 int v6config = 1; #endif @@ -645,6 +643,8 @@ again: /* try a dhcp configuration */ dhcp_config = config_dhcp(net_dev); if (dhcp_config) { + char *nl; + /* Get newly configured data off interface. */ get_ifinterface_info(); get_if6interface_info(); @@ -657,44 +657,62 @@ again: * 'route -n show' */ if (collect(T_OUTPUT, &textbuf, - "/sbin/route -n show | " - "while read dest gateway flags;" - " do [ \"$dest\" = default ] && {" - " echo $gateway; break; };" - " done" ) > 0) + "/sbin/route -n show | " + "while read dest gateway flags;" + " do [ \"$dest\" = default ] && {" + " echo \"$gateway\"; break; };" + " done" ) > 0) strlcpy(net_defroute, textbuf, sizeof net_defroute); free(textbuf); + if ((nl = strchr(net_namesvr, '\n'))) + *nl = '\0'; /* pull nameserver info out of /etc/resolv.conf */ if (collect(T_OUTPUT, &textbuf, - "cat /etc/resolv.conf 2>/dev/null |" - " while read keyword address rest;" - " do [ \"$keyword\" = nameserver " - " -a \"${address#*:}\" = " - "\"${address}\" ] && {" - " echo $address; break; };" - " done" ) > 0) + "cat /etc/resolv.conf 2>/dev/null |" + " while read keyword address rest;" + " do [ \"$keyword\" = nameserver ] &&" + " { echo \"$address\"; break; };" + " done" ) > 0) strlcpy(net_namesvr, textbuf, sizeof net_namesvr); free(textbuf); + if ((nl = strchr(net_namesvr, '\n'))) + *nl = '\0'; if (net_namesvr[0] != '\0') net_dhcpconf |= DHCPCONF_NAMESVR; - /* pull domainname out of leases file */ - get_dhcp_value(net_domain, sizeof(net_domain), - "domain-name"); + /* pull domain info out of /etc/resolv.conf */ + if (collect(T_OUTPUT, &textbuf, + "cat /etc/resolv.conf 2>/dev/null |" + " while read keyword domain rest;" + " do [ \"$keyword\" = domain ] &&" + " { echo \"$domain\"; break; };" + " done" ) > 0) + strlcpy(net_domain, textbuf, + sizeof net_domain); + free(textbuf); + if (net_domain[0] == '\0') { + /* pull domain info out of /etc/resolv.conf */ + if (collect(T_OUTPUT, &textbuf, + "cat /etc/resolv.conf 2>/dev/null |" + " while read keyword search rest;" + " do [ \"$keyword\" = search ] &&" + " { echo \"$search\"; break; };" + " done" ) > 0) + strlcpy(net_domain, textbuf, + sizeof net_domain); + free(textbuf); + } + if ((nl = strchr(net_domain, '\n'))) + *nl = '\0'; if (net_domain[0] != '\0') net_dhcpconf |= DHCPCONF_DOMAIN; - /* pull hostname out of leases file */ - dhcp_host[0] = 0; - get_dhcp_value(dhcp_host, sizeof(dhcp_host), - "host-name"); - if (dhcp_host[0] != '\0') { + if (gethostname(net_host, sizeof(net_host)) == 0 && + net_host[0] != 0) net_dhcpconf |= DHCPCONF_HOST; - strlcpy(net_host, dhcp_host, sizeof net_host); - } } } @@ -1229,37 +1247,3 @@ config_dhcp(char *inter) } return 0; } - -static void -get_dhcp_value(char *targ, size_t l, const char *var) -{ - static const char *lease_data = "/tmp/dhcpcd-lease"; - FILE *fp; - char *line; - size_t len, var_len; - - if ((fp = fopen(lease_data, "r")) == NULL) { - warn("Could not open %s", lease_data); - *targ = '\0'; - return; - } - - var_len = strlen(var); - - while ((line = fgetln(fp, &len)) != NULL) { - if (line[len - 1] == '\n') - --len; - if (len <= var_len) - continue; - if (memcmp(line, var, var_len)) - continue; - if (line[var_len] != '=') - continue; - line += var_len + 1; - len -= var_len + 1; - strlcpy(targ, line, l > len ? len + 1: l); - break; - } - - fclose(fp); -}