]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: ecommunity show bgp ipv4 flowspec
authorPhilippe Guibert <philippe.guibert@6wind.com>
Mon, 15 Jan 2018 18:17:02 +0000 (19:17 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 30 Mar 2018 12:01:01 +0000 (14:01 +0200)
ecommunity library is modified to return the flowspec ecommunities in
display format.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
bgpd/bgp_ecommunity.c
bgpd/bgp_ecommunity.h
bgpd/bgp_flowspec_private.h

index 8b60ead383d81ea6b6d53ccb0fbb0cba588fb244..54ec7d392b341d7a35e62c7924a8c54870666d46 100644 (file)
 #include "bgpd/bgp_ecommunity.h"
 #include "bgpd/bgp_lcommunity.h"
 #include "bgpd/bgp_aspath.h"
+#include "bgpd/bgp_flowspec_private.h"
+
+/* struct used to dump the rate contained in FS set traffic-rate EC */
+union traffic_rate {
+       float rate_float;
+       uint8_t rate_byte[4];
+};
 
 /* Hash of community attribute. */
 static struct hash *ecomhash;
@@ -661,8 +668,10 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
                }
 
                /* Space between each value.  */
-               if (!first)
+               if (!first) {
                        str_buf[str_pnt++] = ' ';
+                       len++;
+               }
 
                pnt = ecom->val + (i * 8);
 
@@ -727,6 +736,61 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
                                                      "MM:%u", seqnum);
                        } else
                                unk_ecom = 1;
+               } else if (type == ECOMMUNITY_ENCODE_TRANS_EXP) {
+                       sub_type = *pnt++;
+
+                       if (sub_type == ECOMMUNITY_TRAFFIC_ACTION) {
+                               char action[64];
+                               char *ptr = action;
+
+                               if (*(pnt+3) ==
+                                   1 << FLOWSPEC_TRAFFIC_ACTION_TERMINAL)
+                                       ptr += snprintf(ptr, sizeof(action),
+                                                       "terminate (apply)");
+                               else
+                                       ptr += snprintf(ptr, sizeof(action),
+                                                      "eval stops");
+                               if (*(pnt+3) ==
+                                   1 << FLOWSPEC_TRAFFIC_ACTION_SAMPLE)
+                                       snprintf(ptr, sizeof(action) -
+                                                (size_t)(ptr-action),
+                                                ", sample");
+                               len = snprintf(str_buf + str_pnt,
+                                              str_size - len,
+                                             "FS:action %s", action);
+                       } else if (sub_type == ECOMMUNITY_TRAFFIC_RATE) {
+                               union traffic_rate data;
+
+                               data.rate_byte[3] = *(pnt+2);
+                               data.rate_byte[2] = *(pnt+3);
+                               data.rate_byte[1] = *(pnt+4);
+                               data.rate_byte[0] = *(pnt+5);
+                               len = sprintf(
+                                       str_buf + str_pnt,
+                                       "FS:rate %f", data.rate_float);
+                       } else if (sub_type == ECOMMUNITY_REDIRECT_VRF) {
+                               char buf[16];
+
+                               memset(buf, 0, sizeof(buf));
+                               ecommunity_rt_soo_str(buf, (uint8_t *)pnt,
+                                               type &
+                                               ~ECOMMUNITY_ENCODE_TRANS_EXP,
+                                               ECOMMUNITY_ROUTE_TARGET,
+                                               ECOMMUNITY_FORMAT_DISPLAY);
+                               len = snprintf(
+                                       str_buf + str_pnt,
+                                       str_size - len,
+                                       "FS:redirect VRF %s", buf);
+                       } else if (sub_type == ECOMMUNITY_TRAFFIC_MARKING) {
+                               len = sprintf(
+                                       str_buf + str_pnt,
+                                       "FS:marking %u", *(pnt+5));
+                       } else if (sub_type == ECOMMUNITY_REDIRECT_IP_NH) {
+                               len = sprintf(
+                                       str_buf + str_pnt,
+                                       "FS:redirect IP 0x%x", *(pnt+5));
+                       } else
+                               unk_ecom = 1;
                } else
                        unk_ecom = 1;
 
index 028b7a3166efb2a6ca34a140ae0bb8b14260e10f..31ff1481ba1feda89c3c5c82d760829aa7910e9b 100644 (file)
 #define ECOMMUNITY_ENCODE_AS4               0x02
 #define ECOMMUNITY_ENCODE_OPAQUE            0x03
 #define ECOMMUNITY_ENCODE_EVPN              0x06
+#define ECOMMUNITY_ENCODE_TRANS_EXP         0x80 /* Flow Spec */
+/* RFC7674 */
+#define ECOMMUNITY_EXTENDED_COMMUNITY_PART_2 0x81
+#define ECOMMUNITY_EXTENDED_COMMUNITY_PART_3 0x82
 
 /* Low-order octet of the Extended Communities type field.  */
 #define ECOMMUNITY_ROUTE_TARGET             0x02
 #define ECOMMUNITY_SITE_ORIGIN              0x03
+#define ECOMMUNITY_TRAFFIC_RATE             0x06 /* Flow Spec */
+#define ECOMMUNITY_TRAFFIC_ACTION           0x07
+#define ECOMMUNITY_REDIRECT_VRF             0x08
+#define ECOMMUNITY_TRAFFIC_MARKING          0x09
+#define ECOMMUNITY_REDIRECT_IP_NH           0x00
 
 /* Low-order octet of the Extended Communities type field for EVPN types */
 #define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY  0x00
index c82bb7851962e470dd9e7d72a3f87233ff0051fb..4f086a9f7b02956f00da2d1500128b90804dbe6c 100644 (file)
@@ -21,4 +21,9 @@
 
 #define FLOWSPEC_NLRI_SIZELIMIT                        240
 
+/* Flowspec raffic action bit*/
+#define FLOWSPEC_TRAFFIC_ACTION_TERMINAL       1
+#define FLOWSPEC_TRAFFIC_ACTION_SAMPLE         0
+#define FLOWSPEC_TRAFFIC_ACTION_DISTRIBUTE     1
+
 #endif /* _FRR_BGP_FLOWSPEC_PRIVATE_H */