]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: evpn NLRI route type 5 forging
authorPhilippe Guibert <philippe.guibert@6wind.com>
Mon, 5 Sep 2016 12:19:40 +0000 (14:19 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 14 Feb 2017 12:58:58 +0000 (13:58 +0100)
This patch introduces the ability to make route type 5 message
when EVPN is enabled. Picked up paramters are collected from the
bgp extra attribute structure and are the ESI, the ethernet tag
information. In addition to this, nexthop attribute is collected too.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
bgpd/bgp_attr.c
bgpd/bgp_attr.h
bgpd/bgp_evpn.c
bgpd/bgp_evpn.h
bgpd/bgp_packet.c
bgpd/bgp_updgrp_packet.c

index cc2e23ec04d76c5b328dd9ede0920cc1758f7029..70d8ffbcc711dcc864ad4dbddfe43727aec9b797 100644 (file)
@@ -50,6 +50,8 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 # include "bgp_encap_types.h"
 # include "bgp_vnc_types.h"
 #endif
+#include "bgp_encap_types.h"
+#include "bgp_evpn.h"
 
 /* Attribute strings for logging. */
 static const struct message attr_str [] = 
@@ -2858,7 +2860,7 @@ void
 bgp_packet_mpattr_prefix (struct stream *s, afi_t afi, safi_t safi,
                          struct prefix *p, struct prefix_rd *prd,
                           u_char *tag, int addpath_encode,
-                          u_int32_t addpath_tx_id)
+                          u_int32_t addpath_tx_id, struct attr *attr)
 {
   if (safi == SAFI_MPLS_VPN)
     {
@@ -2870,6 +2872,10 @@ 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))
+    {
+      bgp_packet_mpattr_route_type_5(s, p, prd, tag, attr);
+    }
   else
     stream_put_prefix_addpath (s, p, addpath_encode, addpath_tx_id);
 }
@@ -3023,7 +3029,7 @@ bgp_packet_attribute (struct bgp *bgp, struct peer *peer,
                                      AFI_MAX), /* get from NH */
                                     vecarr, attr);
       bgp_packet_mpattr_prefix(s, afi, safi, p, prd, tag,
-                               addpath_encode, addpath_tx_id);
+                               addpath_encode, addpath_tx_id, attr);
       bgp_packet_mpattr_end(s, mpattrlen_pos);
     }
 
@@ -3431,21 +3437,10 @@ void
 bgp_packet_mpunreach_prefix (struct stream *s, struct prefix *p,
                             afi_t afi, safi_t safi, struct prefix_rd *prd,
                             u_char *tag, int addpath_encode,
-                             u_int32_t addpath_tx_id)
+                             u_int32_t addpath_tx_id, struct attr *attr)
 {
-  if (safi == SAFI_MPLS_VPN)
-    {
-      /* addpath TX ID */
-      if (addpath_encode)
-        stream_putl(s, addpath_tx_id);
-
-      stream_putc (s, p->prefixlen + 88);
-      stream_put (s, tag, 3);
-      stream_put (s, prd->val, 8);
-      stream_put (s, &p->u.prefix, PSIZE (p->prefixlen));
-    }
-  else
-    stream_put_prefix_addpath (s, p, addpath_encode, addpath_tx_id);
+  return bgp_packet_mpattr_prefix (s, afi, safi, p, prd,
+                                   tag, addpath_encode, addpath_tx_id, attr);
 }
 
 void
index 3ccf65029cebe45014163c7536f87713ba42c423..bd9d7daf4db72eb2733196811d906c7fafc24bec 100644 (file)
@@ -294,7 +294,8 @@ extern size_t bgp_packet_mpattr_start(struct stream *s, afi_t afi, safi_t safi,
 extern void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi,
                                     struct prefix *p, struct prefix_rd *prd,
                                     u_char *tag, int addpath_encode,
-                                     u_int32_t addpath_tx_id);
+                                     u_int32_t addpath_tx_id,
+                                     struct attr *);
 extern size_t bgp_packet_mpattr_prefix_size(afi_t afi, safi_t safi,
                                             struct prefix *p);
 extern void bgp_packet_mpattr_end(struct stream *s, size_t sizep);
@@ -303,7 +304,7 @@ extern size_t bgp_packet_mpunreach_start (struct stream *s, afi_t afi,
                                          safi_t safi);
 extern void bgp_packet_mpunreach_prefix (struct stream *s, struct prefix *p,
                             afi_t afi, safi_t safi, struct prefix_rd *prd,
-                            u_char *tag, int, u_int32_t);
+                             u_char *tag, int, u_int32_t, struct attr *);
 extern void bgp_packet_mpunreach_end (struct stream *s, size_t attrlen_pnt);
 
 static inline int
index fd785b9a64e8567f01bd5ba3f383d7f42e9fecd9..a9db7d2360a15c5daec06a857c24c858f3882330 100644 (file)
@@ -187,3 +187,54 @@ bgp_nlri_parse_evpn (struct peer *peer, struct attr *attr,
 
   return 0;
 }
