Add UPDOWN_INTERFACES option to ethercat.conf

This commit is contained in:
Nicola Fontana
2021-12-13 09:56:32 +00:00
committed by Florian Pose
parent 65285fe74c
commit 0ae450d7c7
2 changed files with 34 additions and 11 deletions

View File

@@ -61,12 +61,21 @@ MASTER0_DEVICE=""
# Note: The e100, e1000, e1000e, r8169, ccat and igb drivers are not built by
# default. Enable them with the --enable-<driver> configure switches.
#
# Attention: When using the generic driver, the corresponding Ethernet device
# has to be activated (with OS methods, for example 'ip link set ethX up'),
# before the master is started, otherwise all frames will time out.
#
DEVICE_MODULES=""
#
# List of interfaces to bring up and down automatically.
#
# Specify a space-separated list of interface names (such as eth0 or
# enp0s1) that shall be brought up on `ethercatctl start` and down on
# `ethercatctl stop`.
#
# When using the generic driver, the corresponding Ethernet device has to be
# activated before the master is started, otherwise all frames will time out.
# This the perfect use-case for `UPDOWN_INTERFACES`.
#
UPDOWN_INTERFACES=""
#
# Flags for loading kernel modules.
#

View File

@@ -53,18 +53,22 @@ fi
#------------------------------------------------------------------------------
is_mac_address() {
local x='[0-9a-fA-F]'
echo "$1" | grep -qE "^($x$x:){5}$x$x\$" -
}
#------------------------------------------------------------------------------
parse_mac_address() {
local DEVICENAMETOMAC
if [ -z "${1}" ]; then
MAC=""
elif echo ${1} | grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then
MAC=${1}
if [ -z "${1}" ] || is_mac_address "${1}"; then
MAC="${1}"
else
DEVICENAMETOMAC=$("${IP}" address show dev "${1}" |
awk '/link\/ether/ { print $2; }')
if echo "${DEVICENAMETOMAC}" |
grep -qE '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$'; then
MAC=${DEVICENAMETOMAC}
if is_mac_address "${DEVICENAMETOMAC}"; then
MAC="${DEVICENAMETOMAC}"
else
echo Invalid MAC address or interface name \""${1}"\" \
in ${ETHERCAT_CONFIG}
@@ -78,6 +82,11 @@ parse_mac_address() {
case "${1}" in
start)
# bring up all updown interfaces before anything else
for interface in $UPDOWN_INTERFACES; do
$IP link set dev $interface up
done
# construct DEVICES and BACKUPS from configuration variables
DEVICES=""
BACKUPS=""
@@ -165,6 +174,11 @@ stop)
${MODPROBE} ${MODPROBE_FLAGS} "${MODULE}"
done
# bring down all updown interfaces
for interface in $UPDOWN_INTERFACES; do
$IP link set dev $interface down
done
exit 0
;;