1 #!/bin/sh 1 #!/bin/sh 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 # 3 # 4 # Execute a subprocess in a network namespace 4 # Execute a subprocess in a network namespace 5 5 6 set -e 6 set -e 7 7 8 readonly NETNS="ns-$(mktemp -u XXXXXX)" 8 readonly NETNS="ns-$(mktemp -u XXXXXX)" 9 9 10 setup() { 10 setup() { 11 ip netns add "${NETNS}" 11 ip netns add "${NETNS}" 12 ip -netns "${NETNS}" link set lo up 12 ip -netns "${NETNS}" link set lo up 13 } 13 } 14 14 15 cleanup() { 15 cleanup() { 16 ip netns del "${NETNS}" 16 ip netns del "${NETNS}" 17 } 17 } 18 18 19 trap cleanup EXIT 19 trap cleanup EXIT 20 setup 20 setup 21 21 22 ip netns exec "${NETNS}" "$@" 22 ip netns exec "${NETNS}" "$@" 23 exit "$?" 23 exit "$?"
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.