From: Ralph Ronnquist Date: Sun, 27 Sep 2020 13:37:33 +0000 (+1000) Subject: added ifupdown hook script X-Git-Tag: 0.3~9 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=d4bafdf7e0afe86b8a9263c7838dc56b6f39ede1;p=rrq%2Frrqnet.git added ifupdown hook script --- diff --git a/Makefile b/Makefile index cee9a5b..1c18b47 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ MAN1DIR = $(DESTDIR)/usr/local/share/man/man1 MAN8DIR = $(DESTDIR)/usr/local/share/man/man8 SBINFILES = rrqnet rrqnet-cron.sh -ETCFILES = set-source-route.sh +ETCFILES = set-source-route.sh ifupdown.sh MAN1FILES = MAN8FILES = rrqnet.8 rrqnet-cron.sh.8 HTMLDOC = $(MAN8FILES:%=%.html) @@ -46,7 +46,7 @@ INSTALL = install $(addprefix $(ETCDIR)/,conf.d keys): mkdir -p $@ -$(ETCCFG)/cron.sh: rrqnet-cron.sh +$(ETCDIR)/ifupdown.sh: rrqnet-ifupdown.sh $(INSTALL) -D -T $< $@ $(SBINDIR)/% $(ETCDIR)/% $(MAN1DIR)/% $(MAN8DIR)/%: % diff --git a/rrqnet-ifupdown.sh b/rrqnet-ifupdown.sh new file mode 100755 index 0000000..fab8bba --- /dev/null +++ b/rrqnet-ifupdown.sh @@ -0,0 +1,87 @@ +#!/bin/sh +# +# Control script for starting or stopping an rrqnet virtual cable via +# ifup/ifdown. To use this, you need firstly to links to this script +# set up as /etc/network/if-pre-up.d/rrqnet and +# /etc/network/if-down.d/rrqnet. Secondly, you need a stanza in +# /etc/network/interfaces for the cabling tap and its associated +# configuration settings. +# +# "rrqnet name" is the primary stanza key, which result in +# a creation of a tap by that name, supported by an rrqnet plug +# according to the setup in /etc/rrqnet/conf.d/name.conf + +#echo '===========' >> /tmp/FOO +#env >> /tmp/FOO + +# Verify that it's an rrqnet stanza +[ -z "$IF_RRQNET_PORT" ] && exit 0 + +# An rrqnet stanza may have the following settings: +# rrqnet_port +# rrqnet_remote +# rrqnet_bridge +# rrqnet_log + +: ${RRQDAEMON:=/usr/local/sbin/rrqnet} + +#function +configure_tap_bridge() { + [ -z "$IF_RRQNET_BRIDGE" ] && return 0 + brctl show $IF_RRQNET_BRIDGE | grep -wq $IFACE && return 0 + brctl addif $IF_RRQNET_BRIDGE $IFACE +} + +#function +configure_tap_up() { + ( ip link show $IFACE 2>/dev/null || ip tuntap add $IFACE mode tap ) | \ + grep -q "state UP" || ip link set dev $IFACE up +} + +#function start_cable +start_cable_pre_up() { + configure_tap_up + NAME="rrqnet-$IFACE" + if [ -z "$IF_RRQNET_LOG" ] ; then + daemon -U -r -n $NAME -- \ + $RRQDAEMON -4 $IF_RRQNET_OPTIONS \ + -t $IFACE $IF_RRQNET $IF_RRQNET_REMOTE + else + daemon -U -r -n $NAME -E "${IF_RRQNET_LOG#* }" -- \ + $RRQDAEMON ${IF_RRQNET_LOG%% *} -4 $IF_RRQNET_OPTIONS \ + -t $IFACE $IF_RRQNET_PORT $IF_RRQNET_REMOTE + fi +} + +#function +start_cable_post_up() { + configure_tap_bridge +} + +#function +stop_cable_pre_down() { + : +} + +#function +stop_cable_post_down() { + NAME="rrqnet-$IFACE" + daemon -n $NAME --stop +} + +# 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 + ;; +esac