Deleted Added
full compact
uipc_mbuf.c (103552) uipc_mbuf.c (103569)
1/*
2 * Copyright (c) 1982, 1986, 1988, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)uipc_mbuf.c 8.2 (Berkeley) 1/4/94
1/*
2 * Copyright (c) 1982, 1986, 1988, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)uipc_mbuf.c 8.2 (Berkeley) 1/4/94
34 * $FreeBSD: head/sys/kern/uipc_mbuf.c 103552 2002-09-18 19:42:06Z phk $
34 * $FreeBSD: head/sys/kern/uipc_mbuf.c 103569 2002-09-18 22:33:52Z bmilekic $
35 */
36
37#include "opt_mac.h"
38#include "opt_param.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>

--- 128 unchanged lines hidden (view full) ---

171 n->m_len = min(len, m->m_len - off);
172 if (m->m_flags & M_EXT) {
173 n->m_data = m->m_data + off;
174 n->m_ext = m->m_ext;
175 n->m_flags |= M_EXT;
176 MEXT_ADD_REF(m);
177 } else
178 bcopy(mtod(m, caddr_t)+off, mtod(n, caddr_t),
35 */
36
37#include "opt_mac.h"
38#include "opt_param.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>

--- 128 unchanged lines hidden (view full) ---

171 n->m_len = min(len, m->m_len - off);
172 if (m->m_flags & M_EXT) {
173 n->m_data = m->m_data + off;
174 n->m_ext = m->m_ext;
175 n->m_flags |= M_EXT;
176 MEXT_ADD_REF(m);
177 } else
178 bcopy(mtod(m, caddr_t)+off, mtod(n, caddr_t),
179 (unsigned)n->m_len);
179 (u_int)n->m_len);
180 if (len != M_COPYALL)
181 len -= n->m_len;
182 off = 0;
183 m = m->m_next;
184 np = &n->m_next;
185 }
186 if (top == NULL)
187 mbstat.m_mcfail++; /* XXX: No consistency. */

--- 66 unchanged lines hidden (view full) ---

254
255/*
256 * Copy data from an mbuf chain starting "off" bytes from the beginning,
257 * continuing for "len" bytes, into the indicated buffer.
258 */
259void
260m_copydata(const struct mbuf *m, int off, int len, caddr_t cp)
261{
180 if (len != M_COPYALL)
181 len -= n->m_len;
182 off = 0;
183 m = m->m_next;
184 np = &n->m_next;
185 }
186 if (top == NULL)
187 mbstat.m_mcfail++; /* XXX: No consistency. */

--- 66 unchanged lines hidden (view full) ---

