Skip to contentSkip to conversation

ipv6: fix the reassembly expire code in nf_conntrack

PATCH In review Cong Wang 3 participants 8 messages Sep 19, 2012 – Sep 20, 2012

Subsystems (4)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

v4 cover ipv6: fix the reassembly expire code in nf_conntrack

V4: some coding style fix

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

Cc Herbert Xu <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Pablo Neira Ayuso <[email protected]>

-----

 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 |  199 +++++++++++++++++--------------
 net/ipv6/reassembly.c                   |   89 ++++----------
 8 files changed, 182 insertions(+), 165 deletions(-)
author
#1 lore raw

PATCH v4 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.

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]>
---
 include/net/net_namespace.h             |    3 +
 include/net/netns/ipv6.h                |    8 ++
 net/ipv6/netfilter/nf_conntrack_reasm.c |  137 +++++++++++++++++++++----------
 3 files changed, 106 insertions(+), 42 deletions(-)
include/net/net_namespace.h +3 -0
index 5ae57f1..d61e2b3 100644
@@ -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
index 0318104..214cb0a 100644
@@ -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 +95 -42

242 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
author
#2 lore raw

PATCH v4 2/4 ipv6: unify conntrack reassembly expire code with standard one

In reply to Cong Wang

Two 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.

Cc Herbert Xu <[email protected]>
Cc Michal Kubeček <[email protected]>
Cc David Miller <[email protected]>
Cc Hideaki YOSHIFUJI <[email protected]>
Cc Patrick McHardy <[email protected]>
Cc Pablo Neira Ayuso <[email protected]>
---
 include/net/ipv6.h                      |   19 ++++++++
 net/ipv6/netfilter/nf_conntrack_reasm.c |   74 ++++++++-----------------------
 net/ipv6/reassembly.c                   |   63 ++++++++------------------
 3 files changed, 57 insertions(+), 99 deletions(-)
include/net/ipv6.h +19 -0
index 9bed5d4..81d4455 100644
@@ -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 +19 -55

152 lines not on this page · raw message

net/ipv6/reassembly.c +19 -44

114 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
author
#5 lore raw

PATCH v4 3/4 ipv6: make ip6_frag_nqueues() and ip6_frag_mem() static inline

In reply to Cong Wang
Cc Herbert Xu <[email protected]>
Cc Michal Kubeček <[email protected]>
Cc David Miller <[email protected]>
---
 include/net/ipv6.h    |   13 +++++++++++--
 net/ipv6/reassembly.c |   10 ----------
 2 files changed, 11 insertions(+), 12 deletions(-)
include/net/ipv6.h +11 -2
index 81d4455..979bf6c 100644
@@ -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
index 0ee5533..cf74f4e 100644
@@ -67,16 +67,6 @@ struct ip6frag_skb_cb
 
 static 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
author
#6 lore raw

PATCH v4 4/4 ipv6: unify fragment thresh handling code

In reply to Cong Wang
Cc Herbert Xu <[email protected]>
Cc Michal Kubeček <[email protected]>
Cc David Miller <[email protected]>
---
 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
index 5098ee7..32786a0 100644
@@ -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
index 85190e6..4750d2b 100644
@@ -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
index fa6a12c..448e685 100644
@@ -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
index 54274c3..1af12fde 100644
@@ -566,11 +566,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
index cf74f4e..da8a4e3 100644
@@ -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)
 {
@@ -515,6 +506,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);
 
@@ -539,8 +531,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
#3 lore raw

Re: [PATCH 2/4] ipv6: unify conntrack reassembly expire code with standard one

In reply to Cong Wang

On Wed, 19 Sep 2012, Cong Wang wrote:

[cut]

Quoted 3 lines

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.

Typo "UPD" -> "UDP"

If people want to redo the IPv6 UDP fragment tests, they can use my scapy script, and comment out sending the last fragment:
https://github.com/netoptimizer/network-testing/blob/master/scapy/ipv6_fragment01.py

Another thing, could you please "mark"/put the version of the patch in the subject line, like:

[PATCH V4 2/4] ipv6: ...

This makes it easier, to follow on which version of the patch people are replying to.

With git send-email I think you have to do:

  git send-email --subject-prefix="PATCH V4"

And with stg (stacked git) I usually do:

stg mail --version "V4" --to netdev ...

Cheers,
Jesper Brouer

--
-------------------------------------------------------------------
MSc. Master of Computer Science
Dept. of Computer Science, University of Copenhagen Author of http://www.adsl-optimizer.dk
-------------------------------------------------------------------

maintainer
#7 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Wed, 19 Sep 2012 10:50:07 +0800

Quoted 12 lines

V4: some coding style fix

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

Quoted 4 lines
Cc Herbert Xu <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Pablo Neira Ayuso <[email protected]>

All applied to net-next, thanks.

author
#4 lore raw

Re: [PATCH 2/4] ipv6: unify conntrack reassembly expire code with standard one

In reply to Jesper Dangaard Brouer
Quoted 21 lines · Jesper Dangaard Brouer

On Wed, 19 Sep 2012, Cong Wang wrote:

[cut]

Quoted 3 lines

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.

Typo "UPD" -> "UDP"

If people want to redo the IPv6 UDP fragment tests, they can use my scapy script, and comment out sending the last fragment:
https://github.com/netoptimizer/network-testing/blob/master/scapy/ipv6_fragment01.py

Another thing, could you please "mark"/put the version of the patch in the subject line, like:

[PATCH V4 2/4] ipv6: ...

This makes it easier, to follow on which version of the patch people are replying to.

Quoted 7 lines

With git send-email I think you have to do:

   git send-email --subject-prefix="PATCH V4"

And with stg (stacked git) I usually do:

   stg mail --version "V4" --to netdev ...

Thanks, Jesper!

Unfortunately, git-send-email on F16 doesn't have --subject-prefix option (git-format-patch does), that is why I didn't add "V4" to every patch. Perhaps I should use git-format-patch + git-send-email next time.