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