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