I suspect the AC66U could also be configured the same way as the N66U. Possibly the N16 too (I forgot if they share the same switch).
AC56 is a different story. I implemented most of the 5310x support in robocfg by now (at least robord/wr works properly now), so once you know the proper registers, it might probably be used to do the same configuration as well.
Having a quick look at the vlan code in robocfg, there's a chance it might even work already since it relies on robo_write - untested however.
#!/bin/sh
# TODO: Store VLAN IDs in nvram?
VLANS="${BOND_VLANS:-3 4}"
bond_set()
{
# bond_iface param value
[ -d "/sys/class/net/${1}/bonding" ] || return 1
[ -f "/sys/class/net/${1}/bonding/${2}" ] || return 1
echo "${3}" > "/sys/class/net/${1}/bonding/${2}"
}
PORTS="1 2 3 4"
for vlan in ${VLANS}; do
local vlan1_ports="8t"
for port in ${PORTS}; do
if [ "${port}" != "${1}" ]; then
vlan1_ports="${port} ${vlan1_ports}"
fi
done
# Remove port from the default VLAN
robocfg vlan 1 ports "${vlan1_ports}"
# Add it to new VLAN
robocfg vlan ${vlan} ports "${1} 8t"
# Create new VLAN interface
vconfig add eth0 ${vlan}
PORTS="${vlan1_ports% 8t}"
shift
done
# Insert bonding module
modprobe bonding
# 802.3ad mode
bond_set bond0 mode "802.3ad"
# LACPDUs every 1 sec
bond_set bond0 lacp_rate fast
# 100msec MII link monitoring
bond_set bond0 miimon 100
# Bring up bond0
ip link set bond0 up
for vlan in ${VLANS}; do
# enslave VLAN to bond0
bond_set bond0 slaves "+vlan${vlan}"
# Allow VLANs to access the AP
iptables -I INPUT 1 -i "vlan${vlan}" -j ACCEPT
done
# Bridge the bond0 allowing AP access
brctl addif br0 bond0
# We allow bond0 to access the AP
iptables -I INPUT 1 -i bond0 -j ACCEPT
Are you saying that robocfg might work for all models? Or at least for sure for the AC66U and N66U, and maybe for the N16 and AC56?
I'll test it out tonight as well, after I run those networkmap tests
I'll be leaving work in a few minutes
another thing I thought of, we might want to check that vlan3 or vlan4 etc do not already exist
before we create them, they could already be in use
t@RT-AC66U:/jffs# ./LinkAgg
Invalid ports ' 8t'.
Invalid ports ' 8t'.
#!/bin/sh
robocfg vlan 1 ports "1 2 8t"
robocfg vlan 3 ports "3 8t"
robocfg vlan 4 ports "4 8t"
# Create the interfaces
vconfig add eth0 3
vconfig add eth0 4
# Insert bonding module and set parameters (802.3ad, 100ms MII link monitoring,$
modprobe bonding
# 802.3ad mode
echo 802.3ad > /sys/class/net/bond0/bonding/mode
# LACPDUs every 1 sec
echo fast > /sys/class/net/bond0/bonding/lacp_rate
# Bring up bond0
ip link set bond0 up
# 100msec MII link monitoring
echo 100 > /sys/class/net/bond0/bonding/miimon
# enslave vlans to bond0
echo +vlan3 > /sys/class/net/bond0/bonding/slaves
echo +vlan4 > /sys/class/net/bond0/bonding/slaves
# Bridge the bond0 allowing AP access
brctl addif br0 bond0
# We allow these VLANs to access the AP
iptables -I INPUT 1 -i vlan3 -j ACCEPT
iptables -I INPUT 1 -i vlan4 -j ACCEPT
iptables -I INPUT 1 -i bond0 -j ACCEPT
if [[ `ifconfig | grep vlan${1}` ]]; then
#!/bin/sh
if [ $# -lt 2 -o $# -gt 2 ]; then
echo "No Args"
exit
fi
if [ $1 = $2 ]; then
echo "Invalid Port Entries"
exit
fi
if [ "$1" != "1" ] && [ "$1" != "2" ] && [ "$1" != "3" ] && [ "$1" != "4" ]; then
echo "Not A Valid Port"
exit
fi
if [ "$2" != "1" ] && [ "$2" != "2" ] && [ "$2" != "3" ] && [ "$2" != "4" ]; then
echo "Not A Valid Port"
exit
fi
VLANS=$(ip link show | grep vlan* | cut -d ' ' -f 2 | cut -d '@' -f 1)
if [ ${#VLANS} = "5" ]; then
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)
if [ ${#BONDS} = "" ]; then
bond=bond0
# Insert bonding module and set parameters (802.3ad, 100ms MII link monitoring)
modprobe bonding
# 802.3ad mode
echo 802.3ad > /sys/class/net/$bond/bonding/mode
# LACPDUs every 1 sec
echo fast > /sys/class/net/$bond/bonding/lacp_rate
# Bring up bond
ip link set $bond up
# 100msec MII link monitoring
echo 100 > /sys/class/net/$bond/bonding/miimon
# enslave vlans to bond
echo +vlan3 > /sys/class/net/$bond/bonding/slaves
echo +vlan4 > /sys/class/net/$bond/bonding/slaves
# Bridge the bond allowing AP access
brctl addif br0 $bond
# We allow these VLANs to access the AP
iptables -I INPUT 1 -i vlan3 -j ACCEPT
iptables -I INPUT 1 -i vlan4 -j ACCEPT
iptables -I INPUT 1 -i $bond -j ACCEPT
else
bond=bond0
modprobe -r bonding
# Insert bonding module and set parameters (802.3ad, 100ms MII link monitoring)
modprobe bonding
# 802.3ad mode
echo 802.3ad > /sys/class/net/$bond/bonding/mode
# LACPDUs every 1 sec
echo fast > /sys/class/net/$bond/bonding/lacp_rate
# Bring up bond
ip link set $bond up
# 100msec MII link monitoring
echo 100 > /sys/class/net/$bond/bonding/miimon
# enslave vlans to bond
echo +vlan3 > /sys/class/net/$bond/bonding/slaves
echo +vlan4 > /sys/class/net/$bond/bonding/slaves
# Bridge the bond allowing AP access
brctl addif br0 $bond
# We allow these VLANs to access the AP
iptables -I INPUT 1 -i vlan3 -j ACCEPT
iptables -I INPUT 1 -i vlan4 -j ACCEPT
iptables -I INPUT 1 -i $bond -j ACCEPT
fi
else
echo "Bonding Failed WTF!!"
fi
else
VLAN2=vlan$1
tmp=$(echo "$VLANS" | grep $VLAN2)
a=$1
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)
if [ $VLAN2 = "vlan2" ]; then
a=`expr $a + 1`
VLAN2=vlan$a
tmp=$(echo "$VLANS" | grep $VLAN2)
fi
done
VLAN2=$( echo "$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
VLAN3=vlan$2
VLANS=$(ip link show | grep vlan* | cut -d ' ' -f 2 | cut -d '@' -f 1)
tmp1=$(echo "$VLANS" | grep $VLAN3)
b=$2
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)
if [ $VLAN3 = "vlan2" ]; then
b=`expr $b + 1`
VLAN3=vlan$b
tmp1=$(echo "$VLANS" | grep $VLAN3)
fi
done
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)
if [ ${#BONDS} = "" ]; then
bond=bond0
# Insert bonding module and set parameters (802.3ad, 100ms MII link monitoring)
modprobe bonding
# 802.3ad mode
echo 802.3ad > /sys/class/net/$bond/bonding/mode
# LACPDUs every 1 sec
echo fast > /sys/class/net/$bond/bonding/lacp_rate
# Bring up bond
ip link set $bond up
# 100msec MII link monitoring
echo 100 > /sys/class/net/$bond/bonding/miimon
# enslave vlans to bond
echo +vlan$VLAN2 > /sys/class/net/$bond/bonding/slaves
echo +vlan$VLAN3 > /sys/class/net/$bond/bonding/slaves
# Bridge the bond allowing AP access
brctl addif br0 $bond
# We allow these VLANs to access the AP
iptables -I INPUT 1 -i vlan$VLAN2 -j ACCEPT
iptables -I INPUT 1 -i vlan$VLAN3 -j ACCEPT
iptables -I INPUT 1 -i $bond -j ACCEPT
else
bond=bond0
modprobe -r bonding
# Insert bonding module and set parameters (802.3ad, 100ms MII link monitoring)
modprobe bonding
# 802.3ad mode
echo 802.3ad > /sys/class/net/$bond/bonding/mode
# LACPDUs every 1 sec
echo fast > /sys/class/net/$bond/bonding/lacp_rate
# Bring up bond
ip link set $bond up
# 100msec MII link monitoring
echo 100 > /sys/class/net/$bond/bonding/miimon
# enslave vlans to bond
echo +vlan$VLAN2 > /sys/class/net/$bond/bonding/slaves
echo +vlan$VLAN3 > /sys/class/net/$bond/bonding/slaves
# Bridge the bond allowing AP access
brctl addif br0 $bond
# We allow these VLANs to access the AP
iptables -I INPUT 1 -i vlan$VLAN2 -j ACCEPT
iptables -I INPUT 1 -i vlan$VLAN3 -j ACCEPT
iptables -I INPUT 1 -i $bond -j ACCEPT
fi
fi
#!/bin/sh
# Written By KAD
# Dynamic Link Aggregation Setup
# Version 1.1
Help()
{
echo -e "\n---- Link Aggregation 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"
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
Check_Bond_Status
}
#Check that bond creation was successful
#If Bond was unsuccessful set vlan1 back to default
Check_Bond_Status()
{
Check1=$(ip link show | grep bond0: | cut -d '<' -f 2 | cut -d ',' -f 4)
if [ $Check1 != "UP" ]; then
echo "Bonding Failed - Set vlan1 back to Default Settings"
robocfg vlan1 ports "1 2 3 4 8t"
exit
fi
VLAN1=$(cat /sys/class/net/bond0/bonding/slaves | cut -d ' ' -f 1)
VLAN2=$(cat /sys/class/net/bond0/bonding/slaves | cut -d ' ' -f 2)
if [ $VLAN1 = "" ]; then
echo "Bonding Failed - Set vlan1 back to original Settings"
robocfg vlan1 ports "1 2 3 4 8t"
exit
fi
if [ $VLAN2 = "" ]; then
echo "Bonding Failed - Set vlan1 back to original Settings"
robocfg vlan1 ports "1 2 3 4 8t"
exit
fi
Check2=$(ip link show | grep $VLAN1 | cut -d '<' -f 2 | cut -d ',' -f 4)
if [ $Check2 != "UP" ]; then
echo "Bonding Failed - Set vlan1 back to original Settings"
robocfg vlan1 ports "1 2 3 4 8t"
exit
fi
Check3=$(ip link show | grep $VLAN2 | cut -d '<' -f 2 | cut -d ',' -f 4)
if [ $Check3 != "UP" ]; then
echo "Bonding Failed - Set vlan1 back to original Settings"
robocfg vlan1 ports "1 2 3 4 8t"
exit
fi
Check4=$(cat /proc/net/bonding/bond0 | grep "bond bond0 has no active aggregator")
if [ $Check4 != "" ]; then
echo "Bonding Failed - Set vlan1 back to original Settings"
robocfg vlan1 ports "1 2 3 4 8t"
exit
fi
echo -e "\nBond0 Successfully Created"
exit
}
# Status Checker
if [ "$1" = "-s" -o "$1" = "--status" ]; then
Check1=$(ip link show | grep bond0: | cut -d '<' -f 2 | cut -d ',' -f 4)
if [ $Check1 != "UP" ]; then
echo "Status : bond0 not UP"
exit
fi
VLAN1=$(cat /sys/class/net/bond0/bonding/slaves | cut -d ' ' -f 1)
VLAN2=$(cat /sys/class/net/bond0/bonding/slaves | cut -d ' ' -f 2)
if [ $VLAN1 = "" ]; then
echo "Status : Slave 1 does not exist"
exit
fi
if [ $VLAN2 = "" ]; then
echo "Status : Slave 2 does not exist"
exit
fi
Check2=$(ip link show | grep $VLAN1 | cut -d '<' -f 2 | cut -d ',' -f 4)
if [ $Check2 != "UP" ]; then
echo "Status : Slave 1 not UP"
exit
fi
Check3=$(ip link show | grep $VLAN2 | cut -d '<' -f 2 | cut -d ',' -f 4)
if [ $Check3 != "UP" ]; then
echo "Slave : Slave 2 not UP"
exit
fi
Check4=$(cat /proc/net/bonding/bond0 | grep "bond bond0 has no active aggregator")
if [ $Check4 != "" ]; then
echo "Status : No Active Aggregator for bond0"
exit
fi
echo -e "\nBond0 Up & Running Correctly"
exit
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"
Help
fi
# The Ports Must not be the same
if [ $1 = $2 ]; then
echo -e "\nError : Port Entries Must Be Unique"
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"
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"
Help
fi
#Store current vlan1 config for later use
DefaultVLAN=$(robocfg show | grep vlan1 | cut -d ':' -f 3 | sed -e "s/^ //")
#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} = "" ]; then
Create_Bond bond0 vlan3 vlan4
#If bond0 already exist remove it
else
modprobe -r bonding
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 "$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} = "" ]; then
Create_Bond bond0 vlan$VLAN2 vlan$VLAN3
else
#If bond0 already exist remove it
modprobe -r bonding
Create_Bond bond0 vlan$VLAN2 vlan$VLAN3
fi
fi
#!/bin/sh
# Written By KAD
# Dynamic Link Aggregation Setup
# Version 1.2
Help()
{
echo -e "\n---- Link Aggregation 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\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 "Bond Created Successfully"
}
# 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
# Set vlan1 back to default
if [[ "$1" = "-d" -o "$1" = "--delete" ]]; then
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 "$DeadVLAN2"
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 | cut -d ',' -f 4)
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 | cut -d ',' -f 4)
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
if [[ "$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" && "$1" = "BondCreated" ]]; then
Delete_Bond -d
elif [ "$1" = "BondCreated" ]; then
return
fi
echo -e "\n--- Bond Errors ---"
echo "$Error1"
echo "$Error2"
echo "$Error3"
echo "$Error4"
echo "$Error5"
echo -e "\n--- Bond Status ---\n"
echo -e "Bond Status: bond0 $Check1"
echo -e "Slave 1 Status: vlan=$CHECKVLAN1 Link=$Check2 Port=$PORT1"
echo -e "Slave 2 Status: vlan=$CHECKVLAN2 Link=$Check3 Port=$PORT2\n"
exit
}
# 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"
Help
fi
# The Ports Must not be the same
if [ $1 = $2 ]; then
echo -e "\nError : Port Entries Must Be Unique"
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"
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"
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
admin@RT-AC66U:/tmp/home/root# /jffs/scripts/LinkAgg 3 4
Bond Created Successfully
admin@RT-AC66U:/tmp/home/root# /jffs/scripts/LinkAgg -s
--- Bond Errors ---
--- Bond Status ---
Bond Status: bond0 UP
Slave 1 Status: vlan=vlan3 Link=UP Port=3
Slave 2 Status: vlan=vlan4 Link=UP Port=4
admin@RT-AC66U:/tmp/home/root# /jffs/scripts/LinkAgg -d
Welcome To SNBForums
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!