]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_rpki.c
Merge pull request #5703 from ton31337/feature/limit_outgoing_prefixes
[mirror_frr.git] / bgpd / bgp_rpki.c
index 32f599745fe74755589680c3b9cea1f5765c681a..7247210c93d7305300e645a88fd1830271ca8525 100644 (file)
 #include "lib/thread.h"
 #ifndef VTYSH_EXTRACT_PL
 #include "rtrlib/rtrlib.h"
-#include "rtrlib/rtr_mgr.h"
-#include "rtrlib/lib/ip.h"
-#include "rtrlib/transport/tcp/tcp_transport.h"
-#if defined(FOUND_SSH)
-#include "rtrlib/transport/ssh/ssh_transport.h"
-#endif
 #endif
 #include "hook.h"
 #include "libfrr.h"
@@ -76,8 +70,6 @@ DEFINE_MTYPE_STATIC(BGPD, BGP_RPKI_CACHE_GROUP, "BGP RPKI Cache server group")
 #define POLLING_PERIOD_DEFAULT 3600
 #define EXPIRE_INTERVAL_DEFAULT 7200
 #define RETRY_INTERVAL_DEFAULT 600
-#define TIMEOUT_DEFAULT 600
-#define INITIAL_SYNCHRONISATION_TIMEOUT_DEFAULT 30
 
 #define RPKI_DEBUG(...)                                                        \
        if (rpki_debug) {                                                      \
@@ -147,13 +139,11 @@ static int rpki_debug;
 static unsigned int polling_period;
 static unsigned int expire_interval;
 static unsigned int retry_interval;
-static unsigned int timeout;
-static unsigned int initial_synchronisation_timeout;
 static int rpki_sync_socket_rtr;
 static int rpki_sync_socket_bgpd;
 
 static struct cmd_node rpki_node = {RPKI_NODE, "%s(config-rpki)# ", 1};
-static struct route_map_rule_cmd route_match_rpki_cmd = {
+static const struct route_map_rule_cmd route_match_rpki_cmd = {
        "rpki", route_match, route_match_compile, route_match_free};
 
 static void *malloc_wrapper(size_t size)
@@ -416,7 +406,7 @@ static int bgpd_sync_callback(struct thread *thread)
                }
        }
 
-       prefix_free(prefix);
+       prefix_free(&prefix);
        return 0;
 }
 
@@ -538,9 +528,6 @@ static int bgp_rpki_init(struct thread_master *master)
        polling_period = POLLING_PERIOD_DEFAULT;
        expire_interval = EXPIRE_INTERVAL_DEFAULT;
        retry_interval = RETRY_INTERVAL_DEFAULT;
-       timeout = TIMEOUT_DEFAULT;
-       initial_synchronisation_timeout =
-               INITIAL_SYNCHRONISATION_TIMEOUT_DEFAULT;
        install_cli_commands();
        rpki_init_sync_socket();
        return 0;
@@ -756,8 +743,6 @@ static int add_cache(struct cache *cache)
        group.sockets_len = 1;
        group.sockets = &cache->rtr_socket;
 
-       listnode_add(cache_list, cache);
-
        if (rtr_is_running) {
                init_tr_socket(cache);
 
@@ -767,6 +752,8 @@ static int add_cache(struct cache *cache)
                }
        }
 
+       listnode_add(cache_list, cache);
+
        return SUCCESS;
 }
 
@@ -793,7 +780,12 @@ static int add_tcp_cache(const char *host, const char *port,
        cache->rtr_socket = rtr_socket;
        cache->preference = preference;
 
-       return add_cache(cache);
+       int ret = add_cache(cache);
+       if (ret != SUCCESS) {
+               free_cache(cache);
+       }
+
+       return ret;
 }
 
 #if defined(FOUND_SSH)
@@ -829,7 +821,12 @@ static int add_ssh_cache(const char *host, const unsigned int port,
        cache->rtr_socket = rtr_socket;
        cache->preference = preference;
 
-       return add_cache(cache);
+       int ret = add_cache(cache);
+       if (ret != SUCCESS) {
+               free_cache(cache);
+       }
+
+       return ret;
 }
 #endif
 
@@ -869,9 +866,6 @@ static int config_write(struct vty *vty)
                vty_out(vty, "!\n");
                vty_out(vty, "rpki\n");
                vty_out(vty, "  rpki polling_period %d\n", polling_period);
