summaryrefslogtreecommitdiffstats
path: root/ospfd
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2021-08-12 14:49:54 +0200
committerIgor Ryzhov <iryzhov@nfware.com>2021-08-12 14:49:54 +0200
commit5bd78355d1d454ab6537b8fa455e9e21ac4ded57 (patch)
tree5885217b360c3b238775a4c3964997b0a9f0ff1f /ospfd
parentMerge pull request #9370 from opensourcerouting/rpm-keep-config-master (diff)
downloadfrr-5bd78355d1d454ab6537b8fa455e9e21ac4ded57.tar.xz
frr-5bd78355d1d454ab6537b8fa455e9e21ac4ded57.zip
ospfd: fix initialization when vrf doesn't exist yet
There are a couple of things that are not initialized if the OSPF router is created in a non-existent VRF: - ospf_lsa_maxage_walker - ospf_lsa_refresh_walker - ospf_opaque_type11_lsa_init Rearrange some code to always initialize them and make it easier to find similar problems in the future. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'ospfd')
-rw-r--r--ospfd/ospfd.c62
1 files changed, 27 insertions, 35 deletions
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index 21fa62531..9a421de01 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -291,6 +291,16 @@ static int ospf_area_id_cmp(struct ospf_area *a1, struct ospf_area *a2)
return 0;
}
+static void ospf_add(struct ospf *ospf)
+{
+ listnode_add(om->ospf, ospf);
+}
+
+static void ospf_delete(struct ospf *ospf)
+{
+ listnode_delete(om->ospf, ospf);
+}
+
struct ospf *ospf_new_alloc(unsigned short instance, const char *name)
{
int i;
@@ -366,6 +376,8 @@ struct ospf *ospf_new_alloc(unsigned short instance, const char *name)
new->maxage_delay = OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT;
new->maxage_lsa = route_table_init();
new->t_maxage_walker = NULL;
+ thread_add_timer(master, ospf_lsa_maxage_walker, new,
+ OSPF_LSA_MAXAGE_CHECK_INTERVAL, &new->t_maxage_walker);
/* Max paths initialization */
new->max_multipath = MULTIPATH_NUM;
@@ -376,6 +388,8 @@ struct ospf *ospf_new_alloc(unsigned short instance, const char *name)
new->lsa_refresh_queue.index = 0;
new->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
new->t_lsa_refresher = NULL;
+ thread_add_timer(master, ospf_lsa_refresh_walker, new,
+ new->lsa_refresh_interval, &new->t_lsa_refresher);
new->lsa_refresher_started = monotime(NULL);
new->ibuf = stream_new(OSPF_MAX_PACKET_SIZE + 1);
@@ -390,6 +404,8 @@ struct ospf *ospf_new_alloc(unsigned short instance, const char *name)
ospf_asbr_external_aggregator_init(new);
+ ospf_opaque_type11_lsa_init(new);
+
QOBJ_REG(new, ospf);
new->fd = -1;
@@ -403,23 +419,23 @@ static struct ospf *ospf_new(unsigned short instance, const char *name)
struct ospf *new;
new = ospf_new_alloc(instance, name);
+ ospf_add(new);
+
+ if (new->vrf_id == VRF_UNKNOWN)
+ return new;
if ((ospf_sock_init(new)) < 0) {
- if (new->vrf_id != VRF_UNKNOWN)
- flog_err(
- EC_LIB_SOCKET,
- "%s: ospf_sock_init is unable to open a socket",
- __func__);
+ flog_err(EC_LIB_SOCKET,
+ "%s: ospf_sock_init is unable to open a socket",
+ __func__);
return new;
}
- thread_add_timer(master, ospf_lsa_maxage_walker, new,
- OSPF_LSA_MAXAGE_CHECK_INTERVAL, &new->t_maxage_walker);
- thread_add_timer(master, ospf_lsa_refresh_walker, new,
- new->lsa_refresh_interval, &new->t_lsa_refresher);
-
thread_add_read(master, ospf_read, new, new->fd, &new->t_read);
+ new->oi_running = 1;
+ ospf_router_id_update(new);
+
/*
* Read from non-volatile memory whether this instance is performing a
* graceful restart or not.
@@ -455,16 +471,6 @@ static int ospf_is_ready(struct ospf *ospf)
return 1;
}
-static void ospf_add(struct ospf *ospf)
-{
- listnode_add(om->ospf, ospf);
-}
-
-static void ospf_delete(struct ospf *ospf)
-{
- listnode_delete(om->ospf, ospf);
-}
-
struct ospf *ospf_lookup_by_inst_name(unsigned short instance, const char *name)
{
struct ospf *ospf = NULL;
@@ -483,16 +489,6 @@ struct ospf *ospf_lookup_by_inst_name(unsigned short instance, const char *name)
return NULL;
}
-static void ospf_init(struct ospf *ospf)
-{
- ospf_opaque_type11_lsa_init(ospf);
-
- if (ospf->vrf_id != VRF_UNKNOWN)
- ospf->oi_running = 1;
-
- ospf_router_id_update(ospf);
-}
-
struct ospf *ospf_lookup(unsigned short instance, const char *name)
{
struct ospf *ospf;
@@ -513,12 +509,8 @@ struct ospf *ospf_get(unsigned short instance, const char *name, bool *created)
ospf = ospf_lookup(instance, name);
*created = (ospf == NULL);
- if (ospf == NULL) {
+ if (ospf == NULL)
ospf = ospf_new(instance, name);
- ospf_add(ospf);
-
- ospf_init(ospf);
- }
return ospf;
}