summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLakshman Krishnamoorthy <lkrishnamoor@vmware.com>2019-05-11 19:17:23 +0200
committerLakshman Krishnamoorthy <lkrishnamoor@vmware.com>2019-05-14 21:25:44 +0200
commitf4bd90c5fcf211f946f1413a596091aab85a8de5 (patch)
treebf6d46c4f65d0cb5daffbedc50665e84a0decb37
parentMerge pull request #4311 from ton31337/fix/remote_trailing_tab (diff)
downloadfrr-f4bd90c5fcf211f946f1413a596091aab85a8de5.tar.xz
frr-f4bd90c5fcf211f946f1413a596091aab85a8de5.zip
bgpd: Extract tunnel type from extended communities
This diff contains 2 parts: 1. Extract the tunnel type info from bgp extended communities. 2. Make rfapi use this common tunnel type ap Signed-off-by: Lakshman Krishnamoorthy <lkrishnamoor@vmware.com>
-rw-r--r--bgpd/bgp_attr.c37
-rw-r--r--bgpd/bgp_attr.h4
-rw-r--r--bgpd/bgp_ecommunity.h1
-rw-r--r--bgpd/rfapi/rfapi_import.c35
-rw-r--r--bgpd/rfapi/rfapi_private.h2
-rw-r--r--bgpd/rfapi/rfapi_vty.c4
6 files changed, 47 insertions, 36 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 167ad89a5..0699c8adf 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -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"
@@ -1956,6 +1955,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;
}
@@ -2755,6 +2758,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)
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index 6d5c647b2..3518f1acc 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -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(),
diff --git a/bgpd/bgp_ecommunity.h b/bgpd/bgp_ecommunity.h
index 62b213775..165ab8fe1 100644
--- a/bgpd/bgp_ecommunity.h
+++ b/bgpd/bgp_ecommunity.h
@@ -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
diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c
index 568f8d68e..d67361620 100644
--- a/bgpd/rfapi/rfapi_import.c
+++ b/bgpd/rfapi/rfapi_import.c
@@ -375,41 +375,14 @@ int rfapiGetVncLifetime(struct attr *attr, uint32_t *lifetime)
}
/*
- * 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 */
diff --git a/bgpd/rfapi/rfapi_private.h b/bgpd/rfapi/rfapi_private.h
index 87d9a32f6..ff1cf7ef4 100644
--- a/bgpd/rfapi/rfapi_private.h
+++ b/bgpd/rfapi/rfapi_private.h
@@ -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);
diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c
index ea82c254b..46161b4f3 100644
--- a/bgpd/rfapi/rfapi_vty.c
+++ b/bgpd/rfapi/rfapi_vty.c
@@ -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
*/