3 * Copyright (C) 2014 6WIND S.A.
5 * This file is part of GNU Zebra.
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.
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.
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.
26 #include "openbsd-tree.h"
30 /* The default NS ID */
33 /* The default VRF ID */
35 #define VRF_UNKNOWN UINT16_MAX
37 /* Pending: May need to refine this. */
45 #define IFLA_VRF_MAX (__IFLA_VRF_MAX - 1)
50 #define VRF_DEFAULT_NAME "Default-IP-Routing-Table"
55 #define VRF_CMD_HELP_STR "Specify the VRF\nThe VRF name\n"
56 #define VRF_ALL_CMD_HELP_STR "Specify the VRF\nAll VRFs\n"
62 #define VRF_NEW_HOOK 0 /* a new VRF is just created */
63 #define VRF_DELETE_HOOK 1 /* a VRF is to be deleted */
64 #define VRF_ENABLE_HOOK 2 /* a VRF is ready to use */
65 #define VRF_DISABLE_HOOK 3 /* a VRF is to be unusable */
69 RB_ENTRY(vrf
) id_entry
, name_entry
;
71 /* Identifier, same as the vector index */
75 char name
[VRF_NAMSIZ
+ 1];
77 /* Zebra internal VRF status */
79 #define VRF_ACTIVE (1 << 0)
81 /* Master list of interfaces belonging to this VRF */
89 RB_HEAD (vrf_id_head
, vrf
);
90 RB_PROTOTYPE (vrf_id_head
, vrf
, id_entry
, vrf_id_compare
)
91 RB_HEAD (vrf_name_head
, vrf
);
92 RB_PROTOTYPE (vrf_name_head
, vrf
, name_entry
, vrf_name_compare
)
93 DECLARE_QOBJ_TYPE(vrf
)
96 extern struct vrf_id_head vrfs_by_id
;
97 extern struct vrf_name_head vrfs_by_name
;
100 * Add a specific hook to VRF module.
102 * @param2: the callback function
103 * - param 1: the VRF ID
104 * - param 2: the address of the user data pointer (the user data
105 * can be stored in or freed from there)
107 extern void vrf_add_hook (int, int (*)(struct vrf
*));
109 extern struct vrf
*vrf_lookup_by_id (vrf_id_t
);
110 extern struct vrf
*vrf_lookup_by_name (const char *);
111 extern struct vrf
*vrf_get (vrf_id_t
, const char *);
112 extern void vrf_delete (struct vrf
*);
113 extern int vrf_enable (struct vrf
*);
114 extern vrf_id_t
vrf_name_to_id (const char *);
116 #define VRF_GET_ID(V,NAME) \
119 if (!(vrf = vrf_lookup_by_name(NAME))) \
121 vty_out (vty, "%% VRF %s not found%s", NAME, VTY_NEWLINE);\
122 return CMD_WARNING; \
124 if (vrf->vrf_id == VRF_UNKNOWN) \
126 vty_out (vty, "%% VRF %s not active%s", NAME, VTY_NEWLINE);\
127 return CMD_WARNING; \
133 * Utilities to obtain the user data
136 /* Get the data pointer of the specified VRF. If not found, create one. */
137 extern void *vrf_info_get (vrf_id_t
);
138 /* Look up the data pointer of the specified VRF. */
139 extern void *vrf_info_lookup (vrf_id_t
);
142 * Utilities to obtain the interface list
145 /* Look up the interface list of the specified VRF. */
146 extern struct list
*vrf_iflist (vrf_id_t
);
147 /* Get the interface list of the specified VRF. Create one if not find. */
148 extern struct list
*vrf_iflist_get (vrf_id_t
);
149 /* Create the interface list for the specified VRF, if needed. */
150 extern void vrf_iflist_create (vrf_id_t vrf_id
);
151 /* Free the interface list of the specified VRF. */
152 extern void vrf_iflist_terminate (vrf_id_t vrf_id
);
155 * VRF bit-map: maintaining flags, one bit per VRF ID
158 typedef void * vrf_bitmap_t
;
159 #define VRF_BITMAP_NULL NULL
161 extern vrf_bitmap_t
vrf_bitmap_init (void);
162 extern void vrf_bitmap_free (vrf_bitmap_t
);
163 extern void vrf_bitmap_set (vrf_bitmap_t
, vrf_id_t
);
164 extern void vrf_bitmap_unset (vrf_bitmap_t
, vrf_id_t
);
165 extern int vrf_bitmap_check (vrf_bitmap_t
, vrf_id_t
);
168 * VRF initializer/destructor
170 /* Please add hooks before calling vrf_init(). */
171 extern void vrf_init (void);
172 extern void vrf_terminate (void);
178 /* Create a socket serving for the given VRF */
179 extern int vrf_socket (int, int, int, vrf_id_t
);
184 extern void vrf_install_commands (void);
185 #endif /*_ZEBRA_VRF_H*/