ospfd: use new defaults mechanism (v2)

Some preprocessor constants converted to enums to make the names usable
in the preprocessor.

v2: better isolation between core and vty code to make future northbound
conversion easier.

Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
David Lamparter 2019-08-01 18:49:50 +02:00
parent 8908161ff7
commit c572fbfe2d
6 changed files with 48 additions and 49 deletions

View File

@ -18,24 +18,10 @@
#ifndef _FRR_DEFAULTS_H #ifndef _FRR_DEFAULTS_H
#define _FRR_DEFAULTS_H #define _FRR_DEFAULTS_H
#include "config.h"
#include <stdbool.h> #include <stdbool.h>
#include "compiler.h" #include "compiler.h"
#ifdef HAVE_DATACENTER
#define DFLT_OSPF_LOG_ADJACENCY_CHANGES 1
#define DFLT_OSPF6_LOG_ADJACENCY_CHANGES 1
#else /* !HAVE_DATACENTER */
#define DFLT_OSPF_LOG_ADJACENCY_CHANGES 0
#define DFLT_OSPF6_LOG_ADJACENCY_CHANGES 0
#endif /* !HAVE_DATACENTER */
/* frr_default wraps information about a default that has different /* frr_default wraps information about a default that has different
* values depending on FRR version or default-set * values depending on FRR version or default-set
* *

View File

@ -51,6 +51,11 @@
DEFINE_QOBJ_TYPE(ospf6) DEFINE_QOBJ_TYPE(ospf6)
FRR_CFG_DEFAULT_BOOL(OSPF6_LOG_ADJACENCY_CHANGES,
{ .val_long = true, .match_profile = "datacenter", },
{ .val_long = false },
)
/* global ospf6d variable */ /* global ospf6d variable */
struct ospf6 *ospf6; struct ospf6 *ospf6;
static struct ospf6_master ospf6_master; static struct ospf6_master ospf6_master;
@ -179,11 +184,6 @@ static struct ospf6 *ospf6_create(vrf_id_t vrf_id)
o->distance_table = route_table_init(); o->distance_table = route_table_init();
/* Enable "log-adjacency-changes" */
#if DFLT_OSPF6_LOG_ADJACENCY_CHANGES
SET_FLAG(o->config_flags, OSPF6_LOG_ADJACENCY_CHANGES);
#endif
QOBJ_REG(o, ospf6); QOBJ_REG(o, ospf6);
return o; return o;
@ -327,6 +327,9 @@ DEFUN_NOSH (router_ospf6,
{ {
if (ospf6 == NULL) { if (ospf6 == NULL) {
ospf6 = ospf6_create(VRF_DEFAULT); ospf6 = ospf6_create(VRF_DEFAULT);
if (DFLT_OSPF6_LOG_ADJACENCY_CHANGES)
SET_FLAG(ospf6->config_flags,
OSPF6_LOG_ADJACENCY_CHANGES);
if (ospf6->router_id == 0) if (ospf6->router_id == 0)
ospf6_router_id_update(); ospf6_router_id_update();
} }
@ -1079,9 +1082,9 @@ static int config_write_ospf6(struct vty *vty)
if (CHECK_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES)) { if (CHECK_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_CHANGES)) {
if (CHECK_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL)) if (CHECK_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL))
vty_out(vty, " log-adjacency-changes detail\n"); vty_out(vty, " log-adjacency-changes detail\n");
else if (!DFLT_OSPF6_LOG_ADJACENCY_CHANGES) else if (!SAVE_OSPF6_LOG_ADJACENCY_CHANGES)
vty_out(vty, " log-adjacency-changes\n"); vty_out(vty, " log-adjacency-changes\n");
} else if (DFLT_OSPF6_LOG_ADJACENCY_CHANGES) { } else if (SAVE_OSPF6_LOG_ADJACENCY_CHANGES) {
vty_out(vty, " no log-adjacency-changes\n"); vty_out(vty, " no log-adjacency-changes\n");
} }

View File

