]>
git.proxmox.com Git - mirror_frr.git/blob - lib/ns.h
3 * Copyright (C) 2014 6WIND S.A.
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2, or (at your
10 * option) any later version.
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "openbsd-tree.h"
29 typedef uint32_t ns_id_t
;
31 /* the default NS ID */
32 #define NS_UNKNOWN UINT32_MAX
34 /* Default netns directory (Linux) */
35 #define NS_RUN_DIR "/var/run/netns"
38 #define NS_DEFAULT_NAME "/proc/self/ns/net"
39 #else /* !HAVE_NETNS */
40 #define NS_DEFAULT_NAME "Default-logical-router"
41 #endif /* HAVE_NETNS */
46 /* Identifier, same as the vector index */
55 /* Master list of interfaces belonging to this NS */
58 /* Back Pointer to VRF */
65 RB_PROTOTYPE(ns_head
, ns
, entry
, ns_compare
)
67 extern struct ns_head ns_tree
;
70 * API for managing NETNS. eg from zebra daemon
71 * one want to manage the list of NETNS, etc...
78 #define NS_NEW_HOOK 0 /* a new logical-router is just created */
79 #define NS_DELETE_HOOK 1 /* a logical-router is to be deleted */
80 #define NS_ENABLE_HOOK 2 /* a logical-router is ready to use */
81 #define NS_DISABLE_HOOK 3 /* a logical-router is to be unusable */
84 * Add a specific hook ns module.
86 * @param2: the callback function
87 * - param 1: the NS ID
88 * - param 2: the address of the user data pointer (the user data
89 * can be stored in or freed from there)
91 extern void ns_add_hook(int type
, int (*)(struct ns
*));
95 * NS initializer/destructor
98 extern void ns_terminate(void);
100 /* API to initialize NETNS managerment
101 * parameter is the default ns_id
103 extern void ns_init_management(ns_id_t ns_id
);
110 /* Create a socket serving for the given NS
112 int ns_socket(int domain
, int type
, int protocol
, ns_id_t ns_id
);
114 /* return the path of the NETNS */
115 extern char *ns_netns_pathname(struct vty
*vty
, const char *name
);
117 /* Parse and execute a function on all the NETNS */
118 extern void ns_walk_func(int (*func
)(struct ns
*));
120 /* API to get the NETNS name, from the ns pointer */
121 extern const char *ns_get_name(struct ns
*ns
);
123 /* only called from vrf ( when removing netns from vrf)
124 * or at VRF or logical router termination
126 extern void ns_delete(struct ns
*ns
);
128 /* return > 0 if netns is available
129 * called by VRF to check netns backend is available for VRF
131 extern int ns_have_netns(void);
133 /* API to get context information of a NS */
134 extern void *ns_info_lookup(ns_id_t ns_id
);
138 * should be called from backendx
140 extern void ns_init(void);
142 /* API to retrieve default NS */
143 extern ns_id_t
ns_get_default_id(void);
145 #define NS_DEFAULT ns_get_default_id()
147 /* API that can be used to change from NS */
148 extern int ns_switchback_to_initial(void);
149 extern int ns_switch_to_netns(const char *netns_name
);
152 * NS handling routines.
153 * called by modules that use NS backend
156 /* API to search for already present NETNS */
157 extern struct ns
*ns_lookup(ns_id_t ns_id
);
158 extern struct ns
*ns_lookup_name(const char *name
);
160 /* API to handle NS : creation, enable, disable
161 * for enable, a callback function is passed as parameter
162 * the callback belongs to the module that uses NS as backend
163 * upon enabling the NETNS, the upper layer is informed
165 extern int ns_enable(struct ns
*ns
, void (*func
)(ns_id_t
, void *));
166 extern struct ns
*ns_get_created(struct ns
*ns
, char *name
, ns_id_t ns_id
);
167 extern void ns_disable(struct ns
*ns
);
169 #endif /*_ZEBRA_NS_H*/