summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2019-12-06 20:07:42 +0100
committerGitHub <noreply@github.com>2019-12-06 20:07:42 +0100
commit4f6309324798c0b9d21b6ddddf75ce549112cf7e (patch)
treeadd2f053034c6f279ba71d468b8e923eda8107e9 /lib
parentMerge pull request #5332 from mjstapp/remove_zapi_label_flag (diff)
parenttopojson: use empty vtysh.conf for frr-reload.py (diff)
downloadfrr-4f6309324798c0b9d21b6ddddf75ce549112cf7e.tar.xz
frr-4f6309324798c0b9d21b6ddddf75ce549112cf7e.zip
Merge pull request #4765 from opensourcerouting/defaults-v2
lib/*: new config defaults system, v2
Diffstat (limited to 'lib')
-rw-r--r--lib/command.c17
-rw-r--r--lib/defaults.c229
-rw-r--r--lib/defaults.h138
-rw-r--r--lib/grammar_sandbox.c1
-rw-r--r--lib/grammar_sandbox_main.c4
-rw-r--r--lib/lib_vty.c (renamed from lib/memory_vty.c)79
-rw-r--r--lib/lib_vty.h (renamed from lib/memory_vty.h)8
-rw-r--r--lib/libfrr.c38
-rw-r--r--lib/northbound_cli.c3
-rw-r--r--lib/subdir.am7
10 files changed, 482 insertions, 42 deletions
diff --git a/lib/command.c b/lib/command.c
index 9238ae412..d2145d9f5 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -1575,18 +1575,6 @@ DEFUN (show_version,
return CMD_SUCCESS;
}
-/* "Set" version ... ignore version tags */
-DEFUN (frr_version_defaults,
- frr_version_defaults_cmd,
- "frr <version|defaults> LINE...",
- "FRRouting global parameters\n"
- "version configuration was written by\n"
- "set of configuration defaults used\n"
- "version string\n")
-{
- return CMD_SUCCESS;
-}
-
/* Help display function for all node. */
DEFUN (config_help,
config_help_cmd,
@@ -1721,8 +1709,10 @@ static int vty_write_config(struct vty *vty)
vty_out(vty, "!\n");
}
+ if (strcmp(frr_defaults_version(), FRR_VER_SHORT))
+ vty_out(vty, "! loaded from %s\n", frr_defaults_version());
vty_out(vty, "frr version %s\n", FRR_VER_SHORT);
- vty_out(vty, "frr defaults %s\n", DFLT_NAME);
+ vty_out(vty, "frr defaults %s\n", frr_defaults_profile());
vty_out(vty, "!\n");
for (i = 0; i < vector_active(cmdvec); i++)
@@ -2941,7 +2931,6 @@ void cmd_init(int terminal)
install_element(CONFIG_NODE, &no_hostname_cmd);
install_element(CONFIG_NODE, &domainname_cmd);
install_element(CONFIG_NODE, &no_domainname_cmd);
- install_element(CONFIG_NODE, &frr_version_defaults_cmd);
if (terminal > 0) {
install_element(CONFIG_NODE, &debug_memstats_cmd);
diff --git a/lib/defaults.c b/lib/defaults.c
new file mode 100644
index 000000000..71ccc73cc
--- /dev/null
+++ b/lib/defaults.c
@@ -0,0 +1,229 @@
+/*
+ * FRR switchable defaults.
+ * Copyright (c) 2017-2019 David Lamparter, for NetDEF, Inc.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <zebra.h>
+
+#include "defaults.h"
+#include "version.h"
+
+static char df_version[128] = FRR_VER_SHORT, df_profile[128] = DFLT_NAME;
+static struct frr_default *dflt_first = NULL, **dflt_next = &dflt_first;
+
+/* these are global for all FRR daemons. they have to be, since we write an
+ * integrated config with the same value for all daemons.
+ */
+const char *frr_defaults_profiles[] = {
+ "traditional",
+ "datacenter",
+ NULL,
+};
+
+static int version_value(int ch)
+{
+ /* non-ASCII shouldn't happen */
+ if (ch < 0 || ch >= 128)
+ return 2;
+
+ /* ~foo sorts older than nothing */
+ if (ch == '~')
+ return 0;
+ if (ch == '\0')
+ return 1;
+ if (isalpha(ch))
+ return 0x100 + tolower(ch);
+
+ /* punctuation and digits (and everything else) */
+ return 0x200 + ch;
+}
+
+int frr_version_cmp(const char *aa, const char *bb)
+{
+ const char *apos = aa, *bpos = bb;
+
+ /* || is correct, we won't scan past the end of a string since that
+ * doesn't compare equal to anything else */
+ while (apos[0] || bpos[0]) {
+ if (isdigit((unsigned char)apos[0]) &&
+ isdigit((unsigned char)bpos[0])) {
+ unsigned long av, bv;
+ char *aend = NULL, *bend = NULL;
+
+ av = strtoul(apos, &aend, 10);
+ bv = strtoul(bpos, &bend, 10);
+ if (av < bv)
+ return -1;
+ if (av > bv)
+ return 1;
+
+ apos = aend;
+ bpos = bend;
+ continue;
+ }
+
+ int a = version_value(*apos++);
+ int b = version_value(*bpos++);
+
+ if (a < b)
+ return -1;
+ if (a > b)
+ return 1;
+ }
+ return 0;
+}
+
+static void frr_default_apply_one(struct frr_default *dflt, bool check);
+
+void frr_default_add(struct frr_default *dflt)
+{
+ dflt->next = NULL;
+ *dflt_next = dflt;
+ dflt_next = &dflt->next;
+
+ frr_default_apply_one(dflt, true);
+}
+
+static bool frr_match_version(const char *name, const char *vspec,
+ const char *version, bool check)
+{
+ int cmp;
+ static struct spec {
+ const char *str;
+ bool dir, eq;
+ } *s, specs[] = {
+ {"<=", -1, 1},
+ {">=", 1, 1},
+ {"==", 0, 1},
+ {"<", -1, 0},
+ {">", 1, 0},
+ {"=", 0, 1},
+ {NULL, 0, 0},
+ };
+
+ if (!vspec)
+ /* NULL = all versions */
+ return true;
+
+ for (s = specs; s->str; s++)
+ if (!strncmp(s->str, vspec, strlen(s->str)))
+ break;
+ if (!s->str) {
+ if (check)
+ fprintf(stderr, "invalid version specifier for %s: %s",
+ name, vspec);
+ /* invalid version spec, never matches */
+ return false;
+ }
+
+ vspec += strlen(s->str);
+ while (isspace((unsigned char)*vspec))
+ vspec++;
+
+ cmp = frr_version_cmp(version, vspec);
+ if (cmp == s->dir || (s->eq && cmp == 0))
+ return true;
+
+ return false;
+}
+
+static void frr_default_apply_one(struct frr_default *dflt, bool check)
+{
+ struct frr_default_entry *entry = dflt->entries;
+ struct frr_default_entry *dfltentry = NULL, *saveentry = NULL;
+
+ for (; entry->match_version || entry->match_profile; entry++) {
+ if (entry->match_profile
+ && strcmp(entry->match_profile, df_profile))
+ continue;
+
+ if (!dfltentry && frr_match_version(dflt->name,
+ entry->match_version, df_version, check))
+ dfltentry = entry;
+ if (!saveentry && frr_match_version(dflt->name,
+ entry->match_version, FRR_VER_SHORT, check))
+ saveentry = entry;
+
+ if (dfltentry && saveentry && !check)
+ break;
+ }
+ /* found default or arrived at last entry that has NULL,NULL spec */
+
+ if (!dfltentry)
+ dfltentry = entry;
+ if (!saveentry)
+ saveentry = entry;
+
+ if (dflt->dflt_bool)
+ *dflt->dflt_bool = dfltentry->val_bool;
+ if (dflt->dflt_str)
+ *dflt->dflt_str = dfltentry->val_str;
+ if (dflt->dflt_long)
+ *dflt->dflt_long = dfltentry->val_long;
+ if (dflt->dflt_ulong)
+ *dflt->dflt_ulong = dfltentry->val_ulong;
+ if (dflt->dflt_float)
+ *dflt->dflt_float = dfltentry->val_float;
+ if (dflt->save_bool)
+ *dflt->save_bool = saveentry->val_bool;
+ if (dflt->save_str)
+ *dflt->save_str = saveentry->val_str;
+ if (dflt->save_long)
+ *dflt->save_long = saveentry->val_long;
+ if (dflt->save_ulong)
+ *dflt->save_ulong = saveentry->val_ulong;
+ if (dflt->save_float)
+ *dflt->save_float = saveentry->val_float;
+}
+
+void frr_defaults_apply(void)
+{
+ struct frr_default *dflt;
+
+ for (dflt = dflt_first; dflt; dflt = dflt->next)
+ frr_default_apply_one(dflt, false);
+}
+
+bool frr_defaults_profile_valid(const char *profile)
+{
+ const char **p;
+
+ for (p = frr_defaults_profiles; *p; p++)
+ if (!strcmp(profile, *p))
+ return true;
+ return false;
+}
+
+const char *frr_defaults_version(void)
+{
+ return df_version;
+}
+
+const char *frr_defaults_profile(void)
+{
+ return df_profile;
+}
+
+void frr_defaults_version_set(const char *version)
+{
+ strlcpy(df_version, version, sizeof(df_version));
+ frr_defaults_apply();
+}
+
+void frr_defaults_profile_set(const char *profile)
+{
+ strlcpy(df_profile, profile, sizeof(df_profile));
+ frr_defaults_apply();
+}
diff --git a/lib/defaults.h b/lib/defaults.h
new file mode 100644
index 000000000..7cdd18120
--- /dev/null
+++ b/lib/defaults.h
@@ -0,0 +1,138 @@
+/*
+ * FRR switchable defaults.
+ * Copyright (C) 2017-2019 David Lamparter for NetDEF, Inc.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _FRR_DEFAULTS_H
+#define _FRR_DEFAULTS_H
+
+#include <stdbool.h>
+
+#include "compiler.h"
+
+/* frr_default wraps information about a default that has different
+ * values depending on FRR version or default-set
+ *
+ * frr_default_entry describes one match rule and the resulting value;
+ * entries are evaluated in order and the first matching is used.
+ *
+ * If both match_version and match_profile are specified, they must both
+ * match. A NULL value matches everything.
+ */
+struct frr_default_entry {
+ /* syntax: "(<|<=|==|>=|>) [whitespace] version", e.g.
+ * ">= 6.1-dev" "<6.0"
+ */
+ const char *match_version;
+ /* exact profile string to compare against */
+ const char *match_profile;
+
+ /* value to use */
+ bool val_bool;
+ const char *val_str;
+ long val_long;
+ unsigned long val_ulong;
+ float val_float;
+};
+
+/* one struct frr_default exists for each malleable default value */
+struct frr_default {
+ struct frr_default *next;
+
+ /* for UI/debug use */
+ const char *name;
+
+ /* the following two sets of variables differ because the written
+ * config always targets the *current* FRR version
+ *
+ * e.g. if you load a config that has "frr version 5.0" on 6.0
+ * *dflt_long => set to the default value in 5.0
+ * *save_long => set to the default value in 6.0
+ * config save will write "frr version 6.0" with 6.0 defaults
+ */
+
+ /* variable holding the default value for reading/use */
+ bool *dflt_bool;
+ const char **dflt_str;
+ long *dflt_long;
+ unsigned long *dflt_ulong;
+ float *dflt_float;
+
+ /* variable to use when comparing for config save */
+ bool *save_bool;
+ const char **save_str;
+ long *save_long;
+ unsigned long *save_ulong;
+ float *save_float;
+
+ struct frr_default_entry entries[];
+};
+
+#define _FRR_CFG_DEFAULT(type, typname, varname, ...) \
+ static type DFLT_##varname; \
+ static type SAVE_##varname; \
+ static struct frr_default _dflt_##varname = { \
+ .name = #varname, \
+ .dflt_##typname = &DFLT_##varname, \
+ .save_##typname = &SAVE_##varname, \
+ .entries = { __VA_ARGS__ }, \
+ }; \
+ static void _dfltinit_##varname(void) \
+ __attribute__((_CONSTRUCTOR(1000))); \
+ static void _dfltinit_##varname(void) \
+ { \
+ frr_default_add(&_dflt_##varname); \
+ }
+
+/* use:
+ * FRR_CFG_DEFAULT_LONG(SHARP_BLUNTNESS,
+ * { .val_long = 2, .match_version = ">= 10.0" },
+ * { .val_long = 1, .match_profile = "datacenter" },
+ * { .val_long = 0 },
+ * )
+ *
+ * This will create DFLT_SHARP_BLUNTNESS and SAVE_SHARP_BLUNTNESS variables.
+ *
+ * Note: preprocessor defines cannot be used as variable names because they
+ * will be expanded and blow up with a compile error. Use an enum or add an
+ * extra _ at the beginning (e.g. _SHARP_BLUNTNESS => DFLT__SHARP_BLUNTNESS)
+ */
+#define FRR_CFG_DEFAULT_BOOL(varname, ...) \
+ _FRR_CFG_DEFAULT(bool, bool, varname, ## __VA_ARGS__)
+#define FRR_CFG_DEFAULT_LONG(varname, ...) \
+ _FRR_CFG_DEFAULT(long, long, varname, ## __VA_ARGS__)
+#define FRR_CFG_DEFAULT_ULONG(varname, ...) \
+ _FRR_CFG_DEFAULT(unsigned long, ulong, varname, ## __VA_ARGS__)
+#define FRR_CFG_DEFAULT_FLOAT(varname, ...) \
+ _FRR_CFG_DEFAULT(float, float, varname, ## __VA_ARGS__)
+#define FRR_CFG_DEFAULT_STR(varname, ...) \
+ _FRR_CFG_DEFAULT(const char *, str, varname, ## __VA_ARGS__)
+
+
+/* daemons don't need to call any of these, libfrr handles that */
+extern void frr_default_add(struct frr_default *dflt);
+extern void frr_defaults_version_set(const char *version);
+extern void frr_defaults_profile_set(const char *profile);
+extern const char *frr_defaults_version(void);
+extern const char *frr_defaults_profile(void);
+extern void frr_defaults_apply(void);
+
+extern const char *frr_defaults_profiles[];
+extern bool frr_defaults_profile_valid(const char *profile);
+
+/* like strcmp(), but with version ordering */
+extern int frr_version_cmp(const char *aa, const char *bb);
+
+#endif /* _FRR_DEFAULTS_H */
diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c
index c6fd3c04a..a23874a51 100644
--- a/lib/grammar_sandbox.c
+++ b/lib/grammar_sandbox.c
@@ -28,7 +28,6 @@
#endif
#include "command.h"
-#include "memory_vty.h"
#include "graph.h"
#include "linklist.h"
#include "command_match.h"
diff --git a/lib/grammar_sandbox_main.c b/lib/grammar_sandbox_main.c
index 6d28a667b..4bd8f5138 100644
--- a/lib/grammar_sandbox_main.c
+++ b/lib/grammar_sandbox_main.c
@@ -28,7 +28,7 @@
#endif
#include "command.h"
-#include "memory_vty.h"
+#include "lib_vty.h"
static void vty_do_exit(int isexit)
{
@@ -57,7 +57,7 @@ int main(int argc, char **argv)
host.domainname = strdup("testdomainname");
vty_init(master, true);
- memory_init();
+ lib_cmd_init();
yang_init();
nb_init(master, NULL, 0);
diff --git a/lib/memory_vty.c b/lib/lib_vty.c
index 1adc0d7b7..787da08e2 100644
--- a/lib/memory_vty.c
+++ b/lib/lib_vty.c
@@ -1,5 +1,5 @@
/*
- * Memory and dynamic module VTY routine
+ * Assorted library VTY commands
*
* Copyright (C) 1998 Kunihiro Ishiguro
* Copyright (C) 2016-2017 David Lamparter for NetDEF, Inc.
@@ -35,7 +35,8 @@
#include "log.h"
#include "memory.h"
#include "module.h"
-#include "memory_vty.h"
+#include "defaults.h"
+#include "lib_vty.h"
/* Looking up memory status from vty interface. */
#include "vector.h"
@@ -120,11 +121,11 @@ static int qmem_walker(void *arg, struct memgroup *mg, struct memtype *mt)
}
-DEFUN (show_memory,
- show_memory_cmd,
- "show memory",
- "Show running system information\n"
- "Memory statistics\n")
+DEFUN_NOSH (show_memory,
+ show_memory_cmd,
+ "show memory",
+ "Show running system information\n"
+ "Memory statistics\n")
{
#ifdef HAVE_MALLINFO
show_memory_mallinfo(vty);
@@ -134,11 +135,11 @@ DEFUN (show_memory,
return CMD_SUCCESS;
}
-DEFUN (show_modules,
- show_modules_cmd,
- "show modules",
- "Show running system information\n"
- "Loaded modules\n")
+DEFUN_NOSH (show_modules,
+ show_modules_cmd,
+ "show modules",
+ "Show running system information\n"
+ "Loaded modules\n")
{
struct frrmod_runtime *plug = frrmod_list;
@@ -177,8 +178,60 @@ DEFUN (show_modules,
return CMD_SUCCESS;
}
-void memory_init(void)
+DEFUN (frr_defaults,
+ frr_defaults_cmd,
+ "frr defaults PROFILE...",
+ "FRRouting global parameters\n"
+ "set of configuration defaults used\n"
+ "profile string\n")
{
+ char *profile = argv_concat(argv, argc, 2);
+ int rv = CMD_SUCCESS;
+
+ if (!frr_defaults_profile_valid(profile)) {
+ vty_out(vty, "%% WARNING: profile %s is not known in this version\n",
+ profile);
+ rv = CMD_WARNING;
+ }
+ frr_defaults_profile_set(profile);
+ XFREE(MTYPE_TMP, profile);
+ return rv;
+}
+
+DEFUN (frr_version,
+ frr_version_cmd,
+ "frr version VERSION...",
+ "FRRouting global parameters\n"
+ "version configuration was written by\n"
+ "version string\n")
+{
+ char *version = argv_concat(argv, argc, 2);
+
+ frr_defaults_version_set(version);
+ XFREE(MTYPE_TMP, version);
+ return CMD_SUCCESS;
+}
+
+static void defaults_autocomplete(vector comps, struct cmd_token *token)
+{
+ const char **p;
+
+ for (p = frr_defaults_profiles; *p; p++)
+ vector_set(comps, XSTRDUP(MTYPE_COMPLETION, *p));
+}
+
+static const struct cmd_variable_handler default_var_handlers[] = {
+ {.tokenname = "PROFILE", .completions = defaults_autocomplete},
+ {.completions = NULL},
+};
+
+void lib_cmd_init(void)
+{
+ cmd_variable_handler_register(default_var_handlers);
+
+ install_element(CONFIG_NODE, &frr_defaults_cmd);
+ install_element(CONFIG_NODE, &frr_version_cmd);
+
install_element(VIEW_NODE, &show_memory_cmd);
install_element(VIEW_NODE, &show_modules_cmd);
}
diff --git a/lib/memory_vty.h b/lib/lib_vty.h
index 941255be1..48e409ec5 100644
--- a/lib/memory_vty.h
+++ b/lib/lib_vty.h
@@ -18,8 +18,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef _ZEBRA_MEMORY_VTY_H
-#define _ZEBRA_MEMORY_VTY_H
+#ifndef _ZEBRA_LIB_VTY_H
+#define _ZEBRA_LIB_VTY_H
#include "memory.h"
@@ -27,7 +27,7 @@
extern "C" {
#endif
-extern void memory_init(void);
+extern void lib_cmd_init(void);
/* Human friendly string for given byte count */
#define MTYPE_MEMSTR_LEN 20
@@ -37,4 +37,4 @@ extern const char *mtype_memstr(char *, size_t, unsigned long);
}
#endif
-#endif /* _ZEBRA_MEMORY_VTY_H */
+#endif /* _ZEBRA_LIB_VTY_H */
diff --git a/lib/libfrr.c b/lib/libfrr.c
index 8ef32eaa8..4fb43edff 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -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"
@@ -43,6 +43,7 @@
#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, (), ())
@@ -104,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},
@@ -112,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"
@@ -175,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)
{
@@ -390,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;
@@ -608,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]",
@@ -679,7 +708,7 @@ 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();
@@ -1077,7 +1106,6 @@ void frr_fini(void)
hook_call(frr_fini);
- /* memory_init -> nothing needed */
vty_terminate();
cmd_terminate();
nb_terminate();
diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c
index 009e5bd82..17dc25628 100644
--- a/lib/northbound_cli.c
+++ b/lib/northbound_cli.c
@@ -21,6 +21,7 @@
#include "libfrr.h"
#include "version.h"
+#include "defaults.h"
#include "log.h"
#include "lib_errors.h"
#include "command.h"
@@ -486,7 +487,7 @@ static void nb_cli_show_config_cmds(struct vty *vty, struct nb_config *config,
vty_out(vty, "Configuration:\n");
vty_out(vty, "!\n");
vty_out(vty, "frr version %s\n", FRR_VER_SHORT);
- vty_out(vty, "frr defaults %s\n", DFLT_NAME);
+ vty_out(vty, "frr defaults %s\n", frr_defaults_profile());
LY_TREE_FOR (config->dnode, root)
nb_cli_show_dnode_cmds(vty, root, with_defaults);
diff --git a/lib/subdir.am b/lib/subdir.am
index 23b195038..cb6fa7a3b 100644
--- a/lib/subdir.am
+++ b/lib/subdir.am
@@ -18,6 +18,7 @@ lib_libfrr_la_SOURCES = \
lib/command_parse.y \
lib/csv.c \
lib/debug.c \
+ lib/defaults.c \
lib/distribute.c \
lib/ferr.c \
lib/filter.c \
@@ -40,13 +41,13 @@ lib_libfrr_la_SOURCES = \
lib/json.c \
lib/keychain.c \
lib/lib_errors.c \
+ lib/lib_vty.c \
lib/libfrr.c \
lib/linklist.c \
lib/log.c \
lib/log_vty.c \
lib/md5.c \
lib/memory.c \
- lib/memory_vty.c \
lib/mlag.c \
lib/module.c \
lib/mpls.c \
@@ -114,6 +115,7 @@ vtysh_scan += \
$(top_srcdir)/lib/if.c \
$(top_srcdir)/lib/if_rmap.c \
$(top_srcdir)/lib/keychain.c \
+ $(top_srcdir)/lib/lib_vty.c \
$(top_srcdir)/lib/nexthop_group.c \
$(top_srcdir)/lib/plist.c \
$(top_srcdir)/lib/routemap.c \
@@ -156,6 +158,7 @@ pkginclude_HEADERS += \
lib/csv.h \
lib/db.h \
lib/debug.h \
+ lib/defaults.h \
lib/distribute.h \
lib/ferr.h \
lib/filter.h \
@@ -179,6 +182,7 @@ pkginclude_HEADERS += \
lib/json.h \
lib/keychain.h \
lib/lib_errors.h \
+ lib/lib_vty.h \
lib/libfrr.h \
lib/libospf.h \
lib/linklist.h \
@@ -186,7 +190,6 @@ pkginclude_HEADERS += \
lib/log_vty.h \
lib/md5.h \
lib/memory.h \
- lib/memory_vty.h \
lib/module.h \
lib/monotime.h \
lib/mpls.h \