Browse Source

Added trunk bridges

Dmitry Yu Okunev 5 years ago
parent
commit
268309f62f
1 changed files with 37 additions and 3 deletions
  1. 37 3
      ipw

+ 37 - 3
ipw

@@ -361,7 +361,7 @@ case "$CMD" in
 		#GETTING INFORMATION ABOUT LXC INTERFACES IN BRIDGES
 
 		if [[ "$LXC_DIR" != "" ]]; then
-			LXC_BRIDGE_SLAVES=($(cat "$LXC_DIR"/*/config | tr -d " \t" | awk -F '=' '{if($1=="lxc.network.link") {BRIDGE=$2}; if($1=="lxc.network.veth.pair") {if(BRIDGE!="") {print $2":"BRIDGE; BRIDGE=""}} }'))
+			LXC_BRIDGE_SLAVES=($(cat "$LXC_DIR"/*/config 2>/dev/null | tr -d " \t" | awk -F '=' '{if($1=="lxc.network.link") {BRIDGE=$2}; if($1=="lxc.network.veth.pair") {if(BRIDGE!="") {print $2":"BRIDGE; BRIDGE=""}} }'))
 		fi
 		
 		#REMOVING UNNECESSARY D1Q
@@ -369,6 +369,27 @@ case "$CMD" in
 		OLD_D1Q_IFACES="`cat /sys/class/net/bonding_masters`"
 
 		for OLD_D1Q_IFACE in ${OLD_D1Q_IFACES[@]}; do
+
+			# Removing trunk bridge (like "bond0br")
+
+			TRUNK_BRIDGE_IS_USED=0
+			for D1Q_IFACE in ${D1Q_IFACES[@]}; do
+				if [[ "$D1Q_IFACE" == "$OLD_D1Q_IFACE" ]]; then
+					TRUNK_BRIDGE_IS_USED=1
+					break
+				fi
+			done
+
+			if [[ "$TRUNK_BRIDGE_IS_USED" -eq 0 ]]; then
+				OLD_TRUNK_BRIDGE="$OLD_D1Q_IFACE"br
+				if [[ -d /sys/class/net/"$OLD_TRUNK_BRIDGE" ]]; then
+					ip link set "$OLD_D1Q_IFACE" nomaster 2>/dev/null
+					ip link delete "$OLD_TRUNK_BRIDGE"
+				fi
+			fi
+
+			# Removing slaves and the interface itself
+
 			D1Q_IS_USED=0
 			OLD_SLAVES="`cat /sys/class/net/"$OLD_D1Q_IFACE"/bonding/slaves`"
 			for D1Q_IFACE in ${D1Q_IFACES[@]}; do
@@ -405,6 +426,9 @@ case "$CMD" in
 		declare -A REQUIRED_IFACENAME_HASH
 
 		for D1Q_IFACE_TMP in ${D1Q_IFACES[@]}; do #we should keep slave ifaces
+			REQUIRED_BRNAME_HASH["${D1Q_IFACE_TMP}br"]="${D1Q_IFACE_TMP}br"
+			REQUIRED_IFACENAME_HASH["$D1Q_IFACE_TMP"]="$D1Q_IFACE_TMP"
+
 			VLAN_N_BRIDGE_VARIABLE="${D1Q_IFACE_TMP}_VLAN_N_BRIDGES"
 			VLAN_N_BRIDGE_VARIABLE="${VLAN_N_BRIDGE_VARIABLE//[.]/_}[@]"
 			for VLAN_N_BRIDGE in "${!VLAN_N_BRIDGE_VARIABLE}"; do
@@ -552,10 +576,20 @@ case "$CMD" in
 				ip link set dev "$SLAVE" up
 			done
 
+			# Creating trunk bridge (like "bond0br")
+
+			TRUNK_BRIDGE="$D1Q_IFACE"br
+			if ! [[ -d /sys/class/net/"$TRUNK_BRIDGE" ]]; then
+				ip link add "$TRUNK_BRIDGE" type bridge
+				echo "$BRIDGE_FORWARD_DELAY" > /sys/devices/virtual/net/"$TRUNK_BRIDGE"/bridge/forward_delay
+				ip link set dev "$TRUNK_IFACE" up
+				ip link set "$D1Q_IFACE" master "$TRUNK_BRIDGE"
+			fi
+
+			# Creating necessary bridges and VLANs
+
 			VLAN_N_BRIDGE_VARIABLE="${D1Q_IFACE}_VLAN_N_BRIDGES"
 			VLAN_N_BRIDGE_VARIABLE="${VLAN_N_BRIDGE_VARIABLE//[.]/_}[@]"
-	
-			#CREATING NECESSARY BRIDGES AND VLANS
 
 			for VLAN_N_BRIDGE in "${!VLAN_N_BRIDGE_VARIABLE}"; do
 				parse_vlan_subvlan_bridge "${VLAN_N_BRIDGE}"