]>
Commit | Line | Data |
---|---|---|
f59e1e88 MT |
1 | Submitted By: DJ Lucas (dj at linuxfromscratch dot org) |
2 | Date: 2005-06-18 | |
3 | Initial Package Version: 3.0.2 | |
4 | Origin: Jim Gifford, Bruce Dubbs, DJ Lucas | |
5 | Description: Fixes client script to use iproute2 (added flush to previous | |
6 | unversioned patches) | |
7 | Upstream Status: Not submitted | |
8 | ||
9 | --- dhcp-3.0.2-orig/client/scripts/linux 2002-11-14 19:09:09.000000000 -0600 | |
10 | +++ dhcp-3.0.2/client/scripts/linux 2005-06-18 22:54:59.000000000 -0500 | |
11 | @@ -1,26 +1,15 @@ | |
12 | #!/bin/bash | |
13 | # dhclient-script for Linux. Dan Halbert, March, 1997. | |
14 | # Updated for Linux 2.[12] by Brian J. Murrell, January 1999. | |
15 | -# No guarantees about this. I'm a novice at the details of Linux | |
16 | -# networking. | |
17 | + | |
18 | +# Updated to iproute2 by Jim Gifford (scripts@jg555.com) | |
19 | ||
20 | # Notes: | |
21 | ||
22 | # 0. This script is based on the netbsd script supplied with dhcp-970306. | |
23 | - | |
24 | -# 1. ifconfig down apparently deletes all relevant routes and flushes | |
25 | -# the arp cache, so this doesn't need to be done explicitly. | |
26 | - | |
27 | -# 2. The alias address handling here has not been tested AT ALL. | |
28 | -# I'm just going by the doc of modern Linux ip aliasing, which uses | |
29 | -# notations like eth0:0, eth0:1, for each alias. | |
30 | - | |
31 | -# 3. I have to calculate the network address, and calculate the broadcast | |
32 | -# address if it is not supplied. This might be much more easily done | |
33 | -# by the dhclient C code, and passed on. | |
34 | - | |
35 | -# 4. TIMEOUT not tested. ping has a flag I don't know, and I'm suspicious | |
36 | -# of the $1 in its args. | |
37 | +# 1. This script was modified to work with iproute2 | |
38 | +# 2. cidr_convert based on a script by Kevin Fleming (kpfleming@linuxfromscratch.org) | |
39 | +# 3. Updated to delete addresses when taking an interface down (bdubbs@linuxfromscratch.org) | |
40 | ||
41 | make_resolv_conf() { | |
42 | if [ "x$new_domain_name" != x ] && [ x"$new_domain_name_servers" != x ]; then | |
43 | @@ -32,6 +21,30 @@ | |
44 | fi | |
45 | } | |
46 | ||
47 | +dec2binary() | |
48 | +{ | |
49 | + local n=$1 | |
50 | + local ret="" | |
51 | + while [ $n != 0 ]; do | |
52 | + ret=$[$n%2]$ret | |
53 | + n=$[$n>>1] | |
54 | + done | |
55 | + echo $ret | |
56 | +} | |
57 | + | |
58 | +mask_to_binary() | |
59 | +{ | |
60 | + echo `dec2binary $1``dec2binary $2``dec2binary $3``dec2binary $4` | |
61 | +} | |
62 | + | |
63 | +cidr_convert() | |
64 | +{ | |
65 | + netmask=$1 | |
66 | + local mask=`mask_to_binary ${netmask//./ }` | |
67 | + mask=${mask%%0*} | |
68 | + cidr=${#mask} | |
69 | +} | |
70 | + | |
71 | # Must be used on exit. Invokes the local dhcp client exit hooks, if any. | |
72 | exit_with_hooks() { | |
73 | exit_status=$1 | |
74 | @@ -53,11 +66,6 @@ | |
75 | fi | |
76 | fi | |
77 | ||
78 | -release=`uname -r` | |
79 | -release=`expr $release : '\(.*\)\..*'` | |
80 | -relminor=`echo $release |sed -e 's/[0-9]*\.\([0-9][0-9]*\)\(\..*\)*$/\1/'` | |
81 | -relmajor=`echo $release |sed -e 's/\([0-9][0-9]*\)\..*$/\1/'` | |
82 | - | |
83 | if [ x$new_broadcast_address != x ]; then | |
84 | new_broadcast_arg="broadcast $new_broadcast_address" | |
85 | fi | |
86 | @@ -65,13 +73,12 @@ | |
87 | old_broadcast_arg="broadcast $old_broadcast_address" | |
88 | fi | |
89 | if [ x$new_subnet_mask != x ]; then | |
90 | - new_subnet_arg="netmask $new_subnet_mask" | |
91 | + cidr_convert $new_subnet_mask | |
92 | + new_subnet_arg="$cidr" | |
93 | fi | |
94 | if [ x$old_subnet_mask != x ]; then | |
95 | - old_subnet_arg="netmask $old_subnet_mask" | |
96 | -fi | |
97 | -if [ x$alias_subnet_mask != x ]; then | |
98 | - alias_subnet_arg="netmask $alias_subnet_mask" | |
99 | + cidr_convert $old_subnet_mask | |
100 | + old_subnet_arg="$cidr" | |
101 | fi | |
102 | ||
103 | if [ x$reason = xMEDIUM ]; then | |
104 | @@ -82,17 +89,10 @@ | |
105 | if [ x$reason = xPREINIT ]; then | |
106 | if [ x$alias_ip_address != x ]; then | |
107 | # Bring down alias interface. Its routes will disappear too. | |
108 | - ifconfig $interface:0- inet 0 | |
109 | - fi | |
110 | - if [ $relmajor -lt 2 ] || ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ) | |
111 | - then | |
112 | - ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \ | |
113 | - broadcast 255.255.255.255 up | |
114 | - # Add route to make broadcast work. Do not omit netmask. | |
115 | - route add default dev $interface netmask 0.0.0.0 | |
116 | - else | |
117 | - ifconfig $interface 0 up | |
118 | + ip link set $interface down | |
119 | + ip addr del $alias_ip_address dev $interface | |
120 | fi | |
121 | + ip link set $interface up | |
122 | ||
123 | # We need to give the kernel some time to get the interface up. | |
124 | sleep 1 | |
125 | @@ -115,83 +115,51 @@ | |
126 | fi | |
127 | fi | |
128 | ||
129 | - if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \ | |
130 | - [ x$alias_ip_address != x$old_ip_address ]; then | |
131 | - # Possible new alias. Remove old alias. | |
132 | - ifconfig $interface:0- inet 0 | |
133 | - fi | |
134 | if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then | |
135 | - # IP address changed. Bringing down the interface will delete all routes, | |
136 | + # IP address changed. Bring down the interface, delete all routes, | |
137 | # and clear the ARP cache. | |
138 | - ifconfig $interface inet 0 down | |
139 | - | |
140 | + ip link set $interface down | |
141 | + ip addr flush dev $interface | |
142 | fi | |
143 | if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \ | |
144 | [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then | |
145 | ||
146 | - ifconfig $interface inet $new_ip_address $new_subnet_arg \ | |
147 | - $new_broadcast_arg | |
148 | + ip link set $interface up | |
149 | + ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg \ | |
150 | + label $interface dev $interface | |
151 | # Add a network route to the computed network address. | |
152 | - if [ $relmajor -lt 2 ] || \ | |
153 | - ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then | |
154 | - route add -net $new_network_number $new_subnet_arg dev $interface | |
155 | - fi | |
156 | for router in $new_routers; do | |
157 | - route add default gw $router | |
158 | + ip route add default via $router | |
159 | done | |
160 | fi | |
161 | - if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ]; | |
162 | - then | |
163 | - ifconfig $interface:0- inet 0 | |
164 | - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg | |
165 | - route add -host $alias_ip_address $interface:0 | |
166 | - fi | |
167 | make_resolv_conf | |
168 | exit_with_hooks 0 | |
169 | fi | |
170 | ||
171 | if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \ | |
172 | || [ x$reason = xSTOP ]; then | |
173 | - if [ x$alias_ip_address != x ]; then | |
174 | - # Turn off alias interface. | |
175 | - ifconfig $interface:0- inet 0 | |
176 | - fi | |
177 | if [ x$old_ip_address != x ]; then | |
178 | - # Shut down interface, which will delete routes and clear arp cache. | |
179 | - ifconfig $interface inet 0 down | |
180 | - fi | |
181 | - if [ x$alias_ip_address != x ]; then | |
182 | - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg | |
183 | - route add -host $alias_ip_address $interface:0 | |
184 | + # Shut down interface, delete routes, and clear arp cache. | |
185 | + ip link set $interface down | |
186 | + ip addr flush dev $interface | |
187 | fi | |
188 | exit_with_hooks 0 | |
189 | fi | |
190 | ||
191 | if [ x$reason = xTIMEOUT ]; then | |
192 | - if [ x$alias_ip_address != x ]; then | |
193 | - ifconfig $interface:0- inet 0 | |
194 | - fi | |
195 | - ifconfig $interface inet $new_ip_address $new_subnet_arg \ | |
196 | - $new_broadcast_arg | |
197 | + ip link set $interface up | |
198 | + ip addr set $new_ip_address/$new_subnet_arg $new_broadcast_arg \ | |
199 | + label $interface dev $interface | |
200 | set $new_routers | |
201 | - ############## what is -w in ping? | |
202 | - if ping -q -c 1 $1; then | |
203 | - if [ x$new_ip_address != x$alias_ip_address ] && \ | |
204 | - [ x$alias_ip_address != x ]; then | |
205 | - ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg | |
206 | - route add -host $alias_ip_address dev $interface:0 | |
207 | - fi | |
208 | - if [ $relmajor -lt 2 ] || \ | |
209 | - ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then | |
210 | - route add -net $new_network_number | |
211 | - fi | |
212 | - for router in $new_routers; do | |
213 | - route add default gw $router | |
214 | - done | |
215 | - make_resolv_conf | |
216 | - exit_with_hooks 0 | |
217 | - fi | |
218 | - ifconfig $interface inet 0 down | |
219 | + | |
220 | + for router in $new_routers; do | |
221 | + ip route add default via $router | |
222 | + done | |
223 | + | |
224 | + make_resolv_conf | |
225 | + exit_with_hooks 0 | |
226 | + ip link set $interface down | |
227 | + ip addr flush dev $interface | |
228 | exit_with_hooks 1 | |
229 | fi | |
230 |