1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# Run tests when all ephemeral ports are exhausted.
5#
6# Author: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
7
8set +x
9set -e
10
11readonly NETNS="ns-$(mktemp -u XXXXXX)"
12
13setup() {
14	ip netns add "${NETNS}"
15	ip -netns "${NETNS}" link set lo up
16	ip netns exec "${NETNS}" \
17		sysctl -w net.ipv4.ip_local_port_range="32768 32768" \
18		> /dev/null 2>&1
19	ip netns exec "${NETNS}" \
20		sysctl -w net.ipv4.ip_autobind_reuse=1 > /dev/null 2>&1
21}
22
23cleanup() {
24	ip netns del "${NETNS}"
25}
26
27trap cleanup EXIT
28setup
29
30do_test() {
31	ip netns exec "${NETNS}" ./reuseaddr_ports_exhausted
32}
33
34do_test
35echo "tests done"
36