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