mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-02 10:31:26 -04:00
selftests: net: Add IPv6 support to netconsole basic tests
Add IPv6 support to the netconsole basic functionality tests by:
- Introducing separate IPv4 and IPv6 address variables (SRCIP4/SRCIP6,
DSTIP4/DSTIP6) to replace the single SRCIP/DSTIP variables
- Adding select_ipv4_or_ipv6() function to choose protocol version
- Updating socat configuration to use UDP6-LISTEN for IPv6 tests
- Adding wait_for_port() wrapper to handle protocol-specific port waiting
- Expanding test matrix to run both basic and extended formats against
both IPv4 and IPv6 protocols
- Improving cleanup to kill any remaining socat processes
- Adding sleep delays for better IPv6 packet handling reliability
The test now validates netconsole functionality across both IP versions,
improving test coverage for dual-stack network environments.
This test would avoid the regression fixed by commit f599020702 ("net:
netpoll: Initialize UDP checksum field before checksumming")
Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250702-netpoll_untagle_ip-v2-7-13cf3db24e2b@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
eb4e773f13
commit
3dc6c76391
@@ -11,9 +11,11 @@ set -euo pipefail
|
|||||||
LIBDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")
|
LIBDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")
|
||||||
|
|
||||||
SRCIF="" # to be populated later
|
SRCIF="" # to be populated later
|
||||||
SRCIP=192.0.2.1
|
SRCIP4="192.0.2.1"
|
||||||
|
SRCIP6="fc00::1"
|
||||||
DSTIF="" # to be populated later
|
DSTIF="" # to be populated later
|
||||||
DSTIP=192.0.2.2
|
DSTIP4="192.0.2.2"
|
||||||
|
DSTIP6="fc00::2"
|
||||||
|
|
||||||
PORT="6666"
|
PORT="6666"
|
||||||
MSG="netconsole selftest"
|
MSG="netconsole selftest"
|
||||||
@@ -80,7 +82,23 @@ function configure_ip() {
|
|||||||
ip link set "${SRCIF}" up
|
ip link set "${SRCIF}" up
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function select_ipv4_or_ipv6()
|
||||||
|
{
|
||||||
|
local VERSION=${1}
|
||||||
|
|
||||||
|
if [[ "$VERSION" == "ipv6" ]]
|
||||||
|
then
|
||||||
|
DSTIP="${DSTIP6}"
|
||||||
|
SRCIP="${SRCIP6}"
|
||||||
|
else
|
||||||
|
DSTIP="${DSTIP4}"
|
||||||
|
SRCIP="${SRCIP4}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function set_network() {
|
function set_network() {
|
||||||
|
local IP_VERSION=${1:-"ipv4"}
|
||||||
|
|
||||||
# setup_ns function is coming from lib.sh
|
# setup_ns function is coming from lib.sh
|
||||||
setup_ns NAMESPACE
|
setup_ns NAMESPACE
|
||||||
|
|
||||||
@@ -91,6 +109,7 @@ function set_network() {
|
|||||||
# Link both interfaces back to back
|
# Link both interfaces back to back
|
||||||
link_ifaces
|
link_ifaces
|
||||||
|
|
||||||
|
select_ipv4_or_ipv6 "${IP_VERSION}"
|
||||||
configure_ip
|
configure_ip
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +138,11 @@ function create_dynamic_target() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo 1 > "${NETCONS_PATH}"/enabled
|
echo 1 > "${NETCONS_PATH}"/enabled
|
||||||
|
|
||||||
|
# This will make sure that the kernel was able to
|
||||||
|
# load the netconsole driver configuration. The console message
|
||||||
|
# gets more organized/sequential as well.
|
||||||
|
sleep 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate the command line argument for netconsole following:
|
# Generate the command line argument for netconsole following:
|
||||||
@@ -179,9 +203,18 @@ function set_user_data() {
|
|||||||
|
|
||||||
function listen_port_and_save_to() {
|
function listen_port_and_save_to() {
|
||||||
local OUTPUT=${1}
|
local OUTPUT=${1}
|
||||||
|
local IPVERSION=${2:-"ipv4"}
|
||||||
|
|
||||||
|
if [ "${IPVERSION}" == "ipv4" ]
|
||||||
|
then
|
||||||
|
SOCAT_MODE="UDP-LISTEN"
|
||||||
|
else
|
||||||
|
SOCAT_MODE="UDP6-LISTEN"
|
||||||
|
fi
|
||||||
|
|
||||||
# Just wait for 2 seconds
|
# Just wait for 2 seconds
|
||||||
timeout 2 ip netns exec "${NAMESPACE}" \
|
timeout 2 ip netns exec "${NAMESPACE}" \
|
||||||
socat UDP-LISTEN:"${PORT}",fork "${OUTPUT}"
|
socat "${SOCAT_MODE}":"${PORT}",fork "${OUTPUT}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Only validate that the message arrived properly
|
# Only validate that the message arrived properly
|
||||||
@@ -263,8 +296,15 @@ function check_for_dependencies() {
|
|||||||
exit "${ksft_skip}"
|
exit "${ksft_skip}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ip addr list | grep -E "inet.*(${SRCIP}|${DSTIP})" 2> /dev/null; then
|
REGEXP4="inet.*(${SRCIP4}|${DSTIP4})"
|
||||||
echo "SKIP: IPs already in use. Skipping it" >&2
|
REGEXP6="inet.*(${SRCIP6}|${DSTIP6})"
|
||||||
|
if ip addr list | grep -E "${REGEXP4}" 2> /dev/null; then
|
||||||
|
echo "SKIP: IPv4s already in use. Skipping it" >&2
|
||||||
|
exit "${ksft_skip}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ip addr list | grep -E "${REGEXP6}" 2> /dev/null; then
|
||||||
|
echo "SKIP: IPv6s already in use. Skipping it" >&2
|
||||||
exit "${ksft_skip}"
|
exit "${ksft_skip}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -278,11 +318,13 @@ function check_for_taskset() {
|
|||||||
|
|
||||||
# This is necessary if running multiple tests in a row
|
# This is necessary if running multiple tests in a row
|
||||||
function pkill_socat() {
|
function pkill_socat() {
|
||||||
PROCESS_NAME="socat UDP-LISTEN:6666,fork ${OUTPUT_FILE}"
|
PROCESS_NAME4="socat UDP-LISTEN:6666,fork ${OUTPUT_FILE}"
|
||||||
|
PROCESS_NAME6="socat UDP6-LISTEN:6666,fork ${OUTPUT_FILE}"
|
||||||
# socat runs under timeout(1), kill it if it is still alive
|
# socat runs under timeout(1), kill it if it is still alive
|
||||||
# do not fail if socat doesn't exist anymore
|
# do not fail if socat doesn't exist anymore
|
||||||
set +e
|
set +e
|
||||||
pkill -f "${PROCESS_NAME}"
|
pkill -f "${PROCESS_NAME4}"
|
||||||
|
pkill -f "${PROCESS_NAME6}"
|
||||||
set -e
|
set -e
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,3 +336,23 @@ function check_netconsole_module() {
|
|||||||
exit "${ksft_skip}"
|
exit "${ksft_skip}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# A wrapper to translate protocol version to udp version
|
||||||
|
function wait_for_port() {
|
||||||
|
local NAMESPACE=${1}
|
||||||
|
local PORT=${2}
|
||||||
|
IP_VERSION=${3}
|
||||||
|
|
||||||
|
if [ "${IP_VERSION}" == "ipv6" ]
|
||||||
|
then
|
||||||
|
PROTOCOL="udp6"
|
||||||
|
else
|
||||||
|
PROTOCOL="udp"
|
||||||
|
fi
|
||||||
|
|
||||||
|
wait_local_port_listen "${NAMESPACE}" "${PORT}" "${PROTOCOL}"
|
||||||
|
# even after the port is open, let's wait 1 second before writing
|
||||||
|
# otherwise the packet could be missed, and the test will fail. Happens
|
||||||
|
# more frequently on IPv6
|
||||||
|
sleep 1
|
||||||
|
}
|
||||||
|
|||||||
@@ -36,30 +36,37 @@ trap cleanup EXIT
|
|||||||
# Run the test twice, with different format modes
|
# Run the test twice, with different format modes
|
||||||
for FORMAT in "basic" "extended"
|
for FORMAT in "basic" "extended"
|
||||||
do
|
do
|
||||||
echo "Running with target mode: ${FORMAT}"
|
for IP_VERSION in "ipv6" "ipv4"
|
||||||
# Create one namespace and two interfaces
|
do
|
||||||
set_network
|
echo "Running with target mode: ${FORMAT} (${IP_VERSION})"
|
||||||
# Create a dynamic target for netconsole
|
# Create one namespace and two interfaces
|
||||||
create_dynamic_target "${FORMAT}"
|
set_network "${IP_VERSION}"
|
||||||
# Only set userdata for extended format
|
# Create a dynamic target for netconsole
|
||||||
if [ "$FORMAT" == "extended" ]
|
create_dynamic_target "${FORMAT}"
|
||||||
then
|
# Only set userdata for extended format
|
||||||
# Set userdata "key" with the "value" value
|
if [ "$FORMAT" == "extended" ]
|
||||||
set_user_data
|
then
|
||||||
fi
|
# Set userdata "key" with the "value" value
|
||||||
# Listed for netconsole port inside the namespace and destination interface
|
set_user_data
|
||||||
listen_port_and_save_to "${OUTPUT_FILE}" &
|
fi
|
||||||
# Wait for socat to start and listen to the port.
|
# Listed for netconsole port inside the namespace and
|
||||||
wait_local_port_listen "${NAMESPACE}" "${PORT}" udp
|
# destination interface
|
||||||
# Send the message
|
listen_port_and_save_to "${OUTPUT_FILE}" "${IP_VERSION}" &
|
||||||
echo "${MSG}: ${TARGET}" > /dev/kmsg
|
# Wait for socat to start and listen to the port.
|
||||||
# Wait until socat saves the file to disk
|
wait_for_port "${NAMESPACE}" "${PORT}" "${IP_VERSION}"
|
||||||
busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"
|
# Send the message
|
||||||
|
echo "${MSG}: ${TARGET}" > /dev/kmsg
|
||||||
|
# Wait until socat saves the file to disk
|
||||||
|
busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"
|
||||||
|
|
||||||
# Make sure the message was received in the dst part
|
# Make sure the message was received in the dst part
|
||||||
# and exit
|
# and exit
|
||||||
validate_result "${OUTPUT_FILE}" "${FORMAT}"
|
validate_result "${OUTPUT_FILE}" "${FORMAT}"
|
||||||
cleanup
|
# kill socat in case it is still running
|
||||||
|
pkill_socat
|
||||||
|
cleanup
|
||||||
|
echo "${FORMAT} : ${IP_VERSION} : Test passed" >&2
|
||||||
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
trap - EXIT
|
trap - EXIT
|
||||||
|
|||||||
Reference in New Issue
Block a user