zebra: cleanup host prefix from rmac

Ticket:#2798406
Testing Done:

Signed-off-by: Chirag Shah <chirag@nvidia.com>
This commit is contained in:
Chirag Shah 2021-10-18 11:43:29 -07:00
parent 4a8e182a66
commit 3d43b95ce1
2 changed files with 15 additions and 49 deletions

View File

@ -124,9 +124,6 @@ struct zebra_mac {
/* List of neigh associated with this mac */ /* List of neigh associated with this mac */
struct list *neigh_list; struct list *neigh_list;
/* list of hosts pointing to this remote RMAC */
struct host_rb_tree_entry host_rb;
/* List of nexthop associated with this RMAC */ /* List of nexthop associated with this RMAC */
struct list *nh_list; struct list *nh_list;

View File

@ -398,46 +398,25 @@ static void zl3vni_print_nh(struct zebra_neigh *n, struct vty *vty,
static void zl3vni_print_rmac(struct zebra_mac *zrmac, struct vty *vty, static void zl3vni_print_rmac(struct zebra_mac *zrmac, struct vty *vty,
json_object *json) json_object *json)
{ {
char buf[INET6_ADDRSTRLEN];
char buf1[ETHER_ADDR_STRLEN];
char buf2[PREFIX_STRLEN];
struct listnode *node = NULL; struct listnode *node = NULL;
struct ipaddr *vtep = NULL; struct ipaddr *vtep = NULL;
json_object *json_nhs = NULL; json_object *json_nhs = NULL;
json_object *json_hosts = NULL;
struct host_rb_entry *hle;
if (!json) { if (!json) {
vty_out(vty, "MAC: %s\n", vty_out(vty, "MAC: %pEA\n", &zrmac->macaddr);
prefix_mac2str(&zrmac->macaddr, buf1, sizeof(buf1)));
vty_out(vty, " Remote VTEP: %pI4\n", vty_out(vty, " Remote VTEP: %pI4\n",
&zrmac->fwd_info.r_vtep_ip); &zrmac->fwd_info.r_vtep_ip);
vty_out(vty, " Refcount: %d\n", rb_host_count(&zrmac->host_rb));
vty_out(vty, " Prefixes:\n");
RB_FOREACH (hle, host_rb_tree_entry, &zrmac->host_rb)
vty_out(vty, " %pFX\n", &hle->p);
} else { } else {
json_hosts = json_object_new_array();
json_nhs = json_object_new_array(); json_nhs = json_object_new_array();
json_object_string_add( json_object_string_addf(json, "routerMac", "%pEA",
json, "routerMac", &zrmac->macaddr);
prefix_mac2str(&zrmac->macaddr, buf1, sizeof(buf1)));
json_object_string_addf(json, "vtepIp", "%pI4", json_object_string_addf(json, "vtepIp", "%pI4",
&zrmac->fwd_info.r_vtep_ip); &zrmac->fwd_info.r_vtep_ip);
for (ALL_LIST_ELEMENTS_RO(zrmac->nh_list, node, vtep)) { for (ALL_LIST_ELEMENTS_RO(zrmac->nh_list, node, vtep)) {
json_object_array_add(json_nhs, json_object_array_add(json_nhs, json_object_new_stringf(
json_object_new_string(ipaddr2str( "%pIA", vtep));
vtep, buf, sizeof(buf))));
} }
json_object_object_add(json, "nexthops", json_nhs); json_object_object_add(json, "nexthops", json_nhs);
json_object_int_add(json, "refCount",
rb_host_count(&zrmac->host_rb));
RB_FOREACH (hle, host_rb_tree_entry, &zrmac->host_rb)
json_object_array_add(
json_hosts,
json_object_new_string(prefix2str(
&hle->p, buf2, sizeof(buf2))));
json_object_object_add(json, "prefixList", json_hosts);
} }
} }
@ -1216,7 +1195,6 @@ static struct zebra_mac *zl3vni_rmac_add(struct zebra_l3vni *zl3vni,
zrmac = hash_get(zl3vni->rmac_table, &tmp_rmac, zl3vni_rmac_alloc); zrmac = hash_get(zl3vni->rmac_table, &tmp_rmac, zl3vni_rmac_alloc);
assert(zrmac); assert(zrmac);
RB_INIT(host_rb_tree_entry, &zrmac->host_rb);
zrmac->nh_list = list_new(); zrmac->nh_list = list_new();
zrmac->nh_list->cmp = (int (*)(void *, void *))l3vni_rmac_nh_list_cmp; zrmac->nh_list->cmp = (int (*)(void *, void *))l3vni_rmac_nh_list_cmp;
zrmac->nh_list->del = (void (*)(void *))l3vni_rmac_nh_free; zrmac->nh_list->del = (void (*)(void *))l3vni_rmac_nh_free;
@ -1233,14 +1211,7 @@ static struct zebra_mac *zl3vni_rmac_add(struct zebra_l3vni *zl3vni,
static int zl3vni_rmac_del(struct zebra_l3vni *zl3vni, struct zebra_mac *zrmac) static int zl3vni_rmac_del(struct zebra_l3vni *zl3vni, struct zebra_mac *zrmac)
{ {
struct zebra_mac *tmp_rmac; struct zebra_mac *tmp_rmac;
struct host_rb_entry *hle;
while (!RB_EMPTY(host_rb_tree_entry, &zrmac->host_rb)) {
hle = RB_ROOT(host_rb_tree_entry, &zrmac->host_rb);
RB_REMOVE(host_rb_tree_entry, &zrmac->host_rb, hle);
XFREE(MTYPE_HOST_PREFIX, hle);
}
/* free the list of nh list*/ /* free the list of nh list*/
list_delete(&zrmac->nh_list); list_delete(&zrmac->nh_list);
@ -1343,8 +1314,7 @@ static int zl3vni_rmac_uninstall(struct zebra_l3vni *zl3vni,
/* handle rmac add */ /* handle rmac add */
static int zl3vni_remote_rmac_add(struct zebra_l3vni *zl3vni, static int zl3vni_remote_rmac_add(struct zebra_l3vni *zl3vni,
const struct ethaddr *rmac, const struct ethaddr *rmac,
const struct ipaddr *vtep_ip, const struct ipaddr *vtep_ip)
const struct prefix *host_prefix)
{ {
struct zebra_mac *zrmac = NULL; struct zebra_mac *zrmac = NULL;
struct ipaddr *vtep = NULL; struct ipaddr *vtep = NULL;
@ -1356,8 +1326,8 @@ static int zl3vni_remote_rmac_add(struct zebra_l3vni *zl3vni,
zrmac = zl3vni_rmac_add(zl3vni, rmac); zrmac = zl3vni_rmac_add(zl3vni, rmac);
if (!zrmac) { if (!zrmac) {
zlog_debug( zlog_debug(
"Failed to add RMAC %pEA L3VNI %u Remote VTEP %pIA, prefix %pFX", "Failed to add RMAC %pEA L3VNI %u Remote VTEP %pIA",
rmac, zl3vni->vni, vtep_ip, host_prefix); rmac, zl3vni->vni, vtep_ip);
return -1; return -1;
} }
memset(&zrmac->fwd_info, 0, sizeof(zrmac->fwd_info)); memset(&zrmac->fwd_info, 0, sizeof(zrmac->fwd_info));
@ -1378,9 +1348,9 @@ static int zl3vni_remote_rmac_add(struct zebra_l3vni *zl3vni,
&vtep_ip->ipaddr_v4)) { &vtep_ip->ipaddr_v4)) {
if (IS_ZEBRA_DEBUG_VXLAN) if (IS_ZEBRA_DEBUG_VXLAN)
zlog_debug( zlog_debug(
"L3VNI %u Remote VTEP change(%pI4 -> %pIA) for RMAC %pEA, prefix %pFX", "L3VNI %u Remote VTEP change(%pI4 -> %pIA) for RMAC %pEA",
zl3vni->vni, &zrmac->fwd_info.r_vtep_ip, zl3vni->vni, &zrmac->fwd_info.r_vtep_ip,
vtep_ip, rmac, host_prefix); vtep_ip, rmac);
zrmac->fwd_info.r_vtep_ip = vtep_ip->ipaddr_v4; zrmac->fwd_info.r_vtep_ip = vtep_ip->ipaddr_v4;
@ -1400,8 +1370,7 @@ static int zl3vni_remote_rmac_add(struct zebra_l3vni *zl3vni,
/* handle rmac delete */ /* handle rmac delete */
static void zl3vni_remote_rmac_del(struct zebra_l3vni *zl3vni, static void zl3vni_remote_rmac_del(struct zebra_l3vni *zl3vni,
struct zebra_mac *zrmac, struct zebra_mac *zrmac,
struct ipaddr *vtep_ip, struct ipaddr *vtep_ip)
struct prefix *host_prefix)
{ {
struct ipaddr ipv4_vtep; struct ipaddr ipv4_vtep;
@ -1429,10 +1398,10 @@ static void zl3vni_remote_rmac_del(struct zebra_l3vni *zl3vni,
zrmac->fwd_info.r_vtep_ip = vtep->ipaddr_v4; zrmac->fwd_info.r_vtep_ip = vtep->ipaddr_v4;
if (IS_ZEBRA_DEBUG_VXLAN) if (IS_ZEBRA_DEBUG_VXLAN)
zlog_debug( zlog_debug(
"L3VNI %u Remote VTEP nh change(%pIA -> %pI4) for RMAC %pEA, prefix %pFX", "L3VNI %u Remote VTEP nh change(%pIA -> %pI4) for RMAC %pEA",
zl3vni->vni, &ipv4_vtep, zl3vni->vni, &ipv4_vtep,
&zrmac->fwd_info.r_vtep_ip, &zrmac->fwd_info.r_vtep_ip,
&zrmac->macaddr, host_prefix); &zrmac->macaddr);
/* install rmac in kernel */ /* install rmac in kernel */
zl3vni_rmac_install(zl3vni, zrmac); zl3vni_rmac_install(zl3vni, zrmac);
@ -2343,7 +2312,7 @@ void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id, const struct ethaddr *rmac,
* add the rmac - remote rmac to be installed is against the ipv4 * add the rmac - remote rmac to be installed is against the ipv4
* nexthop address * nexthop address
*/ */
zl3vni_remote_rmac_add(zl3vni, rmac, &ipv4_vtep, host_prefix); zl3vni_remote_rmac_add(zl3vni, rmac, &ipv4_vtep);
} }
/* handle evpn vrf route delete */ /* handle evpn vrf route delete */
@ -2370,7 +2339,7 @@ void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id,
/* delete the rmac entry */ /* delete the rmac entry */
if (zrmac) if (zrmac)
zl3vni_remote_rmac_del(zl3vni, zrmac, vtep_ip, host_prefix); zl3vni_remote_rmac_del(zl3vni, zrmac, vtep_ip);
} }
void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni, void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni,