Deleted Added
full compact
uipc_mbuf.c (105194) uipc_mbuf.c (108466)
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 105194 2002-10-16 01:54:46Z sam $
34 * $FreeBSD: head/sys/kern/uipc_mbuf.c 108466 2002-12-30 20:22:40Z sam $
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>

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

61 &max_linkhdr, 0, "");
62SYSCTL_INT(_kern_ipc, KIPC_MAX_PROTOHDR, max_protohdr, CTLFLAG_RW,
63 &max_protohdr, 0, "");
64SYSCTL_INT(_kern_ipc, KIPC_MAX_HDR, max_hdr, CTLFLAG_RW, &max_hdr, 0, "");
65SYSCTL_INT(_kern_ipc, KIPC_MAX_DATALEN, max_datalen, CTLFLAG_RW,
66 &max_datalen, 0, "");
67
68/*
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>

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

61 &max_linkhdr, 0, "");
62SYSCTL_INT(_kern_ipc, KIPC_MAX_PROTOHDR, max_protohdr, CTLFLAG_RW,
63 &max_protohdr, 0, "");
64SYSCTL_INT(_kern_ipc, KIPC_MAX_HDR, max_hdr, CTLFLAG_RW, &max_hdr, 0, "");
65SYSCTL_INT(_kern_ipc, KIPC_MAX_DATALEN, max_datalen, CTLFLAG_RW,
66 &max_datalen, 0, "");
67
68/*
69 * Copy mbuf pkthdr from "from" to "to".
69 * "Move" mbuf pkthdr from "from" to "to".
70 * "from" must have M_PKTHDR set, and "to" must be empty.
70 * "from" must have M_PKTHDR set, and "to" must be empty.
71 * aux pointer will be moved to "to".
72 */
73void
71 */
72void
74m_copy_pkthdr(struct mbuf *to, struct mbuf *from)
73m_move_pkthdr(struct mbuf *to, struct mbuf *from)
75{
76
77#if 0
74{
75
76#if 0
77 /* see below for why these are not enabled */
78 KASSERT(to->m_flags & M_PKTHDR,
78 KASSERT(to->m_flags & M_PKTHDR,
79 ("m_copy_pkthdr() called on non-header"));
79 ("m_move_pkthdr: called on non-header"));
80 KASSERT(SLIST_EMPTY(&to->m_pkthdr.tags),
81 ("m_move_pkthdr: to has tags"));
80#endif
82#endif
83 KASSERT((to->m_flags & M_EXT) == 0, ("m_move_pkthdr: to has cluster"));
81#ifdef MAC
82 if (to->m_flags & M_PKTHDR)
83 mac_destroy_mbuf(to);
84#endif
84#ifdef MAC
85 if (to->m_flags & M_PKTHDR)
86 mac_destroy_mbuf(to);
87#endif
88 to->m_flags = from->m_flags & M_COPYFLAGS;
85 to->m_data = to->m_pktdat;
89 to->m_data = to->m_pktdat;
90 to->m_pkthdr = from->m_pkthdr; /* especially tags */
91#ifdef MAC
92 mac_init_mbuf(to, 1); /* XXXMAC no way to fail */
93 mac_create_mbuf_from_mbuf(from, to);
94#endif
95 SLIST_INIT(&from->m_pkthdr.tags); /* purge tags from src */
96 from->m_flags &= ~M_PKTHDR;
97}
98
99/*
100 * Duplicate "from"'s mbuf pkthdr in "to".
101 * "from" must have M_PKTHDR set, and "to" must be empty.
102 * In particular, this does a deep copy of the packet tags.
103 */
104int
105m_dup_pkthdr(struct mbuf *to, struct mbuf *from, int how)
106{
107
108#if 0
109 /*
110 * The mbuf allocator only initializes the pkthdr
111 * when the mbuf is allocated with MGETHDR. Many users
112 * (e.g. m_copy*, m_prepend) use MGET and then
113 * smash the pkthdr as needed causing these
114 * assertions to trip. For now just disable them.
115 */
116 KASSERT(to->m_flags & M_PKTHDR, ("m_dup_pkthdr: called on non-header"));
117 KASSERT(SLIST_EMPTY(&to->m_pkthdr.tags), ("m_dup_pkthdr: to has tags"));
118#endif
119 KASSERT((to->m_flags & M_EXT) == 0, ("m_dup_pkthdr: to has cluster"));
120#ifdef MAC
121 if (to->m_flags & M_PKTHDR)
122 mac_destroy_mbuf(to);
123#endif
86 to->m_flags = from->m_flags & M_COPYFLAGS;
124 to->m_flags = from->m_flags & M_COPYFLAGS;
125 to->m_data = to->m_pktdat;
87 to->m_pkthdr = from->m_pkthdr;
88#ifdef MAC
89 mac_init_mbuf(to, 1); /* XXXMAC no way to fail */
90 mac_create_mbuf_from_mbuf(from, to);
91#endif
126 to->m_pkthdr = from->m_pkthdr;
127#ifdef MAC
128 mac_init_mbuf(to, 1); /* XXXMAC no way to fail */
129 mac_create_mbuf_from_mbuf(from, to);
130#endif
92 SLIST_INIT(&from->m_pkthdr.tags);
131 SLIST_INIT(&to->m_pkthdr.tags);
132 return (m_tag_copy_chain(to, from, how));
93}
94
95/*
96 * Lesser-used path for M_PREPEND:
97 * allocate new mbuf to prepend to chain,
98 * copy junk along.
99 */
100struct mbuf *
101m_prepend(struct mbuf *m, int len, int how)
102{
103 struct mbuf *mn;
104
105 MGET(mn, how, m->m_type);
106 if (mn == NULL) {
107 m_freem(m);
108 return (NULL);
109 }
110 if (m->m_flags & M_PKTHDR) {
133}
134
135/*
136 * Lesser-used path for M_PREPEND:
137 * allocate new mbuf to prepend to chain,
138 * copy junk along.
139 */
140struct mbuf *
141m_prepend(struct mbuf *m, int len, int how)
142{
143 struct mbuf *mn;
144
145 MGET(mn, how, m->m_type);
146 if (mn == NULL) {
147 m_freem(m);
148 return (NULL);
149 }
150 if (m->m_flags & M_PKTHDR) {
111 M_COPY_PKTHDR(mn, m);
151 M_MOVE_PKTHDR(mn, m);
112#ifdef MAC
113 mac_destroy_mbuf(m);
114#endif
152#ifdef MAC
153 mac_destroy_mbuf(m);
154#endif
115 m->m_flags &= ~M_PKTHDR;
116 }
117 mn->m_next = m;
118 m = mn;
119 if (len < MHLEN)
120 MH_ALIGN(m, len);
121 m->m_len = len;
122 return (m);
123}

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

156 ("m_copym, length > size of mbuf chain"));
157 break;
158 }
159 MGET(n, wait, m->m_type);
160 *np = n;
161 if (n == NULL)
162 goto nospace;
163 if (copyhdr) {
155 }
156 mn->m_next = m;
157 m = mn;
158 if (len < MHLEN)
159 MH_ALIGN(m, len);
160 m->m_len = len;
161 return (m);
162}

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

