4bdb3a7d06269b14c0e0e2c74a2d4ce9d76cbc1b
[openwrt.git] / package / netifd / files / lib / netifd / proto / dhcp.sh
1 #!/bin/sh
2
3 . /etc/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 }
16
17 proto_dhcp_setup() {
18         local config="$1"
19         local iface="$2"
20
21         json_get_vars ipaddr hostname clientid vendorid broadcast reqopts
22
23         local opt dhcpopts
24         for opt in $reqopts; do
25                 append dhcpopts "-O opt"
26         done
27
28         [ "$broadcast" = 1 ] && broadcast="-O broadcast" || broadcast=
29
30         proto_export "INTERFACE=$config"
31         proto_run_command "$config" udhcpc \
32                 -p /var/run/udhcpc-$iface.pid \
33                 -s /lib/netifd/dhcp.script \
34                 -f -t 0 -i "$iface" \
35                 ${ipaddr:+-r $ipaddr} \
36                 ${hostname:+-H $hostname} \
37                 ${clientid:+-c $clientid} \
38                 ${vendorid:+-V $vendorid} \
39                 $broadcast $dhcpopts
40 }
41
42 proto_dhcp_teardown() {
43         local interface="$1"
44         proto_kill_command "$interface"
45 }
46
47 add_protocol dhcp
48