@ -29,6 +29,12 @@ struct ospf6_master {
uint32_t zebra_router_id; uint32_t zebra_router_id;
}; };
/* ospf6->config_flags */
enum {
OSPF6_LOG_ADJACENCY_CHANGES = (1 << 0),
OSPF6_LOG_ADJACENCY_DETAIL = (1 << 1),
};
/* OSPFv3 top level data structure */ /* OSPFv3 top level data structure */
struct ospf6 { struct ospf6 {
/* The relevant vrf_id */ /* The relevant vrf_id */
@ -68,10 +74,8 @@ struct ospf6 {
uint8_t flag; uint8_t flag;
/* Configured flags */ /* Configuration bitmask, refer to enum above */
uint8_t config_flags; uint8_t config_flags;
#define OSPF6_LOG_ADJACENCY_CHANGES (1 << 0)
#define OSPF6_LOG_ADJACENCY_DETAIL (1 << 1)
/* LSA timer parameters */ /* LSA timer parameters */
unsigned int lsa_minarrival; /* LSA minimum arrival in milliseconds. */ unsigned int lsa_minarrival; /* LSA minimum arrival in milliseconds. */

View File

@ -53,6 +53,11 @@
#include "ospfd/ospf_dump.h" #include "ospfd/ospf_dump.h"
#include "ospfd/ospf_bfd.h" #include "ospfd/ospf_bfd.h"
FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES,
{ .val_long = true, .match_profile = "datacenter", },
{ .val_long = false },
)
static const char *const ospf_network_type_str[] = { static const char *const ospf_network_type_str[] = {
"Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT", "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
"VIRTUALLINK", "LOOPBACK"}; "VIRTUALLINK", "LOOPBACK"};
@ -138,6 +143,7 @@ static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty,
struct ospf *ospf = NULL; struct ospf *ospf = NULL;
int idx_vrf = 0, idx_inst = 0; int idx_vrf = 0, idx_inst = 0;
const char *vrf_name = NULL; const char *vrf_name = NULL;
bool created = false;
*instance = 0; *instance = 0;
if (argv_find(argv, argc, "(1-65535)", &idx_inst)) if (argv_find(argv, argc, "(1-65535)", &idx_inst))
@ -149,18 +155,23 @@ static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty,
vrf_name = NULL; vrf_name = NULL;
if (enable) { if (enable) {
/* Allocate VRF aware instance */ /* Allocate VRF aware instance */
ospf = ospf_get(*instance, vrf_name); ospf = ospf_get(*instance, vrf_name, &created);
} else { } else {
ospf = ospf_lookup_by_inst_name(*instance, vrf_name); ospf = ospf_lookup_by_inst_name(*instance, vrf_name);
} }
} else { } else {
if (enable) { if (enable) {
ospf = ospf_get(*instance, NULL); ospf = ospf_get(*instance, NULL, &created);
} else { } else {
ospf = ospf_lookup_instance(*instance); ospf = ospf_lookup_instance(*instance);
} }
} }
if (created) {
if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
}
return ospf; return ospf;
} }
@ -10358,9 +10369,9 @@ static int ospf_config_write_one(struct vty *vty, struct ospf *ospf)
if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
vty_out(vty, " log-adjacency-changes detail\n"); vty_out(vty, " log-adjacency-changes detail\n");
else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES) else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES)
vty_out(vty, " log-adjacency-changes\n"); vty_out(vty, " log-adjacency-changes\n");
} else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) { } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) {
vty_out(vty, " no log-adjacency-changes\n"); vty_out(vty, " no log-adjacency-changes\n");
} }

View File

