netifd: don't send a default client identifier in DHCP requests if no clientid uci...
[openwrt/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="-B" || broadcast=
30 [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}" || clientid="-C"
31
32 proto_export "INTERFACE=$config"
33 proto_run_command "$config" udhcpc \
34 -p /var/run/udhcpc-$iface.pid \
35 -s /lib/netifd/dhcp.script \
36 -f -t 0 -i "$iface" \
37 ${ipaddr:+-r $ipaddr} \
38 ${hostname:+-H $hostname} \
39 ${vendorid:+-V $vendorid} \
40 $clientid $broadcast $dhcpopts
41 }
42
43 proto_dhcp_teardown() {
44 local interface="$1"
45 proto_kill_command "$interface"
46 }
47
48 add_protocol dhcp
49