0117b27ff851d56b84df529171f5bd36e30377bc
[openwrt/svn-archive/archive.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"
9 proto_config_add_string "netmask"
10 proto_config_add_string "hostname"
11 proto_config_add_string "clientid"
12 proto_config_add_string "vendorid"
13 proto_config_add_boolean "broadcast"
14 proto_config_add_string "reqopts"
15 proto_config_add_string "iface6rd"
16 proto_config_add_string "sendopts"
17 }
18
19 proto_dhcp_setup() {
20 local config="$1"
21 local iface="$2"
22
23 local ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts
24 json_get_vars ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts
25
26 local opt dhcpopts
27 for opt in $reqopts; do
28 append dhcpopts "-O $opt"
29 done
30
31 for opt in $sendopts; do
32 append dhcpopts "-x $opt"
33 done
34
35 [ "$broadcast" = 1 ] && broadcast="-B" || broadcast=
36 [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}" || clientid="-C"
37 [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd"
38
39 proto_export "INTERFACE=$config"
40 proto_run_command "$config" udhcpc \
41 -p /var/run/udhcpc-$iface.pid \
42 -s /lib/netifd/dhcp.script \
43 -f -t 0 -i "$iface" \
44 ${ipaddr:+-r $ipaddr} \
45 ${hostname:+-H $hostname} \
46 ${vendorid:+-V $vendorid} \
47 $clientid $broadcast $dhcpopts
48 }
49
50 proto_dhcp_teardown() {
51 local interface="$1"
52 proto_kill_command "$interface"
53 }
54
55 add_protocol dhcp
56