From 6895b354ef88b30e41c92c0d6efa75cd05dba52a Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 6 Jun 2018 10:13:44 +0200 Subject: [PATCH] ospfd: adaptations to handle vrf alias Some adaptations are done to handle alias when creationg ospf instance. Signed-off-by: Philippe Guibert --- ospfd/ospf_vty.c | 2 ++ ospfd/ospfd.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index fb9770d09a..39f14a00c3 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -145,6 +145,8 @@ static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, if (argv_find(argv, argc, "vrf", &idx_vrf)) { vrf_name = argv[idx_vrf + 1]->arg; + if (vrf_name == NULL || strmatch(vrf_name, VRF_DEFAULT_NAME)) + vrf_name = NULL; if (enable) { /* Allocate VRF aware instance */ ospf = ospf_get(*instance, vrf_name); diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 62de94a475..d311b4da6b 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -234,12 +234,10 @@ static struct ospf *ospf_new(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) { + if (name && !strmatch(name, VRF_DEFAULT_NAME)) { new->vrf_id = VRF_UNKNOWN; /* Freed in ospf_finish_final */ new->name = XSTRDUP(MTYPE_OSPF_TOP, name); - vrf = vrf_lookup_by_name(new->name); if (IS_DEBUG_OSPF_EVENT) zlog_debug( "%s: Create new ospf instance with vrf_name %s vrf_id %u", @@ -381,6 +379,9 @@ 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) @@ -2078,6 +2079,10 @@ 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); -- 2.39.5