6rd / ds-lite: make the firewall-zones of nested-protocols configurable
[openwrt/openwrt.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 local type
10 while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
11 proto_add_ipv4_route "${1%%/*}" "${1##*/}" "$2"
12 max=$(($max-1))
13 shift 2
14 done
15 }
16
17 setup_interface () {
18 proto_init_update "*" 1
19 proto_add_ipv4_address "$ip" "${subnet:-255.255.255.0}"
20 # TODO: apply $broadcast
21
22 for i in $router; do
23 proto_add_ipv4_route 0.0.0.0 0 "$i"
24 done
25
26 # CIDR STATIC ROUTES (rfc3442)
27 [ -n "$staticroutes" ] && set_classless_routes $staticroutes
28 [ -n "$msstaticroutes" ] && set_classless_routes $msstaticroutes
29
30 for dns in $dns; do
31 proto_add_dns_server "$dns"
32 done
33 for domain in $domain; do
34 proto_add_dns_search "$domain"
35 done
36 proto_send_update "$INTERFACE"
37
38 if [ -n "$IFACE6RD" -a -n "$ip6rd" ]; then
39 local v4mask="${ip6rd%% *}"
40 ip6rd="${ip6rd#* }"
41 local ip6rdprefixlen="${ip6rd%% *}"
42 ip6rd="${ip6rd#* }"
43 local ip6rdprefix="${ip6rd%% *}"
44 ip6rd="${ip6rd#* }"
45 local ip6rdbr="${ip6rd%% *}"
46
47 json_init
48 json_add_string name "$IFACE6RD"
49 json_add_string ifname "@$INTERFACE"
50 json_add_string proto "6rd"
51 json_add_string peeraddr "$ip6rdbr"
52 json_add_int ip4prefixlen "$v4mask"
53 json_add_string ip6prefix "$ip6rdprefix"
54 json_add_int ip6prefixlen "$ip6rdprefixlen"
55 json_add_string tunlink "$INTERFACE"
56 [ -n "$IFACE6RD_DELEGATE" ] && json_add_boolean delegate "$IFACE6RD_DELEGATE"
57 [ -n "$ZONE6RD" ] && json_add_string zone "$ZONE6RD"
58 json_close_object
59
60 ubus call network add_dynamic "$(json_dump)"
61 fi
62
63 # TODO
64 # [ -n "$ntpsrv" ] && change_state network "$ifc" lease_ntpsrv "$ntpsrv"
65 # [ -n "$timesvr" ] && change_state network "$ifc" lease_timesrv "$timesvr"
66 # [ -n "$hostname" ] && change_state network "$ifc" lease_hostname "$hostname"
67 # [ -n "$timezone" ] && change_state network "$ifc" lease_timezone "$timezone"
68 }
69
70 deconfig_interface() {
71 proto_init_update "*" 0
72 proto_send_update "$INTERFACE"
73 }
74
75 case "$1" in
76 deconfig)
77 deconfig_interface
78 ;;
79 renew|bound)
80 setup_interface
81 ;;
82 esac
83
84 # user rules
85 [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
86
87 exit 0