xref: /linux/tools/testing/selftests/net/in_netns.sh (revision 24168c5e6dfbdd5b414f048f47f75d64533296ca)
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3#
4# Execute a subprocess in a network namespace
5
6set -e
7
8readonly NETNS="ns-$(mktemp -u XXXXXX)"
9
10setup() {
11	ip netns add "${NETNS}"
12	ip -netns "${NETNS}" link set lo up
13}
14
15cleanup() {
16	ip netns del "${NETNS}"
17}
18
19trap cleanup EXIT
20setup
21
22ip netns exec "${NETNS}" "$@"
23exit "$?"
24