summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/dhcp')
-rw-r--r--src/lib/dhcp/README34
-rw-r--r--src/lib/dhcp/dhclient27
-rw-r--r--src/lib/dhcp/dhcpcd28
3 files changed, 89 insertions, 0 deletions
diff --git a/src/lib/dhcp/README b/src/lib/dhcp/README
new file mode 100644
index 0000000..f55a06e
--- /dev/null
+++ b/src/lib/dhcp/README
@@ -0,0 +1,34 @@
+Support for dhcp clients is implemented by files in
+
+ /usr/lib/network/dhcp/
+
+The file name determines the name of the client for the profile, so
+support for a client named dhcpcd is provided by the file:
+
+ /usr/lib/network/connections/dhcpcd
+
+Files that implement support for a connection type should NOT be
+executable. Such files should contain valid Bash code, among which two
+functions, namely <client_name>_start and <client_name>_stop. For
+the client named dhcpcd these would be:
+
+ dhcpcd_start
+ dhcpcd_stop
+
+These functions are responsible for starting and stopping the dhcp
+client. When the functions are called, three bash files are already
+sourced, so all functions and variables in those files are available.
+The readily sourced files are:
+
+ /usr/lib/network/network
+ /usr/lib/network/globals
+ /etc/netctl/<profile>
+
+Here, <profile> is the profile file specifying the desired network
+configuration.
+
+When called, the start and stop functions get as their first argument
+the version of the IP protocol that the dhcp client is expected to use.
+In the case of starting the client for IPv6, an additional second
+argument 'noaddr' may be supplied, which indicates that the dhcp client
+should configure everything but an IP address.
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:
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: