From 3968dbf8ef4966fb3f9d38640ea9c5a9f13419cf Mon Sep 17 00:00:00 2001 From: Feng Lu Date: Fri, 22 May 2015 11:39:57 +0200 Subject: lib, zebra: add "vrf_id" into the "struct interface" Later, an interface will belong to a specific VRF. Now we add a property "vrf_id" to the "struct interface", and keep it as the default value 0. This property is shown when displaying interfaces information. It is also added in some logs. This is just the preparation to move the interace list into the "struct vrf". The main logic is not changed. Signed-off-by: Feng Lu Reviewed-by: Alain Ritoux Signed-off-by: Nicolas Dichtel Acked-by: Vincent JARDIN Signed-off-by: David Lamparter Conflicts: lib/if.c zebra/interface.c --- zebra/interface.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'zebra/interface.c') diff --git a/zebra/interface.c b/zebra/interface.c index 9d4a2f89d2..248f77d8f5 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -388,21 +388,23 @@ if_add_update (struct interface *ifp) if (if_data && if_data->shutdown == IF_ZEBRA_SHUTDOWN_ON) { if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug ("interface %s index %d is shutdown. Won't wake it up.", - ifp->name, ifp->ifindex); + zlog_debug ("interface %s vrf %u index %d is shutdown. " + "Won't wake it up.", + ifp->name, ifp->vrf_id, ifp->ifindex); return; } if_addr_wakeup (ifp); if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug ("interface %s index %d becomes active.", - ifp->name, ifp->ifindex); + zlog_debug ("interface %s vrf %u index %d becomes active.", + ifp->name, ifp->vrf_id, ifp->ifindex); } else { if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug ("interface %s index %d is added.", ifp->name, ifp->ifindex); + zlog_debug ("interface %s vrf %u index %d is added.", + ifp->name, ifp->vrf_id, ifp->ifindex); } } @@ -419,8 +421,8 @@ if_delete_update (struct interface *ifp) if (if_is_up(ifp)) { - zlog_err ("interface %s index %d is still up while being deleted.", - ifp->name, ifp->ifindex); + zlog_err ("interface %s vrf %u index %d is still up while being deleted.", + ifp->name, ifp->vrf_id, ifp->ifindex); return; } @@ -428,8 +430,8 @@ if_delete_update (struct interface *ifp) UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE); if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug ("interface %s index %d is now inactive.", - ifp->name, ifp->ifindex); + zlog_debug ("interface %s vrf %u index %d is now inactive.", + ifp->name, ifp->vrf_id, ifp->ifindex); /* Delete connected routes from the kernel. */ if (ifp->connected) @@ -846,6 +848,8 @@ if_dump_vty (struct vty *vty, struct interface *ifp) zebra_ptm_show_status(vty, ifp); + vty_out (vty, " vrf: %u%s", ifp->vrf_id, VTY_NEWLINE); + if (ifp->desc) vty_out (vty, " Description: %s%s", ifp->desc, VTY_NEWLINE); -- cgit v1.2.3 From 6a69b354a6656f138a5f11e4542dc84f748f2bea Mon Sep 17 00:00:00 2001 From: Feng Lu Date: Fri, 22 May 2015 11:39:58 +0200 Subject: *: call if_init()/if_terminate() from vrf_init()/vrf_terminate() Later, an interface will belong to a specific VRF, and the interface initialization will be a part of the VRF initialization. So now call if_init() from vrf_init(), and if_terminate() from vrf_terminate(). Daemons have the according changes: - if if_init() was called or "iflist" was initialized, now call vrf_init() instead; - if if_terminate() was called or "iflist" was destroyed, now call vrf_terminate() instead. Signed-off-by: Feng Lu Reviewed-by: Alain Ritoux Signed-off-by: Nicolas Dichtel Acked-by: Vincent JARDIN Signed-off-by: David Lamparter Conflicts: bgpd/bgp_main.c pimd/pim_iface.c pimd/pim_iface.h pimd/pim_main.c pimd/pimd.c --- bgpd/bgp_main.c | 8 ++++---- bgpd/bgp_zebra.c | 3 --- isisd/isis_circuit.c | 1 - isisd/isis_main.c | 2 ++ lib/vrf.c | 5 +++++ ospf6d/ospf6_main.c | 5 +++-- ospfd/ospf_interface.c | 1 - ospfd/ospf_main.c | 2 ++ ripd/rip_interface.c | 1 - ripd/rip_main.c | 2 ++ ripngd/ripng_interface.c | 2 +- ripngd/ripng_main.c | 2 ++ zebra/interface.c | 1 - zebra/test_main.c | 1 - 14 files changed, 21 insertions(+), 15 deletions(-) (limited to 'zebra/interface.c') diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index 49712fcf99..bf154db046 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -37,6 +37,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "plist.h" #include "stream.h" #include "queue.h" +#include "vrf.h" #include "bgpd/bgpd.h" #include "bgpd/bgp_attr.h" @@ -238,17 +239,14 @@ bgp_exit (int status) /* reverse bgp_zebra_init/if_init */ if (retain_mode) if_add_hook (IF_DELETE_HOOK, NULL); - for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { struct listnode *c_node, *c_nnode; struct connected *c; for (ALL_LIST_ELEMENTS (ifp->connected, c_node, c_nnode, c)) bgp_connected_delete (c); - - if_delete (ifp); } - list_free (iflist); /* reverse bgp_attr_init */ bgp_attr_finish (); @@ -280,6 +278,7 @@ bgp_exit (int status) /* reverse community_list_init */ community_list_terminate (bgp_clist); + vrf_terminate (); cmd_terminate (); vty_terminate (); if (zclient) @@ -412,6 +411,7 @@ main (int argc, char **argv) cmd_init (1); vty_init (bm->master); memory_init (); + vrf_init (); /* BGP related initialization. */ bgp_init (); diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 052c2efacb..501af234a2 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1738,9 +1738,6 @@ bgp_zebra_init (struct thread_master *master) zclient->nexthop_update = bgp_read_nexthop_update; zclient->import_check_update = bgp_read_import_check_update; - /* Interface related init. */ - if_init (); - bgp_nexthop_buf = stream_new(BGP_NEXTHOP_BUF_SIZE); bgp_ifindices_buf = stream_new(BGP_IFINDICES_BUF_SIZE); } diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 4f7e2ce9ce..470a86e39d 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -2739,7 +2739,6 @@ void isis_circuit_init () { /* Initialize Zebra interface data structure */ - if_init (); if_add_hook (IF_NEW_HOOK, isis_if_new_hook); if_add_hook (IF_DELETE_HOOK, isis_if_delete_hook); diff --git a/isisd/isis_main.c b/isisd/isis_main.c index 75463b33bb..a19399c5a2 100644 --- a/isisd/isis_main.c +++ b/isisd/isis_main.c @@ -35,6 +35,7 @@ #include "sigevent.h" #include "filter.h" #include "zclient.h" +#include "vrf.h" #include "isisd/dict.h" #include "include-netbsd/iso.h" @@ -335,6 +336,7 @@ main (int argc, char **argv, char **envp) vty_init (master); memory_init (); access_list_init(); + vrf_init (); isis_init (); isis_circuit_init (); isis_spf_cmds_init (); diff --git a/lib/vrf.c b/lib/vrf.c index 3ccbb99617..51f9e3795b 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -22,6 +22,7 @@ #include +#include "if.h" #include "vrf.h" #include "prefix.h" #include "table.h" @@ -249,6 +250,8 @@ vrf_init (void) /* Set the default VRF name. */ default_vrf->name = XSTRDUP (MTYPE_VRF_NAME, "Default-IP-Routing-Table"); + + if_init (); } /* Terminate VRF module. */ @@ -264,5 +267,7 @@ vrf_terminate (void) route_table_finish (vrf_table); vrf_table = NULL; + + if_terminate (); } diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index 75e409357c..af48d1fe4c 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -36,6 +36,7 @@ #include "privs.h" #include "sigevent.h" #include "zclient.h" +#include "vrf.h" #include "ospf6d.h" #include "ospf6_top.h" @@ -151,7 +152,7 @@ ospf6_exit (int status) ospf6_asbr_terminate (); ospf6_lsa_terminate (); - if_terminate (); + vrf_terminate (); vty_terminate (); cmd_terminate (); @@ -322,7 +323,7 @@ main (int argc, char *argv[], char *envp[]) cmd_init (1); vty_init (master); memory_init (); - if_init (); + vrf_init (); access_list_init (); prefix_list_init (); diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index b10f4fb4f7..c0b4e7abea 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -1269,7 +1269,6 @@ void ospf_if_init () { /* Initialize Zebra interface data structure. */ - if_init (); om->iflist = iflist; if_add_hook (IF_NEW_HOOK, ospf_if_new_hook); if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook); diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index e1f5a9a9bb..4e67b20bba 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -39,6 +39,7 @@ #include "privs.h" #include "sigevent.h" #include "zclient.h" +#include "vrf.h" #include "ospfd/ospfd.h" #include "ospfd/ospf_interface.h" @@ -300,6 +301,7 @@ main (int argc, char **argv) debug_init (); vty_init (master); memory_init (); + vrf_init (); access_list_init (); prefix_list_init (); diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index 9a5bffe92b..b12ce5ee10 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -2077,7 +2077,6 @@ void rip_if_init (void) { /* Default initial size of interface vector. */ - if_init(); if_add_hook (IF_NEW_HOOK, rip_interface_new_hook); if_add_hook (IF_DELETE_HOOK, rip_interface_delete_hook); diff --git a/ripd/rip_main.c b/ripd/rip_main.c index 0db5634840..a5ea36a1f1 100644 --- a/ripd/rip_main.c +++ b/ripd/rip_main.c @@ -33,6 +33,7 @@ #include "privs.h" #include "sigevent.h" #include "zclient.h" +#include "vrf.h" #include "ripd/ripd.h" @@ -280,6 +281,7 @@ main (int argc, char **argv) vty_init (master); memory_init (); keychain_init (); + vrf_init (); /* RIP related initialization. */ rip_init (); diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index 9517c924c6..3f9f025975 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -35,6 +35,7 @@ #include "table.h" #include "thread.h" #include "privs.h" +#include "vrf.h" #include "ripngd/ripngd.h" #include "ripngd/ripng_debug.h" @@ -1200,7 +1201,6 @@ void ripng_if_init () { /* Interface initialize. */ - iflist = list_new (); if_add_hook (IF_NEW_HOOK, ripng_if_new_hook); if_add_hook (IF_DELETE_HOOK, ripng_if_delete_hook); diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c index 01590d96d1..c05da0c9ef 100644 --- a/ripngd/ripng_main.c +++ b/ripngd/ripng_main.c @@ -34,6 +34,7 @@ #include "if.h" #include "privs.h" #include "sigevent.h" +#include "vrf.h" #include "ripngd/ripngd.h" @@ -276,6 +277,7 @@ main (int argc, char **argv) cmd_init (1); vty_init (master); memory_init (); + vrf_init (); /* RIPngd inits. */ ripng_init (); diff --git a/zebra/interface.c b/zebra/interface.c index 248f77d8f5..d7dbb241d1 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -1766,7 +1766,6 @@ void zebra_if_init (void) { /* Initialize interface and new hook. */ - if_init (); if_add_hook (IF_NEW_HOOK, if_zebra_new_hook); if_add_hook (IF_DELETE_HOOK, if_zebra_delete_hook); diff --git a/zebra/test_main.c b/zebra/test_main.c index f4a8ca2bad..0013506b9b 100644 --- a/zebra/test_main.c +++ b/zebra/test_main.c @@ -316,7 +316,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 (); -- cgit v1.2.3 From cd2a8a42e10a81f84b8c4dd061f1125b06b06bc5 Mon Sep 17 00:00:00 2001 From: Feng Lu Date: Fri, 22 May 2015 11:40:00 +0200 Subject: lib, zebra, vtysh: configure an interface in non-default VRF Introduce a new command "interface IFNAME vrf N" to configure an interface in the non-default VRF. Till now, only zebra uses this command. Other daemons will install the command when they support multiple VRFs. Signed-off-by: Feng Lu Reviewed-by: Alain Ritoux Signed-off-by: Nicolas Dichtel Acked-by: Vincent JARDIN Signed-off-by: David Lamparter Conflicts: zebra/interface.c --- lib/if.c | 21 +++++++++++++++++++++ lib/if.h | 2 ++ vtysh/extract.pl.in | 1 + vtysh/vtysh.c | 19 +++++++++++++++++++ zebra/interface.c | 23 +++++++++++++++++++---- 5 files changed, 62 insertions(+), 4 deletions(-) (limited to 'zebra/interface.c') diff --git a/lib/if.c b/lib/if.c index 634c79ac4c..b192d48e20 100644 --- a/lib/if.c +++ b/lib/if.c @@ -712,6 +712,9 @@ DEFUN (interface, return CMD_WARNING; } + if (argc > 1) + VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]); + #ifdef SUNOS_5 ifp = if_sunwzebra_get (argv[0], sl, vrf_id); #else @@ -724,6 +727,13 @@ DEFUN (interface, return CMD_SUCCESS; } +ALIAS (interface, + interface_vrf_cmd, + "interface IFNAME " VRF_CMD_STR, + "Select an interface to configure\n" + "Interface's name\n" + VRF_CMD_HELP_STR) + DEFUN_NOSH (no_interface, no_interface_cmd, "no interface IFNAME", @@ -735,6 +745,9 @@ DEFUN_NOSH (no_interface, struct interface *ifp; vrf_id_t vrf_id = VRF_DEFAULT; + if (argc > 1) + VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]); + ifp = if_lookup_by_name_vrf (argv[0], vrf_id); if (ifp == NULL) @@ -755,6 +768,14 @@ DEFUN_NOSH (no_interface, return CMD_SUCCESS; } +ALIAS (no_interface, + no_interface_vrf_cmd, + "no interface IFNAME " VRF_CMD_STR, + NO_STR + "Delete a pseudo interface's configuration\n" + "Interface's name\n" + VRF_CMD_HELP_STR) + /* For debug purpose. */ DEFUN (show_address, show_address_cmd, diff --git a/lib/if.h b/lib/if.h index 57a2a959da..05803d01ad 100644 --- a/lib/if.h +++ b/lib/if.h @@ -370,6 +370,8 @@ extern struct cmd_element interface_desc_cmd; extern struct cmd_element no_interface_desc_cmd; extern struct cmd_element interface_cmd; extern struct cmd_element no_interface_cmd; +extern struct cmd_element interface_vrf_cmd; +extern struct cmd_element no_interface_vrf_cmd; extern struct cmd_element interface_pseudo_cmd; extern struct cmd_element no_interface_pseudo_cmd; extern struct cmd_element show_address_cmd; diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index 2249b4092a..56e7115925 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -31,6 +31,7 @@ print <"'} = "ignore"; $ignore{'"ip vrf NAME"'} = "ignore"; $ignore{'"router rip"'} = "ignore"; $ignore{'"router ripng"'} = "ignore"; diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 54e3e4f6c6..58014c2e0d 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -39,6 +39,7 @@ #include "vtysh/vtysh.h" #include "log.h" #include "bgpd/bgp_vty.h" +#include "vrf.h" /* Struct VTY. */ struct vty *vty; @@ -1498,6 +1499,14 @@ DEFUNSH (VTYSH_INTERFACE, return CMD_SUCCESS; } +ALIAS_SH (VTYSH_ZEBRA, + vtysh_interface, + vtysh_interface_vrf_cmd, + "interface IFNAME " VRF_CMD_STR, + "Select an interface to configure\n" + "Interface's name\n" + VRF_CMD_HELP_STR) + /* TODO Implement "no interface command in isisd. */ DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D, vtysh_no_interface_cmd, @@ -1506,6 +1515,14 @@ DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D, "Delete a pseudo interface's configuration\n" "Interface's name\n") +DEFSH (VTYSH_ZEBRA, + vtysh_no_interface_vrf_cmd, + "no interface IFNAME " VRF_CMD_STR, + NO_STR + "Delete a pseudo interface's configuration\n" + "Interface's name\n" + VRF_CMD_HELP_STR) + /* TODO Implement interface description commands in ripngd, ospf6d * and isisd. */ DEFSH (VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD, @@ -2823,6 +2840,8 @@ vtysh_init_vty (void) install_element (KEYCHAIN_KEY_NODE, &key_chain_cmd); install_element (CONFIG_NODE, &vtysh_interface_cmd); install_element (CONFIG_NODE, &vtysh_no_interface_cmd); + install_element (CONFIG_NODE, &vtysh_interface_vrf_cmd); + install_element (CONFIG_NODE, &vtysh_no_interface_vrf_cmd); install_element (ENABLE_NODE, &vtysh_show_running_config_cmd); install_element (ENABLE_NODE, &vtysh_show_running_config_daemon_cmd); install_element (ENABLE_NODE, &vtysh_copy_runningconfig_startupconfig_cmd); diff --git a/zebra/interface.c b/zebra/interface.c index d7dbb241d1..763f826d81 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -32,6 +32,7 @@ #include "connected.h" #include "log.h" #include "zclient.h" +#include "vrf.h" #include "zebra/interface.h" #include "zebra/rtadv.h" @@ -1033,6 +1034,13 @@ DEFUN_NOSH (zebra_interface, return ret; } +ALIAS (zebra_interface, + zebra_interface_vrf_cmd, + "interface IFNAME " VRF_CMD_STR, + "Select an interface to configure\n" + "Interface's name\n" + VRF_CMD_HELP_STR) + struct cmd_node interface_node = { INTERFACE_NODE, @@ -1689,10 +1697,12 @@ if_config_write (struct vty *vty) { struct listnode *node; struct interface *ifp; + vrf_iter_t iter; zebra_ptm_write (vty); - for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) + for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) + for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp)) { struct zebra_if *if_data; struct listnode *addrnode; @@ -1700,9 +1710,12 @@ if_config_write (struct vty *vty) struct prefix *p; if_data = ifp->info; - - vty_out (vty, "interface %s%s", ifp->name, - VTY_NEWLINE); + + if (ifp->vrf_id == VRF_DEFAULT) + vty_out (vty, "interface %s%s", ifp->name, VTY_NEWLINE); + else + vty_out (vty, "interface %s vrf %u%s", ifp->name, ifp->vrf_id, + VTY_NEWLINE); if (if_data) { @@ -1776,7 +1789,9 @@ zebra_if_init (void) install_element (ENABLE_NODE, &show_interface_cmd); install_element (ENABLE_NODE, &show_interface_desc_cmd); install_element (CONFIG_NODE, &zebra_interface_cmd); + install_element (CONFIG_NODE, &zebra_interface_vrf_cmd); install_element (CONFIG_NODE, &no_interface_cmd); + install_element (CONFIG_NODE, &no_interface_vrf_cmd); install_default (INTERFACE_NODE); install_element (INTERFACE_NODE, &interface_desc_cmd); install_element (INTERFACE_NODE, &no_interface_desc_cmd); -- cgit v1.2.3 From 8b87bdf4165979e072b3417dbf82300d18ca7d96 Mon Sep 17 00:00:00 2001 From: Feng Lu Date: Fri, 22 May 2015 11:40:01 +0200 Subject: zebra: show interfaces in a specified VRF or all VRFs The following commands only show interfaces in the default VRF: show interface show interface IFNAME show interface description New options are introduced to show interfaces in a specified VRF: show interface vrf N show interface IFNAME vrf N show interface description vrf N or all VRFs: show interface vrf all show interface IFNAME vrf all show interface description vrf all Signed-off-by: Feng Lu Reviewed-by: Alain Ritoux Signed-off-by: Nicolas Dichtel Acked-by: Vincent JARDIN Signed-off-by: David Lamparter --- zebra/interface.c | 209 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 186 insertions(+), 23 deletions(-) (limited to 'zebra/interface.c') diff --git a/zebra/interface.c b/zebra/interface.c index 763f826d81..2ae2b0bf51 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -1048,16 +1048,53 @@ struct cmd_node interface_node = 1 }; -/* Show all or specified interface to vty. */ +/* Show all interfaces to vty. */ DEFUN (show_interface, show_interface_cmd, - "show interface [IFNAME]", + "show interface", + SHOW_STR + "Interface status and configuration\n") +{ + struct listnode *node; + struct interface *ifp; + vrf_id_t vrf_id = VRF_DEFAULT; + +#ifdef HAVE_PROC_NET_DEV + /* If system has interface statistics via proc file system, update + statistics. */ + ifstat_update_proc (); +#endif /* HAVE_PROC_NET_DEV */ +#ifdef HAVE_NET_RT_IFLIST + ifstat_update_sysctl (); +#endif /* HAVE_NET_RT_IFLIST */ + + if (argc > 0) + VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]); + + /* All interface print. */ + for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp)) + if_dump_vty (vty, ifp); + + return CMD_SUCCESS; +} + +ALIAS (show_interface, + show_interface_vrf_cmd, + "show interface " VRF_CMD_STR, SHOW_STR "Interface status and configuration\n" - "Inteface name\n") + VRF_CMD_HELP_STR) + +/* Show all interfaces to vty. */ +DEFUN (show_interface_vrf_all, show_interface_vrf_all_cmd, + "show interface " VRF_ALL_CMD_STR, + SHOW_STR + "Interface status and configuration\n" + VRF_ALL_CMD_HELP_STR) { struct listnode *node; struct interface *ifp; - + vrf_iter_t iter; + #ifdef HAVE_PROC_NET_DEV /* If system has interface statistics via proc file system, update statistics. */ @@ -1067,39 +1104,107 @@ DEFUN (show_interface, show_interface_cmd, ifstat_update_sysctl (); #endif /* HAVE_NET_RT_IFLIST */ + /* All interface print. */ + for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) + for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp)) + if_dump_vty (vty, ifp); + + return CMD_SUCCESS; +} + +/* Show specified interface to vty. */ +DEFUN (show_interface_name, show_interface_name_cmd, + "show interface IFNAME", + SHOW_STR + "Interface status and configuration\n" + "Inteface name\n") +{ + struct interface *ifp; + vrf_id_t vrf_id = VRF_DEFAULT; + +#ifdef HAVE_PROC_NET_DEV + /* If system has interface statistics via proc file system, update + statistics. */ + ifstat_update_proc (); +#endif /* HAVE_PROC_NET_DEV */ +#ifdef HAVE_NET_RT_IFLIST + ifstat_update_sysctl (); +#endif /* HAVE_NET_RT_IFLIST */ + + if (argc > 1) + VTY_GET_INTEGER ("VRF ID", vrf_id, argv[1]); + /* Specified interface print. */ - if (argc != 0) + ifp = if_lookup_by_name_vrf (argv[0], vrf_id); + if (ifp == NULL) { - ifp = if_lookup_by_name (argv[0]); - if (ifp == NULL) - { - vty_out (vty, "%% Can't find interface %s%s", argv[0], - VTY_NEWLINE); - return CMD_WARNING; - } - if_dump_vty (vty, ifp); - return CMD_SUCCESS; + vty_out (vty, "%% Can't find interface %s%s", argv[0], + VTY_NEWLINE); + return CMD_WARNING; } - - /* All interface print. */ - for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) - if_dump_vty (vty, ifp); + if_dump_vty (vty, ifp); return CMD_SUCCESS; } -DEFUN (show_interface_desc, - show_interface_desc_cmd, - "show interface description", +ALIAS (show_interface_name, + show_interface_name_vrf_cmd, + "show interface IFNAME " VRF_CMD_STR, SHOW_STR "Interface status and configuration\n" - "Interface description\n") + "Inteface name\n" + VRF_CMD_HELP_STR) + +/* Show specified interface to vty. */ +DEFUN (show_interface_name_vrf_all, show_interface_name_vrf_all_cmd, + "show interface IFNAME " VRF_ALL_CMD_STR, + SHOW_STR + "Interface status and configuration\n" + "Inteface name\n" + VRF_ALL_CMD_HELP_STR) +{ + struct interface *ifp; + vrf_iter_t iter; + int found = 0; + +#ifdef HAVE_PROC_NET_DEV + /* If system has interface statistics via proc file system, update + statistics. */ + ifstat_update_proc (); +#endif /* HAVE_PROC_NET_DEV */ +#ifdef HAVE_NET_RT_IFLIST + ifstat_update_sysctl (); +#endif /* HAVE_NET_RT_IFLIST */ + + /* All interface print. */ + for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) + { + /* Specified interface print. */ + ifp = if_lookup_by_name_vrf (argv[0], vrf_iter2id (iter)); + if (ifp) + { + if_dump_vty (vty, ifp); + found++; + } + } + + if (!found) + { + vty_out (vty, "%% Can't find interface %s%s", argv[0], VTY_NEWLINE); + return CMD_WARNING; + } + + return CMD_SUCCESS; +} + +static void +if_show_description (struct vty *vty, vrf_id_t vrf_id) { struct listnode *node; struct interface *ifp; vty_out (vty, "Interface Status Protocol Description%s", VTY_NEWLINE); - for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) + for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp)) { int len; @@ -1130,6 +1235,52 @@ DEFUN (show_interface_desc, vty_out (vty, "%s", ifp->desc); vty_out (vty, "%s", VTY_NEWLINE); } +} + +DEFUN (show_interface_desc, + show_interface_desc_cmd, + "show interface description", + SHOW_STR + "Interface status and configuration\n" + "Interface description\n") +{ + vrf_id_t vrf_id = VRF_DEFAULT; + + if (argc > 0) + VTY_GET_INTEGER ("VRF ID", vrf_id, argv[0]); + + if_show_description (vty, vrf_id); + + return CMD_SUCCESS; +} + +ALIAS (show_interface_desc, + show_interface_desc_vrf_cmd, + "show interface description " VRF_CMD_STR, + SHOW_STR + "Interface status and configuration\n" + "Interface description\n" + VRF_CMD_HELP_STR) + +DEFUN (show_interface_desc_vrf_all, + show_interface_desc_vrf_all_cmd, + "show interface description " VRF_ALL_CMD_STR, + SHOW_STR + "Interface status and configuration\n" + "Interface description\n" + VRF_ALL_CMD_HELP_STR) +{ + vrf_iter_t iter; + + for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) + if (!list_isempty (vrf_iter2iflist (iter))) + { + vty_out (vty, "%s\tVRF %u%s%s", VTY_NEWLINE, + vrf_iter2id (iter), + VTY_NEWLINE, VTY_NEWLINE); + if_show_description (vty, vrf_iter2id (iter)); + } + return CMD_SUCCESS; } @@ -1786,8 +1937,20 @@ zebra_if_init (void) install_node (&interface_node, if_config_write); install_element (VIEW_NODE, &show_interface_cmd); + install_element (VIEW_NODE, &show_interface_vrf_cmd); + install_element (VIEW_NODE, &show_interface_vrf_all_cmd); + install_element (VIEW_NODE, &show_interface_name_cmd); + install_element (VIEW_NODE, &show_interface_name_vrf_cmd); + install_element (VIEW_NODE, &show_interface_name_vrf_all_cmd); install_element (ENABLE_NODE, &show_interface_cmd); + install_element (ENABLE_NODE, &show_interface_vrf_cmd); + install_element (ENABLE_NODE, &show_interface_vrf_all_cmd); + install_element (ENABLE_NODE, &show_interface_name_cmd); + install_element (ENABLE_NODE, &show_interface_name_vrf_cmd); + install_element (ENABLE_NODE, &show_interface_name_vrf_all_cmd); install_element (ENABLE_NODE, &show_interface_desc_cmd); + install_element (ENABLE_NODE, &show_interface_desc_vrf_cmd); + install_element (ENABLE_NODE, &show_interface_desc_vrf_all_cmd); install_element (CONFIG_NODE, &zebra_interface_cmd); install_element (CONFIG_NODE, &zebra_interface_vrf_cmd); install_element (CONFIG_NODE, &no_interface_cmd); -- cgit v1.2.3 From 78104b9bad14a3185178cedc0dd41d1b1c5db493 Mon Sep 17 00:00:00 2001 From: Feng Lu Date: Fri, 22 May 2015 11:40:02 +0200 Subject: zebra: let FIB stand for its respective VRF A new member "vrf_id" is added to "struct rib", reflecting the VRF which it belongs to. A new parameter "vrf_id" is added to the relative functions where need, except those: - which already have the parameter "vrf_id"; or - which have a parameter in type of "struct rib"; or - which have a parameter in type of "struct interface". All incoming routes are set to default VRF. In fact, all routes in FIB are kept in default VRF. And the logic is not changed. Signed-off-by: Feng Lu Reviewed-by: Alain Ritoux Signed-off-by: Nicolas Dichtel Acked-by: Vincent JARDIN [DL: conflicts fixed + compile warning fix] Signed-off-by: David Lamparter Conflicts: zebra/connected.c zebra/kernel_socket.c zebra/rib.h zebra/rt_netlink.c zebra/zebra_rib.c zebra/zserv.c Conflicts: zebra/connected.c zebra/interface.c zebra/kernel_socket.c zebra/rib.h zebra/rt_netlink.c zebra/rtread_getmsg.c zebra/zebra_rib.c zebra/zebra_vty.c zebra/zserv.c --- lib/prefix.c | 7 +- lib/prefix.h | 2 +- zebra/connected.c | 29 ++++---- zebra/interface.c | 4 +- zebra/kernel_socket.c | 17 +++-- zebra/rib.h | 37 ++++++---- zebra/rt_netlink.c | 20 +++-- zebra/rtread_getmsg.c | 3 +- zebra/zebra_rib.c | 199 ++++++++++++++++++++++++++++---------------------- zebra/zebra_vty.c | 16 ++-- zebra/zserv.c | 19 +++-- 11 files changed, 202 insertions(+), 151 deletions(-) (limited to 'zebra/interface.c') diff --git a/lib/prefix.c b/lib/prefix.c index 739764842d..43331d1552 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -766,14 +766,15 @@ str2prefix (const char *str, struct prefix *p) return 0; } -int -prefix2str (const struct prefix *p, char *str, int size) +const char * +prefix2str (union prefix46constptr pu, char *str, int size) { + const struct prefix *p = pu.p; char buf[BUFSIZ]; inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ); snprintf (str, size, "%s/%d", buf, p->prefixlen); - return 0; + return str; } struct prefix * diff --git a/lib/prefix.h b/lib/prefix.h index cc4bbe280d..7fef37e3ff 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -179,7 +179,7 @@ extern void prefix_free (struct prefix *); extern const char *prefix_family_str (const struct prefix *); extern int prefix_blen (const struct prefix *); extern int str2prefix (const char *, struct prefix *); -extern int prefix2str (const struct prefix *, char *, int); +extern const char *prefix2str (union prefix46constptr, char *, int); extern int prefix_match (const struct prefix *, const struct prefix *); extern int prefix_same (const struct prefix *, const struct prefix *); extern int prefix_cmp (const struct prefix *, const struct prefix *); diff --git a/zebra/connected.c b/zebra/connected.c index 2ec6911d77..0d2407a3e0 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -209,15 +209,15 @@ connected_up_ipv4 (struct interface *ifp, struct connected *ifc) return; rib_add_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, NULL, ifp->ifindex, - RT_TABLE_MAIN, ifp->metric, 0, SAFI_UNICAST); + ifp->vrf_id, RT_TABLE_MAIN, ifp->metric, 0, SAFI_UNICAST); rib_add_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, NULL, ifp->ifindex, - RT_TABLE_MAIN, ifp->metric, 0, SAFI_MULTICAST); + ifp->vrf_id, RT_TABLE_MAIN, ifp->metric, 0, SAFI_MULTICAST); if (IS_ZEBRA_DEBUG_RIB) zlog_debug ("%s: calling rib_update", __func__); - rib_update (); + rib_update (ifp->vrf_id); } /* Add connected IPv4 route to the interface. */ @@ -327,14 +327,16 @@ connected_down_ipv4 (struct interface *ifp, struct connected *ifc) return; /* Same logic as for connected_up_ipv4(): push the changes into the head. */ - rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, 0, SAFI_UNICAST); + rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id, 0, + SAFI_UNICAST); - rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, 0, SAFI_MULTICAST); + rib_delete_ipv4 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id, 0, + SAFI_MULTICAST); if (IS_ZEBRA_DEBUG_RIB) zlog_debug ("%s: calling rib_update_static", __func__); - rib_update_static (); + rib_update_static (ifp->vrf_id); } void @@ -397,7 +399,7 @@ connected_delete_ipv4 (struct interface *ifp, int flags, struct in_addr *addr, if (IS_ZEBRA_DEBUG_RIB) zlog_debug ("%s: calling rib_update_static", __func__); - rib_update_static(); + rib_update_static(ifp->vrf_id); } #ifdef HAVE_IPV6 @@ -420,13 +422,13 @@ connected_up_ipv6 (struct interface *ifp, struct connected *ifc) return; #endif - rib_add_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, RT_TABLE_MAIN, - ifp->metric, 0, SAFI_UNICAST); + rib_add_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, ifp->vrf_id, + RT_TABLE_MAIN, ifp->metric, 0, SAFI_UNICAST); if (IS_ZEBRA_DEBUG_RIB) zlog_debug ("%s: calling rib_update", __func__); - rib_update (); + rib_update (ifp->vrf_id); } /* Add connected IPv6 route to the interface. */ @@ -509,12 +511,13 @@ connected_down_ipv6 (struct interface *ifp, struct connected *ifc) if (IN6_IS_ADDR_UNSPECIFIED (&p.prefix)) return; - rib_delete_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, 0, SAFI_UNICAST); + rib_delete_ipv6 (ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, ifp->ifindex, + ifp->vrf_id, 0, SAFI_UNICAST); if (IS_ZEBRA_DEBUG_RIB) zlog_debug ("%s: calling rib_update_static", __func__); - rib_update_static (); + rib_update_static (ifp->vrf_id); } void @@ -538,6 +541,6 @@ connected_delete_ipv6 (struct interface *ifp, struct in6_addr *address, if (IS_ZEBRA_DEBUG_RIB) zlog_debug ("%s: calling rib_update_static", __func__); - rib_update_static(); + rib_update_static(ifp->vrf_id); } #endif /* HAVE_IPV6 */ diff --git a/zebra/interface.c b/zebra/interface.c index 2ae2b0bf51..a3d297d327 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -644,7 +644,7 @@ if_up (struct interface *ifp) ifp->name); /* Examine all static routes. */ - rib_update (); + rib_update (ifp->vrf_id); } /* Interface goes down. We have to manage different behavior of based @@ -681,7 +681,7 @@ if_down (struct interface *ifp) zlog_debug ("%s: calling rib_update_static on interface %s down", __func__, ifp->name); - rib_update_static (); + rib_update_static (ifp->vrf_id); if_nbr_ipv6ll_to_ipv4ll_neigh_del_all (ifp); diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 03f3eaeb6a..a1002a4d86 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -32,6 +32,7 @@ #include "table.h" #include "rib.h" #include "privs.h" +#include "vrf.h" #include "zebra/interface.h" #include "zebra/zserv.h" @@ -870,8 +871,8 @@ rtm_read (struct rt_msghdr *rtm) int ret; if (! IS_ZEBRA_DEBUG_RIB) return; - ret = rib_lookup_ipv4_route (&p, &gate); - inet_ntop (AF_INET, &p.prefix, buf, INET_ADDRSTRLEN); + ret = rib_lookup_ipv4_route (&p, &gate, VRF_DEFAULT); + prefix2str (&p, buf, sizeof(buf)); switch (rtm->rtm_type) { case RTM_ADD: @@ -935,16 +936,16 @@ rtm_read (struct rt_msghdr *rtm) */ if (rtm->rtm_type == RTM_CHANGE) rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, - NULL, 0, 0, SAFI_UNICAST); + NULL, 0, VRF_DEFAULT, SAFI_UNICAST); if (rtm->rtm_type == RTM_GET || rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE) rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - &p, &gate.sin.sin_addr, NULL, 0, 0, 0, 0, SAFI_UNICAST); + &p, &gate.sin.sin_addr, NULL, 0, VRF_DEFAULT, 0, 0, SAFI_UNICAST); else rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0 zebra_flags, - &p, &gate.sin.sin_addr, 0, 0, SAFI_UNICAST); + &p, &gate.sin.sin_addr, 0, VRF_DEFAULT, SAFI_UNICAST); } #ifdef HAVE_IPV6 if (dest.sa.sa_family == AF_INET6) @@ -977,16 +978,16 @@ rtm_read (struct rt_msghdr *rtm) */ if (rtm->rtm_type == RTM_CHANGE) rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, - NULL, 0, 0, SAFI_UNICAST); + NULL, 0, VRF_DEFAULT, SAFI_UNICAST); if (rtm->rtm_type == RTM_GET || rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE) rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - &p, &gate.sin6.sin6_addr, ifindex, 0, 0, 0, SAFI_UNICAST); + &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, 0, 0, SAFI_UNICAST); else rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, - &p, &gate.sin6.sin6_addr, ifindex, 0, SAFI_UNICAST); + &p, &gate.sin6.sin6_addr, ifindex, VRF_DEFAULT, SAFI_UNICAST); } #endif /* HAVE_IPV6 */ } diff --git a/zebra/rib.h b/zebra/rib.h index 8c82a7eec3..6908e9d816 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -52,6 +52,9 @@ struct rib /* Source protocol instance */ u_short instance; + /* VRF identifier. */ + vrf_id_t vrf_id; + /* Which routing table */ uint32_t table; @@ -367,7 +370,8 @@ extern void rib_lookup_and_pushup (struct prefix_ipv4 *); #define rib_dump(prefix ,rib) _rib_dump(__func__, prefix, rib) extern void _rib_dump (const char *, union prefix46constptr, const struct rib *); -extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *); +extern int rib_lookup_ipv4_route (struct prefix_ipv4 *, union sockunion *, + vrf_id_t); #define ZEBRA_RIB_LOOKUP_ERROR -1 #define ZEBRA_RIB_FOUND_EXACT 0 #define ZEBRA_RIB_FOUND_NOGATE 1 @@ -401,21 +405,21 @@ extern int zebra_check_addr (struct prefix *p); * also implicitly withdraw equal prefix of same type. */ extern int rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, struct in_addr *gate, struct in_addr *src, - unsigned int ifindex, u_int32_t vrf_id, + unsigned int ifindex, vrf_id_t vrf_id, u_int32_t table_id, u_int32_t, u_char, safi_t); extern int rib_add_ipv4_multipath (struct prefix_ipv4 *, struct rib *, safi_t); extern int rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, struct in_addr *gate, unsigned int ifindex, - u_int32_t, safi_t safi); + vrf_id_t, u_int32_t, safi_t safi); -extern struct rib *rib_match_ipv4 (struct in_addr); +extern struct rib *rib_match_ipv4 (struct in_addr, vrf_id_t); -extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *); +extern struct rib *rib_lookup_ipv4 (struct prefix_ipv4 *, vrf_id_t); -extern void rib_update (void); -extern void rib_update_static (void); +extern void rib_update (vrf_id_t); +extern void rib_update_static (vrf_id_t); extern void rib_weed_tables (void); extern void rib_sweep_route (void); extern void rib_close (void); @@ -427,32 +431,33 @@ extern void rib_queue_add (struct zebra_t *zebra, struct route_node *rn); extern int static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname, - u_char flags, u_short tag, u_char distance, u_int32_t vrf_id); + u_char flags, u_short tag, u_char distance, vrf_id_t vrf_id); extern int static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname, - u_short tag, u_char distance, u_int32_t vrf_id); + u_short tag, u_char distance, vrf_id_t vrf_id); #ifdef HAVE_IPV6 extern int rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, - struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, - u_int32_t metric, u_char distance, safi_t safi); + struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, + u_int32_t table_id, u_int32_t metric, u_char distance, safi_t safi); extern int rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, - struct in6_addr *gate, unsigned int ifindex, u_int32_t vrf_id, safi_t safi); + struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, + u_int32_t table_id, safi_t safi); -extern struct rib *rib_lookup_ipv6 (struct in6_addr *); +extern struct rib *rib_lookup_ipv6 (struct in6_addr *, vrf_id_t); -extern struct rib *rib_match_ipv6 (struct in6_addr *); +extern struct rib *rib_match_ipv6 (struct in6_addr *, vrf_id_t); extern struct route_table *rib_table_ipv6; extern int static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, const char *ifname, u_char flags, u_short tag, - u_char distance, u_int32_t vrf_id); + u_char distance, vrf_id_t vrf_id); extern int rib_add_ipv6_multipath (struct prefix *, struct rib *, safi_t, @@ -461,7 +466,7 @@ rib_add_ipv6_multipath (struct prefix *, struct rib *, safi_t, extern int static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, const char *ifname, u_short tag, u_char distance, - u_int32_t vrf_id); + vrf_id_t vrf_id); #endif /* HAVE_IPV6 */ diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 4c16df61a1..e312801e55 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -37,6 +37,7 @@ #include "thread.h" #include "privs.h" #include "nexthop.h" +#include "vrf.h" #include "zebra/zserv.h" #include "zebra/rt.h" @@ -755,7 +756,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h) if (!tb[RTA_MULTIPATH]) rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, src, index, - table, metric, 0, SAFI_UNICAST); + VRF_DEFAULT, table, metric, 0, SAFI_UNICAST); else { /* This is a multipath route */ @@ -771,6 +772,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h) rib->distance = 0; rib->flags = flags; rib->metric = metric; + rib->vrf_id = VRF_DEFAULT; rib->table = table; rib->nexthop_num = 0; rib->uptime = time (NULL); @@ -821,8 +823,8 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h) memcpy (&p.prefix, dest, 16); p.prefixlen = rtm->rtm_dst_len; - rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, index, table, - metric, 0, SAFI_UNICAST); + rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, flags, &p, gate, index, VRF_DEFAULT, + table, metric, 0, SAFI_UNICAST); } #endif /* HAVE_IPV6 */ @@ -958,8 +960,8 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h) if (h->nlmsg_type == RTM_NEWROUTE) { if (!tb[RTA_MULTIPATH]) - rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, src, index, table, - metric, 0, SAFI_UNICAST); + rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, src, index, VRF_DEFAULT, + table, metric, 0, SAFI_UNICAST); else { /* This is a multipath route */ @@ -975,6 +977,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h) rib->distance = 0; rib->flags = 0; rib->metric = metric; + rib->vrf_id = VRF_DEFAULT; rib->table = table; rib->nexthop_num = 0; rib->uptime = time (NULL); @@ -1020,7 +1023,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h) } else rib_delete_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, gate, index, - table, SAFI_UNICAST); + VRF_DEFAULT, table, SAFI_UNICAST); } #ifdef HAVE_IPV6 @@ -1046,10 +1049,11 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h) } if (h->nlmsg_type == RTM_NEWROUTE) - rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, index, table, metric, 0, SAFI_UNICAST); + rib_add_ipv6 (ZEBRA_ROUTE_KERNEL, 0, 0, &p, gate, index, VRF_DEFAULT, + table, metric, 0, SAFI_UNICAST); else rib_delete_ipv6 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, gate, index, - table, SAFI_UNICAST); + VRF_DEFAULT, table, SAFI_UNICAST); } #endif /* HAVE_IPV6 */ diff --git a/zebra/rtread_getmsg.c b/zebra/rtread_getmsg.c index 17d75b283a..f9bfb338a0 100644 --- a/zebra/rtread_getmsg.c +++ b/zebra/rtread_getmsg.c @@ -25,6 +25,7 @@ #include "prefix.h" #include "log.h" #include "if.h" +#include "vrf.h" #include "zebra/rib.h" #include "zebra/zserv.h" @@ -90,7 +91,7 @@ handle_route_entry (mib2_ipRouteEntry_t *routeEntry) gateway.s_addr = routeEntry->ipRouteNextHop; rib_add_ipv4 (ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &prefix, - &gateway, NULL, 0, 0, 0, 0, SAFI_UNICAST); + &gateway, NULL, 0, VRF_DEFAULT, 0, 0, 0, SAFI_UNICAST); } void diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index b15cbd3cdb..79aa989814 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -483,7 +483,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set, p.prefix = nexthop->gate.ipv4; /* Lookup table. */ - table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, rib->vrf_id); if (! table) return 0; @@ -692,7 +692,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set, p.prefix = nexthop->gate.ipv6; /* Lookup table. */ - table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, rib->vrf_id); if (! table) return 0; @@ -846,7 +846,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set, #endif /* HAVE_IPV6 */ struct rib * -rib_match_ipv4 (struct in_addr addr) +rib_match_ipv4 (struct in_addr addr, vrf_id_t vrf_id) { struct prefix_ipv4 p; struct route_table *table; @@ -856,7 +856,7 @@ rib_match_ipv4 (struct in_addr addr) int recursing; /* Lookup table. */ - table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); if (! table) return 0; @@ -908,7 +908,7 @@ rib_match_ipv4 (struct in_addr addr) } struct rib * -rib_lookup_ipv4 (struct prefix_ipv4 *p) +rib_lookup_ipv4 (struct prefix_ipv4 *p, vrf_id_t vrf_id) { struct route_table *table; struct route_node *rn; @@ -917,7 +917,7 @@ rib_lookup_ipv4 (struct prefix_ipv4 *p) int recursing; /* Lookup table. */ - table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); if (! table) return 0; @@ -964,7 +964,8 @@ rib_lookup_ipv4 (struct prefix_ipv4 *p) * 3: no matches found */ int -rib_lookup_ipv4_route (struct prefix_ipv4 *p, union sockunion * qgate) +rib_lookup_ipv4_route (struct prefix_ipv4 *p, union sockunion * qgate, + vrf_id_t vrf_id) { struct route_table *table; struct route_node *rn; @@ -974,7 +975,7 @@ rib_lookup_ipv4_route (struct prefix_ipv4 *p, union sockunion * qgate) int nexthops_active; /* Lookup table. */ - table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); if (! table) return ZEBRA_RIB_LOOKUP_ERROR; @@ -1030,7 +1031,7 @@ rib_lookup_ipv4_route (struct prefix_ipv4 *p, union sockunion * qgate) #ifdef HAVE_IPV6 struct rib * -rib_match_ipv6 (struct in6_addr *addr) +rib_match_ipv6 (struct in6_addr *addr, vrf_id_t vrf_id) { struct prefix_ipv6 p; struct route_table *table; @@ -1040,7 +1041,7 @@ rib_match_ipv6 (struct in6_addr *addr) int recursing; /* Lookup table. */ - table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id); if (! table) return 0; @@ -1124,7 +1125,7 @@ nexthop_active_check (struct route_node *rn, struct rib *rib, switch (nexthop->type) { case NEXTHOP_TYPE_IFINDEX: - ifp = if_lookup_by_index (nexthop->ifindex); + ifp = if_lookup_by_index_vrf (nexthop->ifindex, rib->vrf_id); if (ifp && if_is_operative(ifp)) SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE); else @@ -1133,7 +1134,7 @@ nexthop_active_check (struct route_node *rn, struct rib *rib, case NEXTHOP_TYPE_IPV6_IFNAME: family = AFI_IP6; case NEXTHOP_TYPE_IFNAME: - ifp = if_lookup_by_name (nexthop->ifname); + ifp = if_lookup_by_name_vrf (nexthop->ifname, rib->vrf_id); if (ifp && if_is_operative(ifp)) { if (set) @@ -1169,7 +1170,7 @@ nexthop_active_check (struct route_node *rn, struct rib *rib, family = AFI_IP6; if (IN6_IS_ADDR_LINKLOCAL (&nexthop->gate.ipv6)) { - ifp = if_lookup_by_index (nexthop->ifindex); + ifp = if_lookup_by_index_vrf (nexthop->ifindex, rib->vrf_id); if (ifp && if_is_operative(ifp)) SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE); else @@ -2150,7 +2151,7 @@ rib_delnode (struct route_node *rn, struct rib *rib) int rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, struct in_addr *gate, struct in_addr *src, - unsigned int ifindex, u_int32_t table_id, + unsigned int ifindex, vrf_id_t vrf_id, u_int32_t table_id, u_int32_t metric, u_char distance, safi_t safi) { struct rib *rib; @@ -2162,11 +2163,11 @@ rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, /* Lookup table. */ if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default)) { - table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP, safi, vrf_id); } else { - table = zebra_vrf_other_route_table (AFI_IP, table_id, VRF_DEFAULT); + table = zebra_vrf_other_route_table (AFI_IP, table_id, vrf_id); } if (! table) return 0; @@ -2226,6 +2227,7 @@ rib_add_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, rib->flags = flags; rib->metric = metric; rib->table = table_id; + rib->vrf_id = vrf_id; rib->nexthop_num = 0; rib->uptime = time (NULL); @@ -2279,8 +2281,8 @@ void _rib_dump (const char * func, struct nexthop *nexthop, *tnexthop; int recursing; - inet_ntop (p->family, &p->u.prefix, straddr, INET6_ADDRSTRLEN); - zlog_debug ("%s: dumping RIB entry %p for %s/%d", func, rib, straddr, p->prefixlen); + zlog_debug ("%s: dumping RIB entry %p for %s vrf %u", func, rib, + prefix2str(pp, straddr, sizeof(straddr)), rib->vrf_id); zlog_debug ( "%s: refcnt == %lu, uptime == %lu, type == %u, instance == %d, table == %d", @@ -2439,11 +2441,11 @@ rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi) /* Lookup table. */ if ((rib->table == zebrad.rtm_table_default) || (rib->table == RT_TABLE_MAIN)) { - table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP, safi, rib->vrf_id); } else { - table = zebra_vrf_other_route_table (AFI_IP, rib->table, VRF_DEFAULT); + table = zebra_vrf_other_route_table (AFI_IP, rib->table, rib->vrf_id); } if (! table) return 0; @@ -2513,7 +2515,7 @@ rib_add_ipv4_multipath (struct prefix_ipv4 *p, struct rib *rib, safi_t safi) /* XXX factor with rib_delete_ipv6 */ int rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, - struct in_addr *gate, unsigned int ifindex, + struct in_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, u_int32_t table_id, safi_t safi) { struct route_table *table; @@ -2529,11 +2531,11 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, /* Lookup table. */ if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default)) { - table = zebra_vrf_table (AFI_IP, safi, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP, safi, vrf_id); } else { - table = zebra_vrf_other_route_table(AFI_IP, table_id, VRF_DEFAULT); + table = zebra_vrf_other_route_table(AFI_IP, table_id, vrf_id); } if (! table) return 0; @@ -2544,15 +2546,13 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, if (IS_ZEBRA_DEBUG_KERNEL) { if (gate) - zlog_debug ("rib_delete_ipv4(): route delete %s/%d via %s ifindex %d", - inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN), - p->prefixlen, + zlog_debug ("rib_delete_ipv4(): route delete %s vrf %u via %s ifindex %d", + prefix2str (p, buf1, sizeof(buf1)), vrf_id, inet_ntoa (*gate), ifindex); else - zlog_debug ("rib_delete_ipv4(): route delete %s/%d ifindex %d", - inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN), - p->prefixlen, + zlog_debug ("rib_delete_ipv4(): route delete %s vrf %u ifindex %d", + prefix2str (p, buf1, sizeof(buf1)), vrf_id, ifindex); } @@ -2563,15 +2563,13 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, if (IS_ZEBRA_DEBUG_KERNEL) { if (gate) - zlog_debug ("route %s/%d via %s ifindex %d doesn't exist in rib", - inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN), - p->prefixlen, + zlog_debug ("route %s vrf %u via %s ifindex %d doesn't exist in rib", + prefix2str (p, buf1, sizeof(buf1)), vrf_id, inet_ntop (AF_INET, gate, buf2, INET_ADDRSTRLEN), ifindex); else - zlog_debug ("route %s/%d ifindex %d doesn't exist in rib", - inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN), - p->prefixlen, + zlog_debug ("route %s vrf %u ifindex %d doesn't exist in rib", + prefix2str (p, buf1, sizeof(buf1)), vrf_id, ifindex); } return ZEBRA_ERR_RTNOEXIST; @@ -2656,16 +2654,15 @@ rib_delete_ipv4 (int type, u_short instance, int flags, struct prefix_ipv4 *p, if (IS_ZEBRA_DEBUG_KERNEL) { if (gate) - zlog_debug ("route %s/%d via %s ifindex %d type %d doesn't exist in rib", - inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN), - p->prefixlen, + zlog_debug ("route %s vrf %u via %s ifindex %d type %d " + "doesn't exist in rib", + prefix2str (p, buf1, sizeof(buf1)), vrf_id, inet_ntop (AF_INET, gate, buf2, INET_ADDRSTRLEN), ifindex, type); else - zlog_debug ("route %s/%d ifindex %d type %d doesn't exist in rib", - inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN), - p->prefixlen, + zlog_debug ("route %s vrf %u ifindex %d type %d doesn't exist in rib", + prefix2str (p, buf1, sizeof(buf1)), vrf_id, ifindex, type); } @@ -2742,6 +2739,7 @@ static_install_ipv4 (struct prefix *p, struct static_ipv4 *si) rib->instance = 0; rib->distance = si->distance; rib->metric = 0; + rib->vrf_id = VRF_DEFAULT; rib->table = zebrad.rtm_table_default; rib->nexthop_num = 0; rib->tag = si->tag; @@ -2876,7 +2874,7 @@ static_uninstall_ipv4 (struct prefix *p, struct static_ipv4 *si) /* Add static route into static route configuration. */ int static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname, - u_char flags, u_short tag, u_char distance, u_int32_t vrf_id) + u_char flags, u_short tag, u_char distance, vrf_id_t vrf_id) { u_char type = 0; struct route_node *rn; @@ -2884,10 +2882,9 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname, struct static_ipv4 *pp; struct static_ipv4 *cp; struct static_ipv4 *update = NULL; - struct route_table *stable; + struct zebra_vrf *zvrf = vrf_info_get (vrf_id); + struct route_table *stable = zvrf->stable[AFI_IP][SAFI_UNICAST]; - /* Lookup table. */ - stable = zebra_vrf_static_table (AFI_IP, SAFI_UNICAST, vrf_id); if (! stable) return -1; @@ -2972,7 +2969,7 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname, /* Delete static route from static route configuration. */ int static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname, - u_short tag, u_char distance, u_int32_t vrf_id) + u_short tag, u_char distance, vrf_id_t vrf_id) { u_char type = 0; struct route_node *rn; @@ -3059,8 +3056,8 @@ rib_bogus_ipv6 (int type, struct prefix_ipv6 *p, int rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, - struct in6_addr *gate, unsigned int ifindex, u_int32_t table_id, - u_int32_t metric, u_char distance, safi_t safi) + struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, + u_int32_t table_id, u_int32_t metric, u_char distance, safi_t safi) { struct rib *rib; struct rib *same = NULL; @@ -3071,11 +3068,11 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, /* Lookup table. */ if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default)) { - table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP6, safi, vrf_id); } else { - table = zebra_vrf_other_route_table(AFI_IP6, table_id, VRF_DEFAULT); + table = zebra_vrf_other_route_table(AFI_IP6, table_id, vrf_id); } if (! table) return 0; @@ -3131,6 +3128,7 @@ rib_add_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, rib->flags = flags; rib->metric = metric; rib->table = table_id; + rib->vrf_id = vrf_id; rib->nexthop_num = 0; rib->uptime = time (NULL); @@ -3294,7 +3292,8 @@ rib_add_ipv6_multipath (struct prefix *p, struct rib *rib, safi_t safi, /* XXX factor with rib_delete_ipv6 */ int rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, - struct in6_addr *gate, unsigned int ifindex, u_int32_t table_id, safi_t safi) + struct in6_addr *gate, unsigned int ifindex, vrf_id_t vrf_id, + u_int32_t table_id, safi_t safi) { struct route_table *table; struct route_node *rn; @@ -3312,7 +3311,7 @@ rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, /* Lookup table. */ if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default)) { - table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP6, safi, vrf_id); } else { @@ -3328,15 +3327,13 @@ rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, if (IS_ZEBRA_DEBUG_KERNEL) { if (gate) - zlog_debug ("route %s/%d via %s ifindex %d doesn't exist in rib", - inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN), - p->prefixlen, + zlog_debug ("route %s vrf %u via %s ifindex %d doesn't exist in rib", + prefix2str (p, buf1, sizeof(buf1)), vrf_id, inet_ntop (AF_INET6, gate, buf2, INET6_ADDRSTRLEN), ifindex); else - zlog_debug ("route %s/%d ifindex %d doesn't exist in rib", - inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN), - p->prefixlen, + zlog_debug ("route %s vrf %u ifindex %d doesn't exist in rib", + prefix2str (p, buf1, sizeof(buf1)), vrf_id, ifindex); } return ZEBRA_ERR_RTNOEXIST; @@ -3422,16 +3419,15 @@ rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, if (IS_ZEBRA_DEBUG_KERNEL) { if (gate) - zlog_debug ("route %s/%d via %s ifindex %d type %d doesn't exist in rib", - inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN), - p->prefixlen, + zlog_debug ("route %s vrf %u via %s ifindex %d type %d " + "doesn't exist in rib", + prefix2str (p, buf1, sizeof(buf1)), vrf_id, inet_ntop (AF_INET6, gate, buf2, INET6_ADDRSTRLEN), ifindex, type); else - zlog_debug ("route %s/%d ifindex %d type %d doesn't exist in rib", - inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN), - p->prefixlen, + zlog_debug ("route %s vrf %u ifindex %d type %d doesn't exist in rib", + prefix2str (p, buf1, sizeof(buf1)), vrf_id, ifindex, type); } @@ -3509,6 +3505,7 @@ static_install_ipv6 (struct prefix *p, struct static_ipv6 *si) rib->instance = 0; rib->distance = si->distance; rib->metric = 0; + rib->vrf_id = VRF_DEFAULT; rib->table = zebrad.rtm_table_default; rib->nexthop_num = 0; rib->tag = si->tag; @@ -3644,16 +3641,15 @@ static_uninstall_ipv6 (struct prefix *p, struct static_ipv6 *si) int static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, const char *ifname, u_char flags, u_short tag, - u_char distance, u_int32_t vrf_id) + u_char distance, vrf_id_t vrf_id) { struct route_node *rn; struct static_ipv6 *si; struct static_ipv6 *pp; struct static_ipv6 *cp; - struct route_table *stable; + struct zebra_vrf *zvrf = vrf_info_get (vrf_id); + struct route_table *stable = zvrf->stable[AFI_IP6][SAFI_UNICAST]; - /* Lookup table. */ - stable = zebra_vrf_static_table (AFI_IP6, SAFI_UNICAST, vrf_id); if (! stable) return -1; @@ -3734,7 +3730,7 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, int static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, const char *ifname, u_short tag, u_char distance, - u_int32_t vrf_id) + vrf_id_t vrf_id) { struct route_node *rn; struct static_ipv6 *si; @@ -3788,13 +3784,13 @@ static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, /* RIB update function. */ void -rib_update_static (void) +rib_update_static (vrf_id_t vrf_id) { struct route_node *rn; struct route_table *table; struct rib *rib, *next; - table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); if (table) for (rn = route_top (table); rn; rn = route_next (rn)) RNODE_FOREACH_RIB_SAFE (rn, rib, next) @@ -3804,7 +3800,7 @@ rib_update_static (void) break; } - table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id); if (table) for (rn = route_top (table); rn; rn = route_next (rn)) RNODE_FOREACH_RIB_SAFE (rn, rib, next) @@ -3817,18 +3813,18 @@ rib_update_static (void) /* RIB update function. */ void -rib_update (void) +rib_update (vrf_id_t vrf_id) { struct route_node *rn; struct route_table *table; - table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); if (table) for (rn = route_top (table); rn; rn = route_next (rn)) if (rnode_to_ribs (rn)) rib_queue_add (&zebrad, rn); - table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT); + table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id); if (table) for (rn = route_top (table); rn; rn = route_next (rn)) if (rnode_to_ribs (rn)) @@ -3861,8 +3857,15 @@ rib_weed_table (struct route_table *table) void rib_weed_tables (void) { - rib_weed_table (zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT)); - rib_weed_table (zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT)); + vrf_iter_t iter; + struct zebra_vrf *zvrf; + + for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) + if ((zvrf = vrf_iter2info (iter)) != NULL) + { + rib_weed_table (zvrf->table[AFI_IP][SAFI_UNICAST]); + rib_weed_table (zvrf->table[AFI_IP6][SAFI_UNICAST]); + } } /* Delete self installed routes after zebra is relaunched. */ @@ -3895,8 +3898,15 @@ rib_sweep_table (struct route_table *table) void rib_sweep_route (void) { - rib_sweep_table (zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT)); - rib_sweep_table (zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT)); + vrf_iter_t iter; + struct zebra_vrf *zvrf; + + for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) + if ((zvrf = vrf_iter2info (iter)) != NULL) + { + rib_sweep_table (zvrf->table[AFI_IP][SAFI_UNICAST]); + rib_sweep_table (zvrf->table[AFI_IP6][SAFI_UNICAST]); + } } /* Remove specific by protocol routes from 'table'. */ @@ -3928,8 +3938,16 @@ rib_score_proto_table (u_char proto, u_short instance, struct route_table *table unsigned long rib_score_proto (u_char proto, u_short instance) { - return rib_score_proto_table (proto, instance, zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT)) - +rib_score_proto_table (proto, instance, zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT)); + vrf_iter_t iter; + struct zebra_vrf *zvrf; + unsigned long cnt = 0; + + for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) + if ((zvrf = vrf_iter2info (iter)) != NULL) + cnt += rib_score_proto_table (proto, instance, zvrf->table[AFI_IP][SAFI_UNICAST]) + +rib_score_proto_table (proto, instance, zvrf->table[AFI_IP6][SAFI_UNICAST]); + + return cnt; } /* Close RIB and clean up kernel routes. */ @@ -3957,14 +3975,21 @@ rib_close_table (struct route_table *table) void rib_close (void) { - struct listnode *node, *nnode; + vrf_iter_t iter; + struct zebra_vrf *zvrf; + struct listnode *node; struct interface *ifp; - rib_close_table (zebra_vrf_table (AFI_IP, SAFI_UNICAST, VRF_DEFAULT)); - rib_close_table (zebra_vrf_table (AFI_IP6, SAFI_UNICAST, VRF_DEFAULT)); - - for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) - if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp); + for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) + { + if ((zvrf = vrf_iter2info (iter)) != NULL) + { + rib_close_table (zvrf->table[AFI_IP][SAFI_UNICAST]); + rib_close_table (zvrf->table[AFI_IP6][SAFI_UNICAST]); + } + for (ALL_LIST_ELEMENTS_RO (vrf_iter2iflist (iter), node, ifp)) + if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp); + } } /* Routing information base initialize. */ diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 9728a28c0e..1a50ab6990 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -961,7 +961,8 @@ vty_show_ip_route_detail (struct vty *vty, struct route_node *rn) case NEXTHOP_TYPE_IPV4_IFINDEX: vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4)); if (nexthop->ifindex) - vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex)); + vty_out (vty, ", via %s", + ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); break; #ifdef HAVE_IPV6 case NEXTHOP_TYPE_IPV6: @@ -972,12 +973,13 @@ vty_show_ip_route_detail (struct vty *vty, struct route_node *rn) if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME) vty_out (vty, ", %s", nexthop->ifname); else if (nexthop->ifindex) - vty_out (vty, ", via %s", ifindex2ifname (nexthop->ifindex)); + vty_out (vty, ", via %s", + ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); break; #endif /* HAVE_IPV6 */ case NEXTHOP_TYPE_IFINDEX: vty_out (vty, " directly connected, %s", - ifindex2ifname (nexthop->ifindex)); + ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); break; case NEXTHOP_TYPE_IFNAME: vty_out (vty, " directly connected, %s", nexthop->ifname); @@ -1073,7 +1075,8 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib) case NEXTHOP_TYPE_IPV4_IFINDEX: vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4)); if (nexthop->ifindex) - vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex)); + vty_out (vty, ", %s", + ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); break; #ifdef HAVE_IPV6 case NEXTHOP_TYPE_IPV6: @@ -1084,13 +1087,14 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib) if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME) vty_out (vty, ", %s", nexthop->ifname); else if (nexthop->ifindex) - vty_out (vty, ", %s", ifindex2ifname (nexthop->ifindex)); + vty_out (vty, ", %s", + ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); break; #endif /* HAVE_IPV6 */ case NEXTHOP_TYPE_IFINDEX: vty_out (vty, " is directly connected, %s", - ifindex2ifname (nexthop->ifindex)); + ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); break; case NEXTHOP_TYPE_IFNAME: vty_out (vty, " is directly connected, %s", nexthop->ifname); diff --git a/zebra/zserv.c b/zebra/zserv.c index ba3c59aafb..052c797f8b 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -37,6 +37,7 @@ #include "network.h" #include "buffer.h" #include "nexthop.h" +#include "vrf.h" #include "zebra/zserv.h" #include "zebra/router-id.h" @@ -643,7 +644,7 @@ zsend_ipv6_nexthop_lookup (struct zserv *client, struct in6_addr *addr) struct nexthop *nexthop; /* Lookup nexthop. */ - rib = rib_match_ipv6 (addr); + rib = rib_match_ipv6 (addr, VRF_DEFAULT); /* Get output stream. */ s = client->obuf; @@ -710,7 +711,7 @@ zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr) struct nexthop *nexthop; /* Lookup nexthop. */ - rib = rib_match_ipv4 (addr); + rib = rib_match_ipv4 (addr, VRF_DEFAULT); /* Get output stream. */ s = client->obuf; @@ -892,7 +893,7 @@ zsend_ipv4_import_lookup (struct zserv *client, struct prefix_ipv4 *p) struct nexthop *nexthop; /* Lookup nexthop. */ - rib = rib_lookup_ipv4 (p); + rib = rib_lookup_ipv4 (p, VRF_DEFAULT); /* Get output stream. */ s = client->obuf; @@ -1076,6 +1077,9 @@ zread_ipv4_add (struct zserv *client, u_short length) p.prefixlen = stream_getc (s); stream_get (&p.prefix, s, PSIZE (p.prefixlen)); + /* VRF ID */ + rib->vrf_id = VRF_DEFAULT; + /* Nexthop parse. */ if (CHECK_FLAG (message, ZAPI_MESSAGE_NEXTHOP)) { @@ -1231,7 +1235,7 @@ zread_ipv4_delete (struct zserv *client, u_short length) api.tag = 0; rib_delete_ipv4 (api.type, api.instance, api.flags, &p, nexthop_p, ifindex, - client->rtm_table, api.safi); + VRF_DEFAULT, client->rtm_table, api.safi); client->v4_route_del_cnt++; return 0; } @@ -1505,6 +1509,7 @@ zread_ipv6_add (struct zserv *client, u_short length) /* Table */ rib->table=zebrad.rtm_table_default; + rib->vrf_id = VRF_DEFAULT; ret = rib_add_ipv6_multipath ((struct prefix *)&p, rib, safi, ifindex); /* Stats */ if (ret > 0) @@ -1584,9 +1589,11 @@ zread_ipv6_delete (struct zserv *client, u_short length) api.tag = 0; if (IN6_IS_ADDR_UNSPECIFIED (&nexthop)) - rib_delete_ipv6 (api.type, api.instance, api.flags, &p, NULL, ifindex, client->rtm_table, api.safi); + rib_delete_ipv6 (api.type, api.instance, api.flags, &p, NULL, ifindex, + VRF_DEFAULT, client->rtm_table, api.safi); else - rib_delete_ipv6 (api.type, api.instance, api.flags, &p, &nexthop, ifindex, client->rtm_table, api.safi); + rib_delete_ipv6 (api.type, api.instance, api.flags, &p, &nexthop, ifindex, + VRF_DEFAULT, client->rtm_table, api.safi); client->v6_route_del_cnt++; return 0; -- cgit v1.2.3