2009-11-06 08:34:19 +05:30
|
|
|
#!/bin/sh
|
|
|
|
# executed by udhcpc
|
|
|
|
# parameters: $1 and environment
|
|
|
|
# $1 is:
|
|
|
|
#
|
2009-11-09 15:34:54 +05:30
|
|
|
# deconfig: udhcpc starts, or lease is lost.
|
|
|
|
# Environment example: interface=eth0
|
2009-11-06 08:34:19 +05:30
|
|
|
#
|
2009-11-09 15:34:54 +05:30
|
|
|
# bound: lease is obtained. Environment example:
|
2009-11-09 14:09:50 +05:30
|
|
|
# dhcptype=5
|
|
|
|
# serverid=172.16.42.102
|
|
|
|
# lease=97200
|
|
|
|
# interface=eth0
|
|
|
|
# ip=172.16.42.177
|
|
|
|
# subnet=255.255.255.0
|
|
|
|
# mask=24
|
|
|
|
# broadcast=172.16.22.255
|
|
|
|
# router=172.16.42.98
|
|
|
|
# dns=10.34.32.125 10.32.63.5 10.34.255.7 10.11.255.27
|
|
|
|
# domain=lab.example.com example.com
|
|
|
|
# ntpsrv=10.34.32.125 10.34.255.7
|
2009-11-09 15:34:54 +05:30
|
|
|
#
|
|
|
|
# renew: lease is renewed. Environment is similar to "bound".
|
2017-04-17 19:43:32 +05:30
|
|
|
# The IP address does not change, however, the other DHCP parameters,
|
2009-11-09 15:34:54 +05:30
|
|
|
# such as the default gateway, subnet mask, and dns server may change.
|
|
|
|
#
|
|
|
|
# nak: udhcpc received a NAK message.
|
|
|
|
# Environment example: interface=eth0
|
|
|
|
#
|
|
|
|
# leasefail: udhcpc cannot obtain a lease (DHCP server not responding, etc).
|
|
|
|
# Environment example: interface=eth0
|
2009-11-06 08:34:19 +05:30
|
|
|
|
2009-11-09 15:34:54 +05:30
|
|
|
# TODO: put $domain into /etc/resolv.conf (thru /var/service/fw)
|
2009-11-06 08:34:19 +05:30
|
|
|
|
2009-11-09 14:09:50 +05:30
|
|
|
service=${PWD##*/}
|
|
|
|
file_ipconf="$service.ipconf"
|
|
|
|
file_ntpconf="$service.ntpconf"
|
|
|
|
dir_ipconf="/var/run/service/fw"
|
2015-10-24 18:25:33 +05:30
|
|
|
dir_ntpconf="/var/run/service/ntpd"
|
2009-11-06 08:34:19 +05:30
|
|
|
|
2009-11-09 14:09:50 +05:30
|
|
|
exec >/dev/null
|
|
|
|
#exec >>"$0.out" #debug
|
|
|
|
exec 2>&1
|
2009-11-06 08:34:19 +05:30
|
|
|
|
|
|
|
echo "`date`: Params: $*"
|
|
|
|
|
|
|
|
if test x"$1" != x"bound" && test x"$1" != x"renew" ; then
|
|
|
|
# Reconfigure network with this interface disabled
|
|
|
|
echo "Deconfiguring"
|
2015-10-24 18:25:33 +05:30
|
|
|
rm "env.out"
|
2009-11-09 14:09:50 +05:30
|
|
|
rm "$file_ipconf"
|
|
|
|
rm "$file_ntpconf"
|
|
|
|
rm "$dir_ipconf/$file_ipconf"
|
|
|
|
rm "$dir_ntpconf/$file_ntpconf"
|
2009-11-06 08:34:19 +05:30
|
|
|
sv u /var/service/fw
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Bound: we've got the lease
|
2015-10-24 18:25:33 +05:30
|
|
|
# Record information for e.g. dhcp_$IF_pinger service
|
|
|
|
env >"env.out"
|
2009-11-06 08:34:19 +05:30
|
|
|
|
2009-11-09 15:34:54 +05:30
|
|
|
./convert2ipconf "$file_ipconf"
|
2009-11-06 08:34:19 +05:30
|
|
|
# Reconfigure routing and firewall if needed
|
2009-11-09 14:09:50 +05:30
|
|
|
diff --brief "$file_ipconf" "$dir_ipconf/$file_ipconf" >/dev/null 2>&1
|
2009-11-09 15:34:54 +05:30
|
|
|
if test $? != 0; then
|
2009-11-09 14:09:50 +05:30
|
|
|
echo "Reconfiguring fw"
|
|
|
|
mkdir -p "$dir_ipconf" 2>/dev/null
|
|
|
|
cp "$file_ipconf" "$dir_ipconf/$file_ipconf"
|
2009-11-06 08:34:19 +05:30
|
|
|
sv u /var/service/fw
|
|
|
|
fi
|
2009-11-09 14:09:50 +05:30
|
|
|
|
2015-10-24 18:25:33 +05:30
|
|
|
if test -d /var/service/ntpd; then
|
2009-11-09 15:34:54 +05:30
|
|
|
./convert2ntpconf "$file_ntpconf"
|
|
|
|
# Reconfigure ntp server addresses if needed
|
|
|
|
diff --brief "$file_ntpconf" "$dir_ntpconf/$file_ntpconf" >/dev/null 2>&1
|
|
|
|
if test $? != 0; then
|
|
|
|
echo "Reconfiguring ntp"
|
|
|
|
mkdir -p "$dir_ntpconf" 2>/dev/null
|
|
|
|
cp "$file_ntpconf" "$dir_ntpconf/$file_ntpconf"
|
2015-10-24 18:25:33 +05:30
|
|
|
sv t /var/service/ntpd
|
|
|
|
sv u /var/service/ntpd
|
2009-11-09 15:34:54 +05:30
|
|
|
fi
|
2009-11-09 14:09:50 +05:30
|
|
|
fi
|