* head.
*/
rib_delete(afi, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0,
- &p, NULL, &nh, 0, 0, false);
+ &p, NULL, &nh, 0, 0, false, NULL);
rib_delete(afi, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0,
- 0, &p, NULL, &nh, 0, 0, false);
+ 0, &p, NULL, &nh, 0, 0, false, NULL);
if (IS_ZEBRA_DEBUG_RIB_DETAILED) {
char buf[PREFIX_STRLEN];
if (rtm->rtm_type == RTM_CHANGE)
rib_delete(AFI_IP, SAFI_UNICAST, VRF_DEFAULT,
ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, NULL,
- NULL, 0, 0, true);
+ NULL, 0, 0, true, NULL);
if (!nh.type) {
nh.type = NEXTHOP_TYPE_IPV4;
else
rib_delete(AFI_IP, SAFI_UNICAST, VRF_DEFAULT,
ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, NULL,
- &nh, 0, 0, true);
+ &nh, 0, 0, true, NULL);
}
if (dest.sa.sa_family == AF_INET6) {
/* One day we might have a debug section here like one in the
if (rtm->rtm_type == RTM_CHANGE)
rib_delete(AFI_IP6, SAFI_UNICAST, VRF_DEFAULT,
ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, NULL,
- NULL, 0, 0, true);
+ NULL, 0, 0, true, NULL);
if (!nh.type) {
nh.type = ifindex ? NEXTHOP_TYPE_IPV6_IFINDEX
else
rib_delete(AFI_IP6, SAFI_UNICAST, VRF_DEFAULT,
ZEBRA_ROUTE_KERNEL, 0, zebra_flags, &p, NULL,
- &nh, 0, 0, true);
+ &nh, 0, 0, true, NULL);
}
}
rib_delete(afi, SAFI_UNICAST, re->vrf_id, ZEBRA_ROUTE_TABLE,
re->table, re->flags, &p, NULL, re->nexthop,
- zebrad.rtm_table_default, re->metric, false);
+ zebrad.rtm_table_default, re->metric, false, NULL);
return 0;
}
extern void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type,
u_short instance, int flags, struct prefix *p,
struct prefix_ipv6 *src_p, const struct nexthop *nh,
- u_int32_t table_id, u_int32_t metric, bool fromkernel);
+ u_int32_t table_id, u_int32_t metric, bool fromkernel,
+ struct ethaddr *rmac);
extern struct route_entry *rib_match(afi_t afi, safi_t safi, vrf_id_t,
union g_addr *,
memcpy(&nh.gate, gate, sz);
rib_delete(afi, SAFI_UNICAST, vrf_id,
proto, 0, flags, &p, NULL, &nh,
- table, metric, true);
+ table, metric, true, NULL);
} else {
/* XXX: need to compare the entire list of nexthops
* here for NLM_F_APPEND stupidity */
rib_delete(afi, SAFI_UNICAST, vrf_id,
proto, 0, flags, &p, NULL, NULL,
- table, metric, true);
+ table, metric, true, NULL);
}
}
#include "zebra/zebra_rnh.h"
#include "zebra/interface.h"
#include "zebra/connected.h"
+#include "zebra/zebra_vxlan.h"
DEFINE_HOOK(rib_update, (struct route_node * rn, const char *reason),
(rn, reason))
void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type,
u_short instance, int flags, struct prefix *p,
struct prefix_ipv6 *src_p, const struct nexthop *nh,
- u_int32_t table_id, u_int32_t metric, bool fromkernel)
+ u_int32_t table_id, u_int32_t metric, bool fromkernel,
+ struct ethaddr *rmac)
{
struct route_table *table;
struct route_node *rn;
return;
}
+
+ if (CHECK_FLAG(flags, ZEBRA_FLAG_EVPN_TYPE2_ROUTE)) {
+ struct nexthop *tmp_nh;
+
+ for (ALL_NEXTHOPS(re->nexthop, tmp_nh)) {
+ struct ipaddr vtep_ip;
+
+ memset(&vtep_ip, 0, sizeof(struct ipaddr));
+ vtep_ip.ipa_type = IPADDR_V4;
+ memcpy(&(vtep_ip.ipaddr_v4),
+ &(tmp_nh->gate.ipv4),
+ sizeof(struct in_addr));
+ zebra_vxlan_evpn_vrf_route_del(re->vrf_id, rmac,
+ &vtep_ip, p);
+ }
+ }
rib_delnode(rn, same);
}
#include "zebra/zebra_l2.h"
#include "lib/json.h"
+DEFINE_MTYPE_STATIC(ZEBRA, HOST_PREFIX, "host prefix");
DEFINE_MTYPE_STATIC(ZEBRA, ZVNI, "VNI hash");
DEFINE_MTYPE_STATIC(ZEBRA, ZL3VNI, "L3 VNI hash");
DEFINE_MTYPE_STATIC(ZEBRA, ZVNI_VTEP, "VNI remote VTEP");
vty_out(vty, "%-15s %-17s %6d\n",
ipaddr2str(&(n->ip), buf2, sizeof(buf2)),
prefix_mac2str(&n->emac, buf1, sizeof(buf1)),
- n->nh_refcnt);
+ listcount(n->host_list));
} else {
json_object_string_add(json_nh, "vtep-ip",
inet_ntoa(n->r_vtep_ip));
json_object_string_add(json_nh, "rmac",
prefix_mac2str(&n->emac, buf1,
sizeof(buf1)));
- json_object_int_add(json_nh, "refCnt", n->nh_refcnt);
+ json_object_int_add(json_nh, "refCnt", listcount(n->host_list));
}
}
vty_out(vty, "%-17s %-21s %-6d\n",
prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)),
inet_ntoa(zrmac->fwd_info.r_vtep_ip),
- zrmac->rmac_refcnt);
+ listcount(zrmac->host_list));
} else {
json_object_string_add(json_rmac, "rmac",
prefix_mac2str(&zrmac->macaddr, buf,
sizeof(buf)));
json_object_string_add(json_rmac, "vtep-ip",
inet_ntoa(zrmac->fwd_info.r_vtep_ip));
- json_object_int_add(json_rmac, "refcnt", zrmac->rmac_refcnt);
+ json_object_int_add(json_rmac, "refcnt",
+ listcount(zrmac->host_list));
json_object_array_add(json, json_rmac);
}
}
zvni_del(zvni);
}
+static int is_host_present_in_host_list(struct list *list,
+ struct prefix *host)
+{
+ struct listnode *node = NULL;
+ struct prefix *p = NULL;
+
+ for (ALL_LIST_ELEMENTS_RO(list, node, p)) {
+ if (prefix_same(p, host))
+ return 1;
+ }
+ return 0;
+}
+
+static void host_list_add_host(struct list *list,
+ struct prefix *host)
+{
+ struct prefix *p = NULL;
+
+ p = XCALLOC(MTYPE_HOST_PREFIX, sizeof(struct prefix));
+ memcpy(p, host, sizeof(struct prefix));
+
+ listnode_add_sort(list, p);
+}
+
+static void host_list_delete_host(struct list *list,
+ struct prefix *host)
+{
+ struct listnode *node = NULL, *nnode = NULL, *node_to_del = NULL;
+ struct prefix *p = NULL;
+
+ for (ALL_LIST_ELEMENTS(list, node, nnode, p)) {
+ if (prefix_same(p, host)) {
+ XFREE(MTYPE_HOST_PREFIX, p);
+ node_to_del = node;
+ }
+ }
+
+ if (node_to_del)
+ list_delete_node(list, node_to_del);
+}
+
/*
* Look up MAC hash entry.
*/
zrmac = hash_get(zl3vni->rmac_table, &tmp_rmac, zl3vni_rmac_alloc);
assert(zrmac);
- zrmac->neigh_list = list_new();
- zrmac->neigh_list->cmp = (int (*)(void *, void *))neigh_cmp;
+ zrmac->host_list = list_new();
+ zrmac->host_list->cmp = (int (*)(void *, void *))prefix_cmp;
SET_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE);
SET_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE_RMAC);
}
/* handle rmac add */
-static int zebra_vxlan_l3vni_remote_rmac_add(zebra_l3vni_t *zl3vni,
- struct ethaddr *rmac,
- struct ipaddr *vtep_ip)
+static int zl3vni_remote_rmac_add(zebra_l3vni_t *zl3vni,
+ struct ethaddr *rmac,
+ struct ipaddr *vtep_ip,
+ struct prefix *host_prefix)
{
char buf[ETHER_ADDR_STRLEN];
char buf1[INET6_ADDRSTRLEN];
/* install rmac in kernel */
zl3vni_rmac_install(zl3vni, zrmac);
}
- zrmac->rmac_refcnt++;
+
+ if (!is_host_present_in_host_list(zrmac->host_list, host_prefix))
+ host_list_add_host(zrmac->host_list, host_prefix);
return 0;
}
/* handle rmac delete */
-static int zebra_vxlan_l3vni_remote_rmac_del(zebra_l3vni_t *zl3vni,
- struct ethaddr *rmac)
+static int zl3vni_remote_rmac_del(zebra_l3vni_t *zl3vni,
+ struct ethaddr *rmac,
+ struct prefix *host_prefix)
{
zebra_mac_t *zrmac = NULL;
if (!zrmac)
return -1;
- zrmac->rmac_refcnt--;
- if (!zrmac->rmac_refcnt) {
+ host_list_delete_host(zrmac->host_list, host_prefix);
+ if (list_isempty(zrmac->host_list)) {
/* uninstall from kernel */
zl3vni_rmac_uninstall(zl3vni, zrmac);
n = hash_get(zl3vni->nh_table, &tmp_n, zl3vni_nh_alloc);
assert(n);
+ n->host_list = list_new();
+ n->host_list->cmp = (int (*)(void *, void *))prefix_cmp;
+
memcpy(&n->emac, mac, ETH_ALEN);
SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE);
SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE_NH);
}
/* add remote vtep as a neigh entry */
-static int zebra_vxlan_l3vni_remote_nh_add(zebra_l3vni_t *zl3vni,
- struct ipaddr *vtep_ip,
- struct ethaddr *rmac)
+static int zl3vni_remote_nh_add(zebra_l3vni_t *zl3vni,
+ struct ipaddr *vtep_ip,
+ struct ethaddr *rmac,
+ struct prefix *host_prefix)
{
char buf[ETHER_ADDR_STRLEN];
char buf1[INET6_ADDRSTRLEN];
/* install the nh neigh in kernel */
zl3vni_nh_install(zl3vni, nh);
}
- nh->nh_refcnt++;
+
+ if (!is_host_present_in_host_list(nh->host_list, host_prefix))
+ host_list_add_host(nh->host_list, host_prefix);
+
return 0;
}
/* handle nh neigh delete */
-static int zebra_vxlan_l3vni_remote_nh_del(zebra_l3vni_t *zl3vni,
- struct ipaddr *vtep_ip)
+static int zl3vni_remote_nh_del(zebra_l3vni_t *zl3vni,
+ struct ipaddr *vtep_ip,
+ struct prefix *host_prefix)
{
zebra_neigh_t *nh = NULL;
if (!nh)
return -1;
- nh->nh_refcnt--;
- if (!nh->nh_refcnt) {
+ host_list_delete_host(nh->host_list, host_prefix);
+ if (list_isempty(nh->host_list)) {
/* uninstall from kernel */
zl3vni_nh_uninstall(zl3vni, nh);
/* handle evpn route in vrf table */
void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id,
struct ethaddr *rmac,
- struct ipaddr *ip)
+ struct ipaddr *vtep_ip,
+ struct prefix *host_prefix)
{
zebra_l3vni_t *zl3vni = NULL;
return;
/* add the next hop neighbor */
- zebra_vxlan_l3vni_remote_nh_add(zl3vni, ip, rmac);
+ zl3vni_remote_nh_add(zl3vni, vtep_ip, rmac, host_prefix);
/* add the rmac */
- zebra_vxlan_l3vni_remote_rmac_add(zl3vni, rmac, ip);
+ zl3vni_remote_rmac_add(zl3vni, rmac, vtep_ip, host_prefix);
}
/* handle evpn vrf route delete */
void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id,
struct ethaddr *rmac,
- struct ipaddr *ip)
+ struct ipaddr *vtep_ip,
+ struct prefix *host_prefix)
{
zebra_l3vni_t *zl3vni = NULL;
return;
/* delete the next hop entry */
- zebra_vxlan_l3vni_remote_nh_del(zl3vni, ip);
+ zl3vni_remote_nh_del(zl3vni, vtep_ip, host_prefix);
/* delete the rmac entry */
- zebra_vxlan_l3vni_remote_rmac_del(zl3vni, rmac);
+ zl3vni_remote_rmac_del(zl3vni, rmac, host_prefix);
}
extern void zebra_vxlan_ns_disable(struct zebra_ns *zns);
extern void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id,
struct ethaddr *rmac,
- struct ipaddr *ip);
+ struct ipaddr *ip,
+ struct prefix *host_prefix);
extern void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id,
struct ethaddr *rmac,
- struct ipaddr *ip);
+ struct ipaddr *vtep_ip,
+ struct prefix *host_prefix);
#endif /* _ZEBRA_VXLAN_H */
/* List of neigh associated with this mac */
struct list *neigh_list;
- /* Refcnt of number of mac-ips */
- u_int32_t rmac_refcnt;
+ /* list of hosts pointing to this remote RMAC */
+ struct list *host_list;
};
/*
/* Remote VTEP IP - applicable only for remote neighbors. */
struct in_addr r_vtep_ip;
- /* refcnt of remote mac-ip referring to a NH neigh */
- u_int32_t nh_refcnt;
+ /* list of hosts pointing to this remote NH entry */
+ struct list *host_list;
};
/*
zebra_vxlan_evpn_vrf_route_add(
vrf_id,
&api.rmac,
- &vtep_ip);
+ &vtep_ip,
+ &api.prefix);
}
break;
}
rib_delete(afi, api.safi, zvrf_id(zvrf), api.type, api.instance,
api.flags, &api.prefix, src_p, NULL, zvrf->table_id,
- api.metric, false);
+ api.metric, false, &api.rmac);
/* Stats */
switch (api.prefix.family) {
table_id = zvrf->table_id;
rib_delete(AFI_IP, api.safi, zvrf_id(zvrf), api.type, api.instance,
- api.flags, &p, NULL, NULL, table_id, 0, false);
+ api.flags, &p, NULL, NULL, table_id, 0, false, NULL);
client->v4_route_del_cnt++;
stream_failure:
src_pp = NULL;
rib_delete(AFI_IP6, api.safi, zvrf_id(zvrf), api.type, api.instance,
- api.flags, &p, src_pp, NULL, client->rtm_table, 0, false);
+ api.flags, &p, src_pp, NULL, client->rtm_table, 0, false,
+ NULL);
client->v6_route_del_cnt++;