]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Convert RPKI states to an enum and use them
authorDonald Sharp <sharpd@nvidia.com>
Mon, 8 Mar 2021 20:56:12 +0000 (15:56 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Fri, 26 Mar 2021 12:23:33 +0000 (08:23 -0400)
Convert the rpki states to an enum and use them in the code

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
bgpd/bgp_route.c
bgpd/bgp_rpki.c
bgpd/bgp_rpki.h [new file with mode: 0644]
bgpd/subdir.am

index b73c83f190811e67c7ffe2d49cc444c0a19f5d4c..b19af690679c8a90841837146d967e1e26546418 100644 (file)
@@ -71,6 +71,7 @@
 #include "bgpd/bgp_mac.h"
 #include "bgpd/bgp_network.h"
 #include "bgpd/bgp_trace.h"
+#include "bgpd/bgp_rpki.h"
 
 #ifdef ENABLE_BGP_VNC
 #include "bgpd/rfapi/rfapi_backend.h"
@@ -7551,18 +7552,20 @@ static const char *bgp_origin2str(uint8_t origin)
        return "n/a";
 }
 
-static const char *bgp_rpki_validation2str(int v_state)
+static const char *bgp_rpki_validation2str(enum rpki_states v_state)
 {
        switch (v_state) {
-       case 1:
+       case RPKI_NOT_BEING_USED:
+               return "not used";
+       case RPKI_VALID:
                return "valid";
-       case 2:
+       case RPKI_NOTFOUND:
                return "not found";
-       case 3:
+       case RPKI_INVALID:
                return "invalid";
-       default:
-               break;
        }
+
+       assert(!"We should never get here this is a dev escape");
        return "ERROR";
 }
 
@@ -9582,7 +9585,7 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
        int i;
        char *nexthop_hostname =
                bgp_nexthop_hostname(path->peer, path->nexthop);
-       int rpki_validation_state = 0;
+       enum rpki_states rpki_validation_state = RPKI_NOT_BEING_USED;
 
        if (json_paths) {
                json_path = json_object_new_object();
@@ -10190,10 +10193,11 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
        }
 
        const struct prefix *p = bgp_dest_get_prefix(bn);
+
        if (p->family == AF_INET || p->family == AF_INET6)
                rpki_validation_state = hook_call(bgp_rpki_prefix_status,
                                                  path->peer, path->attr, p);
-       if (rpki_validation_state) {
+       if (rpki_validation_state != RPKI_NOT_BEING_USED) {
                if (json_paths)
                        json_object_string_add(
                                json_path, "rpkiValidationState",
index 9344384956ab7f65f308b91c54e19122e3b681e4..3ef0137ba6b27ec17d0da6479d2816a5665d3081 100644 (file)
@@ -47,6 +47,8 @@
 #include "bgpd/bgp_attr.h"
 #include "bgpd/bgp_aspath.h"
 #include "bgpd/bgp_route.h"
+#include "bgpd/bgp_rpki.h"
+
 #include "lib/network.h"
 #include "lib/thread.h"
 #ifndef VTYSH_EXTRACT_PL
 DEFINE_MTYPE_STATIC(BGPD, BGP_RPKI_CACHE, "BGP RPKI Cache server");
 DEFINE_MTYPE_STATIC(BGPD, BGP_RPKI_CACHE_GROUP, "BGP RPKI Cache server group");
 
-#define RPKI_VALID      1
-#define RPKI_NOTFOUND   2
-#define RPKI_INVALID    3
-
 #define POLLING_PERIOD_DEFAULT 3600
 #define EXPIRE_INTERVAL_DEFAULT 7200
 #define RETRY_INTERVAL_DEFAULT 600
diff --git a/bgpd/bgp_rpki.h b/bgpd/bgp_rpki.h
new file mode 100644 (file)
index 0000000..4dd4b4a
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * bgp_rpki code
+ * Copyright (C) 2021 NVIDIA Corporation and Mellanox Technologies, LTD
+ *                    All Rights Reserved
+ *               Donald Sharp
+ *
+ * This file is part of FRR.
+ *
+ * FRR is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * FRR is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef __BGP_RPKI_H__
+#define __BGP_RPKI_H__
+
+enum rpki_states {
+       RPKI_NOT_BEING_USED,
+       RPKI_VALID,
+       RPKI_NOTFOUND,
+       RPKI_INVALID
+};
+
+#endif
index 3991f7d1ed8420bcc6d40fd079006f6142f21d7b..0ca43fd308562e2122a26ac7f49e4c5ff84b09fb 100644 (file)
@@ -176,6 +176,7 @@ noinst_HEADERS += \
        bgpd/bgp_pbr.h \
        bgpd/bgp_rd.h \
        bgpd/bgp_regex.h \
+       bgpd/bgp_rpki.h \
        bgpd/bgp_route.h \
        bgpd/bgp_script.h \
        bgpd/bgp_table.h \