]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib/defaults: add bool variable support
authorDavid Lamparter <equinox@diac24.net>
Wed, 4 Dec 2019 03:20:55 +0000 (04:20 +0100)
committerDavid Lamparter <equinox@diac24.net>
Fri, 6 Dec 2019 14:13:32 +0000 (15:13 +0100)
(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>
lib/defaults.c
lib/defaults.h

index 8a1cfebe1078d295d1a4b8aaf4c3725be28d9225..71ccc73cc620cccbe757a8b8fcadf0084eb12be2 100644 (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)
index ad2f1ad2e7ccb584accb6de9858a428ecf3386c0..b35bdfeaf3a4497735679963dc96f9bcdfb4811f 100644 (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, ...) \