From 2141e10bafc87aae46ab5b323351bf822352a3e1 Mon Sep 17 00:00:00 2001 From: Florian Pose <fp@igh-essen.com> Date: Mon, 26 Jun 2006 14:36:11 +0000 Subject: [PATCH] Configuring EoE bridge at startup. --- script/ethercat.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++-- script/sysconfig | 30 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/script/ethercat.sh b/script/ethercat.sh index 5899b606..086ff1ae 100755 --- a/script/ethercat.sh +++ b/script/ethercat.sh @@ -66,14 +66,14 @@ case "$1" in 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 @@ case "$1" in 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 ;; diff --git a/script/sysconfig b/script/sysconfig index cfaf478a..5bb4c7ac 100644 --- a/script/sysconfig +++ b/script/sysconfig @@ -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 + #------------------------------------------------------------------------------ -- GitLab