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 (10 years, 3 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
#!/bin/sh
#
# (C)`13 ELWIX network aggregation device appliance
# by Michael Pounov <misho@elwix.org>
#
# $Id: 009.aggr_dev.stop,v 1.2 2014/09/15 19:06:52 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."
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>