254
255/*
256 * Copy data from an mbuf chain starting "off" bytes from the beginning,
257 * continuing for "len" bytes, into the indicated buffer.
258 */
259void
260m_copydata(const struct mbuf *m, int off, int len, caddr_t cp)
261{
262 unsigned count;
262 u_int count;
263
264 KASSERT(off >= 0, ("m_copydata, negative off %d", off));
265 KASSERT(len >= 0, ("m_copydata, negative len %d", len));
266 while (off > 0) {
267 KASSERT(m != NULL, ("m_copydata, offset > size of mbuf chain"));
268 if (off < m->m_len)
269 break;
270 off -= m->m_len;

--- 217 unchanged lines hidden (view full) ---

488 M_COPY_PKTHDR(m, n);
489 n->m_flags &= ~M_PKTHDR;
490 }
491 }
492 space = &m->m_dat[MLEN] - (m->m_data + m->m_len);
493 do {
494 count = min(min(max(len, max_protohdr), space), n->m_len);
495 bcopy(mtod(n, caddr_t), mtod(m, caddr_t) + m->m_len,
263
264 KASSERT(off >= 0, ("m_copydata, negative off %d", off));
265 KASSERT(len >= 0, ("m_copydata, negative len %d", len));
266 while (off > 0) {
267 KASSERT(m != NULL, ("m_copydata, offset > size of mbuf chain"));
268 if (off < m->m_len)
269 break;
270 off -= m->m_len;

--- 217 unchanged lines hidden (view full) ---

488 M_COPY_PKTHDR(m, n);
489 n->m_flags &= ~M_PKTHDR;
490 }
491 }
492 space = &m->m_dat[MLEN] - (m->m_data + m->m_len);
493 do {
494 count = min(min(max(len, max_protohdr), space), n->m_len);
495 bcopy(mtod(n, caddr_t), mtod(m, caddr_t) + m->m_len,
496 (unsigned)count);
496 (u_int)count);
497 len -= count;
498 m->m_len += count;
499 n->m_len -= count;
500 space -= count;
501 if (n->m_len)
502 n->m_data += count;
503 else
504 n = m_free(n);

--- 19 unchanged lines hidden (view full) ---

524 * mbuf can end up sharing an mbuf cluster with the original mbuf if
525 * the "breaking point" happens to lie within a cluster mbuf. Use the
526 * M_WRITABLE() macro to check for this case.
527 */
528struct mbuf *
529m_split(struct mbuf *m0, int len0, int wait)
530{
531 struct mbuf *m, *n;
497 len -= count;
498 m->m_len += count;
499 n->m_len -= count;
500 space -= count;
501 if (n->m_len)
502 n->m_data += count;
503 else
504 n = m_free(n);

--- 19 unchanged lines hidden (view full) ---

524 * mbuf can end up sharing an mbuf cluster with the original mbuf if
525 * the "breaking point" happens to lie within a cluster mbuf. Use the
526 * M_WRITABLE() macro to check for this case.
527 */
528struct mbuf *
529m_split(struct mbuf *m0, int len0, int wait)
530{
531 struct mbuf *m, *n;
532 unsigned len = len0, remain;
532 u_int len = len0, remain;
533
534 for (m = m0; m && len > m->m_len; m = m->m_next)
535 len -= m->m_len;
536 if (m == NULL)
537 return (NULL);
538 remain = m->m_len - len;
539 if (m0->m_flags & M_PKTHDR) {
540 MGETHDR(n, wait, m0->m_type);

--- 89 unchanged lines hidden (view full) ---

630 }
631 if (off) {
632 m->m_data += off;
633 len -= off;
634 off = 0;
635 }
636 m->m_len = len = min(totlen, len);
637 if (copy)
533
534 for (m = m0; m && len > m->m_len; m = m->m_next)
535 len -= m->m_len;
536 if (m == NULL)
537 return (NULL);
538 remain = m->m_len - len;
539 if (m0->m_flags & M_PKTHDR) {
540 MGETHDR(n, wait, m0->m_type);

--- 89 unchanged lines hidden (view full) ---

630 }
631 if (off) {
632 m->m_data += off;
633 len -= off;
634 off = 0;
635 }
636 m->m_len = len = min(totlen, len);
637 if (copy)
638 copy(buf, mtod(m, caddr_t), (unsigned)len);
638 copy(buf, mtod(m, caddr_t), (u_int)len);
639 else
639 else
640 bcopy(buf, mtod(m, caddr_t), (unsigned)len);
640 bcopy(buf, mtod(m, caddr_t), (u_int)len);
641 buf += len;
642 *mp = m;
643 mp = &m->m_next;
644 totlen -= len;
645 }
646 return (top);
647}
648

--- 20 unchanged lines hidden (view full) ---

669 goto out;
670 n->m_len = min(MLEN, len + off);
671 m->m_next = n;
672 }
673 m = m->m_next;
674 }
675 while (len > 0) {
676 mlen = min (m->m_len - off, len);
641 buf += len;
642 *mp = m;
643 mp = &m->m_next;
644 totlen -= len;
645 }
646 return (top);
647}
648

--- 20 unchanged lines hidden (view full) ---

669 goto out;
670 n->m_len = min(MLEN, len + off);
671 m->m_next = n;
672 }
673 m = m->m_next;
674 }
675 while (len > 0) {
676 mlen = min (m->m_len - off, len);
677 bcopy(cp, off + mtod(m, caddr_t), (unsigned)mlen);
677 bcopy(cp, off + mtod(m, caddr_t), (u_int)mlen);
678 cp += mlen;
679 len -= mlen;
680 mlen += off;
681 off = 0;
682 totlen += mlen;
683 if (len == 0)
684 break;
685 if (m->m_next == NULL) {

--- 20 unchanged lines hidden (view full) ---

706 while (len) {
707 printf("%p %*D\n", m2, m2->m_len, (u_char *)m2->m_data, "-");
708 len -= m2->m_len;
709 m2 = m2->m_next;
710 }
711 return;
712}
713
678 cp += mlen;
679 len -= mlen;
680 mlen += off;
681 off = 0;
682 totlen += mlen;
683 if (len == 0)
684 break;
685 if (m->m_next == NULL) {

--- 20 unchanged lines hidden (view full) ---

706 while (len) {
707 printf("%p %*D\n", m2, m2->m_len, (u_char *)m2->m_data, "-");
708 len -= m2->m_len;
709 m2 = m2->m_next;
710 }
711 return;
712}
713
714unsigned
714u_int
715m_fixhdr(struct mbuf *m0)
716{
715m_fixhdr(struct mbuf *m0)
716{
717 unsigned len;
717 u_int len;
718
719 len = m_length(m0, NULL);
720 m0->m_pkthdr.len = len;
721 return (len);
722}
723
718
719 len = m_length(m0, NULL);
720 m0->m_pkthdr.len = len;
721 return (len);
722}
723
724unsigned
724u_int
725m_length(struct mbuf *m0, struct mbuf **last)
726{
727 struct mbuf *m;
725m_length(struct mbuf *m0, struct mbuf **last)
726{
727 struct mbuf *m;
728 unsigned len;
728 u_int len;
729
730 len = 0;
731 for (m = m0; m != NULL; m = m->m_next) {
732 len += m->m_len;
733 if (m->m_next == NULL)
734 break;
735 }
736 if (last != NULL)
737 *last = m;
738 return (len);
739}
729
730 len = 0;
731 for (m = m0; m != NULL; m = m->m_next) {
732 len += m->m_len;
733 if (m->m_next == NULL)
734 break;
735 }
736 if (last != NULL)
737 *last = m;
738 return (len);
739}