2002-11-15 03:55:17 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# udhcpc script edited by Tim Riker <Tim@Rikers.org>
|
|
|
|
|
|
|
|
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
|
|
|
|
|
|
|
|
RESOLV_CONF="/etc/resolv.conf"
|
2014-01-15 20:04:58 +01:00
|
|
|
[ -e $RESOLV_CONF ] || touch $RESOLV_CONF
|
2002-11-15 03:55:17 +01:00
|
|
|
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
|
|
|
|
[ -n "$subnet" ] && NETMASK="netmask $subnet"
|
2019-05-21 04:54:27 +02:00
|
|
|
# Handle stateful DHCPv6 like DHCPv4
|
|
|
|
[ -n "$ipv6" ] && ip="$ipv6/128"
|
2002-11-15 03:55:17 +01:00
|
|
|
|
2019-05-21 04:54:28 +02:00
|
|
|
if [ -z "${IF_WAIT_DELAY}" ]; then
|
|
|
|
IF_WAIT_DELAY=10
|
|
|
|
fi
|
|
|
|
|
|
|
|
wait_for_ipv6_default_route() {
|
|
|
|
printf "Waiting for IPv6 default route to appear"
|
|
|
|
while [ $IF_WAIT_DELAY -gt 0 ]; do
|
2021-02-02 02:54:52 +01:00
|
|
|
if ip -6 route list | grep -q default; then
|
2019-05-21 04:54:28 +02:00
|
|
|
printf "\n"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
printf "."
|
|
|
|
: $((IF_WAIT_DELAY -= 1))
|
|
|
|
done
|
|
|
|
printf " timeout!\n"
|
|
|
|
}
|
|
|
|
|
2002-11-15 03:55:17 +01:00
|
|
|
case "$1" in
|
|
|
|
deconfig)
|
2013-06-26 14:29:19 +02:00
|
|
|
/sbin/ifconfig $interface up
|
|
|
|
/sbin/ifconfig $interface 0.0.0.0
|
|
|
|
|
2013-06-26 15:01:46 +02:00
|
|
|
# drop info from this interface
|
|
|
|
# resolv.conf may be a symlink to /tmp/, so take care
|
|
|
|
TMPFILE=$(mktemp)
|
|
|
|
grep -vE "# $interface\$" $RESOLV_CONF > $TMPFILE
|
|
|
|
cat $TMPFILE > $RESOLV_CONF
|
|
|
|
rm -f $TMPFILE
|
|
|
|
|
2013-06-26 14:22:13 +02:00
|
|
|
if [ -x /usr/sbin/avahi-autoipd ]; then
|
2020-07-23 19:19:17 +02:00
|
|
|
/usr/sbin/avahi-autoipd -c $interface && /usr/sbin/avahi-autoipd -k $interface
|
2013-06-26 14:22:13 +02:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
leasefail|nak)
|
|
|
|
if [ -x /usr/sbin/avahi-autoipd ]; then
|
2020-07-23 19:19:17 +02:00
|
|
|
/usr/sbin/avahi-autoipd -c $interface || /usr/sbin/avahi-autoipd -wD $interface --no-chroot
|
2013-06-26 14:22:13 +02:00
|
|
|
fi
|
2002-11-15 03:55:17 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
renew|bound)
|
2013-06-26 14:22:13 +02:00
|
|
|
if [ -x /usr/sbin/avahi-autoipd ]; then
|
2020-07-23 19:19:17 +02:00
|
|
|
/usr/sbin/avahi-autoipd -c $interface && /usr/sbin/avahi-autoipd -k $interface
|
2013-06-26 14:22:13 +02:00
|
|
|
fi
|
2002-11-15 03:55:17 +01:00
|
|
|
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
|
2019-05-21 04:54:28 +02:00
|
|
|
if [ -n "$ipv6" ] ; then
|
|
|
|
wait_for_ipv6_default_route
|
|
|
|
fi
|
2002-11-15 03:55:17 +01:00
|
|
|
|
2020-09-21 18:20:02 +02:00
|
|
|
# RFC3442: If the DHCP server returns both a Classless
|
|
|
|
# Static Routes option and a Router option, the DHCP
|
|
|
|
# client MUST ignore the Router option.
|
|
|
|
if [ -n "$staticroutes" ]; then
|
|
|
|
echo "deleting routers"
|
|
|
|
route -n | while read dest gw mask flags metric ref use iface; do
|
|
|
|
[ "$iface" != "$interface" -o "$gw" = "0.0.0.0" ] || \
|
|
|
|
route del -net "$dest" netmask "$mask" gw "$gw" dev "$interface"
|
|
|
|
done
|
|
|
|
|
|
|
|
# format: dest1/mask gw1 ... destn/mask gwn
|
|
|
|
set -- $staticroutes
|
|
|
|
while [ -n "$1" -a -n "$2" ]; do
|
|
|
|
route add -net "$1" gw "$2" dev "$interface"
|
|
|
|
shift 2
|
|
|
|
done
|
|
|
|
elif [ -n "$router" ] ; then
|
2002-11-15 03:55:17 +01:00
|
|
|
echo "deleting routers"
|
2014-01-16 08:58:33 +01:00
|
|
|
while route del default gw 0.0.0.0 dev $interface 2> /dev/null; do
|
2002-11-15 03:55:17 +01:00
|
|
|
:
|
|
|
|
done
|
|
|
|
|
|
|
|
for i in $router ; do
|
|
|
|
route add default gw $i dev $interface
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2013-06-26 15:01:46 +02:00
|
|
|
# drop info from this interface
|
|
|
|
# resolv.conf may be a symlink to /tmp/, so take care
|
|
|
|
TMPFILE=$(mktemp)
|
|
|
|
grep -vE "# $interface\$" $RESOLV_CONF > $TMPFILE
|
|
|
|
cat $TMPFILE > $RESOLV_CONF
|
|
|
|
rm -f $TMPFILE
|
|
|
|
|
2019-08-03 17:54:30 +02:00
|
|
|
# prefer rfc3397 domain search list (option 119) if available
|
2016-03-31 09:34:43 +02:00
|
|
|
if [ -n "$search" ]; then
|
|
|
|
search_list=$search
|
|
|
|
elif [ -n "$domain" ]; then
|
|
|
|
search_list=$domain
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -n "$search_list" ] &&
|
|
|
|
echo "search $search_list # $interface" >> $RESOLV_CONF
|
|
|
|
|
2002-11-15 03:55:17 +01:00
|
|
|
for i in $dns ; do
|
|
|
|
echo adding dns $i
|
2013-06-26 15:01:46 +02:00
|
|
|
echo "nameserver $i # $interface" >> $RESOLV_CONF
|
2002-11-15 03:55:17 +01:00
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2014-06-17 07:21:47 +02:00
|
|
|
HOOK_DIR="$0.d"
|
|
|
|
for hook in "${HOOK_DIR}/"*; do
|
|
|
|
[ -f "${hook}" -a -x "${hook}" ] || continue
|
|
|
|
"${hook}" "${@}"
|
|
|
|
done
|
|
|
|
|
2002-11-15 03:55:17 +01:00
|
|
|
exit 0
|