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