tools/testing/selftests/net/unicast_extensions.sh

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/unicast_extensions.sh
Extension
.sh
Size
7958 bytes
Lines
219
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
#
# By Seth Schoen (c) 2021, for the IPv4 Unicast Extensions Project
# Thanks to David Ahern for help and advice on nettest modifications.
#
# Self-tests for IPv4 address extensions: the kernel's ability to accept
# certain traditionally unused or unallocated IPv4 addresses. For each kind
# of address, we test for interface assignment, ping, TCP, and forwarding.
# Must be run as root (to manipulate network namespaces and virtual
# interfaces).
#
# Things we test for here:
#
# * Currently the kernel accepts addresses in 0/8 and 240/4 as valid.
#
# * Notwithstanding that, 0.0.0.0 and 255.255.255.255 cannot be assigned.
#
# * Currently the kernel DOES NOT accept unicast use of the lowest
#   address in an IPv4 subnet (e.g. 192.168.100.0/32 in 192.168.100.0/24).
#   This is treated as a second broadcast address, for compatibility
#   with 4.2BSD (!).
#
# * Currently the kernel DOES NOT accept unicast use of any of 127/8.
#
# * Currently the kernel DOES NOT accept unicast use of any of 224/4.
#
# These tests provide an easy way to flip the expected result of any
# of these behaviors for testing kernel patches that change them.

source lib.sh

check_gen_prog "nettest"

result=0

hide_output(){ exec 3>&1 4>&2 >/dev/null 2>/dev/null; }
show_output(){ exec >&3 2>&4; }

show_result(){
	if [ $1 -eq 0 ]; then
		printf "TEST: %-60s  [ OK ]\n" "${2}"
	else
		printf "TEST: %-60s  [FAIL]\n" "${2}"
		result=1
	fi
}

_do_segmenttest(){
	# Perform a simple set of link tests between a pair of
	# IP addresses on a shared (virtual) segment, using
	# ping and nettest.
	# foo --- bar
	# Arguments: ip_a ip_b prefix_length test_description
	#
	# Caller must set up $foo_ns and $bar_ns namespaces
	# containing linked veth devices foo and bar,
	# respectively.

	ip -n $foo_ns address add $1/$3 dev foo || return 1
	ip -n $foo_ns link set foo up || return 1
	ip -n $bar_ns address add $2/$3 dev bar || return 1
	ip -n $bar_ns link set bar up || return 1

	ip netns exec $foo_ns timeout 2 ping -c 1 $2 || return 1
	ip netns exec $bar_ns timeout 2 ping -c 1 $1 || return 1

	nettest -B -N $bar_ns -O $foo_ns -r $1 || return 1
	nettest -B -N $foo_ns -O $bar_ns -r $2 || return 1

Annotation

Implementation Notes