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