]>
git.proxmox.com Git - mirror_frr.git/blob - lib/netns_other.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * NetNS backend for non Linux systems
4 * Copyright (C) 2018 6WIND S.A.
8 #if !defined(GNU_LINUX) && defined(OPEN_BSD)
16 DEFINE_MTYPE_STATIC(LIB
, NS
, "NetNS Context");
17 DEFINE_MTYPE_STATIC(LIB
, NS_NAME
, "NetNS Name");
20 static inline int ns_compare(const struct ns
*ns
, const struct ns
*ns2
);
22 RB_GENERATE(ns_head
, ns
, entry
, ns_compare
)
24 static struct ns_head ns_tree
= RB_INITIALIZER(&ns_tree
);
26 static inline int ns_compare(const struct ns
*a
, const struct ns
*b
)
28 return (a
->ns_id
- b
->ns_id
);
31 void ns_terminate(void)
35 /* API to initialize NETNS managerment
36 * parameter is the default ns_id
38 void ns_init_management(ns_id_t ns_id
)
47 /* Create a socket serving for the given NS
49 int ns_socket(int domain
, int type
, int protocol
, ns_id_t ns_id
)
54 /* return the path of the NETNS */
55 char *ns_netns_pathname(struct vty
*vty
, const char *name
)
60 /* Parse and execute a function on all the NETNS */
61 void ns_walk_func(int (*func
)(struct ns
*))
65 /* API to get the NETNS name, from the ns pointer */
66 const char *ns_get_name(struct ns
*ns
)
71 /* only called from vrf ( when removing netns from vrf)
72 * or at VRF termination
74 void ns_delete(struct ns
*ns
)
78 /* return > 0 if netns is available
79 * called by VRF to check netns backend is available for VRF
81 int ns_have_netns(void)
86 /* API to get context information of a NS */
87 void *ns_info_lookup(ns_id_t ns_id
)
94 * should be called from backendx
100 /* API that can be used to change from NS */
101 int ns_switchback_to_initial(void)
105 int ns_switch_to_netns(const char *netns_name
)
111 * NS handling routines.
112 * called by modules that use NS backend
115 /* API to search for already present NETNS */
116 struct ns
*ns_lookup(ns_id_t ns_id
)
121 struct ns
*ns_lookup_name(const char *name
)
126 /* API to handle NS : creation, enable, disable
127 * for enable, a callback function is passed as parameter
128 * the callback belongs to the module that uses NS as backend
129 * upon enabling the NETNS, the upper layer is informed
131 int ns_enable(struct ns
*ns
, int (*func
)(ns_id_t
, void *))
136 ns_id_t
ns_map_nsid_with_external(ns_id_t ns_id
, bool maporunmap
)
141 struct ns
*ns_get_created(struct ns
*ns
, char *name
, ns_id_t ns_id
)
146 void ns_disable(struct ns
*ns
)
150 #endif /* !GNU_LINUX */