FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
netns.c
Go to the documentation of this file.
1
/*
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:
6
*
7
* http://www.apache.org/licenses/LICENSE-2.0
8
*
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.
14
*/
15
16
#define _GNU_SOURCE
17
#include <fcntl.h>
18
#include <sched.h>
19
20
#include <
vppinfra/format.h
>
21
22
__clib_export
int
23
clib_netns_open
(
u8
*netns_u8)
24
{
25
char
*netns = (
char
*) netns_u8;
26
u8
*s = 0;
27
int
fd;
28
29
if
((NULL) == netns)
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);
35
else
36
s =
format
(0,
"/var/run/netns/%s%c"
, netns, 0);
37
38
fd = open ((
char
*) s, O_RDONLY);
39
vec_free
(s);
40
return
fd;
41
}
42
43
__clib_export
int
44
clib_setns
(
int
nfd)
45
{
46
return
setns (nfd, CLONE_NEWNET);
47
}
48
49
/*
50
* fd.io coding-style-patch-verification: ON
51
*
52
* Local Variables:
53
* eval: (c-set-style "gnu")
54
* End:
55
*/
clib_netns_open
__clib_export int clib_netns_open(u8 *netns_u8)
Definition:
netns.c:23
clib_setns
__clib_export int clib_setns(int nfd)
Definition:
netns.c:44
format.h
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition:
vec.h:395
format
description fragment has unexpected format
Definition:
map.api:433
u8
unsigned char u8
Definition:
types.h:56
src
vppinfra
linux
netns.c
Generated on Sat Jan 8 2022 10:37:14 for FD.io VPP by
1.8.17