ipv6: fix the reassembly expire code in nf_conntrack
Subsystems (4)
cover ipv6: fix the reassembly expire code in nf_conntrack
ipv6: add a new namespace for nf_conntrack_reasm
ipv6: unify conntrack reassembly expire code with
ipv6: make ip6_frag_nqueues() and ip6_frag_mem() static
ipv6: unify fragment thresh handling code
---
include/net/inet_frag.h | 2 +- include/net/ipv6.h | 32 +++++- include/net/net_namespace.h | 3 + include/net/netns/conntrack.h | 6 + net/ipv4/inet_fragment.c | 9 +- net/ipv4/ip_fragment.c | 5 +- net/ipv6/netfilter/nf_conntrack_reasm.c | 196 ++++++++++++++++--------------- net/ipv6/reassembly.c | 88 ++++---------- 8 files changed, 176 insertions(+), 165 deletions(-)
PATCH 1/4 ipv6: add a new namespace for nf_conntrack_reasm
As pointed by Michal, it is necessary to add a new namespace for nf_conntrack_reasm code, this prepares for the second patch.
--- include/net/net_namespace.h | 3 + include/net/netns/conntrack.h | 6 ++ net/ipv6/netfilter/nf_conntrack_reasm.c | 135 +++++++++++++++++++++---------- 3 files changed, 102 insertions(+), 42 deletions(-)
include/net/net_namespace.h +3 -0
@@ -93,6 +93,9 @@ struct net {#if defined(CONFIG_NF_CONNTRACK ) || defined(CONFIG_NF_CONNTRACK_MODULE )struct netns_ct ct;#endif +#if IS_ENABLED (CONFIG_NF_DEFRAG_IPV6 ) +struct netns_nf_ct nf_ct; +#endif struct sock *nfnl;struct sock *nfnl_stash;#endif
include/net/netns/conntrack.h +6 -0
@@ -96,4 +96,10 @@ struct netns_ct {#endif char *slabname; }; + +struct netns_nf_ct { +struct netns_sysctl_ipv6 sysctl; +struct netns_frags frags; +}; +#endif
net/ipv6/netfilter/nf_conntrack_reasm.c +93 -42
246 lines not on this page · raw message
Signature · 6 lines
1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/4 ipv6: unify conntrack reassembly expire code with standard one
In reply to Cong WangTwo years ago, Shan Wei tried to fix this:
http://patchwork.ozlabs.org/patch/43905/
The problem is that RFC2460 requires an ICMP Time Exceeded -- Fragment Reassembly Time Exceeded message should be sent to the source of that fragment, if the defragmentation times out.
"
If insufficient fragments are received to complete reassembly of a packet within 60 seconds of the reception of the first-arriving fragment of that packet, reassembly of that packet must be abandoned and all the fragments that have been received for that packet must be discarded. If the first fragment (i.e., the one with a Fragment Offset of zero) has been received, an ICMP Time Exceeded -- Fragment Reassembly Time Exceeded message should be sent to the source of that fragment.
"
As Herbert suggested, we could actually use the standard IPv6 reassembly code which follows RFC2460.
With this patch applied, I can see ICMP Time Exceeded sent from the receiver when the sender sent out 3/4 fragmented IPv6 UPD packet.
--- include/net/ipv6.h | 19 ++++++++ net/ipv6/netfilter/nf_conntrack_reasm.c | 71 +++++++----------------------- net/ipv6/reassembly.c | 62 ++++++++------------------- 3 files changed, 54 insertions(+), 98 deletions(-)
include/net/ipv6.h +19 -0
@@ -411,6 +411,25 @@ struct ip6_create_arg {void ip6_frag_init (struct inet_frag_queue *q,void *a);bool ip6_frag_match (struct inet_frag_queue *q,void *a); +/* +* Equivalent of ipv4 struct ip +*/ +struct frag_queue { +struct inet_frag_queue q; + +__be32 id;/* fragment id */ +u32 user; +struct in6_addr saddr; +struct in6_addr daddr; + +int iif; +unsigned int csum; +__u16 nhoffset; +}; + +void ip6_expire_frag_queue (struct net *net,struct frag_queue *fq, +struct inet_frags *frags); +static inline bool ipv6_addr_any (const struct in6_addr *a) {#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ) &&BITS_PER_LONG ==64
net/ipv6/netfilter/nf_conntrack_reasm.c +17 -54
149 lines not on this page · raw message
net/ipv6/reassembly.c +18 -44
113 lines not on this page · raw message
Signature · 6 lines
1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/4 ipv6: make ip6_frag_nqueues() and ip6_frag_mem() static inline
In reply to Cong Wang--- include/net/ipv6.h | 13 +++++++++++-- net/ipv6/reassembly.c | 10 ---------- 2 files changed, 11 insertions(+), 12 deletions(-)
include/net/ipv6.h +11 -2
@@ -271,8 +271,17 @@ struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,extern bool ipv6_opt_accepted (const struct sock *sk,const struct sk_buff *skb); -int ip6_frag_nqueues (struct net *net); -int ip6_frag_mem (struct net *net); +#ifdef CONFIG_IPV6 +static inline int ip6_frag_nqueues (struct net *net) +{ +return net->ipv6.frags.nqueues; +} + +static inline int ip6_frag_mem (struct net *net) +{ +return atomic_read (&net->ipv6.frags.mem); +} +#endif #define IPV6_FRAG_HIGH_THRESH (256 * 1024)/* 262144 */ #define IPV6_FRAG_LOW_THRESH (192 * 1024)/* 196608 */
net/ipv6/reassembly.c +0 -10
@@ -67,16 +67,6 @@ struct ip6frag_skb_cbstatic struct inet_frags ip6_frags; -int ip6_frag_nqueues (struct net *net) -{ -return net->ipv6.frags.nqueues; -} - -int ip6_frag_mem (struct net *net) -{ -return atomic_read (&net->ipv6.frags.mem); -} -static int ip6_frag_reasm (struct frag_queue *fq,struct sk_buff *prev,struct net_device *dev);
Signature · 1 line
1.7.7.6
PATCH 4/4 ipv6: unify fragment thresh handling code
In reply to Cong Wang--- include/net/inet_frag.h | 2 +- net/ipv4/inet_fragment.c | 9 +++++++-- net/ipv4/ip_fragment.c | 5 ++--- net/ipv6/netfilter/nf_conntrack_reasm.c | 8 +++----- net/ipv6/reassembly.c | 16 +++++----------- 5 files changed, 18 insertions(+), 22 deletions(-)
include/net/inet_frag.h +1 -1
@@ -61,7 +61,7 @@ void inet_frags_exit_net(struct netns_frags *nf, struct inet_frags *f);void inet_frag_kill (struct inet_frag_queue *q,struct inet_frags *f);void inet_frag_destroy (struct inet_frag_queue *q,struct inet_frags *f,int *work); -int inet_frag_evictor (struct netns_frags *nf,struct inet_frags *f); +int inet_frag_evictor (struct netns_frags *nf,struct inet_frags *f,bool force);struct inet_frag_queue *inet_frag_find (struct netns_frags *nf,struct inet_frags *f,void *key,unsigned int hash) __releases(&f->lock);
net/ipv4/inet_fragment.c +7 -2
@@ -89,7 +89,7 @@ void inet_frags_exit_net(struct netns_frags *nf, struct inet_frags *f) nf->low_thresh =0 ;local_bh_disable (); -inet_frag_evictor (nf, f); +inet_frag_evictor (nf, f, true);local_bh_enable (); }EXPORT_SYMBOL (inet_frags_exit_net);
@@ -158,11 +158,16 @@ void inet_frag_destroy(struct inet_frag_queue *q, struct inet_frags *f, }EXPORT_SYMBOL (inet_frag_destroy); -int inet_frag_evictor (struct netns_frags *nf,struct inet_frags *f) +int inet_frag_evictor (struct netns_frags *nf,struct inet_frags *f,bool force) {struct inet_frag_queue *q;int work, evicted =0 ; +if (!force) { +if (atomic_read (&nf->mem) <= nf->high_thresh) +return 0 ; + } + work =atomic_read (&nf->mem) - nf->low_thresh;while (work >0 ) {read_lock (&f->lock);
net/ipv4/ip_fragment.c +2 -3
@@ -219,7 +219,7 @@ static void ip_evictor(struct net *net) {int evicted; - evicted =inet_frag_evictor (&net->ipv4.frags, &ip4_frags); + evicted =inet_frag_evictor (&net->ipv4.frags, &ip4_frags, false);if (evicted)IP_ADD_STATS_BH (net,IPSTATS_MIB_REASMFAILS , evicted); }
@@ -684,8 +684,7 @@ int ip_defrag(struct sk_buff *skb, u32 user)IP_INC_STATS_BH (net,IPSTATS_MIB_REASMREQDS );/* Start by cleaning up the memory. */ -if (atomic_read (&net->ipv4.frags.mem) > net->ipv4.frags.high_thresh) -ip_evictor (net); +ip_evictor (net);/* Lookup (or create) queue header */ if ((qp =ip_find (net,ip_hdr (skb), user)) !=NULL ) {
net/ipv6/netfilter/nf_conntrack_reasm.c +3 -5
@@ -563,11 +563,9 @@ struct sk_buff *nf_ct_frag6_gather(struct sk_buff *skb, u32 user) hdr =ipv6_hdr (clone); fhdr = (struct frag_hdr *)skb_transport_header (clone); -if (atomic_read (&net->nf_ct.frags.mem) > net->nf_ct.frags.high_thresh) { -local_bh_disable (); -inet_frag_evictor (&net->nf_ct.frags, &nf_frags); -local_bh_enable (); - } +local_bh_disable (); +inet_frag_evictor (&net->nf_ct.frags, &nf_frags, false); +local_bh_enable (); fq =fq_find (net, fhdr->identification, user, &hdr->saddr, &hdr->daddr);if (fq ==NULL ) {
net/ipv6/reassembly.c +5 -11
@@ -131,15 +131,6 @@ void ip6_frag_init(struct inet_frag_queue *q, void *a) }EXPORT_SYMBOL (ip6_frag_init); -static void ip6_evictor (struct net *net,struct inet6_dev *idev) -{ -int evicted; - - evicted =inet_frag_evictor (&net->ipv6.frags, &ip6_frags); -if (evicted) -IP6_ADD_STATS_BH (net, idev,IPSTATS_MIB_REASMFAILS , evicted); -} -void ip6_expire_frag_queue (struct net *net,struct frag_queue *fq,struct inet_frags *frags) {struct net_device *dev =NULL ;
@@ -514,6 +505,7 @@ static int ipv6_frag_rcv(struct sk_buff *skb)struct frag_queue *fq;const struct ipv6hdr *hdr =ipv6_hdr (skb);struct net *net =dev_net (skb_dst (skb)->dev); +int evicted;IP6_INC_STATS_BH (net,ip6_dst_idev (skb_dst (skb)),IPSTATS_MIB_REASMREQDS );
@@ -538,8 +530,10 @@ static int ipv6_frag_rcv(struct sk_buff *skb)return 1 ; } -if (atomic_read (&net->ipv6.frags.mem) > net->ipv6.frags.high_thresh) -ip6_evictor (net,ip6_dst_idev (skb_dst (skb))); + evicted =inet_frag_evictor (&net->ipv6.frags, &ip6_frags, false); +if (evicted) +IP6_ADD_STATS_BH (net,ip6_dst_idev (skb_dst (skb)), +IPSTATS_MIB_REASMFAILS , evicted); fq =fq_find (net, fhdr->identification, &hdr->saddr, &hdr->daddr);if (fq !=NULL ) {
Signature · 6 lines
1.7.7.6 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Ping... Any review? :)
Quoted 21 lines · Cong Wang
ipv6: add a new namespace for
nf_conntrack_reasm
ipv6: unify conntrack reassembly expire code with
ipv6: makeip6_frag_nqueues()andip6_frag_mem()static
ipv6: unify fragment thresh handling codeCc Herbert Xu <[email protected]>Cc "David S. Miller" <[email protected]>Signed-off-by Cong Wang <[email protected]>---
include/net/inet_frag.h | 2 +- include/net/ipv6.h | 32 +++++- include/net/net_namespace.h | 3 + include/net/netns/conntrack.h | 6 + net/ipv4/inet_fragment.c | 9 +- net/ipv4/ip_fragment.c | 5 +- net/ipv6/netfilter/nf_conntrack_reasm.c | 196 ++++++++++++++++--------------- net/ipv6/reassembly.c | 88 ++++---------- 8 files changed, 176 insertions(+), 165 deletions(-)
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Thu, 13 Sep 2012 14:25:37 +0800
Quoted 8 lines
ipv6: add a new namespace for
nf_conntrack_reasm
ipv6: unify conntrack reassembly expire code with
ipv6: makeip6_frag_nqueues()andip6_frag_mem()static
ipv6: unify fragment thresh handling codeCc Herbert Xu <[email protected]>Cc "David S. Miller" <[email protected]>Signed-off-by Cong Wang <[email protected]>
These changes look great, all applied to net-next, thanks.
David Miller
maintainerFrom: David Miller <[email protected]>
Date: Mon, 17 Sep 2012 12:54:19 -0400 (EDT)
Quoted 8 lines
From: Cong Wang <[email protected]>
Date: Thu, 13 Sep 2012 14:25:37 +0800Quoted 5 lines
ipv6: add a new namespace for
nf_conntrack_reasm
ipv6: unify conntrack reassembly expire code with
ipv6: makeip6_frag_nqueues()andip6_frag_mem()static
ipv6: unify fragment thresh handling code
Quoted 5 lines
Quoted 3 lines
Cc Herbert Xu <[email protected]>Cc "David S. Miller" <[email protected]>Signed-off-by Cong Wang <[email protected]>These changes look great, all applied to net-next, thanks.
I have to ask if you actually build tested this change at all:
net/ipv6/proc.c: In function ‘sockstat6_seq_show’:net/ipv6/proc.c:46:10: error: implicit declaration of function ‘ip6_frag_nqueues’ [-Werror=implicit-function-declaration] net/ipv6/proc.c:46:10: error: implicit declaration of function ‘ip6_frag_mem’ [-Werror=implicit-function-declaration]
It is absolutely impossible for you to have enabled ipv6 and not gotten that build error.
The only logical explanation is that you didn't commit the changes to net/ipv6/proc.c in your tree when you put together these patches.
Please fix this up and resubmit the full series.
Thanks.
Quoted 17 lines · David Miller
From: David Miller <[email protected]>
Date: Mon, 17 Sep 2012 12:54:19 -0400 (EDT)Quoted 8 lines
From: Cong Wang <[email protected]>
Date: Thu, 13 Sep 2012 14:25:37 +0800Quoted 5 lines
ipv6: add a new namespace for
nf_conntrack_reasm
ipv6: unify conntrack reassembly expire code with
ipv6: makeip6_frag_nqueues()andip6_frag_mem()static
ipv6: unify fragment thresh handling codeQuoted 5 lines
Quoted 3 lines
Cc Herbert Xu <[email protected]>Cc "David S. Miller" <[email protected]>Signed-off-by Cong Wang <[email protected]>These changes look great, all applied to net-next, thanks.
Quoted 8 lines
I have to ask if you actually build tested this change at all:
net/ipv6/proc.c: In function ‘sockstat6_seq_show’:net/ipv6/proc.c:46:10: error: implicit declaration of function ‘ip6_frag_nqueues’ [-Werror=implicit-function-declaration]net/ipv6/proc.c:46:10: error: implicit declaration of function ‘ip6_frag_mem’ [-Werror=implicit-function-declaration]It is absolutely impossible for you to have enabled ipv6 and not gotten that build error.
Weird, I don't see any build error:
% grep CONFIG_IPV6 .configCONFIG_IPV6=yCONFIG_IPV6_PRIVACY=yCONFIG_IPV6_ROUTER_PREF=yCONFIG_IPV6_ROUTE_INFO=yCONFIG_IPV6_OPTIMISTIC_DAD=yCONFIG_IPV6_MIP6=yCONFIG_IPV6_SIT=yCONFIG_IPV6_SIT_6RD=yCONFIG_IPV6_NDISC_NODETYPE=yCONFIG_IPV6_TUNNEL=yCONFIG_IPV6_GRE=yCONFIG_IPV6_MULTIPLE_TABLES=yCONFIG_IPV6_SUBTREES=yCONFIG_IPV6_MROUTE=yCONFIG_IPV6_MROUTE_MULTIPLE_TABLES=yCONFIG_IPV6_PIMSM_V2=y
% rm net/ipv6/proc.o
% make net/ipv6/proc.o
make[1]: Nothing to be done for `all'.
make[1]: Nothing to be done for `relocs'.
CHK include/linux/version.h CHK include/generated/utsrelease.h CC kernel/bounds.s GEN include/generated/bounds.h CC arch/x86/kernel/asm-offsets.s GEN include/generated/asm-offsets.h CALL scripts/checksyscalls.sh CC scripts/mod/empty.o MKELF scripts/mod/elfconfig.h HOSTCC scripts/mod/file2alias.o HOSTCC scripts/mod/modpost.o HOSTCC scripts/mod/sumversion.o HOSTLD scripts/mod/modpost CC net/ipv6/proc.o
Rebuild the whole tree:
...
CC net/ipv6/ip6mr.o CC net/ipv6/xfrm6_policy.o CC net/ipv6/xfrm6_state.o CC net/ipv6/xfrm6_input.o CC net/ipv6/xfrm6_output.o CC net/ipv6/netfilter.o CC net/ipv6/fib6_rules.o CC net/ipv6/proc.o CC net/ipv6/syncookies.o LD net/ipv6/ipv6.o CC net/ipv6/ah6.o CC net/ipv6/esp6.o CC net/ipv6/ipcomp6.o CC net/ipv6/xfrm6_tunnel.o CC net/ipv6/tunnel6.o
...
% gcc --version
gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Quoted 3 lines
The only logical explanation is that you didn't commit the changes to
net/ipv6/proc.cin your tree when you put together these patches.
There is no change for net/ipv6/proc.c, ip6_frag_nqueues() and ip6_frag_mem() are now defined as static inline in include/net/ipv6.h which is already #included by net/ipv6/proc.c. This is why I still don't see how that build error could happen.
Actually, the #ifdef CONFIG_IPV6 is not needed at all, as sockstat6_seq_show() is their only caller, which is compiled only when CONFIG_IPV6 is enabled.
Thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Tue, 18 Sep 2012 10:34:16 +0800
Quoted 3 lines
Actually, the #ifdef
CONFIG_IPV6is not needed at all, assockstat6_seq_show()is their only caller, which is compiled only whenCONFIG_IPV6is enabled.
"#ifdef CONFIG_IPV6 doesn't work for modular ipv6.
Quoted 8 lines · David Miller
From: Cong Wang <[email protected]>
Date: Tue, 18 Sep 2012 10:34:16 +0800Quoted 3 lines
Actually, the #ifdef
CONFIG_IPV6is not needed at all, assockstat6_seq_show()is their only caller, which is compiled only whenCONFIG_IPV6is enabled."#ifdef
CONFIG_IPV6doesn't work for modular ipv6.
Ah... then this should be the cause of your build failure, as I always compile IPV6 as builtin.
Sorry for this, my bad. I will remove this #ifdef and resend the whole patchset.
Thanks!
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Tue, 18 Sep 2012 10:47:23 +0800
Quoted 1 line
I will remove this #ifdef and resend the whole patchset.
Or, alternatively, use IS_ENABLED() or a similar test which will take the modular case into account.
Quoted 8 lines · David Miller
From: Cong Wang <[email protected]>
Date: Tue, 18 Sep 2012 10:47:23 +0800Quoted 1 line
I will remove this #ifdef and resend the whole patchset.
Or, alternatively, use
IS_ENABLED()or a similar test which will take the modular case into account.
Yeah, actually net->ipv6 is also defined with #if IS_ENABLED(CONFIG_IPV6), so IS_ENABLED() is the right fix.
Thanks!