--- embedaddon/quagga/zebra/test_main.c 2013/07/21 23:54:41 1.1.1.2 +++ embedaddon/quagga/zebra/test_main.c 2016/11/02 10:09:10 1.1.1.3 @@ -29,6 +29,7 @@ #include "log.h" #include "privs.h" #include "sigevent.h" +#include "vrf.h" #include "zebra/rib.h" #include "zebra/zserv.h" @@ -103,9 +104,9 @@ usage (char *progname, int status) exit (status); } - -static unsigned int test_ifindex = 0; +static ifindex_t test_ifindex = 0; + /* testrib commands */ DEFUN (test_interface_state, test_interface_state_cmd, @@ -149,7 +150,7 @@ test_cmd_init (void) { install_element (INTERFACE_NODE, &test_interface_state_cmd); } - + /* SIGHUP handler. */ static void sighup (void) @@ -195,7 +196,72 @@ struct quagga_signal_t zebra_signals[] = .handler = &sigint, }, }; - + +/* 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; +} + +/* Callback upon enabling a VRF. */ +static int +zebra_vrf_enable (vrf_id_t vrf_id, void **info) +{ + struct zebra_vrf *zvrf = (struct zebra_vrf *) (*info); + + assert (zvrf); + + kernel_init (zvrf); + route_read (zvrf); + + return 0; +} + +/* Callback upon disabling a VRF. */ +static int +zebra_vrf_disable (vrf_id_t vrf_id, void **info) +{ + struct zebra_vrf *zvrf = (struct zebra_vrf *) (*info); + struct listnode *list_node; + struct interface *ifp; + + assert (zvrf); + + rib_close_table (zvrf->table[AFI_IP][SAFI_UNICAST]); + rib_close_table (zvrf->table[AFI_IP6][SAFI_UNICAST]); + + for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), list_node, ifp)) + { + int operative = if_is_operative (ifp); + UNSET_FLAG (ifp->flags, IFF_UP); + if (operative) + if_down (ifp); + } + + kernel_terminate (zvrf); + + return 0; +} + +/* Zebra VRF initialization. */ +static void +zebra_vrf_init (void) +{ + vrf_add_hook (VRF_NEW_HOOK, zebra_vrf_new); + vrf_add_hook (VRF_ENABLE_HOOK, zebra_vrf_enable); + vrf_add_hook (VRF_DISABLE_HOOK, zebra_vrf_disable); + vrf_init (); +} + /* Main startup routine. */ int main (int argc, char **argv) @@ -284,7 +350,6 @@ main (int argc, char **argv) cmd_init (1); vty_init (zebrad.master); memory_init (); - if_init(); zebra_debug_init (); zebra_if_init (); test_cmd_init (); @@ -294,12 +359,8 @@ main (int argc, char **argv) access_list_init (); /* Make kernel routing socket. */ - kernel_init (); - route_read (); + zebra_vrf_init (); zebra_vty_init(); - - /* Sort VTY commands. */ - sort_node (); /* Configuration file read*/ vty_read_config (config_file, config_default);