]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: use common api in bgp_get 7277/head
authorChirag Shah <chirag@nvidia.com>
Mon, 12 Oct 2020 23:11:58 +0000 (16:11 -0700)
committerChirag Shah <chirag@nvidia.com>
Mon, 12 Oct 2020 23:41:39 +0000 (16:41 -0700)
Use consolidate api in bgp_get and bgp northbound
create callback.

Signed-off-by: Chirag Shah <chirag@nvidia.com>
bgpd/bgp_nb_config.c
bgpd/bgpd.c
bgpd/bgpd.h

index e37017bb04894d390d75ef310645cfbd0db31986..f01325577c4d054978af3db563d2673f51ba7ab0 100644 (file)
@@ -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)
 {
index 30566b2c16f0f6dfd48e3f652753e0d1af11e606..3e2ca70a02c755b1990bedc2f4dbae696b37298c 100644 (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);
 }
 
-/* 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)
index 3e3c6fc9e33ef18e7ae0855d735036e72114a1a3..00f1d5acc993563b4d1f89d292704a4f29173fad 100644 (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,
                                        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))