ipv6: fix the reassembly expire code in nf_conntrack
Subsystems (4)
v2 cover ipv6: fix the reassembly expire code in nf_conntrack
V2: use IS_ENABLED(CONFIG_IPV6) to fix a build error
rebase to latest net-next
ipv6: add a new namespace for nf_conntrack_reasm
ipv6: unify conntrack reassembly expire code with standard one
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 v2 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 · 1 line
1.7.7.6
Pablo Neira Ayuso
maintainerRe: [PATCH 1/4] ipv6: add a new namespace for nf_conntrack_reasm
Quoted 3 lines · Cong Wang
As pointed by Michal, it is necessary to add a new namespace for
nf_conntrack_reasmcode, this prepares for the second patch.
This looks good to me, but there are some comestical changes I have to request.
Quoted 18 lines
Cc Herbert Xu <[email protected]>Cc Michal Kubeček <[email protected]>Cc David Miller <[email protected]>Cc Patrick McHardy <[email protected]>Cc Pablo Neira Ayuso <[email protected]>Signed-off-by Cong Wang <[email protected]>--- 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 +0
-0
include/net/net_namespace.h struct net { · line 98
Quoted 6 lines
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
There's above one "struct netns_ct" that already encapsulates netfilter conntrack netns parameters.
However, I'd prefer if, while at it, you define some struct netns_nf_frag instead.
In net/ipv6/netfilter/Makefile, it says:
# defrag nf_defrag_ipv6-y := nf_defrag_ipv6_hooks.o nf_conntrack_reasm.o
Note that nf defragmentation is not glued to conntrack anymore. So I'd go for one netns_nf_frag for this in include/net/net_namespace.h
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
Re: [PATCH 1/4] ipv6: add a new namespace for nf_conntrack_reasm
Quoted 10 lines · Pablo Neira Ayuso
include/net/net_namespace.h struct net { · line 98
Quoted 3 lines
include/net/net_namespace.h +3
-0+#if IS_ENABLED (CONFIG_NF_DEFRAG_IPV6 ) +struct netns_nf_ct nf_ct; +#endif There's above one "struct
netns_ct" that already encapsulates netfilter conntrack netns parameters.However, I'd prefer if, while at it, you define some struct
netns_nf_fraginstead.
Quoted 8 lines
In
net/ipv6/netfilter/Makefile, it says:# defrag nf_defrag_ipv6-y := nf_defrag_ipv6_hooks.o nf_conntrack_reasm.oNote that nf defragmentation is not glued to conntrack anymore. So I'd go for one
netns_nf_fragfor this ininclude/net/net_namespace.h
Sure, I will rename that struct to 'struct netns_nf_frag'.
Thanks for review!
PATCH v2 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 · 1 line
1.7.7.6
PATCH v2 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); +#if IS_ENABLED (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 v2 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
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Tue, 18 Sep 2012 12:29:38 +0800
Quoted 11 lines
V2: use
IS_ENABLED(CONFIG_IPV6)to fix a build error
rebase to latest net-nextipv6: add a new namespace for
nf_conntrack_reasm
ipv6: unify conntrack reassembly expire code with standard one
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]>
Please address Pedro's feedback and resubmit, thanks.
David Miller
maintainerFrom: David Miller <[email protected]>
Date: Tue, 18 Sep 2012 17:44:22 -0400 (EDT)
Quoted 11 lines
From: Cong Wang <[email protected]>
Date: Tue, 18 Sep 2012 12:29:38 +0800Quoted 8 lines
V2: use
IS_ENABLED(CONFIG_IPV6)to fix a build error
rebase to latest net-nextipv6: add a new namespace for
nf_conntrack_reasm
ipv6: unify conntrack reassembly expire code with standard one
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]>Please address Pedro's feedback and resubmit, thanks.
Of course I meant "Pablo", and I meant to reply to v3 of your patches, sorry :-)