lib/defaults: add bool variable support

(I hadn't initially added this because I thought it superfluous, but it
kinda makes things nicer.)

Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
David Lamparter 2019-12-04 04:20:55 +01:00
parent ac4adef441
commit f210b3e300
2 changed files with 12 additions and 0 deletions

View File

@ -166,6 +166,8 @@ static void frr_default_apply_one(struct frr_default *dflt, bool check)
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)
@ -174,6 +176,8 @@ static void frr_default_apply_one(struct frr_default *dflt, bool check)
*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)

View File

@ -19,6 +19,9 @@
#define _FRR_DEFAULTS_H
#include "config.h"
#include <stdbool.h>
#include "compiler.h"
#ifdef HAVE_DATACENTER
@ -67,6 +70,7 @@ struct frr_default_entry {
const char *match_profile;
/* value to use */
bool val_bool;
const char *val_str;
long val_long;
unsigned long val_ulong;
@ -90,12 +94,14 @@ struct frr_default {
*/
/* 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;
@ -133,6 +139,8 @@ struct frr_default {
* 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, ...) \