]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/libfrr.c
Merge pull request #5793 from ton31337/fix/formatting_show_bgp_summary_failed
[mirror_frr.git] / lib / libfrr.c
index 4301dc20ad957c95661e6d67075df516f4ada59f..4fb43edff28e3d88b431d173313ad35fab2961d9 100644 (file)
@@ -30,7 +30,7 @@
 #include "vty.h"
 #include "command.h"
 #include "version.h"
-#include "memory_vty.h"
+#include "lib_vty.h"
 #include "log_vty.h"
 #include "zclient.h"
 #include "log_int.h"
@@ -42,6 +42,8 @@
 #include "northbound_db.h"
 #include "debug.h"
 #include "frrcu.h"
+#include "frr_pthread.h"
+#include "defaults.h"
 
 DEFINE_HOOK(frr_late_init, (struct thread_master * tm), (tm))
 DEFINE_KOOH(frr_early_fini, (), ())
@@ -103,6 +105,7 @@ static const struct option lo_always[] = {
        {"version", no_argument, NULL, 'v'},
        {"daemon", no_argument, NULL, 'd'},
        {"module", no_argument, NULL, 'M'},
+       {"profile", required_argument, NULL, 'F'},
        {"vty_socket", required_argument, NULL, OPTION_VTYSOCK},
        {"moduledir", required_argument, NULL, OPTION_MODULEDIR},
        {"log", required_argument, NULL, OPTION_LOG},
@@ -111,11 +114,12 @@ static const struct option lo_always[] = {
        {"command-log-always", no_argument, NULL, OPTION_LOGGING},
        {NULL}};
 static const struct optspec os_always = {
-       "hvdM:",
+       "hvdM:F:",
        "  -h, --help         Display this help and exit\n"
        "  -v, --version      Print program version\n"
        "  -d, --daemon       Runs in daemon mode\n"
        "  -M, --module       Load specified module\n"
+       "  -F, --profile      Use specified configuration profile\n"
        "      --vty_socket   Override vty socket path\n"
        "      --moduledir    Override modules directory\n"
        "      --log          Set Logging to stdout, syslog, or file:<name>\n"
@@ -174,7 +178,6 @@ static const struct optspec os_user = {"u:g:",
                                       "  -g, --group        Group to run as\n",
                                       lo_user};
 
-
 bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len,
                      const char *path)
 {
@@ -389,6 +392,32 @@ static int frr_opt(int opt)
                *modnext = oc;
                modnext = &oc->next;
                break;
+       case 'F':
+               if (!frr_defaults_profile_valid(optarg)) {
+                       const char **p;
+                       FILE *ofd = stderr;
+
+                       if (!strcmp(optarg, "help"))
+                               ofd = stdout;
+                       else
+                               fprintf(stderr,
+                                       "The \"%s\" configuration profile is not valid for this FRR version.\n",
+                                       optarg);
+
+                       fprintf(ofd, "Available profiles are:\n");
+                       for (p = frr_defaults_profiles; *p; p++)
+                               fprintf(ofd, "%s%s\n",
+                                       strcmp(*p, DFLT_NAME) ? "   " : " * ",
+                                       *p);
+
+                       if (ofd == stdout)
+                               exit(0);
+                       fprintf(ofd, "\n");
+                       errors++;
+                       break;
+               }
+               frr_defaults_profile_set(optarg);
+               break;
        case 'i':
                if (di->flags & FRR_NO_CFG_PID_DRY)
                        return 1;
@@ -607,6 +636,7 @@ struct thread_master *frr_init(void)
        dir = di->module_path ? di->module_path : frr_moduledir;
 
        srandom(time(NULL));
+       frr_defaults_apply();
 
        if (di->instance) {
                snprintf(frr_protonameinst, sizeof(frr_protonameinst), "%s[%u]",
@@ -678,9 +708,11 @@ struct thread_master *frr_init(void)
                cmd_init(1);
 
        vty_init(master, di->log_always);
-       memory_init();
+       lib_cmd_init();
        log_filter_cmd_init();
 
+       frr_pthread_init();
+
        log_ref_init();
        log_ref_vty_init();
        lib_error_init();
@@ -850,27 +882,34 @@ static void frr_daemonize(void)
  */
 static int frr_config_read_in(struct thread *t)
 {
-       if (!vty_read_config(NULL, di->config_file, config_default) &&
-           di->backup_config_file) {
+       if (!vty_read_config(vty_shared_candidate_config, di->config_file,
+                            config_default)
+           && di->backup_config_file) {
                char *orig = XSTRDUP(MTYPE_TMP, host_config_get());
 
                zlog_info("Attempting to read backup config file: %s specified",
                          di->backup_config_file);
-               vty_read_config(NULL, di->backup_config_file, config_default);
+               vty_read_config(vty_shared_candidate_config,
+                               di->backup_config_file, config_default);
 
                host_config_set(orig);
                XFREE(MTYPE_TMP, orig);
        }
 
        /*
-        * Update the shared candidate after reading the startup configuration.
+        * Automatically commit the candidate configuration after
+        * reading the configuration file.
         */
-       pthread_rwlock_rdlock(&running_config->lock);
-       {
-               nb_config_replace(vty_shared_candidate_config, running_config,
-                                 true);
+       if (frr_get_cli_mode() == FRR_CLI_TRANSACTIONAL) {
+               int ret;
+
+               ret = nb_candidate_commit(vty_shared_candidate_config,
+                                         NB_CLIENT_CLI, NULL, true,
+                                         "Read configuration file", NULL);
+               if (ret != NB_OK && ret != NB_ERR_NO_CHANGES)
+                       zlog_err("%s: failed to read configuration file.",
+                                __func__);
        }
-       pthread_rwlock_unlock(&running_config->lock);
 
        return 0;
 }
@@ -1067,7 +1106,6 @@ void frr_fini(void)
 
        hook_call(frr_fini);
 
-       /* memory_init -> nothing needed */
        vty_terminate();
        cmd_terminate();
        nb_terminate();
@@ -1076,6 +1114,7 @@ void frr_fini(void)
        db_close();
 #endif
        log_ref_fini();
+       frr_pthread_finish();
        zprivs_terminate(di->privs);
        /* signal_init -> nothing needed */
        thread_master_free(master);