summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/net/net_helper.sh
blob: 4fe0befa13fbc6aa52fed84080615362ff92724f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Helper functions

wait_local_port_listen()
{
	local listener_ns="${1}"
	local port="${2}"
	local protocol="${3}"
	local port_hex
	local i

	port_hex="$(printf "%04X" "${port}")"
	for i in $(seq 10); do
		if ip netns exec "${listener_ns}" cat /proc/net/"${protocol}"* | \
		   grep -q "${port_hex}"; then
			break
		fi
		sleep 0.1
	done
}