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