netfilter: Prepare netfilter to future .flowi4_tos conversion.
Subsystems (3)
cover netfilter: Prepare netfilter to future .flowi4_tos conversion.
There are multiple occasions where Netfilter code needs to perform route lookups and initialise struct flowi4. As we're in the process of converting the .flowi4_tos field to dscp_t, we need to convert the users so that they have a dscp_t value at hand, rather than a __u8.
All netfilter users get the DSCP (TOS) value from IPv4 packet headers. So we just need to use the new ip4h_dscp() helper to get a dscp_t variable.
Converting .flowi4_tos to dscp_t will allow to detect regressions where ECN bits are mistakenly treated as DSCP when doing route lookups.
Guillaume Nault (5):
netfilter: ipv4: Convert ip_route_me_harder() to dscp_t.
netfilter: flow_offload: Convert nft_flow_route() to dscp_t.
netfilter: rpfilter: Convert rpfilter_mt() to dscp_t.
netfilter: nft_fib: Convert nft_fib4_eval() to dscp_t.
netfilter: nf_dup4: Convert nf_dup_ipv4_route() to dscp_t.
net/ipv4/netfilter.c | 2 +- net/ipv4/netfilter/ipt_rpfilter.c | 2 +- net/ipv4/netfilter/nf_dup_ipv4.c | 2 +- net/ipv4/netfilter/nft_fib_ipv4.c | 3 ++- net/netfilter/nft_flow_offload.c | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-)
Signature · 1 line
2.39.2
PATCH 1/5 netfilter: ipv4: Convert ip_route_me_harder() to dscp_t.
Use ip4h_dscp()instead of reading iph->tos directly.
ip4h_dscp() returns a dscp_t value which is temporarily converted back to __u8 with inet_dscp_to_dsfield(). When converting ->flowi4_tos to dscp_t in the future, we'll only have to remove that inet_dscp_to_dsfield() call.
--- net/ipv4/netfilter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/netfilter.c +1 -1
@@ -44,7 +44,7 @@ int ip_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb, un*/ fl4.daddr = iph->daddr; fl4.saddr = saddr; - fl4.flowi4_tos = iph->tos &INET_DSCP_MASK ; + fl4.flowi4_tos =inet_dscp_to_dsfield (ip4h_dscp (iph)); fl4.flowi4_oif = sk ? sk->sk_bound_dev_if :0 ; fl4.flowi4_l3mdev =l3mdev_master_ifindex (dev); fl4.flowi4_mark = skb->mark;
Signature · 1 line
2.39.2
PATCH 2/5 netfilter: flow_offload: Convert nft_flow_route() to dscp_t.
In reply to Guillaume NaultUse ip4h_dscp()instead of reading ip_hdr()->tos directly.
ip4h_dscp() returns a dscp_t value which is temporarily converted back to __u8 with inet_dscp_to_dsfield(). When converting ->flowi4_tos to dscp_t in the future, we'll only have to remove that inet_dscp_to_dsfield() call.
Also, remove the comment about the net/ip.h include file, since it's now required for the ip4h_dscp() helper too.
--- net/netfilter/nft_flow_offload.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_flow_offload.c +2 -2
@@ -8,7 +8,7 @@#include <linux/spinlock.h> #include <linux/netfilter/nf_conntrack_common.h> #include <linux/netfilter/nf_tables.h> -#include <net/ip.h> /* for ipv4 options. */ +#include <net/ip.h> #include <net/inet_dscp.h> #include <net/netfilter/nf_tables.h> #include <net/netfilter/nf_tables_core.h>
@@ -236,7 +236,7 @@ static int nft_flow_route(const struct nft_pktinfo *pkt, fl.u.ip4.saddr = ct->tuplehash[!dir].tuple.src.u3.ip; fl.u.ip4.flowi4_oif =nft_in (pkt)->ifindex; fl.u.ip4.flowi4_iif = this_dst->dev->ifindex; - fl.u.ip4.flowi4_tos =ip_hdr (pkt->skb)->tos &INET_DSCP_MASK ; + fl.u.ip4.flowi4_tos =inet_dscp_to_dsfield (ip4h_dscp (ip_hdr (pkt->skb))); fl.u.ip4.flowi4_mark = pkt->skb->mark; fl.u.ip4.flowi4_flags =FLOWI_FLAG_ANYSRC ;break ;
Signature · 1 line
2.39.2
PATCH 3/5 netfilter: rpfilter: Convert rpfilter_mt() to dscp_t.
In reply to Guillaume NaultUse ip4h_dscp() instead of reading iph->tos directly.
ip4h_dscp() returns a dscp_t value which is temporarily converted back to __u8 with inet_dscp_to_dsfield(). When converting ->flowi4_tos to dscp_t in the future, we'll only have to remove that inet_dscp_to_dsfield() call.
--- net/ipv4/netfilter/ipt_rpfilter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/netfilter/ipt_rpfilter.c +1 -1
@@ -76,7 +76,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par) flow.daddr = iph->saddr; flow.saddr =rpfilter_get_saddr (iph->daddr); flow.flowi4_mark = info->flags &XT_RPFILTER_VALID_MARK ? skb->mark :0 ; - flow.flowi4_tos = iph->tos &INET_DSCP_MASK ; + flow.flowi4_tos =inet_dscp_to_dsfield (ip4h_dscp (iph)); flow.flowi4_scope =RT_SCOPE_UNIVERSE ; flow.flowi4_l3mdev =l3mdev_master_ifindex_rcu (xt_in (par)); flow.flowi4_uid =sock_net_uid (xt_net (par),NULL );
Signature · 1 line
2.39.2
PATCH 4/5 netfilter: nft_fib: Convert nft_fib4_eval() to dscp_t.
In reply to Guillaume NaultUse ip4h_dscp() instead of reading iph->tos directly.
ip4h_dscp() returns a dscp_t value which is temporarily converted back to __u8 with inet_dscp_to_dsfield(). When converting ->flowi4_tos to dscp_t in the future, we'll only have to remove that inet_dscp_to_dsfield() call.
--- net/ipv4/netfilter/nft_fib_ipv4.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/netfilter/nft_fib_ipv4.c +2 -1
@@ -11,6 +11,7 @@#include <net/netfilter/nft_fib.h> #include <net/inet_dscp.h> +#include <net/ip.h> #include <net/ip_fib.h> #include <net/route.h>
@@ -107,7 +108,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,if (priv->flags &NFTA_FIB_F_MARK ) fl4.flowi4_mark = pkt->skb->mark; - fl4.flowi4_tos = iph->tos &INET_DSCP_MASK ; + fl4.flowi4_tos =inet_dscp_to_dsfield (ip4h_dscp (iph));if (priv->flags &NFTA_FIB_F_DADDR ) { fl4.daddr = iph->daddr;
Signature · 1 line
2.39.2
PATCH 5/5 netfilter: nf_dup4: Convert nf_dup_ipv4_route() to dscp_t.
In reply to Guillaume NaultUse ip4h_dscp() instead of reading iph->tos directly.
ip4h_dscp() returns a dscp_t value which is temporarily converted back to __u8 with inet_dscp_to_dsfield(). When converting ->flowi4_tos to dscp_t in the future, we'll only have to remove that inet_dscp_to_dsfield() call.
--- net/ipv4/netfilter/nf_dup_ipv4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/netfilter/nf_dup_ipv4.c +1 -1
@@ -33,7 +33,7 @@ static bool nf_dup_ipv4_route(struct net *net, struct sk_buff *skb, fl4.flowi4_oif = oif; fl4.daddr = gw->s_addr; - fl4.flowi4_tos = iph->tos &INET_DSCP_MASK ; + fl4.flowi4_tos =inet_dscp_to_dsfield (ip4h_dscp (iph)); fl4.flowi4_scope =RT_SCOPE_UNIVERSE ; fl4.flowi4_flags =FLOWI_FLAG_KNOWN_NH ; rt =ip_route_output_key (net, &fl4);
Signature · 1 line
2.39.2
Pablo Neira Ayuso
maintainerQuoted 11 lines · Guillaume Nault
There are multiple occasions where Netfilter code needs to perform route lookups and initialise struct flowi4. As we're in the process of converting the .flowi4_tos field to
dscp_t, we need to convert the users so that they have adscp_tvalue at hand, rather than a__u8.All netfilter users get the DSCP (TOS) value from IPv4 packet headers. So we just need to use the new
ip4h_dscp()helper to get adscp_tvariable.Converting .flowi4_tos to
dscp_twill allow to detect regressions where ECN bits are mistakenly treated as DSCP when doing route lookups.
Series applied, thanks