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