]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/isc-dhcp/client/scripts/freebsd
This commit was generated by cvs2svn to compensate for changes in r54427,
[FreeBSD/FreeBSD.git] / contrib / isc-dhcp / client / scripts / freebsd
1 #!/bin/sh
2
3 if [ -x /usr/bin/logger ]; then
4         LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
5 else
6         LOGGER=echo
7 fi
8
9 make_resolv_conf() {
10   echo search $new_domain_name >/etc/resolv.conf
11   for nameserver in $new_domain_name_servers; do
12     echo nameserver $nameserver >>/etc/resolv.conf
13   done
14 }
15
16 # Must be used on exit.   Invokes the local dhcp client exit hooks, if any.
17 exit_with_hooks() {
18   exit_status=$1
19   if [ -x /etc/dhclient-exit-hooks ]; then
20     . /etc/dhclient-exit-hooks
21   fi
22 # probably should do something with exit status of the local script
23   exit $exit_status
24 }
25
26 # Invoke the local dhcp client enter hooks, if they exist.
27 if [ -x /etc/dhclient-enter-hooks ]; then
28   exit_status=0
29   . /etc/dhclient-enter-hooks
30   # allow the local script to abort processing of this state
31   # local script must set exit_status variable to nonzero.
32   if [ $exit_status -ne 0 ]; then
33     exit $exit_status
34   fi
35 fi
36
37 if [ x$new_network_number != x ]; then
38    $LOGGER New Network Number: $new_network_number
39 fi
40
41 if [ x$new_broadcast_address != x ]; then
42   $LOGGER New Broadcast Address: $new_broadcast_address
43   new_broadcast_arg="broadcast $new_broadcast_address"
44 fi
45 if [ x$old_broadcast_address != x ]; then
46   old_broadcast_arg="broadcast $old_broadcast_address"
47 fi
48 if [ x$new_subnet_mask != x ]; then
49   $LOGGER New Subnet Mask for $interface: $new_subnet_mask
50   new_netmask_arg="netmask $new_subnet_mask"
51 fi
52 if [ x$old_subnet_mask != x ]; then
53   old_netmask_arg="netmask $old_subnet_mask"
54 fi
55 if [ x$alias_subnet_mask != x ]; then
56   alias_subnet_arg="netmask $alias_subnet_mask"
57 fi
58
59 if [ x$reason = xMEDIUM ]; then
60   ifconfig $interface $medium
61   ifconfig $interface inet -alias 0.0.0.0 $medium >/dev/null 2>&1
62   sleep 1
63   exit_with_hooks 0
64 fi
65
66 if [ x$reason = xPREINIT ]; then
67   if [ x$alias_ip_address != x ]; then
68     ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
69     route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
70   fi
71   ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
72                 broadcast 255.255.255.255 up
73   exit_with_hooks 0
74 fi
75
76 if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
77   exit_with_hooks 0;
78 fi
79   
80 if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
81    [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
82   current_hostname=`/bin/hostname`
83   if [ x$current_hostname = x ] || \
84      [ x$current_hostname = x$old_host_name ]; then
85     if [ x$new_host_name != x$old_host_name ]; then
86       $LOGGER New Hostname: $new_host_name
87       hostname $new_host_name
88     fi
89   fi
90   if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
91                 [ x$alias_ip_address != x$old_ip_address ]; then
92     ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
93     route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
94   fi
95   if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
96     ifconfig $interface inet -alias $old_ip_address $medium
97     route delete $old_ip_address 127.1 >/dev/null 2>&1
98     for router in $old_routers; do
99       route delete default $router >/dev/null 2>&1
100     done
101     if [ "$old_static_routes" != "" ]; then
102       set $old_static_routes
103       while [ $# -gt 1 ]; do
104         route delete $1 $2
105         shift; shift
106       done
107     fi
108     arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' |sh
109   fi
110   if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
111      [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
112     ifconfig $interface inet $new_ip_address $new_netmask_arg \
113                                         $new_broadcast_arg $medium
114     route add $new_ip_address 127.1 >/dev/null 2>&1
115     for router in $new_routers; do
116       route add default $router >/dev/null 2>&1
117     done
118     if [ "$new_static_routes" != "" ]; then
119       $LOGGER New Static Routes: $new_static_routes
120       set $new_static_routes
121       while [ $# -gt 1 ]; do
122         route add $1 $2
123         shift; shift
124       done
125     fi
126   fi
127   if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
128    then
129     ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
130     route add $alias_ip_address 127.0.0.1
131   fi
132   echo search $new_domain_name >/etc/resolv.conf
133   for nameserver in $new_domain_name_servers; do
134     echo nameserver $nameserver >>/etc/resolv.conf
135   done
136   exit_with_hooks 0
137 fi
138
139 if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ]; then
140   if [ x$alias_ip_address != x ]; then
141     ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
142     route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
143   fi
144   if [ x$old_ip_address != x ]; then
145     ifconfig $interface inet -alias $old_ip_address $medium
146     route delete $old_ip_address 127.1 >/dev/null 2>&1
147     for router in $old_routers; do
148       route delete default $router >/dev/null 2>&1
149     done
150     if [ "$old_static_routes" != "" ]; then
151       set $old_static_routes
152       while [ $# -gt 1 ]; do
153         route delete $1 $2
154         shift; shift
155       done
156     fi
157     arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' \
158                                                 |sh >/dev/null 2>&1
159   fi
160   if [ x$alias_ip_address != x ]; then
161     ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
162     route add $alias_ip_address 127.0.0.1
163   fi
164   exit_with_hooks 0
165 fi
166
167 if [ x$reason = xTIMEOUT ]; then
168   if [ x$alias_ip_address != x ]; then
169     ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
170     route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
171   fi
172   ifconfig $interface inet $new_ip_address $new_netmask_arg \
173                                         $new_broadcast_arg $medium
174   sleep 1
175   if [ "$new_routers" != "" ]; then
176     $LOGGER New Routers: $new_routers
177     set $new_routers
178     if ping -q -c 1 $1; then
179       if [ x$new_ip_address != x$alias_ip_address ] && \
180                         [ x$alias_ip_address != x ]; then
181         ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
182         route add $alias_ip_address 127.0.0.1
183       fi
184       route add $new_ip_address 127.1 >/dev/null 2>&1
185       for router in $new_routers; do
186         route add default $router >/dev/null 2>&1
187       done
188       set $new_static_routes
189       while [ $# -gt 1 ]; do
190         route add $0 $1
191         shift; shift
192       done
193       echo search $new_domain_name >/etc/resolv.conf.std
194       for nameserver in $new_domain_name_servers; do
195         echo nameserver $nameserver >>/etc/resolv.conf.std
196       done
197       if [ -f /etc/resolv.conf ]; then
198         rm -f /etc/resolv.conf
199       fi
200       mv /etc/resolv.conf.std /etc/resolv.conf
201       exit_with_hooks 0
202     fi
203   fi
204   ifconfig $interface inet -alias $new_ip_address $medium
205   for router in $old_routers; do
206     route delete default $router >/dev/null 2>&1
207   done
208   if [ "$old_static_routes" != "" ]; then
209     set $old_static_routes
210     while [ $# -gt 1 ]; do
211       route delete $1 $2
212       shift; shift
213     done
214   fi
215   arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' \
216                                                         |sh >/dev/null 2>&1
217   exit_with_hooks 1
218 fi
219
220 exit_with_hooks 0