Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Use the 20-resolv.conf hook from dhcpcd rather than the mini...
details: https://anonhg.NetBSD.org/src/rev/449bdb850938
branches: trunk
changeset: 332240:449bdb850938
user: roy <roy%NetBSD.org@localhost>
date: Fri Sep 12 20:42:13 2014 +0000
description:
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.
diffstat:
distrib/common/10-resolv.conf | 22 --------
distrib/common/99-print-sysinst | 11 ----
distrib/common/Makefile.dhcpcd | 3 +-
distrib/common/list.dhcpcd | 6 +-
usr.sbin/sysinst/net.c | 102 ++++++++++++++++-----------------------
5 files changed, 47 insertions(+), 97 deletions(-)
diffs (230 lines):
diff -r 61e96f4a6dfc -r 449bdb850938 distrib/common/10-resolv.conf
--- a/distrib/common/10-resolv.conf Fri Sep 12 20:20:25 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-# Minimal version using shell builtins.
-
-make_resolv_conf()
-{
- if [ -z "${new_domain_name_servers}" -a \
- -z "${new_domain_name}" -a \
- -z "${new_domain_search}" ]; then
- return 0
- fi
- if [ -n "${new_domain_search}" ]; then
- echo "search ${new_domain_search}" >> /etc/resolv.conf
- elif [ -n "${new_domain_name}" ]; then
- echo "search ${new_domain_name}" >> /etc/resolv.conf
- fi
- for x in ${new_domain_name_servers}; do
- echo "nameserver ${x}" >> /etc/resolv.conf
- done
-}
-
-case "${reason}" in
-BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) make_resolv_conf;;
-esac
diff -r 61e96f4a6dfc -r 449bdb850938 distrib/common/99-print-sysinst
--- a/distrib/common/99-print-sysinst Fri Sep 12 20:20:25 2014 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-# $NetBSD: 99-print-sysinst,v 1.1 2009/04/07 11:49:17 joerg Exp $
-
-case "${reason}" in
-BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)
- cat > /tmp/dhcpcd-lease << EOF
-host-name=${new_host_name}
-domain-name=${new_domain_name}
-EOF
- set > /tmp/dhcpcd-lease-all
- ;;
-esac
diff -r 61e96f4a6dfc -r 449bdb850938 distrib/common/Makefile.dhcpcd
--- a/distrib/common/Makefile.dhcpcd Fri Sep 12 20:20:25 2014 +0000
+++ b/distrib/common/Makefile.dhcpcd Fri Sep 12 20:42:13 2014 +0000
@@ -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
diff -r 61e96f4a6dfc -r 449bdb850938 distrib/common/list.dhcpcd
--- a/distrib/common/list.dhcpcd Fri Sep 12 20:20:25 2014 +0000
+++ b/distrib/common/list.dhcpcd Fri Sep 12 20:42:13 2014 +0000
@@ -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 @@
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
diff -r 61e96f4a6dfc -r 449bdb850938 usr.sbin/sysinst/net.c
--- a/usr.sbin/sysinst/net.c Fri Sep 12 20:20:25 2014 +0000
+++ b/usr.sbin/sysinst/net.c Fri Sep 12 20:42:13 2014 +0000
@@ -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 @@
#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 @@
int selected_net;
int i;
- char dhcp_host[STRSIZE];
#ifdef INET6
int v6config = 1;
#endif
@@ -645,6 +643,8 @@
/* 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 @@
* '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 @@
}
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);
-}
Home |
Main Index |
Thread Index |
Old Index