]> git.proxmox.com Git - mirror_frr.git/commitdiff
zebra: nexthop groups vrf's are only a function of namespaces
authorDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 13 Jan 2020 21:11:46 +0000 (16:11 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 31 Jan 2020 13:45:51 +0000 (08:45 -0500)
Nexthop groups as a whole do not make sense to have a vrf'ness
As that you can have a arbitrary number of nexthops that point
to separate vrf's.

Modify the code to make this distinction, by clearly delineating
the line between the nhg and the nexthop a bit better.
Nexthop groups having a vrf_id only make sense if you are using
network namespaces to represent them.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
zebra/rt_netlink.c
zebra/zebra_nhg.c
zebra/zebra_nhg.h
zebra/zebra_vty.c

index dd6e62ee6c8569a215a1f6904f84b42bd5d6baeb..fe1c26a34f7703fe804ba7fb46651f6cc8c74c34 100644 (file)
@@ -2364,6 +2364,9 @@ int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
 
        nhm = NLMSG_DATA(h);
 
+       if (ns_id)
+               vrf_id = ns_id;
+
        if (startup && h->nlmsg_type != RTM_NEWNEXTHOP)
                return 0;
 
@@ -2443,7 +2446,7 @@ int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
                        return -1;
 
        } else if (h->nlmsg_type == RTM_DELNEXTHOP)
-               zebra_nhg_kernel_del(id);
+               zebra_nhg_kernel_del(id, vrf_id);
 
        return 0;
 }
index a3b414975ec52bdff738831d13dbb1f5d6e541f3..732349a570621f96c7e95e4bd480a5e0fb40c5b6 100644 (file)
@@ -317,15 +317,15 @@ zebra_nhg_connect_depends(struct nhg_hash_entry *nhe,
                struct interface *ifp = NULL;
 
                ifp = if_lookup_by_index(nhe->nhg->nexthop->ifindex,
-                                        nhe->vrf_id);
+                                        nhe->nhg->nexthop->vrf_id);
                if (ifp)
                        zebra_nhg_set_if(nhe, ifp);
                else
                        flog_err(
                                EC_ZEBRA_IF_LOOKUP_FAILED,
                                "Zebra failed to lookup an interface with ifindex=%d in vrf=%u for NHE id=%u",
-                               nhe->nhg->nexthop->ifindex, nhe->vrf_id,
-                               nhe->id);
+                               nhe->nhg->nexthop->ifindex,
+                               nhe->nhg->nexthop->vrf_id, nhe->id);
        }
 }
 
@@ -535,10 +535,10 @@ static bool zebra_nhg_find(struct nhg_hash_entry **nhe, uint32_t id,
        lookup.type = type ? type : ZEBRA_ROUTE_NHG;
        lookup.nhg = nhg;
 
+       lookup.vrf_id = vrf_id;
        if (lookup.nhg->nexthop->next) {
                /* Groups can have all vrfs and AF's in them */
                lookup.afi = AFI_UNSPEC;
-               lookup.vrf_id = VRF_DEFAULT;
        } else {
                switch (lookup.nhg->nexthop->type) {
                case (NEXTHOP_TYPE_IFINDEX):
@@ -562,8 +562,6 @@ static bool zebra_nhg_find(struct nhg_hash_entry **nhe, uint32_t id,
                        lookup.afi = AFI_IP6;
                        break;
                }
-
-               lookup.vrf_id = vrf_id;
        }
 
        if (id)
@@ -622,10 +620,11 @@ zebra_nhg_find_nexthop(uint32_t id, struct nexthop *nh, afi_t afi, int type)
 {
        struct nhg_hash_entry *nhe = NULL;
        struct nexthop_group nhg = {};
+       vrf_id_t vrf_id = !vrf_is_backend_netns() ? VRF_DEFAULT : nh->vrf_id;
 
        nexthop_group_add_sorted(&nhg, nh);
 
-       zebra_nhg_find(&nhe, id, &nhg, NULL, nh->vrf_id, afi, type);
+       zebra_nhg_find(&nhe, id, &nhg, NULL, vrf_id, afi, type);
 
        return nhe;
 }
@@ -1062,11 +1061,11 @@ int zebra_nhg_kernel_find(uint32_t id, struct nexthop *nh, struct nh_grp *grp,
 }
 
 /* Kernel-side, received delete message */
-int zebra_nhg_kernel_del(uint32_t id)
+int zebra_nhg_kernel_del(uint32_t id, vrf_id_t vrf_id)
 {
        struct nhg_ctx *ctx = NULL;
 
-       ctx = nhg_ctx_init(id, NULL, NULL, 0, 0, 0, 0);
+       ctx = nhg_ctx_init(id, NULL, NULL, vrf_id, 0, 0, 0);
 
        nhg_ctx_set_op(ctx, NHG_CTX_OP_DEL);
 
@@ -1183,6 +1182,14 @@ struct nhg_hash_entry *
 zebra_nhg_rib_find(uint32_t id, struct nexthop_group *nhg, afi_t rt_afi)
 {
        struct nhg_hash_entry *nhe = NULL;
+       vrf_id_t vrf_id;
+
+       /*
+        * CLANG SA is complaining that nexthop may be NULL
+        * Make it happy but this is ridonc
+        */
+       assert(nhg->nexthop);
+       vrf_id = !vrf_is_backend_netns() ? VRF_DEFAULT : nhg->nexthop->vrf_id;
 
        if (!(nhg && nhg->nexthop)) {
                flog_err(EC_ZEBRA_TABLE_LOOKUP_FAILED,
@@ -1190,7 +1197,7 @@ zebra_nhg_rib_find(uint32_t id, struct nexthop_group *nhg, afi_t rt_afi)
                return NULL;
        }
 
-       zebra_nhg_find(&nhe, id, nhg, NULL, nhg->nexthop->vrf_id, rt_afi, 0);
+       zebra_nhg_find(&nhe, id, nhg, NULL, vrf_id, rt_afi, 0);
 
        return nhe;
 }
index 522ec1e9ddfb6615cc5b98431a2dfcf559fe3f09..c2e173e0947d75f5dcc00fb000f653e444e57603 100644 (file)
@@ -195,7 +195,7 @@ extern int zebra_nhg_kernel_find(uint32_t id, struct nexthop *nh,
                                 vrf_id_t vrf_id, afi_t afi, int type,
                                 int startup);
 /* Del via kernel */
-extern int zebra_nhg_kernel_del(uint32_t id);
+extern int zebra_nhg_kernel_del(uint32_t id, vrf_id_t vrf_id);
 
 /* Find via route creation */
 extern struct nhg_hash_entry *
index ef6c4eb6f3783a98b30bdb4ee599cea92fd4e3d8..78001da170a19829d7f018f5bc0bc9eb774f05ee 100644 (file)
@@ -1373,6 +1373,11 @@ DEFPY (show_nexthop_group,
        else if (v6)
                afi = AFI_IP6;
 
+       if (vrf_is_backend_netns() && (vrf_name || vrf_all)) {
+               vty_out(vty, "VRF subcommand does not make any sense in l3mdev based vrf's");
+               return CMD_WARNING;
+       }
+
        if (vrf_all) {
                struct vrf *vrf;