Date: Fri, 14 Dec 2007 12:47:51 +0300 From: Eygene Ryabinkin <rea-fbsd@codelabs.ru> To: freebsd-current@freebsd.org Subject: [RFC] Automated generation of /etc/resolv.conf from the rc.d script Message-ID: <7ExUpek150AdEdP4WR1b6w@lz%2BEvuNSgXKgs9kqjMxQNA>
next in thread | raw e-mail | index | archive | help
Good day. I happened to use my notebook in the variety of the networks and some of them have no DHCP servers. So I had made my network settings in the /etc/rc.conf to be conditional. But there is one bit that I am missing with the current /etc/rc.d scripts: automated construction of /etc/resolv.conf basing on the variables from /etc/rc.conf. I know that just now I can achieve my needs by doing something like ----- rm -f /etc/resolv.conf kenv dhcp.domain-name-servers="IP1,IP2,IP3" kenv dhcp.domain-name="domain" ----- but the use of variables in /etc/rc.conf sounds a bit better to me. After all, dhcp.* values belong to the DHCP data, so playing with kenv looks like a hack. Below is the patch that adds two variables that are recognized by /etc/rc.d/resolv: resolv_domain and resolv_nameservers. If any of two has some value, then /etc/resolv.conf will be built from scratch. Values from kenv take higher precedence, so the default behaviour is not changed. Can this modification hit the tree, or it is completely unneeded, or it should be reworked? Any comments? The patch follows. ----- --- resolv.orig 2007-12-13 11:57:17.000000000 +0300 +++ resolv 2007-12-13 11:57:17.000000000 +0300 @@ -37,6 +37,23 @@ load_rc_config $name +# Helper that echoes the contents of the resolv.conf to the stdout. +# Arguments: +# 1. domain name, +# 2. list of name servers separated by ','. +# Either argument can be empty. If so, it won't be included to the output. + +build_resolv () { + if [ -n "$1" ]; then + echo domain "$1" > /etc/resolv.conf + fi + + set -- "$2" + for ns in `IFS=','; echo $*`; do + echo nameserver $ns >> /etc/resolv.conf; + done +} + # if the info is available via dhcp/kenv # build the resolv.conf # @@ -44,13 +61,13 @@ -n "`/bin/kenv dhcp.domain-name-servers 2> /dev/null`" ]; then > /etc/resolv.conf - if [ -n "`/bin/kenv dhcp.domain-name 2> /dev/null`" ]; then - echo domain `/bin/kenv dhcp.domain-name` > /etc/resolv.conf - fi + build_resolv \ + "`/bin/kenv dhcp.domain-name 2> /dev/null`" \ + "`/bin/kenv dhcp.domain-name-servers`" +elif [ -n "${resolv_domain}" -o -n "${resolv_nameservers}" ]; then + > /etc/resolv.conf - set -- `/bin/kenv dhcp.domain-name-servers` - for ns in `IFS=','; echo $*`; do - echo nameserver $ns >> /etc/resolv.conf; - done + build_resolv \ + "${resolv_domain}" "${resolv_nameservers}" fi ----- -- Eygene
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7ExUpek150AdEdP4WR1b6w>