File:  [ELWIX - Embedded LightWeight unIX -] / elwix / config / etc / uboot / rc.d / 009.aggr_dev.stop
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Mon Sep 15 19:06:52 2014 UTC (9 years, 10 months ago) by misho
Branches: MAIN
CVS tags: elwix2_8, elwix2_7, elwix2_6, elwix2_3, HEAD, ELWIX2_7, ELWIX2_6, ELWIX2_5, ELWIX2_2p0
elwix 2.2

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

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