From 7f497011aee03f141a5bd055222ca337383f43a3 Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Tue, 25 Feb 2014 14:22:22 +0100 Subject: Factor out DHCP client support Support for additional DHCP clients is now easy to add. --- src/lib/dhcp/dhcpcd | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/lib/dhcp/dhcpcd (limited to 'src/lib/dhcp/dhcpcd') diff --git a/src/lib/dhcp/dhcpcd b/src/lib/dhcp/dhcpcd new file mode 100644 index 0000000..42f33ef --- /dev/null +++ b/src/lib/dhcp/dhcpcd @@ -0,0 +1,28 @@ +type dhcpcd &> /dev/null || return + +dhcpcd_start() { + if [[ $1 != "4" ]]; then + report_error "Using 'dhcpcd' for IPv6 is currently not possible in netctl" + return 1 + fi + rm -f "/run/dhcpcd-$Interface".{pid,cache} + # If using own dns, tell dhcpcd to NOT replace resolv.conf + [[ $DNS ]] && DhcpcdOptions+=" -C resolv.conf" + do_debug dhcpcd -4qL -t "${TimeoutDHCP:-30}" $DhcpcdOptions "$Interface" |& report_debug "$(cat)" + # The first array value of PIPESTATUS is the exit status of dhcpcd + if (( PIPESTATUS != 0 )); then + report_error "DHCP IP lease attempt failed on interface '$Interface'" + return 1 + fi +} + +dhcpcd_stop() { + local stop="-x" + if [[ -f "/run/dhcpcd-$Interface.pid" ]]; then + is_yes "${DHCPReleaseOnStop:-no}" && stop="-k" + do_debug dhcpcd -q $stop "$Interface" > /dev/null + fi +} + + +# vim: ft=sh ts=4 et sw=4: -- cgit v1.2.3-24-g4f1b