Deleted Added
full compact
uipc_mbuf.c (149598) uipc_mbuf.c (149599)
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>
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 149598 2005-08-29 19:45:39Z andre $");
33__FBSDID("$FreeBSD: head/sys/kern/uipc_mbuf.c 149599 2005-08-29 19:58:56Z andre $");
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>

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

289 m->m_type = MT_DATA;
290 if (m != m0 && m->m_nextpkt)
291 m->m_nextpkt = NULL;
292 m->m_flags = m->m_flags & (M_EXT|M_EOR|M_RDONLY|M_FREELIST);
293 }
294}
295
296/*
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>

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

289 m->m_type = MT_DATA;
290 if (m != m0 && m->m_nextpkt)
291 m->m_nextpkt = NULL;
292 m->m_flags = m->m_flags & (M_EXT|M_EOR|M_RDONLY|M_FREELIST);
293 }
294}
295
296/*
297 * Sanity checks on mbuf (chain).
298 * Returns 0 bad, 1 good, panic worse.
299 * sanitize, 0 run M_SANITY_ACTION, 1 garble things so they blow up later.
300 */
301int
302m_sanity(struct mbuf *m0, int sanitize)
303{
304 struct mbuf *m;
305 caddr_t a, b;
306 int pktlen = 0;
307
308#define M_SANITY_ACTION(s) return (0)
309/* #define M_SANITY_ACTION(s) panic("mbuf %p: " s, m) */
310
311 m = m0;
312 while (m) {
313 /*
314 * Basic pointer checks. If any of these fails then some
315 * unrelated kernel memory before or after us is trashed.
316 * No way to recover from that.
317 */
318 a = (m->m_flags & M_EXT ? m->m_ext.ext_buf :
319 (m->m_flags & M_PKTHDR ? (caddr_t)(&m->m_pktdat) :
320 (caddr_t)(&m->m_dat)) );
321 b = (caddr_t)(a + (m->m_flags & M_EXT ? m->m_ext.ext_size :
322 (m->m_flags & M_PKTHDR ? MHLEN : MLEN)));
323 if ((caddr_t)m->m_data < a)
324 M_SANITY_ACTION("m_data outside mbuf data range left");
325 if ((caddr_t)m->m_data > b)
326 M_SANITY_ACTION("m_data outside mbuf data range right");
327 if ((caddr_t)m->m_data + m->m_len > b)
328 M_SANITY_ACTION("m_data + m_len exeeds mbuf space");
329 if (m->m_flags & M_PKTHDR && m->m_pkthdr.header) {
330 if ((caddr_t)m->m_pkthdr.header < a ||
331 (caddr_t)m->m_pkthdr.header > b)
332 M_SANITY_ACTION("m_pkthdr.header outside mbuf data range");
333 }
334
335 /* m->m_nextpkt may only be set on first mbuf in chain. */
336 if (m != m0 && m->m_nextpkt) {
337 if (sanitize) {
338 m_freem(m->m_nextpkt);
339 m->m_nextpkt = (struct mbuf *)0xDEADC0DE;
340 } else
341 M_SANITY_ACTION("m->m_nextpkt on in-chain mbuf");
342 }
343
344 /* correct type correlations. */
345 if (m->m_type == MT_HEADER && !(m->m_flags & M_PKTHDR)) {
346 if (sanitize)
347 m->m_type = MT_DATA;
348 else
349 M_SANITY_ACTION("MT_HEADER set but not M_PKTHDR");
350 }
351
352 /* packet length (not mbuf length!) calculation */
353 if (m0->m_flags & M_PKTHDR)
354 pktlen += m->m_len;
355
356 /* m_tags may only be attached to first mbuf in chain. */
357 if (m != m0 && m->m_flags & M_PKTHDR &&
358 !SLIST_EMPTY(&m->m_pkthdr.tags)) {
359 if (sanitize) {
360 m_tag_delete_chain(m, NULL);
361 /* put in 0xDEADC0DE perhaps? */
362 }
363 else
364 M_SANITY_ACTION("m_tags on in-chain mbuf");
365 }
366
367 /* M_PKTHDR may only be set on first mbuf in chain */
368 if (m != m0 && m->m_flags & M_PKTHDR) {
369 if (sanitize) {
370 bzero(&m->m_pkthdr, sizeof(m->m_pkthdr));
371 m->m_flags &= ~M_PKTHDR;
372 /* put in 0xDEADCODE and leave hdr flag in */
373 } else
374 M_SANITY_ACTION("M_PKTHDR on in-chain mbuf");
375 }
376
377 m = m->m_next;
378 }
379 if (pktlen && pktlen != m0->m_pkthdr.len) {
380 if (sanitize)
381 m0->m_pkthdr.len = 0;
382 else
383 M_SANITY_ACTION("m_pkthdr.len != mbuf chain length");
384 }
385#undef M_SANITY_ACTION
386
387 return 1;
388}
389
390
391/*
297 * "Move" mbuf pkthdr from "from" to "to".
298 * "from" must have M_PKTHDR set, and "to" must be empty.
299 */
300void
301m_move_pkthdr(struct mbuf *to, struct mbuf *from)
302{
303
304#if 0

--- 1123 unchanged lines hidden ---
392 * "Move" mbuf pkthdr from "from" to "to".
393 * "from" must have M_PKTHDR set, and "to" must be empty.
394 */
395void
396m_move_pkthdr(struct mbuf *to, struct mbuf *from)
397{
398
399#if 0

--- 1123 unchanged lines hidden ---