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