X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=rrqnet-ifupdown.sh;h=b36131eec9f8c8716615bc535e0df9c7ffa3720c;hb=ac2de9795912108a9933df0bcb273c6447ac3c1f;hp=fab8bba2b7e7345d2ba71263221537d6d2963b42;hpb=d4bafdf7e0afe86b8a9263c7838dc56b6f39ede1;p=rrq%2Frrqnet.git diff --git a/rrqnet-ifupdown.sh b/rrqnet-ifupdown.sh index fab8bba..b36131e 100755 --- a/rrqnet-ifupdown.sh +++ b/rrqnet-ifupdown.sh @@ -19,11 +19,15 @@ # An rrqnet stanza may have the following settings: # rrqnet_port +# rrqnet_nice # rrqnet_remote -# rrqnet_bridge +# rrqnet_options # rrqnet_log +# rrqnet_bridge +# rrqnet_dhcp -: ${RRQDAEMON:=/usr/local/sbin/rrqnet} +: ${RRQDAEMON:=/usr/sbin/rrqnet} +: ${NAME:=rrqnet-${IFACE}} #function configure_tap_bridge() { @@ -38,50 +42,80 @@ configure_tap_up() { grep -q "state UP" || ip link set dev $IFACE up } -#function start_cable +############################################################ +## 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 - NAME="rrqnet-$IFACE" + configure_tap_up || return 1 + configure_tap_bridge || return 1 + [ -z "$IF_RRQNET_NICE" ] || \ + RRQDAEMON="/usr/bin/nice -n $IF_RRQNET_NICE $RRQDAEMON" if [ -z "$IF_RRQNET_LOG" ] ; then - daemon -U -r -n $NAME -- \ - $RRQDAEMON -4 $IF_RRQNET_OPTIONS \ - -t $IFACE $IF_RRQNET $IF_RRQNET_REMOTE + 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#* }" -- \ - $RRQDAEMON ${IF_RRQNET_LOG%% *} -4 $IF_RRQNET_OPTIONS \ + 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() { - configure_tap_bridge + 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 + daemon -n $NAME --stop } #function stop_cable_post_down() { - NAME="rrqnet-$IFACE" - daemon -n $NAME --stop + ip link del $IFACE } # main script body - case "$MODE-$PHASE" in - start-pre-up) - start_cable_pre_up - ;; - start-post-up) - start_cable_post_up - ;; - stop-pre-down) - : - ;; - stop-post-down) - stop_cable_post_down - ;; + start-pre-up) start_cable_pre_up ;; + start-post-up) start_cable_post_up ;; + stop-pre-down) stop_cable_pre_down ;; + stop-post-down) stop_cable_post_down ;; esac