dhcp: add option specifying overriding custom-routes
[openwrt/staging/chunkeey.git] / package / network / config / netifd / files / lib / netifd / proto / dhcp.sh
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . ../netifd-proto.sh
5 init_proto "$@"
6
7 proto_dhcp_init_config() {
8 renew_handler=1
9
10 proto_config_add_string 'ipaddr:ipaddr'
11 proto_config_add_string 'hostname:hostname'
12 proto_config_add_string clientid
13 proto_config_add_string vendorid
14 proto_config_add_boolean 'broadcast:bool'
15 proto_config_add_string 'reqopts:list(string)'
16 proto_config_add_string iface6rd
17 proto_config_add_string sendopts
18 proto_config_add_boolean delegate
19 proto_config_add_string zone6rd
20 proto_config_add_string zone
21 proto_config_add_string mtu6rd
22 proto_config_add_string customroutes
23 }
24
25 proto_dhcp_setup() {
26 local config="$1"
27 local iface="$2"
28
29 local ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes
30 json_get_vars ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes
31
32 local opt dhcpopts
33 for opt in $reqopts; do
34 append dhcpopts "-O $opt"
35 done
36
37 for opt in $sendopts; do
38 append dhcpopts "-x $opt"
39 done
40
41 [ "$broadcast" = 1 ] && broadcast="-B" || broadcast=
42 [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}" || clientid="-C"
43 [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd"
44 [ "$iface6rd" != 0 -a -f /lib/netifd/proto/6rd.sh ] && append dhcpopts "-O 212"
45 [ -n "$zone6rd" ] && proto_export "ZONE6RD=$zone6rd"
46 [ -n "$zone" ] && proto_export "ZONE=$zone"
47 [ -n "$mtu6rd" ] && proto_export "MTU6RD=$mtu6rd"
48 [ -n "$customroutes" ] && proto_export "CUSTOMROUTES=$customroutes"
49 [ "$delegate" = "0" ] && proto_export "IFACE6RD_DELEGATE=0"
50
51 proto_export "INTERFACE=$config"
52 proto_run_command "$config" udhcpc \
53 -p /var/run/udhcpc-$iface.pid \
54 -s /lib/netifd/dhcp.script \
55 -f -t 0 -i "$iface" \
56 ${ipaddr:+-r $ipaddr} \
57 ${hostname:+-H $hostname} \
58 ${vendorid:+-V $vendorid} \
59 $clientid $broadcast $dhcpopts
60 }
61
62 proto_dhcp_renew() {
63 local interface="$1"
64 # SIGUSR1 forces udhcpc to renew its lease
65 local sigusr1="$(kill -l SIGUSR1)"
66 [ -n "$sigusr1" ] && proto_kill_command "$interface" $sigusr1
67 }
68
69 proto_dhcp_teardown() {
70 local interface="$1"
71 proto_kill_command "$interface"
72 }
73
74 add_protocol dhcp