From: Ralph Ronnquist Date: Tue, 23 Feb 2021 04:22:24 +0000 (+1100) Subject: added dhclient control option X-Git-Tag: 0.3.3~2 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=746fe0f6034ead5765d08ce4b12f0945f7b7e5de;p=rrq%2Frrqnet.git added dhclient control option --- diff --git a/rrqnet-ifupdown.sh b/rrqnet-ifupdown.sh index 336c46d..6658929 100755 --- a/rrqnet-ifupdown.sh +++ b/rrqnet-ifupdown.sh @@ -24,6 +24,7 @@ # rrqnet_options # rrqnet_log # rrqnet_bridge +# rrqnet_dhcp : ${RRQDAEMON:=/usr/local/sbin/rrqnet} : ${NAME:=rrqnet-${IFACE}} @@ -41,6 +42,29 @@ configure_tap_up() { grep -q "state UP" || ip link set dev $IFACE up } +############################################################ +## DHCP support +: ${LEASES:=/var/lib/dhcp/dhclient.$IFACE.leases} +: ${DHCPARGS:="-4 -cf /dev/null"} +: ${PIDFILE:=/var/run/dhclient.$IFACE} + +#function +start_dhclient() { + shift 1 + [ -z "$*" ] || DHCPARGS="$*" + /sbin/dhclient -pf $PIDFILE $DHCPARGS -lf $LEASES $IFACE +} + +#function +stop_dhclient() { + shift 1 + [ -z "$*" ] || DHCPARGS="$*" + /sbin/dhclient -x -pf $PIDFILE $DHCPARGS -lf $LEASES $IFACE 2>/dev/null +} + +############################################################ +## The action functions + #function start_cable_pre_up() { configure_tap_up || return 1 @@ -48,26 +72,49 @@ start_cable_pre_up() { [ -z "$IF_RRQNET_NICE" ] || \ RRQDAEMON="/usr/bin/nice -n $IF_RRQNET_NICE $RRQDAEMON" if [ -z "$IF_RRQNET_LOG" ] ; then - daemon -U -r -n $NAME -- \ + daemon -U -r -a 10 -n $NAME -- \ $RRQDAEMON $IF_RRQNET_OPTIONS \ -t $IFACE $IF_RRQNET_PORT $IF_RRQNET_REMOTE else - daemon -U -r -n $NAME -E "${IF_RRQNET_LOG#* }" -- \ + daemon -U -r -a 10 -n $NAME -E "${IF_RRQNET_LOG#* }" -- \ $RRQDAEMON ${IF_RRQNET_LOG%% *} $IF_RRQNET_OPTIONS \ -t $IFACE $IF_RRQNET_PORT $IF_RRQNET_REMOTE fi } +#function +start_cable_post_up() { + case "$IF_RRQNET_DHCP" in + dhclient*) + start_dhclient IF_RRQNET_DHCP + ;; + *) + : # no or unkown dhcp option + ;; + esac +} + +#function +stop_cable_pre_down() { + case "$IF_RRQNET_DHCP" in + dhclient*) + stop_dhclient $IF_RRQNET_DHCP + ;; + *) + : # no or unkown dhcp option + ;; + esac +} + #function stop_cable_post_down() { daemon -n $NAME --stop } # main script body - case "$MODE-$PHASE" in start-pre-up) start_cable_pre_up ;; - start-post-up) : ;; - stop-pre-down) : ;; + start-post-up) start_cable_post_up ;; + stop-pre-down) stop_cable_pre_down ;; stop-post-down) stop_cable_post_down ;; esac diff --git a/rrqnet-ifupdown.sh.8.adoc b/rrqnet-ifupdown.sh.8.adoc index 98d1210..536cbc7 100644 --- a/rrqnet-ifupdown.sh.8.adoc +++ b/rrqnet-ifupdown.sh.8.adoc @@ -10,8 +10,9 @@ ifup and ifdown SYNOPSIS -------- - ln -s /etc/rrqnet/ifupdown.sh /etc/network/if-post-down.d/rrqnet - ln -s /etc/rrqnet/ifupdown.sh /etc/network/if-pre-up.d/rrqnet + for HOOKD in down post-down pre-up up ; do + ln -s /etc/rrqnet/ifupdown.sh /etc/network/if-$HOOKD.d/rrqnet + done DESCRIPTION ----------- @@ -78,6 +79,20 @@ made a "port" of the nominated preceding +bridge+ interface. The same things is achieved by including the +tap+ in the +bridge_ports+ list of the bridge, provided that the +tap+ is created before the bridge. +*rrqnet_dhcp* _method args_:: + +This IFACE option is used for attaching a DHCP client to the +interface. The +method+ identifies the DHCP client method, and +currently only the +dhclient+ method is defined, which is run as +follows: ++ +---- +dhclient -pf $PIDFILE $DHCPARGS -lf $LEASES $IFACE +---- ++ +The given +args+ if non-empty replaces +$DHCPARGS+, which by default +are "-4 -cf /dev/null". Refer to the +dhclient+ man page for details. + EXAMPLES -------- @@ -117,14 +132,20 @@ tunnel traffic. The tunnel packets will have a UDP header in addition to the orignal packet, which means that packets grow with some 28/48 (ipv4/6) bytes. + SEE ALSO -------- - *brctl(8)* - ethernet bridge administration - *daemon(1)* - turns other processes into daemons - *interfaces(5)* - network interface configuration for ifup and ifdown - *rrqnet(8)* - packet tunneling over UDP, multiple channels - +*brctl(8)* - ethernet bridge administration + +*daemon(1)* - turns other processes into daemons + +*dhclient(8)* - Dynamic Host Configuration Protocol Client + +*interfaces(5)* - network interface configuration for ifup and ifdown + +*rrqnet(8)* - packet tunneling over UDP, multiple channels + AUTHOR ------ Ralph Rönnquist