diff options
| author | Igor Ryzhov <iryzhov@nfware.com> | 2021-04-29 16:31:15 +0300 |
|---|---|---|
| committer | Igor Ryzhov <iryzhov@nfware.com> | 2021-04-29 16:50:29 +0300 |
| commit | 0d6d0208a55c786513f472ad690bae1788e173fa (patch) | |
| tree | 3ea04e6425faeb0a51e8cd531c99ef4450974161 | |
| parent | d8c3daca19add1c3cedea05e9a30fb33f2b4e9ad (diff) | |
bgpd: fix crash when as/type mismatches in config
When we're trying to create the config for already existing router and
the AS number or instance type mismatches, we're returning the
inconsistency error and don't set the NB entry.
Any subsequent command that configures this router will crash because
every command relies on the existence of the NB entry.
Let's store the entry even when there's a mismatch to prevent the crash.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
| -rw-r--r-- | bgpd/bgp_nb_config.c | 27 | ||||
| -rw-r--r-- | bgpd/bgpd.c | 2 |
2 files changed, 19 insertions, 10 deletions
diff --git a/bgpd/bgp_nb_config.c b/bgpd/bgp_nb_config.c index 307fa4e9bc..1939e78e73 100644 --- a/bgpd/bgp_nb_config.c +++ b/bgpd/bgp_nb_config.c @@ -109,15 +109,24 @@ int bgp_router_create(struct nb_cb_create_args *args) is_new_bgp = (bgp_lookup_by_name(name) == NULL); ret = bgp_get_vty(&bgp, &as, name, inst_type); - switch (ret) { - case BGP_ERR_AS_MISMATCH: - snprintf(args->errmsg, args->errmsg_len, - "BGP instance is already running; AS is %u", - as); - return NB_ERR_INCONSISTENCY; - case BGP_ERR_INSTANCE_MISMATCH: - snprintf(args->errmsg, args->errmsg_len, - "BGP instance type mismatch"); + if (ret) { + switch (ret) { + case BGP_ERR_AS_MISMATCH: + snprintf( + args->errmsg, args->errmsg_len, + "BGP instance is already running; AS is %u", + as); + break; + case BGP_ERR_INSTANCE_MISMATCH: + snprintf(args->errmsg, args->errmsg_len, + "BGP instance type mismatch"); + break; + } + + UNSET_FLAG(bgp->vrf_flags, BGP_VRF_AUTO); + + nb_running_set_entry(args->dnode, bgp); + return NB_ERR_INCONSISTENCY; } diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 20bb5e5320..dcc29f4188 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -3374,13 +3374,13 @@ int bgp_lookup_by_as_name_type(struct bgp **bgp_val, as_t *as, const char *name, bgp = bgp_get_default(); if (bgp) { + *bgp_val = bgp; if (bgp->as != *as) { *as = bgp->as; return BGP_ERR_AS_MISMATCH; } if (bgp->inst_type != inst_type) return BGP_ERR_INSTANCE_MISMATCH; - *bgp_val = bgp; return BGP_SUCCESS; } *bgp_val = NULL; |
