Sat Jan 22 18:26:36 2011 UTC ()
When deleting a fragment header use the simple copy operation only if it fits
completely into the mbuf.


(mlelstv)
diff -r1.47 -r1.48 src/sys/netinet6/frag6.c

cvs diff -r1.47 -r1.48 src/sys/netinet6/frag6.c (expand / switch to unified diff)

--- src/sys/netinet6/frag6.c 2009/03/18 16:00:22 1.47
+++ src/sys/netinet6/frag6.c 2011/01/22 18:26:36 1.48
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: frag6.c,v 1.47 2009/03/18 16:00:22 cegger Exp $ */ 1/* $NetBSD: frag6.c,v 1.48 2011/01/22 18:26:36 mlelstv Exp $ */
2/* $KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $ */ 2/* $KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE. 30 * SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.47 2009/03/18 16:00:22 cegger Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.48 2011/01/22 18:26:36 mlelstv Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/malloc.h> 38#include <sys/malloc.h>
39#include <sys/mbuf.h> 39#include <sys/mbuf.h>
40#include <sys/domain.h> 40#include <sys/domain.h>
41#include <sys/protosw.h> 41#include <sys/protosw.h>
42#include <sys/socket.h> 42#include <sys/socket.h>
43#include <sys/socketvar.h> 43#include <sys/socketvar.h>
44#include <sys/errno.h> 44#include <sys/errno.h>
45#include <sys/time.h> 45#include <sys/time.h>
46#include <sys/kernel.h> 46#include <sys/kernel.h>
47#include <sys/syslog.h> 47#include <sys/syslog.h>
@@ -507,27 +507,27 @@ insert: @@ -507,27 +507,27 @@ insert:
507 free(ip6af, M_FTABLE); 507 free(ip6af, M_FTABLE);
508 ip6 = mtod(m, struct ip6_hdr *); 508 ip6 = mtod(m, struct ip6_hdr *);
509 ip6->ip6_plen = htons(next + offset - sizeof(struct ip6_hdr)); 509 ip6->ip6_plen = htons(next + offset - sizeof(struct ip6_hdr));
510 ip6->ip6_src = q6->ip6q_src; 510 ip6->ip6_src = q6->ip6q_src;
511 ip6->ip6_dst = q6->ip6q_dst; 511 ip6->ip6_dst = q6->ip6q_dst;
512 nxt = q6->ip6q_nxt; 512 nxt = q6->ip6q_nxt;
513#ifdef notyet 513#ifdef notyet
514 *q6->ip6q_nxtp = (u_char)(nxt & 0xff); 514 *q6->ip6q_nxtp = (u_char)(nxt & 0xff);
515#endif 515#endif
516 516
517 /* 517 /*
518 * Delete frag6 header with as a few cost as possible. 518 * Delete frag6 header with as a few cost as possible.
519 */ 519 */
520 if (offset < m->m_len) { 520 if (m->m_len >= offset + sizeof(struct ip6_frag)) {
521 memmove((char *)ip6 + sizeof(struct ip6_frag), ip6, offset); 521 memmove((char *)ip6 + sizeof(struct ip6_frag), ip6, offset);
522 m->m_data += sizeof(struct ip6_frag); 522 m->m_data += sizeof(struct ip6_frag);
523 m->m_len -= sizeof(struct ip6_frag); 523 m->m_len -= sizeof(struct ip6_frag);
524 } else { 524 } else {
525 /* this comes with no copy if the boundary is on cluster */ 525 /* this comes with no copy if the boundary is on cluster */
526 if ((t = m_split(m, offset, M_DONTWAIT)) == NULL) { 526 if ((t = m_split(m, offset, M_DONTWAIT)) == NULL) {
527 frag6_remque(q6); 527 frag6_remque(q6);
528 frag6_nfrags -= q6->ip6q_nfrag; 528 frag6_nfrags -= q6->ip6q_nfrag;
529 free(q6, M_FTABLE); 529 free(q6, M_FTABLE);
530 frag6_nfragpackets--; 530 frag6_nfragpackets--;
531 goto dropfrag; 531 goto dropfrag;
532 } 532 }
533 m_adj(t, sizeof(struct ip6_frag)); 533 m_adj(t, sizeof(struct ip6_frag));