File Index
Files and directories
Sign in
FILE

rtnetlink_notification.sh

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/net/rtnetlink_notification.sh BASH
  1#!/bin/bash
  2# SPDX-License-Identifier: GPL-2.0
  3#
  4# This test is for checking rtnetlink notification callpaths, and get as much
  5# coverage as possible.
  6#
  7# set -e
  8
  9ALL_TESTS="
 10	kci_test_mcast_addr_notification
 11	kci_test_anycast_addr_notification
 12"
 13
 14source lib.sh
 15test_dev="test-dummy1"
 16
 17kci_test_mcast_addr_notification()
 18{
 19	RET=0
 20	local tmpfile
 21	local monitor_pid
 22	local match_result
 23
 24	tmpfile=$(mktemp)
 25	defer rm "$tmpfile"
 26
 27	ip monitor maddr > $tmpfile &
 28	monitor_pid=$!
 29	defer kill_process "$monitor_pid"
 30
 31	sleep 1
 32
 33	if [ ! -e "/proc/$monitor_pid" ]; then
 34		RET=$ksft_skip
 35		log_test "mcast addr notification: iproute2 too old"
 36		return $RET
 37	fi
 38
 39	ip link add name "$test_dev" type dummy
 40	check_err $? "failed to add dummy interface"
 41	ip link set "$test_dev" up
 42	check_err $? "failed to set dummy interface up"
 43	ip link del dev "$test_dev"
 44	check_err $? "Failed to delete dummy interface"
 45	sleep 1
 46
 47	# There should be 4 line matches as follows.
 48	# 13: test-dummy1    inet6 mcast ff02::1 scope global 
 49	# 13: test-dummy1    inet mcast 224.0.0.1 scope global 
 50	# Deleted 13: test-dummy1    inet mcast 224.0.0.1 scope global 
 51	# Deleted 13: test-dummy1    inet6 mcast ff02::1 scope global 
 52	match_result=$(grep -cE "$test_dev.*(224.0.0.1|ff02::1)" "$tmpfile")
 53	if [ "$match_result" -ne 4 ]; then
 54		RET=$ksft_fail
 55	fi
 56	log_test "mcast addr notification: Expected 4 matches, got $match_result"
 57	return $RET
 58}
 59
 60kci_test_anycast_addr_notification()
 61{
 62	RET=0
 63	local tmpfile
 64	local monitor_pid
 65	local match_result
 66
 67	tmpfile=$(mktemp)
 68	defer rm "$tmpfile"
 69
 70	ip monitor acaddress > "$tmpfile" &
 71	monitor_pid=$!
 72	defer kill_process "$monitor_pid"
 73	sleep 1
 74
 75	if [ ! -e "/proc/$monitor_pid" ]; then
 76		RET=$ksft_skip
 77		log_test "anycast addr notification: iproute2 too old"
 78		return "$RET"
 79	fi
 80
 81	ip link add name "$test_dev" type dummy
 82	check_err $? "failed to add dummy interface"
 83	ip link set "$test_dev" up
 84	check_err $? "failed to set dummy interface up"
 85	sysctl -qw net.ipv6.conf."$test_dev".forwarding=1
 86	ip link del dev "$test_dev"
 87	check_err $? "Failed to delete dummy interface"
 88	sleep 1
 89
 90	# There should be 2 line matches as follows.
 91	# 9: dummy2    inet6 any fe80:: scope global
 92	# Deleted 9: dummy2    inet6 any fe80:: scope global
 93	match_result=$(grep -cE "$test_dev.*(fe80::)" "$tmpfile")
 94	if [ "$match_result" -ne 2 ]; then
 95		RET=$ksft_fail
 96	fi
 97	log_test "anycast addr notification: Expected 2 matches, got $match_result"
 98	return "$RET"
 99}
100
101#check for needed privileges
102if [ "$(id -u)" -ne 0 ];then
103	RET=$ksft_skip
104	log_test "need root privileges"
105	exit $RET
106fi
107
108require_command ip
109
110tests_run
111
112exit $EXIT_STATUS
~/ Read-only file preview.