What's new

Working Link Aggregation Config RT-AC66U

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

I'm not sure what else can be done, I think it's clearly some issue on the Synology side

I would have to agree. Maybe I'm missing something that might be obvious to someone else though.

My Scenario: I have a couple TP-LINK TL-SG3424 switches. Since those were all I could afford, and yes, I know they are NOT on the Synology approved/tested list.

Anyway, with these as my main backbone with LAG enabled between them, meaning, my cable modem and router is at one end of the building, and my servers/Synology NAS (DS713+) is at the other end of the building, I have easily setup LAG for load balancing and failover between the two switches with the same (latest firmware). However, when I tried, several times mind you, to setup the DS713+ in IEEE 802.3ad Dynamic Link aggregation mode, it always failed. I'm not sure what error it threw at me. It was a while ago. Which reminds me, I haven't tried again since I updated the firmware a few weeks ago...hmm....

At the previous time, several months ago, setting the Synology in Network fault Tolerance (non-802.3ad network environment) worked fine. I never lost connection with the web interface while testing regardless of how I messed with it, thank gosh, but I just couldn't set it in link aggregation (IEEE 802.3ad Dynamic Link aggregation mode) no matter what I tried, or how I approached it.

I was happy with fault tolerance in the end then. While nothing earth shattering with the gigabit backbone, no special super computers or anything (actually low power asus eeebox PC's, I can easily get 60-75 megabytes per second read/write from the NAS with load balancing/fault tolerance in the switches, and in the Synology NAS.) That is when the network isn't so hammered with day to day business WAN access and OVPN traffic.

I know I'll be experimenting with LAN LAG in the near future. I have an rt-n66u now, last beta Merlin build, but I'll be switching to an rt-n68 if/when we get some magic happening in the future. Obviously my WAN connection is the slowest link in the chain, but all in all, some fault tolerance and load balancing isn't going to hurt anything at the router level too...
 
Last edited:
interesting that you have the same issues on 713+ that anders has on 712+

I never reviewed the synology approved list
but my dad is running an HP 1810-8g v1 with a synology 1512+

not sure why you couldn't set up LAG in 802.3ad between the 2 switches
but the fact that you never lost access while trying is very good

that is how 802.3ad is supposed to work
when configured correctly you get increased bandwidth
when something goes wrong
the bad trunk, gets marked inactive and all traffic still flows through the active line

which further brings to question the synology issues, because even if set up was incorrect, traffic should still be flowing on the active line

regarding other modes like fault tolerance only
those should all be possible on these firmwares as well
but I don't know anybody who has actually tested the other modes
and I'm not expanding the script I wrote to include them
in fact I haven't even looked into what configuration entries would be needed for other modes

unless somebody with a working synology setup comes along, I doubt I'll solve this, since I don't have one to test on
 
Last edited:
I never had issues between the switches with load balancing/failover. Super easy actually. I had issues with setting up the DS713+ in IEEE 802.3ad Dynamic Link aggregation mode on one of the switches.

Even though: http://www.tp-link.com/en/products/details/?model=TL-SG3424#spec

I guess my point was that I think the synology implementation is a bit finicky I suspect, or theory and practice are two different things. Which they are. I never contacted TP-Link or Synology on it either so...

I've upgraded the firmware for the switches recently, which was really nice when it set EVERYTHING to defaults on me after I flashed it. Luckily, I only had a few settings. A couple ports that were LAG, and a static IP basically.

I'll test again with my NAS on the TP-Link switch, to see if I can get the IEEE 802.3ad Dynamic Link aggregation mode working on the switch. It won't directly solve anything with the ports on the router to a synology NAS, but at least it's one more bullet perhaps, or troubleshooting result.

I almost remember reading about LAG, or Teaming, way back in the day, and that if you dont' have two nics yourself, and you LAG something else, it won't work right. Or maybe my memory is a bit gray...

I'll also test to see if I can get some LAG working from my router (RTN-66u currently using the code example) or I will wait for Merlin magic on the RT-AC68u to see if the code works as well.

I'd hope within the next week or so for at least one of those things to be tested by me. I'll report back, and I would hope that it would help someone with my results somewhere along the way.
 
Hmmmm....

Well, In Denmark I can get the HP1910-8 for 135 USD, so I think I will give it a go.

I'll get back to you when I know something new :p

BR

Anders
 
Why VLANs?

Can I ask what the reasoning is behind creating two new VLANs and adding those ports into said VLANs? Why not just keep the ports in VLAN 1 or even creating one new VLAN and putting them both in that?

I'm not exactly a Linux guru so I don't fully understand everything the script is doing.
 
Working with NETGEAR ProSafe (GS724Tv3)

Script works like a charm. I just put
Code:
/jffs/scripts/linkagg 3 4
into
Code:
/jffs/scripts/services-start
so it would recreate the bond on startup.

Under the NETGEAR I set it to LACP mode and add the switchports. Pretty simple.

I did want to warn people though KEEP STP ENABLED ON ALL PORTS AND LAG.

The netgear is strange and it will let you enable STP on the LAG without enabling it on the actual interface. So when the ASUS rebooted I'd get a broadcast storm and it would freeze up until I unplugged one of the cables :D
 
Script works like a charm. I just put
Code:
/jffs/scripts/linkagg 3 4
into
Code:
/jffs/scripts/services-start
so it would recreate the bond on startup.

Under the NETGEAR I set it to LACP mode and add the switchports. Pretty simple.

I did want to warn people though KEEP STP ENABLED ON ALL PORTS AND LAG.

The netgear is strange and it will let you enable STP on the LAG without enabling it on the actual interface. So when the ASUS rebooted I'd get a broadcast storm and it would freeze up until I unplugged one of the cables :D

MysticRyuujin - what model Netgear switch are you using?
 
Hmmmm....

Well, In Denmark I can get the HP1910-8 for 135 USD, so I think I will give it a go.

I'll get back to you when I know something new :p

BR

Anders

HP1910-8g that's what I've got, so I guess it's a safe bet
while I don't own a syno, I can say 1910 works with the AC66U
and the 1810 in my dad's set up works with his syno 1512+
just remember what I said above, he still have a few issues with initiall set up
which once figured out made it easy, just be sure to enable LAG on the switch before doing the syno LAG set up

I can say this the 1810 and the 1910 operate quite a bit differently
1810 is layer 2 only
1910 does layer 2 and 3 routing and also has a sfp port
 
Can I ask what the reasoning is behind creating two new VLANs and adding those ports into said VLANs? Why not just keep the ports in VLAN 1 or even creating one new VLAN and putting them both in that?

I'm not exactly a Linux guru so I don't fully understand everything the script is doing.

you can't specifiy only enslave port 3
because port 3 is not an interface, it's 1 port on an interface
you can however enslave a vlan, because it is an interface

this operates quite a bit different than a traditional desktop or linux server
in those environments each rj-45 has it's own assigned interface
but that's not true with routers
 
Did the testing between the NAS and Switch. I couldn't get "IEEE 802.3ad Dynamic Link aggregation mode" working from my NAS to the TP-Link switch.

I was able to get it working in "Network Fault Tolerance Only (non-802.3ad network environment)" as I had before. It's been working in that mode for months.

Next week I'll play around with LAG on the router to a TP-Link switch I hope...Maybe after I understand it more with this thread being updated... :)
 
Here we go round 3 , lol

LinkAgg 1.3

this is a small update
add -v or --version flag
fix potential issue with status checker -
--- it's a rare issue, I've run this thing hundreds of times already, and it's only happened once, but now it's fixed
also added check for WAN access - is bond0 a member of bridge br0
small bits of code clean up , i.e. comment lines, etc ...

Code:
#!/bin/sh
# Written By KAD
# Dynamic Link Aggregation Setup
# Version 1.3

Help()
{
	echo -e "\n----  Link Aggregation Version 1.3 Help  ----"
	echo -e "\nDynamically enable Link Aggregation using 802.3ad"
	echo "802.3ad requires a Switch/PC/NAS which..."
	echo "also supports 802.3ad to fucntion correctly"
	echo -e "\nUsage: /path/to/LinkAgg <port> <port>"
	echo "Example: /path/to/LinkAgg 3 4"
	echo -e "Only 2 ports are currently supported\n"
	echo -e "\n--- Special Flags ---"
	echo -e "\nHelp: -h or --help"
	echo "Status: -s or --status"
	echo -e "Delete: -d or --delete"
	echo -e "Version: -v or --version\n"
	exit
}

#Set all needed bonding parameters
Create_Bond()
{
	# Insert bonding module and set parameters (802.3ad, 100ms MII link monitoring)
	modprobe bonding
	# 802.3ad mode
	echo 802.3ad > /sys/class/net/${1}/bonding/mode
	# LACPDUs every 1 sec
	echo fast > /sys/class/net/${1}/bonding/lacp_rate
	# Bring up bond
	ip link set ${1} up
	# 100msec MII link monitoring
	echo 100 > /sys/class/net/${1}/bonding/miimon
	# enslave vlans to bond
	echo +${2} > /sys/class/net/${1}/bonding/slaves
	echo +${3} > /sys/class/net/${1}/bonding/slaves
	# Bridge the bond allowing AP access
	brctl addif br0 ${1}
	# We allow these VLANs to access the AP
	iptables -I INPUT 1 -i ${2} -j ACCEPT
	iptables -I INPUT 1 -i ${3} -j ACCEPT
	iptables -I INPUT 1 -i ${1} -j ACCEPT
	#Check Bond Status
	sleep 10
	Check_Bond_Status BondCreated
	echo -e "\nBond Created Successfully\n"
}

# Delete Bond Function
Delete_Bond()
{
	# Get vlan's used in current bond
	DELETEVLAN1=$(cat /sys/class/net/bond0/bonding/slaves | cut -d ' ' -f 1)
	DELETEVLAN2=$(cat /sys/class/net/bond0/bonding/slaves | cut -d ' ' -f 2)
	# Remove bonding module, this also deletes bond0
	modprobe -r bonding
	#Second check for -d flag allows delete function to be used in new bond creation as well as old bond removal
	if [[ "$1" = "-d" -o "$1" = "--delete" ]]; then
		# Set vlan1 back to default
		robocfg vlan 1 ports "1 2 3 4 8t"
		ReturnDefaultPorts="vlan1 default ports restored to - 1 2 3 4 8t"
		# Remove dead vlan's
		if [[ $DELETEVLAN1 != "" -o $DELETEVLAN1 != NULL ]]; then
			vconfig rem $DELETEVLAN1
			DeadVLAN1="Removed Dead $DELETEVLAN1"
		fi
		if [[ $DELETEVLAN2 != "" -o $DELETEVLAN2 != NULL ]]; then
			vconfig rem $DELETEVLAN2
			DeadVLAN2="Removed Dead $DELETEVLAN2"
		fi
		echo -e "\nbond0 Deleted\n"
		echo "$ReturnDefaultPorts"
		echo "$DeadVLAN1"
		echo -e "$DeadVLAN2\n"
		exit
	else
		return
	fi
}

# Status Checker
Check_Bond_Status()
{
	Check1=$(ip link show | grep bond0: | cut -d '<' -f 2 | cut -d ',' -f 4)
	if [ "$Check1" != "UP" ]; then
		Check1=NONE
		Error1="Status : bond0 not UP"
	fi
	CHECKVLAN1=$(cat /sys/class/net/bond0/bonding/slaves | cut -d ' ' -f 1)
	CHECKVLAN2=$(cat /sys/class/net/bond0/bonding/slaves | cut -d ' ' -f 2)
	if [[ "$CHECKVLAN1" = "" -o "$CHECKVLAN1" = NULL ]]; then
		CHECKVLAN1=NONE
		PORT1=NONE
		Check2=NONE
		Error2="Status : Slave 1 does not exist"
	else
		Check2=$(ip link show | grep "$CHECKVLAN1" | cut -d '<' -f 2 | grep -o UP)
		if [ "$Check2" != "UP" ]; then
			PORT1=NONE
			Check2=Down
			Error3="Status : Slave 1 not UP"
		elif [ "$Check2" = "UP" ]; then
			PORT1=$(robocfg show | grep "$CHECKVLAN1" | cut -d ':' -f 3 | sed -e "s/^ //" | cut -d ' ' -f 1)
		fi
	fi
	if [[ "$CHECKVLAN2" = "" -o "$CHECKVLAN2" = NULL ]]; then
		CHECKVLAN2=NONE
		PORT2=NONE
		Check3=NONE
		Error4="Status : Slave 2 does not exist"
	else
		Check3=$(ip link show | grep "$CHECKVLAN2" | cut -d '<' -f 2 | grep -o UP)
		if [ "$Check3" != "UP" ]; then
			PORT2=NONE
			Check3=Down
			Error5="Status : Slave 2 not UP"
		elif [ "$Check3" = "UP" ]; then
			PORT2=$(robocfg show | grep "$CHECKVLAN2" | cut -d ':' -f 3 | sed -e "s/^ //" | cut -d ' ' -f 1)
		fi
	fi
	WANACCESS=$(brctl show | grep bond0 | awk '{$1=$1}{ print }')
	if [ "$WANACCESS" != "bond0" ]; then
		WANACCESS=NONE
		Error6="Status : bond0 not part of br0 - no WAN Access"
	fi
	# check if status call was done by Create bond function
	if [ "$1" = "BondCreated" ]; then
		# if -d flag is set and any of these status checks fail, delete bond0, this is part of error recovery after new bond creation
		if [[ "$WANACCESS" = "NONE" -o "$Check1" = "NONE" -o "$CHECKVLAN1" = "NONE" -o "$PORT1" = "NONE" -o "$Check2" = "NONE" -o "$Check2" = "Down" -o "$CHECKVLAN2" = "NONE" -o "$PORT2" = "NONE" -o "$Check3" = "NONE" -o "$Check3" = "Down" ]]; then
			Delete_Bond -d
		else
			return
		fi
	fi
	echo -e "\n--- Bond Errors ---"
	echo "$Error1"
	echo "$Error2"
	echo "$Error3"
	echo "$Error4"
	echo "$Error5"
	echo "$Error6"
	echo -e "\n--- Bond Status ---\n"
	echo -e "Bond Status: bond0 $Check1"
	echo -e "Bridge to WAN Status: Member of br0=$WANACCESS"
	echo -e "Slave 1 Status: vlan=$CHECKVLAN1 Link=$Check2 Port=$PORT1"
	echo -e "Slave 2 Status: vlan=$CHECKVLAN2 Link=$Check3 Port=$PORT2\n"
	exit
}

#Version Flag
if [[ "$1" = "-v" -o "$1" = "--version" ]]; then
	Help
fi

# Status Check Flag
if [[ "$1" = "-s" -o "$1" = "--status" ]]; then
	Check_Bond_Status
fi

# Delete Bond Flag
if [[ "$1" = "-d" -o "$1" = "--delete" ]]; then
	Delete_Bond $1
fi

# Enable Help Menu
if [[ "$1" = "-h" -o "$1" = "--help" ]]; then
	Help
fi

# Number of ports must equal 2
if [[ "$#" -lt "2" -o "$#" -gt "2" ]]; then
	echo -e "\nError : Incorrect Number of Ports\n"
	Help
fi

# The Ports Must not be the same
if [ "$1" = "$2" ]; then
	echo -e "\nError : Port Entries Must Be Unique\n"
	Help
fi

# Valid port1 entries are 1,2,3,4
if [[ "$1" != "1" && "$1" != "2" && "$1" != "3" && "$1" != "4" ]]; then
	echo -e "\nError : Port1 : Not A Valid Port\n"
	Help
fi

# Valid port2 entries are 1,2,3,4
if [[ "$2" != "1" && "$2" != "2" && "$2" != "3" && "$2" != "4" ]]; then
	echo -e "\nError : Port2 : Not A Valid Port\n"
	Help
fi

#Find how many vlans exist
VLANS=$(ip link show | grep vlan* | cut -d ' ' -f 2 | cut -d '@' -f 1)
#If only 1 vlan exist
if [ ${#VLANS} = "5" ]; then
	#Check if only 1 vlan exist it should be vlan1
	if [ "$VLANS" = "vlan1" ]; then
		VLAN1="1 2 3 4 8t"
		TMP=$(echo $VLAN1 | sed -e "s/$1 //g")
		TMP1=$(echo $TMP | sed -e "s/$2 //g")
		robocfg vlan 1 ports "$TMP1"
		robocfg vlan 3 ports "$1 8t"
		robocfg vlan 4 ports "$2 8t"
		# Create the interfaces
		vconfig add eth0 $1
		vconfig add eth0 $2
		BONDS=$(ip link show | grep bond0: | cut -d ' ' -f 2 | cut -d ':' -f 1)
		#Check that bond0 does not exist
		if [ ${#BONDS} = "0" ]; then
			Create_Bond bond0 vlan3 vlan4
		#If bond0 already exist remove it
		else
			Delete_Bond
			Create_Bond bond0 vlan3 vlan4
		fi
	#Only 1 vlan exist but it's not vlan1
	else
		echo -e "\nBonding Failed WTF!!\n"
		Help
	fi
# if more than 1 vlan exist
else 
	#Find first available vlan
	VLAN2=vlan$1
	tmp=$(echo "$VLANS" | grep "$VLAN2")
	a=$1
	# vlan2 is used by system internals and does not show up in ip link, useage of vlan2 is not allowed
	if [ $VLAN2 = "vlan2" ]; then
		a=`expr $a + 1`
		VLAN2=vlan$a
		tmp=$(echo "$VLANS" | grep "$VLAN2")
	fi
	while [[ "$tmp" = "$VLAN2" ]];
	do
		a=`expr $a + 1`
		VLAN2=vlan$a
		tmp=$(echo "$VLANS" | grep "$VLAN2")
		# vlan2 is used by system internals and does not show up in ip link, useage of vlan2 is not allowed
		if [ $VLAN2 = "vlan2" ]; then
			a=`expr $a + 1`
			VLAN2=vlan$a
			tmp=$(echo "$VLANS" | grep "$VLAN2")
		fi
	done
	# Create First vlan for bond
	# Remove port from vlan1 so we can use it in bond
	VLAN2=$( echo -e "$VLAN2" | sed -e "s/vlan//g" )
	VLAN1="1 2 3 4 8t"
	TMP=$(echo "$VLAN1" | sed -e "s/$1 //g")
	robocfg vlan 1 ports "$TMP"
	robocfg vlan $VLAN2 ports "$1 8t"
	vconfig add eth0 $VLAN2
	#Find second available vlan
	VLAN3=vlan$2
	VLANS=$(ip link show | grep vlan* | cut -d ' ' -f 2 | cut -d '@' -f 1)
	tmp1=$(echo "$VLANS" | grep "$VLAN3")
	b=$2
	# vlan2 is used by system internals and does not show up in ip link, useage of vlan2 is not allowed
	if [ $VLAN3 = "vlan2" ]; then
		b=`expr $b + 1`
		VLAN3=vlan$b
		tmp1=$(echo "$VLANS" | grep "$VLAN3")
	fi
	while [[ "$tmp1" = "$VLAN3" ]];
	do
		b=`expr $b + 1`
		VLAN3=vlan$b
		tmp1=$(echo "$VLANS" | grep "$VLAN3")
		# vlan2 is used by system internals and does not show up in ip link, useage of vlan2 is not allowed
		if [ $VLAN3 = "vlan2" ]; then
			b=`expr $b + 1`
			VLAN3=vlan$b
			tmp1=$(echo "$VLANS" | grep "$VLAN3")
		fi
	done
	# Create Second vlan for bond
	# Remove port from vlan1 so we can use it in bond
	VLAN3=$( echo "$VLAN3" | sed -e "s/vlan//g" )
	TMP1=$(echo "$TMP" | sed -e "s/$2 //g")
	robocfg vlan 1 ports "$TMP1"
	robocfg vlan $VLAN3 ports "$2 8t"
	vconfig add eth0 $VLAN3
	BONDS=$(ip link show | grep bond0: | cut -d ' ' -f 2 | cut -d ':' -f 1)
	#Check that bond0 does not exist
	if [ ${#BONDS} = "0" ]; then
		Create_Bond bond0 vlan$VLAN2 vlan$VLAN3
	else
	#If bond0 already exist remove it
		Delete_Bond
		Create_Bond bond0 vlan$VLAN2 vlan$VLAN3
	fi
fi
 
Strange that It won't work with the TP-Link.

Seems like Synology is only working with the reference models :(

Just ordered the 1910-8 and a "USB to GB adapter". Will try to make a Link Agg from my iMac to the new switch as well - should be quite easy on the mac (I read :) )

Br

Anders
 
Last edited:
Some Forums say that the LAG for Synology should be "LACP".

I don't know what this means , but could this be the issue?

BR

Anders
 
Some Forums say that the LAG for Synology should be "LACP".

I don't know what this means , but could this be the issue?

BR

Anders

Same thing

Link Aggregation aka LAG
Link Aggregation Control Protocol aka LACP (specifically refers to 802.3ad)
NIC Teaming
Bonding or NIC Bonding

there's probably some other names I'm forgetting as well
Besides the 1 mode we're using here there's

balance-rr or 0
active-backup or 1
balance-xor or 2
broadcast or 3
802.3ad or 4
balance-tlb or 5
balance-alb or 6
 
Last edited:
LinkAgg 1.4

Regardless of how Delete_Bond function is called - delete dead vlans
--Previously dead vlans where only removed if -d flag was specified

Code:
#!/bin/sh
# Written By KAD
# Dynamic Link Aggregation Setup
# Version 1.4

Help()
{
	echo -e "\n----  Link Aggregation Version 1.4 Help  ----"
	echo -e "\nDynamically enable Link Aggregation using 802.3ad"
	echo "802.3ad requires a Switch/PC/NAS which..."
	echo "also supports 802.3ad to function correctly"
	echo -e "\nUsage: /path/to/LinkAgg <port> <port>"
	echo "Example: /path/to/LinkAgg 3 4"
	echo -e "Only 2 ports are currently supported\n"
	echo -e "\n--- Special Flags ---"
	echo -e "\nHelp: -h or --help"
	echo "Status: -s or --status"
	echo -e "Delete: -d or --delete"
	echo -e "Version: -v or --version\n"
	exit
}

#Set all needed bonding parameters
Create_Bond()
{
	# Insert bonding module and set parameters (802.3ad, 100ms MII link monitoring)
	modprobe bonding
	# 802.3ad mode
	echo 802.3ad > /sys/class/net/${1}/bonding/mode
	# LACPDUs every 1 sec
	echo fast > /sys/class/net/${1}/bonding/lacp_rate
	# Bring up bond
	ip link set ${1} up
	# 100msec MII link monitoring
	echo 100 > /sys/class/net/${1}/bonding/miimon
	# enslave vlans to bond
	echo +${2} > /sys/class/net/${1}/bonding/slaves
	echo +${3} > /sys/class/net/${1}/bonding/slaves
	# Bridge the bond allowing AP access
	brctl addif br0 ${1}
	# We allow these VLANs to access the AP
	iptables -I INPUT 1 -i ${2} -j ACCEPT
	iptables -I INPUT 1 -i ${3} -j ACCEPT
	iptables -I INPUT 1 -i ${1} -j ACCEPT
	#Check Bond Status
	sleep 10
	Check_Bond_Status BondCreated
	echo -e "\nBond Created Successfully\n"
}

# Delete Bond Function
Delete_Bond()
{
	# Get vlan's used in current bond
	DELETEVLAN1=$(cat /sys/class/net/bond0/bonding/slaves | cut -d ' ' -f 1)
	DELETEVLAN2=$(cat /sys/class/net/bond0/bonding/slaves | cut -d ' ' -f 2)
	# Remove bonding module, this also deletes bond0
	modprobe -r bonding
	# Remove dead vlan's
	if [[ $DELETEVLAN1 != "" -o $DELETEVLAN1 != NULL ]]; then
		vconfig rem $DELETEVLAN1
		DeadVLAN1="Removed Dead $DELETEVLAN1"
	fi
	if [[ $DELETEVLAN2 != "" -o $DELETEVLAN2 != NULL ]]; then
		vconfig rem $DELETEVLAN2
		DeadVLAN2="Removed Dead $DELETEVLAN2"
	fi
	#Second check for -d flag allows delete function to be used in new bond creation as well as old bond removal
	if [[ "$1" = "-d" -o "$1" = "--delete" ]]; then
		# Set vlan1 back to default
		robocfg vlan 1 ports "1 2 3 4 8t"
		ReturnDefaultPorts="vlan1 default ports restored to - 1 2 3 4 8t"
		echo -e "\nbond0 Deleted\n"
		echo "$ReturnDefaultPorts"
		echo "$DeadVLAN1"
		echo -e "$DeadVLAN2\n"
		exit
	else
		return
	fi
}

# Status Checker
Check_Bond_Status()
{
	Check1=$(ip link show | grep bond0: | cut -d '<' -f 2 | cut -d ',' -f 4)
	if [ "$Check1" != "UP" ]; then
		Check1=NONE
		Error1="Status : bond0 not UP"
	fi
	CHECKVLAN1=$(cat /sys/class/net/bond0/bonding/slaves | cut -d ' ' -f 1)
	CHECKVLAN2=$(cat /sys/class/net/bond0/bonding/slaves | cut -d ' ' -f 2)
	if [[ "$CHECKVLAN1" = "" -o "$CHECKVLAN1" = NULL ]]; then
		CHECKVLAN1=NONE
		PORT1=NONE
		Check2=NONE
		Error2="Status : Slave 1 does not exist"
	else
		Check2=$(ip link show | grep "$CHECKVLAN1" | cut -d '<' -f 2 | grep -o UP)
		if [ "$Check2" != "UP" ]; then
			PORT1=NONE
			Check2=Down
			Error3="Status : Slave 1 not UP"
		elif [ "$Check2" = "UP" ]; then
			PORT1=$(robocfg show | grep "$CHECKVLAN1" | cut -d ':' -f 3 | sed -e "s/^ //" | cut -d ' ' -f 1)
		fi
	fi
	if [[ "$CHECKVLAN2" = "" -o "$CHECKVLAN2" = NULL ]]; then
		CHECKVLAN2=NONE
		PORT2=NONE
		Check3=NONE
		Error4="Status : Slave 2 does not exist"
	else
		Check3=$(ip link show | grep "$CHECKVLAN2" | cut -d '<' -f 2 | grep -o UP)
		if [ "$Check3" != "UP" ]; then
			PORT2=NONE
			Check3=Down
			Error5="Status : Slave 2 not UP"
		elif [ "$Check3" = "UP" ]; then
			PORT2=$(robocfg show | grep "$CHECKVLAN2" | cut -d ':' -f 3 | sed -e "s/^ //" | cut -d ' ' -f 1)
		fi
	fi
	WANACCESS=$(brctl show | grep bond0 | awk '{$1=$1}{ print }')
	if [ "$WANACCESS" != "bond0" ]; then
		WANACCESS=NONE
		Error6="Status : bond0 not part of br0 - no WAN Access"
	fi
	# check if status call was done by Create bond function
	if [ "$1" = "BondCreated" ]; then
		# if -d flag is set and any of these status checks fail, delete bond0, this is part of error recovery after new bond creation
		if [[ "$WANACCESS" = "NONE" -o "$Check1" = "NONE" -o "$CHECKVLAN1" = "NONE" -o "$PORT1" = "NONE" -o "$Check2" = "NONE" -o "$Check2" = "Down" -o "$CHECKVLAN2" = "NONE" -o "$PORT2" = "NONE" -o "$Check3" = "NONE" -o "$Check3" = "Down" ]]; then
			Delete_Bond -d
		else
			return
		fi
	fi
	echo -e "\n--- Bond Errors ---"
	echo "$Error1"
	echo "$Error2"
	echo "$Error3"
	echo "$Error4"
	echo "$Error5"
	echo "$Error6"
	echo -e "\n--- Bond Status ---\n"
	echo -e "Bond Status: bond0 $Check1"
	echo -e "Bridge to WAN Status: Member of br0=$WANACCESS"
	echo -e "Slave 1 Status: vlan=$CHECKVLAN1 Link=$Check2 Port=$PORT1"
	echo -e "Slave 2 Status: vlan=$CHECKVLAN2 Link=$Check3 Port=$PORT2\n"
	exit
}

#Version Flag
if [[ "$1" = "-v" -o "$1" = "--version" ]]; then
	Help
fi

# Status Check Flag
if [[ "$1" = "-s" -o "$1" = "--status" ]]; then
	Check_Bond_Status
fi

# Delete Bond Flag
if [[ "$1" = "-d" -o "$1" = "--delete" ]]; then
	Delete_Bond $1
fi

# Enable Help Menu
if [[ "$1" = "-h" -o "$1" = "--help" ]]; then
	Help
fi

# Number of ports must equal 2
if [[ "$#" -lt "2" -o "$#" -gt "2" ]]; then
	echo -e "\nError : Incorrect Number of Ports\n"
	Help
fi

# The Ports Must not be the same
if [ "$1" = "$2" ]; then
	echo -e "\nError : Port Entries Must Be Unique\n"
	Help
fi

# Valid port1 entries are 1,2,3,4
if [[ "$1" != "1" && "$1" != "2" && "$1" != "3" && "$1" != "4" ]]; then
	echo -e "\nError : Port1 : Not A Valid Port\n"
	Help
fi

# Valid port2 entries are 1,2,3,4
if [[ "$2" != "1" && "$2" != "2" && "$2" != "3" && "$2" != "4" ]]; then
	echo -e "\nError : Port2 : Not A Valid Port\n"
	Help
fi

#Find how many vlans exist
VLANS=$(ip link show | grep vlan* | cut -d ' ' -f 2 | cut -d '@' -f 1)
#If only 1 vlan exist
if [ ${#VLANS} = "5" ]; then
	#Check if only 1 vlan exist it should be vlan1
	if [ "$VLANS" = "vlan1" ]; then
		VLAN1="1 2 3 4 8t"
		TMP=$(echo $VLAN1 | sed -e "s/$1 //g")
		TMP1=$(echo $TMP | sed -e "s/$2 //g")
		robocfg vlan 1 ports "$TMP1"
		robocfg vlan 3 ports "$1 8t"
		robocfg vlan 4 ports "$2 8t"
		# Create the interfaces
		vconfig add eth0 $1
		vconfig add eth0 $2
		BONDS=$(ip link show | grep bond0: | cut -d ' ' -f 2 | cut -d ':' -f 1)
		#Check that bond0 does not exist
		if [ ${#BONDS} = "0" ]; then
			Create_Bond bond0 vlan3 vlan4
		#If bond0 already exist remove it
		else
			Delete_Bond
			Create_Bond bond0 vlan3 vlan4
		fi
	#Only 1 vlan exist but it's not vlan1
	else
		echo -e "\nBonding Failed WTF!!\n"
		Help
	fi
# if more than 1 vlan exist
else 
	#Find first available vlan
	VLAN2=vlan$1
	tmp=$(echo "$VLANS" | grep "$VLAN2")
	a=$1
	# vlan2 is used by system internals and does not show up in ip link, useage of vlan2 is not allowed
	if [ $VLAN2 = "vlan2" ]; then
		a=`expr $a + 1`
		VLAN2=vlan$a
		tmp=$(echo "$VLANS" | grep "$VLAN2")
	fi
	while [[ "$tmp" = "$VLAN2" ]];
	do
		a=`expr $a + 1`
		VLAN2=vlan$a
		tmp=$(echo "$VLANS" | grep "$VLAN2")
		# vlan2 is used by system internals and does not show up in ip link, useage of vlan2 is not allowed
		if [ $VLAN2 = "vlan2" ]; then
			a=`expr $a + 1`
			VLAN2=vlan$a
			tmp=$(echo "$VLANS" | grep "$VLAN2")
		fi
	done
	# Create First vlan for bond
	# Remove port from vlan1 so we can use it in bond
	VLAN2=$( echo -e "$VLAN2" | sed -e "s/vlan//g" )
	VLAN1="1 2 3 4 8t"
	TMP=$(echo "$VLAN1" | sed -e "s/$1 //g")
	robocfg vlan 1 ports "$TMP"
	robocfg vlan $VLAN2 ports "$1 8t"
	vconfig add eth0 $VLAN2
	#Find second available vlan
	VLAN3=vlan$2
	VLANS=$(ip link show | grep vlan* | cut -d ' ' -f 2 | cut -d '@' -f 1)
	tmp1=$(echo "$VLANS" | grep "$VLAN3")
	b=$2
	# vlan2 is used by system internals and does not show up in ip link, useage of vlan2 is not allowed
	if [ $VLAN3 = "vlan2" ]; then
		b=`expr $b + 1`
		VLAN3=vlan$b
		tmp1=$(echo "$VLANS" | grep "$VLAN3")
	fi
	while [[ "$tmp1" = "$VLAN3" ]];
	do
		b=`expr $b + 1`
		VLAN3=vlan$b
		tmp1=$(echo "$VLANS" | grep "$VLAN3")
		# vlan2 is used by system internals and does not show up in ip link, useage of vlan2 is not allowed
		if [ $VLAN3 = "vlan2" ]; then
			b=`expr $b + 1`
			VLAN3=vlan$b
			tmp1=$(echo "$VLANS" | grep "$VLAN3")
		fi
	done
	# Create Second vlan for bond
	# Remove port from vlan1 so we can use it in bond
	VLAN3=$( echo "$VLAN3" | sed -e "s/vlan//g" )
	TMP1=$(echo "$TMP" | sed -e "s/$2 //g")
	robocfg vlan 1 ports "$TMP1"
	robocfg vlan $VLAN3 ports "$2 8t"
	vconfig add eth0 $VLAN3
	BONDS=$(ip link show | grep bond0: | cut -d ' ' -f 2 | cut -d ':' -f 1)
	#Check that bond0 does not exist
	if [ ${#BONDS} = "0" ]; then
		Create_Bond bond0 vlan$VLAN2 vlan$VLAN3
	else
	#If bond0 already exist remove it
		Delete_Bond
		Create_Bond bond0 vlan$VLAN2 vlan$VLAN3
	fi
fi
 
This is awesome. I don't really need a LAG, but because of this script, I'm considering getting LACP capable switch and NAS as a result.
 
I was curious, and no I will not support this in my script
but thought it might be useful for somebody

when you load the bonding module, if can use the max_bonds parameter to create multiple bonds
Code:
modprobe bonding max_bonds=2
will create bond0 and bond1

so you can in theory have 2GB bandwidth the whole way
server to router to PC

of coarse the downside is that config would use all 4 available ports
 
Do all devices in the chain need to support 2 x 1Gbps speed?

I have a QNAP dual GigE NAS connected to the router, then a GigE dumb switch, then my desktop with a single GigE. I take it there would be no speed benefit for my configuration?
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top