netifd: pass on delegate flag from dhcp to 6rd
[openwrt.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         proto_config_add_string 'ipaddr:ipaddr'
9         proto_config_add_string 'netmask:ipaddr'
10         proto_config_add_string 'hostname:hostname'
11         proto_config_add_string clientid
12         proto_config_add_string vendorid
13         proto_config_add_boolean 'broadcast:ipaddr'
14         proto_config_add_string 'reqopts:list(string)'
15         proto_config_add_string iface6rd
16         proto_config_add_string sendopts
17         proto_config_add_boolean delegate
18 }
19
20 proto_dhcp_setup() {
21         local config="$1"
22         local iface="$2"
23
24         local ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate
25         json_get_vars ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate
26
27         local opt dhcpopts
28         for opt in $reqopts; do
29                 append dhcpopts "-O $opt"
30         done
31
32         for opt in $sendopts; do
33                 append dhcpopts "-x $opt"
34         done
35
36         [ "$broadcast" = 1 ] && broadcast="-B" || broadcast=
37         [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}" || clientid="-C"
38         [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd"
39         [ "$delegate" = "0" ] && proto_export "IFACE6RD_DELEGATE=0"
40
41         proto_export "INTERFACE=$config"
42         proto_run_command "$config" udhcpc \
43                 -p /var/run/udhcpc-$iface.pid \
44                 -s /lib/netifd/dhcp.script \
45                 -f -t 0 -i "$iface" \
46                 ${ipaddr:+-r $ipaddr} \
47                 ${hostname:+-H $hostname} \
48                 ${vendorid:+-V $vendorid} \
49                 $clientid $broadcast $dhcpopts
50 }
51
52 proto_dhcp_teardown() {
53         local interface="$1"
54         proto_kill_command "$interface"
55 }
56
57 add_protocol dhcp
58