]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/main.c
Merge pull request #5789 from donaldsharp/bgp_ebgp_reason
[mirror_frr.git] / zebra / main.c
index b54c36c109eaea698141dc73e224aefe9b862d0b..5951c7e280758959e62a9400680c3d205430f2a2 100644 (file)
 #include "filter.h"
 #include "memory.h"
 #include "zebra_memory.h"
-#include "memory_vty.h"
 #include "prefix.h"
 #include "log.h"
 #include "plist.h"
 #include "privs.h"
 #include "sigevent.h"
 #include "vrf.h"
-#include "logicalrouter.h"
 #include "libfrr.h"
 #include "routemap.h"
-#include "frr_pthread.h"
 
 #include "zebra/zebra_router.h"
 #include "zebra/zebra_errors.h"
@@ -55,6 +52,7 @@
 #include "zebra/zebra_netns_notify.h"
 #include "zebra/zebra_rnh.h"
 #include "zebra/zebra_pbr.h"
+#include "zebra/zebra_vxlan.h"
 
 #if defined(HANDLE_NETLINK_FUZZING)
 #include "zebra/kernel_netlink.h"
 
 #define ZEBRA_PTM_SUPPORT
 
-/* Zebra instance */
-struct zebra_t zebrad = {
-       .rtm_table_default = 0,
-       .packets_to_process = ZEBRA_ZAPI_PACKETS_TO_PROCESS,
-};
-
 /* process id. */
 pid_t pid;
 
@@ -80,8 +72,7 @@ int retain_mode = 0;
 /* Allow non-quagga entities to delete quagga routes */
 int allow_delete = 0;
 
-/* Don't delete kernel route. */
-int keep_kernel_mode = 0;
+int graceful_restart;
 
 bool v6_rr_semantics = false;
 
@@ -92,15 +83,15 @@ uint32_t nl_rcvbufsize = 4194304;
 
 #define OPTION_V6_RR_SEMANTICS 2000
 /* Command line options. */
