]> git.proxmox.com Git - mirror_frr.git/blob - lib/defaults.h
bgpd: use new defaults system (v2)
[mirror_frr.git] / lib / defaults.h
1 /*
2 * FRR switchable defaults.
3 * Copyright (C) 2017-2019 David Lamparter for NetDEF, Inc.
4 *
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.
8 *
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.
16 */
17
18 #ifndef _FRR_DEFAULTS_H
19 #define _FRR_DEFAULTS_H
20
21 #include "config.h"
22
23 #include <stdbool.h>
24
25 #include "compiler.h"
26
27 #ifdef HAVE_DATACENTER
28
29 #define DFLT_OSPF_LOG_ADJACENCY_CHANGES 1
30 #define DFLT_OSPF6_LOG_ADJACENCY_CHANGES 1
31
32 #else /* !HAVE_DATACENTER */
33
34 #define DFLT_OSPF_LOG_ADJACENCY_CHANGES 0
35 #define DFLT_OSPF6_LOG_ADJACENCY_CHANGES 0
36
37 #endif /* !HAVE_DATACENTER */
38
39 /* frr_default wraps information about a default that has different
40 * values depending on FRR version or default-set
41 *
42 * frr_default_entry describes one match rule and the resulting value;
43 * entries are evaluated in order and the first matching is used.
44 *
45 * If both match_version and match_profile are specified, they must both
46 * match. A NULL value matches everything.
47 */
48 struct frr_default_entry {
49 /* syntax: "(<|<=|==|>=|>) [whitespace] version", e.g.
50 * ">= 6.1-dev" "<6.0"
51 */
52 const char *match_version;
53 /* exact profile string to compare against */
54 const char *match_profile;
55
56 /* value to use */
57 bool val_bool;
58 const char *val_str;
59 long val_long;
60 unsigned long val_ulong;
61 float val_float;
62 };
63
64 /* one struct frr_default exists for each malleable default value */
65 struct frr_default {
66 struct frr_default *next;
67
68 /* for UI/debug use */
69 const char *name;
70
71 /* the following two sets of variables differ because the written
72 * config always targets the *current* FRR version
73 *
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
78 */
79
80 /* variable holding the default value for reading/use */
81 bool *dflt_bool;
82 const char **dflt_str;
83 long *dflt_long;
84 unsigned long *dflt_ulong;
85 float *dflt_float;
86
87 /* variable to use when comparing for config save */
88 bool *save_bool;
89 const char **save_str;
90 long *save_long;
91 unsigned long *save_ulong;
92 float *save_float;
93
94 struct frr_default_entry entries[];
95 };
96
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 = { \
101 .name = #varname, \
102 .dflt_##typname = &DFLT_##varname, \
103 .save_##typname = &SAVE_##varname, \
104 .entries = { __VA_ARGS__ }, \
105 }; \
106 static void _dfltinit_##varname(void) \
107 __attribute__((_CONSTRUCTOR(1000))); \
108 static void _dfltinit_##varname(void) \
109 { \
110 frr_default_add(&_dflt_##varname); \
111 }
112
113 /* use:
114 * FRR_CFG_DEFAULT_LONG(SHARP_BLUNTNESS,
115 * { .val_long = 2, .match_version = ">= 10.0" },
116 * { .val_long = 1, .match_profile = "datacenter" },
117 * { .val_long = 0 },
118 * )
119 *
120 * This will create DFLT_SHARP_BLUNTNESS and SAVE_SHARP_BLUNTNESS variables.
121 *
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)
125 */
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__)
136
137
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);
145
146 extern const char *frr_defaults_profiles[];
147 extern bool frr_defaults_profile_valid(const char *profile);
148
149 /* like strcmp(), but with version ordering */
150 extern int frr_version_cmp(const char *aa, const char *bb);
151
152 #endif /* _FRR_DEFAULTS_H */