As per draft-ietf-idr-tunnel-encaps-02, section 3.2.1, BGP Encap
attribute supports vxlan tunnel type. A new tunnel attribute has been
appended to subtlv list, describing the vxlan network identifier to
be used for the routing information of the BGP update message.

Signed-off-by: Philippe Guibert <philippe.guib...@6wind.com>
---
 bgpd/bgp_attr.c        |  5 +++--
 bgpd/bgp_encap_tlv.c   | 22 ++++++++++++++++++++++
 bgpd/bgp_encap_types.h |  7 ++++++-
 bgpd/bgp_route.c       |  9 +++++++++
 4 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 5c5bafa8af81..f53fb14c759d 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -3058,8 +3058,9 @@ bgp_packet_attribute (struct bgp *bgp, struct peer *peer,
       stream_put_ipv4 (s, attr->extra->aggregator_addr.s_addr);
     }
 
-  if ((afi == AFI_IP || afi == AFI_IP6) &&
-      (safi == SAFI_ENCAP || safi == SAFI_MPLS_VPN))
+  if (((afi == AFI_IP || afi == AFI_IP6) &&
+       (safi == SAFI_ENCAP || safi == SAFI_MPLS_VPN)) ||
+      (afi == AFI_INTERNAL_L2VPN && safi == SAFI_INTERNAL_EVPN))
     {
        /* Tunnel Encap attribute */
        bgp_packet_mpattr_tea(bgp, peer, s, attr, BGP_ATTR_ENCAP);
diff --git a/bgpd/bgp_encap_tlv.c b/bgpd/bgp_encap_tlv.c
index 347b4b3ce72c..0814b811d031 100644
--- a/bgpd/bgp_encap_tlv.c
+++ b/bgpd/bgp_encap_tlv.c
@@ -390,8 +390,30 @@ bgp_encap_type_vxlan_to_tlv(
     struct attr                                *attr)
 {
     struct attr_extra                  *extra = bgp_attr_extra_get(attr);
+    struct bgp_attr_encap_subtlv       *tlv;
+    uint32_t vnid;
 
     extra->encap_tunneltype = BGP_ENCAP_TYPE_VXLAN;
+
+    if(bet == NULL ||!bet->vnid)
+      return;
+    if(extra->encap_subtlvs)
+      XFREE(MTYPE_ENCAP_TLV, extra->encap_subtlvs);
+    tlv = XCALLOC (MTYPE_ENCAP_TLV, sizeof(struct bgp_attr_encap_subtlv)-1+12);
+    tlv->type = 1; /* encapsulation type */
+    tlv->length = 12;
+    if(bet->vnid)
+      {
+        vnid = htonl(bet->vnid | VXLAN_ENCAP_MASK_VNID_VALID);
+        memcpy(&tlv->value, &vnid, 4);
+      }
+    if(bet->mac_address)
+      {
+        char *ptr = (char *)&tlv->value + 4;
+        memcpy( ptr, bet->mac_address, 6);
+      }
+    extra->encap_subtlvs = tlv;
+    return;
 }
 
 void
diff --git a/bgpd/bgp_encap_types.h b/bgpd/bgp_encap_types.h
index 603ff9d2d624..0e999ccde833 100644
--- a/bgpd/bgp_encap_types.h
+++ b/bgpd/bgp_encap_types.h
@@ -167,10 +167,15 @@ struct 
bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode {
     struct bgp_tea_subtlv_remote_endpoint       st_endpoint;    /* optional */
 };
 
+#define VXLAN_ENCAP_MASK_VNID_VALID 0x80000000
+#define VXLAN_ENCAP_MASK_MAC_VALID  0x40000000
+
 struct bgp_encap_type_vxlan {
     uint32_t                                   valid_subtlvs;
     struct bgp_tea_subtlv_remote_endpoint       st_endpoint;    /* optional */
-    /* No subtlvs defined in spec? */
+    /* draft-ietf-idr-tunnel-encaps-02 */
+    uint32_t                                    vnid; /* does not include V 
and M bit */
+    uint8_t                                     *mac_address;   /* optional */
 };
 
 struct bgp_encap_type_nvgre {
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index af191f64a472..d1e1c6d19643 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -57,9 +57,12 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, 
Boston, MA
 #include "bgpd/bgp_vty.h"
 #include "bgpd/bgp_mpath.h"
 #include "bgpd/bgp_nht.h"
+#include "bgpd/bgp_encap_types.h"
+#include "bgpd/bgp_encap_tlv.h"
 #include "bgpd/bgp_evpn.h"
 #include "bgpd/bgp_attr_evpn.h"
 
+
 /* Extern from bgp_dump.c */
 extern const char *bgp_origin_str[];
 extern const char *bgp_origin_long_str[];
@@ -4750,6 +4753,12 @@ bgp_static_update_safi (struct bgp *bgp, struct prefix 
*p,
     }
   if(afi == AFI_INTERNAL_L2VPN)
     {
+      struct bgp_encap_type_vxlan bet;
+
+      memset(&bet, 0, sizeof(struct bgp_encap_type_vxlan));
+      if(bgp_static->eth_t_id)
+        bet.vnid = bgp_static->eth_t_id;
+      bgp_encap_type_vxlan_to_tlv(&bet, &attr);
       if (bgp_static->igpnexthop.s_addr)
         {
           union gw_addr add;
-- 
2.1.4


_______________________________________________
Quagga-dev mailing list
Quagga-dev@lists.quagga.net
https://lists.quagga.net/mailman/listinfo/quagga-dev

Reply via email to