@ -293,11 +293,6 @@ static struct ospf *ospf_new(unsigned short instance, const char *name)
new->oi_write_q = list_new(); new->oi_write_q = list_new();
new->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; new->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT;
/* Enable "log-adjacency-changes" */
#if DFLT_OSPF_LOG_ADJACENCY_CHANGES
SET_FLAG(new->config, OSPF_LOG_ADJACENCY_CHANGES);
#endif
QOBJ_REG(new, ospf); QOBJ_REG(new, ospf);
new->fd = -1; new->fd = -1;
@ -368,7 +363,7 @@ struct ospf *ospf_lookup_by_inst_name(unsigned short instance, const char *name)
return NULL; return NULL;
} }
struct ospf *ospf_get(unsigned short instance, const char *name) struct ospf *ospf_get(unsigned short instance, const char *name, bool *created)
{ {
struct ospf *ospf; struct ospf *ospf;
@ -379,6 +374,7 @@ struct ospf *ospf_get(unsigned short instance, const char *name)
else else
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
*created = (ospf == NULL);
if (ospf == NULL) { if (ospf == NULL) {
ospf = ospf_new(instance, name); ospf = ospf_new(instance, name);
ospf_add(ospf); ospf_add(ospf);
@ -392,11 +388,12 @@ struct ospf *ospf_get(unsigned short instance, const char *name)
return ospf; return ospf;
} }
struct ospf *ospf_get_instance(unsigned short instance) struct ospf *ospf_get_instance(unsigned short instance, bool *created)
{ {
struct ospf *ospf; struct ospf *ospf;
ospf = ospf_lookup_instance(instance); ospf = ospf_lookup_instance(instance);
*created = (ospf == NULL);
if (ospf == NULL) { if (ospf == NULL) {
ospf = ospf_new(instance, NULL /* VRF_DEFAULT*/); ospf = ospf_new(instance, NULL /* VRF_DEFAULT*/);
ospf_add(ospf); ospf_add(ospf);
@ -574,7 +571,6 @@ static void ospf_finish_final(struct ospf *ospf)
struct ospf_vl_data *vl_data; struct ospf_vl_data *vl_data;
struct listnode *node, *nnode; struct listnode *node, *nnode;
int i; int i;
unsigned short instance = 0;
QOBJ_UNREG(ospf); QOBJ_UNREG(ospf);
@ -745,9 +741,6 @@ static void ospf_finish_final(struct ospf *ospf)
ospf_distance_reset(ospf); ospf_distance_reset(ospf);
route_table_finish(ospf->distance_table); route_table_finish(ospf->distance_table);
if (!CHECK_FLAG(om->options, OSPF_MASTER_SHUTDOWN))
instance = ospf->instance;
list_delete(&ospf->areas); list_delete(&ospf->areas);
list_delete(&ospf->oi_write_q); list_delete(&ospf->oi_write_q);
@ -768,9 +761,6 @@ static void ospf_finish_final(struct ospf *ospf)
} }
XFREE(MTYPE_OSPF_TOP, ospf); XFREE(MTYPE_OSPF_TOP, ospf);
if (!CHECK_FLAG(om->options, OSPF_MASTER_SHUTDOWN))
ospf_get_instance(instance);
} }

View File

@ -117,6 +117,14 @@ struct ospf_redist {
#define ROUTEMAP(R) (R->route_map.map) #define ROUTEMAP(R) (R->route_map.map)
}; };
/* ospf->config */
enum {
OSPF_RFC1583_COMPATIBLE = (1 << 0),
OSPF_OPAQUE_CAPABLE = (1 << 2),
OSPF_LOG_ADJACENCY_CHANGES = (1 << 3),
OSPF_LOG_ADJACENCY_DETAIL = (1 << 4),
};
/* OSPF instance structure. */ /* OSPF instance structure. */
struct ospf { struct ospf {
/* OSPF's running state based on the '[no] router ospf [<instance>]' /* OSPF's running state based on the '[no] router ospf [<instance>]'
@ -151,12 +159,8 @@ struct ospf {
/* NSSA ABR */ /* NSSA ABR */
uint8_t anyNSSA; /* Bump for every NSSA attached. */ uint8_t anyNSSA; /* Bump for every NSSA attached. */
/* Configured variables. */ /* Configuration bitmask, refer to enum above */
uint8_t config; uint8_t config;
#define OSPF_RFC1583_COMPATIBLE (1 << 0)
#define OSPF_OPAQUE_CAPABLE (1 << 2)
#define OSPF_LOG_ADJACENCY_CHANGES (1 << 3)
#define OSPF_LOG_ADJACENCY_DETAIL (1 << 4)
/* Opaque-LSA administrative flags. */ /* Opaque-LSA administrative flags. */
uint8_t opaque; uint8_t opaque;
@ -500,8 +504,9 @@ extern struct zebra_privs_t ospfd_privs;
/* Prototypes. */ /* Prototypes. */
extern const char *ospf_redist_string(unsigned int route_type); extern const char *ospf_redist_string(unsigned int route_type);
extern struct ospf *ospf_lookup_instance(unsigned short); extern struct ospf *ospf_lookup_instance(unsigned short);
extern struct ospf *ospf_get(unsigned short instance, const char *name); extern struct ospf *ospf_get(unsigned short instance, const char *name,
extern struct ospf *ospf_get_instance(unsigned short); bool *created);
extern struct ospf *ospf_get_instance(unsigned short, bool *created);
extern struct ospf *ospf_lookup_by_inst_name(unsigned short instance, extern struct ospf *ospf_lookup_by_inst_name(unsigned short instance,
const char *name); const char *name);
extern struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id); extern struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id);