]> git.pld-linux.org Git - packages/dhcp.git/blame - dhcp-dhclient.script.patch
- patch no-ipv6 - don't require ipv6 support in kernel
[packages/dhcp.git] / dhcp-dhclient.script.patch
CommitLineData
53716e04
ER
1--- dhcp-3.1.0a3/client/scripts/linux.orig 2006-07-22 04:24:16.000000000 +0200
2+++ dhcp-3.1.0a3/client/scripts/linux 2007-04-16 17:25:06.000000000 +0200
3@@ -1,290 +1,302 @@
893aa178
JR
4-#!/bin/bash
5+#!/bin/sh
6 # dhclient-script for Linux. Dan Halbert, March, 1997.
7 # Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
8-# No guarantees about this. I'm a novice at the details of Linux
9-# networking.
10
11 # Notes:
12
13 # 0. This script is based on the netbsd script supplied with dhcp-970306.
14
15-# 1. ifconfig down apparently deletes all relevant routes and flushes
16-# the arp cache, so this doesn't need to be done explicitly.
17+# 1. This script was modified to work with iproute2
18
19-# 2. The alias address handling here has not been tested AT ALL.
20-# I'm just going by the doc of modern Linux ip aliasing, which uses
21-# notations like eth0:0, eth0:1, for each alias.
22-
23-# 3. I have to calculate the network address, and calculate the broadcast
24-# address if it is not supplied. This might be much more easily done
25-# by the dhclient C code, and passed on.
26-
27-# 4. TIMEOUT not tested. ping has a flag I don't know, and I'm suspicious
28-# of the $1 in its args.
7cecd907
AM
29-
30-# 'ip' just looks too weird. /sbin/ip looks less weird.
31-ip=/sbin/ip
893aa178
JR
32+calc_prefix()
33+{
34+ local old_IFS=$IFS
35+ IFS='.'
36+ local netmask=$(echo $1)
37+ IFS=$old_IFS
38+
39+ local ret=0
40+ local endp=0
893aa178
JR
41+ for n in $netmask ; do
42+ for i in 128 64 32 16 8 4 2 1 ; do
43+ if [ $(($n & $i)) -ne 0 ]; then
44+ if [ $endp -eq 0 ]; then
45+ ret=$(($ret + 1))
46+ else
47+ echo "32"
48+ return
49+ fi
50+ else
51+ endp=1
52+ fi
53+ done
54+ done
55+ echo $ret
56+}
57
58 make_resolv_conf() {
59- if [ x"$new_domain_name_servers" != x ]; then
60- cat /dev/null > /etc/resolv.conf.dhclient
61- chmod 644 /etc/resolv.conf.dhclient
62- if [ x"$new_domain_search" != x ]; then
63- echo search $new_domain_search >> /etc/resolv.conf.dhclient
64- elif [ x"$new_domain_name" != x ]; then
65- # Note that the DHCP 'Domain Name Option' is really just a domain
66- # name, and that this practice of using the domain name option as
67- # a search path is both nonstandard and deprecated.
68- echo search $new_domain_name >> /etc/resolv.conf.dhclient
69- fi
70- for nameserver in $new_domain_name_servers; do
71- echo nameserver $nameserver >>/etc/resolv.conf.dhclient
72- done
73-
74- mv /etc/resolv.conf.dhclient /etc/resolv.conf
7cecd907
AM
75- elif [ "x${new_dhcp6_name_servers}" != x ] ; then
76- cat /dev/null > /etc/resolv.conf.dhclient6
77- chmod 644 /etc/resolv.conf.dhclient6
78-
79- if [ "x${new_dhcp6_domain_search}" != x ] ; then
80- echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6
81- fi
82- for nameserver in ${new_dhcp6_name_servers} ; do
83- echo nameserver ${nameserver} >> /etc/resolv.conf.dhclient6
84- done
85-
86- mv /etc/resolv.conf.dhclient6 /etc/resolv.conf
893aa178
JR
87- fi
88+ if [ -n "$new_domain_name_servers" ]; then
89+ :> /etc/resolv.conf.dhclient
90+ chmod 644 /etc/resolv.conf.dhclient
91+ if [ -n "$new_domain_search" ]; then
92+ echo search $new_domain_search >> /etc/resolv.conf.dhclient
93+ elif [ -n "$new_domain_name" ]; then
94+ # Note that the DHCP 'Domain Name Option' is really just a domain
95+ # name, and that this practice of using the domain name option as
96+ # a search path is both nonstandard and deprecated.
97+ echo search $new_domain_name >> /etc/resolv.conf.dhclient
98+ fi
99+ for nameserver in $new_domain_name_servers; do
100+ echo nameserver $nameserver >>/etc/resolv.conf.dhclient
101+ done
102+ mv /etc/resolv.conf.dhclient /etc/resolv.conf
7cecd907
AM
103+ elif [ -n "${new_dhcp6_name_servers}" ] ; then
104+ :> /etc/resolv.conf.dhclient6
105+ chmod 644 /etc/resolv.conf.dhclient6
106+
107+ if [ "x${new_dhcp6_domain_search}" != x ] ; then
108+ echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6
109+ fi
110+ for nameserver in ${new_dhcp6_name_servers} ; do
111+ echo nameserver ${nameserver} >> /etc/resolv.conf.dhclient6
112+ done
113+ mv /etc/resolv.conf.dhclient6 /etc/resolv.conf
893aa178
JR
114+ fi
115 }
116
117-# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
118+# Must be used on exit.
119+# Invokes the local dhcp client exit hooks, if any.
120 exit_with_hooks() {
121- exit_status=$1
122- if [ -f /etc/dhclient-exit-hooks ]; then
123- . /etc/dhclient-exit-hooks
124- fi
125-# probably should do something with exit status of the local script
126- exit $exit_status
127+ exit_status=$1
128+ if [ -f /etc/dhclient-exit-hooks ]; then
129+ . /etc/dhclient-exit-hooks
130+ fi
131+ # probably should do something with exit status of the local script
132+ exit $exit_status
133 }
134
135 # Invoke the local dhcp client enter hooks, if they exist.
136 if [ -f /etc/dhclient-enter-hooks ]; then
137- exit_status=0
138- . /etc/dhclient-enter-hooks
139- # allow the local script to abort processing of this state
140- # local script must set exit_status variable to nonzero.
141- if [ $exit_status -ne 0 ]; then
142- exit $exit_status
143- fi
7cecd907
AM
144+ exit_status=0
145+ . /etc/dhclient-enter-hooks
146+ # allow the local script to abort processing of this state
147+ # local script must set exit_status variable to nonzero.
148+ if [ $exit_status -ne 0 ]; then
149+ exit $exit_status
150+ fi
151 fi
152
893aa178
JR
153-release=`uname -r`
154-release=`expr $release : '\(.*\)\..*'`
155-relminor=`echo $release |sed -e 's/[0-9]*\.\([0-9][0-9]*\)\(\..*\)*$/\1/'`
156-relmajor=`echo $release |sed -e 's/\([0-9][0-9]*\)\..*$/\1/'`
157-
7cecd907
AM
158 ###
159 ### DHCPv4 Handlers
160 ###
161
893aa178
JR
162-if [ x$new_broadcast_address != x ]; then
163- new_broadcast_arg="broadcast $new_broadcast_address"
164-fi
165-if [ x$old_broadcast_address != x ]; then
166- old_broadcast_arg="broadcast $old_broadcast_address"
167-fi
168-if [ x$new_subnet_mask != x ]; then
169- new_subnet_arg="netmask $new_subnet_mask"
170-fi
171-if [ x$old_subnet_mask != x ]; then
172- old_subnet_arg="netmask $old_subnet_mask"
173-fi
174-if [ x$alias_subnet_mask != x ]; then
175- alias_subnet_arg="netmask $alias_subnet_mask"
176-fi
177-
178-if [ x$reason = xMEDIUM ]; then
179- # Linux doesn't do mediums (ok, ok, media).
180- exit_with_hooks 0
181-fi
182-
183-if [ x$reason = xPREINIT ]; then
184- if [ x$alias_ip_address != x ]; then
185- # Bring down alias interface. Its routes will disappear too.
186- ifconfig $interface:0- inet 0
187- fi
188- if [ $relmajor -lt 2 ] || ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] )
189- then
190- ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
191- broadcast 255.255.255.255 up
192- # Add route to make broadcast work. Do not omit netmask.
193- route add default dev $interface netmask 0.0.0.0
194- else
195- ifconfig $interface 0 up
196- fi
197-
198- # We need to give the kernel some time to get the interface up.
199- sleep 1
200-
201- exit_with_hooks 0
202-fi
203-
204-if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
205- exit_with_hooks 0
206-fi
207-
208-if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
209- [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
210- current_hostname=`hostname`
211- if [ x$current_hostname = x ] || \
212- [ x$current_hostname = x$old_host_name ]; then
213- if [ x$current_hostname = x ] || \
214- [ x$new_host_name != x$old_host_name ]; then
215- hostname $new_host_name
216- fi
217- fi
218-
219- if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
220- [ x$alias_ip_address != x$old_ip_address ]; then
221- # Possible new alias. Remove old alias.
222- ifconfig $interface:0- inet 0
223- fi
224- if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
225- # IP address changed. Bringing down the interface will delete all routes,
226- # and clear the ARP cache.
227- ifconfig $interface inet 0 down
228-
229- fi
230- if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
231- [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
232-
233- ifconfig $interface inet $new_ip_address $new_subnet_arg \
234- $new_broadcast_arg
235- # Add a network route to the computed network address.
236- if [ $relmajor -lt 2 ] || \
237- ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
238- route add -net $new_network_number $new_subnet_arg dev $interface
239- fi
240- for router in $new_routers; do
241- route add default gw $router
242- done
243- fi
244- if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
245- then
246- ifconfig $interface:0- inet 0
247- ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
248- route add -host $alias_ip_address $interface:0
249- fi
250- make_resolv_conf
251- exit_with_hooks 0
252-fi
253-
254-if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
255- || [ x$reason = xSTOP ]; then
256- if [ x$alias_ip_address != x ]; then
257- # Turn off alias interface.
258- ifconfig $interface:0- inet 0
259- fi
260- if [ x$old_ip_address != x ]; then
261- # Shut down interface, which will delete routes and clear arp cache.
262- ifconfig $interface inet 0 down
263- fi
264- if [ x$alias_ip_address != x ]; then
265- ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
266- route add -host $alias_ip_address $interface:0
267- fi
268- exit_with_hooks 0
7cecd907
AM
269+if [ -n "$new_broadcast_address" ]; then
270+ new_broadcast_arg="broadcast $new_broadcast_address"
271 fi
893aa178
JR
272-
273-if [ x$reason = xTIMEOUT ]; then
274- if [ x$alias_ip_address != x ]; then
275- ifconfig $interface:0- inet 0
276- fi
277- ifconfig $interface inet $new_ip_address $new_subnet_arg \
278- $new_broadcast_arg
279- set $new_routers
893aa178
JR
280- if ping -q -c 1 $1; then
281- if [ x$new_ip_address != x$alias_ip_address ] && \
282- [ x$alias_ip_address != x ]; then
283- ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
284- route add -host $alias_ip_address dev $interface:0
285- fi
286- if [ $relmajor -lt 2 ] || \
287- ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
288- route add -net $new_network_number
289- fi
290- for router in $new_routers; do
291- route add default gw $router
292- done
293- make_resolv_conf
294- exit_with_hooks 0
295- fi
296- ifconfig $interface inet 0 down
297- exit_with_hooks 1
893aa178
JR
298+if [ -n "$old_broadcast_address" ]; then
299+ old_broadcast_arg="broadcast $old_broadcast_address"
7cecd907
AM
300 fi
301-
302-###
303-### DHCPv6 Handlers
304-###
305-
306-if [ ${reason} = PREINIT6 ] ; then
307- # Ensure interface is up.
308- ${ip} link set ${interface} up
309-
310- # Remove any stale addresses from aborted clients.
311- ${ip} -f inet6 addr flush dev ${interface} scope global permanent
312-
313- exit_with_hooks 0
893aa178
JR
314+if [ -n "$new_subnet_mask" ]; then
315+ new_subnet_arg="$(calc_prefix $new_subnet_mask)"
7cecd907 316 fi
893aa178
JR
317+if [ -n "$old_subnet_mask" ]; then
318+ old_subnet_arg="$(calc_prefix $old_subnet_mask)"
319+fi
320+if [ -n "$alias_subnet_mask" ]; then
321+ alias_subnet_arg="$(calc_prefix $alias_subnet_mask)"
322+fi
323+[ -z "new_subnet_arg" ] && $new_subnet_arg="32"
324+[ -z "old_subnet_arg" ] && $old_subnet_arg="32"
325+[ -z "alias_subnet_arg" ] && $alias_subnet_arg="32"
326+
327+case "$reason" in
328+ MEDIUM)
329+ # Linux doesn't do mediums (ok, ok, media).
330+ ;;
331+
332+ PREINIT)
333+ if [ -n "$alias_ip_address" ]; then
334+ /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
335+ fi
336+ /sbin/ip link set $interface up
337+
338+ # We need to give the kernel some time to get the interface up.
339+ sleep 1
340+ ;;
341+
342+ BOUND|RENEW|REBIND|REBOOT)
343+ current_hostname=`hostname`
344+ if [ -z "$current_hostname" ]; then
345+ hostname $new_host_name
346+ elif [ "$current_hostname" = "$old_host_name" -a \
347+ "$new_host_name" != "$old_host_name" ]; then
348+ hostname $new_host_name
349+ fi
350+
351+ if [ -n "$old_ip_address" -a -n "$alias_ip_address" -a \
352+ "$alias_ip_address" != "$old_ip_address" ]; then
353+ # Possible new alias. Remove old alias.
354+ /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
355+ fi
356+ if [ -n "$old_ip_address" -a "$old_ip_address" != "$new_ip_address" ]; then
357+ # IP address changed.
358+ /sbin/ip addr del $old_ip_address/$old_subnet_arg dev $interface
359+ for router in $old_routers; do
360+ /sbin/ip route del default via $router
361+ done
362+ if [ -n "$old_static_routes" ]; then
363+ set -- $old_static_routes
364+ while [ $# -gt 1 ]; do
365+ /sbin/ip route del $1 via $2
366+ shift; shift
367+ done
368+ fi
369+ fi
370+ if [ -z "$old_ip_address" -o "$old_ip_address" != "$new_ip_address" -o \
371+ "$reason" = "BOUND" -o "$reason" = "REBOOT" ]; then
372+ /sbin/ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg dev $interface
373+ # Add a network route to the computed network address.
374+ for router in $new_routers; do
375+ /sbin/ip route add default via $router
376+ done
377+ if [ -n "$new_static_routes" ]; then
378+ set -- $new_static_routes
379+ while [ $# -gt 1 ]; do
380+ /sbin/ip route add $1 via $2
381+ shift; shift
382+ done
383+ fi
384+ fi
385+ if [ -n "$alias_ip_address" -a "$new_ip_address" != "$alias_ip_address" ]; then
386+ /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
387+ fi
388+ make_resolv_conf
389+ ;;
390+
391+ EXPIRE|FAIL|RELEASE|STOP)
392+ if [ -n "$alias_ip_address" ]; then
393+ # Turn off alias interface.
394+ /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
395+ fi
396+ if [ -n "$old_ip_address" ]; then
397+ /sbin/ip addr del $old_ip_address/$old_subnet_arg dev $interface
398+ for router in $old_routers; do
399+ /sbin/ip route del default via $router
400+ done
401+ if [ -n "$old_static_routes" ]; then
402+ set -- $old_static_routes
403+ while [ $# -gt 1 ]; do
404+ /sbin/ip route del $1 via $2
405+ shift; shift
406+ done
407+ fi
408+ fi
409+ if [ -n "$alias_ip_address" ]; then
410+ /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
411+ fi
412+ ;;
413+
414+ TIMEOUT)
415+ if [ -n "$alias_ip_address" ]; then
416+ /sbin/ip addr del $alias_ip_address/$alias_subnet_arg dev $interface
417+ fi
418+ /sbin/ip addr add $new_ip_address/$new_subnet_arg $new_broadcast_arg dev $interface
419+
420+ set $new_routers
421+ if ping -q -c 1 $1; then
422+ if [ "$new_ip_address" != "$alias_ip_address" ] && \
423+ [ -n "$alias_ip_address" ]; then
424+ /sbin/ip addr add $alias_ip_address/$alias_subnet_arg dev $interface
425+ fi
426+ for router in $new_routers; do
427+ /sbin/ip route add default via $router
428+ done
429+ if [ -n "$new_static_routes" ]; then
430+ set -- $new_static_routes
431+ while [ $# -gt 1 ]; do
432+ /sbin/ip route add $1 via $2
433+ shift; shift
434+ done
435+ fi
436+ make_resolv_conf
437+ exit_with_hooks 0
438+ fi
439+
440+ /sbin/ip addr del $new_ip_address/$new_subnet_arg dev $interface
441+ for router in $old_routers; do
442+ /sbin/ip route del default via $router
443+ done
444+ if [ -n "$old_static_routes" ]; then
445+ set -- $old_static_routes
446+ while [ $# -gt 1 ]; do
447+ /sbin/ip route del $1 via $2
448+ shift; shift
449+ done
450+ fi
451+ exit_with_hooks 1
452+ ;;
7cecd907
AM
453+
454+ PREINIT6)
455+ # Ensure interface is up.
456+ /sbin/ip link set ${interface} up
457+
458+ # Remove any stale addresses from aborted clients.
459+ /sbin/ip -f inet6 addr flush dev ${interface} scope global permanent
460+
461+ exit_with_hooks 0
462+ ;;
463+ BOUND6)
464+ if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then
465+ exit_with_hooks 2;
466+ fi
467
468-if [ ${reason} = BOUND6 ] ; then
469- if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then
470- exit_with_hooks 2;
471- fi
472-
473- ${ip} -f inet6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
474+ /sbin/ip -f inet6 addr add ${new_ip6_address}/${new_ip6_prefixlen} \
475 dev ${interface} scope global
476
477- # Check for nameserver options.
478- make_resolv_conf
479-
480- exit_with_hooks 0
481-fi
482+ # Check for nameserver options.
483+ make_resolv_conf
484
485-if [ ${reason} = RENEW6 ] || [ ${reason} = REBIND6 ] ; then
486- # Make sure nothing has moved around on us.
487+ exit_with_hooks 0
488+ ;;
489
490- # Nameservers/domains/etc.
491- if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
492- [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then
493- make_resolv_conf
494- fi
495-
496- exit_with_hooks 0
497-fi
498+ RENEW6|REBIND6)
499+ # Make sure nothing has moved around on us.
500
501-if [ ${reason} = DEPREF6 ] ; then
502- if [ x${new_ip6_prefixlen} = x ] ; then
503- exit_with_hooks 2;
504- fi
505-
506- # There doesn't appear to be a way to update an addr to indicate
507- # preference.
508-# ${ip} -f inet6 addr ??? ${new_ip6_address}/${new_ip6_prefixlen} \
509-# dev ${interface} scope global deprecated?
510+ # Nameservers/domains/etc.
511+ if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] ||
512+ [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then
513+ make_resolv_conf
514+ fi
515+
516+ exit_with_hooks 0
517+ ;;
518+
519+ DEPREF6)
520+ if [ x${new_ip6_prefixlen} = x ] ; then
521+ exit_with_hooks 2;
522+ fi
523+
524+ # There doesn't appear to be a way to update an addr to indicate
525+ # preference.
526+ # /sbin/ip -f inet6 addr ??? ${new_ip6_address}/${new_ip6_prefixlen} \
527+ # dev ${interface} scope global deprecated?
528+
529+ exit_with_hooks 0
530+ ;;
531+
532+ EXPIRE6|RELEASE6|STOP6)
533+ if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then
534+ exit_with_hooks 2;
535+ fi
536
537- exit_with_hooks 0
538-fi
539-
540-if [ ${reason} = EXPIRE6 -o ${reason} = RELEASE6 -o ${reason} = STOP6 ] ; then
541- if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then
542- exit_with_hooks 2;
543- fi
544-
545- ${ip} -f inet6 addr del ${old_ip6_address}/${old_ip6_prefixlen} \
546+ /sbin/ip -f inet6 addr del ${old_ip6_address}/${old_ip6_prefixlen} \
547 dev ${interface}
548
549- exit_with_hooks 0
550-fi
551+ exit_with_hooks 0
552+ ;;
553+
893aa178
JR
554+ *)
555+ ;;
556+esac
557
558 exit_with_hooks 0
This page took 0.137944 seconds and 4 git commands to generate.