blob: e4c1f2d76429eadfb129f817838194aaf12cd785 [file] [log] [blame]
Russ Dill61fb4892002-10-14 21:41:28 +00001#!/bin/sh
Russ Dill61fb4892002-10-14 21:41:28 +00002# udhcpc script edited by Tim Riker <Tim@Rikers.org>
3
Russ Dill61fb4892002-10-14 21:41:28 +00004RESOLV_CONF="/etc/resolv.conf"
Denis Vlasenko1b47bbd2009-04-21 00:17:00 +00005
Denys Vlasenkoc8ab67c2009-05-10 23:27:43 +02006[ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
Denis Vlasenko1b47bbd2009-04-21 00:17:00 +00007
Denis Vlasenkoea4f0842009-04-16 20:04:09 +00008NETMASK=""
Russ Dill61fb4892002-10-14 21:41:28 +00009[ -n "$subnet" ] && NETMASK="netmask $subnet"
Denis Vlasenkoea4f0842009-04-16 20:04:09 +000010BROADCAST="broadcast +"
11[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
Russ Dill61fb4892002-10-14 21:41:28 +000012
13case "$1" in
14 deconfig)
Denis Vlasenkoea4f0842009-04-16 20:04:09 +000015 echo "Setting IP address 0.0.0.0 on $interface"
16 ifconfig $interface 0.0.0.0
Russ Dill61fb4892002-10-14 21:41:28 +000017 ;;
18
19 renew|bound)
Denis Vlasenkoea4f0842009-04-16 20:04:09 +000020 echo "Setting IP address $ip on $interface"
21 ifconfig $interface $ip $NETMASK $BROADCAST
Russ Dill61fb4892002-10-14 21:41:28 +000022
23 if [ -n "$router" ] ; then
Denis Vlasenkoea4f0842009-04-16 20:04:09 +000024 echo "Deleting routers"
Russ Dill61fb4892002-10-14 21:41:28 +000025 while route del default gw 0.0.0.0 dev $interface ; do
26 :
27 done
28
Eric Andersen1aee3ff2004-10-13 07:18:05 +000029 metric=0
Russ Dill61fb4892002-10-14 21:41:28 +000030 for i in $router ; do
Denis Vlasenkoea4f0842009-04-16 20:04:09 +000031 echo "Adding router $i"
Denys Vlasenko9c192e72017-04-06 00:53:43 +020032 if [ "$subnet" = "255.255.255.255" ]; then
33 # special case for /32 subnets:
34 # /32 instructs kernel to always use routing for all outgoing packets
35 # (they can never be sent to local subnet - there is no local subnet for /32).
36 # Used in datacenters, avoids the need for private ip-addresses between two hops.
37 ip route add $i dev $interface
38 fi
39 route add default gw $i dev $interface metric $((metric++))
Russ Dill61fb4892002-10-14 21:41:28 +000040 done
41 fi
42
Denis Vlasenkoea4f0842009-04-16 20:04:09 +000043 echo "Recreating $RESOLV_CONF"
Mike Frysinger39b8fb42013-02-27 01:01:43 -050044 # If the file is a symlink somewhere (like /etc/resolv.conf
45 # pointing to /run/resolv.conf), make sure things work.
Mike Frysingerbca5c552013-03-12 10:48:09 -040046 realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF")
Mike Frysinger39b8fb42013-02-27 01:01:43 -050047 tmpfile="$realconf-$$"
48 > "$tmpfile"
49 [ -n "$domain" ] && echo "search $domain" >> "$tmpfile"
Russ Dill61fb4892002-10-14 21:41:28 +000050 for i in $dns ; do
Denis Vlasenkoea4f0842009-04-16 20:04:09 +000051 echo " Adding DNS server $i"
Mike Frysinger39b8fb42013-02-27 01:01:43 -050052 echo "nameserver $i" >> "$tmpfile"
Russ Dill61fb4892002-10-14 21:41:28 +000053 done
Mike Frysinger39b8fb42013-02-27 01:01:43 -050054 mv "$tmpfile" "$realconf"
Russ Dill61fb4892002-10-14 21:41:28 +000055 ;;
56esac
57
58exit 0