mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-09 07:35:21 +00:00
Merge pull request #4314 from lkrishnamoor/extract_tunnel_type_extcom
bgpd: Extract tunnel type from extended communities
This commit is contained in:
commit
13f9ea7253
@ -51,7 +51,6 @@
|
||||
#include "bgp_encap_types.h"
|
||||
#include "bgp_vnc_types.h"
|
||||
#endif
|
||||
#include "bgp_encap_types.h"
|
||||
#include "bgp_evpn.h"
|
||||
#include "bgp_flowspec_private.h"
|
||||
#include "bgp_mac.h"
|
||||
@ -1957,6 +1956,10 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args)
|
||||
|
||||
}
|
||||
|
||||
/* Get the tunnel type from encap extended community */
|
||||
bgp_attr_extcom_tunnel_type(attr,
|
||||
(bgp_encap_types *)&attr->encap_tunneltype);
|
||||
|
||||
return BGP_ATTR_PARSE_PROCEED;
|
||||
}
|
||||
|
||||
@ -2776,6 +2779,38 @@ bgp_attr_parse_ret_t bgp_attr_parse(struct peer *peer, struct attr *attr,
|
||||
return BGP_ATTR_PARSE_PROCEED;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract the tunnel type from extended community
|
||||
*/
|
||||
void bgp_attr_extcom_tunnel_type(struct attr *attr,
|
||||
bgp_encap_types *tunnel_type)
|
||||
{
|
||||
struct ecommunity *ecom;
|
||||
int i;
|
||||
if (!attr)
|
||||
return false;
|
||||
|
||||
ecom = attr->ecommunity;
|
||||
if (!ecom || !ecom->size)
|
||||
return false;
|
||||
|
||||
for (i = 0; i < ecom->size; i++) {
|
||||
uint8_t *pnt;
|
||||
uint8_t type, sub_type;
|
||||
|
||||
pnt = (ecom->val + (i * ECOMMUNITY_SIZE));
|
||||
type = pnt[0];
|
||||
sub_type = pnt[1];
|
||||
if (!(type == ECOMMUNITY_ENCODE_OPAQUE &&
|
||||
sub_type == ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP))
|
||||
continue;
|
||||
*tunnel_type = ((pnt[6] << 8) | pnt[7]);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi,
|
||||
safi_t safi, struct bpacket_attr_vec_arr *vecarr,
|
||||
struct attr *attr)
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "mpls.h"
|
||||
#include "bgp_attr_evpn.h"
|
||||
#include "bgpd/bgp_encap_types.h"
|
||||
|
||||
/* Simple bit mapping. */
|
||||
#define BITMAP_NBBY 8
|
||||
@ -317,6 +318,9 @@ encap_tlv_dup(struct bgp_attr_encap_subtlv *orig);
|
||||
|
||||
extern void bgp_attr_flush_encap(struct attr *attr);
|
||||
|
||||
extern void bgp_attr_extcom_tunnel_type(struct attr *attr,
|
||||
bgp_encap_types *tunnel_type);
|
||||
|
||||
/**
|
||||
* Set of functions to encode MP_REACH_NLRI and MP_UNREACH_NLRI attributes.
|
||||
* Typical call sequence is to call _start(), followed by multiple _prefix(),
|
||||
|
@ -22,6 +22,7 @@
|
||||
#define _QUAGGA_BGP_ECOMMUNITY_H
|
||||
|
||||
#include "bgpd/bgp_route.h"
|
||||
#include "bgpd/bgpd.h"
|
||||
|
||||
/* High-order octet of the Extended Communities type field. */
|
||||
#define ECOMMUNITY_ENCODE_AS 0x00
|
||||
|
@ -374,42 +374,15 @@ int rfapiGetVncLifetime(struct attr *attr, uint32_t *lifetime)
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract the tunnel type from the extended community
|
||||
*/
|
||||
int rfapiGetTunnelType(struct attr *attr, bgp_encap_types *type)
|
||||
{
|
||||
*type = BGP_ENCAP_TYPE_MPLS; /* default to MPLS */
|
||||
if (attr && attr->ecommunity) {
|
||||
struct ecommunity *ecom = attr->ecommunity;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (ecom->size * ECOMMUNITY_SIZE);
|
||||
i += ECOMMUNITY_SIZE) {
|
||||
uint8_t *ep;
|
||||
|
||||
ep = ecom->val + i;
|
||||
if (ep[0] == ECOMMUNITY_ENCODE_OPAQUE
|
||||
&& ep[1] == ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP) {
|
||||
*type = (ep[6] << 8) + ep[7];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Look for UN address in Encap attribute
|
||||
*/
|
||||
int rfapiGetVncTunnelUnAddr(struct attr *attr, struct prefix *p)
|
||||
{
|
||||
struct bgp_attr_encap_subtlv *pEncap;
|
||||
bgp_encap_types tun_type;
|
||||
bgp_encap_types tun_type = BGP_ENCAP_TYPE_MPLS;/*Default tunnel type*/
|
||||
|
||||
rfapiGetTunnelType(attr, &tun_type);
|
||||
bgp_attr_extcom_tunnel_type(attr, &tun_type);
|
||||
if (tun_type == BGP_ENCAP_TYPE_MPLS) {
|
||||
if (!p)
|
||||
return 0;
|
||||
@ -1350,7 +1323,7 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix,
|
||||
}
|
||||
|
||||
if (bpi->attr) {
|
||||
bgp_encap_types tun_type;
|
||||
bgp_encap_types tun_type = BGP_ENCAP_TYPE_MPLS; /*Default*/
|
||||
new->prefix.cost = rfapiRfpCost(bpi->attr);
|
||||
|
||||
struct bgp_attr_encap_subtlv *pEncap;
|
||||
@ -1390,7 +1363,7 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix,
|
||||
}
|
||||
}
|
||||
|
||||
rfapiGetTunnelType(bpi->attr, &tun_type);
|
||||
bgp_attr_extcom_tunnel_type(bpi->attr, &tun_type);
|
||||
if (tun_type == BGP_ENCAP_TYPE_MPLS) {
|
||||
struct prefix p;
|
||||
/* MPLS carries UN address in next hop */
|
||||
|
@ -306,8 +306,6 @@ extern int rfapiCliGetPrefixAddr(struct vty *vty, const char *str,
|
||||
|
||||
extern int rfapiGetVncLifetime(struct attr *attr, uint32_t *lifetime);
|
||||
|
||||
extern int rfapiGetTunnelType(struct attr *attr, bgp_encap_types *type);
|
||||
|
||||
extern int rfapiGetVncTunnelUnAddr(struct attr *attr, struct prefix *p);
|
||||
|
||||
extern int rfapi_reopen(struct rfapi_descriptor *rfd, struct bgp *bgp);
|
||||
|
@ -1020,7 +1020,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream,
|
||||
struct prefix pfx_vn;
|
||||
uint8_t cost;
|
||||
uint32_t lifetime;
|
||||
bgp_encap_types tun_type;
|
||||
bgp_encap_types tun_type = BGP_ENCAP_TYPE_MPLS;/*Default tunnel type*/
|
||||
|
||||
char buf_pfx[BUFSIZ];
|
||||
char buf_ntop[BUFSIZ];
|
||||
@ -1055,7 +1055,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream,
|
||||
BUFSIZ));
|
||||
}
|
||||
|
||||
rfapiGetTunnelType(bpi->attr, &tun_type);
|
||||
bgp_attr_extcom_tunnel_type(bpi->attr, &tun_type);
|
||||
/*
|
||||
* VN addr
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user