#!/bin/sh # # (C)`13 ELWIX network aggregation device appliance # by Michael Pounov # # $Id: 009.aggr_dev.stop,v 1.5 2013/05/07 20:46:48 misho Exp $ IFACES="" LANPORT="" BRIDGE="" LAGG="" LAGGPORTS="" CLEANUP_FILE="/tmp/cleanup.agg" select_eth() { local RETIF="" IFACES=$(ifconfig -l) for i in $IFACES; do ISETH=$(ifconfig $i | grep "ether") ISVLAN=$(ifconfig $i | grep "vlan") if [ -n "$ISETH" -a -z "$ISVLAN" ]; then RETIF="$RETIF $i" fi done IFACES=$RETIF } cleanup() { echo ">> Emergency destroy clones ..." ifconfig $BRIDGE destroy >/dev/null 2>&1 ifconfig $LAGG destroy >/dev/null 2>&1 rm -f $CLEANUP_FILE } up_lan() { echo "+ Up lan port $1" if ! `ifconfig $1 description "LAN port" up`; then exit 1 else LANPORT=$1 fi } up_others() { if [ $# -lt 2 ]; then echo "Error:: Not enough ethernet interfaces for aggregation!" exit 2 else shift LAGGPORTS=$* fi for i in $LAGGPORTS; do echo "+ Up aggregation port $i" if ! `ifconfig $i description "Aggregation port" up`; then exit 2 fi done } bring_clones() { rm -f $CLEANUP_FILE BRIDGE=$(ifconfig bridge create up) if [ -z "$BRIDGE" ]; then exit 3 else echo "+ Create link-bridge interface $BRIDGE" echo $BRIDGE >>/tmp/cleanup.agg fi LAGG=$(ifconfig lagg create laggproto roundrobin up) if [ -z "$LAGG" ]; then ifconfig $BRIDGE destroy >/dev/null 2>&1 rm -f $CLEANUP_FILE exit 3 else echo "+ Create link-aggregation interface $LAGG" echo $LAGG >>/tmp/cleanup.agg fi } join2lagg() { echo "+ Join to aggregation interface $LAGG ports $LAGGPORTS" for i in $LAGGPORTS; do if ! `ifconfig $LAGG laggport $i`; then cleanup exit 4 fi done } join2bridge() { echo "+ Join to bridge interface $BRIDGE ports $LANPORT $LAGG" if ! `ifconfig $BRIDGE addm $LANPORT addm $LAGG`; then cleanup exit 5 fi } # main() if [ -n "$1" ]; then echo ">> Cleanup cloned interfaces ..." if [ -r $CLEANUP_FILE ]; then while read line; do if ! `ifconfig $line >/dev/null 2>&1`; then break else ifconfig $line destroy >/dev/null 2>&1 fi done <$CLEANUP_FILE rm -f $CLEANUP_FILE fi else echo ">> Setup aggregation device ..." select_eth up_lan $IFACES up_others $IFACES bring_clones join2lagg join2bridge fi echo ">> Done."