Skip to content

Commit 0b5e2e3

Browse files
dsaherndavem330
authored andcommitted
nexthop: Expand nexthop_is_multipath in a few places
I got too fancy consolidating checks on multipath type. The result is that path lookups can access 2 different nh_grp structs as exposed by Nik's torture tests. Expand nexthop_is_multipath within nexthop.h to avoid multiple, nh_grp dereferences and make decisions based on the consistent struct. Only 2 places left using nexthop_is_multipath are within IPv6, both only check that the nexthop is a multipath for a branching decision which are acceptable. Fixes: 430a049 ("nexthop: Add support for nexthop groups") Signed-off-by: David Ahern <[email protected]> Acked-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 90f33bf commit 0b5e2e3

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

include/net/nexthop.h

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,20 @@ static inline unsigned int nexthop_num_path(const struct nexthop *nh)
137137
{
138138
unsigned int rc = 1;
139139

140-
if (nexthop_is_multipath(nh)) {
140+
if (nh->is_group) {
141141
struct nh_group *nh_grp;
142142

143143
nh_grp = rcu_dereference_rtnl(nh->nh_grp);
144-
rc = nh_grp->num_nh;
144+
if (nh_grp->mpath)
145+
rc = nh_grp->num_nh;
145146
}
146147

147148
return rc;
148149
}
149150

150151
static inline
151-
struct nexthop *nexthop_mpath_select(const struct nexthop *nh, int nhsel)
152+
struct nexthop *nexthop_mpath_select(const struct nh_group *nhg, int nhsel)
152153
{
153-
const struct nh_group *nhg = rcu_dereference_rtnl(nh->nh_grp);
154-
155154
/* for_nexthops macros in fib_semantics.c grabs a pointer to
156155
* the nexthop before checking nhsel
157156
*/
@@ -186,12 +185,14 @@ static inline bool nexthop_is_blackhole(const struct nexthop *nh)
186185
{
187186
const struct nh_info *nhi;
188187

189-
if (nexthop_is_multipath(nh)) {
190-
if (nexthop_num_path(nh) > 1)
191-
return false;
192-
nh = nexthop_mpath_select(nh, 0);
193-
if (!nh)
188+
if (nh->is_group) {
189+
struct nh_group *nh_grp;
190+
191+
nh_grp = rcu_dereference_rtnl(nh->nh_grp);
192+
if (nh_grp->num_nh > 1)
194193
return false;
194+
195+
nh = nh_grp->nh_entries[0].nh;
195196
}
196197

197198
nhi = rcu_dereference_rtnl(nh->nh_info);
@@ -217,10 +218,15 @@ struct fib_nh_common *nexthop_fib_nhc(struct nexthop *nh, int nhsel)
217218
BUILD_BUG_ON(offsetof(struct fib_nh, nh_common) != 0);
218219
BUILD_BUG_ON(offsetof(struct fib6_nh, nh_common) != 0);
219220

220-
if (nexthop_is_multipath(nh)) {
221-
nh = nexthop_mpath_select(nh, nhsel);
222-
if (!nh)
223-
return NULL;
221+
if (nh->is_group) {
222+
struct nh_group *nh_grp;
223+
224+
nh_grp = rcu_dereference_rtnl(nh->nh_grp);
225+
if (nh_grp->mpath) {
226+
nh = nexthop_mpath_select(nh_grp, nhsel);
227+
if (!nh)
228+
return NULL;
229+
}
224230
}
225231

226232
nhi = rcu_dereference_rtnl(nh->nh_info);
@@ -264,8 +270,11 @@ static inline struct fib6_nh *nexthop_fib6_nh(struct nexthop *nh)
264270
{
265271
struct nh_info *nhi;
266272

267-
if (nexthop_is_multipath(nh)) {
268-
nh = nexthop_mpath_select(nh, 0);
273+
if (nh->is_group) {
274+
struct nh_group *nh_grp;
275+
276+
nh_grp = rcu_dereference_rtnl(nh->nh_grp);
277+
nh = nexthop_mpath_select(nh_grp, 0);
269278
if (!nh)
270279
return NULL;
271280
}

0 commit comments

Comments
 (0)