]>
git.proxmox.com Git - mirror_frr.git/blob - lib/netns_other.c
b6570d3b9e58627576d254f8b7f3941f6298634f
2 * NetNS backend for non Linux systems
3 * Copyright (C) 2018 6WIND S.A.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #if !defined(GNU_LINUX) && defined(OPEN_BSD)
29 DEFINE_MTYPE_STATIC(LIB
, NS
, "NetNS Context");
30 DEFINE_MTYPE_STATIC(LIB
, NS_NAME
, "NetNS Name");
33 static inline int ns_compare(const struct ns
*ns
, const struct ns
*ns2
);
35 RB_GENERATE(ns_head
, ns
, entry
, ns_compare
)
37 static struct ns_head ns_tree
= RB_INITIALIZER(&ns_tree
);
39 static inline int ns_compare(const struct ns
*a
, const struct ns
*b
)
41 return (a
->ns_id
- b
->ns_id
);
44 void ns_terminate(void)
48 /* API to initialize NETNS managerment
49 * parameter is the default ns_id
51 void ns_init_management(ns_id_t ns_id
)
60 /* Create a socket serving for the given NS
62 int ns_socket(int domain
, int type
, int protocol
, ns_id_t ns_id
)
67 /* return the path of the NETNS */
68 char *ns_netns_pathname(struct vty
*vty
, const char *name
)
73 /* Parse and execute a function on all the NETNS */
74 void ns_walk_func(int (*func
)(struct ns
*))
78 /* API to get the NETNS name, from the ns pointer */
79 const char *ns_get_name(struct ns
*ns
)
84 /* only called from vrf ( when removing netns from vrf)
85 * or at VRF termination
87 void ns_delete(struct ns
*ns
)
91 /* return > 0 if netns is available
92 * called by VRF to check netns backend is available for VRF
94 int ns_have_netns(void)
99 /* API to get context information of a NS */
100 void *ns_info_lookup(ns_id_t ns_id
)
107 * should be called from backendx
113 /* API that can be used to change from NS */
114 int ns_switchback_to_initial(void)
118 int ns_switch_to_netns(const char *netns_name
)
124 * NS handling routines.
125 * called by modules that use NS backend
128 /* API to search for already present NETNS */
129 struct ns
*ns_lookup(ns_id_t ns_id
)
134 struct ns
*ns_lookup_name(const char *name
)
139 /* API to handle NS : creation, enable, disable
140 * for enable, a callback function is passed as parameter
141 * the callback belongs to the module that uses NS as backend
142 * upon enabling the NETNS, the upper layer is informed
144 int ns_enable(struct ns
*ns
, int (*func
)(ns_id_t
, void *))
149 ns_id_t
ns_map_nsid_with_external(ns_id_t ns_id
, bool maporunmap
)
154 struct ns
*ns_get_created(struct ns
*ns
, char *name
, ns_id_t ns_id
)
159 void ns_disable(struct ns
*ns
)
163 #endif /* !GNU_LINUX */