Configuring EoE bridge at startup.
authorFlorian Pose <fp@igh-essen.com>
Mon, 26 Jun 2006 14:36:11 +0000
changeset 283 a480a0703c58
parent 282 b9f15748cade
child 284 7eed6020d5cf
Configuring EoE bridge at startup.
script/ethercat.sh
script/sysconfig
--- a/script/ethercat.sh	Mon Jun 26 14:35:37 2006 +0000
+++ b/script/ethercat.sh	Mon Jun 26 14:36:11 2006 +0000
@@ -66,14 +66,14 @@
     start)
 	echo -n "Starting EtherCAT master "
 
-	if [ ! $DEVICE_INDEX ]; then
+	if [ -z "$DEVICE_INDEX" ]; then
 	    echo "ERROR: DEVICE_INDEX not set!"
 	    /bin/false
 	    rc_status -v
 	    rc_exit
 	fi
 
-	if [ ! $EOE_DEVICES ]; then
+	if [ -z "$EOE_DEVICES" ]; then
 	    EOE_DEVICES=0
 	fi
 
@@ -99,6 +99,50 @@
 	    rc_exit
 	fi
 
+	# Build EoE bridge
+	if [ -n "$EOE_BRIDGE" ]; then
+
+		EOE_INTERFACES=`/sbin/ifconfig -a | grep -o -E "^eoe[0-9]+ "`
+
+		# add bridge, if it does not already exist
+		if ! /sbin/brctl show | grep -E -q "^$EOE_BRIDGE"; then
+			if ! /sbin/brctl addbr $EOE_BRIDGE; then
+				/bin/false
+				rc_status -v
+				rc_exit
+			fi
+		fi
+
+		# free all interfaces of their addresses and add them to the bridge
+		for interface in $EOE_INTERFACES $EOE_EXTRA_INTERFACES; do
+			if ! /sbin/ifconfig $interface 0.0.0.0 up; then
+				/bin/false
+				rc_status -v
+				rc_exit
+			fi
+			if ! /sbin/brctl show | grep -E -q "^$EOE_BRIDGE.*$interface"; then
+				if ! /sbin/brctl addif $EOE_BRIDGE $interface; then
+					/bin/false
+					rc_status -v
+					rc_exit
+				fi
+			fi
+		done
+		if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then
+			if ! /sbin/ifconfig $EOE_BRIDGE $EOE_IP_ADDRESS \
+				netmask $EOE_IP_NETMASK; then
+				/bin/false
+				rc_status -v
+				rc_exit
+			fi
+		fi
+		if ! /sbin/ifconfig $EOE_BRIDGE up; then
+			/bin/false
+			rc_status -v
+			rc_exit
+		fi
+	fi
+
 	rc_status -v
 	;;
 
--- a/script/sysconfig	Mon Jun 26 14:35:37 2006 +0000
+++ b/script/sysconfig	Mon Jun 26 14:36:11 2006 +0000
@@ -18,4 +18,34 @@
 #
 #EOE_DEVICES=0
 
+#
+#  Bridge all EoE interfaces after master startup
+#  This variable shall contain the name of the EoE bridge to set up.
+#  If the variable is empty or undefined, no EoE bridge will be built.
+#
+#EOE_BRIDGE=eoebr0
+
+#
+#  IP address of the EoE bridge
+#  Set both EOE_IP_ADDRESS and EOE_IP_NETMASK to let the local host communicate
+#  with devices on the EoE bridge.
+#
+#EOE_IP_ADDRESS=192.168.X.X
+
+#
+#  IP netmask of the EoE bridge
+#  See EOE_IP_ADDRESS.
+#
+#EOE_IP_NETMASK=255.255.255.0
+
+#
+#  List of extra interfaces to include in the EoE bridge.
+#  Set this to interconnect the EoE bridge with other local interfaces.
+#  If EOE_BRIDGE is empty or undefined, setting this variable has no effect.
+#  Important: The IP address of these interfaces will be cleared. Set
+#  EOE_IP_ADDRESS and EOE_IP_NETMASK accordingly to enable IP traffic to
+#  extra interfaces.
+#
+#EOE_EXTRA_INTERFACES=eth0
+
 #------------------------------------------------------------------------------