FD.io VPP  v21.06
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 
25 
26 u8 *
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
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
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  {
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  */
lcp_main_t lcp_main
Definition: lcp.c:24
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#define LCP_NS_LEN
Definition: lcp.h:20
int lcp_set_default_ns(u8 *ns)
Get/Set the default namespace for LCP host taps.
Definition: lcp.c:48
unsigned char u8
Definition: types.h:56
u8 * lcp_get_default_ns(void)
Definition: lcp.c:27
int lcp_get_default_ns_fd(void)
Definition: lcp.c:37
description fragment has unexpected format
Definition: map.api:433
int default_ns_fd
Definition: lcp.h:26
u8 len
Definition: ip_types.api:103
#define clib_strncpy(d, s, n)
Definition: string.h:992
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:395
Definition: lcp.h:22
u8 default_namespace[LCP_NS_LEN]
Definition: lcp.h:25
#define clib_strnlen(s, m)
Definition: string.h:782