-               vty_out(vty, "  rpki timeout %d\n", timeout);
-               vty_out(vty, "  rpki initial-synchronisation-timeout %d\n",
-                       initial_synchronisation_timeout);
                for (ALL_LIST_ELEMENTS_RO(cache_list, cache_node, cache)) {
                        switch (cache->type) {
                                struct tr_tcp_config *tcp_config;
@@ -1020,48 +1014,64 @@ DEFUN (no_rpki_retry_interval,
        return CMD_SUCCESS;
 }
 
-DEFPY (rpki_timeout,
+#if (CONFDATE > 20200901)
+CPP_NOTICE("bgpd: time to remove rpki timeout")
+CPP_NOTICE("bgpd: this includes rpki_timeout and rpki_synchronisation_timeout")
+#endif
+
+DEFPY_HIDDEN (rpki_timeout,
        rpki_timeout_cmd,
        "rpki timeout (1-4294967295)$to_arg",
        RPKI_OUTPUT_STRING
        "Set timeout\n"
        "Timeout value\n")
 {
-       timeout = to_arg;
+       vty_out(vty,
+               "This config option is deprecated, and is scheduled for removal.\n");
+       vty_out(vty,
+               "This functionality has also already been removed because it caused bugs and was pointless\n");
        return CMD_SUCCESS;
 }
 
-DEFUN (no_rpki_timeout,
+DEFUN_HIDDEN (no_rpki_timeout,
        no_rpki_timeout_cmd,
        "no rpki timeout",
        NO_STR
        RPKI_OUTPUT_STRING
        "Set timeout back to default\n")
 {
-       timeout = TIMEOUT_DEFAULT;
+       vty_out(vty,
+               "This config option is deprecated, and is scheduled for removal.\n");
+       vty_out(vty,
+               "This functionality has also already been removed because it caused bugs and was pointless\n");
        return CMD_SUCCESS;
 }
 
-DEFPY (rpki_synchronisation_timeout,
+DEFPY_HIDDEN (rpki_synchronisation_timeout,
        rpki_synchronisation_timeout_cmd,
        "rpki initial-synchronisation-timeout (1-4294967295)$ito_arg",
        RPKI_OUTPUT_STRING
        "Set a timeout for the initial synchronisation of prefix validation data\n"
        "Timeout value\n")
 {
-       initial_synchronisation_timeout = ito_arg;
+       vty_out(vty,
+               "This config option is deprecated, and is scheduled for removal.\n");
+       vty_out(vty,
+               "This functionality has also already been removed because it caused bugs and was pointless\n");
        return CMD_SUCCESS;
 }
 
-DEFUN (no_rpki_synchronisation_timeout,
+DEFUN_HIDDEN (no_rpki_synchronisation_timeout,
        no_rpki_synchronisation_timeout_cmd,
        "no rpki initial-synchronisation-timeout",
        NO_STR
        RPKI_OUTPUT_STRING
        "Set the initial synchronisation timeout back to default (30 sec.)\n")
 {
-       initial_synchronisation_timeout =
-               INITIAL_SYNCHRONISATION_TIMEOUT_DEFAULT;
+       vty_out(vty,
+               "This config option is deprecated, and is scheduled for removal.\n");
+       vty_out(vty,
+               "This functionality has also already been removed because it caused bugs and was pointless\n");
        return CMD_SUCCESS;
 }
 
@@ -1140,11 +1150,11 @@ DEFPY (no_rpki_cache,
                return CMD_WARNING;
        }
 
-       if (rtr_is_running) {
+       if (rtr_is_running && listcount(cache_list) == 1) {
+               stop();
+       } else if (rtr_is_running) {
                if (rtr_mgr_remove_group(rtr_config, preference) == RTR_ERROR) {
                        vty_out(vty, "Could not remove cache %ld", preference);
-                       if (listcount(cache_list) == 1)
-                               vty_out(vty, " because it is the last cache");
 
                        vty_out(vty, "\n");
                        return CMD_WARNING;
@@ -1224,7 +1234,8 @@ DEFPY (show_rpki_prefix,
                const struct pfx_record *record = &matches[i];
 
                if (record->max_len >= prefix->prefixlen
-                   && ((asn != 0 && asn == record->asn) || asn == 0)) {
+                   && ((asn != 0 && (uint32_t)asn == record->asn)
+                       || asn == 0)) {
                        print_record(&matches[i], vty);
                }
        }
@@ -1397,7 +1408,7 @@ DEFUN (match_rpki,
        "Prefix not found\n")
 {
        VTY_DECLVAR_CONTEXT(route_map_index, index);
-       int ret;
+       enum rmap_compile_rets ret;
 
        ret = route_map_add_match(index, "rpki", argv[2]->arg,
                                  RMAP_EVENT_MATCH_ADDED);
@@ -1409,6 +1420,11 @@ DEFUN (match_rpki,
                case RMAP_COMPILE_ERROR:
                        vty_out(vty, "%% BGP Argument is malformed.\n");
                        return CMD_WARNING_CONFIG_FAILED;
+               case RMAP_COMPILE_SUCCESS:
+                       /*
+                        * Intentionally doing nothing here
+                        */
+                       break;
                }
        }
        return CMD_SUCCESS;
@@ -1425,9 +1441,10 @@ DEFUN (no_match_rpki,
        "Prefix not found\n")
 {
        VTY_DECLVAR_CONTEXT(route_map_index, index);
-       int ret;
+       enum rmap_compile_rets ret;
 
-       ret = route_map_delete_match(index, "rpki", argv[3]->arg);
+       ret = route_map_delete_match(index, "rpki", argv[3]->arg,
+                                    RMAP_EVENT_MATCH_DELETED);
        if (ret) {
                switch (ret) {
                case RMAP_RULE_MISSING:
@@ -1436,6 +1453,11 @@ DEFUN (no_match_rpki,
                case RMAP_COMPILE_ERROR:
                        vty_out(vty, "%% BGP Argument is malformed.\n");
                        break;
+               case RMAP_COMPILE_SUCCESS:
+                       /*
+                        * Nothing to do here
+                        */
+                       break;
                }
                return CMD_WARNING_CONFIG_FAILED;
        }