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