From 41f44a23e86a65a5cad7e5e8cafd7e935f153232 Mon Sep 17 00:00:00 2001 From: Feng Lu Date: Fri, 22 May 2015 11:39:56 +0200 Subject: lib, zebra: move "struct vrf" to be a lib module Previously "struct vrf" is defined locally in zebra. Now it is moved to be a lib module. This is the first step to support multi-VRF in quagga. The implementation is splitted into small patches for the purpose of easy review. * lib: "struct vrf" with basic members is defined in vrf.c. The member "void *info" is for user data. Some basic functions are defined in vrf.c for adding/deleting/ looking up a VRF, scanning the VRF table and initializing the VRF module. The type "vrf_id_t" is defined specificly for VRF ID. * zebra: The previous "struct vrf" is re-defined as "struct zebra_vrf"; and previous "vrf" variables are renamed to "zvrf". The previous "struct vrf" related functions are removed from zbera_rib.c. New functions are defined to maintain the new "struct zebra_vrf". The names vrf_xxx are reserved for the functions in VRF module. So: - the previous vrf_table() are renamed to zebra_vrf_table(); - the previous vrf_static_table() are renamed to zebra_vrf_static_table(). The main logic is not changed. BTW: Add a statement to zebra_snmp.c telling that the SNMP is running only for the MIBs in the default VRF. Signed-off-by: Feng Lu Reviewed-by: Alain Ritoux Signed-off-by: Nicolas Dichtel Acked-by: Vincent JARDIN Signed-off-by: David Lamparter --- zebra/main.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'zebra/main.c') diff --git a/zebra/main.c b/zebra/main.c index d7f2a108..a690c9a1 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -32,6 +32,7 @@ #include "plist.h" #include "privs.h" #include "sigevent.h" +#include "vrf.h" #include "zebra/rib.h" #include "zebra/zserv.h" @@ -204,6 +205,29 @@ struct quagga_signal_t zebra_signals[] = }, }; +/* Callback upon creating a new VRF. */ +static int +zebra_vrf_new (vrf_id_t vrf_id, void **info) +{ + struct zebra_vrf *zvrf = *info; + + if (! zvrf) + { + zvrf = zebra_vrf_alloc (vrf_id); + *info = (void *)zvrf; + } + + return 0; +} + +/* Zebra VRF initialization. */ +static void +zebra_vrf_init (void) +{ + vrf_add_hook (VRF_NEW_HOOK, zebra_vrf_new); + vrf_init (); +} + /* Main startup routine. */ int main (int argc, char **argv) @@ -338,7 +362,8 @@ main (int argc, char **argv) /* For debug purpose. */ /* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */ - /* Make kernel routing socket. */ + /* Initialize VRF module, and make kernel routing socket. */ + zebra_vrf_init (); kernel_init (); interface_list (); route_read (); -- cgit v1.2.3