]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: Extract tunnel type from extended communities
authorLakshman Krishnamoorthy <lkrishnamoor@vmware.com>
Sat, 11 May 2019 17:17:23 +0000 (10:17 -0700)
committerLakshman Krishnamoorthy <lkrishnamoor@vmware.com>
Tue, 14 May 2019 19:25:44 +0000 (12:25 -0700)
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>
bgpd/bgp_attr.c
bgpd/bgp_attr.h
bgpd/bgp_ecommunity.h
bgpd/rfapi/rfapi_import.c
bgpd/rfapi/rfapi_private.h
bgpd/rfapi/rfapi_vty.c

index 167ad89a5988f026f4424db02b90505601e26c6f..0699c8adfacd5104f0e23697b9e8c1d6e5acdabb 100644 (file)
@@ -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)
index 6d5c647b21c296f4d794f03cc2c398350f295ad6..3518f1accbfcfb764abec27dde7641b68cc7d2ed 100644 (file)
@@ -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(),
index 62b213775391f64f599c94567a97423cacde894c..165ab8fe14980cec11391ccd4d582f8d926dd63d 100644 (file)
@@ -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
index 568f8d68e863e72d0e106dbedfab07099c168051..d67361620db84c0967e5e91e8a740dfd4099de45 100644 (file)
@@ -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 */
index 87d9a32f67c2be4085340bfadd1a9f4e99161c43..ff1cf7ef427d57119483383b7ce707a3e62d1d56 100644 (file)
@@ -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);
index ea82c254bcecbea7168ac2f5ef6b8b0869e7970c..46161b4f382d3afecc6bd1598cc49114dbd491d6 100644 (file)
@@ -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
         */