forked from Mirror/frr
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:
parent
a5ab756f24
commit
bdaadb91e8
|
@ -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)
|
||||
{
|
||||
|
|
28
bgpd/bgpd.c
28
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)
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue