Skip to content

Commit 5481d73

Browse files
dsaherndavem330
authored andcommitted
ipv4: Use accessors for fib_info nexthop data
Use helpers to access fib_nh and fib_nhs fields of a fib_info. Drop the fib_dev macro which is an alias for the first nexthop. Replacements: fi->fib_dev --> fib_info_nh(fi, 0)->fib_nh_dev fi->fib_nh --> fib_info_nh(fi, 0) fi->fib_nh[i] --> fib_info_nh(fi, i) fi->fib_nhs --> fib_info_num_path(fi) where fib_info_nh(fi, i) returns fi->fib_nh[nhsel] and fib_info_num_path returns fi->fib_nhs. Move the existing fib_info_nhc to nexthop.h and define the new ones there. A later patch adds a check if a fib_info uses a nexthop object, and defining the helpers in nexthop.h avoid circular header dependencies. After this all remaining open coded references to fi->fib_nhs and fi->fib_nh are in: - fib_create_info and helpers used to lookup an existing fib_info entry, and - the netdev event functions fib_sync_down_dev and fib_sync_up. The latter two will not be reused for nexthops, and the fib_create_info will be updated to handle a nexthop in a fib_info. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7dd7316 commit 5481d73

File tree

12 files changed

+132
-80
lines changed

12 files changed

+132
-80
lines changed

drivers/net/ethernet/mellanox/mlx5/core/lag_mp.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Copyright (c) 2019 Mellanox Technologies. */
33

