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