diff options
Diffstat (limited to 'package/netifd/files/lib/netifd/proto/dhcp.sh')
-rwxr-xr-x | package/netifd/files/lib/netifd/proto/dhcp.sh | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/package/netifd/files/lib/netifd/proto/dhcp.sh b/package/netifd/files/lib/netifd/proto/dhcp.sh new file mode 100755 index 0000000000..a4b96baa3f --- /dev/null +++ b/package/netifd/files/lib/netifd/proto/dhcp.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +. /etc/functions.sh +. ../netifd-proto.sh +init_proto "$@" + +dhcp_init_config() { + proto_config_add_string "ipaddr" + proto_config_add_string "netmask" + proto_config_add_string "hostname" + proto_config_add_string "clientid" + proto_config_add_string "vendorid" + proto_config_add_boolean "broadcast" + proto_config_add_string "reqopts" +} + +dhcp_setup() { + local config="$1" + local iface="$2" + + json_get_var ipaddr ipaddr + json_get_var hostname hostname + json_get_var clientid clientid + json_get_var vendorid vendorid + json_get_var broadcast broadcast + json_get_var reqopts reqopts + + local opt dhcpopts + for opt in $reqopts; do + append dhcpopts "-O opt" + done + + [ "$broadcast" = 1 ] && broadcast="-O broadcast" || broadcast= + + proto_export "INTERFACE=$config" + proto_run_command "$config" udhcpc \ + -p /var/run/udhcpc-$iface.pid \ + -s /lib/netifd/dhcp.script \ + -f -t 0 -i "$iface" \ + ${ipaddr:+-r $ipaddr} \ + ${hostname:+-H $hostname} \ + ${clientid:+-c $clientid} \ + ${vendorid:+-V $vendorid} \ + $broadcast $dhcpopts +} + +dhcp_teardown() { + proto_kill_command +} + +dhcp_init() { + return +} + +add_protocol dhcp + |