From d176d9fa5013a0c4a8b25754cec053c24a0d83d1 Mon Sep 17 00:00:00 2001 From: James Rayner Date: Thu, 22 Oct 2009 00:18:15 +1100 Subject: Add initial net-auto-wired concept --- ifplugd/net-auto-wired | 44 ++++++++++++++++++++++++++++++++++++++++++++ ifplugd/netcfg.action | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100755 ifplugd/net-auto-wired create mode 100755 ifplugd/netcfg.action (limited to 'ifplugd') diff --git a/ifplugd/net-auto-wired b/ifplugd/net-auto-wired new file mode 100755 index 0000000..79e5beb --- /dev/null +++ b/ifplugd/net-auto-wired @@ -0,0 +1,44 @@ +#!/bin/bash + +. /etc/rc.conf +. /etc/rc.d/functions + +CFG=/etc/ifplugd/ifplugd.conf +ACTION=/etc/ifplugd/netcfg.action +PID=$(cat /var/run/ifplugd.$WIRED_INTERFACE) + +# Source ifplugd configuration +[ -f $CFG ] && . $CFG + +case "$1" in + start) + stat_busy "Starting netcfg auto-wired mode for interface ${WIRED_INTERFACE}" + A="`eval echo \$\{ARGS_${WIRED_INTERFACE}\}`" + [ -z "$A" ] && A="$ARGS" + [ -z "$PID" ] && /usr/sbin/ifplugd -i $WIRED_INTERFACE -r $ACTION $A + if [ $? -gt 0 ]; then + stat_fail + else + add_daemon net-auto-wired + stat_done + fi + ;; + stop) + stat_busy "Stopping netcfg auto-wired mode for interface ${WIRED_INTERFACE}" + [ ! -z "$PID" ] && /usr/sbin/ifplugd -k -i $WIRED_INTERFACE -r $ACTION + if [ $? -gt 0 ]; then + stat_fail + else + rm_daemon net-auto-wired + stat_done + fi + ;; + restart) + $0 stop + sleep 1 + $0 start + ;; + *) + echo "usage: $0 {start|stop|restart}" +esac +exit 0 diff --git a/ifplugd/netcfg.action b/ifplugd/netcfg.action new file mode 100755 index 0000000..cb8ad7f --- /dev/null +++ b/ifplugd/netcfg.action @@ -0,0 +1,41 @@ +#!/bin/sh +# +# ifplugd.action script for netcfg + +. /etc/rc.conf +. /etc/rc.d/functions +. /usr/lib/network/network + +case "$2" in + up) + # Look for a dhcp based profile to try first + # dhcp can actually outright fail, whereas + # it's difficult to tell if static succeeded + # Also check profile is same iface and is right connection + for profile in $(list_profiles); do ( + load_profile $profile + [[ $INTERFACE != $1 ]] && continue + [[ $CONNECTION != @(ethernet|ethernet-iproute) ]] && continue + if [[ $IP == "dhcp" ]]; then + netcfg $profile && exit 0 + fi + ) done + for profile in $(list profiles}; do ( + load_profile $profile + [[ $INTERFACE != $1 ]] && continue + [[ $CONNECTION != "(ethernet|ethernet-iproute)" ]] && continue + netcfg $profile && exit 0 + ) done + exit 1 + ;; + down) + if check_iface $1; then + netcfg -i $1 + fi + ;; + *) + echo "Wrong arguments" > /dev/stderr + ;; +esac + +exit 1 -- cgit v1.2.3-24-g4f1b