From bdaadb91e8adc103197d8f57a6a3358ff313a23c Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Mon, 12 Oct 2020 16:11:58 -0700 Subject: [PATCH] bgpd: use common api in bgp_get Use consolidate api in bgp_get and bgp northbound create callback. Signed-off-by: Chirag Shah --- bgpd/bgp_nb_config.c | 27 --------------------------- bgpd/bgpd.c | 28 +++++++++++++++++++++++----- bgpd/bgpd.h | 3 +++ 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/bgpd/bgp_nb_config.c b/bgpd/bgp_nb_config.c index e37017bb04..f01325577c 100644 --- a/bgpd/bgp_nb_config.c +++ b/bgpd/bgp_nb_config.c @@ -44,33 +44,6 @@ FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE, { .val_ulong = 60 }, ) - -static int bgp_lookup_by_as_name_type(struct bgp **bgp_val, as_t *as, - const char *name, - enum bgp_instance_type inst_type) -{ - struct bgp *bgp; - - if (name) - bgp = bgp_lookup_by_name(name); - else - bgp = bgp_get_default(); - - if (bgp) { - if (bgp->as != *as) { - *as = bgp->as; - return BGP_ERR_INSTANCE_MISMATCH; - } - if (bgp->inst_type != inst_type) - return BGP_ERR_INSTANCE_MISMATCH; - *bgp_val = bgp; - } else { - *bgp_val = NULL; - } - - return BGP_SUCCESS; -} - int routing_control_plane_protocols_name_validate( struct nb_cb_create_args *args) { diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 30566b2c16..3e2ca70a02 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -3238,12 +3238,10 @@ int bgp_handle_socket(struct bgp *bgp, struct vrf *vrf, vrf_id_t old_vrf_id, return bgp_check_main_socket(create, bgp); } -/* Called from VTY commands. */ -int bgp_get(struct bgp **bgp_val, as_t *as, const char *name, - enum bgp_instance_type inst_type) +int bgp_lookup_by_as_name_type(struct bgp **bgp_val, as_t *as, const char *name, + enum bgp_instance_type inst_type) { struct bgp *bgp; - struct vrf *vrf = NULL; /* Multiple instance check. */ if (name) @@ -3251,7 +3249,6 @@ int bgp_get(struct bgp **bgp_val, as_t *as, const char *name, else bgp = bgp_get_default(); - /* Already exists. */ if (bgp) { if (bgp->as != *as) { *as = bgp->as; @@ -3262,6 +3259,27 @@ int bgp_get(struct bgp **bgp_val, as_t *as, const char *name, *bgp_val = bgp; return BGP_SUCCESS; } + *bgp_val = NULL; + + return BGP_SUCCESS; +} + +/* Called from VTY commands. */ +int bgp_get(struct bgp **bgp_val, as_t *as, const char *name, + enum bgp_instance_type inst_type) +{ + struct bgp *bgp; + struct vrf *vrf = NULL; + int ret = 0; + + ret = bgp_lookup_by_as_name_type(bgp_val, as, name, inst_type); + switch (ret) { + case BGP_ERR_INSTANCE_MISMATCH: + return ret; + case BGP_SUCCESS: + if (*bgp_val) + return ret; + } bgp = bgp_create(as, name, inst_type); if (bgp_option_check(BGP_OPT_NO_ZEBRA) && name) diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 3e3c6fc9e3..00f1d5acc9 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -2181,6 +2181,9 @@ extern struct peer *peer_new(struct bgp *bgp); extern struct peer *peer_lookup_in_view(struct vty *vty, struct bgp *bgp, const char *ip_str, bool use_json); +extern int bgp_lookup_by_as_name_type(struct bgp **bgp_val, as_t *as, + const char *name, + enum bgp_instance_type inst_type); /* Hooks */ DECLARE_HOOK(peer_status_changed, (struct peer * peer), (peer)) -- 2.39.5