Skip to content

Commit 5a4d148

Browse files
committed
Merge branch 'per-nexthop-offload'
Jiri Pirko says: ==================== ipv4: fib: Provide per-nexthop offload indication Ido says: Offload indication for IPv4 routes is currently set in the FIB info's flags. When multipath routes are employed, this can lead to a route being marked as offloaded although only one of its nexthops is actually offloaded. Instead, this patchset aims to proivde a higher resolution for the offload indication and report it on a per-nexthop basis. Example output from patched iproute: $ ip route show 192.168.200.0/24 192.168.200.0/24 nexthop via 192.168.100.2 dev enp3s0np7 weight 1 offload nexthop via 192.168.101.3 dev enp3s0np8 weight 1 And once the second gateway is resolved: $ ip route show 192.168.200.0/24 192.168.200.0/24 nexthop via 192.168.100.2 dev enp3s0np7 weight 1 offload nexthop via 192.168.101.3 dev enp3s0np8 weight 1 offload First patch teaches the kernel to look for the offload indication in the nexthop flags. Patches 2-5 adjust current capable drivers to provide offload indication on a per-nexthop basis. Last patch removes no longer used functions to set offload indication in the FIB info's flags. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 9820355 + 2202e35 commit 5a4d148

File tree

4 files changed

+65
-29
lines changed

4 files changed

+65
-29
lines changed

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

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ struct mlxsw_sp_fib_entry {
394394
enum mlxsw_sp_fib_entry_type type;
395395
struct list_head nexthop_group_node;
396396
struct mlxsw_sp_nexthop_group *nh_group;
397-
bool offloaded;
398397
};
399398

400399
struct mlxsw_sp_fib4_entry {
@@ -1653,6 +1652,24 @@ mlxsw_sp_nexthop_fib_entries_update(struct mlxsw_sp *mlxsw_sp,
16531652
return 0;
16541653
}
16551654

1655+
static void
1656+
mlxsw_sp_fib_entry_offload_refresh(struct mlxsw_sp_fib_entry *fib_entry,
1657+
enum mlxsw_reg_ralue_op op, int err);
1658+
1659+
static void
1660+
mlxsw_sp_nexthop_fib_entries_refresh(struct mlxsw_sp_nexthop_group *nh_grp)
1661+
{
1662+
enum mlxsw_reg_ralue_op op = MLXSW_REG_RALUE_OP_WRITE_WRITE;
1663+
struct mlxsw_sp_fib_entry *fib_entry;
1664+
1665+
list_for_each_entry(fib_entry, &nh_grp->fib_list, nexthop_group_node) {
1666+
if (!mlxsw_sp_fib_node_entry_is_first(fib_entry->fib_node,
1667+
fib_entry))
1668+
continue;
1669+
mlxsw_sp_fib_entry_offload_refresh(fib_entry, op, 0);
1670+
}
1671+
}
1672+
16561673
static void
16571674
mlxsw_sp_nexthop_group_refresh(struct mlxsw_sp *mlxsw_sp,
16581675
struct mlxsw_sp_nexthop_group *nh_grp)
@@ -1740,6 +1757,10 @@ mlxsw_sp_nexthop_group_refresh(struct mlxsw_sp *mlxsw_sp,
17401757
dev_warn(mlxsw_sp->bus_info->dev, "Failed to mass-update adjacency index for nexthop group.\n");
17411758
goto set_trap;
17421759
}
1760+
1761+
/* Offload state within the group changed, so update the flags. */
1762+
mlxsw_sp_nexthop_fib_entries_refresh(nh_grp);
1763+
17431764
return;
17441765

17451766
set_trap:
@@ -2103,13 +2124,45 @@ mlxsw_sp_fib_entry_should_offload(const struct mlxsw_sp_fib_entry *fib_entry)
21032124
}
21042125
}
21052126