+
+void
+bgp_packet_mpattr_route_type_5 (struct stream *s,
+                                struct prefix *p, struct prefix_rd *prd,
+                                u_char *label, struct attr *attr)
+{
+  int len;
+  char temp[16];
+  struct evpn_addr *p_evpn_p;
+
+  memset(&temp, 0, 16);
+  if(p->family != AF_ETHERNET)
+    return;
+  p_evpn_p = &(p->u.prefix_evpn);
+  if (p_evpn_p->flags & IP_PREFIX_V4)
+    len = 8; /* ipv4 */
+  else
+    len = 32; /* ipv6 */
+  stream_putc (s, EVPN_IP_PREFIX);
+  stream_putc (s, 8 /* RD */ + 10 /* ESI */  + 4 /* EthTag */ + 1 + len + 3 /* label */);
+  stream_put (s, prd->val, 8);
+  if(attr && attr->extra)
+    stream_put (s, &(attr->extra->evpn_overlay.eth_s_id), 10);
+  else
+    stream_put (s, &temp, 10);
+  stream_putl (s, p_evpn_p->eth_tag);
+  stream_putc (s, p_evpn_p->ip_prefix_length);
+  if (p_evpn_p->flags & IP_PREFIX_V4)
+    stream_put_ipv4(s, p_evpn_p->ip.v4_addr.s_addr);
+  else
+    stream_put(s, &p_evpn_p->ip.v6_addr, 16);
+  if(attr && attr->extra)
+    {
+      if (p_evpn_p->flags & IP_PREFIX_V4)
+        stream_put_ipv4(s, attr->extra->evpn_overlay.gw_ip.ipv4.s_addr);
+      else
+        stream_put(s, &(attr->extra->evpn_overlay.gw_ip.ipv6), 16);
+    }
+  else
+    {
+      if (p_evpn_p->flags & IP_PREFIX_V4)
+        stream_put_ipv4(s, 0);
+      else
+        stream_put(s, &temp, 16);
+    }
+  if(label)
+    stream_put (s, label, 3);
+  else
+    stream_put3 (s, 0);
+  return;
+}
index a4939623506ccf2bd026d3ce7bece1a187bb2864..d23509304bd374b78f76c36432a576880ac53ad8 100644 (file)
@@ -24,6 +24,10 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 extern int bgp_nlri_parse_evpn (struct peer *peer, struct attr *attr,
                                 struct bgp_nlri *packet, int withdraw);
 
+extern void
+bgp_packet_mpattr_route_type_5 (struct stream *s,
+                                struct prefix *p, struct prefix_rd *prd,
+                                u_char *label, struct attr *attr);
 /* EVPN route types as per RFC7432 and
  * as per draft-ietf-bess-evpn-prefix-advertisement-02
  */
index 9a8722a749db1bd462626a59d3543c1869c42e6d..0dbf41a4a18202b2b94ba60ee1298ec279f116c2 100644 (file)
@@ -51,6 +51,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 #include "bgpd/bgp_mplsvpn.h"
 #include "bgpd/bgp_evpn.h"
 #include "bgpd/bgp_encap.h"
+#include "bgpd/bgp_evpn.h"
 #include "bgpd/bgp_advertise.h"
 #include "bgpd/bgp_vty.h"
 #include "bgpd/bgp_updgrp.h"
index ca1bd1e0e6668b3e7ec7743ee516b4e645996ab6..02979602bf74fd2bef0df1e4fad2d851a59ecf13 100644 (file)
@@ -766,8 +766,9 @@ subgroup_update_packet (struct update_subgroup *subgrp)
                                          (peer_cap_enhe(peer) ? AFI_IP6 :
                                           AFI_MAX), /* get from NH */
                                          &vecarr, adv->baa->attr);
-          bgp_packet_mpattr_prefix (snlri, afi, safi, &rn->p, prd, tag,
-                                    addpath_encode, addpath_tx_id);
+
+          bgp_packet_mpattr_prefix (snlri, afi, safi, &rn->p, prd,
+                                    tag, addpath_encode, addpath_tx_id, adv->baa->attr);
        }
 
       num_pfx++;
@@ -922,7 +923,7 @@ subgroup_withdraw_packet (struct update_subgroup *subgrp)
            }
 
          bgp_packet_mpunreach_prefix (s, &rn->p, afi, safi, prd, NULL,
-                                       addpath_encode, addpath_tx_id);
+                                       addpath_encode, addpath_tx_id, NULL);
        }
 
       num_pfx++;
@@ -1126,7 +1127,7 @@ subgroup_default_withdraw_packet (struct update_subgroup *subgrp)
       mplen_pos = bgp_packet_mpunreach_start (s, afi, safi);
       bgp_packet_mpunreach_prefix (s, &p, afi, safi, NULL, NULL,
                                    addpath_encode,
-                                   BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE);
+                                   BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE, NULL);
 
       /* Set the mp_unreach attr's length */
       bgp_packet_mpunreach_end (s, mplen_pos);