From e2b1be648db7e7906aa5e4e04b23ef88cbeff04a Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 13 Apr 2016 10:06:36 -0400 Subject: [PATCH] lib, zebra: Rework vrf_add_update The vrf_add_update function does not need to exist. Move it's constituent parts into the appropriate vrf_create/vrf_enable functionality as well as move the zebra_vrf_add_update() function call into zebra_vrf_enable() Signed-off-by: Donald Sharp Reviewed-by: Don Slice Reviewed-by: Vivek Venkatraman --- lib/vrf.c | 14 +++++--------- zebra/interface.c | 25 ------------------------- zebra/main.c | 3 +++ zebra/rt_netlink.c | 14 ++++++++++---- 4 files changed, 18 insertions(+), 38 deletions(-) diff --git a/lib/vrf.c b/lib/vrf.c index eab720fe1d..90f8fa86ba 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -231,20 +231,16 @@ vrf_is_enabled (struct vrf *vrf) int vrf_enable (struct vrf *vrf) { -//Pending: see if VRF lib had a reason to leave it for default only -// /* Till now, only the default VRF can be enabled. */ -// if (vrf->vrf_id == VRF_DEFAULT) -// { if (debug_vrf) zlog_debug ("VRF %u is enabled.", vrf->vrf_id); - if (vrf_master.vrf_enable_hook) - (*vrf_master.vrf_enable_hook) (vrf->vrf_id, vrf->name, &vrf->info); + if (!CHECK_FLAG (vrf->status, VRF_ACTIVE)) + SET_FLAG (vrf->status, VRF_ACTIVE); - return 1; -// } + if (vrf_master.vrf_enable_hook) + (*vrf_master.vrf_enable_hook) (vrf->vrf_id, vrf->name, &vrf->info); -// return 0; + return 1; } /* diff --git a/zebra/interface.c b/zebra/interface.c index cd5f1d9f0d..df6848f05a 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -714,31 +714,6 @@ if_handle_vrf_change (struct interface *ifp, vrf_id_t vrf_id) rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE); } - -/* Handle VRF addition */ -void -vrf_add_update (struct vrf *vrfp) -{ - zebra_vrf_add_update (vrf_info_lookup (vrfp->vrf_id)); - - if (! CHECK_FLAG (vrfp->status, VRF_ACTIVE)) - { - SET_FLAG (vrfp->status, VRF_ACTIVE); - - //Pending: Check if the equivalent of if_addr_wakeup (ifp) is needed here. - - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug ("VRF %s id %u becomes active.", - vrfp->name, vrfp->vrf_id); - } - else - { - if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug ("VRF %s id %u is added.", - vrfp->name, vrfp->vrf_id); - } -} - static void ipv6_ll_address_to_mac (struct in6_addr *address, u_char *mac) { diff --git a/zebra/main.c b/zebra/main.c index eb46aad6ca..5da91042d3 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -43,6 +43,7 @@ #include "zebra/rtadv.h" #include "zebra/zebra_fpm.h" #include "zebra/zebra_ptm.h" +#include "zebra/redistribute.h" #define ZEBRA_PTM_SUPPORT @@ -276,6 +277,8 @@ zebra_vrf_enable (vrf_id_t vrf_id, const char *name, void **info) assert (zvrf); + zebra_vrf_add_update (zvrf); + return 0; } diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 41db582df4..499881877e 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -556,6 +556,9 @@ netlink_vrf_change (struct nlmsghdr *h, struct rtattr *tb, const char *name) zlog_debug ("RTM_NEWLINK for VRF %s(%u) table %u", name, ifi->ifi_index, nl_table_id); + /* + * vrf_get is implied creation if it does not exist + */ vrf = vrf_get((vrf_id_t)ifi->ifi_index, name); // It would create vrf if (!vrf) { @@ -570,11 +573,14 @@ netlink_vrf_change (struct nlmsghdr *h, struct rtattr *tb, const char *name) return; } - /*Pending: See if you want to optimize this code.. vrf, zvrf all have name */ - zvrf = vrf->info; + /* + * This is the only place that we get the actual kernel table_id + * being used. We need it to set the table_id of the routes + * we are passing to the kernel.... And to throw some totally + * awesome parties. that too. + */ + zvrf = (struct zebra_vrf *)vrf->info; zvrf->table_id = nl_table_id; - - vrf_add_update(vrf); } else //h->nlmsg_type == RTM_DELLINK { -- 2.39.5