-struct option longopts[] = {
+const struct option longopts[] = {
        {"batch", no_argument, NULL, 'b'},
        {"allow_delete", no_argument, NULL, 'a'},
        {"keep_kernel", no_argument, NULL, 'k'},
        {"socket", required_argument, NULL, 'z'},
        {"ecmp", required_argument, NULL, 'e'},
-       {"label_socket", no_argument, NULL, 'l'},
        {"retain", no_argument, NULL, 'r'},
        {"vrfdefaultname", required_argument, NULL, 'o'},
+       {"graceful_restart", required_argument, NULL, 'K'},
 #ifdef HAVE_NETLINK
        {"vrfwnetns", no_argument, NULL, 'n'},
        {"nl-bufsize", required_argument, NULL, 's'},
@@ -125,8 +116,6 @@ struct zebra_privs_t zserv_privs = {
        .cap_num_p = array_size(_caps_p),
        .cap_num_i = 0};
 
-unsigned int multipath_num = MULTIPATH_NUM;
-
 /* SIGHUP handler. */
 static void sighup(void)
 {
@@ -152,14 +141,26 @@ static void sigint(void)
 
        zlog_notice("Terminating on signal");
 
+       atomic_store_explicit(&zrouter.in_shutdown, true,
+                             memory_order_relaxed);
+
+       /* send RA lifetime of 0 before stopping. rfc4861/6.2.5 */
+       rtadv_stop_ra_all();
+
        frr_early_fini();
 
        zebra_dplane_pre_finish();
 
-       for (ALL_LIST_ELEMENTS(zebrad.client_list, ln, nn, client))
+       /* Clean up GR related info. */
+       zebra_gr_stale_client_cleanup(zrouter.stale_client_list);
+       list_delete_all_node(zrouter.stale_client_list);
+
+       for (ALL_LIST_ELEMENTS(zrouter.client_list, ln, nn, client))
                zserv_close_client(client);
 
-       list_delete_all_node(zebrad.client_list);
+       zserv_close();
+       list_delete_all_node(zrouter.client_list);
+
        zebra_ptm_finish();
 
        if (retain_mode)
@@ -168,8 +169,9 @@ static void sigint(void)
                        if (zvrf)
                                SET_FLAG(zvrf->flags, ZEBRA_VRF_RETAIN);
                }
-       if (zebrad.lsp_process_q)
-               work_queue_free_and_null(&zebrad.lsp_process_q);
+       if (zrouter.lsp_process_q)
+               work_queue_free_and_null(&zrouter.lsp_process_q);
+
        vrf_terminate();
 
        ns_walk_func(zebra_ns_early_shutdown);
@@ -179,7 +181,7 @@ static void sigint(void)
        prefix_list_reset();
        route_map_finish();
 
-       list_delete(&zebrad.client_list);
+       list_delete(&zrouter.client_list);
 
        /* Indicate that all new dplane work has been enqueued. When that
         * work is complete, the dataplane will enqueue an event
@@ -202,9 +204,6 @@ int zebra_finalize(struct thread *dummy)
        /* Stop dplane thread and finish any cleanup */
        zebra_dplane_shutdown();
 
-       work_queue_free_and_null(&zebrad.ribq);
-       meta_queue_free(zebrad.mq);
-
        zebra_router_terminate();
 
        frr_fini();
@@ -236,8 +235,9 @@ struct quagga_signal_t zebra_signals[] = {
        },
 };
 
-static const struct frr_yang_module_info *zebra_yang_modules[] = {
+static const struct frr_yang_module_info *const zebra_yang_modules[] = {
        &frr_interface_info,
+       &frr_route_map_info,
 };
 
 FRR_DAEMON_INFO(
@@ -260,8 +260,6 @@ int main(int argc, char **argv)
        // int batch_mode = 0;
        char *zserv_path = NULL;
        char *vrf_default_name_configured = NULL;
-       /* Socket to external label manager */
-       char *lblmgr_path = NULL;
        struct sockaddr_storage dummy;
        socklen_t dummylen;
 #if defined(HANDLE_ZAPI_FUZZING)
@@ -271,13 +269,13 @@ int main(int argc, char **argv)
        char *netlink_fuzzing = NULL;
 #endif /* HANDLE_NETLINK_FUZZING */
 
+       graceful_restart = 0;
        vrf_configure_backend(VRF_BACKEND_VRF_LITE);
-       logicalrouter_configure_backend(LOGICALROUTER_BACKEND_NETNS);
 
        frr_preinit(&zebra_di, argc, argv);
 
        frr_opt_add(
-               "bakz:e:l:o:r"
+               "baz:e:o:rK:"
 #ifdef HAVE_NETLINK
                "s:n"
 #endif
@@ -289,24 +287,23 @@ int main(int argc, char **argv)
 #endif /* HANDLE_NETLINK_FUZZING */
                ,
                longopts,
-               "  -b, --batch           Runs in batch mode\n"
-               "  -a, --allow_delete    Allow other processes to delete zebra routes\n"
-               "  -z, --socket          Set path of zebra socket\n"
-               "  -e, --ecmp            Specify ECMP to use.\n"
-               "  -l, --label_socket    Socket to external label manager\n"
-               "  -k, --keep_kernel     Don't delete old routes which were installed by zebra.\n"
-               "  -r, --retain          When program terminates, retain added route by zebra.\n"
-               "  -o, --vrfdefaultname  Set default VRF name.\n"
+               "  -b, --batch              Runs in batch mode\n"
+               "  -a, --allow_delete       Allow other processes to delete zebra routes\n"
+               "  -z, --socket             Set path of zebra socket\n"
+               "  -e, --ecmp               Specify ECMP to use.\n"
+               "  -r, --retain             When program terminates, retain added route by zebra.\n"
+               "  -o, --vrfdefaultname     Set default VRF name.\n"
+               "  -K, --graceful_restart   Graceful restart at the kernel level, timer in seconds for expiration\n"
 #ifdef HAVE_NETLINK
-               "  -n, --vrfwnetns       Use NetNS as VRF backend\n"
-               "  -s, --nl-bufsize      Set netlink receive buffer size\n"
-               "      --v6-rr-semantics Use v6 RR semantics\n"
+               "  -n, --vrfwnetns          Use NetNS as VRF backend\n"
+               "  -s, --nl-bufsize         Set netlink receive buffer size\n"
+               "      --v6-rr-semantics    Use v6 RR semantics\n"
 #endif /* HAVE_NETLINK */
 #if defined(HANDLE_ZAPI_FUZZING)
-               "  -c <file>             Bypass normal startup and use this file for testing of zapi\n"
+               "  -c <file>                Bypass normal startup and use this file for testing of zapi\n"
 #endif /* HANDLE_ZAPI_FUZZING */
 #if defined(HANDLE_NETLINK_FUZZING)
-               "  -w <file>             Bypass normal startup and use this file for testing of netlink input\n"
+               "  -w <file>                Bypass normal startup and use this file for testing of netlink input\n"
 #endif /* HANDLE_NETLINK_FUZZING */
        );
 
@@ -325,13 +322,10 @@ int main(int argc, char **argv)
                case 'a':
                        allow_delete = 1;
                        break;
-               case 'k':
-                       keep_kernel_mode = 1;
-                       break;
                case 'e':
-                       multipath_num = atoi(optarg);
-                       if (multipath_num > MULTIPATH_NUM
-                           || multipath_num <= 0) {
+                       zrouter.multipath_num = atoi(optarg);
+                       if (zrouter.multipath_num > MULTIPATH_NUM
+                           || zrouter.multipath_num <= 0) {
                                flog_err(
                                        EC_ZEBRA_BAD_MULTIPATH_NUM,
                                        "Multipath Number specified must be less than %d and greater than 0",
@@ -351,20 +345,18 @@ int main(int argc, char **argv)
                                exit(1);
                        }
                        break;
-               case 'l':
-                       lblmgr_path = optarg;
-                       break;
                case 'r':
                        retain_mode = 1;
                        break;
+               case 'K':
+                       graceful_restart = atoi(optarg);
+                       break;
 #ifdef HAVE_NETLINK
                case 's':
                        nl_rcvbufsize = atoi(optarg);
                        break;
                case 'n':
                        vrf_configure_backend(VRF_BACKEND_NETNS);
-                       logicalrouter_configure_backend(
-                               LOGICALROUTER_BACKEND_OFF);
                        break;
                case OPTION_V6_RR_SEMANTICS:
                        v6_rr_semantics = true;
@@ -391,10 +383,7 @@ int main(int argc, char **argv)
                }
        }
 
-       zebrad.master = frr_init();
-
-       /* Initialize pthread library */
-       frr_pthread_init();
+       zrouter.master = frr_init();
 
        /* Zebra related initialize. */
        zebra_router_init();
@@ -444,8 +433,9 @@ int main(int argc, char **argv)
        *  will be equal to the current getpid(). To know about such routes,
        * we have to have route_read() called before.
        */
-       if (!keep_kernel_mode)
-               rib_sweep_route();
+       zrouter.startup_time = monotime(NULL);
+       thread_add_timer(zrouter.master, rib_sweep_route,
+                        NULL, graceful_restart, NULL);
 
        /* Needed for BSD routing socket. */
        pid = getpid();
@@ -457,11 +447,14 @@ int main(int argc, char **argv)
        zserv_start(zserv_path);
 
        /* Init label manager */
-       label_manager_init(lblmgr_path);
+       label_manager_init();
 
        /* RNH init */
        zebra_rnh_init();
 
+       /* Config handler Init */
+       zebra_evpn_init();
+
        /* Error init */
        zebra_error_init();
 
@@ -479,7 +472,7 @@ int main(int argc, char **argv)
 #endif /* HANDLE_NETLINK_FUZZING */
 
 
-       frr_run(zebrad.master);
+       frr_run(zrouter.master);
 
        /* Not reached... */
        return 0;