Skip to content

Commit

Permalink
bgpd,zebra,lib: bgp evpn vni macip into two tables
Browse files Browse the repository at this point in the history
Re-work the bgp vni table to use separately keyed tables for type2
routes.

So, with type2 routes, we have the main table keyed off of the IP and a
new MAC table keyed off of MACs.

By separating out the two, we are able to run path selection separately
for the neigh and mac. Keeping the two separate is also more in-line
with what happens in zebra (they are managed comptletely seperate).

With this change type2 routes go into each table like so:

```
Remote MAC-IP -> IP Table & MAC Table
Remote MAC -> MAC Table

Local MAC-IP -> IP Table
Local MAC -> MAC Table
```

The difference for local is necessary because we should not ever allow
multiple paths for a local MAC.

Also cleaned up the commands for querying the vni tables:

```
show bgp vni all type ...
show bgp vni VNI type ...

```

Old commands will be deprecated in a separate commit.

Signed-off-by: Stephen Worley <sworley@nvidia.com>
  • Loading branch information
sworleys committed Oct 11, 2022
1 parent 36bac85 commit 852d9f9
Show file tree
Hide file tree
Showing 12 changed files with 1,473 additions and 464 deletions.
858 changes: 605 additions & 253 deletions bgpd/bgp_evpn.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bgpd/bgp_evpn_mh.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ static int bgp_evpn_mh_route_delete(struct bgp *bgp, struct bgp_evpn_es *es,
struct prefix_rd *prd;

if (vpn) {
rt_table = vpn->route_table;
rt_table = vpn->ip_table;
prd = &vpn->prd;
} else {
rt_table = es->route_table;
Expand Down Expand Up @@ -960,7 +960,7 @@ static int bgp_evpn_type1_route_update(struct bgp *bgp, struct bgp_evpn_es *es,
bgp_evpn_type1_evi_route_extcomm_build(es, vpn, &attr);

/* First, create (or fetch) route node within the VNI. */
dest = bgp_node_get(vpn->route_table, (struct prefix *)p);
dest = bgp_node_get(vpn->ip_table, (struct prefix *)p);

/* Create or update route entry. */
ret = bgp_evpn_mh_route_update(bgp, es, vpn, afi, safi, dest,
Expand Down
92 changes: 73 additions & 19 deletions bgpd/bgp_evpn_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ struct bgpevpn {
*/
struct hash *remote_ip_hash;

/* Route table for EVPN routes for
/* Route tables for EVPN routes for
* this VNI. */
struct bgp_table *route_table;
struct bgp_table *ip_table;
struct bgp_table *mac_table;

/* RB tree of ES-EVIs */
struct bgp_es_evi_rb_head es_evi_rb_tree;
Expand Down Expand Up @@ -531,10 +532,10 @@ static inline void evpn_type1_prefix_global_copy(struct prefix_evpn *global_p,
/* EAD prefix in the global table doesn't include the VTEP-IP so
* we need to create a different copy for the VNI
*/
static inline struct prefix_evpn *evpn_type1_prefix_vni_copy(
struct prefix_evpn *vni_p,
const struct prefix_evpn *global_p,
struct in_addr originator_ip)
static inline struct prefix_evpn *
evpn_type1_prefix_vni_ip_copy(struct prefix_evpn *vni_p,
const struct prefix_evpn *global_p,
struct in_addr originator_ip)
{
memcpy(vni_p, global_p, sizeof(*vni_p));
vni_p->prefix.ead_addr.ip.ipa_type = IPADDR_V4;
Expand All @@ -543,37 +544,75 @@ static inline struct prefix_evpn *evpn_type1_prefix_vni_copy(
return vni_p;
}

static inline void
evpn_type2_prefix_global_copy(struct prefix_evpn *global_p,
const struct prefix_evpn *vni_p,
const struct ethaddr mac)
static inline void evpn_type2_prefix_global_copy(
struct prefix_evpn *global_p, const struct prefix_evpn *vni_p,
const struct ethaddr *mac, const struct ipaddr *ip)
{
memcpy(global_p, vni_p, sizeof(*global_p));
global_p->prefix.macip_addr.mac = mac;

if (mac)
global_p->prefix.macip_addr.mac = *mac;

if (ip)
global_p->prefix.macip_addr.ip = *ip;
}

static inline void
evpn_type2_prefix_vni_copy(struct prefix_evpn *vni_p,
const struct prefix_evpn *global_p)
evpn_type2_prefix_vni_ip_copy(struct prefix_evpn *vni_p,
const struct prefix_evpn *global_p)
{
memcpy(vni_p, global_p, sizeof(*vni_p));
memset(&vni_p->prefix.macip_addr.mac, 0, sizeof(struct ethaddr));
}

static inline void
evpn_type2_prefix_vni_mac_copy(struct prefix_evpn *vni_p,
const struct prefix_evpn *global_p)
{
memcpy(vni_p, global_p, sizeof(*vni_p));
memset(&vni_p->prefix.macip_addr.ip, 0, sizeof(struct ipaddr));
}

/* Get MAC of path_info prefix */
static inline struct ethaddr *
evpn_type2_path_info_get_mac(const struct bgp_path_info *local_pi)
{
assert(local_pi->extra);
return &local_pi->extra->mac;
return &local_pi->extra->vni_info.mac;
}

/* Get IP of path_info prefix */
static inline struct ipaddr *
evpn_type2_path_info_get_ip(const struct bgp_path_info *local_pi)
{
assert(local_pi->extra);
return &local_pi->extra->vni_info.ip;
}

/* Set MAC of path_info prefix */
static inline void evpn_type2_path_info_set_mac(struct bgp_path_info *local_pi,
const struct ethaddr mac)
{
assert(local_pi->extra);
local_pi->extra->mac = mac;
local_pi->extra->vni_info.mac = mac;
}

/* Set IP of path_info prefix */
static inline void evpn_type2_path_info_set_ip(struct bgp_path_info *local_pi,
const struct ipaddr ip)
{
assert(local_pi->extra);
local_pi->extra->vni_info.ip = ip;
}

/* Is the IP empty for the RT's dest? */
static inline bool is_evpn_type2_dest_ipaddr_none(const struct bgp_dest *dest)
{
const struct prefix_evpn *evp =
(const struct prefix_evpn *)bgp_dest_get_prefix(dest);

assert(evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE);
return is_evpn_prefix_ipaddr_none(evp);
}

static inline int evpn_default_originate_set(struct bgp *bgp, afi_t afi,
Expand Down Expand Up @@ -676,13 +715,28 @@ bgp_evpn_global_node_lookup(struct bgp_table *table, afi_t afi, safi_t safi,
struct prefix_rd *prd,
const struct bgp_path_info *local_pi);
extern struct bgp_dest *
bgp_evpn_vni_node_get(struct bgp_table *const table,
const struct prefix_evpn *evp,
bgp_evpn_vni_ip_node_get(struct bgp_table *const table,
const struct prefix_evpn *evp,
const struct bgp_path_info *parent_pi);
extern struct bgp_dest *
bgp_evpn_vni_ip_node_lookup(const struct bgp_table *const table,
const struct prefix_evpn *evp,
const struct bgp_path_info *parent_pi);
extern struct bgp_dest *
bgp_evpn_vni_mac_node_get(struct bgp_table *const table,
const struct prefix_evpn *evp,
const struct bgp_path_info *parent_pi);
extern struct bgp_dest *
bgp_evpn_vni_mac_node_lookup(const struct bgp_table *const table,
const struct prefix_evpn *evp,
const struct bgp_path_info *parent_pi);
extern struct bgp_dest *
bgp_evpn_vni_node_get(struct bgpevpn *vpn, const struct prefix_evpn *p,
const struct bgp_path_info *parent_pi);
extern struct bgp_dest *
bgp_evpn_vni_node_lookup(const struct bgp_table *const table,
const struct prefix_evpn *evp,
bgp_evpn_vni_node_lookup(const struct bgpevpn *vpn, const struct prefix_evpn *p,
const struct bgp_path_info *parent_pi);

extern void bgp_evpn_import_route_in_vrfs(struct bgp_path_info *pi, int import);
extern void bgp_evpn_update_type2_route_entry(struct bgp *bgp,
struct bgpevpn *vpn,
Expand Down
Loading

0 comments on commit 852d9f9

Please sign in to comment.