From 421bb26a51b36cc7081aae7418cb932743bfc6d5 Mon Sep 17 00:00:00 2001 From: Mitesh Kanjariya Date: Wed, 21 Jun 2017 12:55:29 -0700 Subject: [PATCH] bgpd/zebra: fix bgpd crash happening in mac mobility code path Ticket: CM-16216 Review: CCR-6210 Unit-test: Manual Signed-off-by: Mitesh Kanjariya --- bgpd/bgp_evpn.c | 26 +++++++++++++------------- zebra/zebra_vxlan.c | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index fe311832a2..7a5e370bcf 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -347,9 +347,9 @@ static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn, s = zclient->obuf; stream_reset(s); - zclient_create_header( - s, add ? ZEBRA_REMOTE_MACIP_ADD : ZEBRA_REMOTE_MACIP_DEL, - bgp->vrf_id); + zclient_create_header(s, add ? ZEBRA_REMOTE_MACIP_ADD + : ZEBRA_REMOTE_MACIP_DEL, + bgp->vrf_id); stream_putl(s, vpn->vni); stream_put(s, &p->prefix.mac.octet, ETH_ALEN); /* Mac Addr */ /* IP address length and IP address, if any. */ @@ -400,9 +400,9 @@ static int bgp_zebra_send_remote_vtep(struct bgp *bgp, struct bgpevpn *vpn, s = zclient->obuf; stream_reset(s); - zclient_create_header( - s, add ? ZEBRA_REMOTE_VTEP_ADD : ZEBRA_REMOTE_VTEP_DEL, - bgp->vrf_id); + zclient_create_header(s, add ? ZEBRA_REMOTE_VTEP_ADD + : ZEBRA_REMOTE_VTEP_DEL, + bgp->vrf_id); stream_putl(s, vpn->vni); if (IS_EVPN_PREFIX_IPADDR_V4(p)) stream_put_in_addr(s, &p->prefix.ip.ipaddr_v4); @@ -472,7 +472,7 @@ static void add_mac_mobility_to_attr(u_int32_t seq_num, struct attr *attr) { struct ecommunity ecom_tmp; struct ecommunity_val eval; - struct ecommunity *ecom_mm; + u_int8_t *ecom_val_ptr; int i; u_int8_t *pnt; int type = 0; @@ -482,7 +482,7 @@ static void add_mac_mobility_to_attr(u_int32_t seq_num, struct attr *attr) encode_mac_mobility_extcomm(0, seq_num, &eval); /* Find current MM ecommunity */ - ecom_mm = NULL; + ecom_val_ptr = NULL; if (attr->ecommunity) { for (i = 0; i < attr->ecommunity->size; i++) { @@ -493,17 +493,17 @@ static void add_mac_mobility_to_attr(u_int32_t seq_num, struct attr *attr) if (type == ECOMMUNITY_ENCODE_EVPN && sub_type == ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY) { - ecom_mm = (struct ecommunity *) - attr->ecommunity->val - + (i * 8); + ecom_val_ptr = + (u_int8_t *)(attr->ecommunity->val + + (i * 8)); break; } } } /* Update the existing MM ecommunity */ - if (ecom_mm) { - memcpy(ecom_mm->val, eval.val, sizeof(char) * ECOMMUNITY_SIZE); + if (ecom_val_ptr) { + memcpy(ecom_val_ptr, eval.val, sizeof(char) * ECOMMUNITY_SIZE); } /* Add MM to existing */ else { diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index 7d265af309..542b66898b 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -2601,6 +2601,20 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp, } add = 0; /* This is an update of local interface. */ + } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { + /* + * If we have already learned the MAC as a remote sticky + * MAC, + * this is a operator error and we must log a warning + */ + if (CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY)) + zlog_warn( + "MAC %s is already learnt as a remote sticky mac behind VTEP %s VNI %d", + prefix_mac2str(macaddr, buf, + sizeof(buf)), + inet_ntoa(mac->fwd_info.r_vtep_ip), + zvni->vni); + return 0; } } -- 2.39.5