80c3562e69a36e380738ab6af68f53411fe86867
[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 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 [ -n "$iface6rd" ] && append dhcpopts "-O 212"
40 [ "$delegate" = "0" ] && proto_export "IFACE6RD_DELEGATE=0"
41
42 proto_export "INTERFACE=$config"
43 proto_run_command "$config" udhcpc \
44 -p /var/run/udhcpc-$iface.pid \
45 -s /lib/netifd/dhcp.script \
46 -f -t 0 -i "$iface" \
47 ${ipaddr:+-r $ipaddr} \
48 ${hostname:+-H $hostname} \
49 ${vendorid:+-V $vendorid} \
50 $clientid $broadcast $dhcpopts
51 }
52
53 proto_dhcp_teardown() {
54 local interface="$1"
55 proto_kill_command "$interface"
56 }
57
58 add_protocol dhcp
59