195 ("m_copym, length > size of mbuf chain"));
196 break;
197 }
198 MGET(n, wait, m->m_type);
199 *np = n;
200 if (n == NULL)
201 goto nospace;
202 if (copyhdr) {
164 M_COPY_PKTHDR(n, m);
203 if (!m_dup_pkthdr(n, m, wait))
204 goto nospace;
165 if (len == M_COPYALL)
166 n->m_pkthdr.len -= off0;
167 else
168 n->m_pkthdr.len = len;
169 copyhdr = 0;
170 }
171 n->m_len = min(len, m->m_len - off);
172 if (m->m_flags & M_EXT) {

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

207{
208 struct mbuf *top, *n, *o;
209
210 MGET(n, how, m->m_type);
211 top = n;
212 if (n == NULL)
213 goto nospace;
214
205 if (len == M_COPYALL)
206 n->m_pkthdr.len -= off0;
207 else
208 n->m_pkthdr.len = len;
209 copyhdr = 0;
210 }
211 n->m_len = min(len, m->m_len - off);
212 if (m->m_flags & M_EXT) {

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

247{
248 struct mbuf *top, *n, *o;
249
250 MGET(n, how, m->m_type);
251 top = n;
252 if (n == NULL)
253 goto nospace;
254
215 M_COPY_PKTHDR(n, m);
255 if (!m_dup_pkthdr(n, m, how))
256 goto nospace;
216 n->m_len = m->m_len;
217 if (m->m_flags & M_EXT) {
218 n->m_data = m->m_data;
219 n->m_ext = m->m_ext;
220 n->m_flags |= M_EXT;
221 MEXT_ADD_REF(m);
222 } else {
223 n->m_data = n->m_pktdat + (m->m_data - m->m_pktdat );

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

304 while (remain > 0 || top == NULL) { /* allow m->m_pkthdr.len == 0 */
305 struct mbuf *n;
306
307 /* Get the next new mbuf */
308 MGET(n, how, m->m_type);
309 if (n == NULL)
310 goto nospace;
311 if (top == NULL) { /* first one, must be PKTHDR */
257 n->m_len = m->m_len;
258 if (m->m_flags & M_EXT) {
259 n->m_data = m->m_data;
260 n->m_ext = m->m_ext;
261 n->m_flags |= M_EXT;
262 MEXT_ADD_REF(m);
263 } else {
264 n->m_data = n->m_pktdat + (m->m_data - m->m_pktdat );

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

345 while (remain > 0 || top == NULL) { /* allow m->m_pkthdr.len == 0 */
346 struct mbuf *n;
347
348 /* Get the next new mbuf */
349 MGET(n, how, m->m_type);
350 if (n == NULL)
351 goto nospace;
352 if (top == NULL) { /* first one, must be PKTHDR */
312 M_COPY_PKTHDR(n, m);
353 if (!m_dup_pkthdr(n, m, how))
354 goto nospace;
313 nsize = MHLEN;
314 } else /* not the first one */
315 nsize = MLEN;
316 if (remain >= MINCLSIZE) {
317 MCLGET(n, how);
318 if ((n->m_flags & M_EXT) == 0) {
319 (void)m_free(n);
320 goto nospace;

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

479 len -= m->m_len;
480 } else {
481 if (len > MHLEN)
482 goto bad;
483 MGET(m, M_DONTWAIT, n->m_type);
484 if (m == NULL)
485 goto bad;
486 m->m_len = 0;
355 nsize = MHLEN;
356 } else /* not the first one */
357 nsize = MLEN;
358 if (remain >= MINCLSIZE) {
359 MCLGET(n, how);
360 if ((n->m_flags & M_EXT) == 0) {
361 (void)m_free(n);
362 goto nospace;

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

521 len -= m->m_len;
522 } else {
523 if (len > MHLEN)
524 goto bad;
525 MGET(m, M_DONTWAIT, n->m_type);
526 if (m == NULL)
527 goto bad;
528 m->m_len = 0;
487 if (n->m_flags & M_PKTHDR) {
488 M_COPY_PKTHDR(m, n);
489 n->m_flags &= ~M_PKTHDR;
490 }
529 if (n->m_flags & M_PKTHDR)
530 M_MOVE_PKTHDR(m, n);
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 (u_int)count);
497 len -= count;
498 m->m_len += count;

--- 241 unchanged lines hidden ---
531 }
532 space = &m->m_dat[MLEN] - (m->m_data + m->m_len);
533 do {
534 count = min(min(max(len, max_protohdr), space), n->m_len);
535 bcopy(mtod(n, caddr_t), mtod(m, caddr_t) + m->m_len,
536 (u_int)count);
537 len -= count;
538 m->m_len += count;

--- 241 unchanged lines hidden ---