Path: blob/master/tools/testing/selftests/drivers/net/netconsole/netcons_resume.sh
121896 views
#!/usr/bin/env bash1# SPDX-License-Identifier: GPL-2.023# This test validates that netconsole is able to resume a target that was4# deactivated when its interface was removed when the interface is brought5# back up.6#7# The test configures a netconsole target and then removes netdevsim module to8# cause the interface to disappear. Targets are configured via cmdline to ensure9# targets bound by interface name and mac address can be resumed.10# The test verifies that the target moved to disabled state before adding11# netdevsim and the interface back.12#13# Finally, the test verifies that the target is re-enabled automatically and14# the message is received on the destination interface.15#16# Author: Andre Carvalho <[email protected]>1718set -euo pipefail1920SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")2122source "${SCRIPTDIR}"/../lib/sh/lib_netcons.sh2324SAVED_SRCMAC="" # to be populated later25SAVED_DSTMAC="" # to be populated later2627modprobe netdevsim 2> /dev/null || true28rmmod netconsole 2> /dev/null || true2930check_netconsole_module3132function cleanup() {33cleanup_netcons "${NETCONS_CONFIGFS}/cmdline0"34do_cleanup35rmmod netconsole36}3738function trigger_reactivation() {39# Add back low level module40modprobe netdevsim41# Recreate namespace and two interfaces42set_network43# Restore MACs44ip netns exec "${NAMESPACE}" ip link set "${DSTIF}" \45address "${SAVED_DSTMAC}"46if [ "${BINDMODE}" == "mac" ]; then47ip link set dev "${SRCIF}" down48ip link set dev "${SRCIF}" address "${SAVED_SRCMAC}"49# Rename device in order to trigger target resume, as initial50# when device was recreated it didn't have correct mac address.51ip link set dev "${SRCIF}" name "${TARGET}"52fi53}5455function trigger_deactivation() {56# Start by storing mac addresses so we can be restored in reactivate57SAVED_DSTMAC=$(ip netns exec "${NAMESPACE}" \58cat /sys/class/net/"$DSTIF"/address)59SAVED_SRCMAC=$(mac_get "${SRCIF}")60# Remove low level module61rmmod netdevsim62}6364trap cleanup EXIT6566# Run the test twice, with different cmdline parameters67for BINDMODE in "ifname" "mac"68do69echo "Running with bind mode: ${BINDMODE}" >&270# Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5)71echo "6 5" > /proc/sys/kernel/printk7273# Create one namespace and two interfaces74set_network7576# Create the command line for netconsole, with the configuration from77# the function above78CMDLINE=$(create_cmdline_str "${BINDMODE}")7980# The content of kmsg will be save to the following file81OUTPUT_FILE="/tmp/${TARGET}-${BINDMODE}"8283# Load the module, with the cmdline set84modprobe netconsole "${CMDLINE}"85# Expose cmdline target in configfs86mkdir "${NETCONS_CONFIGFS}/cmdline0"8788# Target should be enabled89wait_target_state "cmdline0" "enabled"9091# Trigger deactivation by unloading netdevsim module. Target should be92# disabled.93trigger_deactivation94wait_target_state "cmdline0" "disabled"9596# Trigger reactivation by loading netdevsim, recreating the network and97# restoring mac addresses. Target should be re-enabled.98trigger_reactivation99wait_target_state "cmdline0" "enabled"100101# Listen for netconsole port inside the namespace and destination102# interface103listen_port_and_save_to "${OUTPUT_FILE}" &104# Wait for socat to start and listen to the port.105wait_local_port_listen "${NAMESPACE}" "${PORT}" udp106# Send the message107echo "${MSG}: ${TARGET}" > /dev/kmsg108# Wait until socat saves the file to disk109busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"110# Make sure the message was received in the dst part111# and exit112validate_msg "${OUTPUT_FILE}"113114# kill socat in case it is still running115pkill_socat116# Cleanup & unload the module117cleanup118119echo "${BINDMODE} : Test passed" >&2120done121122trap - EXIT123exit "${EXIT_STATUS}"124125126