summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcp/dhclient
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2014-02-25 14:22:22 +0100
committerJouke Witteveen <j.witteveen@gmail.com>2014-02-27 13:48:49 +0100
commit7f497011aee03f141a5bd055222ca337383f43a3 (patch)
tree3e790e15f1e007de95b95e18a71ec020dbc615eb /src/lib/dhcp/dhclient
parent03afcdce237b2dc52a6c1fea72b715cf6c34bf05 (diff)
downloadnetctl-7f497011aee03f141a5bd055222ca337383f43a3.tar.gz
netctl-7f497011aee03f141a5bd055222ca337383f43a3.tar.xz
Factor out DHCP client support
Support for additional DHCP clients is now easy to add.
Diffstat (limited to 'src/lib/dhcp/dhclient')
-rw-r--r--src/lib/dhcp/dhclient27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib/dhcp/dhclient b/src/lib/dhcp/dhclient
new file mode 100644
index 0000000..42b5f14
--- /dev/null
+++ b/src/lib/dhcp/dhclient
@@ -0,0 +1,27 @@
+type dhclient &> /dev/null || return
+
+dhclient_start() {
+ local options pidfile="/run/dhclient$1-$Interface.pid"
+ case $1 in
+ 4) options=$DhclientOptions;;
+ 6) options=$DhclientOptions6;;
+ *) return 1;;
+ esac
+ [[ $2 == "noaddr" ]] && options+=" -S"
+ rm -f "$pidfile"
+ if ! do_debug dhclient -$1 -q -e "TIMEOUT=${TimeoutDHCP:-30}" -pf "$pidfile" $options "$Interface"; then
+ report_error "DHCP IPv$1 lease attempt failed on interface '$Interface'"
+ return 1
+ fi
+}
+
+dhclient_stop() {
+ local stop="-x" pidfile="/run/dhclient$1-$Interface.pid"
+ if [[ -f $pidfile ]]; then
+ is_yes "${DHCPReleaseOnStop:-no}" && stop="-r"
+ do_debug dhclient -$1 -q $stop "$Interface" -pf "$pidfile" > /dev/null
+ fi
+}
+
+
+# vim: ft=sh ts=4 et sw=4: