tools/testing/selftests/drivers/net/bonding/netcons_over_bonding.sh

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

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/drivers/net/bonding/netcons_over_bonding.sh
Extension
.sh
Size
12110 bytes
Lines
362
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 setup_bonding_ifaces() {
	local RAND=$(( RANDOM % 100 ))
	BOND_TX_MAIN_IF="bond_tx_$RAND"
	BOND_RX_MAIN_IF="bond_rx_$RAND"

	# Setup TX
	if ! ip -n "${TXNS}" link add "${BOND_TX_MAIN_IF}" type bond mode balance-rr
	then
		echo "Failed to create bond TX interface. Is CONFIG_BONDING set?" >&2
		# only clean nsim ifaces and namespace. Nothing else has been
		# initialized
		cleanup_bond_nsim
		trap - EXIT
		exit "${ksft_skip}"
	fi

	# create_netdevsim() got the interface up, but it needs to be down
	# before being enslaved.
	ip -n "${TXNS}" \
		link set "${BOND_TX1_SLAVE_IF}" down
	ip -n "${TXNS}" \
		link set "${BOND_TX2_SLAVE_IF}" down
	ip -n "${TXNS}" \
		link set "${BOND_TX1_SLAVE_IF}" master "${BOND_TX_MAIN_IF}"
	ip -n "${TXNS}" \
		link set "${BOND_TX2_SLAVE_IF}" master "${BOND_TX_MAIN_IF}"
	ip -n "${TXNS}" \
		link set "${BOND_TX_MAIN_IF}" up

	# Setup RX
	ip -n "${RXNS}" \
		link add "${BOND_RX_MAIN_IF}" type bond mode balance-rr
	ip -n "${RXNS}" \
		link set "${BOND_RX1_SLAVE_IF}" down
	ip -n "${RXNS}" \
		link set "${BOND_RX2_SLAVE_IF}" down
	ip -n "${RXNS}" \
		link set "${BOND_RX1_SLAVE_IF}" master "${BOND_RX_MAIN_IF}"
	ip -n "${RXNS}" \
		link set "${BOND_RX2_SLAVE_IF}" master "${BOND_RX_MAIN_IF}"
	ip -n "${RXNS}" \
		link set "${BOND_RX_MAIN_IF}" up

	export DSTIF="${BOND_RX_MAIN_IF}"
	export SRCIF="${BOND_TX_MAIN_IF}"
}

# Create 4 netdevsim interfaces. Two of them will be bound to TX bonding iface
# and the other two will be bond to the RX interface (on the other namespace)
function create_ifaces_bond() {
	BOND_TX1_SLAVE_IF=$(create_netdevsim "${NSIM_BOND_TX_1}" "${TXNS}")
	BOND_TX2_SLAVE_IF=$(create_netdevsim "${NSIM_BOND_TX_2}" "${TXNS}")
	BOND_RX1_SLAVE_IF=$(create_netdevsim "${NSIM_BOND_RX_1}" "${RXNS}")
	BOND_RX2_SLAVE_IF=$(create_netdevsim "${NSIM_BOND_RX_2}" "${RXNS}")
}

# netdevsim link BOND_TX to BOND_RX interfaces
function link_ifaces_bond() {
	local BOND_TX1_SLAVE_IFIDX
	local BOND_TX2_SLAVE_IFIDX
	local BOND_RX1_SLAVE_IFIDX
	local BOND_RX2_SLAVE_IFIDX
	local TXNS_FD
	local RXNS_FD

	BOND_TX1_SLAVE_IFIDX=$(ip netns exec "${TXNS}" \
				cat /sys/class/net/"$BOND_TX1_SLAVE_IF"/ifindex)
	BOND_TX2_SLAVE_IFIDX=$(ip netns exec "${TXNS}" \
				cat /sys/class/net/"$BOND_TX2_SLAVE_IF"/ifindex)
	BOND_RX1_SLAVE_IFIDX=$(ip netns exec "${RXNS}" \

Annotation

Implementation Notes