From owner-freebsd-current@FreeBSD.ORG Fri Dec 14 09:47:55 2007 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 43E4416A419 for ; Fri, 14 Dec 2007 09:47:55 +0000 (UTC) (envelope-from rea-fbsd@codelabs.ru) Received: from pobox.codelabs.ru (pobox.codelabs.ru [144.206.177.45]) by mx1.freebsd.org (Postfix) with ESMTP id F007013C4DB for ; Fri, 14 Dec 2007 09:47:54 +0000 (UTC) (envelope-from rea-fbsd@codelabs.ru) DomainKey-Signature: a=rsa-sha1; q=dns; c=simple; s=one; d=codelabs.ru; h=Received:Date:From:To:Message-ID:MIME-Version:Content-Type:Content-Disposition:Sender:X-Spam-Status:Subject; b=eXbsXuhWU+Hq47NPDemaZFDSwWJ5VXpIb4dj5gB3w4zUO5dAN8wSk3RVu8jx2HRSbvbnV4D2+r8/eOmcSzUh0+5dm4pA0ybnJHjbmQ0MYaKj4m0AAX08qEVTaUo97YqXqo3XVj/o5WLf3zKIx1ONI0aNJKLekZkmXA5ruO+CsWk=; Received: from void.codelabs.ru (void.codelabs.ru [144.206.177.25]) by pobox.codelabs.ru with esmtpsa (TLSv1:AES256-SHA:256) id 1J3797-00076N-6V for freebsd-current@freebsd.org; Fri, 14 Dec 2007 12:47:53 +0300 Date: Fri, 14 Dec 2007 12:47:51 +0300 From: Eygene Ryabinkin To: freebsd-current@freebsd.org Message-ID: <7ExUpek150AdEdP4WR1b6w@lz+EvuNSgXKgs9kqjMxQNA> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Sender: rea-fbsd@codelabs.ru X-Spam-Status: No, score=-3.2 required=4.0 tests=ALL_TRUSTED,AWL,BAYES_00 Subject: [RFC] Automated generation of /etc/resolv.conf from the rc.d script X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Dec 2007 09:47:55 -0000 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