]> git.proxmox.com Git - mirror_frr.git/blob - lib/vrf.h
Merge branch 'cmaster-next' into vtysh-grammar
[mirror_frr.git] / lib / vrf.h
1 /*
2 * VRF 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_VRF_H
24 #define _ZEBRA_VRF_H
25
26 #include "linklist.h"
27 #include "qobj.h"
28
29 /* The default NS ID */
30 #define NS_DEFAULT 0
31
32 /* The default VRF ID */
33 #define VRF_DEFAULT 0
34 #define VRF_UNKNOWN UINT16_MAX
35
36 /* Pending: May need to refine this. */
37 #ifndef IFLA_VRF_MAX
38 enum {
39 IFLA_VRF_UNSPEC,
40 IFLA_VRF_TABLE,
41 __IFLA_VRF_MAX
42 };
43
44 #define IFLA_VRF_MAX (__IFLA_VRF_MAX - 1)
45 #endif
46
47 #define VRF_NAMSIZ 36
48
49 #define VRF_DEFAULT_NAME "Default-IP-Routing-Table"
50
51 /*
52 * The command strings
53 */
54 #define VRF_CMD_HELP_STR "Specify the VRF\nThe VRF name\n"
55 #define VRF_ALL_CMD_HELP_STR "Specify the VRF\nAll VRFs\n"
56
57 /*
58 * VRF hooks
59 */
60
61 #define VRF_NEW_HOOK 0 /* a new VRF is just created */
62 #define VRF_DELETE_HOOK 1 /* a VRF is to be deleted */
63 #define VRF_ENABLE_HOOK 2 /* a VRF is ready to use */
64 #define VRF_DISABLE_HOOK 3 /* a VRF is to be unusable */
65
66 struct vrf
67 {
68 /* Identifier, same as the vector index */
69 vrf_id_t vrf_id;
70 /* Name */
71
72 char name[VRF_NAMSIZ + 1];
73
74 /* Zebra internal VRF status */
75 u_char status;
76 #define VRF_ACTIVE (1 << 0)
77
78 struct route_node *node;
79
80 /* Master list of interfaces belonging to this VRF */
81 struct list *iflist;
82
83 /* User data */
84 void *info;
85
86 QOBJ_FIELDS
87 };
88 DECLARE_QOBJ_TYPE(vrf)
89
90
91 extern struct list *vrf_list;
92
93 /*
94 * Add a specific hook to VRF module.
95 * @param1: hook type
96 * @param2: the callback function
97 * - param 1: the VRF ID
98 * - param 2: the address of the user data pointer (the user data
99 * can be stored in or freed from there)
100 */
101 extern void vrf_add_hook (int, int (*)(vrf_id_t, const char *, void **));
102
103 /*
104 * VRF iteration
105 */
106
107 typedef void * vrf_iter_t;
108 #define VRF_ITER_INVALID NULL /* invalid value of the iterator */
109
110 extern struct vrf *vrf_lookup (vrf_id_t);
111 extern struct vrf *vrf_lookup_by_name (const char *);
112 extern struct vrf *vrf_list_lookup_by_name (const char *);
113 extern struct vrf *vrf_get (vrf_id_t, const char *);
114 extern void vrf_delete (struct vrf *);
115 extern int vrf_enable (struct vrf *);
116 extern vrf_id_t vrf_name_to_id (const char *);
117
118 #define VRF_GET_ID(V,NAME) \
119 do { \
120 struct vrf *vrf; \
121 if (!(vrf = vrf_list_lookup_by_name(NAME))) \
122 { \
123 vty_out (vty, "%% VRF %s not found%s", NAME, VTY_NEWLINE);\
124 return CMD_WARNING; \
125 } \
126 if (vrf->vrf_id == VRF_UNKNOWN) \
127 { \
128 vty_out (vty, "%% VRF %s not active%s", NAME, VTY_NEWLINE);\
129 return CMD_WARNING; \
130 } \
131 (V) = vrf->vrf_id; \
132 } while (0)
133
134 /*
135 * VRF iteration utilities. Example for the usage:
136 *
137 * vrf_iter_t iter = vrf_first();
138 * for (; iter != VRF_ITER_INVALID; iter = vrf_next (iter))
139 *
140 * or
141 *
142 * vrf_iter_t iter = vrf_iterator (<a given VRF ID>);
143 * for (; iter != VRF_ITER_INVALID; iter = vrf_next (iter))
144 */
145
146 /* Return the iterator of the first VRF. */
147 extern vrf_iter_t vrf_first (void);
148 /* Return the next VRF iterator to the given iterator. */
149 extern vrf_iter_t vrf_next (vrf_iter_t);
150 /* Return the VRF iterator of the given VRF ID. If it does not exist,
151 * the iterator of the next existing VRF is returned. */
152 extern vrf_iter_t vrf_iterator (vrf_id_t);
153
154 /*
155 * VRF iterator to properties
156 */
157 extern vrf_id_t vrf_iter2id (vrf_iter_t);
158 extern struct vrf *vrf_iter2vrf (vrf_iter_t);
159 extern void *vrf_iter2info (vrf_iter_t);
160 extern struct list *vrf_iter2iflist (vrf_iter_t);
161
162 /*
163 * Utilities to obtain the user data
164 */
165
166 /* Get the data pointer of the specified VRF. If not found, create one. */
167 extern void *vrf_info_get (vrf_id_t);
168 /* Look up the data pointer of the specified VRF. */
169 extern void *vrf_info_lookup (vrf_id_t);
170
171 /*
172 * Utilities to obtain the interface list
173 */
174
175 /* Look up the interface list of the specified VRF. */
176 extern struct list *vrf_iflist (vrf_id_t);
177 /* Get the interface list of the specified VRF. Create one if not find. */
178 extern struct list *vrf_iflist_get (vrf_id_t);
179 /* Create the interface list for the specified VRF, if needed. */
180 extern void vrf_iflist_create (vrf_id_t vrf_id);
181 /* Free the interface list of the specified VRF. */
182 extern void vrf_iflist_terminate (vrf_id_t vrf_id);
183
184 /*
185 * VRF bit-map: maintaining flags, one bit per VRF ID
186 */
187
188 typedef void * vrf_bitmap_t;
189 #define VRF_BITMAP_NULL NULL
190
191 extern vrf_bitmap_t vrf_bitmap_init (void);
192 extern void vrf_bitmap_free (vrf_bitmap_t);
193 extern void vrf_bitmap_set (vrf_bitmap_t, vrf_id_t);
194 extern void vrf_bitmap_unset (vrf_bitmap_t, vrf_id_t);
195 extern int vrf_bitmap_check (vrf_bitmap_t, vrf_id_t);
196
197 /*
198 * VRF initializer/destructor
199 */
200 /* Please add hooks before calling vrf_init(). */
201 extern void vrf_init (void);
202 extern void vrf_terminate (void);
203
204 /*
205 * VRF utilities
206 */
207
208 /* Create a socket serving for the given VRF */
209 extern int vrf_socket (int, int, int, vrf_id_t);
210
211 /*
212 * VRF Debugging
213 */
214 extern void vrf_install_commands (void);
215 #endif /*_ZEBRA_VRF_H*/
216