{ .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)
{
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)
else
bgp = bgp_get_default();
- /* Already exists. */
if (bgp) {
if (bgp->as != *as) {
*as = bgp->as;
*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)
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))