xref: /kernel/linux/linux-5.10/tools/testing/selftests/net/in_netns.sh
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /kernel/linux/linux-5.10/tools/testing/selftests/net/
18c2ecf20Sopenharmony_ci#!/bin/sh
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci# Execute a subprocess in a network namespace
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciset -e
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_cireadonly NETNS="ns-$(mktemp -u XXXXXX)"
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_cisetup() {
118c2ecf20Sopenharmony_ci	ip netns add "${NETNS}"
128c2ecf20Sopenharmony_ci	ip -netns "${NETNS}" link set lo up
138c2ecf20Sopenharmony_ci}
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cicleanup() {
168c2ecf20Sopenharmony_ci	ip netns del "${NETNS}"
178c2ecf20Sopenharmony_ci}
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_citrap cleanup EXIT
208c2ecf20Sopenharmony_cisetup
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciip netns exec "${NETNS}" "$@"
238c2ecf20Sopenharmony_ciexit "$?"
24

Indexes created Thu Nov 07 10:32:03 CST 2024