2106-
static void mlxsw_sp_fib_entry_offload_set(struct mlxsw_sp_fib_entry *fib_entry)
2127+
static void
2128+
mlxsw_sp_fib4_entry_offload_set(struct mlxsw_sp_fib_entry *fib_entry)
2129+
{
2130+
struct mlxsw_sp_nexthop_group *nh_grp = fib_entry->nh_group;
2131+
int i;
2132+
2133+
if (fib_entry->type == MLXSW_SP_FIB_ENTRY_TYPE_LOCAL) {
2134+
nh_grp->nexthops->key.fib_nh->nh_flags |= RTNH_F_OFFLOAD;
2135+
return;
2136+
}
2137+
2138+
for (i = 0; i < nh_grp->count; i++) {
2139+
struct mlxsw_sp_nexthop *nh = &nh_grp->nexthops[i];
2140+
2141+
if (nh->offloaded)
2142+
nh->key.fib_nh->nh_flags |= RTNH_F_OFFLOAD;
2143+
else
2144+
nh->key.fib_nh->nh_flags &= ~RTNH_F_OFFLOAD;
2145+
}
2146+
}
2147+
2148+
static void
2149+
mlxsw_sp_fib4_entry_offload_unset(struct mlxsw_sp_fib_entry *fib_entry)
21072150
{
2108-
fib_entry->offloaded = true;
2151+
struct mlxsw_sp_nexthop_group *nh_grp = fib_entry->nh_group;
2152+
int i;
2153+
2154+
for (i = 0; i < nh_grp->count; i++) {
2155+
struct mlxsw_sp_nexthop *nh = &nh_grp->nexthops[i];
21092156

2157+
nh->key.fib_nh->nh_flags &= ~RTNH_F_OFFLOAD;
2158+
}
2159+
}
2160+
2161+
static void mlxsw_sp_fib_entry_offload_set(struct mlxsw_sp_fib_entry *fib_entry)
2162+
{
21102163
switch (fib_entry->fib_node->fib->proto) {
21112164
case MLXSW_SP_L3_PROTO_IPV4:
2112-
fib_info_offload_inc(fib_entry->nh_group->key.fi);
2165+
mlxsw_sp_fib4_entry_offload_set(fib_entry);
21132166
break;
21142167
case MLXSW_SP_L3_PROTO_IPV6:
21152168
WARN_ON_ONCE(1);
@@ -2121,13 +2174,11 @@ mlxsw_sp_fib_entry_offload_unset(struct mlxsw_sp_fib_entry *fib_entry)
21212174
{
21222175
switch (fib_entry->fib_node->fib->proto) {
21232176
case MLXSW_SP_L3_PROTO_IPV4:
2124-
fib_info_offload_dec(fib_entry->nh_group->key.fi);
2177+
mlxsw_sp_fib4_entry_offload_unset(fib_entry);
21252178
break;
21262179
case MLXSW_SP_L3_PROTO_IPV6:
21272180
WARN_ON_ONCE(1);
21282181
}
2129-
2130-
fib_entry->offloaded = false;
21312182
}
21322183

21332184
static void
@@ -2136,17 +2187,13 @@ mlxsw_sp_fib_entry_offload_refresh(struct mlxsw_sp_fib_entry *fib_entry,
21362187
{
21372188
switch (op) {
21382189
case MLXSW_REG_RALUE_OP_WRITE_DELETE:
2139-
if (!fib_entry->offloaded)
2140-
return;
21412190
return mlxsw_sp_fib_entry_offload_unset(fib_entry);
21422191
case MLXSW_REG_RALUE_OP_WRITE_WRITE:
21432192
if (err)
21442193
return;
2145-
if (mlxsw_sp_fib_entry_should_offload(fib_entry) &&
2146-
!fib_entry->offloaded)
2194+
if (mlxsw_sp_fib_entry_should_offload(fib_entry))
21472195
mlxsw_sp_fib_entry_offload_set(fib_entry);
2148-
else if (!mlxsw_sp_fib_entry_should_offload(fib_entry) &&
2149-
fib_entry->offloaded)
2196+
else if (!mlxsw_sp_fib_entry_should_offload(fib_entry))
21502197
mlxsw_sp_fib_entry_offload_unset(fib_entry);
21512198
return;
21522199
default:

drivers/net/ethernet/rocker/rocker_ofdpa.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,7 +2761,7 @@ static int ofdpa_fib4_add(struct rocker *rocker,
27612761
fen_info->tb_id, 0);
27622762
if (err)
27632763
return err;
2764-
fib_info_offload_inc(fen_info->fi);
2764+
fen_info->fi->fib_nh->nh_flags |= RTNH_F_OFFLOAD;
27652765
return 0;
27662766
}
27672767

@@ -2776,7 +2776,7 @@ static int ofdpa_fib4_del(struct rocker *rocker,
27762776
ofdpa_port = ofdpa_port_dev_lower_find(fen_info->fi->fib_dev, rocker);
27772777
if (!ofdpa_port)
27782778
return 0;
2779-
fib_info_offload_dec(fen_info->fi);
2779+
fen_info->fi->fib_nh->nh_flags &= ~RTNH_F_OFFLOAD;
27802780
return ofdpa_port_fib_ipv4(ofdpa_port, htonl(fen_info->dst),
27812781
fen_info->dst_len, fen_info->fi,
27822782
fen_info->tb_id, OFDPA_OP_FLAG_REMOVE);
@@ -2803,7 +2803,7 @@ static void ofdpa_fib4_abort(struct rocker *rocker)
28032803
rocker);
28042804
if (!ofdpa_port)
28052805
continue;
2806-
fib_info_offload_dec(flow_entry->fi);
2806+
flow_entry->fi->fib_nh->nh_flags &= ~RTNH_F_OFFLOAD;
28072807
ofdpa_flow_tbl_del(ofdpa_port, OFDPA_OP_FLAG_REMOVE,
28082808
flow_entry);
28092809
}

include/net/ip_fib.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ struct fib_info {
124124
#ifdef CONFIG_IP_ROUTE_MULTIPATH
125125
int fib_weight;
126126
#endif
127-
unsigned int fib_offload_cnt;
128127
struct rcu_head rcu;
129128
struct fib_nh fib_nh[0];
130129
#define fib_dev fib_nh[0].nh_dev
@@ -177,18 +176,6 @@ struct fib_result_nl {
177176

178177
__be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
179178

180-
static inline void fib_info_offload_inc(struct fib_info *fi)
181-
{
182-
fi->fib_offload_cnt++;
183-
fi->fib_flags |= RTNH_F_OFFLOAD;
184-
}
185-
186-
static inline void fib_info_offload_dec(struct fib_info *fi)
187-
{
188-
if (--fi->fib_offload_cnt == 0)
189-
fi->fib_flags &= ~RTNH_F_OFFLOAD;
190-
}
191-
192179
#define FIB_RES_SADDR(net, res) \
193180
((FIB_RES_NH(res).nh_saddr_genid == \
194181
atomic_read(&(net)->ipv4.dev_addr_genid)) ? \

net/ipv4/fib_semantics.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,8 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
13421342
IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev))
13431343
rtm->rtm_flags |= RTNH_F_DEAD;
13441344
}
1345+
if (fi->fib_nh->nh_flags & RTNH_F_OFFLOAD)
1346+
rtm->rtm_flags |= RTNH_F_OFFLOAD;
13451347
#ifdef CONFIG_IP_ROUTE_CLASSID
13461348
if (fi->fib_nh[0].nh_tclassid &&
13471349
nla_put_u32(skb, RTA_FLOW, fi->fib_nh[0].nh_tclassid))

0 commit comments

Comments
 (0)