File:  [ELWIX - Embedded LightWeight unIX -] / elwix / config / etc / default / rc.d / 009.aggr_dev.stop
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Mon Jan 28 10:42:47 2013 UTC (11 years, 5 months ago) by misho
Branches: MAIN
CVS tags: HEAD
ELWIX 1.7

    1: #!/bin/sh
    2: #
    3: # (C)`13 ELWIX network aggregation device appliance
    4: #	by Michael Pounov <misho@elwix.org>
    5: #
    6: # $Id: 009.aggr_dev.stop,v 1.3 2013/01/28 10:42:47 misho Exp $
    7: 
    8: IFACES=""
    9: LANPORT=""
   10: BRIDGE=""
   11: LAGG=""
   12: LAGGPORTS=""
   13: 
   14: CLEANUP_FILE="/tmp/cleanup.agg"
   15: 
   16: select_eth()
   17: {
   18: 	local RETIF=""
   19: 
   20: 	IFACES=$(ifconfig -l)
   21: 
   22: 	for i in $IFACES; do
   23: 		ISETH=$(ifconfig $i | grep "ether")
   24: 		if [ -n "$ISETH" ]; then
   25: 			RETIF="$RETIF $i"
   26: 		fi
   27: 	done
   28: 
   29: 	IFACES=$RETIF
   30: }
   31: 
   32: cleanup()
   33: {
   34: 	echo ">> Emergency destroy clones ..."
   35: 	ifconfig $BRIDGE destroy >/dev/null 2>&1
   36: 	ifconfig $LAGG destroy >/dev/null 2>&1
   37: 	rm -f $CLEANUP_FILE
   38: }
   39: 
   40: up_lan()
   41: {
   42: 	echo "+ Up lan port $1"
   43: 	if ! `ifconfig $1 description "LAN port" up`; then
   44: 		exit 1
   45: 	else
   46: 		LANPORT=$1
   47: 	fi
   48: }
   49: 
   50: up_others()
   51: {
   52: 	if [ $# -lt 2 ]; then
   53: 		echo "Error:: Not enough ethernet interfaces for aggregation!"
   54: 		exit 2
   55: 	else
   56: 		shift
   57: 		LAGGPORTS=$*
   58: 	fi
   59: 
   60: 	for i in $LAGGPORTS; do
   61: 		echo "+ Up aggregation port $i"
   62: 		if ! `ifconfig $i description "Aggregation port" up`; then
   63: 			exit 2
   64: 		fi
   65: 	done
   66: }
   67: 
   68: bring_clones()
   69: {
   70: 	rm -f $CLEANUP_FILE
   71: 
   72: 	BRIDGE=$(ifconfig bridge create up)
   73: 	if [ -z "$BRIDGE" ]; then
   74: 		exit 3
   75: 	else
   76: 		echo "+ Create link-bridge interface $BRIDGE"
   77: 		echo $BRIDGE >>/tmp/cleanup.agg
   78: 	fi
   79: 
   80: 	LAGG=$(ifconfig lagg create laggproto roundrobin up)
   81: 	if [ -z "$LAGG" ]; then
   82: 		ifconfig $BRIDGE destroy >/dev/null 2>&1
   83: 		rm -f $CLEANUP_FILE
   84: 		exit 3
   85: 	else
   86: 		echo "+ Create link-aggregation interface $LAGG"
   87: 		echo $LAGG >>/tmp/cleanup.agg
   88: 	fi
   89: }
   90: 
   91: join2lagg()
   92: {
   93: 	echo "+ Join to aggregation interface $LAGG ports $LAGGPORTS"
   94: 
   95: 	for i in $LAGGPORTS; do
   96: 		if ! `ifconfig $LAGG laggport $i`; then
   97: 			cleanup
   98: 			exit 4
   99: 		fi
  100: 	done
  101: }
  102: 
  103: join2bridge()
  104: {
  105: 	echo "+ Join to bridge interface $BRIDGE ports $LANPORT $LAGG"
  106: 
  107: 	if ! `ifconfig $BRIDGE addm $LANPORT addm $LAGG`; then
  108: 		cleanup
  109: 		exit 5
  110: 	fi
  111: }
  112: 
  113: # main()
  114: if [ -n "$1" ]; then
  115: 	echo ">> Cleanup cloned interfaces ..."
  116: 
  117: 	if [ -r $CLEANUP_FILE ]; then
  118: 		while read line; do
  119: 			if ! `ifconfig $line >/dev/null 2>&1`; then
  120: 				break
  121: 			else
  122: 				ifconfig $line destroy >/dev/null 2>&1
  123: 			fi
  124: 		done <$CLEANUP_FILE
  125: 
  126: 		rm -f $CLEANUP_FILE
  127: 	fi
  128: else
  129: 	echo ">> Setup aggregation device ..."
  130: 	select_eth
  131: 
  132: 	up_lan $IFACES
  133: 	up_others $IFACES
  134: 
  135: 	bring_clones
  136: 	join2lagg
  137: 	join2bridge
  138: fi
  139: 
  140: echo ">> Done."

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>