93f4a5e09a5cf0b9fe4be98811ff519a69325c80
[openwrt/staging/wigyori.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 proto_config_add_string zone6rd
19 }
20
21 proto_dhcp_setup() {
22 local config="$1"
23 local iface="$2"
24
25 local ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate zone6rd
26 json_get_vars ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate zone6rd
27
28 local opt dhcpopts
29 for opt in $reqopts; do
30 append dhcpopts "-O $opt"
31 done
32
33 for opt in $sendopts; do
34 append dhcpopts "-x $opt"
35 done
36
37 [ "$broadcast" = 1 ] && broadcast="-B" || broadcast=
38 [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}" || clientid="-C"
39 [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd"
40 [ -n "$iface6rd" ] && append dhcpopts "-O 212"
41 [ -n "$zone6rd" ] && proto_export "ZONE6RD=$zone6rd"
42 [ "$delegate" = "0" ] && proto_export "IFACE6RD_DELEGATE=0"
43
44 proto_export "INTERFACE=$config"
45 proto_run_command "$config" udhcpc \
46 -p /var/run/udhcpc-$iface.pid \
47 -s /lib/netifd/dhcp.script \
48 -f -t 0 -i "$iface" \
49 ${ipaddr:+-r $ipaddr} \
50 ${hostname:+-H $hostname} \
51 ${vendorid:+-V $vendorid} \
52 $clientid $broadcast $dhcpopts
53 }
54
55 proto_dhcp_teardown() {
56 local interface="$1"
57 proto_kill_command "$interface"
58 }
59
60 add_protocol dhcp
61