Message ID | 20230529201914.69828-4-bpoirier@nvidia.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | nexthop: Refactor and fix nexthop selection for multipath routes | expand |
On 5/29/23 2:19 PM, Benjamin Poirier wrote: > diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c > index c12acbf39659..ca501ced04fb 100644 > --- a/net/ipv4/nexthop.c > +++ b/net/ipv4/nexthop.c > @@ -1186,6 +1186,7 @@ static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash) > static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) > { > struct nexthop *rc = NULL; > + bool first = false; > int i; > > if (nhg->fdb_nh) > @@ -1194,20 +1195,24 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) > for (i = 0; i < nhg->num_nh; ++i) { > struct nh_grp_entry *nhge = &nhg->nh_entries[i]; > > - if (hash > atomic_read(&nhge->hthr.upper_bound)) > - continue; > - > /* nexthops always check if it is good and does > * not rely on a sysctl for this behavior > */ > - if (nexthop_is_good_nh(nhge->nh)) > - return nhge->nh; > + if (!nexthop_is_good_nh(nhge->nh)) > + continue; > > - if (!rc) > + if (!first) { Setting 'first' and 'rc' are equivalent, so 'first' is not needed. As I recall it was used in fib_select_multipath before the nexthop refactoring (eba618abacade) because nhsel == 0 is valid, so the loop could not rely on it. > rc = nhge->nh; > + first = true; > + } > + > + if (hash > atomic_read(&nhge->hthr.upper_bound)) > + continue; > + > + return nhge->nh; > } > > - return rc; > + return rc ? : nhg->nh_entries[0].nh; > } > > static struct nexthop *nexthop_select_path_res(struct nh_group *nhg, int hash)
On Tue, May 30, 2023 at 09:08:01AM -0600, David Ahern wrote: > On 5/29/23 2:19 PM, Benjamin Poirier wrote: > > diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c > > index c12acbf39659..ca501ced04fb 100644 > > --- a/net/ipv4/nexthop.c > > +++ b/net/ipv4/nexthop.c > > @@ -1186,6 +1186,7 @@ static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash) > > static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) > > { > > struct nexthop *rc = NULL; > > + bool first = false; > > int i; > > > > if (nhg->fdb_nh) > > @@ -1194,20 +1195,24 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) > > for (i = 0; i < nhg->num_nh; ++i) { > > struct nh_grp_entry *nhge = &nhg->nh_entries[i]; > > > > - if (hash > atomic_read(&nhge->hthr.upper_bound)) > > - continue; > > - > > /* nexthops always check if it is good and does > > * not rely on a sysctl for this behavior > > */ > > - if (nexthop_is_good_nh(nhge->nh)) > > - return nhge->nh; > > + if (!nexthop_is_good_nh(nhge->nh)) > > + continue; > > > > - if (!rc) > > + if (!first) { > > Setting 'first' and 'rc' are equivalent, so 'first' is not needed. Yea, looking at it again not sure what I was thinking... Thanks for the review! > As I recall it was used in fib_select_multipath before the nexthop > refactoring (eba618abacade) because nhsel == 0 is valid, so the loop > could not rely on it. > > > > > rc = nhge->nh; > > + first = true; > > + } > > + > > + if (hash > atomic_read(&nhge->hthr.upper_bound)) > > + continue; > > + > > + return nhge->nh; > > } > > > > - return rc; > > + return rc ? : nhg->nh_entries[0].nh; > > } > > > > static struct nexthop *nexthop_select_path_res(struct nh_group *nhg, int hash) > >
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index c12acbf39659..ca501ced04fb 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -1186,6 +1186,7 @@ static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash) static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) { struct nexthop *rc = NULL; + bool first = false; int i; if (nhg->fdb_nh) @@ -1194,20 +1195,24 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) for (i = 0; i < nhg->num_nh; ++i) { struct nh_grp_entry *nhge = &nhg->nh_entries[i]; - if (hash > atomic_read(&nhge->hthr.upper_bound)) - continue; - /* nexthops always check if it is good and does * not rely on a sysctl for this behavior */ - if (nexthop_is_good_nh(nhge->nh)) - return nhge->nh; + if (!nexthop_is_good_nh(nhge->nh)) + continue; - if (!rc) + if (!first) { rc = nhge->nh; + first = true; + } + + if (hash > atomic_read(&nhge->hthr.upper_bound)) + continue; + + return nhge->nh; } - return rc; + return rc ? : nhg->nh_entries[0].nh; } static struct nexthop *nexthop_select_path_res(struct nh_group *nhg, int hash)