diff mbox series

ip_frag: fix ipv6 when MTU sizes not aligned to 8 bytes

Message ID 20181127045613.16437-1-3chas3@gmail.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers show
Series ip_frag: fix ipv6 when MTU sizes not aligned to 8 bytes | expand

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Chas Williams Nov. 27, 2018, 4:56 a.m. UTC
From: Chas Williams <chas3@att.com>

The same issue was fixed on for the ipv4 version of this routine in
commit 8d4d3a4f7337 ("ip_frag: handle MTU sizes not aligned to 8 bytes").
Briefly, the size of an ipv6 header is always 40 bytes.  With an MTU of
1500, this will never produce a multiple of 8 bytes for the frag_size
and this routine can never succeed. Since RTE_ASSERTS are disabled by
default, this failure is tpyically ignored.

To fix this, round down to the nearest 8 bytes and use this when
producing the fragments.

Fixes: 0aa31d7a5929 ("ip_frag: add IPv6 fragmentation support")

Signed-off-by: Chas Williams <chas3@att.com>
---
 lib/librte_ip_frag/rte_ip_frag.h            |  1 +
 lib/librte_ip_frag/rte_ipv6_fragmentation.c | 18 +++++++++++-------
 2 files changed, 12 insertions(+), 7 deletions(-)

Comments

