]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_ecommunity.c
Merge pull request #3502 from donaldsharp/socket_to_me_baby
[mirror_frr.git] / bgpd / bgp_ecommunity.c
index 85b9ffd8ca27ea859481c37df30df96d02bf19ea..ed0900a7218c93b14df79672bc6f52541631d6e7 100644 (file)
@@ -52,6 +52,11 @@ struct ecommunity *ecommunity_new(void)
                                            sizeof(struct ecommunity));
 }
 
+void ecommunity_strfree(char **s)
+{
+       XFREE(MTYPE_ECOMMUNITY_STR, *s);
+}
+
 /* Allocate ecommunities.  */
 void ecommunity_free(struct ecommunity **ecom)
 {
@@ -60,7 +65,6 @@ void ecommunity_free(struct ecommunity **ecom)
        if ((*ecom)->str)
                XFREE(MTYPE_ECOMMUNITY_STR, (*ecom)->str);
        XFREE(MTYPE_ECOMMUNITY, *ecom);
-       ecom = NULL;
 }
 
 static void ecommunity_hash_free(struct ecommunity *ecom)
@@ -249,16 +253,16 @@ unsigned int ecommunity_hash_make(void *arg)
 }
 
 /* Compare two Extended Communities Attribute structure.  */
-int ecommunity_cmp(const void *arg1, const void *arg2)
+bool ecommunity_cmp(const void *arg1, const void *arg2)
 {
        const struct ecommunity *ecom1 = arg1;
        const struct ecommunity *ecom2 = arg2;
 
        if (ecom1 == NULL && ecom2 == NULL)
-               return 1;
+               return true;
 
        if (ecom1 == NULL || ecom2 == NULL)
-               return 0;
+               return false;
 
        return (ecom1->size == ecom2->size
                && memcmp(ecom1->val, ecom2->val, ecom1->size * ECOMMUNITY_SIZE)
@@ -637,9 +641,9 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
 {
        int i;
        uint8_t *pnt;
-       int type = 0;
-       int sub_type = 0;
-#define ECOMMUNITY_STR_DEFAULT_LEN  27
+       uint8_t type = 0;
+       uint8_t sub_type = 0;
+#define ECOMMUNITY_STR_DEFAULT_LEN  64
        int str_size;
        int str_pnt;
        char *str_buf;
@@ -684,9 +688,23 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
                        /* Low-order octet of type. */
                        sub_type = *pnt++;
                        if (sub_type != ECOMMUNITY_ROUTE_TARGET
-                           && sub_type != ECOMMUNITY_SITE_ORIGIN)
-                               unk_ecom = 1;
-                       else
+                           && sub_type != ECOMMUNITY_SITE_ORIGIN) {
+                               if (sub_type ==
+                                   ECOMMUNITY_FLOWSPEC_REDIRECT_IPV4 &&
+                                   type == ECOMMUNITY_ENCODE_IP) {
+                                       struct in_addr *ipv4 =
+                                               (struct in_addr *)pnt;
+                                       char ipv4str[INET_ADDRSTRLEN];
+
+                                       inet_ntop(AF_INET, ipv4,
+                                                 ipv4str,
+                                                 INET_ADDRSTRLEN);
+                                       len = sprintf(str_buf + str_pnt,
+                                                     "NH:%s:%d",
+                                                     ipv4str, pnt[5]);
+                               } else
+                                       unk_ecom = 1;
+                       } else
                                len = ecommunity_rt_soo_str(str_buf + str_pnt,
                                                            pnt, type, sub_type,
                                                            format);
@@ -735,6 +753,13 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
                                else
                                        len = sprintf(str_buf + str_pnt,
                                                      "MM:%u", seqnum);
+                       } else if (*pnt == ECOMMUNITY_EVPN_SUBTYPE_ND) {
+                               uint8_t flags = *++pnt;
+
+                               if (flags
+                                   & ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG)
+                                       len = sprintf(str_buf + str_pnt,
+                                                     "ND:Router Flag");
                        } else
                                unk_ecom = 1;
                } else if (type == ECOMMUNITY_ENCODE_REDIRECT_IP_NH) {
@@ -745,10 +770,25 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
                                        "FS:redirect IP 0x%x", *(pnt+5));
                        } else
                                unk_ecom = 1;
-               } else if (type == ECOMMUNITY_ENCODE_TRANS_EXP) {
+               } else if (type == ECOMMUNITY_ENCODE_TRANS_EXP ||
+                          type == ECOMMUNITY_EXTENDED_COMMUNITY_PART_2 ||
+                          type == ECOMMUNITY_EXTENDED_COMMUNITY_PART_3) {
                        sub_type = *pnt++;
+                       if (sub_type == ECOMMUNITY_REDIRECT_VRF) {
+                               char buf[16];
 
-                       if (sub_type == ECOMMUNITY_TRAFFIC_ACTION) {
+                               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 (type != ECOMMUNITY_ENCODE_TRANS_EXP)
+                               unk_ecom = 1;
+                       else if (sub_type == ECOMMUNITY_TRAFFIC_ACTION) {
                                char action[64];
                                char *ptr = action;
 
@@ -777,30 +817,35 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
                                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 (*pnt
+                                  == ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT) {
+                               struct ethaddr mac;
+
+                               pnt++;
+                               memcpy(&mac, pnt, ETH_ALEN);
+                               len = sprintf(
+                                       str_buf + str_pnt,
+                                       "ES-Import-Rt:%02x:%02x:%02x:%02x:%02x:%02x",
+                                       (uint8_t)mac.octet[0],
+                                       (uint8_t)mac.octet[1],
+                                       (uint8_t)mac.octet[2],
+                                       (uint8_t)mac.octet[3],
+                                       (uint8_t)mac.octet[4],
+                                       (uint8_t)mac.octet[5]);
                        } else
                                unk_ecom = 1;
-               } else
+               } else {
+                       sub_type = *pnt++;
                        unk_ecom = 1;
+               }
 
                if (unk_ecom)
-                       len = sprintf(str_buf + str_pnt, "?");
+                       len = sprintf(str_buf + str_pnt, "UNK:%d, %d",
+                                     type, sub_type);
 
                str_pnt += len;
                first = 0;