-
Notifications
You must be signed in to change notification settings - Fork 5
/
default.script
executable file
·66 lines (55 loc) · 1.69 KB
/
default.script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
RESOLV_CONF="/etc/resolv.conf"
log() {
logger -t "uchcpc[$PPID]" -p daemon.$1 "$interface: $2"
}
case $1 in
bound|renew)
# Configure new IP address.
# Do it unconditionally even if the address hasn't changed,
# to also set subnet, broadcast, mtu, ...
busybox ifconfig $interface ${mtu:+mtu $mtu} \
$ip netmask $subnet ${broadcast:+broadcast $broadcast}
# get current ("old") routes (after setting new IP)
crouter=$(busybox ip -4 route show dev $interface |
busybox awk '$1 == "default" { print $3; }')
router="${router%% *}" # linux kernel supports only one (default) route
if [ ".$router" != ".$crouter" ]; then
# reset just default routes
busybox ip -4 route flush exact 0.0.0.0/0 dev $interface
fi
if [ -n "$router" ]; then
# special case for /32 subnets: use onlink keyword
[ ".$subnet" = .255.255.255.255 ] \
&& onlink=onlink || onlink=
busybox ip -4 route add default via $router dev $interface $onlink
fi
# Update resolver configuration file
[ -n "$domain" ] && R="domain $domain" || R=""
for i in $dns; do
R="$R
nameserver $i"
done
if [ -x /sbin/resolvconf ]; then
echo "$R" | resolvconf -a "$interface.udhcpc"
else
echo "$R" > "$RESOLV_CONF"
fi
log info "$1: IP=$ip/$subnet router=$router domain=\"$domain\" dns=\"$dns\" lease=$lease"
;;
deconfig)
busybox ip link set $interface up
busybox ip -4 addr flush dev $interface
busybox ip -4 route flush dev $interface
[ -x /sbin/resolvconf ] &&
resolvconf -d "$interface.udhcpc"
log notice "deconfigured"
;;
leasefail | nak)
log err "configuration failed: $1: $message"
;;
*)
echo "$0: Unknown udhcpc command: $1" >&2
exit 1
;;
esac