]> git.ipfire.org Git - thirdparty/dhcp.git/blob - client/scripts/solaris
- Support for compressed 'domain name list' style DHCP option contents, and
[thirdparty/dhcp.git] / client / scripts / solaris
1 #!/bin/sh
2
3 make_resolv_conf() {
4 if [ x"$new_domain_name_servers" != x ]; then
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
14 for nameserver in $new_domain_name_servers; do
15 echo nameserver $nameserver >>/etc/resolv.conf.dhclient
16 done
17
18 mv /etc/resolv.conf.dhclient /etc/resolv.conf
19 fi
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
25 if [ -f /etc/dhclient-exit-hooks ]; then
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.
33 if [ -f /etc/dhclient-enter-hooks ]; then
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
43 if [ x$new_broadcast_address != x ]; then
44 new_broadcast_arg="broadcast $new_broadcast_address"
45 fi
46 if [ x$old_broadcast_address != x ]; then
47 old_broadcast_arg="broadcast $old_broadcast_address"
48 fi
49 if [ x$new_subnet_mask != x ]; then
50 new_netmask_arg="netmask $new_subnet_mask"
51 fi
52 if [ x$old_subnet_mask != x ]; then
53 old_netmask_arg="netmask $old_subnet_mask"
54 fi
55 if [ x$alias_subnet_mask != x ]; then
56 alias_subnet_arg="netmask $alias_subnet_mask"
57 fi
58
59 ifconfig=/sbin/ifconfig
60
61 release=`uname -r`
62 release=`expr $release : '\(.*\)\..*'`
63 relmajor=`echo $release |sed -e 's/^\([^\.]*\)\..*$/\1/'`
64 relminor=`echo $release |sed -e 's/^.*\.\([^\.]*\)$/\1/'`
65
66 if [ x$reason = xMEDIUM ]; then
67 eval "$ifconfig $interface $medium"
68 $ifconfig $interface
69 sleep 1
70 exit_with_hooks 0
71 fi
72
73 if [ x$reason = xPREINIT ]; then
74 if [ x$alias_ip_address != x ]; then
75 $ifconfig ${interface}:1 0 down > /dev/null 2>&1
76 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
77 fi
78 if [ $relmajor -gt 5 ] || ( [ $relmajor -eq 5 ] && [ $relminor -ge 5 ] )
79 then
80 # Turn the interface on
81 $ifconfig $interface plumb
82 $ifconfig $interface up
83 else
84 $ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
85 broadcast 255.255.255.255 up
86 fi
87 exit_with_hooks 0
88 fi
89
90 if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
91 exit_with_hooks 0;
92 fi
93
94 if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
95 [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
96 current_hostname=`hostname`
97 if [ x$current_hostname = x ] || \
98 [ x$current_hostname = x$old_host_name ]; then
99 if [ x$current_hostname = x ] || \
100 [ x$new_host_name != x$old_host_name ]; then
101 hostname $new_host_name
102 fi
103 fi
104
105 if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
106 [ x$alias_ip_address != x$old_ip_address ]; then
107 $ifconfig ${interface}:1 inet 0 down > /dev/null 2>&1
108 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
109 fi
110 if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then
111 $ifconfig ${interface} inet 0 down
112 route delete $old_ip_address 127.1 >/dev/null 2>&1
113 for router in $old_routers; do
114 route delete default $router >/dev/null 2>&1
115 done
116 fi
117 if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
118 [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
119 eval "$ifconfig $interface inet $new_ip_address $new_netmask_arg \
120 $new_broadcast_arg $medium"
121 route add $new_ip_address 127.1 1 >/dev/null 2>&1
122 for router in $new_routers; do
123 route add default $router 1 >/dev/null 2>&1
124 done
125 fi
126 if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
127 then
128 $ifconfig ${interface}:1 inet $alias_ip_address $alias_subnet_arg
129 route add $alias_ip_address 127.0.0.1 1
130 fi
131 make_resolv_conf
132 exit_with_hooks 0
133 fi
134
135 if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
136 || [ x$reason = xSTOP ]; then
137 if [ x$alias_ip_address != x ]; then
138 $ifconfig ${interface}:1 0 down > /dev/null 2>&1
139 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
140 fi
141 if [ x$old_ip_address != x ]; then
142 $ifconfig $interface inet 0 down
143 route delete $old_ip_address 127.1 >/dev/null 2>&1
144 for router in $old_routers; do
145 route delete default $router >/dev/null 2>&1
146 done
147 fi
148 if [ x$alias_ip_address != x ]; then
149 $ifconfig ${interface}:1 inet $alias_ip_address $alias_subnet_arg
150 route add $alias_ip_address 127.0.0.1 1
151 fi
152 exit_with_hooks 0
153 fi
154
155 if [ x$reason = xTIMEOUT ]; then
156 if [ x$alias_ip_address != x ]; then
157 $ifconfig ${interface}:1 0 down > /dev/null 2>&1
158 route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
159 fi
160 eval "$ifconfig $interface inet $new_ip_address $new_netmask_arg \
161 $new_broadcast_arg $medium"
162 sleep 1
163 set $new_routers
164 if ping -s -n -I 1 $1 64 1; then
165 if [ x$new_ip_address != x$alias_ip_address ] && \
166 [ x$alias_ip_address != x ]; then
167 $ifconfig ${interface}:1 inet $alias_ip_address $alias_subnet_arg
168 route add $alias_ip_address 127.0.0.1 1
169 fi
170 route add $new_ip_address 127.1 1 >/dev/null 2>&1
171 for router in $new_routers; do
172 route add default $router 1 >/dev/null 2>&1
173 done
174 make_resolv_conf
175 exit_with_hooks 0
176 fi
177 $ifconfig $interface inet 0 down
178 for router in $old_routers; do
179 route delete default $router >/dev/null 2>&1
180 done
181 exit_with_hooks 1
182 fi
183
184 exit_with_hooks 0