Merge branch 'UPDOWN_INTERFACES' into 'stable-1.6'

Add UPDOWN_INTERFACES option to ethercat.conf

See merge request etherlab.org/ethercat!157
This commit is contained in:
Florian Pose 2025-02-17 09:12:05 +00:00
commit 4ce0c74d35
2 changed files with 34 additions and 11 deletions

View File

@ -61,10 +61,6 @@ MASTER0_DEVICE=""
# Note: The e100, e1000, e1000e, r8169, ccat, igb and igc drivers are not built by # Note: The e100, e1000, e1000e, r8169, ccat, igb and igc drivers are not built by
# default. Enable them with the --enable-<driver> configure switches. # 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="" DEVICE_MODULES=""
# If you have any issues about network interfaces not being configured # If you have any issues about network interfaces not being configured
@ -72,6 +68,19 @@ DEVICE_MODULES=""
# Have a look at the service file, you'll find some details there. # Have a look at the service file, you'll find some details there.
# #
#
# 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. # Flags for loading kernel modules.
# #

View File

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