]> git.proxmox.com Git - mirror_frr.git/blob - lib/ns.h
Merge remote-tracking branch 'origin/cmaster' into cmaster-next
[mirror_frr.git] / lib / ns.h
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 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23 #ifndef _ZEBRA_NS_H
24 #define _ZEBRA_NS_H
25
26 #include "linklist.h"
27
28 typedef u_int16_t ns_id_t;
29
30 /* The default NS ID */
31 #define NS_DEFAULT 0
32
33 /*
34 * The command strings
35 */
36 #define NS_RUN_DIR "/var/run/netns"
37 #define NS_CMD_STR "logical-router <0-65535>"
38 #define NS_CMD_HELP_STR "Specify the Logical-Router\nThe Logical-Router ID\n"
39
40 #define NS_ALL_CMD_STR "logical-router all"
41 #define NS_ALL_CMD_HELP_STR "Specify the logical-router\nAll logical-router's\n"
42
43 /*
44 * NS hooks
45 */
46
47 #define NS_NEW_HOOK 0 /* a new logical-router is just created */
48 #define NS_DELETE_HOOK 1 /* a logical-router is to be deleted */
49 #define NS_ENABLE_HOOK 2 /* a logical-router is ready to use */
50 #define NS_DISABLE_HOOK 3 /* a logical-router is to be unusable */
51
52 /*
53 * Add a specific hook ns module.
54 * @param1: hook type
55 * @param2: the callback function
56 * - param 1: the NS ID
57 * - param 2: the address of the user data pointer (the user data
58 * can be stored in or freed from there)
59 */
60 extern void ns_add_hook (int, int (*)(ns_id_t, void **));
61
62 /*
63 * NS iteration
64 */
65
66 typedef void * ns_iter_t;
67 #define NS_ITER_INVALID NULL /* invalid value of the iterator */
68
69 /*
70 * NS iteration utilities. Example for the usage:
71 *
72 * ns_iter_t iter = ns_first();
73 * for (; iter != NS_ITER_INVALID; iter = ns_next (iter))
74 *
75 * or
76 *
77 * ns_iter_t iter = ns_iterator (<a given NS ID>);
78 * for (; iter != NS_ITER_INVALID; iter = ns_next (iter))
79 */
80
81 /* Return the iterator of the first NS. */
82 extern ns_iter_t ns_first (void);
83 /* Return the next NS iterator to the given iterator. */
84 extern ns_iter_t ns_next (ns_iter_t);
85 /* Return the NS iterator of the given NS ID. If it does not exist,
86 * the iterator of the next existing NS is returned. */
87 extern ns_iter_t ns_iterator (ns_id_t);
88
89 /*
90 * NS iterator to properties
91 */
92 extern ns_id_t ns_iter2id (ns_iter_t);
93 extern void *ns_iter2info (ns_iter_t);
94 extern struct list *ns_iter2iflist (ns_iter_t);
95
96 /*
97 * Utilities to obtain the user data
98 */
99
100 /* Get the data pointer of the specified NS. If not found, create one. */
101 extern void *ns_info_get (ns_id_t);
102 /* Look up the data pointer of the specified NS. */
103 extern void *ns_info_lookup (ns_id_t);
104
105 /*
106 * Utilities to obtain the interface list
107 */
108
109 /* Look up the interface list of the specified NS. */
110 extern struct list *ns_iflist (ns_id_t);
111 /* Get the interface list of the specified NS. Create one if not find. */
112 extern struct list *ns_iflist_get (ns_id_t);
113
114 /*
115 * NS bit-map: maintaining flags, one bit per NS ID
116 */
117
118 typedef void * ns_bitmap_t;
119 #define NS_BITMAP_NULL NULL
120
121 extern ns_bitmap_t ns_bitmap_init (void);
122 extern void ns_bitmap_free (ns_bitmap_t);
123 extern void ns_bitmap_set (ns_bitmap_t, ns_id_t);
124 extern void ns_bitmap_unset (ns_bitmap_t, ns_id_t);
125 extern int ns_bitmap_check (ns_bitmap_t, ns_id_t);
126
127 /*
128 * NS initializer/destructor
129 */
130 /* Please add hooks before calling ns_init(). */
131 extern void ns_init (void);
132 extern void ns_terminate (void);
133
134 /*
135 * NS utilities
136 */
137
138 /* Create a socket serving for the given NS */
139 extern int ns_socket (int, int, int, ns_id_t);
140
141 #endif /*_ZEBRA_NS_H*/
142