]> git.proxmox.com Git - mirror_frr.git/blame - lib/ns.h
lib: Hide list macros in linklist.c
[mirror_frr.git] / lib / ns.h
CommitLineData
32bcb8b0
DS
1/*
2 * NS related header.
3 * Copyright (C) 2014 6WIND S.A.
4 *
5 * This file is part of GNU Zebra.
6 *
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.
11 *
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.
16 *
896014f4
DL
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
32bcb8b0
DS
20 */
21
22#ifndef _ZEBRA_NS_H
23#define _ZEBRA_NS_H
24
c7fdd84f 25#include "openbsd-tree.h"
32bcb8b0 26#include "linklist.h"
697d3ec7 27#include "vty.h"
32bcb8b0 28
5e244469
RW
29#ifdef __cplusplus
30extern "C" {
31#endif
32
d7c0a89a 33typedef uint32_t ns_id_t;
32bcb8b0 34
3eca551f 35/* the default NS ID */
3eca551f 36#define NS_UNKNOWN UINT32_MAX
32bcb8b0 37
1fbe3e58 38/* Default netns directory (Linux) */
13460c44 39#define NS_RUN_DIR "/var/run/netns"
32bcb8b0 40
ec31f30d
PG
41#ifdef HAVE_NETNS
42#define NS_DEFAULT_NAME "/proc/self/ns/net"
43#else /* !HAVE_NETNS */
c7975431 44#define NS_DEFAULT_NAME "default-netns"
ec31f30d
PG
45#endif /* HAVE_NETNS */
46
d62a17ae 47struct ns {
48 RB_ENTRY(ns) entry;
c7fdd84f 49
d62a17ae 50 /* Identifier, same as the vector index */
51 ns_id_t ns_id;
c7fdd84f 52
03aff2d8
PG
53 /* Identifier, mapped on the NSID value */
54 ns_id_t internal_ns_id;
55
20f4b2b0
PG
56 /* Identifier, value of NSID of default netns,
57 * relative value in that local netns
58 */
59 ns_id_t relative_default_ns;
60
d62a17ae 61 /* Name */
62 char *name;
c7fdd84f 63
d62a17ae 64 /* File descriptor */
65 int fd;
f30c50b9 66
d62a17ae 67 /* Master list of interfaces belonging to this NS */
68 struct list *iflist;
f30c50b9 69
b95c1883
PG
70 /* Back Pointer to VRF */
71 void *vrf_ctxt;
72
d62a17ae 73 /* User data */
74 void *info;
f30c50b9 75};
d62a17ae 76RB_HEAD(ns_head, ns);
77RB_PROTOTYPE(ns_head, ns, entry, ns_compare)
c7fdd84f 78
e26aedbe
PG
79/*
80 * API for managing NETNS. eg from zebra daemon
81 * one want to manage the list of NETNS, etc...
82 */
83
32bcb8b0
DS
84/*
85 * NS hooks
86 */
87
c7975431
IR
88#define NS_NEW_HOOK 0 /* a new netns is just created */
89#define NS_DELETE_HOOK 1 /* a netns is to be deleted */
90#define NS_ENABLE_HOOK 2 /* a netns is ready to use */
91#define NS_DISABLE_HOOK 3 /* a netns is to be unusable */
32bcb8b0
DS
92
93/*
94 * Add a specific hook ns module.
95 * @param1: hook type
96 * @param2: the callback function
97 * - param 1: the NS ID
98 * - param 2: the address of the user data pointer (the user data
99 * can be stored in or freed from there)
100 */
3347430b 101extern void ns_add_hook(int type, int (*)(struct ns *));
32bcb8b0 102
e26aedbe 103
32bcb8b0
DS
104/*
105 * NS initializer/destructor
106 */
e26aedbe 107
d62a17ae 108extern void ns_terminate(void);
32bcb8b0 109
e26aedbe
PG
110/* API to initialize NETNS managerment
111 * parameter is the default ns_id
112 */
03aff2d8 113extern void ns_init_management(ns_id_t ns_id, ns_id_t internal_ns_idx);
e26aedbe
PG
114
115
32bcb8b0
DS
116/*
117 * NS utilities
118 */
119
e26aedbe
PG
120/* Create a socket serving for the given NS
121 */
122int ns_socket(int domain, int type, int protocol, ns_id_t ns_id);
123
124/* return the path of the NETNS */
697d3ec7 125extern char *ns_netns_pathname(struct vty *vty, const char *name);
e26aedbe
PG
126
127/* Parse and execute a function on all the NETNS */
2961d060
PG
128#define NS_WALK_CONTINUE 0
129#define NS_WALK_STOP 1
130
131extern void ns_walk_func(int (*func)(struct ns *,
132 void *,
133 void **),
134 void *param_in,
135 void **param_out);
e26aedbe
PG
136
137/* API to get the NETNS name, from the ns pointer */
81c9005f 138extern const char *ns_get_name(struct ns *ns);
e26aedbe
PG
139
140/* only called from vrf ( when removing netns from vrf)
c7975431 141 * or at VRF termination
e26aedbe
PG
142 */
143extern void ns_delete(struct ns *ns);
144
145/* return > 0 if netns is available
146 * called by VRF to check netns backend is available for VRF
147 */
148extern int ns_have_netns(void);
149
150/* API to get context information of a NS */
151extern void *ns_info_lookup(ns_id_t ns_id);
152
03aff2d8
PG
153/* API to map internal ns id value with
154 * user friendly ns id external value
155 */
f0295a54 156extern ns_id_t ns_map_nsid_with_external(ns_id_t ns_id, bool map);
03aff2d8 157
e26aedbe
PG
158/*
159 * NS init routine
160 * should be called from backendx
161 */
162extern void ns_init(void);
163
1eb92f06 164#define NS_DEFAULT 0
e26aedbe
PG
165
166/* API that can be used to change from NS */
ce1be369
PG
167extern int ns_switchback_to_initial(void);
168extern int ns_switch_to_netns(const char *netns_name);
ce1be369 169
e26aedbe
PG
170/*
171 * NS handling routines.
172 * called by modules that use NS backend
173 */
174
175/* API to search for already present NETNS */
176extern struct ns *ns_lookup(ns_id_t ns_id);
177extern struct ns *ns_lookup_name(const char *name);
ec31f30d 178
e26aedbe
PG
179/* API to handle NS : creation, enable, disable
180 * for enable, a callback function is passed as parameter
181 * the callback belongs to the module that uses NS as backend
182 * upon enabling the NETNS, the upper layer is informed
183 */
184extern int ns_enable(struct ns *ns, void (*func)(ns_id_t, void *));
185extern struct ns *ns_get_created(struct ns *ns, char *name, ns_id_t ns_id);
b1cc23b2 186extern ns_id_t ns_id_get_absolute(ns_id_t ns_id_reference, ns_id_t link_nsid);
e26aedbe 187extern void ns_disable(struct ns *ns);
2d4e4d39 188extern struct ns *ns_get_default(void);
ec31f30d 189
5e244469
RW
190#ifdef __cplusplus
191}
192#endif
193
32bcb8b0 194#endif /*_ZEBRA_NS_H*/