Project

General

Profile

Download (7.48 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/sh
2
#
3
# $Id$
4
#
5
# $FreeBSD: src/contrib/isc-dhcp/client/scripts/freebsd,v 1.9.2.6 2003/03/02 16:42:38 murray Exp $
6

    
7
if [ -x /usr/bin/logger ]; then
8
        LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
9
else
10
        LOGGER=echo
11
fi
12

    
13
make_resolv_conf() {
14
  if [ x"$new_domain_name_servers" != x ]; then
15
    if [ "x$new_domain_name" != x ]; then
16
      echo $new_domain_name >/var/etc/defaultdomain.conf
17
    else
18
      rm -f /var/etc/defaultdomain.conf
19
    fi
20
    rm -f /var/etc/nameservers.conf
21
    for nameserver in $new_domain_name_servers; do
22
      echo $nameserver >>/var/etc/nameservers.conf
23
    done
24
  fi
25
}
26

    
27
# Must be used on exit.   Invokes the local dhcp client exit hooks, if any.
28
exit_with_hooks() {
29
  exit_status=$1
30
  if [ -f /etc/dhclient-exit-hooks ]; then
31
    . /etc/dhclient-exit-hooks
32
  fi
33
# probably should do something with exit status of the local script
34
  exit $exit_status
35
}
36

    
37
# Invoke the local dhcp client enter hooks, if they exist.
38
if [ -f /etc/dhclient-enter-hooks ]; then
39
  exit_status=0
40
  . /etc/dhclient-enter-hooks
41
  # allow the local script to abort processing of this state
42
  # local script must set exit_status variable to nonzero.
43
  if [ $exit_status -ne 0 ]; then
44
    exit $exit_status
45
  fi
46
fi
47

    
48
if [ x$new_network_number != x ]; then
49
   $LOGGER New Network Number: $new_network_number
50
fi
51

    
52
if [ x$new_broadcast_address != x ]; then
53
 $LOGGER New Broadcast Address: $new_broadcast_address
54
  new_broadcast_arg="broadcast $new_broadcast_address"
55
fi
56
if [ x$old_broadcast_address != x ]; then
57
  old_broadcast_arg="broadcast $old_broadcast_address"
58
fi
59
if [ x$new_subnet_mask != x ]; then
60
  new_netmask_arg="netmask $new_subnet_mask"
61
fi
62
if [ x$old_subnet_mask != x ]; then
63
  old_netmask_arg="netmask $old_subnet_mask"
64
fi
65
if [ x$alias_subnet_mask != x ]; then
66
  alias_subnet_arg="netmask $alias_subnet_mask"
67
fi
68

    
69
if [ x$reason = xMEDIUM ]; then
70
  eval "ifconfig $interface $medium"
71
  eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
72
  sleep 1
73
  exit 0
74
fi
75

    
76
if [ x$reason = xPREINIT ]; then
77
  if [ x$alias_ip_address != x ]; then
78
    ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
79
    route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
80
  fi
81
  ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
82
                broadcast 255.255.255.255 up
83
  exit 0
84
fi
85

    
86
if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then
87
  exit 0;
88
fi
89

    
90
if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \
91
   [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then
92
  current_hostname=`/bin/hostname`
93
  if [ x$current_hostname = x ] || \
94
     [ x$current_hostname = x$old_host_name ]; then
95
    if [ x$current_hostname = x ] || \
96
       [ x$new_host_name != x$old_host_name ]; then
97
      $LOGGER "New Hostname: $new_host_name"
98
      hostname $new_host_name
99
    fi
100
  fi
101
  if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \
102
                [ x$alias_ip_address != x$old_ip_address ]; then
103
    ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
104
    route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
105
  fi
106
  if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]
107
   then
108
    eval "ifconfig $interface inet -alias $old_ip_address $medium"
109
    route delete $old_ip_address 127.1 >/dev/null 2>&1
110
    for router in $old_routers; do
111
      route delete default $router >/dev/null 2>&1
112
    done
113
    if [ -n "$old_static_routes" ]; then
114
      set -- $old_static_routes
115
      while [ $# -gt 1 ]; do
116
        route delete $1 $2
117
        shift; shift
118
      done
119
    fi
120
    arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' |sh
121
  fi
122
  if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \
123
     [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then
124
    eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
125
                                        $new_broadcast_arg $medium"
126
    $LOGGER "New IP Address ($interface): $new_ip_address"
127
    $LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
128
    $LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
129
    if [ -n "$new_routers" ]; then
130
      $LOGGER "New Routers: $new_routers"
131
      echo $new_routers > /tmp/${interface}_router
132
    fi
133
    route add $new_ip_address 127.1 >/dev/null 2>&1
134
    for router in $new_routers; do
135
      route add default $router >/dev/null 2>&1
136
    done
137
    if [ -n "$new_static_routes" ]; then
138
      $LOGGER "New Static Routes: $new_static_routes"
139
      set -- $new_static_routes
140
      while [ $# -gt 1 ]; do
141
        route add $1 $2
142
        shift; shift
143
      done
144
    fi
145
  fi
146
  if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ];
147
   then
148
    ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
149
    route add $alias_ip_address 127.0.0.1
150
  fi
151
  make_resolv_conf
152
  exit_with_hooks 0
153
fi
154

    
155
if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \
156
   || [ x$reason = xSTOP ]; then
157
  if [ x$alias_ip_address != x ]; then
158
    ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
159
    route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
160
  fi
161
  if [ x$old_ip_address != x ]; then
162
    eval "ifconfig $interface inet -alias $old_ip_address $medium"
163
    route delete $old_ip_address 127.1 >/dev/null 2>&1
164
    for router in $old_routers; do
165
      route delete default $router >/dev/null 2>&1
166
    done
167
    if [ -n "$old_static_routes" ]; then
168
      set -- $old_static_routes
169
      while [ $# -gt 1 ]; do
170
        route delete $1 $2
171
        shift; shift
172
      done
173
    fi
174
    arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \
175
                                                |sh >/dev/null 2>&1
176
  fi
177
  if [ x$alias_ip_address != x ]; then
178
    ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
179
    route add $alias_ip_address 127.0.0.1
180
  fi
181
  exit_with_hooks 0
182
fi
183

    
184
if [ x$reason = xTIMEOUT ]; then
185
  if [ x$alias_ip_address != x ]; then
186
    ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
187
    route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
188
  fi
189
  eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
190
                                        $new_broadcast_arg $medium"
191
  $LOGGER "New IP Address ($interface): $new_ip_address"
192
  $LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
193
  $LOGGER "New Broadcast Address ($interface): $new_broadcast_address"
194
  sleep 1
195
  if [ -n "$new_routers" ]; then
196
    $LOGGER "New Routers: $new_routers"
197
    echo $new_routers > /tmp/${interface}_router
198
    set -- $new_routers
199
    if ping -q -c 1 $1; then
200
      if [ x$new_ip_address != x$alias_ip_address ] && \
201
                        [ x$alias_ip_address != x ]; then
202
        ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg
203
        route add $alias_ip_address 127.0.0.1
204
      fi
205
      route add $new_ip_address 127.1 >/dev/null 2>&1
206
      for router in $new_routers; do
207
        route add default $router >/dev/null 2>&1
208
      done
209
      set -- $new_static_routes
210
      while [ $# -gt 1 ]; do
211
        route add $1 $2
212
        shift; shift
213
      done
214
      make_resolv_conf
215
      exit_with_hooks 0
216
    fi
217
  fi
218
  eval "ifconfig $interface inet -alias $new_ip_address $medium"
219
  for router in $old_routers; do
220
    route delete default $router >/dev/null 2>&1
221
  done
222
  if [ -n "$old_static_routes" ]; then
223
    set -- $old_static_routes
224
    while [ $# -gt 1 ]; do
225
      route delete $1 $2
226
      shift; shift
227
    done
228
  fi
229
  arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \
230
                                                        |sh >/dev/null 2>&1
231
  exit_with_hooks 1
232
fi
233

    
234
exit_with_hooks 0
    (1-1/1)