ipv6: fix the reassembly expire code in nf_conntrack
Subsystems (4)
v3 cover ipv6: fix the reassembly expire code in nf_conntrack
V3: rename struct netns_nf_ct to struct netns_nf_frag
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/ipv6.h | 8 ++ 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, 178 insertions(+), 165 deletions(-)
PATCH v3 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/ipv6.h | 8 ++ net/ipv6/netfilter/nf_conntrack_reasm.c | 135 +++++++++++++++++++++---------- 3 files changed, 104 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_frag nf_frag; +#endif struct sock *nfnl;struct sock *nfnl_stash;#endif
include/net/netns/ipv6.h +8 -0
@@ -71,4 +71,12 @@ struct netns_ipv6 {#endif #endif }; + +#if IS_ENABLED (CONFIG_NF_DEFRAG_IPV6 ) +struct netns_nf_frag { +struct netns_sysctl_ipv6 sysctl; +struct netns_frags frags; +}; +#endif +#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
Pablo Neira Ayuso
maintainerRe: [PATCH 1/4] ipv6: add a new namespace for nf_conntrack_reasm
Quoted 86 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.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/ipv6.h | 8 ++ net/ipv6/netfilter/nf_conntrack_reasm.c | 135 +++++++++++++++++++++---------- 3 files changed, 104 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_frag nf_frag; +#endif struct sock *nfnl;struct sock *nfnl_stash;#endif include/net/netns/ipv6.h +8
-0@@ -71,4 +71,12 @@ struct netns_ipv6 {#endif #endif }; + +#if IS_ENABLED (CONFIG_NF_DEFRAG_IPV6 ) +struct netns_nf_frag { +struct netns_sysctl_ipv6 sysctl; +struct netns_frags frags; +}; +#endif +#endif net/ipv6/netfilter/nf_conntrack_reasm.c +3
-4@@ -71,27 +71,26 @@ struct nf_ct_frag6_queue };static struct inet_frags nf_frags; -static struct netns_frags nf_init_frags; #ifdef CONFIG_SYSCTL static struct ctl_table nf_ct_frag6_sysctl_table[] = { { .procname = "nf_conntrack_frag6_timeout", - .data = &nf_init_frags.timeout, + .data = &init_net.nf_frag.frags.timeout, .maxlen = sizeof(unsigned int), .mode = 0644, .proc_handler = proc_dointvec_jiffies, }, { .procname = "nf_conntrack_frag6_low_thresh", - .data = &nf_init_frags.low_thresh, + .data = &init_net.nf_frag.frags.low_thresh, .maxlen = sizeof(unsigned int), .mode = 0644, .proc_handler = proc_dointvec, }, { .procname = "nf_conntrack_frag6_high_thresh", - .data = &nf_init_frags.high_thresh, + .data = &init_net.nf_frag.frags.high_thresh, .maxlen = sizeof(unsigned int), .mode = 0644, .proc_handler = proc_dointvec,@@ -99,7 +98,54 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = { { } };
net/ipv6/netfilter/nf_conntrack_reasm.c static struct ctl_table nf_ct_frag6_sysctl_table[] = { · line 108
Quoted 10 lines
net/ipv6/netfilter/nf_conntrack_reasm.c +8
-1-static struct ctl_table_header *nf_ct_frag6_sysctl_header; +static int __net_init nf_ct_frag6_sysctl_register (struct net *net) +{ +struct ctl_table *table; +struct ctl_table_header *hdr; + + table = nf_ct_frag6_sysctl_table; +if (!net_eq (net, &init_net)) { + table =kmemdup (table,sizeof (nf_ct_frag6_sysctl_table),GFP_KERNEL );
Sorry, you have to break lines at 80 chars.
--
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 5 lines · Pablo Neira Ayuso
net/ipv6/netfilter/nf_conntrack_reasm.c static struct ctl_table nf_ct_frag6_sysctl_table[] = { · line 108
Quoted 2 lines · Cong Wang
net/ipv6/netfilter/nf_conntrack_reasm.c +2
-0+if (!net_eq (net, &init_net)) { + table =kmemdup (table,sizeof (nf_ct_frag6_sysctl_table),GFP_KERNEL );Sorry, you have to break lines at 80 chars.
Ok, will do.
PATCH v3 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 v3 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 · 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 v3 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_frag.frags.mem) > net->nf_frag.frags.high_thresh) { -local_bh_disable (); -inet_frag_evictor (&net->nf_frag.frags, &nf_frags); -local_bh_enable (); - } +local_bh_disable (); +inet_frag_evictor (&net->nf_frag.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 · 1 line
1.7.7.6