tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh

Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh
Extension
.sh
Size
11515 bytes
Lines
445
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

function configure_ip() {
	# Configure the IPs for both interfaces
	ip netns exec "${NAMESPACE}" ip addr add "${DSTIP}"/24 dev "${DSTIF}"
	ip netns exec "${NAMESPACE}" ip link set "${DSTIF}" up

	ip addr add "${SRCIP}"/24 dev "${SRCIF}"
	ip link set "${SRCIF}" up
}

function select_ipv4_or_ipv6()
{
	local VERSION=${1}

	if [[ "$VERSION" == "ipv6" ]]
	then
		DSTIP="${DSTIP6}"
		SRCIP="${SRCIP6}"
	else
		DSTIP="${DSTIP4}"
		SRCIP="${SRCIP4}"
	fi
}

function set_network() {
	local IP_VERSION=${1:-"ipv4"}

	# setup_ns function is coming from lib.sh
	setup_ns NAMESPACE

	# Create both interfaces, and assign the destination to a different
	# namespace
	create_ifaces

	# Link both interfaces back to back
	link_ifaces

	select_ipv4_or_ipv6 "${IP_VERSION}"
	configure_ip
}

function _create_dynamic_target() {
	local FORMAT="${1:?FORMAT parameter required}"
	local NCPATH="${2:?NCPATH parameter required}"

	DSTMAC=$(ip netns exec "${NAMESPACE}" \
		 ip link show "${DSTIF}" | awk '/ether/ {print $2}')

	# Create a dynamic target
	mkdir "${NCPATH}"

	echo "${DSTIP}" > "${NCPATH}"/remote_ip
	echo "${SRCIP}" > "${NCPATH}"/local_ip
	echo "${DSTMAC}" > "${NCPATH}"/remote_mac
	echo "${SRCIF}" > "${NCPATH}"/dev_name

	if [ "${FORMAT}" == "basic" ]
	then
		# Basic target does not support release
		echo 0 > "${NCPATH}"/release
		echo 0 > "${NCPATH}"/extended
	elif [ "${FORMAT}" == "extended" ]
	then
		echo 1 > "${NCPATH}"/extended
	fi
}

function create_dynamic_target() {
	local FORMAT=${1:-"extended"}
	local NCPATH=${2:-"$NETCONS_PATH"}
	_create_dynamic_target "${FORMAT}" "${NCPATH}"

Annotation

Implementation Notes