xref: /linux/tools/testing/selftests/net/rtnetlink_notification.sh (revision fa2f0454174c2f33005f5a6e6f70c7160a15b2a1)
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"
12
13source lib.sh
14
15kci_test_mcast_addr_notification()
16{
17	RET=0
18	local tmpfile
19	local monitor_pid
20	local match_result
21	local test_dev="test-dummy1"
22
23	tmpfile=$(mktemp)
24	defer rm "$tmpfile"
25
26	ip monitor maddr > $tmpfile &
27	monitor_pid=$!
28	defer kill_process "$monitor_pid"
29
30	sleep 1
31
32	if [ ! -e "/proc/$monitor_pid" ]; then
33		RET=$ksft_skip
34		log_test "mcast addr notification: iproute2 too old"
35		return $RET
36	fi
37
38	ip link add name "$test_dev" type dummy
39	check_err $? "failed to add dummy interface"
40	ip link set "$test_dev" up
41	check_err $? "failed to set dummy interface up"
42	ip link del dev "$test_dev"
43	check_err $? "Failed to delete dummy interface"
44	sleep 1
45
46	# There should be 4 line matches as follows.
47	# 13: test-dummy1    inet6 mcast ff02::1 scope global 
48	# 13: test-dummy1    inet mcast 224.0.0.1 scope global 
49	# Deleted 13: test-dummy1    inet mcast 224.0.0.1 scope global 
50	# Deleted 13: test-dummy1    inet6 mcast ff02::1 scope global 
51	match_result=$(grep -cE "$test_dev.*(224.0.0.1|ff02::1)" "$tmpfile")
52	if [ "$match_result" -ne 4 ]; then
53		RET=$ksft_fail
54	fi
55	log_test "mcast addr notification: Expected 4 matches, got $match_result"
56	return $RET
57}
58
59#check for needed privileges
60if [ "$(id -u)" -ne 0 ];then
61	RET=$ksft_skip
62	log_test "need root privileges"
63	exit $RET
64fi
65
66require_command ip
67
68tests_run
69
70exit $EXIT_STATUS
71