]>
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 | ||
1a1a7065 | 26 | #include "openbsd-tree.h" |
8736158a | 27 | #include "linklist.h" |
e80e7cce | 28 | #include "qobj.h" |
8736158a | 29 | |
216b18ef DS |
30 | /* The default NS ID */ |
31 | #define NS_DEFAULT 0 | |
32 | ||
b72ede27 FL |
33 | /* The default VRF ID */ |
34 | #define VRF_DEFAULT 0 | |
58255d34 | 35 | #define VRF_UNKNOWN UINT16_MAX |
b72ede27 | 36 | |
216b18ef DS |
37 | /* Pending: May need to refine this. */ |
38 | #ifndef IFLA_VRF_MAX | |
39 | enum { | |
40 | IFLA_VRF_UNSPEC, | |
41 | IFLA_VRF_TABLE, | |
42 | __IFLA_VRF_MAX | |
43 | }; | |
44 | ||
45 | #define IFLA_VRF_MAX (__IFLA_VRF_MAX - 1) | |
46 | #endif | |
47 | ||
48 | #define VRF_NAMSIZ 36 | |
49 | ||
50 | #define VRF_DEFAULT_NAME "Default-IP-Routing-Table" | |
51 | ||
8736158a FL |
52 | /* |
53 | * The command strings | |
54 | */ | |
55 | ||
216b18ef DS |
56 | #define VRF_CMD_STR "vrf NAME" |
57 | #define VRF_CMD_HELP_STR "Specify the VRF\nThe VRF name\n" | |
8736158a FL |
58 | |
59 | #define VRF_ALL_CMD_STR "vrf all" | |
60 | #define VRF_ALL_CMD_HELP_STR "Specify the VRF\nAll VRFs\n" | |
61 | ||
b72ede27 FL |
62 | /* |
63 | * VRF hooks | |
64 | */ | |
65 | ||
66 | #define VRF_NEW_HOOK 0 /* a new VRF is just created */ | |
67 | #define VRF_DELETE_HOOK 1 /* a VRF is to be deleted */ | |
e5bf3e1e FL |
68 | #define VRF_ENABLE_HOOK 2 /* a VRF is ready to use */ |
69 | #define VRF_DISABLE_HOOK 3 /* a VRF is to be unusable */ | |
b72ede27 | 70 | |
216b18ef DS |
71 | struct vrf |
72 | { | |
806f8760 | 73 | RB_ENTRY(vrf) id_entry, name_entry; |
1a1a7065 | 74 | |
216b18ef DS |
75 | /* Identifier, same as the vector index */ |
76 | vrf_id_t vrf_id; | |
216b18ef | 77 | |
1a1a7065 | 78 | /* Name */ |
216b18ef DS |
79 | char name[VRF_NAMSIZ + 1]; |
80 | ||
81 | /* Zebra internal VRF status */ | |
82 | u_char status; | |
79694123 | 83 | #define VRF_ACTIVE (1 << 0) |
216b18ef | 84 | |
216b18ef DS |
85 | /* Master list of interfaces belonging to this VRF */ |
86 | struct list *iflist; | |
87 | ||
88 | /* User data */ | |
89 | void *info; | |
e80e7cce DL |
90 | |
91 | QOBJ_FIELDS | |
216b18ef | 92 | }; |
1a1a7065 RW |
93 | RB_HEAD (vrf_id_head, vrf); |
94 | RB_PROTOTYPE (vrf_id_head, vrf, id_entry, vrf_id_compare) | |
806f8760 RW |
95 | RB_HEAD (vrf_name_head, vrf); |
96 | RB_PROTOTYPE (vrf_name_head, vrf, name_entry, vrf_name_compare) | |
e80e7cce | 97 | DECLARE_QOBJ_TYPE(vrf) |
216b18ef DS |
98 | |
99 | ||
1a1a7065 | 100 | extern struct vrf_id_head vrfs_by_id; |
806f8760 | 101 | extern struct vrf_name_head vrfs_by_name; |
216b18ef | 102 | |
b72ede27 FL |
103 | /* |
104 | * Add a specific hook to VRF module. | |
105 | * @param1: hook type | |
106 | * @param2: the callback function | |
107 | * - param 1: the VRF ID | |
108 | * - param 2: the address of the user data pointer (the user data | |
109 | * can be stored in or freed from there) | |
110 | */ | |
661512bf | 111 | extern void vrf_add_hook (int, int (*)(struct vrf *)); |
b72ede27 | 112 | |
5f3d1bdf | 113 | extern struct vrf *vrf_lookup_by_id (vrf_id_t); |
216b18ef | 114 | extern struct vrf *vrf_lookup_by_name (const char *); |
216b18ef | 115 | extern struct vrf *vrf_get (vrf_id_t, const char *); |
216b18ef DS |
116 | extern void vrf_delete (struct vrf *); |
117 | extern int vrf_enable (struct vrf *); | |
118 | extern vrf_id_t vrf_name_to_id (const char *); | |
119 | ||
120 | #define VRF_GET_ID(V,NAME) \ | |
121 | do { \ | |
122 | struct vrf *vrf; \ | |
05e8e11e | 123 | if (!(vrf = vrf_lookup_by_name(NAME))) \ |
216b18ef DS |
124 | { \ |
125 | vty_out (vty, "%% VRF %s not found%s", NAME, VTY_NEWLINE);\ | |
126 | return CMD_WARNING; \ | |
127 | } \ | |
6f16f5a0 | 128 | if (vrf->vrf_id == VRF_UNKNOWN) \ |
216b18ef DS |
129 | { \ |
130 | vty_out (vty, "%% VRF %s not active%s", NAME, VTY_NEWLINE);\ | |
131 | return CMD_WARNING; \ | |
132 | } \ | |
133 | (V) = vrf->vrf_id; \ | |
134 | } while (0) | |
135 | ||
b72ede27 FL |
136 | /* |
137 | * Utilities to obtain the user data | |
138 | */ | |
139 | ||
140 | /* Get the data pointer of the specified VRF. If not found, create one. */ | |
141 | extern void *vrf_info_get (vrf_id_t); | |
142 | /* Look up the data pointer of the specified VRF. */ | |
143 | extern void *vrf_info_lookup (vrf_id_t); | |
144 | ||
8736158a FL |
145 | /* |
146 | * Utilities to obtain the interface list | |
147 | */ | |
148 | ||
149 | /* Look up the interface list of the specified VRF. */ | |
150 | extern struct list *vrf_iflist (vrf_id_t); | |
151 | /* Get the interface list of the specified VRF. Create one if not find. */ | |
152 | extern struct list *vrf_iflist_get (vrf_id_t); | |
b33adb7c | 153 | /* Create the interface list for the specified VRF, if needed. */ |
154 | extern void vrf_iflist_create (vrf_id_t vrf_id); | |
009b18fc | 155 | /* Free the interface list of the specified VRF. */ |
156 | extern void vrf_iflist_terminate (vrf_id_t vrf_id); | |
8736158a | 157 | |
7076bb2f FL |
158 | /* |
159 | * VRF bit-map: maintaining flags, one bit per VRF ID | |
160 | */ | |
161 | ||
162 | typedef void * vrf_bitmap_t; | |
163 | #define VRF_BITMAP_NULL NULL | |
164 | ||
165 | extern vrf_bitmap_t vrf_bitmap_init (void); | |
166 | extern void vrf_bitmap_free (vrf_bitmap_t); | |
167 | extern void vrf_bitmap_set (vrf_bitmap_t, vrf_id_t); | |
168 | extern void vrf_bitmap_unset (vrf_bitmap_t, vrf_id_t); | |
169 | extern int vrf_bitmap_check (vrf_bitmap_t, vrf_id_t); | |
170 | ||
b72ede27 FL |
171 | /* |
172 | * VRF initializer/destructor | |
173 | */ | |
174 | /* Please add hooks before calling vrf_init(). */ | |
175 | extern void vrf_init (void); | |
176 | extern void vrf_terminate (void); | |
177 | ||
e5bf3e1e FL |
178 | /* |
179 | * VRF utilities | |
180 | */ | |
181 | ||
182 | /* Create a socket serving for the given VRF */ | |
183 | extern int vrf_socket (int, int, int, vrf_id_t); | |
184 | ||
19dc275e DS |
185 | /* |
186 | * VRF Debugging | |
187 | */ | |
188 | extern void vrf_install_commands (void); | |
b72ede27 FL |
189 | #endif /*_ZEBRA_VRF_H*/ |
190 |