1*b3827c91SAndre Carvalho#!/usr/bin/env bash 2*b3827c91SAndre Carvalho# SPDX-License-Identifier: GPL-2.0 3*b3827c91SAndre Carvalho 4*b3827c91SAndre Carvalho# This test creates two netdevsim virtual interfaces, assigns one of them (the 5*b3827c91SAndre Carvalho# "destination interface") to a new namespace, and assigns IP addresses to both 6*b3827c91SAndre Carvalho# interfaces. 7*b3827c91SAndre Carvalho# 8*b3827c91SAndre Carvalho# It listens on the destination interface using socat and configures a dynamic 9*b3827c91SAndre Carvalho# target on netconsole, pointing to the destination IP address. 10*b3827c91SAndre Carvalho# 11*b3827c91SAndre Carvalho# Finally, it checks whether the message was received properly on the 12*b3827c91SAndre Carvalho# destination interface. Note that this test may pollute the kernel log buffer 13*b3827c91SAndre Carvalho# (dmesg) and relies on dynamic configuration and namespaces being configured. 14*b3827c91SAndre Carvalho# 15*b3827c91SAndre Carvalho# Author: Breno Leitao <leitao@debian.org> 16*b3827c91SAndre Carvalho 17*b3827c91SAndre Carvalhoset -euo pipefail 18*b3827c91SAndre Carvalho 19*b3827c91SAndre CarvalhoSCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") 20*b3827c91SAndre Carvalho 21*b3827c91SAndre Carvalhosource "${SCRIPTDIR}"/../lib/sh/lib_netcons.sh 22*b3827c91SAndre Carvalho 23*b3827c91SAndre Carvalhomodprobe netdevsim 2> /dev/null || true 24*b3827c91SAndre Carvalhomodprobe netconsole 2> /dev/null || true 25*b3827c91SAndre Carvalho 26*b3827c91SAndre Carvalho# The content of kmsg will be save to the following file 27*b3827c91SAndre CarvalhoOUTPUT_FILE="/tmp/${TARGET}" 28*b3827c91SAndre Carvalho 29*b3827c91SAndre Carvalho# Check for basic system dependency and exit if not found 30*b3827c91SAndre Carvalhocheck_for_dependencies 31*b3827c91SAndre Carvalho# Remove the namespace, interfaces and netconsole target on exit 32*b3827c91SAndre Carvalhotrap cleanup EXIT 33*b3827c91SAndre Carvalho 34*b3827c91SAndre Carvalho# Run the test twice, with different format modes 35*b3827c91SAndre Carvalhofor FORMAT in "basic" "extended" 36*b3827c91SAndre Carvalhodo 37*b3827c91SAndre Carvalho for IP_VERSION in "ipv6" "ipv4" 38*b3827c91SAndre Carvalho do 39*b3827c91SAndre Carvalho echo "Running with target mode: ${FORMAT} (${IP_VERSION})" 40*b3827c91SAndre Carvalho # Set current loglevel to KERN_INFO(6), and default to 41*b3827c91SAndre Carvalho # KERN_NOTICE(5) 42*b3827c91SAndre Carvalho echo "6 5" > /proc/sys/kernel/printk 43*b3827c91SAndre Carvalho # Create one namespace and two interfaces 44*b3827c91SAndre Carvalho set_network "${IP_VERSION}" 45*b3827c91SAndre Carvalho # Create a dynamic target for netconsole 46*b3827c91SAndre Carvalho create_dynamic_target "${FORMAT}" 47*b3827c91SAndre Carvalho # Only set userdata for extended format 48*b3827c91SAndre Carvalho if [ "$FORMAT" == "extended" ] 49*b3827c91SAndre Carvalho then 50*b3827c91SAndre Carvalho # Set userdata "key" with the "value" value 51*b3827c91SAndre Carvalho set_user_data 52*b3827c91SAndre Carvalho fi 53*b3827c91SAndre Carvalho # Listed for netconsole port inside the namespace and 54*b3827c91SAndre Carvalho # destination interface 55*b3827c91SAndre Carvalho listen_port_and_save_to "${OUTPUT_FILE}" "${IP_VERSION}" & 56*b3827c91SAndre Carvalho # Wait for socat to start and listen to the port. 57*b3827c91SAndre Carvalho wait_for_port "${NAMESPACE}" "${PORT}" "${IP_VERSION}" 58*b3827c91SAndre Carvalho # Send the message 59*b3827c91SAndre Carvalho echo "${MSG}: ${TARGET}" > /dev/kmsg 60*b3827c91SAndre Carvalho # Wait until socat saves the file to disk 61*b3827c91SAndre Carvalho busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}" 62*b3827c91SAndre Carvalho 63*b3827c91SAndre Carvalho # Make sure the message was received in the dst part 64*b3827c91SAndre Carvalho # and exit 65*b3827c91SAndre Carvalho validate_result "${OUTPUT_FILE}" "${FORMAT}" 66*b3827c91SAndre Carvalho # kill socat in case it is still running 67*b3827c91SAndre Carvalho pkill_socat 68*b3827c91SAndre Carvalho cleanup 69*b3827c91SAndre Carvalho echo "${FORMAT} : ${IP_VERSION} : Test passed" >&2 70*b3827c91SAndre Carvalho done 71*b3827c91SAndre Carvalhodone 72*b3827c91SAndre Carvalho 73*b3827c91SAndre Carvalhotrap - EXIT 74*b3827c91SAndre Carvalhoexit "${ksft_pass}" 75