ipv4: Use dscp_t in struct fib_rt_info

Use the new dscp_t type to replace the tos field of struct fib_rt_info.
This ensures ECN bits are ignored and makes it compatible with the
fa_dscp field of struct fib_alias.

This also allows sparse to flag potential incorrect uses of DSCP and
ECN bits.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Guillaume Nault 2022-04-08 22:08:37 +02:00 committed by Jakub Kicinski
parent d072c88c28
commit 888ade8f90
7 changed files with 17 additions and 14 deletions

View File

@ -4,6 +4,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/inetdevice.h> #include <linux/inetdevice.h>
#include <net/inet_dscp.h>
#include <net/switchdev.h> #include <net/switchdev.h>
#include <linux/rhashtable.h> #include <linux/rhashtable.h>
@ -132,7 +133,7 @@ __prestera_k_arb_fib_lpm_offload_set(struct prestera_switch *sw,
fri.tb_id = fc->key.kern_tb_id; fri.tb_id = fc->key.kern_tb_id;
fri.dst = fc->key.addr.u.ipv4; fri.dst = fc->key.addr.u.ipv4;
fri.dst_len = fc->key.prefix_len; fri.dst_len = fc->key.prefix_len;
fri.tos = fc->kern_tos; fri.dscp = inet_dsfield_to_dscp(fc->kern_tos);
fri.type = fc->kern_type; fri.type = fc->kern_type;
/* flags begin */ /* flags begin */
fri.offload = offload; fri.offload = offload;

View File

@ -21,6 +21,7 @@
#include <net/netevent.h> #include <net/netevent.h>
#include <net/neighbour.h> #include <net/neighbour.h>
#include <net/arp.h> #include <net/arp.h>
#include <net/inet_dscp.h>
#include <net/ip_fib.h> #include <net/ip_fib.h>
#include <net/ip6_fib.h> #include <net/ip6_fib.h>
#include <net/nexthop.h> #include <net/nexthop.h>
@ -5620,7 +5621,7 @@ mlxsw_sp_fib4_offload_failed_flag_set(struct mlxsw_sp *mlxsw_sp,
fri.tb_id = fen_info->tb_id; fri.tb_id = fen_info->tb_id;
fri.dst = cpu_to_be32(*p_dst); fri.dst = cpu_to_be32(*p_dst);
fri.dst_len = fen_info->dst_len; fri.dst_len = fen_info->dst_len;
fri.tos = fen_info->tos; fri.dscp = inet_dsfield_to_dscp(fen_info->tos);
fri.type = fen_info->type; fri.type = fen_info->type;
fri.offload = false; fri.offload = false;
fri.trap = false; fri.trap = false;
@ -5645,7 +5646,7 @@ mlxsw_sp_fib4_entry_hw_flags_set(struct mlxsw_sp *mlxsw_sp,
fri.tb_id = fib4_entry->tb_id; fri.tb_id = fib4_entry->tb_id;
fri.dst = cpu_to_be32(*p_dst); fri.dst = cpu_to_be32(*p_dst);
fri.dst_len = dst_len; fri.dst_len = dst_len;
fri.tos = fib4_entry->tos; fri.dscp = inet_dsfield_to_dscp(fib4_entry->tos);
fri.type = fib4_entry->type; fri.type = fib4_entry->type;
fri.offload = should_offload; fri.offload = should_offload;
fri.trap = !should_offload; fri.trap = !should_offload;
@ -5668,7 +5669,7 @@ mlxsw_sp_fib4_entry_hw_flags_clear(struct mlxsw_sp *mlxsw_sp,
fri.tb_id = fib4_entry->tb_id; fri.tb_id = fib4_entry->tb_id;
fri.dst = cpu_to_be32(*p_dst); fri.dst = cpu_to_be32(*p_dst);
fri.dst_len = dst_len; fri.dst_len = dst_len;
fri.tos = fib4_entry->tos; fri.dscp = inet_dsfield_to_dscp(fib4_entry->tos);
fri.type = fib4_entry->type; fri.type = fib4_entry->type;
fri.offload = false; fri.offload = false;
fri.trap = false; fri.trap = false;

View File

@ -22,6 +22,7 @@
#include <linux/spinlock_types.h> #include <linux/spinlock_types.h>
#include <linux/types.h> #include <linux/types.h>
#include <net/fib_notifier.h> #include <net/fib_notifier.h>
#include <net/inet_dscp.h>
#include <net/ip_fib.h> #include <net/ip_fib.h>
#include <net/ip6_fib.h> #include <net/ip6_fib.h>
#include <net/fib_rules.h> #include <net/fib_rules.h>
@ -322,7 +323,7 @@ nsim_fib4_rt_offload_failed_flag_set(struct net *net,
fri.tb_id = fen_info->tb_id; fri.tb_id = fen_info->tb_id;
fri.dst = cpu_to_be32(*p_dst); fri.dst = cpu_to_be32(*p_dst);
fri.dst_len = fen_info->dst_len; fri.dst_len = fen_info->dst_len;
fri.tos = fen_info->tos; fri.dscp = inet_dsfield_to_dscp(fen_info->tos);
fri.type = fen_info->type; fri.type = fen_info->type;
fri.offload = false; fri.offload = false;
fri.trap = false; fri.trap = false;
@ -342,7 +343,7 @@ static void nsim_fib4_rt_hw_flags_set(struct net *net,
fri.tb_id = fib4_rt->common.key.tb_id; fri.tb_id = fib4_rt->common.key.tb_id;
fri.dst = cpu_to_be32(*p_dst); fri.dst = cpu_to_be32(*p_dst);
fri.dst_len = dst_len; fri.dst_len = dst_len;
fri.tos = fib4_rt->tos; fri.dscp = inet_dsfield_to_dscp(fib4_rt->tos);
fri.type = fib4_rt->type; fri.type = fib4_rt->type;
fri.offload = false; fri.offload = false;
fri.trap = trap; fri.trap = trap;

View File

@ -212,7 +212,7 @@ struct fib_rt_info {
u32 tb_id; u32 tb_id;
__be32 dst; __be32 dst;
int dst_len; int dst_len;
u8 tos; dscp_t dscp;
u8 type; u8 type;
u8 offload:1, u8 offload:1,
trap:1, trap:1,

View File

@ -524,7 +524,7 @@ void rtmsg_fib(int event, __be32 key, struct fib_alias *fa,
fri.tb_id = tb_id; fri.tb_id = tb_id;
fri.dst = key; fri.dst = key;
fri.dst_len = dst_len; fri.dst_len = dst_len;
fri.tos = inet_dscp_to_dsfield(fa->fa_dscp); fri.dscp = fa->fa_dscp;
fri.type = fa->fa_type; fri.type = fa->fa_type;
fri.offload = READ_ONCE(fa->offload); fri.offload = READ_ONCE(fa->offload);
fri.trap = READ_ONCE(fa->trap); fri.trap = READ_ONCE(fa->trap);
@ -1781,7 +1781,7 @@ int fib_dump_info(struct sk_buff *skb, u32 portid, u32 seq, int event,
rtm->rtm_family = AF_INET; rtm->rtm_family = AF_INET;
rtm->rtm_dst_len = fri->dst_len; rtm->rtm_dst_len = fri->dst_len;
rtm->rtm_src_len = 0; rtm->rtm_src_len = 0;
rtm->rtm_tos = fri->tos; rtm->rtm_tos = inet_dscp_to_dsfield(fri->dscp);
if (tb_id < 256) if (tb_id < 256)
rtm->rtm_table = tb_id; rtm->rtm_table = tb_id;
else else

View File

@ -1032,8 +1032,8 @@ fib_find_matching_alias(struct net *net, const struct fib_rt_info *fri)
hlist_for_each_entry_rcu(fa, &l->leaf, fa_list) { hlist_for_each_entry_rcu(fa, &l->leaf, fa_list) {
if (fa->fa_slen == slen && fa->tb_id == fri->tb_id && if (fa->fa_slen == slen && fa->tb_id == fri->tb_id &&
fa->fa_dscp == inet_dsfield_to_dscp(fri->tos) && fa->fa_dscp == fri->dscp && fa->fa_info == fri->fi &&
fa->fa_info == fri->fi && fa->fa_type == fri->type) fa->fa_type == fri->type)
return fa; return fa;
} }
@ -2305,7 +2305,7 @@ static int fn_trie_dump_leaf(struct key_vector *l, struct fib_table *tb,
fri.tb_id = tb->tb_id; fri.tb_id = tb->tb_id;
fri.dst = xkey; fri.dst = xkey;
fri.dst_len = KEYLENGTH - fa->fa_slen; fri.dst_len = KEYLENGTH - fa->fa_slen;
fri.tos = inet_dscp_to_dsfield(fa->fa_dscp); fri.dscp = fa->fa_dscp;
fri.type = fa->fa_type; fri.type = fa->fa_type;
fri.offload = READ_ONCE(fa->offload); fri.offload = READ_ONCE(fa->offload);
fri.trap = READ_ONCE(fa->trap); fri.trap = READ_ONCE(fa->trap);

View File

@ -3394,7 +3394,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
fri.tb_id = table_id; fri.tb_id = table_id;
fri.dst = res.prefix; fri.dst = res.prefix;
fri.dst_len = res.prefixlen; fri.dst_len = res.prefixlen;
fri.tos = fl4.flowi4_tos; fri.dscp = inet_dsfield_to_dscp(fl4.flowi4_tos);
fri.type = rt->rt_type; fri.type = rt->rt_type;
fri.offload = 0; fri.offload = 0;
fri.trap = 0; fri.trap = 0;
@ -3407,7 +3407,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
if (fa->fa_slen == slen && if (fa->fa_slen == slen &&
fa->tb_id == fri.tb_id && fa->tb_id == fri.tb_id &&
fa->fa_dscp == inet_dsfield_to_dscp(fri.tos) && fa->fa_dscp == fri.dscp &&
fa->fa_info == res.fi && fa->fa_info == res.fi &&
fa->fa_type == fri.type) { fa->fa_type == fri.type) {
fri.offload = READ_ONCE(fa->offload); fri.offload = READ_ONCE(fa->offload);