]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_flowspec.c
Merge pull request #3444 from donaldsharp/adj_stuff
[mirror_frr.git] / bgpd / bgp_flowspec.c
index ebfa7dae66f5acfe4604f6fd43c75b68edb6845e..ab8bfcb770c708268db3dcb21a91e1dbd85a433f 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "math.h"
-
 #include <zebra.h>
+#include <math.h>
+
 #include "prefix.h"
+#include "lib_errors.h"
 
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_route.h"
 #include "bgpd/bgp_flowspec.h"
 #include "bgpd/bgp_flowspec_util.h"
 #include "bgpd/bgp_flowspec_private.h"
+#include "bgpd/bgp_ecommunity.h"
+#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
 
 static int bgp_fs_nlri_validate(uint8_t *nlri_content, uint32_t len)
 {
@@ -57,7 +61,8 @@ static int bgp_fs_nlri_validate(uint8_t *nlri_content, uint32_t len)
                                                   len - offset, NULL, &error);
                        break;
                case FLOWSPEC_TCP_FLAGS:
-                       ret = bgp_flowspec_tcpflags_decode(
+               case FLOWSPEC_FRAGMENT:
+                       ret = bgp_flowspec_bitmask_decode(
                                                   BGP_FLOWSPEC_VALIDATE_ONLY,
                                                   nlri_content + offset,
                                                   len - offset, NULL, &error);
@@ -69,12 +74,6 @@ static int bgp_fs_nlri_validate(uint8_t *nlri_content, uint32_t len)
                                                nlri_content + offset,
                                                len - offset, NULL, &error);
                        break;
-               case FLOWSPEC_FRAGMENT:
-                       ret = bgp_flowspec_fragment_type_decode(
-                                               BGP_FLOWSPEC_VALIDATE_ONLY,
-                                               nlri_content + offset,
-                                               len - offset, NULL, &error);
-                       break;
                default:
                        error = -1;
                        break;
@@ -94,7 +93,6 @@ int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr,
        afi_t afi;
        safi_t safi;
        int psize = 0;
-       uint8_t rlen;
        struct prefix p;
        int ret;
        void *temp;
@@ -106,12 +104,13 @@ int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr,
        safi = packet->safi;
 
        if (afi == AFI_IP6) {
-               zlog_err("BGP flowspec IPv6 not supported");
+               flog_err(EC_LIB_DEVELOPMENT, "BGP flowspec IPv6 not supported");
                return -1;
        }
 
        if (packet->length >= FLOWSPEC_NLRI_SIZELIMIT) {
-               zlog_err("BGP flowspec nlri length maximum reached (%u)",
+               flog_err(EC_BGP_FLOWSPEC_PACKET,
+                        "BGP flowspec nlri length maximum reached (%u)",
                         packet->length);
                return -1;
        }
@@ -124,16 +123,20 @@ int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr,
                if (pnt + 1 > lim)
                        return -1;
 
-               psize = rlen = *pnt++;
+               psize = *pnt++;
 
                /* When packet overflow occur return immediately. */
                if (pnt + psize > lim) {
-                       zlog_err("Flowspec NLRI length inconsistent ( size %u seen)",
-                                psize);
+                       flog_err(
+                               EC_BGP_FLOWSPEC_PACKET,
+                               "Flowspec NLRI length inconsistent ( size %u seen)",
+                               psize);
                        return -1;
                }
                if (bgp_fs_nlri_validate(pnt, psize) < 0) {
-                       zlog_err("Bad flowspec format or NLRI options not supported");
+                       flog_err(
+                               EC_BGP_FLOWSPEC_PACKET,
+                               "Bad flowspec format or NLRI options not supported");
                        return -1;
                }
                p.family = AF_FLOWSPEC;
@@ -143,6 +146,37 @@ int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr,
                temp = XCALLOC(MTYPE_TMP, psize);
                memcpy(temp, pnt, psize);
                p.u.prefix_flowspec.ptr = (uintptr_t) temp;
+
+               if (BGP_DEBUG(flowspec, FLOWSPEC)) {
+                       char return_string[BGP_FLOWSPEC_NLRI_STRING_MAX];
+                       char local_string[BGP_FLOWSPEC_NLRI_STRING_MAX*2+16];
+                       char ec_string[BGP_FLOWSPEC_NLRI_STRING_MAX];
+                       char *s = NULL;
+
+                       bgp_fs_nlri_get_string((unsigned char *)
+                                              p.u.prefix_flowspec.ptr,
+                                              p.u.prefix_flowspec.prefixlen,
+                                              return_string,
+                                              NLRI_STRING_FORMAT_MIN, NULL);
+                       snprintf(ec_string, sizeof(ec_string),
+                                "EC{none}");
+                       if (attr && attr->ecommunity) {
+                               s = ecommunity_ecom2str(attr->ecommunity,
+                                               ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
+                               snprintf(ec_string, sizeof(ec_string),
+                                        "EC{%s}",
+                                       s == NULL ? "none" : s);
+
+                               if (s)
+                                       ecommunity_strfree(&s);
+                       }
+                       snprintf(local_string, sizeof(local_string),
+                                "FS Rx %s %s %s %s", withdraw ?
+                                "Withdraw":"Update",
+                                afi2str(afi), return_string,
+                                attr != NULL ? ec_string : "");
+                       zlog_info("%s", local_string);
+               }
                /* Process the route. */
                if (!withdraw)
                        ret = bgp_update(peer, &p, 0, attr,
@@ -155,7 +189,8 @@ int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr,
                                           ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
                                           NULL, NULL, 0, NULL);
                if (ret) {
-                       zlog_err("Flowspec NLRI failed to be %s.",
+                       flog_err(EC_BGP_FLOWSPEC_INSTALLATION,
+                                "Flowspec NLRI failed to be %s.",
                                 attr ? "added" : "withdrawn");
                        return -1;
                }