Browse Source

Adopted for manticore

Dmitry Yu Okunev 7 years ago
parent
commit
d71787c7ea
1 changed files with 60 additions and 31 deletions
  1. 60 31
      ipw

+ 60 - 31
ipw

@@ -1,7 +1,7 @@
 #!/bin/bash
 
 #    Copyright (C) 2013 Artyom A Anikeev <anikeev@ut.mephi.ru> 0xB5385841,
-#    Dmitry Yu Okunev <xai@mephi.ru> 0x8E30679C
+#                       Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
 
 CMD="$1"; shift;
 
-DEFAULT_BONDING_MODE='802.3ad'
+DEFAULT_BONDING_MODE='balance-tlb'
 
 eerror() {
 	echo "$@" >&2
@@ -278,6 +278,12 @@ case "$CMD" in
 		fi	;;
 	fix)	#fix all interfaces to config state
 		#brctl addif bond0 eth2
+
+		#GETTING INFORMATION ABOUT LXC INTERFACES IN BRIDGES
+
+		if [[ "$LXC_DIR" != "" ]]; then
+			LXC_BRIDGE_SLAVES=($(cat /srv/lxc/*/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=""}} }'))
+		fi
 		
 		#REMOVING UNNECESSARY D1Q
 
@@ -333,7 +339,7 @@ case "$CMD" in
 			IS_SLAVE=0
 			
 			BRIDGE_IN_USE=0
-			VLAN_IN_USE=0
+			IFACE_IN_USE=0
 			VLAN_N_BRIDGE_IN_USE=0
 			for D1Q_IFACE_TMP in ${D1Q_IFACES[@]}; do #we should keep slave ifaces
 				VLAN_N_BRIDGE_VARIABLE="${D1Q_IFACE_TMP}_VLAN_N_BRIDGES"
@@ -342,23 +348,36 @@ case "$CMD" in
 					parse_vlan_subvlan_bridge "${VLAN_N_BRIDGE}"
 					if [[ "$LINE" = "$D1Q_IFACE_TMP"."$VLAN_N_BRIDGE" ]]; then
 						BRIDGE_IN_USE=1
-						VLAN_IN_USE=1
+						IFACE_IN_USE=1
 						VLAN_N_BRIDGE_IN_USE=1
 						break 2
-					elif [[ "$BRNAME" = "$OLD_BRNAME" ]]; then
+					fi
+					if [[ "$OLD_BRNAME" = "$BRNAME" ]]; then
 						BRIDGE_IN_USE=1
-					elif [[ "$VLANNAME" = "$OLD_VLANNAME" ]]; then
-						VLAN_IN_USE=1
+					fi
+					if [[ "$OLD_VLANNAME" = "$VLANNAME" ]]; then
+						IFACE_IN_USE=1
+					fi
+					if [[ "$OLD_VLANNAME" = "$D1Q_IFACE_TMP"."$VLAN" ]]; then
+						IFACE_IN_USE=1
 					fi
 				done
 			done
+			for LXCIF_N_BRIDGE in ${LXC_BRIDGE_SLAVES[@]}; do
+				if [[ "$LINE" = "$LXCIF_N_BRIDGE" ]]; then
+					IFACE_IN_USE=1
+					break
+				fi
+			done
 			if [[ "$BRIDGE_IN_USE" = 0 ]]; then
-				#echo "ip link delete $OLD_BRNAME"
+				[[ "$OLD_BRNAME" != '' ]] &&
+					ip link delete "$OLD_BRNAME"
+			fi
+			if [[ "$IFACE_IN_USE" = 0 ]]; then
 				if [[ "$OLD_VLANNAME" != '' ]]; then
 					ip link set    "$OLD_VLANNAME" nomaster
 					ip link delete "$OLD_VLANNAME"
 				fi
-				ip link delete "$OLD_BRNAME"
 			fi
 		done
 
@@ -375,9 +394,9 @@ case "$CMD" in
 			for OLD_D1Q_IFACE in ${OLD_D1Q_IFACES[@]}; do
 				if [[ "$D1Q_IFACE" == "$OLD_D1Q_IFACE" ]]; then #it's here. Let's fix it.
 					OLD_SLAVES="`cat /sys/class/net/"$OLD_D1Q_IFACE"/bonding/slaves`"
-					OLD_BONDING_MODE="`cat /sys/class/net/"$OLD_D1Q_IFACE"/bonding/mode`"
+					OLD_BONDING_MODE=(`cat /sys/class/net/"$OLD_D1Q_IFACE"/bonding/mode`)
 
-					if [[ "$OLD_BONDING_MODE" != "${MODE}" ]]; then
+					if [ "${OLD_BONDING_MODE[0]}" != "${MODE}" -a "${OLD_BONDING_MODE[1]}" != "${MODE}" ]; then
 						for OLD_SLAVE in ${OLD_SLAVES[@]}; do
 							echo "-$OLD_SLAVE" > /sys/class/net/"$OLD_D1Q_IFACE"/bonding/slaves
 						done
@@ -453,7 +472,7 @@ case "$CMD" in
 
 				#VLAN STUFF
 				if  [[ "$VLAN" != "" ]]; then
-					if ! ip link show "$FULL_VLAN_NAME" 2>/dev/null; then #should we create a new vlan?
+					if ! ip link show "$FULL_VLAN_NAME" >/dev/null 2>/dev/null; then #should we create a new vlan?
 					#ip link show | grep -q "$FULL_VLAN_NAME"
 					#if $?; then #should we create a new vlan?
 						if [[ "$SUBVLAN" != "" ]]; then #is it subvlan?
@@ -462,7 +481,7 @@ case "$CMD" in
 							#echo FULL_PARVLAN_NAME $FULL_PARVLAN_NAME
 							#echo D1Q_IFACE $D1Q_IFACE 
 							##
-							if ! ip link show "$FULL_PARVLAN_NAME" 2>/dev/null; then #should we create a new parent vlan?
+							if ! ip link show "$FULL_PARVLAN_NAME" >/dev/null 2>/dev/null; then #should we create a new parent vlan?
 								#echo "ip link add link $D1Q_IFACE name $FULL_PARVLAN_NAME type vlan id $VLAN" #vlan in bond
 								ip link add link "$D1Q_IFACE" name "$FULL_PARVLAN_NAME" type vlan id "$VLAN" #vlan in bond
 								#echo "ip link set dev $FULL_PARVLAN_NAME up"
@@ -471,6 +490,7 @@ case "$CMD" in
 							#echo "ip link add link $FULL_PARVLAN_NAME name $FULL_VLAN_NAME type vlan id $SUBVLAN" #subvlan in vlan
 							ip link add link "$FULL_PARVLAN_NAME" name "$FULL_VLAN_NAME" type vlan id "$SUBVLAN" #subvlan in vlan
 							#echo "ip link set dev $FULL_VLAN_NAME up"
+							ip link set dev "$FULL_VLAN_NAME" mtu 1496
 							ip link set dev "$FULL_VLAN_NAME" up
 						else
 							#echo "ip link add link $D1Q_IFACE name $FULL_VLAN_NAME type vlan id $VLANNAME" #vlan in bond
@@ -489,15 +509,17 @@ case "$CMD" in
 				if [[ "$BRNAME" != "" ]]; then
 
 					#if [[ "`brctl show | grep "$BRNAME"`" = "" ]]; then #do this bridge exists?
-					if ! ip link show "$BRNAME" 2>/dev/null; then #do this bridge exists?
+					if ! ip link show "$BRNAME" >/dev/null 2>/dev/null; then #do this bridge exists?
 						#brctl addbr "$BRNAME"
 						#echo "ip link add "$BRNAME" type bridge"
 						ip link add "$BRNAME" type bridge
 					fi
+					[[ "$SUBVLAN" != "" ]] &&
+						ip link set dev "$BRNAME" mtu 1496
 
 					if [[ "$VLAN" != "" ]]; then
 						#OLD_BRNAME="`brctl show | grep "$FULL_VLANNAME" | awk '{print $1}'`"
-						OLD_BRNAME="`get_brname_byslave "$FULL_VLANNAME"`"
+						OLD_BRNAME="`get_brname_byslave "$FULL_VLAN_NAME"`"
 						if [[ "$OLD_BRNAME" = "" ]]; then #is this vlan have been already enslaved?
 							#brctl addif "$BRNAME" "$FULL_VLANNAME"
 							#echo "ip link set "$FULL_VLAN_NAME" master "$BRNAME
@@ -505,34 +527,42 @@ case "$CMD" in
 							#echo "ip link set dev $BRNAME up"
 							ip link set dev "$BRNAME" up
 						else
-							#brctl delif "$OLD_BRNAME" "FULL_VLANNAME"
-							#echo "ip link set "$FULL_VLAN_NAME" nomaster"
-							ip link set "$FULL_VLAN_NAME" nomaster
-							#brctl addif "$BRNAME" "$FULL_VLANNAME"
-							#echo "ip link set "$FULL_VLAN_NAME" master "$BRNAME
-							ip link set "$FULL_VLAN_NAME" master "$BRNAME"
-							#echo "ip link set dev $BRNAME up"
-							ip link set dev "$BRNAME" up
+							if [[ "$BRNAME" != "$OLD_BRNAME" ]]; then
+								#brctl delif "$OLD_BRNAME" "FULL_VLANNAME"
+								#echo "ip link set "$FULL_VLAN_NAME" nomaster"
+								ip link set "$FULL_VLAN_NAME" nomaster
+								#brctl addif "$BRNAME" "$FULL_VLANNAME"
+								#echo "ip link set "$FULL_VLAN_NAME" master "$BRNAME
+								ip link set "$FULL_VLAN_NAME" master "$BRNAME"
+								#echo "ip link set dev $BRNAME up"
+								ip link set dev "$BRNAME" up
+							fi
 						fi
 					fi
 
+					ip addr flush dev "$BRNAME"
 					IP_CMDS_VARIABLE="${BRNAME//[.]/_}_IP"
 					IP_CMDS_VARIABLE="${IP_CMDS_VARIABLE}[@]"
 					for IP_CMD in "${!IP_CMDS_VARIABLE}"; do
-						echo ip $IP_CMD dev "$BRNAME" | bash #2>/dev/null ||
-#						echo ip $IP_CMD | bash
+						ip $IP_CMD dev "$BRNAME"
 					done
 				else
+					ip addr flush dev "$VLANNAME"
 					IP_CMDS_VARIABLE="vlan${VLANNAME//[.]/_}_IP"
 					IP_CMDS_VARIABLE="${IP_CMDS_VARIABLE}[@]"
 					for IP_CMD in "${!IP_CMDS_VARIABLE}"; do
-						echo ip $IP_CMD dev "$VLANNAME" | bash #2>/dev/null ||
-#						echo ip $IP_CMD | bash
+						ip $IP_CMD dev "$VLANNAME"
 					done
 				fi
-			done			
+			done
 		done
 
+		# ADDING LXC IFACES TO BRIDGES IF REQUIRED
+#		for LXCIF_N_BRIDGE in ${LXC_BRIDGE_SLAVES[@]}; do
+#			parse_vlan_subvlan_bridge "$LINE"
+#			brctl addif "$BRNAME" "$VLANNAME" 2>/dev/null
+#		done
+
 		;;
 	*)
 		;;
@@ -581,7 +611,7 @@ for D1Q_IFACE in ${D1Q_IFACES[@]}; do
 			hasanIP_CMD=0
 			for IP_CMD in "${!IP_CMDS_VARIABLE}"; do
 				newconfig_push 128 "	\"$IP_CMD\""
-				echo ip $IP_CMD dev $BRNAME
+				#echo ip $IP_CMD dev $BRNAME
 				hasanIP_CMD=1
 			done
 
@@ -599,7 +629,7 @@ for D1Q_IFACE in ${D1Q_IFACES[@]}; do
 			hasanIP_CMD=0
 			for IP_CMD in "${!IP_CMDS_VARIABLE}"; do
 				newconfig_push 128 "	\"$IP_CMD\""
-				echo ip $IP_CMD dev $VLANNAME
+				#echo ip $IP_CMD dev $VLANNAME
 				hasanIP_CMD=1
 			done
 
@@ -613,7 +643,6 @@ for D1Q_IFACE in ${D1Q_IFACES[@]}; do
 		printf "br: %-10s vlan:%4s subvlan:%4s\n" "$BRNAME" "$VLAN" "$SUBVLAN"
 	done
 	newconfig_push 1 ")"
-	
 
 done