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