Deleted Added
sdiff udiff text old ( 128402 ) new ( 129906 )
full compact
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

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

25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)uipc_mbuf.c 8.2 (Berkeley) 1/4/94
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/kern/uipc_mbuf.c 128402 2004-04-18 13:01:28Z luigi $");
34
35#include "opt_mac.h"
36#include "opt_param.h"
37#include "opt_mbuf_stress_test.h"
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/kernel.h>

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

81 &m_defraguseless, 0, "");
82SYSCTL_INT(_kern_ipc, OID_AUTO, m_defragfailure, CTLFLAG_RD,
83 &m_defragfailure, 0, "");
84SYSCTL_INT(_kern_ipc, OID_AUTO, m_defragrandomfailures, CTLFLAG_RW,
85 &m_defragrandomfailures, 0, "");
86#endif
87
88/*
89 * "Move" mbuf pkthdr from "from" to "to".
90 * "from" must have M_PKTHDR set, and "to" must be empty.
91 */
92void
93m_move_pkthdr(struct mbuf *to, struct mbuf *from)
94{
95
96#if 0

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

359 /* While there's more data, get a new mbuf, tack it on, and fill it */
360 remain = m->m_pkthdr.len;
361 moff = 0;
362 p = &top;
363 while (remain > 0 || top == NULL) { /* allow m->m_pkthdr.len == 0 */
364 struct mbuf *n;
365
366 /* Get the next new mbuf */
367 MGET(n, how, m->m_type);
368 if (n == NULL)
369 goto nospace;
370 if (top == NULL) { /* first one, must be PKTHDR */
371 if (!m_dup_pkthdr(n, m, how))
372 goto nospace;
373 nsize = MHLEN;
374 } else /* not the first one */
375 nsize = MLEN;
376 if (remain >= MINCLSIZE) {
377 MCLGET(n, how);
378 if ((n->m_flags & M_EXT) == 0) {
379 (void)m_free(n);
380 goto nospace;
381 }
382 nsize = MCLBYTES;
383 }
384 n->m_len = 0;
385
386 /* Link it into the new chain */
387 *p = n;
388 p = &n->m_next;
389
390 /* Copy data from original mbuf(s) into new mbuf */

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

646 * Note that `off' argument is offset into first mbuf of target chain from
647 * which to begin copying the data to.
648 */
649struct mbuf *
650m_devget(char *buf, int totlen, int off, struct ifnet *ifp,
651 void (*copy)(char *from, caddr_t to, u_int len))
652{
653 struct mbuf *m;
654 struct mbuf *top = 0, **mp = &top;
655 int len;
656
657 if (off < 0 || off > MHLEN)
658 return (NULL);
659
660 MGETHDR(m, M_DONTWAIT, MT_DATA);
661 if (m == NULL)
662 return (NULL);
663 m->m_pkthdr.rcvif = ifp;
664 m->m_pkthdr.len = totlen;
665 len = MHLEN;
666
667 while (totlen > 0) {
668 if (top) {
669 MGET(m, M_DONTWAIT, MT_DATA);
670 if (m == NULL) {
671 m_freem(top);
672 return (NULL);
673 }
674 len = MLEN;
675 }
676 if (totlen + off >= MINCLSIZE) {
677 MCLGET(m, M_DONTWAIT);
678 if (m->m_flags & M_EXT)
679 len = MCLBYTES;
680 } else {
681 /*
682 * Place initial small packet/header at end of mbuf.
683 */
684 if (top == NULL && totlen + off + max_linkhdr <= len) {
685 m->m_data += max_linkhdr;
686 len -= max_linkhdr;
687 }
688 }
689 if (off) {
690 m->m_data += off;
691 len -= off;
692 off = 0;
693 }
694 m->m_len = len = min(totlen, len);
695 if (copy)
696 copy(buf, mtod(m, caddr_t), (u_int)len);

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

717 int totlen = 0;
718
719 if (m0 == NULL)
720 return;
721 while (off > (mlen = m->m_len)) {
722 off -= mlen;
723 totlen += mlen;
724 if (m->m_next == NULL) {
725 n = m_get_clrd(M_DONTWAIT, m->m_type);
726 if (n == NULL)
727 goto out;
728 n->m_len = min(MLEN, len + off);
729 m->m_next = n;
730 }
731 m = m->m_next;
732 }
733 while (len > 0) {
734 mlen = min (m->m_len - off, len);
735 bcopy(cp, off + mtod(m, caddr_t), (u_int)mlen);

--- 341 unchanged lines hidden ---