From owner-freebsd-bugs Thu May 18 13:40:17 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id C991D37B992 for ; Thu, 18 May 2000 13:40:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id NAA65448; Thu, 18 May 2000 13:40:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Date: Thu, 18 May 2000 13:40:03 -0700 (PDT) Message-Id: <200005182040.NAA65448@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Brooks Davis Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname. Reply-To: Brooks Davis Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR conf/18583; it has been noted by GNATS. From: Brooks Davis To: "David O'Brien" Cc: Brooks Davis , Sheldon Hearn , FreeBSD-gnats-submit@FreeBSD.org Subject: Re: conf/18583: [PATCH] DHCP should be able to override hostname. Date: Thu, 18 May 2000 13:31:41 -0700 On Tue, May 16, 2000 at 02:19:03PM -0700, David O'Brien wrote: > On Tue, May 16, 2000 at 02:06:44PM -0700, Brooks Davis wrote: > > I'll try a re-write of the dhclient-script with an eye towards that > > degree of flexability under a more friendly license. > > Cool. Here is is. It looks similar to the on in the other PR because I took some ideas from it, but it's a new rewrite. It seems to work in general and it has been running on my laptop since last night. It does want to /etc/defaults/rc.conf and /etc/rc.network portions of my previous patch with it, but I believe it will work without them. -- Brooks -- Any statement of the form "X is the one, true Y" is FALSE. #!/bin/sh ############################################################################# # Copyright (c) 2000 Brooks Davis # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # ############################################################################# # Many of the ideas behind this file are based on a version submitted as # pr bin/15342 by Patrick Bihan-Faou, patrick@mindstep.com. The actual # file is a # complete rewrite derived from FreeBSD's v1.9. This should # be almost identical in function to v1.9 except for the support for # the default_hostname variable to allow proper disconnected operation. ############################################################################# # Use logger(1) if it's available # if [ -x /usr/bin/logger ]; then LOGGER="/usr/bin/logger -s -p user.notice -t dhclient" else LOGGER=echo fi # These functions are to be overridden as necessicary in the optional # /etc/dhclient-enter-hooks file. The pre_state_*_hook functions are # called before the (non-overable) if_state_* functions which are # followed by calls to the post_state_*_functions. # pre_state_ARPCHECK_hook() { } pre_state_APRSEND_hook() { } pre_state_BOUND_hook() { } pre_state_EXPIRE_hook() { } pre_state_FAIL_hook() { } pre_state_MEDIUM_hook() { } pre_state_PREINIT_hook() { } pre_state_REBIND_hook() { } pre_state_REBOOT_hook() { } pre_state_RENEW_hook() { } pre_state_TIMEOUT_hook() { } post_state_ARPCHECK_hook() { } post_state_APRSEND_hook() { } post_state_BOUND_hook() { } post_state_EXPIRE_hook() { } post_state_FAIL_hook() { } post_state_MEDIUM_hook() { } post_state_PREINIT_hook() { } post_state_REBIND_hook() { } post_state_REBOOT_hook() { } post_state_RENEW_hook() { } post_state_TIMEOUT_hook() { } # The make_resolv_conf() function may be overridden as well. # make_resolv_conf() { echo search $new_domain_name >/etc/resolv.conf for nameserver in $new_domain_name_servers; do echo nameserver $nameserver >>/etc/resolv.conf done } # This must be used on exit to allow any exit hooks to be called. # exit_with_hooks() { exit_status=$1 if [ -x /etc/dhclient-exit-hooks ]; then . /etc/dhclient-exit-hooks fi exit $exit_status } # This function does the overriding of functions. If the local script # wishes to, it may abort processing of this state. The local script # must set exit_status to a nonzero value to do so. # enter_with_hooks() { if [ -x /etc/dhclient-enter-hooks ]; then exit_status=0 . /etc/dhclient-enter-hooks # allow the local script to abort processing of this state # local script must set exit_status variable to nonzero. if [ $exit_status -ne 0 ]; then exit_with_hooks $exit_status fi fi } # This function prints any important changes in network config. # print_net_changes() { if [ -n "$new_host_name" ]; then $LOGGER "New Hostname: $new_host_name" fi if [ -n "$new_ip_address" ]; then $LOGGER "New IP Address ($interface): $new_ip_address" fi if [ -n "$new_subnet_mask" ]; then $LOGGER "New Subnet Mask ($interface): $new_subnet_mask" fi if [ -n "$new_broadcast_address" ]; then $LOGGER "New Broadcast Address ($interface): $new_broadcast_address" fi if [ -n "$new_routers" ]; then $LOGGER "New Routers: $new_routers" fi if [ -n "$new_static_routes" ]; then $LOGGER "New Static Routes: $new_static_routes" fi } # Utility functions. # add_route() { route add $1 $2 > /dev/null 2>&1 } delete_route() { route delete $1 $2 > /dev/null 2>&1 } add_routers() { eval routers="\$${1}_routers" for router in $routers; do add_route default $router done } delete_routers() { eval routers="\$${1}_routers" for router in $routers; do delete_route default $router done } add_static_routes() { eval static_routes="\$${1}_static_routes" set "$static_routes" while [ $# -gt 1 ]; do add_route $1 $2 shift; shift done } delete_static_routes() { eval static_routes="\$${1}_static_routes" set "$static_routes" while [ $# -gt 1 ]; do delete_route $1 $2 shift; shift done } config_ip_address() { eval address="\$${1}_ip_address" eval netmask="\$${1}_subnet_mask" eval broadcast="\$${1}_broadcast_address" if [ -n "$address" ]; then ifconfig $interface inet $address netmask $netmask \ broadcast $broadcast $medium fi } delete_ip_address() { eval address="\$${1}_ip_address" if [ -n "$address" ]; then ifconfig inet delete $address $medium fi } clear_arp_table() { arp -d -a } get_rc_conf_var() { ( if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi eval echo \$${1} ) } set_hostname() { current_hostname=`hostname` if [ "$current_hostname" = "`get_rc_conf_var default_hostname`" ] || \ [ "$current_hostname" = "$old_host_name" ]; then if [ "$new_host_name" != "$old_host_name" ] && \ [ -n "$new_host_name" ]; then hostname $new_host_name fi fi } config_alias() { if [ -n "$alias_ip_address" ]; then ifconfig $interface inet $alias_ip_address \ netmask $alias_subnet_mask fi } delete_alias() { if [ -n "$alias_ip_address" ]; then delete_ip_address alias delete_route $alias_ip_address 127.0.0.1 fi } test_lease() { if [ -n "$new_routers" ]; then config_ip_address new set $new_routers if ping -q -c $1; then rval=0 else rval=1 fi delete_ip_address new else rval=1 fi return $rval } config_new() { config_ip_address new if [ "$alias_ip_address" != "$new_ip_address" ]; then config_alias fi add_routers new add_static_routes new make_resolv_conf } delete_old() { delete_ip_address old delete_routers old delete_static_routes old clear_arp_table } # in_state_* functions. These should not be overridden in the hooks files. # in_state_ARPCHECK() { exit_status=0 } in_state_APRSEND() { exit_status=0; } in_state_BOUND() { set_hostname if [ "$alias_ip_address" != "$old_ip_address" ]; then delete_alias fi if [ -n "$old_ip_address" ] && \ [ "$old_ip_address" != "$new_ip_address" ]; then delete_old fi config_new exit_status=0 } in_state_EXPIRE() { if_state_FAIL } in_state_FAIL() { delete_alias delete_old config_alias exit_status=0 } in_state_MEDIUM() { ifconfig $interface $medium ifconfig $interface inet delete 0.0.0.0 $medium >/dev/null 2>&1 sleep 1 exit_status=0 } in_state_PREINIT() { delete_alias ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \ broadcast 255.255.255.255 up exit_status=0 } in_state_REBIND() { set_hostname if [ "$alias_ip_address" != "$old_ip_address" ]; then delete_alias fi if [ "$old_ip_address" != "$new_ip_address" ]; then delete_old config_new fi exit_status=0 } in_state_REBOOT() { in_state_BOUND } in_state_RENEW() { in_state_REBIND } in_state_TIMEOUT() { delete_alias if test_lease; then config_new exit_status=0 else delete_old config_alias exit_status=1 fi } # Actually do something # enter_with_hooks print_net_changes pre_state_${reason}_hook in_state_${reason} post_state_${reason}_hook exit_with_hooks $exit_status To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message