bgpd: use common api in bgp_get

Use consolidate api in bgp_get and bgp northbound
create callback.

Signed-off-by: Chirag Shah <chirag@nvidia.com>
This commit is contained in:
Chirag Shah 2020-10-12 16:11:58 -07:00
parent a5ab756f24
commit bdaadb91e8
3 changed files with 26 additions and 32 deletions

View file

@ -44,33 +44,6 @@ FRR_CFG_DEFAULT_ULONG(BGP_KEEPALIVE,
{ .val_ulong = 60 }, { .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( int routing_control_plane_protocols_name_validate(
struct nb_cb_create_args *args) struct nb_cb_create_args *args)
{ {

View file

@ -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); return bgp_check_main_socket(create, bgp);
} }
/* Called from VTY commands. */ int bgp_lookup_by_as_name_type(struct bgp **bgp_val, as_t *as, const char *name,
int bgp_get(struct bgp **bgp_val, as_t *as, const char *name,
enum bgp_instance_type inst_type) enum bgp_instance_type inst_type)
{ {
struct bgp *bgp; struct bgp *bgp;
struct vrf *vrf = NULL;
/* Multiple instance check. */ /* Multiple instance check. */
if (name) if (name)
@ -3251,7 +3249,6 @@ int bgp_get(struct bgp **bgp_val, as_t *as, const char *name,
else else
bgp = bgp_get_default(); bgp = bgp_get_default();
/* Already exists. */
if (bgp) { if (bgp) {
if (bgp->as != *as) { if (bgp->as != *as) {
*as = bgp->as; *as = bgp->as;
@ -3262,6 +3259,27 @@ int bgp_get(struct bgp **bgp_val, as_t *as, const char *name,
*bgp_val = bgp; *bgp_val = bgp;
return BGP_SUCCESS; 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); bgp = bgp_create(as, name, inst_type);
if (bgp_option_check(BGP_OPT_NO_ZEBRA) && name) if (bgp_option_check(BGP_OPT_NO_ZEBRA) && name)

View file

@ -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, extern struct peer *peer_lookup_in_view(struct vty *vty, struct bgp *bgp,
const char *ip_str, bool use_json); 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 */ /* Hooks */
DECLARE_HOOK(peer_status_changed, (struct peer * peer), (peer)) DECLARE_HOOK(peer_status_changed, (struct peer * peer), (peer))