From 4fe5171412a8d9b93d07495acfec37684f53018d Mon Sep 17 00:00:00 2001 From: Don Slice Date: Thu, 21 Apr 2016 17:12:26 -0700 Subject: [PATCH] zebra: Change interface handling so non-vrf aware protocols correctly handle them Changed interaction between zebra and routing protocols so that they correctly fill in the vrf_iflist even for vrfs they're not responsible for. In that way, when they get callbacks from zebra they can correctly understand whether they need to create them or not. Ticket: CM-10427 Signed-off-by: Don Slice Reviewed-by: --- ospfd/ospf_zebra.c | 8 +++---- zebra/redistribute.c | 57 +++++++++++++------------------------------- zebra/zserv.c | 48 +++++++++++++------------------------ 3 files changed, 36 insertions(+), 77 deletions(-) diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index 725bdeb4ca..49a35a11c0 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -95,8 +95,8 @@ ospf_interface_add (int command, struct zclient *zclient, zebra_size_t length, ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) - zlog_debug ("Zebra: interface add %s index %d flags %llx metric %d mtu %d", - ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, + zlog_debug ("Zebra: interface add %s[%u] index %d flags %llx metric %d mtu %d", + ifp->name, ifp->vrf_id, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu); assert (ifp->info); @@ -137,8 +137,8 @@ ospf_interface_delete (int command, struct zclient *zclient, if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) zlog_debug - ("Zebra: interface delete %s index %d flags %llx metric %d mtu %d", - ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu); + ("Zebra: interface delete %s[%u] index %d flags %llx metric %d mtu %d", + ifp->name, ifp->vrf_id, ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu); #ifdef HAVE_SNMP ospf_snmp_if_delete (ifp); diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 40fae82f7b..03310ad3f0 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -427,14 +427,13 @@ zebra_interface_add_update (struct interface *ifp) struct zserv *client; if (IS_ZEBRA_DEBUG_EVENT) - zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADD %s", ifp->name); + zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADD %s[%d]", ifp->name, ifp->vrf_id); for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) - if (client->ifinfo) - { - client->ifadd_cnt++; - zsend_interface_add (client, ifp); - } + { + client->ifadd_cnt++; + zsend_interface_add (client, ifp); + } } void @@ -447,11 +446,10 @@ zebra_interface_delete_update (struct interface *ifp) zlog_debug ("MESSAGE: ZEBRA_INTERFACE_DELETE %s", ifp->name); for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) - if (client->ifinfo) - { - client->ifdel_cnt++; - zsend_interface_delete (client, ifp); - } + { + client->ifdel_cnt++; + zsend_interface_delete (client, ifp); + } } /* Interface address addition. */ @@ -479,7 +477,7 @@ zebra_interface_address_add_update (struct interface *ifp, router_id_add_address(ifc); for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) - if (client->ifinfo && CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) + if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) { client->connected_rt_add_cnt++; zsend_interface_address (ZEBRA_INTERFACE_ADDRESS_ADD, client, ifp, ifc); @@ -508,7 +506,7 @@ zebra_interface_address_delete_update (struct interface *ifp, router_id_del_address(ifc); for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) - if (client->ifinfo && CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) + if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) { client->connected_rt_del_cnt++; zsend_interface_address (ZEBRA_INTERFACE_ADDRESS_DELETE, client, ifp, ifc); @@ -530,23 +528,11 @@ zebra_interface_vrf_update_del (struct interface *ifp, vrf_id_t new_vrf_id) for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) { - /* Skip clients not interested in both VRFs. */ - if (!vrf_bitmap_check (client->ifinfo, ifp->vrf_id) && - !vrf_bitmap_check (client->ifinfo, new_vrf_id)) - continue; - - if (!vrf_bitmap_check (client->ifinfo, new_vrf_id)) - { - /* Need to delete if the client is not interested in the new VRF. */ - zsend_interface_update (ZEBRA_INTERFACE_DOWN, client, ifp); - client->ifdel_cnt++; - zsend_interface_delete (client, ifp); - } - else if (vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) - { - /* Client is interested in both VRFs, inform about the change. */ - zsend_interface_vrf_update (client, ifp, new_vrf_id); - } + /* Need to delete if the client is not interested in the new VRF. */ + zsend_interface_update (ZEBRA_INTERFACE_DOWN, client, ifp); + client->ifdel_cnt++; + zsend_interface_delete (client, ifp); + zsend_interface_vrf_update (client, ifp, new_vrf_id); } } @@ -565,17 +551,6 @@ zebra_interface_vrf_update_add (struct interface *ifp, vrf_id_t old_vrf_id) for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) { - /* Skip clients interested in both VRFs - they would've got an Update. */ - if (vrf_bitmap_check (client->ifinfo, ifp->vrf_id) && - vrf_bitmap_check (client->ifinfo, old_vrf_id)) - continue; - - /* Skip clients not interested in the new VRF - they would've - * got a Delete. - */ - if (!vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) - continue; - /* Need to add if the client is interested in the new VRF. */ client->ifadd_cnt++; zsend_interface_add (client, ifp); diff --git a/zebra/zserv.c b/zebra/zserv.c index 6db922e4a6..3872d17409 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -197,10 +197,6 @@ zsend_interface_add (struct zserv *client, struct interface *ifp) { struct stream *s; - /* Check this client need interface information. */ - if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) - return 0; - s = client->obuf; stream_reset (s); @@ -217,10 +213,6 @@ zsend_interface_delete (struct zserv *client, struct interface *ifp) { struct stream *s; - /* Check this client need interface information. */ - if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) - return 0; - s = client->obuf; stream_reset (s); @@ -308,10 +300,6 @@ zsend_interface_address (int cmd, struct zserv *client, struct stream *s; struct prefix *p; - /* Check this client need interface information. */ - if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) - return 0; - s = client->obuf; stream_reset (s); @@ -356,10 +344,6 @@ zsend_interface_nbr_address (int cmd, struct zserv *client, struct stream *s; struct prefix *p; - /* Check this client need interface information. */ - if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) - return 0; - s = client->obuf; stream_reset (s); @@ -405,8 +389,7 @@ zebra_interface_nbr_address_add_update (struct interface *ifp, } for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) - if (client->ifinfo) - zsend_interface_nbr_address (ZEBRA_INTERFACE_NBR_ADDRESS_ADD, client, ifp, ifc); + zsend_interface_nbr_address (ZEBRA_INTERFACE_NBR_ADDRESS_ADD, client, ifp, ifc); } /* Interface address deletion. */ @@ -429,8 +412,7 @@ zebra_interface_nbr_address_delete_update (struct interface *ifp, } for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) - if (client->ifinfo) - zsend_interface_nbr_address (ZEBRA_INTERFACE_NBR_ADDRESS_DELETE, client, ifp, ifc); + zsend_interface_nbr_address (ZEBRA_INTERFACE_NBR_ADDRESS_DELETE, client, ifp, ifc); } /* Send addresses on interface to client */ @@ -559,10 +541,6 @@ zsend_interface_update (int cmd, struct zserv *client, struct interface *ifp) { struct stream *s; - /* Check this client need interface information. */ - if (! vrf_bitmap_check (client->ifinfo, ifp->vrf_id)) - return 0; - s = client->obuf; stream_reset (s); @@ -1085,22 +1063,28 @@ static int zread_interface_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf) { struct listnode *ifnode, *ifnnode; + vrf_iter_t iter; struct interface *ifp; + struct zebra_vrf *zvrf_iter; /* Interface information is needed. */ vrf_bitmap_set (client->ifinfo, zvrf->vrf_id); - for (ALL_LIST_ELEMENTS (vrf_iflist (zvrf->vrf_id), ifnode, ifnnode, ifp)) + for (iter = vrf_first (); iter != VRF_ITER_INVALID; iter = vrf_next (iter)) { - /* Skip pseudo interface. */ - if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) - continue; + zvrf_iter = vrf_iter2info (iter); + for (ALL_LIST_ELEMENTS (vrf_iflist (zvrf_iter->vrf_id), ifnode, ifnnode, ifp)) + { + /* Skip pseudo interface. */ + if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) + continue; - if (zsend_interface_add (client, ifp) < 0) - return -1; + if (zsend_interface_add (client, ifp) < 0) + return -1; - if (zsend_interface_addresses (client, ifp) < 0) - return -1; + if (zsend_interface_addresses (client, ifp) < 0) + return -1; + } } return 0; } -- 2.39.5