2 * Copyright (c) 2021 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
20 #include <vppinfra/format.h>
23 clib_netns_open (u8 *netns_u8)
25 char *netns = (char *) netns_u8;
30 s = format (0, "/proc/self/ns/net");
31 else if (strncmp (netns, "pid:", 4) == 0)
32 s = format (0, "/proc/%u/ns/net%c", atoi (netns + 4), 0);
33 else if (netns[0] == '/')
34 s = format (0, "%s%c", netns, 0);
36 s = format (0, "/var/run/netns/%s%c", netns, 0);
38 fd = open ((char *) s, O_RDONLY);
46 return setns (nfd, CLONE_NEWNET);
50 * fd.io coding-style-patch-verification: ON
53 * eval: (c-set-style "gnu")