FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
lcp.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 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
#include <sched.h>
17
#include <fcntl.h>
18
#include <ctype.h>
19
#include <sys/socket.h>
20
#include <net/if.h>
21
22
#include <
plugins/linux-cp/lcp.h
>
23
24
lcp_main_t
lcp_main
;
25
26
u8
*
27
lcp_get_default_ns
(
void
)
28
{
29
lcp_main_t
*lcpm = &
lcp_main
;
30
31
if
(lcpm->
default_namespace
[0] == 0)
32
return
0;
33
return
lcpm->
default_namespace
;
34
}
35
36
int
37
lcp_get_default_ns_fd
(
void
)
38
{
39
lcp_main_t
*lcpm = &
lcp_main
;
40
41
return
lcpm->
default_ns_fd
;
42
}
43
44
/*
45
* ns is expected to be or look like a NUL-terminated C string.
46
*/
47
int
48
lcp_set_default_ns
(
u8
*ns)
49
{
50
lcp_main_t
*lcpm = &
lcp_main
;
51
char
*p;
52
int
len
;
53
u8
*s;
54
55
p = (
char
*) ns;
56
len
=
clib_strnlen
(p,
LCP_NS_LEN
);
57
if
(
len
>=
LCP_NS_LEN
)
58
return
-1;
59
60
if
(!p || *p == 0)
61
{
62
clib_memset
(lcpm->
default_namespace
, 0,
63
sizeof (lcpm->
default_namespace
));
64
if
(lcpm->
default_ns_fd
> 0)
65
close (lcpm->
default_ns_fd
);
66
lcpm->
default_ns_fd
= 0;
67
return
0;
68
}
69
70
clib_strncpy
((
char
*) lcpm->
default_namespace
, p,
LCP_NS_LEN
- 1);
71
72
s =
format
(0,
"/var/run/netns/%s%c"
, (
char
*) lcpm->
default_namespace
, 0);
73
lcpm->
default_ns_fd
= open ((
char
*) s, O_RDONLY);
74
vec_free
(s);
75
76
return
0;
77
}
78
79
/*
80
* fd.io coding-style-patch-verification: ON
81
*
82
* Local Variables:
83
* eval: (c-set-style "gnu")
84
* End:
85
*/
clib_strncpy
#define clib_strncpy(d, s, n)
Definition:
string.h:992
lcp_get_default_ns_fd
int lcp_get_default_ns_fd(void)
Definition:
lcp.c:37
lcp_get_default_ns
u8 * lcp_get_default_ns(void)
Definition:
lcp.c:27
lcp_main_s
Definition:
lcp.h:22
lcp.h
len
u8 len
Definition:
ip_types.api:103
lcp_main_s::default_ns_fd
int default_ns_fd
Definition:
lcp.h:26
lcp_main_s::default_namespace
u8 default_namespace[LCP_NS_LEN]
Definition:
lcp.h:25
LCP_NS_LEN
#define LCP_NS_LEN
Definition:
lcp.h:20
clib_strnlen
#define clib_strnlen(s, m)
Definition:
string.h:782
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
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
lcp_main
lcp_main_t lcp_main
Definition:
lcp.c:24
u8
unsigned char u8
Definition:
types.h:56
lcp_set_default_ns
int lcp_set_default_ns(u8 *ns)
Get/Set the default namespace for LCP host taps.
Definition:
lcp.c:48
src
plugins
linux-cp
lcp.c
Generated on Sat Jan 8 2022 10:04:02 for FD.io VPP by
1.8.17