aboutsummaryrefslogtreecommitdiffstats
path: root/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh
diff options
context:
space:
mode:
authorJames <>2015-11-04 11:49:21 +0000
committerJames <>2015-11-04 11:49:21 +0000
commit716ca530e1c4515d8683c9d5be3d56b301758b66 (patch)
tree700eb5bcc1a462a5f21dcec15ce7c97ecfefa772 /package/network/config/netifd/files/lib/netifd/proto/dhcp.sh
downloadtrunk-47381-master.tar.gz
trunk-47381-master.tar.bz2
trunk-47381-master.zip
trunk-47381HEADmaster
Diffstat (limited to 'package/network/config/netifd/files/lib/netifd/proto/dhcp.sh')
-rwxr-xr-xpackage/network/config/netifd/files/lib/netifd/proto/dhcp.sh74
1 files changed, 74 insertions, 0 deletions
diff --git a/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh b/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh
new file mode 100755
index 0000000..0e88af9
--- /dev/null
+++ b/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. ../netifd-proto.sh
+init_proto "$@"
+
+proto_dhcp_init_config() {
+ renew_handler=1
+
+ proto_config_add_string 'ipaddr:ipaddr'
+ proto_config_add_string 'hostname:hostname'
+ proto_config_add_string clientid
+ proto_config_add_string vendorid
+ proto_config_add_boolean 'broadcast:bool'
+ proto_config_add_string 'reqopts:list(string)'
+ proto_config_add_string iface6rd
+ proto_config_add_string sendopts
+ proto_config_add_boolean delegate
+ proto_config_add_string zone6rd
+ proto_config_add_string zone
+ proto_config_add_string mtu6rd
+ proto_config_add_string customroutes
+}
+
+proto_dhcp_setup() {
+ local config="$1"
+ local iface="$2"
+
+ local ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes
+ json_get_vars ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes
+
+ local opt dhcpopts
+ for opt in $reqopts; do
+ append dhcpopts "-O $opt"
+ done
+
+ for opt in $sendopts; do
+ append dhcpopts "-x $opt"
+ done
+
+ [ "$broadcast" = 1 ] && broadcast="-B" || broadcast=
+ [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}" || clientid="-C"
+ [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd"
+ [ "$iface6rd" != 0 -a -f /lib/netifd/proto/6rd.sh ] && append dhcpopts "-O 212"
+ [ -n "$zone6rd" ] && proto_export "ZONE6RD=$zone6rd"
+ [ -n "$zone" ] && proto_export "ZONE=$zone"
+ [ -n "$mtu6rd" ] && proto_export "MTU6RD=$mtu6rd"
+ [ -n "$customroutes" ] && proto_export "CUSTOMROUTES=$customroutes"
+ [ "$delegate" = "0" ] && proto_export "IFACE6RD_DELEGATE=0"
+
+ 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} \
+ ${vendorid:+-V $vendorid} \
+ $clientid $broadcast $dhcpopts
+}
+
+proto_dhcp_renew() {
+ local interface="$1"
+ # SIGUSR1 forces udhcpc to renew its lease
+ local sigusr1="$(kill -l SIGUSR1)"
+ [ -n "$sigusr1" ] && proto_kill_command "$interface" $sigusr1
+}
+
+proto_dhcp_teardown() {
+ local interface="$1"
+ proto_kill_command "$interface"
+}
+
+add_protocol dhcp