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
27 #ifdef HAVE_DATACENTER
29 #define DFLT_OSPF_LOG_ADJACENCY_CHANGES 1
30 #define DFLT_OSPF6_LOG_ADJACENCY_CHANGES 1
32 #else /* !HAVE_DATACENTER */
34 #define DFLT_OSPF_LOG_ADJACENCY_CHANGES 0
35 #define DFLT_OSPF6_LOG_ADJACENCY_CHANGES 0
37 #endif /* !HAVE_DATACENTER */
39 /* frr_default wraps information about a default that has different
40 * values depending on FRR version or default-set
42 * frr_default_entry describes one match rule and the resulting value;
43 * entries are evaluated in order and the first matching is used.
45 * If both match_version and match_profile are specified, they must both
46 * match. A NULL value matches everything.
48 struct frr_default_entry
{
49 /* syntax: "(<|<=|==|>=|>) [whitespace] version", e.g.
52 const char *match_version
;
53 /* exact profile string to compare against */
54 const char *match_profile
;
60 unsigned long val_ulong
;
64 /* one struct frr_default exists for each malleable default value */
66 struct frr_default
*next
;
68 /* for UI/debug use */
71 /* the following two sets of variables differ because the written
72 * config always targets the *current* FRR version
74 * e.g. if you load a config that has "frr version 5.0" on 6.0
75 * *dflt_long => set to the default value in 5.0
76 * *save_long => set to the default value in 6.0
77 * config save will write "frr version 6.0" with 6.0 defaults
80 /* variable holding the default value for reading/use */
82 const char **dflt_str
;
84 unsigned long *dflt_ulong
;
87 /* variable to use when comparing for config save */
89 const char **save_str
;
91 unsigned long *save_ulong
;
94 struct frr_default_entry entries
[];
97 #define _FRR_CFG_DEFAULT(type, typname, varname, ...) \
98 static type DFLT_##varname; \
99 static type SAVE_##varname; \
100 static struct frr_default _dflt_##varname = { \
102 .dflt_##typname = &DFLT_##varname, \
103 .save_##typname = &SAVE_##varname, \
104 .entries = { __VA_ARGS__ }, \
106 static void _dfltinit_##varname(void) \
107 __attribute__((_CONSTRUCTOR(1000))); \
108 static void _dfltinit_##varname(void) \
110 frr_default_add(&_dflt_##varname); \
114 * FRR_CFG_DEFAULT_LONG(SHARP_BLUNTNESS,
115 * { .val_long = 2, .match_version = ">= 10.0" },
116 * { .val_long = 1, .match_profile = "datacenter" },
120 * This will create DFLT_SHARP_BLUNTNESS and SAVE_SHARP_BLUNTNESS variables.
122 * Note: preprocessor defines cannot be used as variable names because they
123 * will be expanded and blow up with a compile error. Use an enum or add an
124 * extra _ at the beginning (e.g. _SHARP_BLUNTNESS => DFLT__SHARP_BLUNTNESS)
126 #define FRR_CFG_DEFAULT_BOOL(varname, ...) \
127 _FRR_CFG_DEFAULT(bool, bool, varname, ## __VA_ARGS__)
128 #define FRR_CFG_DEFAULT_LONG(varname, ...) \
129 _FRR_CFG_DEFAULT(long, long, varname, ## __VA_ARGS__)
130 #define FRR_CFG_DEFAULT_ULONG(varname, ...) \
131 _FRR_CFG_DEFAULT(unsigned long, ulong, varname, ## __VA_ARGS__)
132 #define FRR_CFG_DEFAULT_FLOAT(varname, ...) \
133 _FRR_CFG_DEFAULT(float, float, varname, ## __VA_ARGS__)
134 #define FRR_CFG_DEFAULT_STR(varname, ...) \
135 _FRR_CFG_DEFAULT(const char *, str, varname, ## __VA_ARGS__)
138 /* daemons don't need to call any of these, libfrr handles that */
139 extern void frr_default_add(struct frr_default
*dflt
);
140 extern void frr_defaults_version_set(const char *version
);
141 extern void frr_defaults_profile_set(const char *profile
);
142 extern const char *frr_defaults_version(void);
143 extern const char *frr_defaults_profile(void);
144 extern void frr_defaults_apply(void);
146 extern const char *frr_defaults_profiles
[];
147 extern bool frr_defaults_profile_valid(const char *profile
);
149 /* like strcmp(), but with version ordering */
150 extern int frr_version_cmp(const char *aa
, const char *bb
);
152 #endif /* _FRR_DEFAULTS_H */