]> git.pld-linux.org Git - packages/dhcp.git/blame - dhcp-dhclient-script
- patches from dhcp-4.0.0-14.fc9.src.rpm
[packages/dhcp.git] / dhcp-dhclient-script
CommitLineData
1397e9b3
ER
1#!/bin/bash
2# dhclient-script for Linux. Dan Halbert, March, 1997.
3# Updated for Linux 2.[12] by Brian J. Murrell, January 1999.
4# No guarantees about this. I'm a novice at the details of Linux
5# networking.
6
7# Notes:
8
9# 0. This script is based on the netbsd script supplied with dhcp-970306.
10
11# 1. ifconfig down apparently deletes all relevant routes and flushes
12# the arp cache, so this doesn't need to be done explicitly.
13
14# 2. The alias address handling here has not been tested AT ALL.
15# I'm just going by the doc of modern Linux ip aliasing, which uses
16# notations like eth0:0, eth0:1, for each alias.
17
18# 3. I have to calculate the network address, and calculate the broadcast
19# address if it is not supplied. This might be much more easily done
20# by the dhclient C code, and passed on.
21
22# 4. TIMEOUT not tested. ping has a flag I don't know, and I'm suspicious
23# of the $1 in its args.
24
25if [ -n "${dhc_dbus}" ]; then
26 if [ -x /usr/bin/dbus-send ]; then
27 /usr/bin/dbus-send \
28 --system \
29 --dest=com.redhat.dhcp \
30 --type=method_call \
31 /com/redhat/dhcp/$interface \
32 com.redhat.dhcp.set \
33 'string:'"`env | /bin/egrep -v '^(PATH|SHLVL|_|PWD|dhc_dbus)\='`";
34
35 if (( ( dhc_dbus & 31 ) == 31 )); then
36 exit 0;
37 fi;
38 fi;
39fi;
40
41make_resolv_conf() {
42 if [ x"$new_domain_name_servers" != x ]; then
43 cat /dev/null > /etc/resolv.conf.dhclient
44 chmod 644 /etc/resolv.conf.dhclient
45 if [ x"$new_domain_search" != x ]; then
46 echo search $new_domain_search >> /etc/resolv.conf.dhclient
47 elif [ x"$new_domain_name" != x ]; then
48 # Note that the DHCP 'Domain Name Option' is really just a domain
49 # name, and that this practice of using the domain name option as
50 # a search path is both nonstandard and deprecated.
51 echo search $new_domain_name >> /etc/resolv.conf.dhclient
52 fi
53 for nameserver in $new_domain_name_servers; do
54 echo nameserver $nameserver >>/etc/resolv.conf.dhclient
55 done
56
57 mv /etc/resolv.conf.dhclient /etc/resolv.conf
58 fi
59}
60
61# Must be used on exit. Invokes the local dhcp client exit hooks, if any.
62exit_with_hooks() {
63 exit_status=$1
64 if [ -f /etc/dhclient-exit-hooks ]; then
65 . /etc/dhclient-exit-hooks
66 fi
67# probably should do something with exit status of the local script
68 exit $exit_status
69}
70
71# Invoke the local dhcp client enter hooks, if they exist.
72if [ -f /etc/dhclient-enter-hooks ]; then
73 exit_status=0
74 . /etc/dhclient-enter-hooks
75 # allow the local script to abort processing of this state
76 # local script must set exit_status variable to nonzero.
77 if [ $exit_status -ne 0 ]; then
78 exit $exit_status
79 fi
80fi
81
82release=`uname -r`
83release=`expr $release : '\(.*\)\..*'`
84relminor=`echo $release |sed -e 's/[0-9]*\.\([0-9][0-9]*\)\(\..*\)*$/\1/'`
85relmajor=`echo $release |sed -e 's/\([0-9][0-9]*\)\..*$/\1/'`
86
87if [ x$new_broadcast_address != x ]; then
88 new_broadcast_arg="broadcast $new_broadcast_address"
89fi
90if [ x$old_broadcast_address != x ]; then
91 old_broadcast_arg="broadcast $old_broadcast_address"
92fi
93if [ x$new_subnet_mask != x ]; then
94 new_subnet_arg="netmask $new_subnet_mask"
95fi
96if [ x$old_subnet_mask != x ]; then
97 old_subnet_arg="netmask $old_subnet_mask"
98fi
99if [ x$alias_subnet_mask != x ]; then
100 alias_subnet_arg="netmask $alias_subnet_mask"
101fi
102
103if [ x$reason = xMEDIUM ]; then
104 # Linux doesn't do mediums (ok, ok, media).
105 exit_with_hooks 0
106fi
107
108if [ x$reason = xPREINIT ]; then
109 if [ x$alias_ip_address != x ]; then
110 # Bring down alias interface. Its routes will disappear too.
111 ifconfig $interface:0- inet 0
112 fi
113 if [ $relmajor -lt 2 ] || ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] )
114 then
115 ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
116 broadcast 255.255.255.255 up
117 # Add route to make broadcast work. Do not omit netmask.
118 route add default dev $interface netmask 0.0.0.0
119 else
120 ifconfig $interface 0 up
121 fi
122
123 # We need to give the kernel some time to get the interface up.
124 sleep 1
125
126 exit_with_hooks 0
127fi
128
129if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
130 exit_with_hooks 0
131fi
132
133if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
134 [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
135 current_hostname=`hostname`
136 if [ x$current_hostname = x ] || \
137 [ x$current_hostname = x$old_host_name ]; then
138 if [ x$current_hostname = x ] || \
139 [ x$new_host_name != x$old_host_name ]; then
140 hostname $new_host_name
141 fi
142 fi
143
144 if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
145 [ x$alias_ip_address != x$old_ip_address ]; then
146 # Possible new alias. Remove old alias.
147 ifconfig $interface:0- inet 0
148 fi
149 if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
150 # IP address changed. Bringing down the interface will delete all routes,
151 # and clear the ARP cache.
152 ifconfig $interface inet 0 down
153
154 fi
155 if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
156 [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
157
158 ifconfig $interface inet $new_ip_address $new_subnet_arg \
159 $new_broadcast_arg
160 # Add a network route to the computed network address.
161 if [ $relmajor -lt 2 ] || \
162 ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
163 route add -net $new_network_number $new_subnet_arg dev $interface
164 fi
165 for router in $new_routers; do
166 route add default gw $router
167 done
168 fi
169 if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
170 then
171 ifconfig $interface:0- inet 0
172 ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
173 route add -host $alias_ip_address $interface:0
174 fi
175 make_resolv_conf
176 exit_with_hooks 0
177fi
178
179if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
180 || [ x$reason = xSTOP ]; then
181 if [ x$alias_ip_address != x ]; then
182 # Turn off alias interface.
183 ifconfig $interface:0- inet 0
184 fi
185 if [ x$old_ip_address != x ]; then
186 # Shut down interface, which will delete routes and clear arp cache.
187 ifconfig $interface inet 0 down
188 fi
189 if [ x$alias_ip_address != x ]; then
190 ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
191 route add -host $alias_ip_address $interface:0
192 fi
193 exit_with_hooks 0
194fi
195
196if [ x$reason = xTIMEOUT ]; then
197 if [ x$alias_ip_address != x ]; then
198 ifconfig $interface:0- inet 0
199 fi
200 ifconfig $interface inet $new_ip_address $new_subnet_arg \
201 $new_broadcast_arg
202 set $new_routers
203 ############## what is -w in ping?
204 if ping -q -c 1 $1; then
205 if [ x$new_ip_address != x$alias_ip_address ] && \
206 [ x$alias_ip_address != x ]; then
207 ifconfig $interface:0 inet $alias_ip_address $alias_subnet_arg
208 route add -host $alias_ip_address dev $interface:0
209 fi
210 if [ $relmajor -lt 2 ] || \
211 ( [ $relmajor -eq 2 ] && [ $relminor -eq 0 ] ); then
212 route add -net $new_network_number
213 fi
214 for router in $new_routers; do
215 route add default gw $router
216 done
217 make_resolv_conf
218 exit_with_hooks 0
219 fi
220 ifconfig $interface inet 0 down
221 exit_with_hooks 1
222fi
223
224exit_with_hooks 0
This page took 0.1309 seconds and 4 git commands to generate.