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)
$(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)/%: %
--- /dev/null
+#!/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 <port>
+# rrqnet_remote <remote declaration>
+# rrqnet_bridge <bridge>
+# rrqnet_log <level> <pathname>
+
+: ${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 <env> start_cable <loglevel> <logfile>
+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