xref: /linux/tools/testing/selftests/net/in_netns.sh (revision b8265621f4888af9494e1d685620871ec81bc33d)
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