diff --git a/zebra/zebra_evpn_mac.c b/zebra/zebra_evpn_mac.c index d02fd7a898..085dc9c661 100644 --- a/zebra/zebra_evpn_mac.c +++ b/zebra/zebra_evpn_mac.c @@ -2196,3 +2196,35 @@ int zebra_evpn_del_local_mac(zebra_evpn_t *zevpn, struct ethaddr *macaddr, return 0; } + +int zebra_evpn_mac_gw_macip_add(struct interface *ifp, zebra_evpn_t *zevpn, + struct ipaddr *ip, zebra_mac_t **macp, + struct ethaddr *macaddr, vlanid_t vlan_id) +{ + char buf[ETHER_ADDR_STRLEN]; + zebra_mac_t *mac; + + mac = zebra_evpn_mac_lookup(zevpn, macaddr); + if (!mac) { + mac = zebra_evpn_mac_add(zevpn, macaddr); + if (!mac) { + flog_err(EC_ZEBRA_MAC_ADD_FAILED, + "Failed to add MAC %s intf %s(%u) VID %u", + prefix_mac2str(macaddr, buf, sizeof(buf)), + ifp->name, ifp->ifindex, vlan_id); + return -1; + } + } + + /* Set "local" forwarding info. */ + SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL); + SET_FLAG(mac->flags, ZEBRA_MAC_AUTO); + SET_FLAG(mac->flags, ZEBRA_MAC_DEF_GW); + memset(&mac->fwd_info, 0, sizeof(mac->fwd_info)); + mac->fwd_info.local.ifindex = ifp->ifindex; + mac->fwd_info.local.vid = vlan_id; + + *macp = mac; + + return 0; +} diff --git a/zebra/zebra_evpn_mac.h b/zebra/zebra_evpn_mac.h index b6ee9d8f30..39aaf1fb30 100644 --- a/zebra/zebra_evpn_mac.h +++ b/zebra/zebra_evpn_mac.h @@ -252,6 +252,9 @@ int zebra_evpn_add_update_local_mac(struct zebra_vrf *zvrf, zebra_evpn_t *zevpn, bool dp_static); int zebra_evpn_del_local_mac(zebra_evpn_t *zevpn, struct ethaddr *macaddr, struct interface *ifp); +int zebra_evpn_mac_gw_macip_add(struct interface *ifp, zebra_evpn_t *zevpn, + struct ipaddr *ip, zebra_mac_t **macp, + struct ethaddr *macaddr, vlanid_t vlan_id); #ifdef __cplusplus } diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index 4b69ac2447..67c178dcbf 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -2251,25 +2251,10 @@ static int zevpn_gw_macip_add(struct interface *ifp, zebra_evpn_t *zevpn, vxl = &zif->l2info.vxl; - mac = zebra_evpn_mac_lookup(zevpn, macaddr); - if (!mac) { - mac = zebra_evpn_mac_add(zevpn, macaddr); - if (!mac) { - flog_err(EC_ZEBRA_MAC_ADD_FAILED, - "Failed to add MAC %s intf %s(%u) VID %u", - prefix_mac2str(macaddr, buf, sizeof(buf)), - ifp->name, ifp->ifindex, vxl->access_vlan); - return -1; - } - } - - /* Set "local" forwarding info. */ - SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL); - SET_FLAG(mac->flags, ZEBRA_MAC_AUTO); - SET_FLAG(mac->flags, ZEBRA_MAC_DEF_GW); - memset(&mac->fwd_info, 0, sizeof(mac->fwd_info)); - mac->fwd_info.local.ifindex = ifp->ifindex; - mac->fwd_info.local.vid = vxl->access_vlan; + if (zebra_evpn_mac_gw_macip_add(ifp, zevpn, ip, &mac, macaddr, + vxl->access_vlan) + != 0) + return -1; n = zevpn_neigh_lookup(zevpn, ip); if (!n) {