netifd: fix fw3 warnings in dhcp script
[openwrt/staging/lynxis/omap.git] / package / network / config / netifd / files / lib / netifd / dhcp.script
1 #!/bin/sh
2 [ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
3
4 . /lib/functions.sh
5 . /lib/netifd/netifd-proto.sh
6
7 set_classless_routes() {
8 local max=128
9 while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
10 proto_add_ipv4_route "${1%%/*}" "${1##*/}" "$2" "$ip"
11 max=$(($max-1))
12 shift 2
13 done
14 }
15
16 setup_interface () {
17 proto_init_update "*" 1
18 proto_add_ipv4_address "$ip" "${subnet:-255.255.255.0}"
19 # TODO: apply $broadcast
20
21 for i in $router; do
22 proto_add_ipv4_route "$i" 32 "" "$ip"
23 proto_add_ipv4_route 0.0.0.0 0 "$i" "$ip"
24
25 for r in $CUSTOMROUTES; do
26 proto_add_ipv4_route "${r%%/*}" "${r##*/}" "$i" "$ip"
27 done
28 done
29
30 # CIDR STATIC ROUTES (rfc3442)
31 [ -n "$staticroutes" ] && set_classless_routes $staticroutes
32 [ -n "$msstaticroutes" ] && set_classless_routes $msstaticroutes
33
34 for dns in $dns; do
35 proto_add_dns_server "$dns"
36 done
37 for domain in $domain; do
38 proto_add_dns_search "$domain"
39 done
40
41 proto_add_data
42 [ -n "$ZONE" ] && json_add_string zone "$ZONE"
43 [ -n "$ntpsrv" ] && json_add_string ntpserver "$ntpsrv"
44 [ -n "$timesvr" ] && json_add_string timeserver "$timesvr"
45 [ -n "$hostname" ] && json_add_string hostname "$hostname"
46 [ -n "$message" ] && json_add_string message "$message"
47 [ -n "$timezone" ] && json_add_int timezone "$timezone"
48 [ -n "$lease" ] && json_add_int leasetime "$lease"
49 proto_close_data
50
51 proto_send_update "$INTERFACE"
52
53
54 if [ "$IFACE6RD" != 0 -a -n "$ip6rd" ]; then
55 local v4mask="${ip6rd%% *}"
56 ip6rd="${ip6rd#* }"
57 local ip6rdprefixlen="${ip6rd%% *}"
58 ip6rd="${ip6rd#* }"
59 local ip6rdprefix="${ip6rd%% *}"
60 ip6rd="${ip6rd#* }"
61 local ip6rdbr="${ip6rd%% *}"
62
63 [ -n "$ZONE" ] || ZONE=$(fw3 -q network $INTERFACE 2>/dev/null)
64 [ -z "$IFACE6RD" -o "$IFACE6RD" = 1 ] && IFACE6RD=${INTERFACE}_6
65
66 json_init
67 json_add_string name "$IFACE6RD"
68 json_add_string ifname "@$INTERFACE"
69 json_add_string proto "6rd"
70 json_add_string peeraddr "$ip6rdbr"
71 json_add_int ip4prefixlen "$v4mask"
72 json_add_string ip6prefix "$ip6rdprefix"
73 json_add_int ip6prefixlen "$ip6rdprefixlen"
74 json_add_string tunlink "$INTERFACE"
75 [ -n "$IFACE6RD_DELEGATE" ] && json_add_boolean delegate "$IFACE6RD_DELEGATE"
76 [ -n "$ZONE6RD" ] || ZONE6RD=$ZONE
77 [ -n "$ZONE6RD" ] && json_add_string zone "$ZONE6RD"
78 [ -n "$MTU6RD" ] && json_add_string mtu "$MTU6RD"
79 json_close_object
80
81 ubus call network add_dynamic "$(json_dump)"
82 fi
83 }
84
85 deconfig_interface() {
86 proto_init_update "*" 0
87 proto_send_update "$INTERFACE"
88 }
89
90 case "$1" in
91 deconfig)
92 deconfig_interface
93 ;;
94 renew|bound)
95 setup_interface
96 ;;
97 esac
98
99 # user rules
100 [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user "$@"
101
102 exit 0