mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-04-29 02:37:00 +00:00
bgpd: EVPN route handling
Core EVPN route handling functionality. This includes support for the following: - interface with zebra to learn about local VNIs and MACIPs as well as to install remote VTEPs (per VNI) and remote MACIPs - create/update/delete EVPN type-2 and type-3 routes - attribute creation, route selection and install - route handling per VNI and for the global routing table - parsing of received EVPN routes and handling by route type - encoding attributes for EVPN routes and EVPN prefix creation (for Updates) Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com> Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Daniel Walton <dwalton@cumulusnetworks.com>
This commit is contained in:
parent
0ee26848f3
commit
128ea8abbd
@ -2136,6 +2136,9 @@ bgp_attr_ext_communities (struct bgp_attr_parser_args *args)
|
||||
|
||||
attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES);
|
||||
|
||||
/* Extract MAC mobility sequence number, if any. */
|
||||
attr->extra->mm_seqnum = bgp_attr_mac_mobility_seqnum (attr);
|
||||
|
||||
return BGP_ATTR_PARSE_PROCEED;
|
||||
}
|
||||
|
||||
@ -2957,9 +2960,11 @@ bgp_packet_mpattr_prefix (struct stream *s, afi_t afi, safi_t safi,
|
||||
stream_put (s, prd->val, 8);
|
||||
stream_put (s, &p->u.prefix, PSIZE (p->prefixlen));
|
||||
}
|
||||
else if (safi == SAFI_EVPN)
|
||||
else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
|
||||
{
|
||||
bgp_packet_mpattr_route_type_5(s, p, prd, label, attr);
|
||||
/* EVPN prefix - contents depend on type */
|
||||
bgp_evpn_encode_prefix (s, p, prd, label, attr,
|
||||
addpath_encode, addpath_tx_id);
|
||||
}
|
||||
else if (safi == SAFI_LABELED_UNICAST)
|
||||
{
|
||||
@ -2976,6 +2981,8 @@ bgp_packet_mpattr_prefix_size (afi_t afi, safi_t safi, struct prefix *p)
|
||||
int size = PSIZE (p->prefixlen);
|
||||
if (safi == SAFI_MPLS_VPN)
|
||||
size += 88;
|
||||
else if (afi == AFI_L2VPN && safi == SAFI_EVPN)
|
||||
size += 232; // TODO: Maximum possible for type-2, type-3 and type-5
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -140,6 +140,9 @@ struct attr_extra
|
||||
/* MP Nexthop preference */
|
||||
u_char mp_nexthop_prefer_global;
|
||||
|
||||
/* Static MAC for EVPN */
|
||||
u_char sticky;
|
||||
|
||||
/* route tag */
|
||||
route_tag_t tag;
|
||||
|
||||
@ -157,6 +160,9 @@ struct attr_extra
|
||||
#endif
|
||||
/* EVPN */
|
||||
struct overlay_index evpn_overlay;
|
||||
|
||||
/* EVPN MAC Mobility sequence number, if any. */
|
||||
u_int32_t mm_seqnum;
|
||||
};
|
||||
|
||||
/* BGP core attribute structure. */
|
||||
@ -333,4 +339,10 @@ bgp_rmap_nhop_changed(u_int32_t out_rmap_flags, u_int32_t in_rmap_flags)
|
||||
CHECK_FLAG(in_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED)) ? 1 : 0);
|
||||
}
|
||||
|
||||
static inline u_int32_t
|
||||
mac_mobility_seqnum (struct attr *attr)
|
||||
{
|
||||
return (attr && attr->extra) ? attr->extra->mm_seqnum : 0;
|
||||
}
|
||||
|
||||
#endif /* _QUAGGA_BGP_ATTR_H */
|
||||
|
@ -33,21 +33,23 @@
|
||||
#include "bgpd/bgp_attr_evpn.h"
|
||||
#include "bgpd/bgp_ecommunity.h"
|
||||
#include "bgpd/bgp_evpn.h"
|
||||
#include "bgpd/bgp_evpn_private.h"
|
||||
|
||||
void bgp_add_routermac_ecom(struct attr *attr, struct ethaddr *routermac)
|
||||
{
|
||||
struct ecommunity_val routermac_ecom;
|
||||
struct ecommunity_val routermac_ecom;
|
||||
|
||||
if (attr->extra) {
|
||||
memset(&routermac_ecom, 0, sizeof(struct ecommunity_val));
|
||||
routermac_ecom.val[0] = ECOMMUNITY_ENCODE_EVPN;
|
||||
routermac_ecom.val[1] = ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC;
|
||||
memcpy(&routermac_ecom.val[2], routermac->octet, ETHER_ADDR_LEN);
|
||||
if (!attr->extra->ecommunity)
|
||||
attr->extra->ecommunity = ecommunity_new();
|
||||
ecommunity_add_val(attr->extra->ecommunity, &routermac_ecom);
|
||||
ecommunity_str (attr->extra->ecommunity);
|
||||
}
|
||||
if (attr->extra)
|
||||
{
|
||||
memset(&routermac_ecom, 0, sizeof(struct ecommunity_val));
|
||||
routermac_ecom.val[0] = ECOMMUNITY_ENCODE_EVPN;
|
||||
routermac_ecom.val[1] = ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC;
|
||||
memcpy(&routermac_ecom.val[2], routermac->octet, ETHER_ADDR_LEN);
|
||||
if (!attr->extra->ecommunity)
|
||||
attr->extra->ecommunity = ecommunity_new();
|
||||
ecommunity_add_val(attr->extra->ecommunity, &routermac_ecom);
|
||||
ecommunity_str (attr->extra->ecommunity);
|
||||
}
|
||||
}
|
||||
|
||||
/* converts to an esi
|
||||
@ -57,85 +59,131 @@ void bgp_add_routermac_ecom(struct attr *attr, struct ethaddr *routermac)
|
||||
*/
|
||||
int str2esi(const char *str, struct eth_segment_id *id)
|
||||
{
|
||||
unsigned int a[ESI_LEN];
|
||||
int i;
|
||||
unsigned int a[ESI_LEN];
|
||||
int i;
|
||||
|
||||
if (!str)
|
||||
return 0;
|
||||
if (sscanf (str, "%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x",
|
||||
a + 0, a + 1, a + 2, a + 3, a + 4, a + 5,
|
||||
a + 6, a + 7, a + 8, a + 9) != ESI_LEN)
|
||||
{
|
||||
/* error in incoming str length */
|
||||
return 0;
|
||||
}
|
||||
/* valid mac address */
|
||||
if (!id)
|
||||
return 1;
|
||||
for (i = 0; i < ESI_LEN; ++i)
|
||||
id->val[i] = a[i] & 0xff;
|
||||
return 1;
|
||||
if (!str)
|
||||
return 0;
|
||||
if (sscanf (str, "%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x",
|
||||
a + 0, a + 1, a + 2, a + 3, a + 4, a + 5,
|
||||
a + 6, a + 7, a + 8, a + 9) != ESI_LEN)
|
||||
{
|
||||
/* error in incoming str length */
|
||||
return 0;
|
||||
}
|
||||
/* valid mac address */
|
||||
if (!id)
|
||||
return 1;
|
||||
for (i = 0; i < ESI_LEN; ++i)
|
||||
id->val[i] = a[i] & 0xff;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *esi2str(struct eth_segment_id *id)
|
||||
{
|
||||
char *ptr;
|
||||
u_char *val;
|
||||
char *ptr;
|
||||
u_char *val;
|
||||
|
||||
if (!id)
|
||||
return NULL;
|
||||
if (!id)
|
||||
return NULL;
|
||||
|
||||
val = id->val;
|
||||
ptr = (char *)XMALLOC(MTYPE_TMP, (ESI_LEN * 2 + ESI_LEN - 1 + 1) * sizeof(char));
|
||||
val = id->val;
|
||||
ptr = (char *)XMALLOC(MTYPE_TMP, (ESI_LEN * 2 + ESI_LEN - 1 + 1) * sizeof(char));
|
||||
|
||||
snprintf(ptr, (ESI_LEN * 2 + ESI_LEN - 1 + 1),
|
||||
"%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
val[0], val[1], val[2], val[3], val[4],
|
||||
val[5], val[6], val[7], val[8], val[9]);
|
||||
snprintf(ptr, (ESI_LEN * 2 + ESI_LEN - 1 + 1),
|
||||
"%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
val[0], val[1], val[2], val[3], val[4],
|
||||
val[5], val[6], val[7], val[8], val[9]);
|
||||
|
||||
return ptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
char *ecom_mac2str(char *ecom_mac)
|
||||
{
|
||||
char *en;
|
||||
char *en;
|
||||
|
||||
en = ecom_mac;
|
||||
en += 2;
|
||||
return prefix_mac2str((struct ethaddr *)en, NULL, 0);
|
||||
en = ecom_mac;
|
||||
en += 2;
|
||||
|
||||
return prefix_mac2str((struct ethaddr *)en, NULL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Fetch and return the sequence number from MAC Mobility extended
|
||||
* community, if present, else 0.
|
||||
*/
|
||||
u_int32_t
|
||||
bgp_attr_mac_mobility_seqnum (struct attr *attr)
|
||||
{
|
||||
struct ecommunity *ecom;
|
||||
int i;
|
||||
|
||||
ecom = attr->extra->ecommunity;
|
||||
if (!ecom || !ecom->size)
|
||||
return 0;
|
||||
|
||||
/* If there is a MAC Mobility extended community, return its
|
||||
* sequence number.
|
||||
* TODO: RFC is silent on handling of multiple MAC mobility extended
|
||||
* communities for the same route. We will bail out upon the first
|
||||
* one.
|
||||
*/
|
||||
for (i = 0; i < ecom->size; i++)
|
||||
{
|
||||
u_char *pnt;
|
||||
u_char type, sub_type;
|
||||
u_int32_t seq_num;
|
||||
|
||||
pnt = (ecom->val + (i * ECOMMUNITY_SIZE));
|
||||
type = *pnt++;
|
||||
sub_type = *pnt++;
|
||||
if (!(type == ECOMMUNITY_ENCODE_EVPN &&
|
||||
sub_type == ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY))
|
||||
continue;
|
||||
pnt++;
|
||||
pnt++;
|
||||
seq_num = (*pnt++ << 24);
|
||||
seq_num |= (*pnt++ << 16);
|
||||
seq_num |= (*pnt++ << 8);
|
||||
seq_num |= (*pnt++);
|
||||
|
||||
return seq_num;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* dst prefix must be AF_INET or AF_INET6 prefix, to forge EVPN prefix */
|
||||
extern int
|
||||
bgp_build_evpn_prefix(int evpn_type, uint32_t eth_tag, struct prefix *dst)
|
||||
{
|
||||
struct evpn_addr *p_evpn_p;
|
||||
struct prefix p2;
|
||||
struct prefix *src = &p2;
|
||||
struct evpn_addr *p_evpn_p;
|
||||
struct prefix p2;
|
||||
struct prefix *src = &p2;
|
||||
|
||||
if (!dst || dst->family == 0)
|
||||
return -1;
|
||||
/* store initial prefix in src */
|
||||
prefix_copy(src, dst);
|
||||
memset(dst, 0, sizeof(struct prefix));
|
||||
p_evpn_p = &(dst->u.prefix_evpn);
|
||||
dst->family = AF_ETHERNET;
|
||||
p_evpn_p->route_type = evpn_type;
|
||||
if (evpn_type == EVPN_IP_PREFIX) {
|
||||
p_evpn_p->eth_tag = eth_tag;
|
||||
p_evpn_p->ip_prefix_length = p2.prefixlen;
|
||||
if (src->family == AF_INET) {
|
||||
if (!dst || dst->family == 0)
|
||||
return -1;
|
||||
/* store initial prefix in src */
|
||||
prefix_copy(src, dst);
|
||||
memset(dst, 0, sizeof(struct prefix));
|
||||
p_evpn_p = &(dst->u.prefix_evpn);
|
||||
dst->family = AF_ETHERNET;
|
||||
p_evpn_p->route_type = evpn_type;
|
||||
if (evpn_type == BGP_EVPN_IP_PREFIX_ROUTE) {
|
||||
p_evpn_p->eth_tag = eth_tag;
|
||||
p_evpn_p->ip_prefix_length = p2.prefixlen;
|
||||
if (src->family == AF_INET) {
|
||||
SET_IPADDR_V4 (&p_evpn_p->ip);
|
||||
memcpy(&p_evpn_p->ip.ipaddr_v4, &src->u.prefix4,
|
||||
sizeof(struct in_addr));
|
||||
dst->prefixlen = (u_char) PREFIX_LEN_ROUTE_TYPE_5_IPV4;
|
||||
} else {
|
||||
memcpy(&p_evpn_p->ip.ipaddr_v4, &src->u.prefix4,
|
||||
sizeof(struct in_addr));
|
||||
dst->prefixlen = (u_char) PREFIX_LEN_ROUTE_TYPE_5_IPV4;
|
||||
} else {
|
||||
SET_IPADDR_V6 (&p_evpn_p->ip);
|
||||
memcpy(&p_evpn_p->ip.ipaddr_v6, &src->u.prefix6,
|
||||
sizeof(struct in6_addr));
|
||||
dst->prefixlen = (u_char) PREFIX_LEN_ROUTE_TYPE_5_IPV6;
|
||||
}
|
||||
} else
|
||||
return -1;
|
||||
return 0;
|
||||
memcpy(&p_evpn_p->ip.ipaddr_v6, &src->u.prefix6,
|
||||
sizeof(struct in6_addr));
|
||||
dst->prefixlen = (u_char) PREFIX_LEN_ROUTE_TYPE_5_IPV6;
|
||||
}
|
||||
} else
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,31 +22,37 @@
|
||||
#define _QUAGGA_BGP_ATTR_EVPN_H
|
||||
|
||||
/* value of first byte of ESI */
|
||||
#define ESI_TYPE_ARBITRARY 0 /* */
|
||||
#define ESI_TYPE_LACP 1 /* <> */
|
||||
#define ESI_TYPE_BRIDGE 2 /* <Root bridge Mac-6B>:<Root Br Priority-2B>:00 */
|
||||
#define ESI_TYPE_MAC 3 /* <Syst Mac Add-6B>:<Local Discriminator Value-3B> */
|
||||
#define ESI_TYPE_ROUTER 4 /* <RouterId-4B>:<Local Discriminator Value-4B> */
|
||||
#define ESI_TYPE_AS 5 /* <AS-4B>:<Local Discriminator Value-4B> */
|
||||
#define ESI_TYPE_ARBITRARY 0 /* */
|
||||
#define ESI_TYPE_LACP 1 /* <> */
|
||||
#define ESI_TYPE_BRIDGE 2 /* <Root bridge Mac-6B>:<Root Br Priority-2B>:00 */
|
||||
#define ESI_TYPE_MAC 3 /* <Syst Mac Add-6B>:<Local Discriminator Value-3B> */
|
||||
#define ESI_TYPE_ROUTER 4 /* <RouterId-4B>:<Local Discriminator Value-4B> */
|
||||
#define ESI_TYPE_AS 5 /* <AS-4B>:<Local Discriminator Value-4B> */
|
||||
|
||||
|
||||
#define MAX_ESI {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}
|
||||
#define ESI_LEN 10
|
||||
|
||||
#define MAX_ET 0xffffffff
|
||||
|
||||
u_long eth_tag_id;
|
||||
struct attr;
|
||||
|
||||
struct eth_segment_id {
|
||||
u_char val[ESI_LEN];
|
||||
struct eth_segment_id
|
||||
{
|
||||
u_char val[ESI_LEN];
|
||||
};
|
||||
|
||||
union gw_addr {
|
||||
struct in_addr ipv4;
|
||||
struct in6_addr ipv6;
|
||||
union gw_addr
|
||||
{
|
||||
struct in_addr ipv4;
|
||||
struct in6_addr ipv6;
|
||||
};
|
||||
|
||||
struct bgp_route_evpn {
|
||||
struct eth_segment_id eth_s_id;
|
||||
union gw_addr gw_ip;
|
||||
struct bgp_route_evpn
|
||||
{
|
||||
struct eth_segment_id eth_s_id;
|
||||
union gw_addr gw_ip;
|
||||
};
|
||||
|
||||
extern int str2esi(const char *str, struct eth_segment_id *id);
|
||||
@ -55,5 +61,9 @@ extern char *ecom_mac2str(char *ecom_mac);
|
||||
|
||||
extern void bgp_add_routermac_ecom(struct attr *attr, struct ethaddr *routermac);
|
||||
extern int bgp_build_evpn_prefix(int type, uint32_t eth_tag,
|
||||
struct prefix *dst);
|
||||
#endif /* _QUAGGA_BGP_ATTR_EVPN_H */
|
||||
struct prefix *dst);
|
||||
|
||||
extern u_int32_t
|
||||
bgp_attr_mac_mobility_seqnum (struct attr *attr);
|
||||
|
||||
#endif /* _QUAGGA_BGP_ATTR_EVPN_H */
|
||||
|
@ -32,12 +32,15 @@
|
||||
#define ECOMMUNITY_ROUTE_TARGET 0x02
|
||||
#define ECOMMUNITY_SITE_ORIGIN 0x03
|
||||
|
||||
/* Low-order octet of the Extended Communities type field for EVPN types */
|
||||
#define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY 0x00
|
||||
#define ECOMMUNITY_EVPN_SUBTYPE_ESI_LABEL 0x01
|
||||
#define ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT 0x02
|
||||
#define ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC 0x03
|
||||
#define ECOMMUNITY_EVPN_SUBTYPE_DEF_GW 0x0d
|
||||
|
||||
#define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY 0x01
|
||||
|
||||
/* Low-order octet of the Extended Communities type field for OPAQUE types */
|
||||
#define ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP 0x0c
|
||||
|
||||
|
2465
bgpd/bgp_evpn.c
2465
bgpd/bgp_evpn.c
File diff suppressed because it is too large
Load Diff
@ -21,14 +21,31 @@
|
||||
#ifndef _QUAGGA_BGP_EVPN_H
|
||||
#define _QUAGGA_BGP_EVPN_H
|
||||
|
||||
extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
|
||||
struct bgp_nlri *packet, int withdraw);
|
||||
#include "vxlan.h"
|
||||
|
||||
extern void
|
||||
bgp_packet_mpattr_route_type_5(struct stream *s,
|
||||
struct prefix *p, struct prefix_rd *prd,
|
||||
mpls_label_t *label, struct attr *attr);
|
||||
|
||||
bgp_evpn_encode_prefix (struct stream *s, struct prefix *p,
|
||||
struct prefix_rd *prd, mpls_label_t *label,
|
||||
struct attr *attr, int addpath_encode,
|
||||
u_int32_t addpath_tx_id);
|
||||
extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
|
||||
struct bgp_nlri *packet, int withdraw);
|
||||
extern int
|
||||
bgp_evpn_import_route (struct bgp *bgp, afi_t afi, safi_t safi,
|
||||
struct prefix *p, struct bgp_info *ri);
|
||||
extern int
|
||||
bgp_evpn_unimport_route (struct bgp *bgp, afi_t afi, safi_t safi,
|
||||
struct prefix *p, struct bgp_info *ri);
|
||||
extern int
|
||||
bgp_evpn_local_macip_del (struct bgp *bgp, vni_t vni,
|
||||
struct ethaddr *mac, struct ipaddr *ip);
|
||||
extern int
|
||||
bgp_evpn_local_macip_add (struct bgp *bgp, vni_t vni,
|
||||
struct ethaddr *mac, struct ipaddr *ip);
|
||||
extern int
|
||||
bgp_evpn_local_vni_del (struct bgp *bgp, vni_t vni);
|
||||
extern int
|
||||
bgp_evpn_local_vni_add (struct bgp *bgp, vni_t vni, struct in_addr originator_ip);
|
||||
extern void
|
||||
bgp_evpn_cleanup_on_disable (struct bgp *bgp);
|
||||
extern void
|
||||
@ -36,13 +53,4 @@ bgp_evpn_cleanup (struct bgp *bgp);
|
||||
extern void
|
||||
bgp_evpn_init (struct bgp *bgp);
|
||||
|
||||
/* EVPN route types as per RFC7432 and
|
||||
* as per draft-ietf-bess-evpn-prefix-advertisement-02
|
||||
*/
|
||||
#define EVPN_ETHERNET_AUTO_DISCOVERY 1
|
||||
#define EVPN_MACIP_ADVERTISEMENT 2
|
||||
#define EVPN_INCLUSIVE_MULTICAST_ETHERNET_TAG 3
|
||||
#define EVPN_ETHERNET_SEGMENT 4
|
||||
#define EVPN_IP_PREFIX 5
|
||||
|
||||
#endif /* _QUAGGA_BGP_EVPN_H */
|
||||
#endif /* _QUAGGA_BGP_EVPN_H */
|
||||
|
@ -94,4 +94,131 @@ struct irt_node
|
||||
struct list *vnis;
|
||||
};
|
||||
|
||||
#define RT_TYPE_IMPORT 1
|
||||
#define RT_TYPE_EXPORT 2
|
||||
#define RT_TYPE_BOTH 3
|
||||
|
||||
static inline int
|
||||
is_vni_configured (struct bgpevpn *vpn)
|
||||
{
|
||||
return (CHECK_FLAG (vpn->flags, VNI_FLAG_CFGD));
|
||||
}
|
||||
|
||||
static inline int
|
||||
is_vni_live (struct bgpevpn *vpn)
|
||||
{
|
||||
return (CHECK_FLAG (vpn->flags, VNI_FLAG_LIVE));
|
||||
}
|
||||
|
||||
static inline int
|
||||
is_rd_configured (struct bgpevpn *vpn)
|
||||
{
|
||||
return (CHECK_FLAG (vpn->flags, VNI_FLAG_RD_CFGD));
|
||||
}
|
||||
|
||||
static inline int
|
||||
bgp_evpn_rd_matches_existing (struct bgpevpn *vpn, struct prefix_rd *prd)
|
||||
{
|
||||
return(memcmp (&vpn->prd.val, prd->val, ECOMMUNITY_SIZE) == 0);
|
||||
}
|
||||
|
||||
static inline int
|
||||
is_import_rt_configured (struct bgpevpn *vpn)
|
||||
{
|
||||
return (CHECK_FLAG (vpn->flags, VNI_FLAG_IMPRT_CFGD));
|
||||
}
|
||||
|
||||
static inline int
|
||||
is_export_rt_configured (struct bgpevpn *vpn)
|
||||
{
|
||||
return (CHECK_FLAG (vpn->flags, VNI_FLAG_EXPRT_CFGD));
|
||||
}
|
||||
|
||||
static inline int
|
||||
is_vni_param_configured (struct bgpevpn *vpn)
|
||||
{
|
||||
return (is_rd_configured (vpn) ||
|
||||
is_import_rt_configured (vpn) ||
|
||||
is_export_rt_configured (vpn));
|
||||
}
|
||||
|
||||
static inline void
|
||||
vni2label (vni_t vni, mpls_label_t *label)
|
||||
{
|
||||
u_char *tag = (u_char *) label;
|
||||
tag[0] = (vni >> 16) & 0xFF;
|
||||
tag[1] = (vni >> 8) & 0xFF;
|
||||
tag[2] = vni & 0xFF;
|
||||
}
|
||||
|
||||
static inline vni_t
|
||||
label2vni (mpls_label_t *label)
|
||||
{
|
||||
u_char *tag = (u_char *) label;
|
||||
vni_t vni;
|
||||
|
||||
vni = ((u_int32_t) *tag++ << 16);
|
||||
vni |= (u_int32_t) *tag++ << 8;
|
||||
vni |= (u_int32_t) (*tag & 0xFF);
|
||||
|
||||
return vni;
|
||||
}
|
||||
|
||||
static inline void
|
||||
encode_mac_mobility_extcomm (int static_mac, u_int32_t seq,
|
||||
struct ecommunity_val *eval)
|
||||
{
|
||||
memset (eval, 0, sizeof (*eval));
|
||||
eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
|
||||
eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY;
|
||||
if (static_mac)
|
||||
eval->val[2] = ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY;
|
||||
eval->val[4] = (seq >> 24) & 0xff;
|
||||
eval->val[5] = (seq >> 16) & 0xff;
|
||||
eval->val[6] = (seq >> 8) & 0xff;
|
||||
eval->val[7] = seq & 0xff;
|
||||
}
|
||||
|
||||
static inline void
|
||||
build_evpn_type2_prefix (struct prefix_evpn *p, struct ethaddr *mac,
|
||||
struct ipaddr *ip)
|
||||
{
|
||||
memset (p, 0, sizeof (struct prefix_evpn));
|
||||
p->family = AF_ETHERNET;
|
||||
p->prefixlen = EVPN_TYPE_2_ROUTE_PREFIXLEN;
|
||||
p->prefix.route_type = BGP_EVPN_MAC_IP_ROUTE;
|
||||
memcpy(&p->prefix.mac.octet, mac->octet, ETHER_ADDR_LEN);
|
||||
p->prefix.ip.ipa_type = IPADDR_NONE;
|
||||
if (ip)
|
||||
memcpy(&p->prefix.ip, ip, sizeof (*ip));
|
||||
}
|
||||
|
||||
static inline void
|
||||
build_evpn_type3_prefix (struct prefix_evpn *p, struct in_addr originator_ip)
|
||||
{
|
||||
memset (p, 0, sizeof (struct prefix_evpn));
|
||||
p->family = AF_ETHERNET;
|
||||
p->prefixlen = EVPN_TYPE_3_ROUTE_PREFIXLEN;
|
||||
p->prefix.route_type = BGP_EVPN_IMET_ROUTE;
|
||||
p->prefix.ip.ipa_type = IPADDR_V4;
|
||||
p->prefix.ip.ipaddr_v4 = originator_ip;
|
||||
}
|
||||
|
||||
|
||||
extern void
|
||||
bgp_evpn_map_vni_to_its_rts (struct bgp *bgp, struct bgpevpn *vpn);
|
||||
extern void
|
||||
bgp_evpn_unmap_vni_from_its_rts (struct bgp *bgp, struct bgpevpn *vpn);
|
||||
extern void
|
||||
bgp_evpn_derive_auto_rt_import (struct bgp *bgp, struct bgpevpn *vpn);
|
||||
extern void
|
||||
bgp_evpn_derive_auto_rt_export (struct bgp *bgp, struct bgpevpn *vpn);
|
||||
extern void
|
||||
bgp_evpn_derive_auto_rd (struct bgp *bgp, struct bgpevpn *vpn);
|
||||
extern struct bgpevpn *
|
||||
bgp_evpn_lookup_vni (struct bgp *bgp, vni_t vni);
|
||||
extern struct bgpevpn *
|
||||
bgp_evpn_new (struct bgp *bgp, vni_t vni, struct in_addr originator_ip);
|
||||
extern void
|
||||
bgp_evpn_free (struct bgp *bgp, struct bgpevpn *vpn);
|
||||
#endif /* _BGP_EVPN_PRIVATE_H */
|
||||
|
@ -681,7 +681,7 @@ DEFUN(evpnrt5_network,
|
||||
argv[idx_ext_community]->arg,
|
||||
argv[idx_word]->arg,
|
||||
argv[idx_rmap] ? argv[idx_gwip]->arg : NULL,
|
||||
EVPN_IP_PREFIX, argv[idx_esi]->arg,
|
||||
BGP_EVPN_IP_PREFIX_ROUTE, argv[idx_esi]->arg,
|
||||
argv[idx_gwip]->arg, argv[idx_ethtag]->arg,
|
||||
argv[idx_routermac]->arg);
|
||||
}
|
||||
@ -713,7 +713,7 @@ DEFUN(no_evpnrt5_network,
|
||||
return bgp_static_unset_safi(AFI_L2VPN, SAFI_EVPN, vty,
|
||||
argv[idx_ipv4_prefixlen]->arg,
|
||||
argv[idx_ext_community]->arg,
|
||||
argv[idx_label]->arg, EVPN_IP_PREFIX,
|
||||
argv[idx_label]->arg, BGP_EVPN_IP_PREFIX_ROUTE,
|
||||
argv[idx_esi]->arg, argv[idx_gwip]->arg,
|
||||
argv[idx_ethtag]->arg);
|
||||
}
|
||||
|
@ -114,3 +114,7 @@ DEFINE_MTYPE(BGPD, BGP_TEA_OPTIONS_VALUE, "BGP TEA Options Value")
|
||||
DEFINE_MTYPE(BGPD, LCOMMUNITY, "Large Community")
|
||||
DEFINE_MTYPE(BGPD, LCOMMUNITY_STR, "Large Community display string")
|
||||
DEFINE_MTYPE(BGPD, LCOMMUNITY_VAL, "Large Community value")
|
||||
|
||||
DEFINE_MTYPE(BGPD, BGP_EVPN, "BGP EVPN Information")
|
||||
DEFINE_MTYPE(BGPD, BGP_EVPN_IMPORT_RT, "BGP EVPN Import RT")
|
||||
DEFINE_MTYPE(BGPD, BGP_EVPN_MACIP, "BGP EVPN MAC IP")
|
||||
|
@ -110,4 +110,8 @@ DECLARE_MTYPE(BGP_TEA_OPTIONS_VALUE)
|
||||
DECLARE_MTYPE(LCOMMUNITY)
|
||||
DECLARE_MTYPE(LCOMMUNITY_STR)
|
||||
DECLARE_MTYPE(LCOMMUNITY_VAL)
|
||||
|
||||
DECLARE_MTYPE(BGP_EVPN)
|
||||
DECLARE_MTYPE(BGP_EVPN_IMPORT_RT)
|
||||
DECLARE_MTYPE(BGP_EVPN_MACIP)
|
||||
#endif /* _QUAGGA_BGP_MEMORY_H */
|
||||
|
194
bgpd/bgp_route.c
194
bgpd/bgp_route.c
@ -110,6 +110,36 @@ bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix
|
||||
return rn;
|
||||
}
|
||||
|
||||
struct bgp_node *
|
||||
bgp_afi_node_lookup (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
|
||||
struct prefix_rd *prd)
|
||||
{
|
||||
struct bgp_node *rn;
|
||||
struct bgp_node *prn = NULL;
|
||||
|
||||
if (!table)
|
||||
return NULL;
|
||||
|
||||
if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || (safi == SAFI_EVPN))
|
||||
{
|
||||
prn = bgp_node_lookup (table, (struct prefix *) prd);
|
||||
if (!prn)
|
||||
return NULL;
|
||||
|
||||
if (prn->info == NULL)
|
||||
{
|
||||
bgp_unlock_node (prn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
table = prn->info;
|
||||
}
|
||||
|
||||
rn = bgp_node_lookup (table, p);
|
||||
|
||||
return rn;
|
||||
}
|
||||
|
||||
/* Allocate bgp_info_extra */
|
||||
static struct bgp_info_extra *
|
||||
bgp_info_extra_new (void)
|
||||
@ -224,7 +254,7 @@ bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
|
||||
|
||||
/* Do the actual removal of info from RIB, for use by bgp_process
|
||||
completion callback *only* */
|
||||
static void
|
||||
void
|
||||
bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
|
||||
{
|
||||
if (ri->next)
|
||||
@ -359,7 +389,7 @@ bgp_info_path_with_addpath_rx_str (struct bgp_info *ri, char *buf)
|
||||
static int
|
||||
bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
|
||||
int *paths_eq, struct bgp_maxpaths_cfg *mpath_cfg, int debug,
|
||||
const char *pfx_buf)
|
||||
char *pfx_buf, afi_t afi, safi_t safi)
|
||||
{
|
||||
struct attr *newattr, *existattr;
|
||||
struct attr_extra *newattre, *existattre;
|
||||
@ -381,6 +411,8 @@ bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
|
||||
int ret;
|
||||
char new_buf[PATH_ADDPATH_STR_BUFFER];
|
||||
char exist_buf[PATH_ADDPATH_STR_BUFFER];
|
||||
u_int32_t new_mm_seq;
|
||||
u_int32_t exist_mm_seq;
|
||||
|
||||
*paths_eq = 0;
|
||||
|
||||
@ -414,6 +446,61 @@ bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
|
||||
newattre = newattr->extra;
|
||||
existattre = existattr->extra;
|
||||
|
||||
/* For EVPN routes, we cannot just go by local vs remote, we have to
|
||||
* look at the MAC mobility sequence number, if present.
|
||||
*/
|
||||
if (safi == SAFI_EVPN)
|
||||
{
|
||||
/* This is an error condition described in RFC 7432 Section 15.2. The RFC
|
||||
* states that in this scenario "the PE MUST alert the operator" but it
|
||||
* does not state what other action to take. In order to provide some
|
||||
* consistency in this scenario we are going to prefer the path with the
|
||||
* sticky flag.
|
||||
*/
|
||||
if (newattre->sticky != existattre->sticky)
|
||||
{
|
||||
if (!debug)
|
||||
{
|
||||
prefix2str (&new->net->p, pfx_buf, sizeof (*pfx_buf) * PREFIX2STR_BUFFER);
|
||||
bgp_info_path_with_addpath_rx_str (new, new_buf);
|
||||
bgp_info_path_with_addpath_rx_str (exist, exist_buf);
|
||||
}
|
||||
|
||||
if (newattre->sticky && !existattre->sticky)
|
||||
{
|
||||
zlog_warn("%s: %s wins over %s due to sticky MAC flag",
|
||||
pfx_buf, new_buf, exist_buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!newattre->sticky && existattre->sticky)
|
||||
{
|
||||
zlog_warn("%s: %s loses to %s due to sticky MAC flag",
|
||||
pfx_buf, new_buf, exist_buf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
new_mm_seq = mac_mobility_seqnum (newattr);
|
||||
exist_mm_seq = mac_mobility_seqnum (existattr);
|
||||
|
||||
if (new_mm_seq > exist_mm_seq)
|
||||
{
|
||||
if (debug)
|
||||
zlog_debug("%s: %s wins over %s due to MM seq %u > %u",
|
||||
pfx_buf, new_buf, exist_buf, new_mm_seq, exist_mm_seq);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (new_mm_seq < exist_mm_seq)
|
||||
{
|
||||
if (debug)
|
||||
zlog_debug("%s: %s loses to %s due to MM seq %u < %u",
|
||||
pfx_buf, new_buf, exist_buf, new_mm_seq, exist_mm_seq);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* 1. Weight check. */
|
||||
new_weight = exist_weight = 0;
|
||||
|
||||
@ -891,11 +978,12 @@ bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
|
||||
* This version is compatible with */
|
||||
int
|
||||
bgp_info_cmp_compatible (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
|
||||
afi_t afi, safi_t safi)
|
||||
char *pfx_buf, afi_t afi, safi_t safi)
|
||||
{
|
||||
int paths_eq;
|
||||
int ret;
|
||||
ret = bgp_info_cmp (bgp, new, exist, &paths_eq, NULL, 0, __func__);
|
||||
ret = bgp_info_cmp (bgp, new, exist, &paths_eq, NULL, 0,
|
||||
pfx_buf, afi, safi);
|
||||
|
||||
if (paths_eq)
|
||||
ret = 0;
|
||||
@ -1599,16 +1687,11 @@ subgroup_announce_check (struct bgp_node *rn, struct bgp_info *ri,
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct bgp_info_pair
|
||||
{
|
||||
struct bgp_info *old;
|
||||
struct bgp_info *new;
|
||||
};
|
||||
|
||||
static void
|
||||
void
|
||||
bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
|
||||
struct bgp_maxpaths_cfg *mpath_cfg,
|
||||
struct bgp_info_pair *result)
|
||||
struct bgp_info_pair *result,
|
||||
afi_t afi, safi_t safi)
|
||||
{
|
||||
struct bgp_info *new_select;
|
||||
struct bgp_info *old_select;
|
||||
@ -1668,7 +1751,7 @@ bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
|
||||
ri2->attr->aspath))
|
||||
{
|
||||
if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq,
|
||||
mpath_cfg, debug, pfx_buf))
|
||||
mpath_cfg, debug, pfx_buf, afi, safi))
|
||||
{
|
||||
bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
|
||||
new_select = ri2;
|
||||
@ -1725,7 +1808,8 @@ bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
|
||||
|
||||
bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
|
||||
|
||||
if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf))
|
||||
if (bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg,
|
||||
debug, pfx_buf, afi, safi))
|
||||
{
|
||||
new_select = ri;
|
||||
}
|
||||
@ -1779,7 +1863,8 @@ bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
|
||||
continue;
|
||||
}
|
||||
|
||||
bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg, debug, pfx_buf);
|
||||
bgp_info_cmp (bgp, ri, new_select, &paths_eq, mpath_cfg,
|
||||
debug, pfx_buf, afi, safi);
|
||||
|
||||
if (paths_eq)
|
||||
{
|
||||
@ -1855,7 +1940,7 @@ subgroup_process_announce_selected (struct update_subgroup *subgrp,
|
||||
* Clear IGP changed flag and attribute changed flag for a route (all paths).
|
||||
* This is called at the end of route processing.
|
||||
*/
|
||||
static void
|
||||
void
|
||||
bgp_zebra_clear_route_change_flags (struct bgp_node *rn)
|
||||
{
|
||||
struct bgp_info *ri;
|
||||
@ -1874,7 +1959,7 @@ bgp_zebra_clear_route_change_flags (struct bgp_node *rn)
|
||||
* if the route selection returns the same best route as earlier - to
|
||||
* determine if we need to update zebra or not.
|
||||
*/
|
||||
static int
|
||||
int
|
||||
bgp_zebra_has_route_changed (struct bgp_node *rn, struct bgp_info *selected)
|
||||
{
|
||||
struct bgp_info *mpinfo;
|
||||
@ -1943,7 +2028,8 @@ bgp_process_main (struct work_queue *wq, void *data)
|
||||
}
|
||||
|
||||
/* Best path selection. */
|
||||
bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
|
||||
bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi],
|
||||
&old_and_new, afi, safi);
|
||||
old_select = old_and_new.old;
|
||||
new_select = old_and_new.new;
|
||||
|
||||
@ -2343,12 +2429,17 @@ bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If this is an EVPN route, process for un-import. */
|
||||
if (safi == SAFI_EVPN)
|
||||
bgp_evpn_unimport_route (peer->bgp, afi, safi, &rn->p, ri);
|
||||
|
||||
bgp_rib_remove (rn, ri, peer, afi, safi);
|
||||
}
|
||||
|
||||
static struct bgp_info *
|
||||
info_make (int type, int sub_type, u_short instance, struct peer *peer, struct attr *attr,
|
||||
struct bgp_node *rn)
|
||||
struct bgp_info *
|
||||
info_make (int type, int sub_type, u_short instance, struct peer *peer,
|
||||
struct attr *attr, struct bgp_node *rn)
|
||||
{
|
||||
struct bgp_info *new;
|
||||
|
||||
@ -2435,7 +2526,8 @@ bgp_update_martian_nexthop (struct bgp *bgp, afi_t afi, safi_t safi, struct attr
|
||||
int ret = 0;
|
||||
|
||||
/* Only validated for unicast and multicast currently. */
|
||||
if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST)
|
||||
/* Also valid for EVPN where the nexthop is an IP address. */
|
||||
if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST && safi != SAFI_EVPN)
|
||||
return 0;
|
||||
|
||||
/* If NEXT_HOP is present, validate it. */
|
||||
@ -2504,6 +2596,7 @@ bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
|
||||
#if ENABLE_BGP_VNC
|
||||
int vnc_implicit_withdraw = 0;
|
||||
#endif
|
||||
int same_attr=0;
|
||||
|
||||
memset (&new_attr, 0, sizeof(struct attr));
|
||||
memset (&new_extra, 0, sizeof(struct attr_extra));
|
||||
@ -2613,6 +2706,7 @@ bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
|
||||
if (ri)
|
||||
{
|
||||
ri->uptime = bgp_clock ();
|
||||
same_attr = attrhash_cmp (ri->attr, attr_new);
|
||||
|
||||
/* Same attribute comes in. */
|
||||
if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
|
||||
@ -2734,7 +2828,32 @@ bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Special handling for EVPN update of an existing route. If the
|
||||
* extended community attribute has changed, we need to un-import
|
||||
* the route using its existing extended community. It will be
|
||||
* subsequently processed for import with the new extended community.
|
||||
*/
|
||||
if (safi == SAFI_EVPN && !same_attr)
|
||||
{
|
||||
if ((ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES)) &&
|
||||
(attr_new->flag & ATTR_FLAG_BIT (BGP_ATTR_EXT_COMMUNITIES)))
|
||||
{
|
||||
int cmp;
|
||||
|
||||
cmp = ecommunity_cmp (ri->attr->extra->ecommunity,
|
||||
attr_new->extra->ecommunity);
|
||||
if (!cmp)
|
||||
{
|
||||
if (bgp_debug_update(peer, p, NULL, 1))
|
||||
zlog_debug ("Change in EXT-COMM, existing %s new %s",
|
||||
ecommunity_str (ri->attr->extra->ecommunity),
|
||||
ecommunity_str (attr_new->extra->ecommunity));
|
||||
bgp_evpn_unimport_route (bgp, afi, safi, p, ri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Update to new attribute. */
|
||||
bgp_attr_unintern (&ri->attr);
|
||||
ri->attr = attr_new;
|
||||
@ -2833,6 +2952,16 @@ bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If this is an EVPN route and some attribute has changed, process
|
||||
* route for import. If the extended community has changed, we would
|
||||
* have done the un-import earlier and the import would result in the
|
||||
* route getting injected into appropriate L2 VNIs. If it is just
|
||||
* some other attribute change, the import will result in updating
|
||||
* the attributes for the route in the VNI(s).
|
||||
*/
|
||||
if (safi == SAFI_EVPN && !same_attr)
|
||||
bgp_evpn_import_route (bgp, afi, safi, p, ri);
|
||||
|
||||
/* Process change. */
|
||||
bgp_aggregate_increment (bgp, p, ri, afi, safi);
|
||||
|
||||
@ -2953,6 +3082,10 @@ bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
|
||||
if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
|
||||
return -1;
|
||||
|
||||
/* If this is an EVPN route, process for import. */
|
||||
if (safi == SAFI_EVPN)
|
||||
bgp_evpn_import_route (bgp, afi, safi, p, new);
|
||||
|
||||
/* Process change. */
|
||||
bgp_process (bgp, rn, afi, safi);
|
||||
|
||||
@ -2991,7 +3124,13 @@ bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
|
||||
}
|
||||
|
||||
if (ri)
|
||||
bgp_rib_remove (rn, ri, peer, afi, safi);
|
||||
{
|
||||
/* If this is an EVPN route, un-import it as it is now filtered. */
|
||||
if (safi == SAFI_EVPN)
|
||||
bgp_evpn_unimport_route (bgp, afi, safi, p, ri);
|
||||
|
||||
bgp_rib_remove (rn, ri, peer, afi, safi);
|
||||
}
|
||||
|
||||
bgp_unlock_node (rn);
|
||||
|
||||
@ -3271,7 +3410,12 @@ bgp_clear_route_node (struct work_queue *wq, void *data)
|
||||
&& ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
|
||||
bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
|
||||
else
|
||||
bgp_rib_remove (rn, ri, peer, afi, safi);
|
||||
{
|
||||
/* If this is an EVPN route, process for un-import. */
|
||||
if (safi == SAFI_EVPN)
|
||||
bgp_evpn_unimport_route (peer->bgp, afi, safi, &rn->p, ri);
|
||||
bgp_rib_remove (rn, ri, peer, afi, safi);
|
||||
}
|
||||
}
|
||||
return WQ_SUCCESS;
|
||||
}
|
||||
|
@ -99,6 +99,9 @@ struct bgp_info_extra
|
||||
|
||||
} vnc;
|
||||
#endif
|
||||
|
||||
/* For imported routes into a VNI (or VRF), this points to the parent. */
|
||||
void *parent;
|
||||
};
|
||||
|
||||
struct bgp_info
|
||||
@ -174,6 +177,13 @@ struct bgp_info
|
||||
|
||||
};
|
||||
|
||||
/* Structure used in BGP path selection */
|
||||
struct bgp_info_pair
|
||||
{
|
||||
struct bgp_info *old;
|
||||
struct bgp_info *new;
|
||||
};
|
||||
|
||||
/* BGP static route configuration. */
|
||||
struct bgp_static
|
||||
{
|
||||
@ -309,6 +319,7 @@ extern struct bgp_node *bgp_afi_node_get (struct bgp_table *table, afi_t afi,
|
||||
extern struct bgp_info *bgp_info_lock (struct bgp_info *);
|
||||
extern struct bgp_info *bgp_info_unlock (struct bgp_info *);
|
||||
extern void bgp_info_add (struct bgp_node *rn, struct bgp_info *ri);
|
||||
extern void bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri);
|
||||
extern void bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri);
|
||||
extern struct bgp_info_extra *bgp_info_extra_get (struct bgp_info *);
|
||||
extern void bgp_info_set_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
|
||||
@ -372,6 +383,10 @@ extern u_char bgp_distance_apply (struct prefix *, struct bgp_info *, afi_t, saf
|
||||
extern afi_t bgp_node_afi (struct vty *);
|
||||
extern safi_t bgp_node_safi (struct vty *);
|
||||
|
||||
extern struct bgp_info *
|
||||
info_make (int type, int sub_type, u_short instance, struct peer *peer,
|
||||
struct attr *attr, struct bgp_node *rn);
|
||||
|
||||
extern void route_vty_out (struct vty *, struct prefix *, struct bgp_info *, int, safi_t, json_object *);
|
||||
extern void route_vty_out_tag (struct vty *, struct prefix *, struct bgp_info *, int, safi_t, json_object *);
|
||||
extern void route_vty_out_tmp (struct vty *, struct prefix *, struct attr *, safi_t, u_char, json_object *);
|
||||
@ -396,10 +411,23 @@ extern void bgp_process_queues_drain_immediate (void);
|
||||
extern struct bgp_node *
|
||||
bgp_afi_node_get (struct bgp_table *, afi_t , safi_t , struct prefix *,
|
||||
struct prefix_rd *);
|
||||
extern struct bgp_node *
|
||||
bgp_afi_node_lookup (struct bgp_table *table, afi_t afi, safi_t safi,
|
||||
struct prefix *p, struct prefix_rd *prd);
|
||||
extern struct bgp_info *bgp_info_new (void);
|
||||
extern void bgp_info_restore (struct bgp_node *, struct bgp_info *);
|
||||
|
||||
extern int bgp_info_cmp_compatible (struct bgp *, struct bgp_info *,
|
||||
struct bgp_info *, afi_t, safi_t );
|
||||
extern int
|
||||
bgp_info_cmp_compatible (struct bgp *, struct bgp_info *, struct bgp_info *,
|
||||
char *pfx_buf, afi_t afi, safi_t safi);
|
||||
|
||||
extern void
|
||||
bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
|
||||
struct bgp_maxpaths_cfg *mpath_cfg,
|
||||
struct bgp_info_pair *result,
|
||||
afi_t afi, safi_t safi);
|
||||
extern void bgp_zebra_clear_route_change_flags (struct bgp_node *rn);
|
||||
extern int
|
||||
bgp_zebra_has_route_changed (struct bgp_node *rn, struct bgp_info *selected);
|
||||
|
||||
#endif /* _QUAGGA_BGP_ROUTE_H */
|
||||
|
@ -607,6 +607,30 @@ bpacket_reformat_for_peer (struct bpacket *pkt, struct peer_af *paf)
|
||||
(nhlen == 24 ? " and RD" : ""));
|
||||
}
|
||||
}
|
||||
else if (paf->afi == AFI_L2VPN)
|
||||
{
|
||||
struct in_addr v4nh, *mod_v4nh;
|
||||
int nh_modified = 0;
|
||||
|
||||
stream_get_from (&v4nh, s, vec->offset + 1, 4);
|
||||
mod_v4nh = &v4nh;
|
||||
|
||||
/* No route-map changes allowed for EVPN nexthops. */
|
||||
if (!v4nh.s_addr)
|
||||
{
|
||||
mod_v4nh = &peer->nexthop.v4;
|
||||
nh_modified = 1;
|
||||
}
|
||||
|
||||
if (nh_modified)
|
||||
stream_put_in_addr_at (s, vec->offset + 1, mod_v4nh);
|
||||
|
||||
if (bgp_debug_update(peer, NULL, NULL, 0))
|
||||
zlog_debug ("u%" PRIu64 ":s%" PRIu64 " %s send UPDATE w/ nexthop %s",
|
||||
PAF_SUBGRP(paf)->update_group->id, PAF_SUBGRP(paf)->id,
|
||||
peer->host, inet_ntoa (*mod_v4nh));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bgp_packet_add (peer, s);
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "lib/bfd.h"
|
||||
#include "filter.h"
|
||||
#include "mpls.h"
|
||||
#include "vxlan.h"
|
||||
|
||||
#include "bgpd/bgpd.h"
|
||||
#include "bgpd/bgp_route.h"
|
||||
@ -52,6 +53,7 @@
|
||||
# include "bgpd/rfapi/rfapi_backend.h"
|
||||
# include "bgpd/rfapi/vnc_export_bgp.h"
|
||||
#endif
|
||||
#include "bgpd/bgp_evpn.h"
|
||||
|
||||
/* All information about zebra. */
|
||||
struct zclient *zclient = NULL;
|
||||
@ -2139,6 +2141,82 @@ bgp_zebra_connected (struct zclient *zclient)
|
||||
*/
|
||||
}
|
||||
|
||||
static int
|
||||
bgp_zebra_process_local_vni (int command, struct zclient *zclient,
|
||||
zebra_size_t length, vrf_id_t vrf_id)
|
||||
{
|
||||
struct stream *s;
|
||||
vni_t vni;
|
||||
struct bgp *bgp;
|
||||
struct in_addr vtep_ip;
|
||||
|
||||
s = zclient->ibuf;
|
||||
vni = stream_getl (s);
|
||||
if (command == ZEBRA_VNI_ADD)
|
||||
vtep_ip.s_addr = stream_get_ipv4 (s);
|
||||
bgp = bgp_lookup_by_vrf_id (vrf_id);
|
||||
if (!bgp)
|
||||
return 0;
|
||||
|
||||
if (BGP_DEBUG (zebra, ZEBRA))
|
||||
zlog_debug("Rx VNI %s VRF %u VNI %u",
|
||||
(command == ZEBRA_VNI_ADD) ? "add" : "del", vrf_id, vni);
|
||||
|
||||
if (command == ZEBRA_VNI_ADD)
|
||||
return bgp_evpn_local_vni_add (bgp, vni, vtep_ip.s_addr? vtep_ip : bgp->router_id);
|
||||
else
|
||||
return bgp_evpn_local_vni_del (bgp, vni);
|
||||
}
|
||||
|
||||
static int
|
||||
bgp_zebra_process_local_macip (int command, struct zclient *zclient,
|
||||
zebra_size_t length, vrf_id_t vrf_id)
|
||||
{
|
||||
struct stream *s;
|
||||
vni_t vni;
|
||||
struct bgp *bgp;
|
||||
struct ethaddr mac;
|
||||
struct ipaddr ip;
|
||||
int ipa_len;
|
||||
char buf[ETHER_ADDR_STRLEN];
|
||||
char buf1[INET6_ADDRSTRLEN];
|
||||
|
||||
memset (&ip, 0, sizeof (ip));
|
||||
s = zclient->ibuf;
|
||||
vni = stream_getl (s);
|
||||
stream_get (&mac.octet, s, ETHER_ADDR_LEN);
|
||||
ipa_len = stream_getl (s);
|
||||
if (ipa_len != 0 &&
|
||||
ipa_len != IPV4_MAX_BYTELEN &&
|
||||
ipa_len != IPV6_MAX_BYTELEN)
|
||||
{
|
||||
zlog_err ("%u:Recv MACIP %s with invalid IP addr length %d",
|
||||
vrf_id, (command == ZEBRA_MACIP_ADD) ? "Add" : "Del",
|
||||
ipa_len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ipa_len)
|
||||
{
|
||||
ip.ipa_type = (ipa_len == IPV4_MAX_BYTELEN) ? IPADDR_V4: IPADDR_V6;
|
||||
stream_get (&ip.ip.addr, s, ipa_len);
|
||||
}
|
||||
|
||||
bgp = bgp_lookup_by_vrf_id (vrf_id);
|
||||
if (!bgp)
|
||||
return 0;
|
||||
|
||||
if (BGP_DEBUG (zebra, ZEBRA))
|
||||
zlog_debug ("%u:Recv MACIP %s MAC %s IP %s VNI %u",
|
||||
vrf_id, (command == ZEBRA_MACIP_ADD) ? "Add" : "Del",
|
||||
prefix_mac2str (&mac, buf, sizeof (buf)),
|
||||
ipaddr2str (&ip, buf1, sizeof(buf1)), vni);
|
||||
|
||||
if (command == ZEBRA_MACIP_ADD)
|
||||
return bgp_evpn_local_macip_add (bgp, vni, &mac, &ip);
|
||||
else
|
||||
return bgp_evpn_local_macip_del (bgp, vni, &mac, &ip);
|
||||
}
|
||||
|
||||
void
|
||||
bgp_zebra_init (struct thread_master *master)
|
||||
@ -2166,6 +2244,10 @@ bgp_zebra_init (struct thread_master *master)
|
||||
zclient->nexthop_update = bgp_read_nexthop_update;
|
||||
zclient->import_check_update = bgp_read_import_check_update;
|
||||
zclient->fec_update = bgp_read_fec_update;
|
||||
zclient->local_vni_add = bgp_zebra_process_local_vni;
|
||||
zclient->local_vni_del = bgp_zebra_process_local_vni;
|
||||
zclient->local_macip_add = bgp_zebra_process_local_macip;
|
||||
zclient->local_macip_del = bgp_zebra_process_local_macip;
|
||||
|
||||
bgp_nexthop_buf = stream_new(multipath_num * sizeof (struct in6_addr));
|
||||
bgp_ifindices_buf = stream_new(multipath_num * sizeof (unsigned int));
|
||||
|
@ -2121,6 +2121,8 @@ rfapiBgpInfoAttachSorted (
|
||||
struct bgp *bgp;
|
||||
struct bgp_info *prev;
|
||||
struct bgp_info *next;
|
||||
char pfx_buf[PREFIX2STR_BUFFER];
|
||||
|
||||
|
||||
bgp = bgp_get_default (); /* assume 1 instance for now */
|
||||
|
||||
@ -2136,7 +2138,7 @@ rfapiBgpInfoAttachSorted (
|
||||
if (!bgp ||
|
||||
(!CHECK_FLAG (info_new->flags, BGP_INFO_REMOVED) &&
|
||||
CHECK_FLAG (next->flags, BGP_INFO_REMOVED)) ||
|
||||
bgp_info_cmp_compatible (bgp, info_new, next, afi, safi) == -1)
|
||||
bgp_info_cmp_compatible (bgp, info_new, next, pfx_buf, afi, safi) == -1)
|
||||
{ /* -1 if 1st is better */
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user