tools/testing/selftests/net/test_vxlan_vnifilter_notify.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/test_vxlan_vnifilter_notify.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/test_vxlan_vnifilter_notify.sh
Extension
.sh
Size
4482 bytes
Lines
185
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# shellcheck disable=SC2034,SC2154,SC2317,SC2329
#
# Test for VXLAN vnifilter netlink notifications (RTM_NEWTUNNEL /
# RTM_DELTUNNEL).
#
# Verifies that:
# - Adding a new VNI sends a notification
# - Adding a new VNI with a remote sends a notification
# - Deleting a VNI sends a notification
# - Re-adding an existing VNI with the same attributes does not send
#   a spurious notification
# - Updating an existing VNI's remote sends a notification
# - Deleting a non-existent VNI does not send a notification

source lib.sh

require_command bridge

VXLAN_DEV=vxlan100

ALL_TESTS="
	test_vni_add_notify
	test_vni_add_remote_notify
	test_vni_del_notify
	test_vni_readd_no_notify
	test_vni_update_remote_notify
	test_vni_del_nonexistent_no_notify
"

setup_prepare()
{
	setup_ns NS1
	defer cleanup_all_ns

	ip -n "$NS1" link add $VXLAN_DEV type vxlan dstport 4789 \
		local 10.0.0.1 nolearning external vnifilter
	ip -n "$NS1" link set $VXLAN_DEV up
}

# Run bridge monitor in the background, execute a command, then count
# the notification lines.
# Usage: vni_notify_check <command> [args...]
# Sets: NOTIFY_COUNT with the number of notifications observed.
vni_notify_check()
{
	local tmpf cmd_ret monitor_pid

	tmpf=$(mktemp)
	defer rm "$tmpf"

	defer_scope_push
		ip netns exec "$NS1" bridge monitor vni > "$tmpf" 2>/dev/null &
		monitor_pid=$!
		defer kill_process "$monitor_pid"

		sleep 0.5
		if [ ! -e "/proc/$monitor_pid" ]; then
			RET=$ksft_skip
			log_test "iproute2 'bridge monitor vni' not supported"
			return "$RET"
		fi

		"$@"
		cmd_ret=$?
		sleep 0.2
	defer_scope_pop

	NOTIFY_COUNT=$(grep -c "$VXLAN_DEV" "$tmpf")

Annotation

Implementation Notes