2 * FRR switchable defaults.
3 * Copyright (C) 2017-2019 David Lamparter for NetDEF, Inc.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #ifndef _FRR_DEFAULTS_H
19 #define _FRR_DEFAULTS_H
29 /* frr_default wraps information about a default that has different
30 * values depending on FRR version or default-set
32 * frr_default_entry describes one match rule and the resulting value;
33 * entries are evaluated in order and the first matching is used.
35 * If both match_version and match_profile are specified, they must both
36 * match. A NULL value matches everything.
38 struct frr_default_entry
{
39 /* syntax: "(<|<=|==|>=|>) [whitespace] version", e.g.
42 const char *match_version
;
43 /* exact profile string to compare against */
44 const char *match_profile
;
50 unsigned long val_ulong
;
54 /* one struct frr_default exists for each malleable default value */
56 struct frr_default
*next
;
58 /* for UI/debug use */
61 /* the following two sets of variables differ because the written
62 * config always targets the *current* FRR version
64 * e.g. if you load a config that has "frr version 5.0" on 6.0
65 * *dflt_long => set to the default value in 5.0
66 * *save_long => set to the default value in 6.0
67 * config save will write "frr version 6.0" with 6.0 defaults
70 /* variable holding the default value for reading/use */
72 const char **dflt_str
;
74 unsigned long *dflt_ulong
;
77 /* variable to use when comparing for config save */
79 const char **save_str
;
81 unsigned long *save_ulong
;
84 struct frr_default_entry entries
[];
87 #define _FRR_CFG_DEFAULT(type, typname, varname, ...) \
88 static type DFLT_##varname; \
89 static type SAVE_##varname; \
90 static struct frr_default _dflt_##varname = { \
92 .dflt_##typname = &DFLT_##varname, \
93 .save_##typname = &SAVE_##varname, \
94 .entries = { __VA_ARGS__ }, \
96 static void _dfltinit_##varname(void) \
97 __attribute__((_CONSTRUCTOR(1000))); \
98 static void _dfltinit_##varname(void) \
100 frr_default_add(&_dflt_##varname); \
102 MACRO_REQUIRE_SEMICOLON() /* end */
105 * FRR_CFG_DEFAULT_LONG(SHARP_BLUNTNESS,
106 * { .val_long = 2, .match_version = ">= 10.0" },
107 * { .val_long = 1, .match_profile = "datacenter" },
111 * This will create DFLT_SHARP_BLUNTNESS and SAVE_SHARP_BLUNTNESS variables.
113 * Note: preprocessor defines cannot be used as variable names because they
114 * will be expanded and blow up with a compile error. Use an enum or add an
115 * extra _ at the beginning (e.g. _SHARP_BLUNTNESS => DFLT__SHARP_BLUNTNESS)
117 #define FRR_CFG_DEFAULT_BOOL(varname, ...) \
118 _FRR_CFG_DEFAULT(bool, bool, varname, ## __VA_ARGS__)
119 #define FRR_CFG_DEFAULT_LONG(varname, ...) \
120 _FRR_CFG_DEFAULT(long, long, varname, ## __VA_ARGS__)
121 #define FRR_CFG_DEFAULT_ULONG(varname, ...) \
122 _FRR_CFG_DEFAULT(unsigned long, ulong, varname, ## __VA_ARGS__)
123 #define FRR_CFG_DEFAULT_FLOAT(varname, ...) \
124 _FRR_CFG_DEFAULT(float, float, varname, ## __VA_ARGS__)
125 #define FRR_CFG_DEFAULT_STR(varname, ...) \
126 _FRR_CFG_DEFAULT(const char *, str, varname, ## __VA_ARGS__)
129 /* daemons don't need to call any of these, libfrr handles that */
130 extern void frr_default_add(struct frr_default
*dflt
);
131 extern void frr_defaults_version_set(const char *version
);
132 extern void frr_defaults_profile_set(const char *profile
);
133 extern const char *frr_defaults_version(void);
134 extern const char *frr_defaults_profile(void);
135 extern void frr_defaults_apply(void);
137 extern const char *frr_defaults_profiles
[];
138 extern bool frr_defaults_profile_valid(const char *profile
);
140 /* like strcmp(), but with version ordering */
141 extern int frr_version_cmp(const char *aa
, const char *bb
);
147 #endif /* _FRR_DEFAULTS_H */