Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests: netconsole: Validate interface selection by MAC address

Extend the existing netconsole cmdline selftest to also validate that
interface selection can be performed via MAC address.

The test now validates that netconsole works with both interface name
and MAC address, improving test coverage.

Suggested-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Andre Carvalho <asantostc@gmail.com>
Link: https://patch.msgid.link/20250812-netcons-cmdline-selftest-v2-1-8099fb7afa9e@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Andre Carvalho and committed by
Jakub Kicinski
acfea936 3051f49b

+41 -20
+9 -1
tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh
··· 148 148 # Generate the command line argument for netconsole following: 149 149 # netconsole=[+][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr] 150 150 function create_cmdline_str() { 151 + local BINDMODE=${1:-"ifname"} 152 + if [ "${BINDMODE}" == "ifname" ] 153 + then 154 + SRCDEV=${SRCIF} 155 + else 156 + SRCDEV=$(mac_get "${SRCIF}") 157 + fi 158 + 151 159 DSTMAC=$(ip netns exec "${NAMESPACE}" \ 152 160 ip link show "${DSTIF}" | awk '/ether/ {print $2}') 153 161 SRCPORT="1514" 154 162 TGTPORT="6666" 155 163 156 - echo "netconsole=\"+${SRCPORT}@${SRCIP}/${SRCIF},${TGTPORT}@${DSTIP}/${DSTMAC}\"" 164 + echo "netconsole=\"+${SRCPORT}@${SRCIP}/${SRCDEV},${TGTPORT}@${DSTIP}/${DSTMAC}\"" 157 165 } 158 166 159 167 # Do not append the release to the header of the message
+32 -19
tools/testing/selftests/drivers/net/netcons_cmdline.sh
··· 19 19 modprobe netdevsim 2> /dev/null || true 20 20 rmmod netconsole 2> /dev/null || true 21 21 22 - # The content of kmsg will be save to the following file 23 - OUTPUT_FILE="/tmp/${TARGET}" 24 - 25 22 # Check for basic system dependency and exit if not found 26 23 # check_for_dependencies 27 24 # Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5) ··· 27 30 trap do_cleanup EXIT 28 31 # Create one namespace and two interfaces 29 32 set_network 30 - # Create the command line for netconsole, with the configuration from the 31 - # function above 32 - CMDLINE="$(create_cmdline_str)" 33 33 34 - # Load the module, with the cmdline set 35 - modprobe netconsole "${CMDLINE}" 34 + # Run the test twice, with different cmdline parameters 35 + for BINDMODE in "ifname" "mac" 36 + do 37 + echo "Running with bind mode: ${BINDMODE}" >&2 38 + # Create the command line for netconsole, with the configuration from 39 + # the function above 40 + CMDLINE=$(create_cmdline_str "${BINDMODE}") 36 41 37 - # Listed for netconsole port inside the namespace and destination interface 38 - listen_port_and_save_to "${OUTPUT_FILE}" & 39 - # Wait for socat to start and listen to the port. 40 - wait_local_port_listen "${NAMESPACE}" "${PORT}" udp 41 - # Send the message 42 - echo "${MSG}: ${TARGET}" > /dev/kmsg 43 - # Wait until socat saves the file to disk 44 - busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}" 45 - # Make sure the message was received in the dst part 46 - # and exit 47 - validate_msg "${OUTPUT_FILE}" 42 + # The content of kmsg will be save to the following file 43 + OUTPUT_FILE="/tmp/${TARGET}-${BINDMODE}" 44 + 45 + # Load the module, with the cmdline set 46 + modprobe netconsole "${CMDLINE}" 47 + 48 + # Listed for netconsole port inside the namespace and destination 49 + # interface 50 + listen_port_and_save_to "${OUTPUT_FILE}" & 51 + # Wait for socat to start and listen to the port. 52 + wait_local_port_listen "${NAMESPACE}" "${PORT}" udp 53 + # Send the message 54 + echo "${MSG}: ${TARGET}" > /dev/kmsg 55 + # Wait until socat saves the file to disk 56 + busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}" 57 + # Make sure the message was received in the dst part 58 + # and exit 59 + validate_msg "${OUTPUT_FILE}" 60 + 61 + # kill socat in case it is still running 62 + pkill_socat 63 + # Unload the module 64 + rmmod netconsole 65 + echo "${BINDMODE} : Test passed" >&2 66 + done 48 67 49 68 exit "${ksft_pass}"