]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/libfrr.c
*: rework renaming the default VRF
[mirror_frr.git] / lib / libfrr.c
index 0817182f7a462a15db8ff5196f9a3382eb15bbd0..361af49c275d5ad152959e6e39047f0bb0a0ec21 100644 (file)
@@ -44,6 +44,7 @@
 #include "frr_pthread.h"
 #include "defaults.h"
 #include "frrscript.h"
+#include "systemd.h"
 
 DEFINE_HOOK(frr_late_init, (struct thread_master * tm), (tm));
 DEFINE_HOOK(frr_config_pre, (struct thread_master * tm), (tm));
@@ -115,6 +116,7 @@ static const struct option lo_always[] = {
        {"module", no_argument, NULL, 'M'},
        {"profile", required_argument, NULL, 'F'},
        {"pathspace", required_argument, NULL, 'N'},
+       {"vrfdefaultname", required_argument, NULL, 'o'},
        {"vty_socket", required_argument, NULL, OPTION_VTYSOCK},
        {"moduledir", required_argument, NULL, OPTION_MODULEDIR},
        {"scriptdir", required_argument, NULL, OPTION_SCRIPTDIR},
@@ -125,13 +127,14 @@ static const struct option lo_always[] = {
        {"limit-fds", required_argument, NULL, OPTION_LIMIT_FDS},
        {NULL}};
 static const struct optspec os_always = {
-       "hvdM:F:N:",
+       "hvdM:F:N:o:",
        "  -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"
        "  -N, --pathspace    Insert prefix into config & socket paths\n"
+       "  -o, --vrfdefaultname     Set default VRF name.\n"
        "      --vty_socket   Override vty socket path\n"
        "      --moduledir    Override modules directory\n"
        "      --scriptdir    Override scripts directory\n"
@@ -363,6 +366,11 @@ void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv)
 
                startup_fds |= UINT64_C(0x1) << (uint64_t)i;
        }
+
+       /* note this doesn't do anything, it just grabs state, so doing it
+        * early in _preinit is perfect.
+        */
+       systemd_init_env();
 }
 
 bool frr_is_startup_fd(int fd)
@@ -412,7 +420,6 @@ static int frr_opt(int opt)
        switch (opt) {
        case 'h':
                frr_help_exit(0);
-               break;
        case 'v':
                print_version(di->progname);
                exit(0);
@@ -490,6 +497,9 @@ static int frr_opt(int opt)
                snprintf(pidfile_default, sizeof(pidfile_default), "%s/%s.pid",
                         frr_vtydir, di->name);
                break;
+       case 'o':
+               vrf_set_default_name(optarg);
+               break;
 #ifdef HAVE_SQLITE3
        case OPTION_DB_FILE:
                if (di->flags & FRR_NO_CFG_PID_DRY)
@@ -669,13 +679,19 @@ static void frr_mkdir(const char *path, bool strip)
                         strerror(errno));
 }
 
+static void _err_print(const void *cookie, const char *errstr)
+{
+       const char *prefix = (const char *)cookie;
+
+       fprintf(stderr, "%s: %s\n", prefix, errstr);
+}
+
 static struct thread_master *master;
 struct thread_master *frr_init(void)
 {
        struct option_chain *oc;
        struct frrmod_runtime *module;
        struct zprivs_ids_t ids;
-       char moderr[256];
        char p_instance[16] = "", p_pathspace[256] = "";
        const char *dir;
        dir = di->module_path ? di->module_path : frr_moduledir;
@@ -729,11 +745,9 @@ struct thread_master *frr_init(void)
        frrmod_init(di->module);
        while (modules) {
                modules = (oc = modules)->next;
-               module = frrmod_load(oc->arg, dir, moderr, sizeof(moderr));
-               if (!module) {
-                       fprintf(stderr, "%s\n", moderr);
+               module = frrmod_load(oc->arg, dir, _err_print, __func__);
+               if (!module)
                        exit(1);
-               }
                XFREE(MTYPE_TMP, oc);
        }