]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/main.c
zebra: only perform shutdown signal processing once
[mirror_frr.git] / zebra / main.c
index 3e44a4170759cf0a4e5e8a6938ae97c589c9336a..253b3087fbf8a88899d62e2070ce0abb6ec2b21d 100644 (file)
@@ -39,6 +39,7 @@
 #include "routemap.h"
 #include "frr_pthread.h"
 
+#include "zebra/zebra_errors.h"
 #include "zebra/rib.h"
 #include "zebra/zserv.h"
 #include "zebra/debug.h"
 #include "zebra/zebra_rnh.h"
 #include "zebra/zebra_pbr.h"
 
+#if defined(HANDLE_NETLINK_FUZZING)
+#include "zebra/kernel_netlink.h"
+#endif /* HANDLE_NETLINK_FUZZING */
+
 #define ZEBRA_PTM_SUPPORT
 
 /* Zebra instance */
@@ -94,6 +99,7 @@ struct option longopts[] = {
        {"ecmp", required_argument, NULL, 'e'},
        {"label_socket", no_argument, NULL, 'l'},
        {"retain", no_argument, NULL, 'r'},
+       {"vrfdefaultname", required_argument, NULL, 'o'},
 #ifdef HAVE_NETLINK
        {"vrfwnetns", no_argument, NULL, 'n'},
        {"nl-bufsize", required_argument, NULL, 's'},
@@ -134,11 +140,24 @@ static void sigint(void)
 {
        struct vrf *vrf;
        struct zebra_vrf *zvrf;
+       struct listnode *ln, *nn;
+       struct zserv *client;
+       static bool sigint_done;
+
+       if (sigint_done)
+               return;
+
+       sigint_done = true;
 
        zlog_notice("Terminating on signal");
 
        frr_early_fini();
 
+       zebra_dplane_pre_finish();
+
+       for (ALL_LIST_ELEMENTS(zebrad.client_list, ln, nn, client))
+               zserv_close_client(client);
+
        list_delete_all_node(zebrad.client_list);
        zebra_ptm_finish();
 
@@ -159,7 +178,26 @@ static void sigint(void)
        prefix_list_reset();
        route_map_finish();
 
-       list_delete_and_null(&zebrad.client_list);
+       list_delete(&zebrad.client_list);
+
+       /* Indicate that all new dplane work has been enqueued. When that
+        * work is complete, the dataplane will enqueue an event
+        * with the 'finalize' function.
+        */
+       zebra_dplane_finish();
+}
+
+/*
+ * Final shutdown step for the zebra main thread. This is run after all
+ * async update processing has completed.
+ */
+int zebra_finalize(struct thread *dummy)
+{
+       zlog_info("Zebra final shutdown");
+
+       /* Stop dplane thread and finish any cleanup */
+       zebra_dplane_shutdown();
+
        work_queue_free_and_null(&zebrad.ribq);
        meta_queue_free(zebrad.mq);
 
@@ -213,8 +251,11 @@ int main(int argc, char **argv)
        struct sockaddr_storage dummy;
        socklen_t dummylen;
 #if defined(HANDLE_ZAPI_FUZZING)
-       char *fuzzing = NULL;
-#endif
+       char *zapi_fuzzing = NULL;
+#endif /* HANDLE_ZAPI_FUZZING */
+#if defined(HANDLE_NETLINK_FUZZING)
+       char *netlink_fuzzing = NULL;
+#endif /* HANDLE_NETLINK_FUZZING */
 
        vrf_configure_backend(VRF_BACKEND_VRF_LITE);
        logicalrouter_configure_backend(LOGICALROUTER_BACKEND_NETNS);
@@ -222,13 +263,16 @@ int main(int argc, char **argv)
        frr_preinit(&zebra_di, argc, argv);
 
        frr_opt_add(
-               "bakz:e:l:r"
+               "bakz:e:l:o:r"
 #ifdef HAVE_NETLINK
                "s:n"
 #endif
 #if defined(HANDLE_ZAPI_FUZZING)
                "c:"
-#endif
+#endif /* HANDLE_ZAPI_FUZZING */
+#if defined(HANDLE_NETLINK_FUZZING)
+               "w:"
+#endif /* HANDLE_NETLINK_FUZZING */
                ,
                longopts,
                "  -b, --batch           Runs in batch mode\n"
@@ -238,14 +282,18 @@ int main(int argc, char **argv)
                "  -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"
 #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"
 #endif /* HAVE_NETLINK */
 #if defined(HANDLE_ZAPI_FUZZING)
-               "  -c <file>             Bypass normal startup and use this file for testing of zapi"
-#endif
+               "  -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"
+#endif /* HANDLE_NETLINK_FUZZING */
        );
 
        while (1) {
@@ -270,12 +318,16 @@ int main(int argc, char **argv)
                        multipath_num = atoi(optarg);
                        if (multipath_num > MULTIPATH_NUM
                            || multipath_num <= 0) {
-                               zlog_err(
+                               flog_err(
+                                       EC_ZEBRA_BAD_MULTIPATH_NUM,
                                        "Multipath Number specified must be less than %d and greater than 0",
                                        MULTIPATH_NUM);
                                return 1;
                        }
                        break;
+               case 'o':
+                       vrf_set_default_name(optarg);
+                       break;
                case 'z':
                        zserv_path = optarg;
                        if (!frr_zclient_addr(&dummy, &dummylen, optarg)) {
@@ -306,9 +358,19 @@ int main(int argc, char **argv)
 #endif /* HAVE_NETLINK */
 #if defined(HANDLE_ZAPI_FUZZING)
                case 'c':
-                       fuzzing = optarg;
+                       zapi_fuzzing = optarg;
                        break;
-#endif
+#endif /* HANDLE_ZAPI_FUZZING */
+#if defined(HANDLE_NETLINK_FUZZING)
+               case 'w':
+                       netlink_fuzzing = optarg;
+                       /* This ensures we are aren't writing any of the
+                        * startup netlink messages that happen when we
+                        * just want to read.
+                        */
+                       netlink_read = true;
+                       break;
+#endif /* HANDLE_NETLINK_FUZZING */
                default:
                        frr_help_exit(1);
                        break;
@@ -384,12 +446,21 @@ int main(int argc, char **argv)
        /* RNH init */
        zebra_rnh_init();
 
+       /* Error init */
+       zebra_error_init();
+
 #if defined(HANDLE_ZAPI_FUZZING)
-       if (fuzzing) {
-               zserv_read_file(fuzzing);
+       if (zapi_fuzzing) {
+               zserv_read_file(zapi_fuzzing);
                exit(0);
        }
-#endif
+#endif /* HANDLE_ZAPI_FUZZING */
+#if defined(HANDLE_NETLINK_FUZZING)
+       if (netlink_fuzzing) {
+               netlink_read_init(netlink_fuzzing);
+               exit(0);
+       }
+#endif /* HANDLE_NETLINK_FUZZING */
 
 
        frr_run(zebrad.master);