netfilter: nat: remove csum_recalc hook
Subsystems (5)
Pablo Neira Ayuso
maintainerPATCH 10/29 netfilter: nat: remove csum_recalc hook
From: Florian Westphal <[email protected]>
We can now use direct calls.
--- include/net/netfilter/nf_nat_l3proto.h | 7 +++---- net/netfilter/nf_nat_helper.c | 12 ++++-------- net/netfilter/nf_nat_proto.c | 22 ++++++++++++++++++++-- 3 files changed, 27 insertions(+), 14 deletions(-)
include/net/netfilter/nf_nat_l3proto.h +3 -4
@@ -4,15 +4,14 @@struct nf_nat_l3proto {u8 l3proto; - -void (*csum_recalc)(struct sk_buff *skb,u8 proto, -void *data,__sum16 *check, -int datalen,int oldlen); };unsigned int nf_nat_manip_pkt (struct sk_buff *skb,struct nf_conn *ct,enum nf_nat_manip_type mtype,enum ip_conntrack_dir dir); +void nf_nat_csum_recalc (struct sk_buff *skb, +u8 nfproto,u8 proto,void *data,__sum16 *check, +int datalen,int oldlen);int nf_nat_l3proto_register (const struct nf_nat_l3proto *);void nf_nat_l3proto_unregister (const struct nf_nat_l3proto *);
net/netfilter/nf_nat_helper.c +4 -8
@@ -97,7 +97,6 @@ bool __nf_nat_mangle_tcp_packet(struct sk_buff *skb,const char *rep_buffer, unsigned int rep_len, bool adjust) { - const struct nf_nat_l3proto *l3proto; struct tcphdr *tcph;int oldlen, datalen;
@@ -117,9 +116,8 @@ bool __nf_nat_mangle_tcp_packet(struct sk_buff *skb, datalen = skb->len - protoff; - l3proto =__nf_nat_l3proto_find (nf_ct_l3num (ct)); - l3proto->csum_recalc (skb,IPPROTO_TCP , tcph, &tcph->check, - datalen, oldlen); +nf_nat_csum_recalc (skb,nf_ct_l3num (ct),IPPROTO_TCP , + tcph, &tcph->check, datalen, oldlen);if (adjust && rep_len != match_len) nf_ct_seqadj_set(ct, ctinfo, tcph->seq,
@@ -149,7 +147,6 @@ nf_nat_mangle_udp_packet(struct sk_buff *skb, const char *rep_buffer, unsigned int rep_len) { -const struct nf_nat_l3proto *l3proto;struct udphdr *udph;int datalen, oldlen;
@@ -175,9 +172,8 @@ nf_nat_mangle_udp_packet(struct sk_buff *skb,if (!udph->check && skb->ip_summed !=CHECKSUM_PARTIAL )return true; - l3proto =__nf_nat_l3proto_find (nf_ct_l3num (ct)); - l3proto->csum_recalc (skb,IPPROTO_UDP , udph, &udph->check, - datalen, oldlen); +nf_nat_csum_recalc (skb,nf_ct_l3num (ct),IPPROTO_TCP , + udph, &udph->check, datalen, oldlen);return true; }
net/netfilter/nf_nat_proto.c +20 -2
@@ -535,9 +535,28 @@ static void nf_nat_ipv6_csum_recalc(struct sk_buff *skb, }#endif +void nf_nat_csum_recalc (struct sk_buff *skb, +u8 nfproto,u8 proto,void *data,__sum16 *check, +int datalen,int oldlen) +{ +switch (nfproto) { +case NFPROTO_IPV4 : +nf_nat_ipv4_csum_recalc (skb, proto, data, check, + datalen, oldlen); +return ; +#if IS_ENABLED (CONFIG_IPV6 ) +case NFPROTO_IPV6 : +nf_nat_ipv6_csum_recalc (skb, proto, data, check, + datalen, oldlen); +return ; +#endif + } + +WARN_ON_ONCE (1 ); +} +static const struct nf_nat_l3proto nf_nat_l3proto_ipv4 = { .l3proto =NFPROTO_IPV4 , - .csum_recalc = nf_nat_ipv4_csum_recalc, }; int nf_nat_icmp_reply_translation(struct sk_buff *skb,
@@ -788,7 +807,6 @@ void nf_nat_l3proto_exit(void)#if IS_ENABLED (CONFIG_IPV6 )static const struct nf_nat_l3proto nf_nat_l3proto_ipv6 = { .l3proto =NFPROTO_IPV6 , - .csum_recalc = nf_nat_ipv6_csum_recalc, }; int nf_nat_icmpv6_reply_translation(struct sk_buff *skb,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 11/29 netfilter: nat: remove l3proto struct
From: Florian Westphal <[email protected]>
All l3proto function pointers have been removed.
--- include/net/netfilter/nf_nat_l3proto.h | 8 ----- net/netfilter/nf_nat_core.c | 54 ---------------------------------- net/netfilter/nf_nat_proto.c | 38 ------------------------ 3 files changed, 100 deletions(-)
include/net/netfilter/nf_nat_l3proto.h +0 -8
@@ -2,10 +2,6 @@#ifndef _NF_NAT_L3PROTO_H#define _NF_NAT_L3PROTO_H -struct nf_nat_l3proto { -u8 l3proto; -}; -unsigned int nf_nat_manip_pkt (struct sk_buff *skb,struct nf_conn *ct,enum nf_nat_manip_type mtype,enum ip_conntrack_dir dir);
@@ -13,10 +9,6 @@ void nf_nat_csum_recalc(struct sk_buff *skb, u8 nfproto, u8 proto, void *data, __sum16 *check, int datalen, int oldlen); -int nf_nat_l3proto_register (const struct nf_nat_l3proto *); -void nf_nat_l3proto_unregister (const struct nf_nat_l3proto *); -const struct nf_nat_l3proto *__nf_nat_l3proto_find (u8 l3proto); -int nf_nat_icmp_reply_translation (struct sk_buff *skb,struct nf_conn *ct,enum ip_conntrack_info ctinfo,unsigned int hooknum);
net/netfilter/nf_nat_core.c +0 -54
102 lines not on this page · raw message
net/netfilter/nf_nat_proto.c +0 -38
@@ -35,11 +35,6 @@#include <net/netfilter/nf_conntrack.h> #include <linux/netfilter/nfnetlink_conntrack.h> -static const struct nf_nat_l3proto nf_nat_l3proto_ipv4; -#if IS_ENABLED (CONFIG_IPV6 ) -static const struct nf_nat_l3proto nf_nat_l3proto_ipv6; -#endif - static void nf_csum_update(struct sk_buff *skb, unsigned int iphdroff, __sum16 *check, const struct nf_conntrack_tuple *t,
@@ -555,10 +550,6 @@ void nf_nat_csum_recalc(struct sk_buff *skb,WARN_ON_ONCE (1 ); } -static const struct nf_nat_l3proto nf_nat_l3proto_ipv4 = { - .l3proto =NFPROTO_IPV4 , -}; - int nf_nat_icmp_reply_translation(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info ctinfo,
@@ -779,36 +770,7 @@ void nf_nat_l3proto_ipv4_unregister_fn(struct net *net, const struct nf_hook_ops }EXPORT_SYMBOL_GPL (nf_nat_l3proto_ipv4_unregister_fn); -int nf_nat_l3proto_init (void ) -{ -int ret =nf_nat_l3proto_register (&nf_nat_l3proto_ipv4); -#if IS_ENABLED (CONFIG_IPV6 ) -if (ret) -return ret; - - ret =nf_nat_l3proto_register (&nf_nat_l3proto_ipv6); -if (ret ==0 ) -return ret; - -nf_nat_l3proto_unregister (&nf_nat_l3proto_ipv4); -#endif -return ret; -} - -void nf_nat_l3proto_exit (void ) -{ -#if IS_ENABLED (CONFIG_IPV6 ) -nf_nat_l3proto_unregister (&nf_nat_l3proto_ipv6); -#endif -nf_nat_l3proto_unregister (&nf_nat_l3proto_ipv4); -} - -#if IS_ENABLED (CONFIG_IPV6 ) -static const struct nf_nat_l3proto nf_nat_l3proto_ipv6 = { - .l3proto =NFPROTO_IPV6 , -}; - int nf_nat_icmpv6_reply_translation(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info ctinfo,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 13/29 netfilter: conntrack: avoid same-timeout update
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
No need to dirty a cache line if timeout is unchanged. Also, WARN() is useless here: we crash on 'skb->len' access if skb is NULL.
Last, ct->timeout is u32, not 'unsigned long' so adapt the function prototype accordingly.
--- include/net/netfilter/nf_conntrack.h | 10 +++++----- net/netfilter/nf_conntrack_core.c | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-)
include/net/netfilter/nf_conntrack.h +5 -5
@@ -190,23 +190,23 @@ bool nf_ct_get_tuplepr(const struct sk_buff *skb, unsigned int nhoff,void __nf_ct_refresh_acct (struct nf_conn *ct,enum ip_conntrack_info ctinfo,const struct sk_buff *skb, -unsigned long extra_jiffies,int do_acct); +u32 extra_jiffies,bool do_acct);/* Refresh conntrack for this many jiffies and do accounting */ static inline void nf_ct_refresh_acct (struct nf_conn *ct,enum ip_conntrack_info ctinfo,const struct sk_buff *skb, -unsigned long extra_jiffies) +u32 extra_jiffies) { -__nf_ct_refresh_acct (ct, ctinfo, skb, extra_jiffies,1 ); +__nf_ct_refresh_acct (ct, ctinfo, skb, extra_jiffies, true); }/* Refresh conntrack for this many jiffies */ static inline void nf_ct_refresh (struct nf_conn *ct,const struct sk_buff *skb, -unsigned long extra_jiffies) +u32 extra_jiffies) { -__nf_ct_refresh_acct (ct,0 , skb, extra_jiffies,0 ); +__nf_ct_refresh_acct (ct,0 , skb, extra_jiffies, false); }/* kill conntrack and do accounting */
net/netfilter/nf_conntrack_core.c +4 -5
@@ -1751,11 +1751,9 @@ EXPORT_SYMBOL_GPL(nf_conntrack_alter_reply);void __nf_ct_refresh_acct (struct nf_conn *ct,enum ip_conntrack_info ctinfo,const struct sk_buff *skb, -unsigned long extra_jiffies, -int do_acct) +u32 extra_jiffies, +bool do_acct) { -WARN_ON (!skb); -/* Only update if this is not a fixed timeout */ if (test_bit (IPS_FIXED_TIMEOUT_BIT , &ct->status)) goto acct;
@@ -1764,7 +1762,8 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,if (nf_ct_is_confirmed (ct)) extra_jiffies += nfct_time_stamp; - ct->timeout = extra_jiffies; +if (ct->timeout != extra_jiffies) + ct->timeout = extra_jiffies; acct:if (do_acct)nf_ct_acct_update (ct, ctinfo, skb->len);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 12/29 netfilter: nat: remove nf_nat_l3proto.h and nf_nat_core.h
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
The l3proto name is gone, its header file is the last trace. While at it, also remove nf_nat_core.h, its very small and all users include nf_nat.h too.
before:
text data bss dec hex filename
22948 1612 4136 28696 7018 nf_nat.ko
after removal of l3proto register/unregister functions:
text data bss dec hex filename
22196 1516 4136 27848 6cc8 nf_nat.ko
checkpatch complains about overly long lines, but line breaks do not make things more readable and the line length gets smaller here, not larger.
--- include/net/netfilter/nf_nat.h | 39 +++++++++++++++++++++++++++++++++ include/net/netfilter/nf_nat_core.h | 29 ------------------------ include/net/netfilter/nf_nat_l3proto.h | 26 ---------------------- net/ipv4/netfilter/iptable_nat.c | 8 +++---- net/ipv4/netfilter/nft_chain_nat_ipv4.c | 6 ++--- net/ipv6/netfilter/ip6table_nat.c | 8 +++---- net/ipv6/netfilter/nft_chain_nat_ipv6.c | 6 ++--- net/netfilter/nf_conntrack_core.c | 1 - net/netfilter/nf_conntrack_netlink.c | 2 +- net/netfilter/nf_nat_core.c | 2 -- net/netfilter/nf_nat_helper.c | 2 -- net/netfilter/nf_nat_proto.c | 18 +++++++-------- net/netfilter/nft_nat.c | 2 -- net/netfilter/xt_nat.c | 2 +- net/openvswitch/conntrack.c | 4 +--- 15 files changed, 60 insertions(+), 95 deletions(-) delete mode 100644 include/net/netfilter/nf_nat_core.h delete mode 100644 include/net/netfilter/nf_nat_l3proto.h
include/net/netfilter/nf_nat.h +39 -0
@@ -73,4 +73,43 @@ int nf_nat_register_fn(struct net *net, const struct nf_hook_ops *ops, const struct nf_hook_ops *nat_ops, unsigned int ops_count);void nf_nat_unregister_fn (struct net *net,const struct nf_hook_ops *ops,unsigned int ops_count); + +unsigned int nf_nat_packet (struct nf_conn *ct,enum ip_conntrack_info ctinfo, +unsigned int hooknum,struct sk_buff *skb); + +unsigned int nf_nat_manip_pkt (struct sk_buff *skb,struct nf_conn *ct, +enum nf_nat_manip_type mtype, +enum ip_conntrack_dir dir); +void nf_nat_csum_recalc (struct sk_buff *skb, +u8 nfproto,u8 proto,void *data,__sum16 *check, +int datalen,int oldlen); + +int nf_nat_icmp_reply_translation (struct sk_buff *skb,struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +unsigned int hooknum); + +int nf_nat_icmpv6_reply_translation (struct sk_buff *skb,struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +unsigned int hooknum,unsigned int hdrlen); + +int nf_nat_ipv4_register_fn (struct net *net,const struct nf_hook_ops *ops); +void nf_nat_ipv4_unregister_fn (struct net *net,const struct nf_hook_ops *ops); + +int nf_nat_ipv6_register_fn (struct net *net,const struct nf_hook_ops *ops); +void nf_nat_ipv6_unregister_fn (struct net *net,const struct nf_hook_ops *ops); + +unsigned int +nf_nat_inet_fn (void *priv,struct sk_buff *skb, +const struct nf_hook_state *state); + +int nf_xfrm_me_harder (struct net *n,struct sk_buff *s,unsigned int family); + +static inline int nf_nat_initialized (struct nf_conn *ct, +enum nf_nat_manip_type manip) +{ +if (manip ==NF_NAT_MANIP_SRC ) +return ct->status &IPS_SRC_NAT_DONE ; +else +return ct->status &IPS_DST_NAT_DONE ; +}#endif
include/net/netfilter/nf_nat_core.h deleted +0 -29
@@ -1,29 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _NF_NAT_CORE_H -#define _NF_NAT_CORE_H -#include <linux/list.h> -#include <net/netfilter/nf_conntrack.h> -#include <net/netfilter/nf_nat.h> - -/* This header used to share core functionality between the standalone -NAT module, and the compatibility layer's use of NAT for masquerading. */ - -unsigned int nf_nat_packet (struct nf_conn *ct,enum ip_conntrack_info ctinfo, -unsigned int hooknum,struct sk_buff *skb); - -unsigned int -nf_nat_inet_fn (void *priv,struct sk_buff *skb, -const struct nf_hook_state *state); - -int nf_xfrm_me_harder (struct net *net,struct sk_buff *skb,unsigned int family); - -static inline int nf_nat_initialized (struct nf_conn *ct, -enum nf_nat_manip_type manip) -{ -if (manip ==NF_NAT_MANIP_SRC ) -return ct->status &IPS_SRC_NAT_DONE ; -else -return ct->status &IPS_DST_NAT_DONE ; -} - -#endif /* _NF_NAT_CORE_H */
include/net/netfilter/nf_nat_l3proto.h deleted +0 -26
@@ -1,26 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _NF_NAT_L3PROTO_H -#define _NF_NAT_L3PROTO_H - -unsigned int nf_nat_manip_pkt (struct sk_buff *skb,struct nf_conn *ct, -enum nf_nat_manip_type mtype, -enum ip_conntrack_dir dir); -void nf_nat_csum_recalc (struct sk_buff *skb, -u8 nfproto,u8 proto,void *data,__sum16 *check, -int datalen,int oldlen); - -int nf_nat_icmp_reply_translation (struct sk_buff *skb,struct nf_conn *ct, -enum ip_conntrack_info ctinfo, -unsigned int hooknum); - -int nf_nat_icmpv6_reply_translation (struct sk_buff *skb,struct nf_conn *ct, -enum ip_conntrack_info ctinfo, -unsigned int hooknum,unsigned int hdrlen); - -int nf_nat_l3proto_ipv4_register_fn (struct net *net,const struct nf_hook_ops *ops); -void nf_nat_l3proto_ipv4_unregister_fn (struct net *net,const struct nf_hook_ops *ops); - -int nf_nat_l3proto_ipv6_register_fn (struct net *net,const struct nf_hook_ops *ops); -void nf_nat_l3proto_ipv6_unregister_fn (struct net *net,const struct nf_hook_ops *ops); - -#endif /* _NF_NAT_L3PROTO_H */
net/ipv4/netfilter/iptable_nat.c +3 -5
@@ -15,8 +15,6 @@#include <net/ip.h> #include <net/netfilter/nf_nat.h> -#include <net/netfilter/nf_nat_core.h> -#include <net/netfilter/nf_nat_l3proto.h> static int __net_init iptable_nat_table_init (struct net *net);
@@ -70,10 +68,10 @@ static int ipt_nat_register_lookups(struct net *net)int i, ret;for (i =0 ; i <ARRAY_SIZE (nf_nat_ipv4_ops); i++) { - ret =nf_nat_l3proto_ipv4_register_fn (net, &nf_nat_ipv4_ops[i]); + ret =nf_nat_ipv4_register_fn (net, &nf_nat_ipv4_ops[i]);if (ret) {while (i) -nf_nat_l3proto_ipv4_unregister_fn (net, &nf_nat_ipv4_ops[--i]); +nf_nat_ipv4_unregister_fn (net, &nf_nat_ipv4_ops[--i]);return ret; }
@@ -87,7 +85,7 @@ static void ipt_nat_unregister_lookups(struct net *net)int i;for (i =0 ; i <ARRAY_SIZE (nf_nat_ipv4_ops); i++) -nf_nat_l3proto_ipv4_unregister_fn (net, &nf_nat_ipv4_ops[i]); +nf_nat_ipv4_unregister_fn (net, &nf_nat_ipv4_ops[i]); }static int __net_init iptable_nat_table_init (struct net *net)
net/ipv4/netfilter/nft_chain_nat_ipv4.c +2 -4
@@ -20,10 +20,8 @@#include <linux/netfilter/nf_tables.h> #include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_nat.h> -#include <net/netfilter/nf_nat_core.h> #include <net/netfilter/nf_tables.h> #include <net/netfilter/nf_tables_ipv4.h> -#include <net/netfilter/nf_nat_l3proto.h> #include <net/ip.h> static unsigned int nft_nat_do_chain(void *priv,
@@ -40,12 +38,12 @@ static unsigned int nft_nat_do_chain(void *priv,static int nft_nat_ipv4_reg (struct net *net,const struct nf_hook_ops *ops) { -return nf_nat_l3proto_ipv4_register_fn (net, ops); +return nf_nat_ipv4_register_fn (net, ops); }static void nft_nat_ipv4_unreg (struct net *net,const struct nf_hook_ops *ops) { -nf_nat_l3proto_ipv4_unregister_fn (net, ops); +nf_nat_ipv4_unregister_fn (net, ops); }static const struct nft_chain_type nft_chain_nat_ipv4 = {
net/ipv6/netfilter/ip6table_nat.c +3 -5
@@ -17,8 +17,6 @@#include <net/ipv6.h> #include <net/netfilter/nf_nat.h> -#include <net/netfilter/nf_nat_core.h> -#include <net/netfilter/nf_nat_l3proto.h> static int __net_init ip6table_nat_table_init (struct net *net);
@@ -72,10 +70,10 @@ static int ip6t_nat_register_lookups(struct net *net)int i, ret;for (i =0 ; i <ARRAY_SIZE (nf_nat_ipv6_ops); i++) { - ret =nf_nat_l3proto_ipv6_register_fn (net, &nf_nat_ipv6_ops[i]); + ret =nf_nat_ipv6_register_fn (net, &nf_nat_ipv6_ops[i]);if (ret) {while (i) -nf_nat_l3proto_ipv6_unregister_fn (net, &nf_nat_ipv6_ops[--i]); +nf_nat_ipv6_unregister_fn (net, &nf_nat_ipv6_ops[--i]);return ret; }
@@ -89,7 +87,7 @@ static void ip6t_nat_unregister_lookups(struct net *net)int i;for (i =0 ; i <ARRAY_SIZE (nf_nat_ipv6_ops); i++) -nf_nat_l3proto_ipv6_unregister_fn (net, &nf_nat_ipv6_ops[i]); +nf_nat_ipv6_unregister_fn (net, &nf_nat_ipv6_ops[i]); }static int __net_init ip6table_nat_table_init (struct net *net)
net/ipv6/netfilter/nft_chain_nat_ipv6.c +2 -4
@@ -18,10 +18,8 @@#include <linux/netfilter/nf_tables.h> #include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_nat.h> -#include <net/netfilter/nf_nat_core.h> #include <net/netfilter/nf_tables.h> #include <net/netfilter/nf_tables_ipv6.h> -#include <net/netfilter/nf_nat_l3proto.h> #include <net/ipv6.h> static unsigned int nft_nat_do_chain(void *priv,
@@ -38,12 +36,12 @@ static unsigned int nft_nat_do_chain(void *priv,static int nft_nat_ipv6_reg (struct net *net,const struct nf_hook_ops *ops) { -return nf_nat_l3proto_ipv6_register_fn (net, ops); +return nf_nat_ipv6_register_fn (net, ops); }static void nft_nat_ipv6_unreg (struct net *net,const struct nf_hook_ops *ops) { -nf_nat_l3proto_ipv6_unregister_fn (net, ops); +nf_nat_ipv6_unregister_fn (net, ops); }static const struct nft_chain_type nft_chain_nat_ipv6 = {
net/netfilter/nf_conntrack_core.c +0 -1
@@ -51,7 +51,6 @@#include <net/netfilter/nf_conntrack_labels.h> #include <net/netfilter/nf_conntrack_synproxy.h> #include <net/netfilter/nf_nat.h> -#include <net/netfilter/nf_nat_core.h> #include <net/netfilter/nf_nat_helper.h> #include <net/netns/hash.h> #include <net/ip.h>
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -46,7 +46,7 @@#include <net/netfilter/nf_conntrack_labels.h> #include <net/netfilter/nf_conntrack_synproxy.h> #ifdef CONFIG_NF_NAT_NEEDED -#include <net/netfilter/nf_nat_core.h> +#include <net/netfilter/nf_nat.h> #include <net/netfilter/nf_nat_helper.h> #endif
net/netfilter/nf_nat_core.c +0 -2
@@ -22,8 +22,6 @@#include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_conntrack_core.h> #include <net/netfilter/nf_nat.h> -#include <net/netfilter/nf_nat_l3proto.h> -#include <net/netfilter/nf_nat_core.h> #include <net/netfilter/nf_nat_helper.h> #include <net/netfilter/nf_conntrack_helper.h> #include <net/netfilter/nf_conntrack_seqadj.h>
net/netfilter/nf_nat_helper.c +0 -2
@@ -22,8 +22,6 @@#include <net/netfilter/nf_conntrack_expect.h> #include <net/netfilter/nf_conntrack_seqadj.h> #include <net/netfilter/nf_nat.h> -#include <net/netfilter/nf_nat_l3proto.h> -#include <net/netfilter/nf_nat_core.h> #include <net/netfilter/nf_nat_helper.h> /* Frobs data inside this packet, which is linear. */
net/netfilter/nf_nat_proto.c +8 -10
@@ -20,8 +20,6 @@#include <linux/netfilter.h> #include <net/netfilter/nf_nat.h> -#include <net/netfilter/nf_nat_core.h> -#include <net/netfilter/nf_nat_l3proto.h> #include <linux/ipv6.h> #include <linux/netfilter_ipv6.h>
@@ -758,17 +756,17 @@ static const struct nf_hook_ops nf_nat_ipv4_ops[] = { }, }; -int nf_nat_l3proto_ipv4_register_fn (struct net *net,const struct nf_hook_ops *ops) +int nf_nat_ipv4_register_fn (struct net *net,const struct nf_hook_ops *ops) {return nf_nat_register_fn (net, ops, nf_nat_ipv4_ops,ARRAY_SIZE (nf_nat_ipv4_ops)); } -EXPORT_SYMBOL_GPL (nf_nat_l3proto_ipv4_register_fn); +EXPORT_SYMBOL_GPL (nf_nat_ipv4_register_fn); -void nf_nat_l3proto_ipv4_unregister_fn (struct net *net,const struct nf_hook_ops *ops) +void nf_nat_ipv4_unregister_fn (struct net *net,const struct nf_hook_ops *ops) {nf_nat_unregister_fn (net, ops,ARRAY_SIZE (nf_nat_ipv4_ops)); } -EXPORT_SYMBOL_GPL (nf_nat_l3proto_ipv4_unregister_fn); +EXPORT_SYMBOL_GPL (nf_nat_ipv4_unregister_fn);#if IS_ENABLED (CONFIG_IPV6 ) int nf_nat_icmpv6_reply_translation(struct sk_buff *skb,
@@ -1010,16 +1008,16 @@ static const struct nf_hook_ops nf_nat_ipv6_ops[] = { }, }; -int nf_nat_l3proto_ipv6_register_fn (struct net *net,const struct nf_hook_ops *ops) +int nf_nat_ipv6_register_fn (struct net *net,const struct nf_hook_ops *ops) {return nf_nat_register_fn (net, ops, nf_nat_ipv6_ops,ARRAY_SIZE (nf_nat_ipv6_ops)); } -EXPORT_SYMBOL_GPL (nf_nat_l3proto_ipv6_register_fn); +EXPORT_SYMBOL_GPL (nf_nat_ipv6_register_fn); -void nf_nat_l3proto_ipv6_unregister_fn (struct net *net,const struct nf_hook_ops *ops) +void nf_nat_ipv6_unregister_fn (struct net *net,const struct nf_hook_ops *ops) {nf_nat_unregister_fn (net, ops,ARRAY_SIZE (nf_nat_ipv6_ops)); } -EXPORT_SYMBOL_GPL (nf_nat_l3proto_ipv6_unregister_fn); +EXPORT_SYMBOL_GPL (nf_nat_ipv6_unregister_fn);#endif /* CONFIG_IPV6 */
net/netfilter/nft_nat.c +0 -2
@@ -21,9 +21,7 @@#include <linux/netfilter/nf_tables.h> #include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_nat.h> -#include <net/netfilter/nf_nat_core.h> #include <net/netfilter/nf_tables.h> -#include <net/netfilter/nf_nat_l3proto.h> #include <net/ip.h> struct nft_nat {
net/netfilter/xt_nat.c +1 -1
@@ -14,7 +14,7 @@#include <linux/skbuff.h> #include <linux/netfilter.h> #include <linux/netfilter/x_tables.h> -#include <net/netfilter/nf_nat_core.h> +#include <net/netfilter/nf_nat.h> static int xt_nat_checkentry_v0 (const struct xt_tgchk_param *par) {
net/openvswitch/conntrack.c +1 -3
@@ -29,9 +29,7 @@#include <net/ipv6_frag.h> #ifdef CONFIG_NF_NAT_NEEDED -#include <linux/netfilter/nf_nat.h> -#include <net/netfilter/nf_nat_core.h> -#include <net/netfilter/nf_nat_l3proto.h> +#include <net/netfilter/nf_nat.h> #endif #include "datapath.h"
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 16/29 netfilter: nft_set_hash: bogus element self comparison from deactivation path
In reply to Pablo Neira AyusoUse the element from the loop iteration, not the same element we want to deactivate otherwise this branch always evaluates true.
--- net/netfilter/nft_set_hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_set_hash.c +1 -1
@@ -541,7 +541,7 @@ static void *nft_hash_deactivate(const struct net *net, hash =nft_jhash (set, priv, &this->ext);hlist_for_each_entry (he, &priv->table[hash], node) { -if (!memcmp (nft_set_ext_key (&this->ext), &elem->key.val, +if (!memcmp (nft_set_ext_key (&he->ext), &elem->key.val, set->klen) &&nft_set_elem_active (&he->ext, genmask)) {nft_set_elem_change_active (net, set, &he->ext);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 19/29 netfilter: conntrack: tcp: only close if RST matches exact sequence
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
TCP resets cause instant transition from established to closed state provided the reset is in-window. Endpoints that implement RFC 5961 require resets to match the next expected sequence number. RST segments that are in-window (but that do not match RCV.NXT) are ignored, and a "challenge ACK" is sent back.
Main problem for conntrack is that its a middlebox, i.e. whereas an end host might have ACK'd SEQ (and would thus accept an RST with this sequence number), conntrack might not have seen this ACK (yet).
Therefore we can't simply flag RSTs with non-exact match as invalid.
This updates RST processing as follows:
1. If the connection is in a state other than ESTABLISHED, nothing is changed, RST is subject to normal in-window check.
2. If the RSTs sequence number either matches exactly RCV.NXT, connection state moves to CLOSE.
3. The same applies if the RST sequence number aligns with a previous packet in the same direction.
In all other cases, the connection remains in ESTABLISHED state. If the normal-in-window check passes, the timeout will be lowered to that of CLOSE.
If the peer sends a challenge ack, connection timeout will be reset.
If the challenge ACK triggers another RST (RST was valid after all), this 2nd RST will match expected sequence and conntrack state changes to CLOSE.
If no challenge ACK is received, the connection will time out after CLOSE seconds (10 seconds by default), just like without this patch.
Packetdrill test case:
0.000 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3 0.000 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 0.000 bind(3, ..., ...) = 0
0.000 listen(3, 1) = 0
0.100 < S 0:0(0) win 32792 <mss 1460,sackOK,nop,nop,nop,wscale 7> 0.100 > S. 0:0(0) ack 1 win 64240 <mss 1460,nop,nop,sackOK,nop,wscale 7> 0.200 < . 1:1(0) ack 1 win 257
0.200 accept(3, ..., ...) = 4
// Receive a segment.
0.210 < P. 1:1001(1000) ack 1 win 46
0.210 > . 1:1(0) ack 1001
// Application writes 1000 bytes.
0.250 write(4, ..., 1000) = 1000
0.250 > P. 1:1001(1000) ack 1001
// First reset, old sequence. Conntrack (correctly) considers this // invalid due to failed window validation (regardless of this patch). 0.260 < R 2:2(0) ack 1001 win 260
// 2nd reset, but too far ahead sequence. Same: correctly handled // as invalid.
0.270 < R 99990001:99990001(0) ack 1001 win 260
// in-window, but not exact sequence.
// Current Linux kernels might reply with a challenge ack, and do not // remove connection.
// Without this patch, conntrack state moves to CLOSE.
// With patch, timeout is lowered like CLOSE, but connection stays // in ESTABLISHED state.
0.280 < R 1010:1010(0) ack 1001 win 260
// Expect challenge ACK
0.281 > . 1001:1001(0) ack 1001 win 501
// With or without this patch, RST will cause connection // to move to CLOSE (sequence number matches) // 0.282 < R 1001:1001(0) ack 1001 win 260
// ACK
0.300 < . 1001:1001(0) ack 1001 win 257
// more data could be exchanged here, connection
// is still established
// Client closes the connection.
0.610 < F. 1001:1001(0) ack 1001 win 260
0.650 > . 1001:1001(0) ack 1002
// Close the connection without reading outstanding data 0.700 close(4) = 0
// so one more reset. Will be deemed acceptable with patch as well:
// connection is already closing.
0.701 > R. 1001:1001(0) ack 1002 win 501
// End packetdrill test case.
With patch, this generates following conntrack events:
[NEW] 120 SYN_SENT src=10.0.2.1 dst=10.0.0.1 sport=5437 dport=80 [UNREPLIED]
[UPDATE] 60 SYN_RECV src=10.0.2.1 dst=10.0.0.1 sport=5437 dport=80 [UPDATE] 432000 ESTABLISHED src=10.0.2.1 dst=10.0.0.1 sport=5437 dport=80 [ASSURED] [UPDATE] 120 FIN_WAIT src=10.0.2.1 dst=10.0.0.1 sport=5437 dport=80 [ASSURED] [UPDATE] 60 CLOSE_WAIT src=10.0.2.1 dst=10.0.0.1 sport=5437 dport=80 [ASSURED] [UPDATE] 10 CLOSE src=10.0.2.1 dst=10.0.0.1 sport=5437 dport=80 [ASSURED]
Without patch, first RST moves connection to close, whereas socket state does not change until FIN is received.
[NEW] 120 SYN_SENT src=10.0.2.1 dst=10.0.0.1 sport=5141 dport=80 [UNREPLIED]
[UPDATE] 60 SYN_RECV src=10.0.2.1 dst=10.0.0.1 sport=5141 dport=80 [UPDATE] 432000 ESTABLISHED src=10.0.2.1 dst=10.0.0.1 sport=5141 dport=80 [ASSURED] [UPDATE] 10 CLOSE src=10.0.2.1 dst=10.0.0.1 sport=5141 dport=80 [ASSURED]
--- net/netfilter/nf_conntrack_proto_tcp.c | 50 +++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 10 deletions(-)
net/netfilter/nf_conntrack_proto_tcp.c +40 -10
@@ -828,6 +828,12 @@ static noinline bool tcp_new(struct nf_conn *ct, const struct sk_buff *skb,return true; } +static bool nf_conntrack_tcp_established (const struct nf_conn *ct) +{ +return ct->proto.tcp.state ==TCP_CONNTRACK_ESTABLISHED && +test_bit (IPS_ASSURED_BIT , &ct->status); +} +/* Returns verdict for packet, or -1 for invalid. */ int nf_conntrack_tcp_packet(struct nf_conn *ct, struct sk_buff *skb,
@@ -1030,16 +1036,38 @@ int nf_conntrack_tcp_packet(struct nf_conn *ct, new_state =TCP_CONNTRACK_ESTABLISHED ;break ;case TCP_CONNTRACK_CLOSE : -if (index ==TCP_RST_SET - && (ct->proto.tcp.seen[!dir].flags &IP_CT_TCP_FLAG_MAXACK_SET ) - &&before (ntohl (th->seq), ct->proto.tcp.seen[!dir].td_maxack)) { -/* Invalid RST */ -spin_unlock_bh (&ct->lock); -nf_ct_l4proto_log_invalid (skb, ct,"invalid rst" ); -return -NF_ACCEPT ; +if (index !=TCP_RST_SET ) +break ; + +if (ct->proto.tcp.seen[!dir].flags &IP_CT_TCP_FLAG_MAXACK_SET ) { +u32 seq =ntohl (th->seq); + +if (before (seq, ct->proto.tcp.seen[!dir].td_maxack)) { +/* Invalid RST */ +spin_unlock_bh (&ct->lock); +nf_ct_l4proto_log_invalid (skb, ct,"invalid rst" ); +return -NF_ACCEPT ; + } + +if (!nf_conntrack_tcp_established (ct) || + seq == ct->proto.tcp.seen[!dir].td_maxack) +break ; + +/* Check if rst is part of train, such as +* foo:80 > bar:4379: P, 235946583:235946602(19) ack 42 +* foo:80 > bar:4379: R, 235946602:235946602(0) ack 42 +*/ +if (ct->proto.tcp.last_index ==TCP_ACK_SET && + ct->proto.tcp.last_dir == dir && + seq == ct->proto.tcp.last_end) +break ; + +/* ... RST sequence number doesn't match exactly, keep +* established state to allow a possible challenge ACK. +*/ + new_state = old_state; } -if (index ==TCP_RST_SET - && ((test_bit (IPS_SEEN_REPLY_BIT , &ct->status) +if (((test_bit (IPS_SEEN_REPLY_BIT , &ct->status) && ct->proto.tcp.last_index ==TCP_SYN_SET ) || (!test_bit (IPS_ASSURED_BIT , &ct->status) && ct->proto.tcp.last_index == TCP_ACK_SET))
@@ -1055,7 +1083,7 @@ int nf_conntrack_tcp_packet(struct nf_conn *ct,* segments we ignored. */ goto in_window; } -/* Just fall through */ +break ;default :/* Keep compilers happy. */ break ;
@@ -1090,6 +1118,8 @@ int nf_conntrack_tcp_packet(struct nf_conn *ct,if (ct->proto.tcp.retrans >= tn->tcp_max_retrans && timeouts[new_state] > timeouts[TCP_CONNTRACK_RETRANS ]) timeout = timeouts[TCP_CONNTRACK_RETRANS ]; +else if (unlikely (index ==TCP_RST_SET )) + timeout = timeouts[TCP_CONNTRACK_CLOSE ];else if ((ct->proto.tcp.seen[0 ].flags | ct->proto.tcp.seen[1 ].flags) &IP_CT_TCP_FLAG_DATA_UNACKNOWLEDGED && timeouts[new_state] > timeouts[TCP_CONNTRACK_UNACK ])
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 17/29 netfilter: nft_set_hash: remove nft_hash_key()
In reply to Pablo Neira Ayusohashtable is never used for 2-byte keys, remove nft_hash_key().
--- net/netfilter/nft_set_hash.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
net/netfilter/nft_set_hash.c +2 -11
@@ -442,15 +442,6 @@ static void *nft_hash_get(const struct net *net, const struct nft_set *set,return ERR_PTR (-ENOENT ); } -/* nft_hash_select_ops() makes sure key size can be either 2 or 4 bytes . */ -static inline u32 nft_hash_key (const u32 *key,u32 klen) -{ -if (klen ==4 ) -return *key; - -return *(u16 *)key; -} -static bool nft_hash_lookup_fast (const struct net *net,const struct nft_set *set,const u32 *key,const struct nft_set_ext **ext)
@@ -460,11 +451,11 @@ static bool nft_hash_lookup_fast(const struct net *net,const struct nft_hash_elem *he;u32 hash, k1, k2; - k1 =nft_hash_key (key, set->klen); + k1 = *key; hash =jhash_1word (k1, priv->seed); hash =reciprocal_scale (hash, priv->buckets);hlist_for_each_entry_rcu (he, &priv->table[hash], node) { - k2 =nft_hash_key (nft_set_ext_key (&he->ext)->data, set->klen); + k2 = *(u32 *)nft_set_ext_key (&he->ext)->data;if (k1 == k2 &&nft_set_elem_active (&he->ext, genmask)) { *ext = &he->ext;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 18/29 ipvs: change some data types from int to bool
In reply to Pablo Neira AyusoFrom: Andrea Claudi <[email protected]>
Change the data type of the following variables from int to bool across ipvs code:
- found
- loop
- need_full_dest
- need_full_svc
- payload_csum
Also change the following functions to use bool full_entry param instead of int:
- ip_vs_genl_parse_dest()
- ip_vs_genl_parse_service()
This patch does not change any functionality but makes the source code slightly easier to read.
--- net/netfilter/ipvs/ip_vs_ctl.c | 12 ++++++------ net/netfilter/ipvs/ip_vs_ftp.c | 4 ++-- net/netfilter/ipvs/ip_vs_proto_tcp.c | 8 ++++---- net/netfilter/ipvs/ip_vs_proto_udp.c | 8 ++++---- net/netfilter/ipvs/ip_vs_xmit.c | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +6 -6
@@ -3086,7 +3086,7 @@ static bool ip_vs_is_af_valid(int af)static int ip_vs_genl_parse_service (struct netns_ipvs *ipvs,struct ip_vs_service_user_kern *usvc, -struct nlattr *nla,int full_entry, +struct nlattr *nla,bool full_entry,struct ip_vs_service **ret_svc) {struct nlattr *attrs[IPVS_SVC_ATTR_MAX +1 ];
@@ -3173,7 +3173,7 @@ static struct ip_vs_service *ip_vs_genl_find_service(struct netns_ipvs *ipvs,struct ip_vs_service *svc;int ret; - ret =ip_vs_genl_parse_service (ipvs, &usvc, nla,0 , &svc); + ret =ip_vs_genl_parse_service (ipvs, &usvc, nla, false, &svc);return ret ?ERR_PTR (ret) : svc; }
@@ -3283,7 +3283,7 @@ static int ip_vs_genl_dump_dests(struct sk_buff *skb, }static int ip_vs_genl_parse_dest (struct ip_vs_dest_user_kern *udest, -struct nlattr *nla,int full_entry) +struct nlattr *nla,bool full_entry) {struct nlattr *attrs[IPVS_DEST_ATTR_MAX +1 ];struct nlattr *nla_addr, *nla_port;
@@ -3545,11 +3545,11 @@ static int ip_vs_genl_set_daemon(struct sk_buff *skb, struct genl_info *info)static int ip_vs_genl_set_cmd (struct sk_buff *skb,struct genl_info *info) { +bool need_full_svc = false, need_full_dest = false;struct ip_vs_service *svc =NULL ;struct ip_vs_service_user_kern usvc;struct ip_vs_dest_user_kern udest;int ret =0 , cmd; -int need_full_svc =0 , need_full_dest =0 ;struct net *net =sock_net (skb->sk);struct netns_ipvs *ipvs =net_ipvs (net);
@@ -3573,7 +3573,7 @@ static int ip_vs_genl_set_cmd(struct sk_buff *skb, struct genl_info *info)* received a valid one. We need a full service specification when * adding / editing a service. Only identifying members otherwise. */ if (cmd ==IPVS_CMD_NEW_SERVICE || cmd ==IPVS_CMD_SET_SERVICE ) - need_full_svc =1 ; + need_full_svc = true; ret = ip_vs_genl_parse_service(ipvs, &usvc, info->attrs[IPVS_CMD_ATTR_SERVICE],
@@ -3593,7 +3593,7 @@ static int ip_vs_genl_set_cmd(struct sk_buff *skb, struct genl_info *info)if (cmd ==IPVS_CMD_NEW_DEST || cmd ==IPVS_CMD_SET_DEST || cmd ==IPVS_CMD_DEL_DEST ) {if (cmd !=IPVS_CMD_DEL_DEST ) - need_full_dest =1 ; + need_full_dest = true; ret = ip_vs_genl_parse_dest(&udest, info->attrs[IPVS_CMD_ATTR_DEST],
net/netfilter/ipvs/ip_vs_ftp.c +2 -2
@@ -124,7 +124,7 @@ static int ip_vs_ftp_get_addrport(char *data, char *data_limit, } s = data + plen;if (skip) { -int found =0 ; +bool found = false;for (;; s++) {if (s == data_limit)
@@ -136,7 +136,7 @@ static int ip_vs_ftp_get_addrport(char *data, char *data_limit,if (!ext &&isdigit (*s))break ;if (*s == skip) - found =1 ; + found = true; }else if (*s != skip) {break ; }
net/netfilter/ipvs/ip_vs_proto_tcp.c +4 -4
@@ -153,8 +153,8 @@ tcp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, {struct tcphdr *tcph;unsigned int tcphoff = iph->len; +bool payload_csum = false;int oldlen; -int payload_csum =0 ;#ifdef CONFIG_IP_VS_IPV6 if (cp->af ==AF_INET6 && iph->fragoffs)
@@ -180,7 +180,7 @@ tcp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,if (ret ==1 ) oldlen = skb->len - tcphoff;else - payload_csum =1 ; + payload_csum = true; } tcph = (void *)skb_network_header (skb) + tcphoff;
@@ -231,8 +231,8 @@ tcp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, {struct tcphdr *tcph;unsigned int tcphoff = iph->len; +bool payload_csum = false;int oldlen; -int payload_csum =0 ;#ifdef CONFIG_IP_VS_IPV6 if (cp->af ==AF_INET6 && iph->fragoffs)
@@ -261,7 +261,7 @@ tcp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,if (ret ==1 ) oldlen = skb->len - tcphoff;else - payload_csum =1 ; + payload_csum = true; } tcph = (void *)skb_network_header (skb) + tcphoff;
net/netfilter/ipvs/ip_vs_proto_udp.c +4 -4
@@ -143,8 +143,8 @@ udp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, {struct udphdr *udph;unsigned int udphoff = iph->len; +bool payload_csum = false;int oldlen; -int payload_csum =0 ;#ifdef CONFIG_IP_VS_IPV6 if (cp->af ==AF_INET6 && iph->fragoffs)
@@ -172,7 +172,7 @@ udp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,if (ret ==1 ) oldlen = skb->len - udphoff;else - payload_csum =1 ; + payload_csum = true; } udph = (void *)skb_network_header (skb) + udphoff;
@@ -226,8 +226,8 @@ udp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, {struct udphdr *udph;unsigned int udphoff = iph->len; +bool payload_csum = false;int oldlen; -int payload_csum =0 ;#ifdef CONFIG_IP_VS_IPV6 if (cp->af ==AF_INET6 && iph->fragoffs)
@@ -256,7 +256,7 @@ udp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,if (ret ==1 ) oldlen = skb->len - udphoff;else - payload_csum =1 ; + payload_csum = true; } udph = (void *)skb_network_header (skb) + udphoff;
net/netfilter/ipvs/ip_vs_xmit.c +2 -2
@@ -126,7 +126,7 @@ static struct rtable *do_output_route4(struct net *net, __be32 daddr, {struct flowi4 fl4;struct rtable *rt; -int loop =0 ; +bool loop = false;memset (&fl4,0 ,sizeof (fl4)); fl4.daddr = daddr;
@@ -149,7 +149,7 @@ static struct rtable *do_output_route4(struct net *net, __be32 daddr,ip_rt_put (rt); *saddr = fl4.saddr;flowi4_update_output (&fl4,0 ,0 , daddr, fl4.saddr); - loop++; + loop = true; goto retry; } *saddr = fl4.saddr;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 14/29 netfilter: remove unneeded switch fall-through
In reply to Pablo Neira AyusoFrom: Li RongQing <[email protected]>
Empty case is fine and does not switch fall-through
--- net/netfilter/nf_nat_core.c | 2 +- net/netfilter/nf_tables_core.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
net/netfilter/nf_nat_core.c +1 -1
@@ -240,7 +240,7 @@ static bool l4proto_in_range(const struct nf_conntrack_tuple *tuple,__be16 port;switch (tuple->dst.protonum) { -case IPPROTO_ICMP :/* fallthrough */ +case IPPROTO_ICMP :case IPPROTO_ICMPV6 :return ntohs (tuple->src.u.icmp.id) >=ntohs (min->icmp.id) &&ntohs (tuple->src.u.icmp.id) <=ntohs (max->icmp.id);
net/netfilter/nf_tables_core.c +0 -1
@@ -221,7 +221,6 @@ nft_do_chain(struct nft_pktinfo *pkt, void *priv) chain = regs.verdict.chain; goto do_chain;case NFT_CONTINUE : -/* fall through */ case NFT_RETURN :nft_trace_packet (&info, chain, rule,NFT_TRACETYPE_RETURN );
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 15/29 netfilter: nft_set_hash: fix lookups with fixed size hash on big endian
In reply to Pablo Neira AyusoCall jhash_1word() for the 4-bytes key case from the insertion and deactivation path, otherwise big endian arch set lookups fail.
--- net/netfilter/nft_set_hash.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
net/netfilter/nft_set_hash.c +19 -4
@@ -474,6 +474,23 @@ static bool nft_hash_lookup_fast(const struct net *net,return false; } +static u32 nft_jhash (const struct nft_set *set,const struct nft_hash *priv, +const struct nft_set_ext *ext) +{ +const struct nft_data *key =nft_set_ext_key (ext); +u32 hash, k1; + +if (set->klen ==4 ) { + k1 = *(u32 *)key; + hash =jhash_1word (k1, priv->seed); + }else { + hash =jhash (key, set->klen, priv->seed); + } + hash =reciprocal_scale (hash, priv->buckets); + +return hash; +} +static int nft_hash_insert (const struct net *net,const struct nft_set *set,const struct nft_set_elem *elem,struct nft_set_ext **ext)
@@ -483,8 +500,7 @@ static int nft_hash_insert(const struct net *net, const struct nft_set *set,u8 genmask =nft_genmask_next (net);u32 hash; - hash =jhash (nft_set_ext_key (&this->ext), set->klen, priv->seed); - hash =reciprocal_scale (hash, priv->buckets); + hash =nft_jhash (set, priv, &this->ext);hlist_for_each_entry (he, &priv->table[hash], node) { if (!memcmp(nft_set_ext_key(&this->ext), nft_set_ext_key(&he->ext), set->klen) &&
@@ -523,8 +539,7 @@ static void *nft_hash_deactivate(const struct net *net,u8 genmask =nft_genmask_next (net);u32 hash; - hash =jhash (nft_set_ext_key (&this->ext), set->klen, priv->seed); - hash =reciprocal_scale (hash, priv->buckets); + hash =nft_jhash (set, priv, &this->ext);hlist_for_each_entry (he, &priv->table[hash], node) { if (!memcmp(nft_set_ext_key(&this->ext), &elem->key.val, set->klen) &&
Signature · 1 line
2.11.0