]> git.puffer.fish Git - matthieu/frr.git/commitdiff
staticd: reject route config with too many nexthops
authorMark Stapp <mstapp@nvidia.com>
Thu, 17 Feb 2022 14:49:41 +0000 (09:49 -0500)
committermergify-bot <noreply@mergify.com>
Fri, 18 Feb 2022 00:52:51 +0000 (00:52 +0000)
Restrict the number of nexthops for a route to the compiled-in
limit. Be careful with the zapi route struct's array of nexthops
too.

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
(cherry picked from commit 1f7ab1a2cc2a7079c9dd2cb791fc6ba3b9c5a6aa)

staticd/static_nb_config.c
staticd/static_zebra.c

index d1b2c9eaa6d8a189b5fb851c6013e5cc79b4b7fb..9ccffe53d9afdc935432f749a0185f1ba7901586 100644 (file)
@@ -115,7 +115,7 @@ static int static_path_list_tag_modify(struct nb_cb_modify_args *args)
 }
 
 struct nexthop_iter {
-       int count;
+       uint32_t count;
        bool blackhole;
 };
 
@@ -171,6 +171,11 @@ static bool static_nexthop_create(struct nb_cb_create_args *args)
                                args->errmsg, args->errmsg_len,
                                "Route cannot have blackhole and non-blackhole nexthops simultaneously");
                        return NB_ERR_VALIDATION;
+               } else if (iter.count > zebra_ecmp_count) {
+                       snprintf(args->errmsg, args->errmsg_len,
+                               "Route cannot have more than %d ECMP nexthops",
+                                zebra_ecmp_count);
+                       return NB_ERR_VALIDATION;
                }
                break;
        case NB_EV_PREPARE:
index a62225294aedc48552f760c6f4d285a050c59bab..b75e1a1cdf6779fa46ece03e9c385e81000ac241 100644 (file)
@@ -414,6 +414,10 @@ extern void static_zebra_route_add(struct static_path *pn, bool install)
                api.tableid = pn->table_id;
        }
        frr_each(static_nexthop_list, &pn->nexthop_list, nh) {
+               /* Don't overrun the nexthop array */
+               if (nh_num == zebra_ecmp_count)
+                       break;
+
                api_nh = &api.nexthops[nh_num];
                if (nh->nh_vrf_id == VRF_UNKNOWN)
                        continue;