make network config script work with brctl from both bridge-utils & busybox
[openwrt.git] / package / base-files / files / usr / share / udhcpc / default.script
1 #!/bin/sh
2 [ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
3 . /etc/functions.sh
4 include /lib/network
5
6 RESOLV_CONF="/tmp/resolv.conf.auto"
7
8 hotplug_event() {
9 scan_interfaces
10 for ifc in $interfaces; do
11 config_get ifname $ifc ifname
12 [ "$ifname" = "$interface" ] || continue
13
14 config_get proto $ifc proto
15 [ "$proto" = "dhcp" ] || continue
16 [ ifup = "$1" ] && {
17 uci_set_state network "$ifc" ipaddr "$ip"
18 uci_set_state network "$ifc" netmask "${subnet:-255.255.255.0}"
19 uci_set_state network "$ifc" dnsdomain "$domain"
20 uci_set_state network "$ifc" dns "$dns"
21 uci_set_state network "$ifc" gateway "$router"
22 }
23 env -i ACTION="$1" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug-call iface
24 done
25 }
26
27 case "$1" in
28 deconfig)
29 ifconfig $interface 0.0.0.0
30 hotplug_event ifdown
31 ;;
32 renew|bound)
33 ifconfig $interface $ip \
34 netmask ${subnet:-255.255.255.0} \
35 broadcast ${broadcast:-+}
36
37 [ -n "$router" ] && {
38 for i in $router ; do
39 echo "adding router $i"
40 route add default gw $i dev $interface
41 valid="$valid|$i"
42
43 done
44
45 echo "deleting old routes"
46 $(route -n | awk '/^0.0.0.0\W{9}('$valid')\W/ {next} /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}')
47 }
48
49 [ -n "$dns" ] && {
50 echo -n > "${RESOLV_CONF}.tmp"
51 ${domain:+echo search $domain} >> "${RESOLV_CONF}.tmp"
52 for i in $dns ; do
53 echo "adding dns $i"
54 echo "nameserver $i" >> "${RESOLV_CONF}.tmp"
55 done
56 mv "${RESOLV_CONF}.tmp" "$RESOLV_CONF"
57 }
58
59 if [ "$1" = "renew" ]; then
60 hotplug_event update
61 else
62 hotplug_event ifup
63 fi
64
65 # user rules
66 [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
67 ;;
68 esac
69
70 exit 0
This page took 0.043026 seconds and 5 git commands to generate.