xref: /dragonfly/sys/netgraph7/vjc/ng_vjc.c (revision ef2687d4)
1 
2 /*
3  * ng_vjc.c
4  */
5 
6 /*-
7  * Copyright (c) 1996-1999 Whistle Communications, Inc.
8  * All rights reserved.
9  *
10  * Subject to the following obligations and disclaimer of warranty, use and
11  * redistribution of this software, in source or object code forms, with or
12  * without modifications are expressly permitted by Whistle Communications;
13  * provided, however, that:
14  * 1. Any and all reproductions of the source or object code must include the
15  *    copyright notice above and the following disclaimer of warranties; and
16  * 2. No rights are granted, in any manner or form, to use Whistle
17  *    Communications, Inc. trademarks, including the mark "WHISTLE
18  *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
19  *    such appears in the above copyright notice or in the software.
20  *
21  * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
22  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
23  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
24  * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
26  * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
27  * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
28  * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
29  * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
30  * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
31  * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
32  * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
33  * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36  * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
37  * OF SUCH DAMAGE.
38  *
39  * Author: Archie Cobbs <archie@freebsd.org>
40  *
41  * $FreeBSD: src/sys/netgraph/ng_vjc.c,v 1.26 2005/12/04 00:25:03 ru Exp $
42  * $Whistle: ng_vjc.c,v 1.17 1999/11/01 09:24:52 julian Exp $
43  */
44 
45 /*
46  * This node performs Van Jacobson IP header (de)compression.
47  * You must have included net/slcompress.c in your kernel compilation.
48  */
49 
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/errno.h>
53 #include <sys/kernel.h>
54 #include <sys/mbuf.h>
55 #include <sys/malloc.h>
56 
57 #include <netgraph7/ng_message.h>
58 #include <netgraph7/netgraph.h>
59 #include <netgraph7/ng_parse.h>
60 #include "ng_vjc.h"
61 
62 #include <netinet/in.h>
63 #include <netinet/in_systm.h>
64 #include <netinet/ip.h>
65 #include <netinet/tcp.h>
66 
67 #include <net/slcompress.h>
68 
69 /* Check agreement with slcompress.c */
70 #if MAX_STATES != NG_VJC_MAX_CHANNELS
71 #error NG_VJC_MAX_CHANNELS must be the same as MAX_STATES
72 #endif
73 
74 /* Maximum length of a compressed TCP VJ header */
75 #define MAX_VJHEADER		19
76 
77 /* Node private data */
78 struct ng_vjc_private {
79 	struct	ngm_vjc_config conf;
80 	struct	slcompress slc;
81 	hook_p	ip;
82 	hook_p	vjcomp;
83 	hook_p	vjuncomp;
84 	hook_p	vjip;
85 };
86 typedef struct ng_vjc_private *priv_p;
87 
88 #define ERROUT(x)	do { error = (x); goto done; } while (0)
89 
90 /* Netgraph node methods */
91 static ng_constructor_t	ng_vjc_constructor;
92 static ng_rcvmsg_t	ng_vjc_rcvmsg;
93 static ng_shutdown_t	ng_vjc_shutdown;
94 static ng_newhook_t	ng_vjc_newhook;
95 static ng_rcvdata_t	ng_vjc_rcvdata;
96 static ng_disconnect_t	ng_vjc_disconnect;
97 
98 /* Helper stuff */
99 static struct mbuf *ng_vjc_pulluphdrs(struct mbuf *m, int knownTCP);
100 
101 /* Parse type for struct ngm_vjc_config */
102 static const struct ng_parse_struct_field ng_vjc_config_type_fields[]
103 	= NG_VJC_CONFIG_TYPE_INFO;
104 static const struct ng_parse_type ng_vjc_config_type = {
105 	&ng_parse_struct_type,
106 	&ng_vjc_config_type_fields
107 };
108 
109 /* Parse type for the 'last_cs' and 'cs_next' fields in struct slcompress,
110    which are pointers converted to integer indices, so parse them that way. */
111 #ifndef __LP64__
112 #define NG_VJC_TSTATE_PTR_TYPE	&ng_parse_uint32_type
113 #else
114 #define NG_VJC_TSTATE_PTR_TYPE	&ng_parse_uint64_type
115 #endif
116 
117 /* Parse type for the 'cs_hdr' field in a struct cstate. Ideally we would
118    like to use a 'struct ip' type instead of a simple array of bytes. */
119 static const struct ng_parse_fixedarray_info ng_vjc_cs_hdr_type_info = {
120 	&ng_parse_hint8_type,
121 	MAX_HDR
122 };
123 static const struct ng_parse_type ng_vjc_cs_hdr_type = {
124 	&ng_parse_fixedarray_type,
125 	&ng_vjc_cs_hdr_type_info
126 };
127 
128 /* Parse type for a struct cstate */
129 static const struct ng_parse_struct_field ng_vjc_cstate_type_fields[] = {
130 	{ "cs_next",		NG_VJC_TSTATE_PTR_TYPE		},
131 	{ "cs_hlen",		&ng_parse_uint16_type		},
132 	{ "cs_id",		&ng_parse_uint8_type		},
133 	{ "cs_filler",		&ng_parse_uint8_type		},
134 	{ "cs_hdr",		&ng_vjc_cs_hdr_type		},
135 	{ NULL }
136 };
137 static const struct ng_parse_type ng_vjc_cstate_type = {
138 	&ng_parse_struct_type,
139 	&ng_vjc_cstate_type_fields
140 };
141 
142 /* Parse type for an array of MAX_STATES struct cstate's, ie, tstate & rstate */
143 static const struct ng_parse_fixedarray_info ng_vjc_cstatearray_type_info = {
144 	&ng_vjc_cstate_type,
145 	MAX_STATES
146 };
147 static const struct ng_parse_type ng_vjc_cstatearray_type = {
148 	&ng_parse_fixedarray_type,
149 	&ng_vjc_cstatearray_type_info
150 };
151 
152 /* Parse type for struct slcompress. Keep this in sync with the
153    definition of struct slcompress defined in <net/slcompress.h> */
154 static const struct ng_parse_struct_field ng_vjc_slcompress_type_fields[] = {
155 	{ "last_cs",		NG_VJC_TSTATE_PTR_TYPE		},
156 	{ "last_recv",		&ng_parse_uint8_type		},
157 	{ "last_xmit",		&ng_parse_uint8_type		},
158 	{ "flags",		&ng_parse_hint16_type		},
159 #ifndef SL_NO_STATS
160 	{ "sls_packets",	&ng_parse_uint32_type		},
161 	{ "sls_compressed",	&ng_parse_uint32_type		},
162 	{ "sls_searches",	&ng_parse_uint32_type		},
163 	{ "sls_misses",		&ng_parse_uint32_type		},
164 	{ "sls_uncompressedin",	&ng_parse_uint32_type		},
165 	{ "sls_compressedin",	&ng_parse_uint32_type		},
166 	{ "sls_errorin",	&ng_parse_uint32_type		},
167 	{ "sls_tossed",		&ng_parse_uint32_type		},
168 #endif
169 	{ "tstate",		&ng_vjc_cstatearray_type	},
170 	{ "rstate",		&ng_vjc_cstatearray_type	},
171 	{ NULL }
172 };
173 static const struct ng_parse_type ng_vjc_slcompress_type = {
174 	&ng_parse_struct_type,
175 	&ng_vjc_slcompress_type_fields
176 };
177 
178 /* List of commands and how to convert arguments to/from ASCII */
179 static const struct ng_cmdlist ng_vjc_cmds[] = {
180 	{
181 	  NGM_VJC_COOKIE,
182 	  NGM_VJC_SET_CONFIG,
183 	  "setconfig",
184 	  &ng_vjc_config_type,
185 	  NULL
186 	},
187 	{
188 	  NGM_VJC_COOKIE,
189 	  NGM_VJC_GET_CONFIG,
190 	  "getconfig",
191 	  NULL,
192 	  &ng_vjc_config_type,
193 	},
194 	{
195 	  NGM_VJC_COOKIE,
196 	  NGM_VJC_GET_STATE,
197 	  "getstate",
198 	  NULL,
199 	  &ng_vjc_slcompress_type,
200 	},
201 	{
202 	  NGM_VJC_COOKIE,
203 	  NGM_VJC_CLR_STATS,
204 	  "clrstats",
205 	  NULL,
206 	  NULL,
207 	},
208 	{
209 	  NGM_VJC_COOKIE,
210 	  NGM_VJC_RECV_ERROR,
211 	  "recverror",
212 	  NULL,
213 	  NULL,
214 	},
215 	{ 0 }
216 };
217 
218 /* Node type descriptor */
219 static struct ng_type ng_vjc_typestruct = {
220 	.version =	NG_ABI_VERSION,
221 	.name =		NG_VJC_NODE_TYPE,
222 	.constructor =	ng_vjc_constructor,
223 	.rcvmsg =	ng_vjc_rcvmsg,
224 	.shutdown =	ng_vjc_shutdown,
225 	.newhook =	ng_vjc_newhook,
226 	.rcvdata =	ng_vjc_rcvdata,
227 	.disconnect =	ng_vjc_disconnect,
228 	.cmdlist =	ng_vjc_cmds,
229 };
230 NETGRAPH_INIT(vjc, &ng_vjc_typestruct);
231 
232 /************************************************************************
233 			NETGRAPH NODE METHODS
234  ************************************************************************/
235 
236 /*
237  * Create a new node
238  */
239 static int
240 ng_vjc_constructor(node_p node)
241 {
242 	priv_p priv;
243 
244 	/* Allocate private structure */
245 	priv = kmalloc(sizeof(*priv), M_NETGRAPH,
246 		       M_WAITOK | M_NULLOK | M_ZERO);
247 	if (priv == NULL)
248 		return (ENOMEM);
249 
250 	NG_NODE_SET_PRIVATE(node, priv);
251 
252 	/* Done */
253 	return (0);
254 }
255 
256 /*
257  * Add a new hook
258  */
259 static int
260 ng_vjc_newhook(node_p node, hook_p hook, const char *name)
261 {
262 	const priv_p priv = NG_NODE_PRIVATE(node);
263 	hook_p *hookp;
264 
265 	/* Get hook */
266 	if (strcmp(name, NG_VJC_HOOK_IP) == 0)
267 		hookp = &priv->ip;
268 	else if (strcmp(name, NG_VJC_HOOK_VJCOMP) == 0)
269 		hookp = &priv->vjcomp;
270 	else if (strcmp(name, NG_VJC_HOOK_VJUNCOMP) == 0)
271 		hookp = &priv->vjuncomp;
272 	else if (strcmp(name, NG_VJC_HOOK_VJIP) == 0)
273 		hookp = &priv->vjip;
274 	else
275 		return (EINVAL);
276 
277 	/* See if already connected */
278 	if (*hookp)
279 		return (EISCONN);
280 
281 	/* OK */
282 	*hookp = hook;
283 	return (0);
284 }
285 
286 /*
287  * Receive a control message
288  */
289 static int
290 ng_vjc_rcvmsg(node_p node, item_p item, hook_p lasthook)
291 {
292 	const priv_p priv = NG_NODE_PRIVATE(node);
293 	struct ng_mesg *resp = NULL;
294 	int error = 0;
295 	struct ng_mesg *msg;
296 
297 	NGI_GET_MSG(item, msg);
298 	/* Check type cookie */
299 	switch (msg->header.typecookie) {
300 	case NGM_VJC_COOKIE:
301 		switch (msg->header.cmd) {
302 		case NGM_VJC_SET_CONFIG:
303 		    {
304 			struct ngm_vjc_config *const c =
305 				(struct ngm_vjc_config *) msg->data;
306 
307 			if (msg->header.arglen != sizeof(*c))
308 				ERROUT(EINVAL);
309 			if ((priv->conf.enableComp || priv->conf.enableDecomp)
310 			    && (c->enableComp || c->enableDecomp))
311 				ERROUT(EALREADY);
312 			if (c->enableComp) {
313 				if (c->maxChannel > NG_VJC_MAX_CHANNELS - 1
314 				    || c->maxChannel < NG_VJC_MIN_CHANNELS - 1)
315 					ERROUT(EINVAL);
316 			} else
317 				c->maxChannel = NG_VJC_MAX_CHANNELS - 1;
318 			if (c->enableComp != 0 || c->enableDecomp != 0) {
319 				bzero(&priv->slc, sizeof(priv->slc));
320 				sl_compress_init(&priv->slc, c->maxChannel);
321 			}
322 			priv->conf = *c;
323 			break;
324 		    }
325 		case NGM_VJC_GET_CONFIG:
326 		    {
327 			struct ngm_vjc_config *conf;
328 
329 			NG_MKRESPONSE(resp, msg, sizeof(*conf), M_WAITOK | M_NULLOK);
330 			if (resp == NULL)
331 				ERROUT(ENOMEM);
332 			conf = (struct ngm_vjc_config *)resp->data;
333 			*conf = priv->conf;
334 			break;
335 		    }
336 		case NGM_VJC_GET_STATE:
337 		    {
338 			const struct slcompress *const sl0 = &priv->slc;
339 			struct slcompress *sl;
340 			u_int16_t index;
341 			int i;
342 
343 			/* Get response structure */
344 			NG_MKRESPONSE(resp, msg, sizeof(*sl), M_WAITOK | M_NULLOK);
345 			if (resp == NULL)
346 				ERROUT(ENOMEM);
347 			sl = (struct slcompress *)resp->data;
348 			*sl = *sl0;
349 
350 			/* Replace pointers with integer indicies */
351 			if (sl->last_cs != NULL) {
352 				index = sl0->last_cs - sl0->tstate;
353 				bzero(&sl->last_cs, sizeof(sl->last_cs));
354 				*((u_int16_t *)&sl->last_cs) = index;
355 			}
356 			for (i = 0; i < MAX_STATES; i++) {
357 				struct cstate *const cs = &sl->tstate[i];
358 
359 				index = sl0->tstate[i].cs_next - sl0->tstate;
360 				bzero(&cs->cs_next, sizeof(cs->cs_next));
361 				*((u_int16_t *)&cs->cs_next) = index;
362 			}
363 			break;
364 		    }
365 		case NGM_VJC_CLR_STATS:
366 			priv->slc.sls_packets = 0;
367 			priv->slc.sls_compressed = 0;
368 			priv->slc.sls_searches = 0;
369 			priv->slc.sls_misses = 0;
370 			priv->slc.sls_uncompressedin = 0;
371 			priv->slc.sls_compressedin = 0;
372 			priv->slc.sls_errorin = 0;
373 			priv->slc.sls_tossed = 0;
374 			break;
375 		case NGM_VJC_RECV_ERROR:
376 			sl_uncompress_tcp(NULL, 0, TYPE_ERROR, &priv->slc);
377 			break;
378 		default:
379 			error = EINVAL;
380 			break;
381 		}
382 		break;
383 	default:
384 		error = EINVAL;
385 		break;
386 	}
387 done:
388 	NG_RESPOND_MSG(error, node, item, resp);
389 	NG_FREE_MSG(msg);
390 	return (error);
391 }
392 
393 /*
394  * Receive data
395  */
396 static int
397 ng_vjc_rcvdata(hook_p hook, item_p item)
398 {
399 	const node_p node = NG_HOOK_NODE(hook);
400 	const priv_p priv = NG_NODE_PRIVATE(node);
401 	int error = 0;
402 	struct mbuf *m;
403 
404 	NGI_GET_M(item, m);
405 	if (hook == priv->ip) {			/* outgoing packet */
406 		u_int type = TYPE_IP;
407 
408 		/* Compress packet if enabled and proto is TCP */
409 		if (priv->conf.enableComp) {
410 			struct ip *ip;
411 
412 			if ((m = ng_vjc_pulluphdrs(m, 0)) == NULL) {
413 				NG_FREE_ITEM(item);
414 				return (ENOBUFS);
415 			}
416 			ip = mtod(m, struct ip *);
417 			if (ip->ip_p == IPPROTO_TCP) {
418 				const int origLen = m->m_len;
419 
420 				type = sl_compress_tcp(m, ip,
421 				    &priv->slc, priv->conf.compressCID);
422 				m->m_pkthdr.len += m->m_len - origLen;
423 			}
424 		}
425 
426 		/* Dispatch to the appropriate outgoing hook */
427 		switch (type) {
428 		case TYPE_IP:
429 			hook = priv->vjip;
430 			break;
431 		case TYPE_UNCOMPRESSED_TCP:
432 			hook = priv->vjuncomp;
433 			break;
434 		case TYPE_COMPRESSED_TCP:
435 			hook = priv->vjcomp;
436 			break;
437 		default:
438 			panic("%s: type=%d", __func__, type);
439 		}
440 	} else if (hook == priv->vjcomp) {	/* incoming compressed packet */
441 		int vjlen, need2pullup;
442 		struct mbuf *hm;
443 		u_char *hdr;
444 		u_int hlen;
445 
446 		/* Are we decompressing? */
447 		if (!priv->conf.enableDecomp) {
448 			NG_FREE_M(m);
449 			NG_FREE_ITEM(item);
450 			return (ENXIO);
451 		}
452 
453 		/* Pull up the necessary amount from the mbuf */
454 		need2pullup = MAX_VJHEADER;
455 		if (need2pullup > m->m_pkthdr.len)
456 			need2pullup = m->m_pkthdr.len;
457 		if (m->m_len < need2pullup
458 		    && (m = m_pullup(m, need2pullup)) == NULL) {
459 			priv->slc.sls_errorin++;
460 			NG_FREE_ITEM(item);
461 			return (ENOBUFS);
462 		}
463 
464 		/* Uncompress packet to reconstruct TCP/IP header */
465 		vjlen = sl_uncompress_tcp_core(mtod(m, u_char *),
466 		    m->m_len, m->m_pkthdr.len, TYPE_COMPRESSED_TCP,
467 		    &priv->slc, &hdr, &hlen);
468 		if (vjlen <= 0) {
469 			NG_FREE_M(m);
470 			NG_FREE_ITEM(item);
471 			return (EINVAL);
472 		}
473 		m_adj(m, vjlen);
474 
475 		/* Copy the reconstructed TCP/IP headers into a new mbuf */
476 		MGETHDR(hm, M_NOWAIT, MT_DATA);
477 		if (hm == NULL) {
478 			priv->slc.sls_errorin++;
479 			NG_FREE_M(m);
480 			NG_FREE_ITEM(item);
481 			return (ENOBUFS);
482 		}
483 		hm->m_len = 0;
484 		hm->m_pkthdr.rcvif = NULL;
485 		if (hlen > MHLEN) {		/* unlikely, but can happen */
486 			MCLGET(hm, M_NOWAIT);
487 			if ((hm->m_flags & M_EXT) == 0) {
488 				m_freem(hm);
489 				priv->slc.sls_errorin++;
490 				NG_FREE_M(m);
491 				NG_FREE_ITEM(item);
492 				return (ENOBUFS);
493 			}
494 		}
495 		bcopy(hdr, mtod(hm, u_char *), hlen);
496 		hm->m_len = hlen;
497 
498 		/* Glue TCP/IP headers and rest of packet together */
499 		hm->m_next = m;
500 		hm->m_pkthdr.len = hlen + m->m_pkthdr.len;
501 		m = hm;
502 		hook = priv->ip;
503 	} else if (hook == priv->vjuncomp) {	/* incoming uncompressed pkt */
504 		u_char *hdr;
505 		u_int hlen;
506 
507 		/* Are we decompressing? */
508 		if (!priv->conf.enableDecomp) {
509 			NG_FREE_M(m);
510 			NG_FREE_ITEM(item);
511 			return (ENXIO);
512 		}
513 
514 		/* Pull up IP+TCP headers */
515 		if ((m = ng_vjc_pulluphdrs(m, 1)) == NULL) {
516 			NG_FREE_ITEM(item);
517 			return (ENOBUFS);
518 		}
519 
520 		/* Run packet through uncompressor */
521 		if (sl_uncompress_tcp_core(mtod(m, u_char *),
522 		    m->m_len, m->m_pkthdr.len, TYPE_UNCOMPRESSED_TCP,
523 		    &priv->slc, &hdr, &hlen) < 0) {
524 			NG_FREE_M(m);
525 			NG_FREE_ITEM(item);
526 			return (EINVAL);
527 		}
528 		hook = priv->ip;
529 	} else if (hook == priv->vjip)	/* incoming regular packet (bypass) */
530 		hook = priv->ip;
531 	else
532 		panic("%s: unknown hook", __func__);
533 
534 	/* Send result back out */
535 	NG_FWD_NEW_DATA(error, item, hook, m);
536 	return (error);
537 }
538 
539 /*
540  * Shutdown node
541  */
542 static int
543 ng_vjc_shutdown(node_p node)
544 {
545 	const priv_p priv = NG_NODE_PRIVATE(node);
546 
547 	bzero(priv, sizeof(*priv));
548 	kfree(priv, M_NETGRAPH);
549 	NG_NODE_SET_PRIVATE(node, NULL);
550 	NG_NODE_UNREF(node);
551 	return (0);
552 }
553 
554 /*
555  * Hook disconnection
556  */
557 static int
558 ng_vjc_disconnect(hook_p hook)
559 {
560 	const node_p node = NG_HOOK_NODE(hook);
561 	const priv_p priv = NG_NODE_PRIVATE(node);
562 
563 	/* Zero out hook pointer */
564 	if (hook == priv->ip)
565 		priv->ip = NULL;
566 	else if (hook == priv->vjcomp)
567 		priv->vjcomp = NULL;
568 	else if (hook == priv->vjuncomp)
569 		priv->vjuncomp = NULL;
570 	else if (hook == priv->vjip)
571 		priv->vjip = NULL;
572 	else
573 		panic("%s: unknown hook", __func__);
574 
575 	/* Go away if no hooks left */
576 	if ((NG_NODE_NUMHOOKS(node) == 0)
577 	&& (NG_NODE_IS_VALID(node)))
578 		ng_rmnode_self(node);
579 	return (0);
580 }
581 
582 /************************************************************************
583 			HELPER STUFF
584  ************************************************************************/
585 
586 /*
587  * Pull up the full IP and TCP headers of a packet. If packet is not
588  * a TCP packet, just pull up the IP header.
589  */
590 static struct mbuf *
591 ng_vjc_pulluphdrs(struct mbuf *m, int knownTCP)
592 {
593 	struct ip *ip;
594 	struct tcphdr *tcp;
595 	int ihlen, thlen;
596 
597 	if (m->m_len < sizeof(*ip) && (m = m_pullup(m, sizeof(*ip))) == NULL)
598 		return (NULL);
599 	ip = mtod(m, struct ip *);
600 	if (!knownTCP && ip->ip_p != IPPROTO_TCP)
601 		return (m);
602 	ihlen = ip->ip_hl << 2;
603 	if (m->m_len < ihlen + sizeof(*tcp)) {
604 		if ((m = m_pullup(m, ihlen + sizeof(*tcp))) == NULL)
605 			return (NULL);
606 		ip = mtod(m, struct ip *);
607 	}
608 	tcp = (struct tcphdr *)((u_char *)ip + ihlen);
609 	thlen = tcp->th_off << 2;
610 	if (m->m_len < ihlen + thlen)
611 		m = m_pullup(m, ihlen + thlen);
612 	return (m);
613 }
614 
615