From fdeb5a813510bcabaf17850f4fdb7a5328c54810 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 8 Mar 2021 15:56:12 -0500 Subject: [PATCH] bgpd: Convert RPKI states to an enum and use them Convert the rpki states to an enum and use them in the code Signed-off-by: Donald Sharp --- bgpd/bgp_route.c | 20 ++++++++++++-------- bgpd/bgp_rpki.c | 6 ++---- bgpd/bgp_rpki.h | 33 +++++++++++++++++++++++++++++++++ bgpd/subdir.am | 1 + 4 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 bgpd/bgp_rpki.h diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index b73c83f190..b19af69067 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -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", diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index 9344384956..3ef0137ba6 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -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 @@ -63,10 +65,6 @@ 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 index 0000000000..4dd4b4a2b2 --- /dev/null +++ b/bgpd/bgp_rpki.h @@ -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 diff --git a/bgpd/subdir.am b/bgpd/subdir.am index 3991f7d1ed..0ca43fd308 100644 --- a/bgpd/subdir.am +++ b/bgpd/subdir.am @@ -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 \ -- 2.39.5