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:
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.
19 #include <sys/socket.h>
22 #include <plugins/linux-cp/lcp.h>
27 lcp_get_default_ns (void)
29 lcp_main_t *lcpm = &lcp_main;
31 if (!lcpm->default_namespace || lcpm->default_namespace[0] == 0)
34 return lcpm->default_namespace;
38 lcp_get_default_ns_fd (void)
40 lcp_main_t *lcpm = &lcp_main;
42 return lcpm->default_ns_fd;
46 * ns is expected to be or look like a NUL-terminated C string.
49 lcp_set_default_ns (u8 *ns)
51 lcp_main_t *lcpm = &lcp_main;
57 len = clib_strnlen (p, LCP_NS_LEN);
58 if (len >= LCP_NS_LEN)
63 lcpm->default_namespace = NULL;
64 if (lcpm->default_ns_fd > 0)
65 close (lcpm->default_ns_fd);
66 lcpm->default_ns_fd = 0;
70 vec_validate_init_c_string (lcpm->default_namespace, p,
71 clib_strnlen (p, LCP_NS_LEN));
72 s = format (0, "/var/run/netns/%s%c", (char *) lcpm->default_namespace, 0);
73 lcpm->default_ns_fd = open ((char *) s, O_RDONLY);
80 * fd.io coding-style-patch-verification: ON
83 * eval: (c-set-style "gnu")