summaryrefslogtreecommitdiffstats
path: root/ospfd/ospfd.c
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2021-12-03 23:22:55 +0100
committerIgor Ryzhov <iryzhov@nfware.com>2021-12-21 20:09:29 +0100
commitac2cb9bf9467ada08014b045c52512c625d6c55b (patch)
tree19983a5108d70d705c0810c6f270332712c0d207 /ospfd/ospfd.c
parentMerge pull request #9472 from rampxxxx/pathd_doc_augmented (diff)
downloadfrr-ac2cb9bf9467ada08014b045c52512c625d6c55b.tar.xz
frr-ac2cb9bf9467ada08014b045c52512c625d6c55b.zip
*: rework renaming the default VRF
Currently, it is possible to rename the default VRF either by passing `-o` option to zebra or by creating a file in `/var/run/netns` and binding it to `/proc/self/ns/net`. In both cases, only zebra knows about the rename and other daemons learn about it only after they connect to zebra. This is a problem, because daemons may read their config before they connect to zebra. To handle this rename after the config is read, we have some special code in every single daemon, which is not very bad but not desirable in my opinion. But things are getting worse when we need to handle this in northbound layer as we have to manually rewrite the config nodes. This approach is already hacky, but still works as every daemon handles its own NB structures. But it is completely incompatible with the central management daemon architecture we are aiming for, as mgmtd doesn't even have a connection with zebra to learn from it. And it shouldn't have it, because operational state changes should never affect configuration. To solve the problem and simplify the code, I propose to expand the `-o` option to all daemons. By using the startup option, we let daemons know about the rename before they read their configs so we don't need any special code to deal with it. There's an easy way to pass the option to all daemons by using `frr_global_options` variable. Unfortunately, the second way of renaming by creating a file in `/var/run/netns` is incompatible with the new mgmtd architecture. Theoretically, we could force daemons to read their configs only after they connect to zebra, but it means adding even more code to handle a very specific use-case. And anyway this won't work for mgmtd as it doesn't have a connection with zebra. So I had to remove this option. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'ospfd/ospfd.c')
-rw-r--r--ospfd/ospfd.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index 05433ccb9..e5f3eec60 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -314,22 +314,19 @@ struct ospf *ospf_new_alloc(unsigned short instance, const char *name)
new->instance = instance;
new->router_id.s_addr = htonl(0);
new->router_id_static.s_addr = htonl(0);
- if (name) {
- vrf = vrf_lookup_by_name(name);
- if (vrf)
- new->vrf_id = vrf->vrf_id;
- else
- new->vrf_id = VRF_UNKNOWN;
- /* Freed in ospf_finish_final */
- new->name = XSTRDUP(MTYPE_OSPF_TOP, name);
- if (IS_DEBUG_OSPF_EVENT)
- zlog_debug(
- "%s: Create new ospf instance with vrf_name %s vrf_id %u",
- __func__, name, new->vrf_id);
- } else {
- new->vrf_id = VRF_DEFAULT;
- vrf = vrf_lookup_by_id(VRF_DEFAULT);
- }
+
+ vrf = vrf_lookup_by_name(name);
+ if (vrf)
+ new->vrf_id = vrf->vrf_id;
+ else
+ new->vrf_id = VRF_UNKNOWN;
+
+ /* Freed in ospf_finish_final */
+ new->name = XSTRDUP(MTYPE_OSPF_TOP, name);
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug(
+ "%s: Create new ospf instance with vrf_name %s vrf_id %u",
+ __func__, name, new->vrf_id);
if (vrf)
ospf_vrf_link(new, vrf);
@@ -479,9 +476,6 @@ struct ospf *ospf_lookup_by_inst_name(unsigned short instance, const char *name)
struct ospf *ospf = NULL;
struct listnode *node, *nnode;
- if (name == NULL || strmatch(name, VRF_DEFAULT_NAME))
- return ospf_lookup_by_vrf_id(VRF_DEFAULT);
-
for (ALL_LIST_ELEMENTS(om->ospf, node, nnode, ospf)) {
if ((ospf->instance == instance)
&& ((ospf->name == NULL && name == NULL)
@@ -911,8 +905,7 @@ static void ospf_finish_final(struct ospf *ospf)
if (vrf)
ospf_vrf_unlink(ospf, vrf);
- if (ospf->name)
- XFREE(MTYPE_OSPF_TOP, ospf->name);
+ XFREE(MTYPE_OSPF_TOP, ospf->name);
XFREE(MTYPE_OSPF_TOP, ospf);
}
@@ -2211,10 +2204,6 @@ static int ospf_vrf_enable(struct vrf *vrf)
ospf = ospf_lookup_by_name(vrf->name);
if (ospf) {
- if (ospf->name && strmatch(vrf->name, VRF_DEFAULT_NAME)) {
- XFREE(MTYPE_OSPF_TOP, ospf->name);
- ospf->name = NULL;
- }
old_vrf_id = ospf->vrf_id;
/* We have instance configured, link to VRF and make it "up". */
ospf_vrf_link(ospf, vrf);
@@ -2283,7 +2272,7 @@ static int ospf_vrf_disable(struct vrf *vrf)
void ospf_vrf_init(void)
{
vrf_init(ospf_vrf_new, ospf_vrf_enable, ospf_vrf_disable,
- ospf_vrf_delete, ospf_vrf_enable);
+ ospf_vrf_delete);
}
void ospf_vrf_terminate(void)