Luca Boccassi Nov. 28, 2018, 10:15 a.m. UTC | #1
On Mon, 2018-11-26 at 23:56 -0500, Chas Williams wrote:
> From: Chas Williams <chas3@att.com>
> 
> The same issue was fixed on for the ipv4 version of this routine in
> commit 8d4d3a4f7337 ("ip_frag: handle MTU sizes not aligned to 8
> bytes").
> Briefly, the size of an ipv6 header is always 40 bytes.  With an MTU
> of
> 1500, this will never produce a multiple of 8 bytes for the frag_size
> and this routine can never succeed. Since RTE_ASSERTS are disabled by
> default, this failure is tpyically ignored.
> 
> To fix this, round down to the nearest 8 bytes and use this when
> producing the fragments.
> 
> Fixes: 0aa31d7a5929 ("ip_frag: add IPv6 fragmentation support")
> 
> Signed-off-by: Chas Williams <chas3@att.com>
> ---
>  lib/librte_ip_frag/rte_ip_frag.h            |  1 +
>  lib/librte_ip_frag/rte_ipv6_fragmentation.c | 18 +++++++++++-------
>  2 files changed, 12 insertions(+), 7 deletions(-)

Acked-by: Luca Boccassi <bluca@debian.org>
Thomas Monjalon Dec. 19, 2018, 3:47 a.m. UTC | #2
28/11/2018 11:15, Luca Boccassi:
> On Mon, 2018-11-26 at 23:56 -0500, Chas Williams wrote:
> > From: Chas Williams <chas3@att.com>
> > 
> > The same issue was fixed on for the ipv4 version of this routine in
> > commit 8d4d3a4f7337 ("ip_frag: handle MTU sizes not aligned to 8
> > bytes").
> > Briefly, the size of an ipv6 header is always 40 bytes.  With an MTU
> > of
> > 1500, this will never produce a multiple of 8 bytes for the frag_size
> > and this routine can never succeed. Since RTE_ASSERTS are disabled by
> > default, this failure is tpyically ignored.
> > 
> > To fix this, round down to the nearest 8 bytes and use this when
> > producing the fragments.
> > 
> > Fixes: 0aa31d7a5929 ("ip_frag: add IPv6 fragmentation support")
> > 
> > Signed-off-by: Chas Williams <chas3@att.com>
> > ---
> >  lib/librte_ip_frag/rte_ip_frag.h            |  1 +
> >  lib/librte_ip_frag/rte_ipv6_fragmentation.c | 18 +++++++++++-------
> >  2 files changed, 12 insertions(+), 7 deletions(-)
> 
> Acked-by: Luca Boccassi <bluca@debian.org>

Konstantin, no comment?
Konstantin Ananyev Dec. 19, 2018, 10:12 a.m. UTC | #3
> -----Original Message-----
> From: Chas Williams [mailto:3chas3@gmail.com]
> Sent: Tuesday, November 27, 2018 4:56 AM
> To: dev@dpdk.org
> Cc: Ananyev, Konstantin <konstantin.ananyev@intel.com>; Chas Williams <chas3@att.com>
> Subject: [PATCH] ip_frag: fix ipv6 when MTU sizes not aligned to 8 bytes
> 
> From: Chas Williams <chas3@att.com>
> 
> The same issue was fixed on for the ipv4 version of this routine in
> commit 8d4d3a4f7337 ("ip_frag: handle MTU sizes not aligned to 8 bytes").
> Briefly, the size of an ipv6 header is always 40 bytes.  With an MTU of
> 1500, this will never produce a multiple of 8 bytes for the frag_size
> and this routine can never succeed. Since RTE_ASSERTS are disabled by
> default, this failure is tpyically ignored.
> 
> To fix this, round down to the nearest 8 bytes and use this when
> producing the fragments.
> 
> Fixes: 0aa31d7a5929 ("ip_frag: add IPv6 fragmentation support")
> 
> Signed-off-by: Chas Williams <chas3@att.com>
> ---

Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

> 2.14.4
Thomas Monjalon Dec. 19, 2018, 9:37 p.m. UTC | #4
> > The same issue was fixed on for the ipv4 version of this routine in
> > commit 8d4d3a4f7337 ("ip_frag: handle MTU sizes not aligned to 8 bytes").
> > Briefly, the size of an ipv6 header is always 40 bytes.  With an MTU of
> > 1500, this will never produce a multiple of 8 bytes for the frag_size
> > and this routine can never succeed. Since RTE_ASSERTS are disabled by
> > default, this failure is tpyically ignored.
> > 
> > To fix this, round down to the nearest 8 bytes and use this when
> > producing the fragments.
> > 
> > Fixes: 0aa31d7a5929 ("ip_frag: add IPv6 fragmentation support")
> > 
> > Signed-off-by: Chas Williams <chas3@att.com>
> 
> Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

Applied, thanks
diff mbox series

Patch

diff --git a/lib/librte_ip_frag/rte_ip_frag.h b/lib/librte_ip_frag/rte_ip_frag.h
index a4ccaf9d1..04fd9df52 100644
--- a/lib/librte_ip_frag/rte_ip_frag.h
+++ b/lib/librte_ip_frag/rte_ip_frag.h
@@ -115,6 +115,7 @@  struct rte_ip_frag_tbl {
 #define	RTE_IPV6_EHDR_MF_MASK			1
 #define	RTE_IPV6_EHDR_FO_SHIFT			3
 #define	RTE_IPV6_EHDR_FO_MASK			(~((1 << RTE_IPV6_EHDR_FO_SHIFT) - 1))
+#define	RTE_IPV6_EHDR_FO_ALIGN			(1 << RTE_IPV6_EHDR_FO_SHIFT)
 
 #define RTE_IPV6_FRAG_USED_MASK			\
 	(RTE_IPV6_EHDR_MF_MASK | RTE_IPV6_EHDR_FO_MASK)
diff --git a/lib/librte_ip_frag/rte_ipv6_fragmentation.c b/lib/librte_ip_frag/rte_ipv6_fragmentation.c
index 62a7e4e83..b9437eb11 100644
--- a/lib/librte_ip_frag/rte_ipv6_fragmentation.c
+++ b/lib/librte_ip_frag/rte_ipv6_fragmentation.c
@@ -77,11 +77,14 @@  rte_ipv6_fragment_packet(struct rte_mbuf *pkt_in,
 	uint32_t out_pkt_pos, in_seg_data_pos;
 	uint32_t more_in_segs;
 	uint16_t fragment_offset, frag_size;
+	uint64_t frag_bytes_remaining;
 
-	frag_size = (uint16_t)(mtu_size - sizeof(struct ipv6_hdr));
-
-	/* Fragment size should be a multiple of 8. */
-	RTE_ASSERT((frag_size & ~RTE_IPV6_EHDR_FO_MASK) == 0);
+	/*
+	 * Ensure the IP payload length of all fragments (except the
+	 * the last fragment) are a multiple of 8 bytes per RFC2460.
+	 */
+	frag_size = RTE_ALIGN_FLOOR(mtu_size - sizeof(struct ipv6_hdr),
+				    RTE_IPV6_EHDR_FO_ALIGN);
 
 	/* Check that pkts_out is big enough to hold all fragments */
 	if (unlikely (frag_size * nb_pkts_out <
@@ -111,6 +114,7 @@  rte_ipv6_fragment_packet(struct rte_mbuf *pkt_in,
 		/* Reserve space for the IP header that will be built later */
 		out_pkt->data_len = sizeof(struct ipv6_hdr) + sizeof(struct ipv6_extension_fragment);
 		out_pkt->pkt_len  = sizeof(struct ipv6_hdr) + sizeof(struct ipv6_extension_fragment);
+		frag_bytes_remaining = frag_size;
 
 		out_seg_prev = out_pkt;
 		more_out_segs = 1;
@@ -130,7 +134,7 @@  rte_ipv6_fragment_packet(struct rte_mbuf *pkt_in,
 
 			/* Prepare indirect buffer */
 			rte_pktmbuf_attach(out_seg, in_seg);
-			len = mtu_size - out_pkt->pkt_len;
+			len = frag_bytes_remaining;
 			if (len > (in_seg->data_len - in_seg_data_pos)) {
 				len = in_seg->data_len - in_seg_data_pos;
 			}
@@ -140,11 +144,11 @@  rte_ipv6_fragment_packet(struct rte_mbuf *pkt_in,
 			    out_pkt->pkt_len);
 			out_pkt->nb_segs += 1;
 			in_seg_data_pos += len;
+			frag_bytes_remaining -= len;
 
 			/* Current output packet (i.e. fragment) done ? */
-			if (unlikely(out_pkt->pkt_len >= mtu_size)) {
+			if (unlikely(frag_bytes_remaining == 0))
 				more_out_segs = 0;
-			}
 
 			/* Current input segment done ? */
 			if (unlikely(in_seg_data_pos == in_seg->data_len)) {