1#!/usr/bin/env bash 2# SPDX-License-Identifier: GPL-2.0 3 4# This test creates two netdevsim virtual interfaces, assigns one of them (the 5# "destination interface") to a new namespace, and assigns IP addresses to both 6# interfaces. 7# 8# It listens on the destination interface using socat and configures a dynamic 9# target on netconsole, pointing to the destination IP address. 10# 11# Finally, it checks whether the message was received properly on the 12# destination interface. Note that this test may pollute the kernel log buffer 13# (dmesg) and relies on dynamic configuration and namespaces being configured. 14# 15# Author: Breno Leitao <leitao@debian.org> 16 17set -euo pipefail 18 19SCRIPTDIR=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") 20 21source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh 22 23modprobe netdevsim 2> /dev/null || true 24modprobe netconsole 2> /dev/null || true 25 26# The content of kmsg will be save to the following file 27OUTPUT_FILE="/tmp/${TARGET}" 28 29# Check for basic system dependency and exit if not found 30check_for_dependencies 31# Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5) 32echo "6 5" > /proc/sys/kernel/printk 33# Remove the namespace, interfaces and netconsole target on exit 34trap cleanup EXIT 35# Create one namespace and two interfaces 36set_network 37# Create a dynamic target for netconsole 38create_dynamic_target 39# Set userdata "key" with the "value" value 40set_user_data 41# Listed for netconsole port inside the namespace and destination interface 42listen_port_and_save_to "${OUTPUT_FILE}" & 43# Wait for socat to start and listen to the port. 44wait_local_port_listen "${NAMESPACE}" "${PORT}" udp 45# Send the message 46echo "${MSG}: ${TARGET}" > /dev/kmsg 47# Wait until socat saves the file to disk 48busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}" 49 50# Make sure the message was received in the dst part 51# and exit 52validate_result "${OUTPUT_FILE}" 53