1 // SPDX-License-Identifier: ISC
3 * FRR switchable defaults.
4 * Copyright (C) 2017-2019 David Lamparter for NetDEF, Inc.
7 #ifndef _FRR_DEFAULTS_H
8 #define _FRR_DEFAULTS_H
18 /* frr_default wraps information about a default that has different
19 * values depending on FRR version or default-set
21 * frr_default_entry describes one match rule and the resulting value;
22 * entries are evaluated in order and the first matching is used.
24 * If both match_version and match_profile are specified, they must both
25 * match. A NULL value matches everything.
27 struct frr_default_entry
{
28 /* syntax: "(<|<=|==|>=|>) [whitespace] version", e.g.
31 const char *match_version
;
32 /* exact profile string to compare against */
33 const char *match_profile
;
39 unsigned long val_ulong
;
43 /* one struct frr_default exists for each malleable default value */
45 struct frr_default
*next
;
47 /* for UI/debug use */
50 /* the following two sets of variables differ because the written
51 * config always targets the *current* FRR version
53 * e.g. if you load a config that has "frr version 5.0" on 6.0
54 * *dflt_long => set to the default value in 5.0
55 * *save_long => set to the default value in 6.0
56 * config save will write "frr version 6.0" with 6.0 defaults
59 /* variable holding the default value for reading/use */
61 const char **dflt_str
;
63 unsigned long *dflt_ulong
;
66 /* variable to use when comparing for config save */
68 const char **save_str
;
70 unsigned long *save_ulong
;
73 struct frr_default_entry entries
[];
76 #define _FRR_CFG_DEFAULT(type, typname, varname, ...) \
77 static type DFLT_##varname; \
78 static type SAVE_##varname; \
79 static struct frr_default _dflt_##varname = { \
81 .dflt_##typname = &DFLT_##varname, \
82 .save_##typname = &SAVE_##varname, \
83 .entries = { __VA_ARGS__ }, \
85 static void _dfltinit_##varname(void) \
86 __attribute__((_CONSTRUCTOR(1000))); \
87 static void _dfltinit_##varname(void) \
89 frr_default_add(&_dflt_##varname); \
91 MACRO_REQUIRE_SEMICOLON() /* end */
94 * FRR_CFG_DEFAULT_LONG(SHARP_BLUNTNESS,
95 * { .val_long = 2, .match_version = ">= 10.0" },
96 * { .val_long = 1, .match_profile = "datacenter" },
100 * This will create DFLT_SHARP_BLUNTNESS and SAVE_SHARP_BLUNTNESS variables.
102 * Note: preprocessor defines cannot be used as variable names because they
103 * will be expanded and blow up with a compile error. Use an enum or add an
104 * extra _ at the beginning (e.g. _SHARP_BLUNTNESS => DFLT__SHARP_BLUNTNESS)
106 #define FRR_CFG_DEFAULT_BOOL(varname, ...) \
107 _FRR_CFG_DEFAULT(bool, bool, varname, ## __VA_ARGS__)
108 #define FRR_CFG_DEFAULT_LONG(varname, ...) \
109 _FRR_CFG_DEFAULT(long, long, varname, ## __VA_ARGS__)
110 #define FRR_CFG_DEFAULT_ULONG(varname, ...) \
111 _FRR_CFG_DEFAULT(unsigned long, ulong, varname, ## __VA_ARGS__)
112 #define FRR_CFG_DEFAULT_FLOAT(varname, ...) \
113 _FRR_CFG_DEFAULT(float, float, varname, ## __VA_ARGS__)
114 #define FRR_CFG_DEFAULT_STR(varname, ...) \
115 _FRR_CFG_DEFAULT(const char *, str, varname, ## __VA_ARGS__)
118 /* daemons don't need to call any of these, libfrr handles that */
119 extern void frr_default_add(struct frr_default
*dflt
);
120 extern void frr_defaults_version_set(const char *version
);
121 extern void frr_defaults_profile_set(const char *profile
);
122 extern const char *frr_defaults_version(void);
123 extern const char *frr_defaults_profile(void);
124 extern void frr_defaults_apply(void);
126 extern const char *frr_defaults_profiles
[];
127 extern bool frr_defaults_profile_valid(const char *profile
);
129 /* like strcmp(), but with version ordering */
130 extern int frr_version_cmp(const char *aa
, const char *bb
);
136 #endif /* _FRR_DEFAULTS_H */