44
#include <linux/netdevice.h>
5+
#include <net/nexthop.h>
56
#include "lag.h"
67
#include "lag_mp.h"
78
#include "mlx5_core.h"
@@ -110,6 +111,8 @@ static void mlx5_lag_fib_route_event(struct mlx5_lag *ldev,
110111
struct fib_info *fi)
111112
{
112113
struct lag_mp *mp = &ldev->lag_mp;
114+
struct fib_nh *fib_nh0, *fib_nh1;
115+
unsigned int nhs;
113116

114117
/* Handle delete event */
115118
if (event == FIB_EVENT_ENTRY_DEL) {
@@ -120,24 +123,28 @@ static void mlx5_lag_fib_route_event(struct mlx5_lag *ldev,
120123
}
121124

122125
/* Handle add/replace event */
123-
if (fi->fib_nhs == 1) {
126+
nhs = fib_info_num_path(fi);
127+
if (nhs == 1) {
124128
if (__mlx5_lag_is_active(ldev)) {
125-
struct net_device *nh_dev = fi->fib_nh[0].fib_nh_dev;
129+
struct fib_nh *nh = fib_info_nh(fi, 0);
130+
struct net_device *nh_dev = nh->fib_nh_dev;
126131
int i = mlx5_lag_dev_get_netdev_idx(ldev, nh_dev);
127132

128133
mlx5_lag_set_port_affinity(ldev, ++i);
129134
}
130135
return;
131136
}
132137

133-
if (fi->fib_nhs != 2)
138+
if (nhs != 2)
134139
return;
135140

136141
/* Verify next hops are ports of the same hca */
137-
if (!(fi->fib_nh[0].fib_nh_dev == ldev->pf[0].netdev &&
138-
fi->fib_nh[1].fib_nh_dev == ldev->pf[1].netdev) &&
139-
!(fi->fib_nh[0].fib_nh_dev == ldev->pf[1].netdev &&
140-
fi->fib_nh[1].fib_nh_dev == ldev->pf[0].netdev)) {
142+
fib_nh0 = fib_info_nh(fi, 0);
143+
fib_nh1 = fib_info_nh(fi, 1);
144+
if (!(fib_nh0->fib_nh_dev == ldev->pf[0].netdev &&
145+
fib_nh1->fib_nh_dev == ldev->pf[1].netdev) &&
146+
!(fib_nh0->fib_nh_dev == ldev->pf[1].netdev &&
147+
fib_nh1->fib_nh_dev == ldev->pf[0].netdev)) {
141148
mlx5_core_warn(ldev->pf[0].dev, "Multipath offload require two ports of the same HCA\n");
142149
return;
143150
}
@@ -174,7 +181,7 @@ static void mlx5_lag_fib_nexthop_event(struct mlx5_lag *ldev,
174181
mlx5_lag_set_port_affinity(ldev, i);
175182
}
176183
} else if (event == FIB_EVENT_NH_ADD &&
177-
fi->fib_nhs == 2) {
184+
fib_info_num_path(fi) == 2) {
178185
mlx5_lag_set_port_affinity(ldev, 0);
179186
}
180187
}
@@ -238,6 +245,7 @@ static int mlx5_lag_fib_event(struct notifier_block *nb,
238245
struct mlx5_fib_event_work *fib_work;
239246
struct fib_entry_notifier_info *fen_info;
240247
struct fib_nh_notifier_info *fnh_info;
248+
struct net_device *fib_dev;
241249
struct fib_info *fi;
242250

243251
if (info->family != AF_INET)
@@ -254,8 +262,9 @@ static int mlx5_lag_fib_event(struct notifier_block *nb,
254262
fen_info = container_of(info, struct fib_entry_notifier_info,
255263
info);
256264
fi = fen_info->fi;
257-
if (fi->fib_dev != ldev->pf[0].netdev &&
258-
fi->fib_dev != ldev->pf[1].netdev) {
265+
fib_dev = fib_info_nh(fen_info->fi, 0)->fib_nh_dev;
266+
if (fib_dev != ldev->pf[0].netdev &&
267+
fib_dev != ldev->pf[1].netdev) {
259268
return NOTIFY_DONE;
260269
}
261270
fib_work = mlx5_lag_init_fib_work(ldev, event);

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <net/arp.h>
2222
#include <net/ip_fib.h>
2323
#include <net/ip6_fib.h>
24+
#include <net/nexthop.h>
2425
#include <net/fib_rules.h>
2526
#include <net/ip_tunnels.h>
2627
#include <net/l3mdev.h>
@@ -3816,35 +3817,37 @@ static void mlxsw_sp_nexthop_rif_gone_sync(struct mlxsw_sp *mlxsw_sp,
38163817
}
38173818

38183819
static bool mlxsw_sp_fi_is_gateway(const struct mlxsw_sp *mlxsw_sp,
3819-
const struct fib_info *fi)
3820+
struct fib_info *fi)
38203821
{
3821-
return fi->fib_nh->fib_nh_scope == RT_SCOPE_LINK ||
3822-
mlxsw_sp_nexthop4_ipip_type(mlxsw_sp, fi->fib_nh, NULL);
3822+
const struct fib_nh *nh = fib_info_nh(fi, 0);
3823+
3824+
return nh->fib_nh_scope == RT_SCOPE_LINK ||
3825+
mlxsw_sp_nexthop4_ipip_type(mlxsw_sp, nh, NULL);
38233826
}
38243827

38253828
static struct mlxsw_sp_nexthop_group *
38263829
mlxsw_sp_nexthop4_group_create(struct mlxsw_sp *mlxsw_sp, struct fib_info *fi)
38273830
{
3831+
unsigned int nhs = fib_info_num_path(fi);
38283832
struct mlxsw_sp_nexthop_group *nh_grp;
38293833
struct mlxsw_sp_nexthop *nh;
38303834
struct fib_nh *fib_nh;
38313835
int i;
38323836
int err;
38333837

3834-
nh_grp = kzalloc(struct_size(nh_grp, nexthops, fi->fib_nhs),
3835-
GFP_KERNEL);
3838+
nh_grp = kzalloc(struct_size(nh_grp, nexthops, nhs), GFP_KERNEL);
38363839
if (!nh_grp)
38373840
return ERR_PTR(-ENOMEM);
38383841
nh_grp->priv = fi;
38393842
INIT_LIST_HEAD(&nh_grp->fib_list);
38403843
nh_grp->neigh_tbl = &arp_tbl;
38413844

38423845
nh_grp->gateway = mlxsw_sp_fi_is_gateway(mlxsw_sp, fi);
3843-
nh_grp->count = fi->fib_nhs;
3846+
nh_grp->count = nhs;
38443847
fib_info_hold(fi);
38453848
for (i = 0; i < nh_grp->count; i++) {
38463849
nh = &nh_grp->nexthops[i];
3847-
fib_nh = &fi->fib_nh[i];
3850+
fib_nh = fib_info_nh(fi, i);
38483851
err = mlxsw_sp_nexthop4_init(mlxsw_sp, nh_grp, nh, fib_nh);
38493852
if (err)
38503853
goto err_nexthop4_init;
@@ -4282,9 +4285,9 @@ mlxsw_sp_fib4_entry_type_set(struct mlxsw_sp *mlxsw_sp,
42824285
const struct fib_entry_notifier_info *fen_info,
42834286
struct mlxsw_sp_fib_entry *fib_entry)
42844287
{
4288+
struct net_device *dev = fib_info_nh(fen_info->fi, 0)->fib_nh_dev;
42854289
union mlxsw_sp_l3addr dip = { .addr4 = htonl(fen_info->dst) };
42864290
u32 tb_id = mlxsw_sp_fix_tb_id(fen_info->tb_id);
4287-
struct net_device *dev = fen_info->fi->fib_dev;
42884291
struct mlxsw_sp_ipip_entry *ipip_entry;
42894292
struct fib_info *fi = fen_info->fi;
42904293

drivers/net/ethernet/rocker/rocker_ofdpa.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <net/neighbour.h>
2323
#include <net/switchdev.h>
2424
#include <net/ip_fib.h>
25+
#include <net/nexthop.h>
2526
#include <net/arp.h>
2627

2728
#include "rocker.h"
@@ -2286,8 +2287,8 @@ static int ofdpa_port_fib_ipv4(struct ofdpa_port *ofdpa_port, __be32 dst,
22862287

22872288
/* XXX support ECMP */
22882289

2289-
nh = fi->fib_nh;
2290-
nh_on_port = (fi->fib_dev == ofdpa_port->dev);
2290+
nh = fib_info_nh(fi, 0);
2291+
nh_on_port = (nh->fib_nh_dev == ofdpa_port->dev);
22912292
has_gw = !!nh->fib_nh_gw4;
22922293

22932294
if (has_gw && nh_on_port) {
@@ -2737,19 +2738,21 @@ static int ofdpa_fib4_add(struct rocker *rocker,
27372738
{
27382739
struct ofdpa *ofdpa = rocker->wpriv;
27392740
struct ofdpa_port *ofdpa_port;
2741+
struct fib_nh *nh;
27402742
int err;
27412743

27422744
if (ofdpa->fib_aborted)
27432745
return 0;
2744-
ofdpa_port = ofdpa_port_dev_lower_find(fen_info->fi->fib_dev, rocker);
2746+
nh = fib_info_nh(fen_info->fi, 0);
2747+
ofdpa_port = ofdpa_port_dev_lower_find(nh->fib_nh_dev, rocker);
27452748
if (!ofdpa_port)
27462749
return 0;
27472750
err = ofdpa_port_fib_ipv4(ofdpa_port, htonl(fen_info->dst),
27482751
fen_info->dst_len, fen_info->fi,
27492752
fen_info->tb_id, 0);
27502753
if (err)
27512754
return err;
2752-
fen_info->fi->fib_nh->fib_nh_flags |= RTNH_F_OFFLOAD;
2755+
nh->fib_nh_flags |= RTNH_F_OFFLOAD;
27532756
return 0;
27542757
}
27552758

@@ -2758,13 +2761,15 @@ static int ofdpa_fib4_del(struct rocker *rocker,
27582761
{
27592762
struct ofdpa *ofdpa = rocker->wpriv;
27602763
struct ofdpa_port *ofdpa_port;
2764+
struct fib_nh *nh;
27612765

27622766
if (ofdpa->fib_aborted)
27632767
return 0;
2764-
ofdpa_port = ofdpa_port_dev_lower_find(fen_info->fi->fib_dev, rocker);
2768+
nh = fib_info_nh(fen_info->fi, 0);
2769+
ofdpa_port = ofdpa_port_dev_lower_find(nh->fib_nh_dev, rocker);
27652770
if (!ofdpa_port)
27662771
return 0;
2767-
fen_info->fi->fib_nh->fib_nh_flags &= ~RTNH_F_OFFLOAD;
2772+
nh->fib_nh_flags &= ~RTNH_F_OFFLOAD;
27682773
return ofdpa_port_fib_ipv4(ofdpa_port, htonl(fen_info->dst),
27692774
fen_info->dst_len, fen_info->fi,
27702775
fen_info->tb_id, OFDPA_OP_FLAG_REMOVE);
@@ -2784,14 +2789,16 @@ static void ofdpa_fib4_abort(struct rocker *rocker)
27842789

27852790
spin_lock_irqsave(&ofdpa->flow_tbl_lock, flags);
27862791
hash_for_each_safe(ofdpa->flow_tbl, bkt, tmp, flow_entry, entry) {
2792+
struct fib_nh *nh;
2793+
27872794
if (flow_entry->key.tbl_id !=
27882795
ROCKER_OF_DPA_TABLE_ID_UNICAST_ROUTING)
27892796
continue;
2790-
ofdpa_port = ofdpa_port_dev_lower_find(flow_entry->fi->fib_dev,
2791-
rocker);
2797+
nh = fib_info_nh(flow_entry->fi, 0);
2798+
ofdpa_port = ofdpa_port_dev_lower_find(nh->fib_nh_dev, rocker);
27922799
if (!ofdpa_port)
27932800
continue;
2794-
flow_entry->fi->fib_nh->fib_nh_flags &= ~RTNH_F_OFFLOAD;
2801+
nh->fib_nh_flags &= ~RTNH_F_OFFLOAD;
27952802
ofdpa_flow_tbl_del(ofdpa_port, OFDPA_OP_FLAG_REMOVE,
27962803
flow_entry);
27972804
}

include/net/ip_fib.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ struct fib_info {
153153
bool nh_updated;
154154
struct rcu_head rcu;
155155
struct fib_nh fib_nh[0];
156-
#define fib_dev fib_nh[0].fib_nh_dev
157156
};
158157

159158

@@ -190,11 +189,6 @@ struct fib_result_nl {
190189
int err;
191190
};
192191

193-
static inline struct fib_nh_common *fib_info_nhc(struct fib_info *fi, int nhsel)
194-
{
195-
return &fi->fib_nh[nhsel].nh_common;
196-
}
197-
198192
#ifdef CONFIG_IP_MULTIPLE_TABLES
199193
#define FIB_TABLE_HASHSZ 256
200194
#else

include/net/nexthop.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,19 @@ static inline bool nexthop_is_blackhole(const struct nexthop *nh)
192192
nhi = rcu_dereference_rtnl(nh->nh_info);
193193
return nhi->reject_nh;
194194
}
195+
196+
static inline unsigned int fib_info_num_path(const struct fib_info *fi)
197+
{
198+
return fi->fib_nhs;
199+
}
200+
201+
static inline struct fib_nh_common *fib_info_nhc(struct fib_info *fi, int nhsel)
202+
{
203+
return &fi->fib_nh[nhsel].nh_common;
204+
}
205+
206+
static inline struct fib_nh *fib_info_nh(struct fib_info *fi, int nhsel)
207+
{
208+
return &fi->fib_nh[nhsel];
209+
}
195210
#endif

net/core/filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#include <net/inet_hashtables.h>
6767
#include <net/inet6_hashtables.h>
6868
#include <net/ip_fib.h>
69+
#include <net/nexthop.h>
6970
#include <net/flow.h>
7071
#include <net/arp.h>
7172
#include <net/ipv6.h>
@@ -4674,7 +4675,7 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
46744675
if (res.type != RTN_UNICAST)
46754676
return BPF_FIB_LKUP_RET_NOT_FWDED;
46764677

4677-
if (res.fi->fib_nhs > 1)
4678+
if (fib_info_num_path(res.fi) > 1)
46784679
fib_select_path(net, &res, &fl4, NULL);
46794680

46804681
if (check_mtu) {

net/ipv4/fib_frontend.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <net/sock.h>
4444
#include <net/arp.h>
4545
#include <net/ip_fib.h>
46+
#include <net/nexthop.h>
4647
#include <net/rtnetlink.h>
4748
#include <net/xfrm.h>
4849
#include <net/l3mdev.h>
@@ -234,7 +235,9 @@ static inline unsigned int __inet_dev_addr_type(struct net *net,
234235
if (table) {
235236
ret = RTN_UNICAST;
236237
if (!fib_table_lookup(table, &fl4, &res, FIB_LOOKUP_NOREF)) {
237-
if (!dev || dev == res.fi->fib_dev)
238+
struct fib_nh *nh = fib_info_nh(res.fi, 0);
239+
240+
if (!dev || dev == nh->fib_nh_dev)
238241
ret = res.type;
239242
}
240243
}
@@ -321,8 +324,8 @@ bool fib_info_nh_uses_dev(struct fib_info *fi, const struct net_device *dev)
321324
#ifdef CONFIG_IP_ROUTE_MULTIPATH
322325
int ret;
323326

324-
for (ret = 0; ret < fi->fib_nhs; ret++) {
325-
struct fib_nh *nh = &fi->fib_nh[ret];
327+
for (ret = 0; ret < fib_info_num_path(fi); ret++) {
328+
const struct fib_nh *nh = fib_info_nh(fi, ret);
326329

327330
if (nh->fib_nh_dev == dev) {
328331
dev_match = true;
@@ -333,7 +336,7 @@ bool fib_info_nh_uses_dev(struct fib_info *fi, const struct net_device *dev)
333336
}
334337
}
335338
#else
336-
if (fi->fib_nh[0].fib_nh_dev == dev)
339+
if (fib_info_nh(fi, 0)->fib_nh_dev == dev)
337340
dev_match = true;
338341
#endif
339342

net/ipv4/fib_lookup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/types.h>
66
#include <linux/list.h>
77
#include <net/ip_fib.h>
8+
#include <net/nexthop.h>
89

910
struct fib_alias {
1011
struct hlist_node fa_list;

net/ipv4/fib_rules.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <net/route.h>
3232
#include <net/tcp.h>
3333
#include <net/ip_fib.h>
34+
#include <net/nexthop.h>
3435
#include <net/fib_rules.h>
3536

3637
struct fib4_rule {
@@ -145,8 +146,11 @@ static bool fib4_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg
145146
struct fib_result *result = (struct fib_result *) arg->result;
146147
struct net_device *dev = NULL;
147148

148-
if (result->fi)
149-
dev = result->fi->fib_dev;
149+
if (result->fi) {
150+
struct fib_nh *nh = fib_info_nh(result->fi, 0);
151+
152+
dev = nh->fib_nh_dev;
153+
}
150154

151155
/* do not accept result if the route does
152156
* not meet the required prefix length

0 commit comments

Comments
 (0)