Skip to content

Commit b5984c8

Browse files
leitaoNipaLocal
authored andcommitted
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 f599020 ("net: netpoll: Initialize UDP checksum field before checksumming") Signed-off-by: Breno Leitao <leitao@debian.org> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: NipaLocal <nipa@local>
1 parent 366d1e9 commit b5984c8

File tree

2 files changed

+99
-30
lines changed

2 files changed

+99
-30
lines changed

tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ set -euo pipefail
1111
LIBDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")
1212

1313
SRCIF="" # to be populated later
14-
SRCIP=192.0.2.1
14+
SRCIP4="192.0.2.1"
15+
SRCIP6="fc00::1"
1516
DSTIF="" # to be populated later
16-
DSTIP=192.0.2.2
17+
DSTIP4="192.0.2.2"
18+
DSTIP6="fc00::2"
1719

1820
PORT="6666"
1921
MSG="netconsole selftest"
@@ -80,7 +82,23 @@ function configure_ip() {
8082
ip link set "${SRCIF}" up
8183
}
8284

85+
function select_ipv4_or_ipv6()
86+
{
87+
local VERSION=${1}
88+
89+
if [[ "$VERSION" == "ipv6" ]]
90+
then
91+
DSTIP="${DSTIP6}"
92+
SRCIP="${SRCIP6}"
93+
else
94+
DSTIP="${DSTIP4}"
95+
SRCIP="${SRCIP4}"
96+
fi
97+
}
98+
8399
function set_network() {
100+
local IP_VERSION=${1:-"ipv4"}
101+
84102
# setup_ns function is coming from lib.sh
85103
setup_ns NAMESPACE
86104

@@ -91,6 +109,7 @@ function set_network() {
91109
# Link both interfaces back to back
92110
link_ifaces
93111

112+
select_ipv4_or_ipv6 "${IP_VERSION}"
94113
configure_ip
95114
}
96115

@@ -119,6 +138,11 @@ function create_dynamic_target() {
119138
fi
120139

121140
echo 1 > "${NETCONS_PATH}"/enabled
141+
142+
# This will make sure that the kernel was able to
143+
# load the netconsole driver configuration. The console message
144+
# gets more organized/sequential as well.
145+
sleep 1
122146
}
123147

124148
# Generate the command line argument for netconsole following:
@@ -179,9 +203,18 @@ function set_user_data() {
179203

180204
function listen_port_and_save_to() {
181205
local OUTPUT=${1}
206+
local IPVERSION=${2:-"ipv4"}
207+
208+
if [ "${IPVERSION}" == "ipv4" ]
209+
then
210+
SOCAT_MODE="UDP-LISTEN"
211+
else
212+
SOCAT_MODE="UDP6-LISTEN"
213+
fi
214+
182215
# Just wait for 2 seconds
183216
timeout 2 ip netns exec "${NAMESPACE}" \
184-
socat UDP-LISTEN:"${PORT}",fork "${OUTPUT}"
217+
socat "${SOCAT_MODE}":"${PORT}",fork "${OUTPUT}"
185218
}
186219

187220
# Only validate that the message arrived properly
@@ -263,8 +296,15 @@ function check_for_dependencies() {
263296
exit "${ksft_skip}"
264297
fi
265298

266-
if ip addr list | grep -E "inet.*(${SRCIP}|${DSTIP})" 2> /dev/null; then
267-
echo "SKIP: IPs already in use. Skipping it" >&2
299+
REGEXP4="inet.*(${SRCIP4}|${DSTIP4})"
300+
REGEXP6="inet.*(${SRCIP6}|${DSTIP6})"
301+
if ip addr list | grep -E "${REGEXP4}" 2> /dev/null; then
302+
echo "SKIP: IPv4s already in use. Skipping it" >&2
303+
exit "${ksft_skip}"
304+
fi
305+
306+
if ip addr list | grep -E "${REGEXP6}" 2> /dev/null; then
307+
echo "SKIP: IPv6s already in use. Skipping it" >&2
268308
exit "${ksft_skip}"
269309
fi
270310
}
@@ -278,11 +318,13 @@ function check_for_taskset() {
278318

279319
# This is necessary if running multiple tests in a row
280320
function pkill_socat() {
281-
PROCESS_NAME="socat UDP-LISTEN:6666,fork ${OUTPUT_FILE}"
321+
PROCESS_NAME4="socat UDP-LISTEN:6666,fork ${OUTPUT_FILE}"
322+
PROCESS_NAME6="socat UDP6-LISTEN:6666,fork ${OUTPUT_FILE}"
282323
# socat runs under timeout(1), kill it if it is still alive
283324
# do not fail if socat doesn't exist anymore
284325
set +e
285-
pkill -f "${PROCESS_NAME}"
326+
pkill -f "${PROCESS_NAME4}"
327+
pkill -f "${PROCESS_NAME6}"
286328
set -e
287329
}
288330

@@ -294,3 +336,23 @@ function check_netconsole_module() {
294336
exit "${ksft_skip}"
295337
fi
296338
}
339+
340+
# A wrapper to translate protocol version to udp version
341+
function wait_for_port() {
342+
local NAMESPACE=${1}
343+
local PORT=${2}
344+
IP_VERSION=${3}
345+
346+
if [ "${IP_VERSION}" == "ipv6" ]
347+
then
348+
PROTOCOL="udp6"
349+
else
350+
PROTOCOL="udp"
351+
fi
352+
353+
wait_local_port_listen "${NAMESPACE}" "${PORT}" "${PROTOCOL}"
354+
# even after the port is open, let's wait 1 second before writing
355+
# otherwise the packet could be missed, and the test will fail. Happens
356+
# more frequently on IPv6
357+
sleep 1
358+
}

tools/testing/selftests/drivers/net/netcons_basic.sh

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,37 @@ trap cleanup EXIT
3636
# Run the test twice, with different format modes
3737
for FORMAT in "basic" "extended"
3838
do
39-
echo "Running with target mode: ${FORMAT}"
40-
# Create one namespace and two interfaces
41-
set_network
42-
# Create a dynamic target for netconsole
43-
create_dynamic_target "${FORMAT}"
44-
# Only set userdata for extended format
45-
if [ "$FORMAT" == "extended" ]
46-
then
47-
# Set userdata "key" with the "value" value
48-
set_user_data
49-
fi
50-
# Listed for netconsole port inside the namespace and destination interface
51-
listen_port_and_save_to "${OUTPUT_FILE}" &
52-
# Wait for socat to start and listen to the port.
53-
wait_local_port_listen "${NAMESPACE}" "${PORT}" udp
54-
# Send the message
55-
echo "${MSG}: ${TARGET}" > /dev/kmsg
56-
# Wait until socat saves the file to disk
57-
busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"
39+
for IP_VERSION in "ipv6" "ipv4"
40+
do
41+
echo "Running with target mode: ${FORMAT} (${IP_VERSION})"
42+
# Create one namespace and two interfaces
43+
set_network "${IP_VERSION}"
44+
# Create a dynamic target for netconsole
45+
create_dynamic_target "${FORMAT}"
46+
# Only set userdata for extended format
47+
if [ "$FORMAT" == "extended" ]
48+
then
49+
# Set userdata "key" with the "value" value
50+
set_user_data
51+
fi
52+
# Listed for netconsole port inside the namespace and
53+
# destination interface
54+
listen_port_and_save_to "${OUTPUT_FILE}" "${IP_VERSION}" &
55+
# Wait for socat to start and listen to the port.
56+
wait_for_port "${NAMESPACE}" "${PORT}" "${IP_VERSION}"
57+
# Send the message
58+
echo "${MSG}: ${TARGET}" > /dev/kmsg
59+
# Wait until socat saves the file to disk
60+
busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}"
5861

59-
# Make sure the message was received in the dst part
60-
# and exit
61-
validate_result "${OUTPUT_FILE}" "${FORMAT}"
62-
cleanup
62+
# Make sure the message was received in the dst part
63+
# and exit
64+
validate_result "${OUTPUT_FILE}" "${FORMAT}"
65+
# kill socat in case it is still running
66+
pkill_socat
67+
cleanup
68+
echo "${FORMAT} : ${IP_VERSION} : Test passed" >&2
69+
done
6370
done
6471

6572
trap - EXIT

0 commit comments

Comments
 (0)