netifd: Make mtu configurable of dynamic 6rd tunnel interface
[openwrt/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 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 }
23
24 proto_dhcp_setup() {
25 local config="$1"
26 local iface="$2"
27
28 local ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate zone6rd zone mtu6rd
29 json_get_vars ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate zone6rd zone mtu6rd
30
31 local opt dhcpopts
32 for opt in $reqopts; do
33 append dhcpopts "-O $opt"
34 done
35
36 for opt in $sendopts; do
37 append dhcpopts "-x $opt"
38 done
39
40 [ "$broadcast" = 1 ] && broadcast="-B" || broadcast=
41 [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}" || clientid="-C"
42 [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd"
43 [ -n "$iface6rd" ] && append dhcpopts "-O 212"
44 [ -n "$zone6rd" ] && proto_export "ZONE6RD=$zone6rd"
45 [ -n "$zone" ] && proto_export "ZONE=$zone"
46 [ -n "$mtu6rd" ] && proto_export "MTU6RD=$mtu6rd"
47 [ "$delegate" = "0" ] && proto_export "IFACE6RD_DELEGATE=0"
48
49 proto_export "INTERFACE=$config"
50 proto_run_command "$config" udhcpc \
51 -p /var/run/udhcpc-$iface.pid \
52 -s /lib/netifd/dhcp.script \
53 -f -t 0 -i "$iface" \
54 ${ipaddr:+-r $ipaddr} \
55 ${hostname:+-H $hostname} \
56 ${vendorid:+-V $vendorid} \
57 $clientid $broadcast $dhcpopts
58 }
59
60 proto_dhcp_renew() {
61 local interface="$1"
62 # SIGUSR1 forces udhcpc to renew its lease
63 local sigusr1="$(kill -l SIGUSR1)"
64 [ -n "$sigusr1" ] && proto_kill_command "$interface" $sigusr1
65 }
66
67 proto_dhcp_teardown() {
68 local interface="$1"
69 proto_kill_command "$interface"
70 }
71
72 add_protocol dhcp