xref: /freebsd/sys/netgraph/ng_ip_input.c (revision f8aae7776f85d2fa8aa93f73c37782cd9e1204c6)
1c2eed105SBrooks Davis /*
2c2eed105SBrooks Davis  * ng_ip_input.c
3c2eed105SBrooks Davis  *
4c2eed105SBrooks Davis  * Copyright 2001 The Aerospace Corporation.  All rights reserved.
5c2eed105SBrooks Davis  *
6c2eed105SBrooks Davis  * Redistribution and use in source and binary forms, with or without
7c2eed105SBrooks Davis  * modification, are permitted provided that the following conditions
8c2eed105SBrooks Davis  * are met:
9c2eed105SBrooks Davis  *
10c2eed105SBrooks Davis  * 1.  Redistributions of source code must retain the above copyright
11c2eed105SBrooks Davis  *     notice, this list of conditions, and the following disclaimer.
12c2eed105SBrooks Davis  * 2.  Redistributions in binary form must reproduce the above copyright
13c2eed105SBrooks Davis  *     notice, this list of conditions, and the following disclaimer in the
14c2eed105SBrooks Davis  *     documentation and/or other materials provided with the distribution.
15c2eed105SBrooks Davis  * 3.  The name of The Aerospace Corporation may not be used to endorse or
16c2eed105SBrooks Davis  *     promote products derived from this software.
17c2eed105SBrooks Davis  *
18c2eed105SBrooks Davis  * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "AS IS" AND
19c2eed105SBrooks Davis  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20c2eed105SBrooks Davis  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21c2eed105SBrooks Davis  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE
22c2eed105SBrooks Davis  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23c2eed105SBrooks Davis  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24c2eed105SBrooks Davis  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25c2eed105SBrooks Davis  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26c2eed105SBrooks Davis  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27c2eed105SBrooks Davis  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28c2eed105SBrooks Davis  * SUCH DAMAGE.
29c2eed105SBrooks Davis  *
30c2eed105SBrooks Davis  * Copyright (c) 1996-1999 Whistle Communications, Inc.
31c2eed105SBrooks Davis  * All rights reserved.
32c2eed105SBrooks Davis  *
33c2eed105SBrooks Davis  * Subject to the following obligations and disclaimer of warranty, use and
34c2eed105SBrooks Davis  * redistribution of this software, in source or object code forms, with or
35c2eed105SBrooks Davis  * without modifications are expressly permitted by Whistle Communications;
36c2eed105SBrooks Davis  * provided, however, that:
37c2eed105SBrooks Davis  * 1. Any and all reproductions of the source or object code must include the
38c2eed105SBrooks Davis  *    copyright notice above and the following disclaimer of warranties; and
39c2eed105SBrooks Davis  * 2. No rights are granted, in any manner or form, to use Whistle
40c2eed105SBrooks Davis  *    Communications, Inc. trademarks, including the mark "WHISTLE
41c2eed105SBrooks Davis  *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
42c2eed105SBrooks Davis  *    such appears in the above copyright notice or in the software.
43c2eed105SBrooks Davis  *
44c2eed105SBrooks Davis  * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
45c2eed105SBrooks Davis  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
46c2eed105SBrooks Davis  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
47c2eed105SBrooks Davis  * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
48c2eed105SBrooks Davis  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
49c2eed105SBrooks Davis  * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
50c2eed105SBrooks Davis  * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
51c2eed105SBrooks Davis  * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
52c2eed105SBrooks Davis  * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
53c2eed105SBrooks Davis  * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
54c2eed105SBrooks Davis  * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
55c2eed105SBrooks Davis  * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
56c2eed105SBrooks Davis  * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
57c2eed105SBrooks Davis  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58c2eed105SBrooks Davis  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
59c2eed105SBrooks Davis  * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
60c2eed105SBrooks Davis  * OF SUCH DAMAGE.
61c2eed105SBrooks Davis  *
62c2eed105SBrooks Davis  * Author:		Brooks Davis <brooks@FreeBSD.org>
63c2eed105SBrooks Davis  * Derived from:	ng_hole.c
64c2eed105SBrooks Davis  *
65c2eed105SBrooks Davis  * $FreeBSD$
66c2eed105SBrooks Davis  */
67c2eed105SBrooks Davis 
68c2eed105SBrooks Davis /*
69c2eed105SBrooks Davis  * This node simply takes IP packets and calls ip_input on them
70c2eed105SBrooks Davis  */
71c2eed105SBrooks Davis 
72c2eed105SBrooks Davis #include <sys/param.h>
73c2eed105SBrooks Davis #include <sys/systm.h>
74c2eed105SBrooks Davis #include <sys/kernel.h>
75c2eed105SBrooks Davis #include <sys/malloc.h>
76c2eed105SBrooks Davis #include <sys/mbuf.h>
77c2eed105SBrooks Davis #include <sys/socket.h>
78c2eed105SBrooks Davis #include <net/if.h>
79c2eed105SBrooks Davis #include <net/if_types.h>
80c2eed105SBrooks Davis #include <net/if_var.h>
81c2eed105SBrooks Davis #include <netinet/in.h>
82c2eed105SBrooks Davis #include <netinet/in_var.h>
83c2eed105SBrooks Davis #include <net/netisr.h>
84c2eed105SBrooks Davis #include <netgraph/ng_message.h>
85c2eed105SBrooks Davis #include <netgraph/netgraph.h>
86c2eed105SBrooks Davis #include <netgraph/ng_ip_input.h>
87c2eed105SBrooks Davis 
88c2eed105SBrooks Davis /* Netgraph methods */
89c2eed105SBrooks Davis static ng_constructor_t	ngipi_cons;
90c2eed105SBrooks Davis static ng_rcvdata_t	ngipi_rcvdata;
91c2eed105SBrooks Davis static ng_disconnect_t	ngipi_disconnect;
92c2eed105SBrooks Davis 
93c2eed105SBrooks Davis static struct ng_type typestruct = {
94f8aae777SJulian Elischer 	.version =	NG_ABI_VERSION,
95f8aae777SJulian Elischer 	.name =		NG_IP_INPUT_NODE_TYPE,
96f8aae777SJulian Elischer 	.constructor =	ngipi_cons,
97f8aae777SJulian Elischer 	.rcvdata =	ngipi_rcvdata,
98f8aae777SJulian Elischer 	.disconnect =	ngipi_disconnect,
99c2eed105SBrooks Davis };
100c2eed105SBrooks Davis NETGRAPH_INIT(ip_input, &typestruct);
101c2eed105SBrooks Davis 
102c2eed105SBrooks Davis /*
103c2eed105SBrooks Davis  * Be obliging. but no work to do.
104c2eed105SBrooks Davis  */
105c2eed105SBrooks Davis static int
106c2eed105SBrooks Davis ngipi_cons(node_p node)
107c2eed105SBrooks Davis {
108c2eed105SBrooks Davis 	return(0);
109c2eed105SBrooks Davis }
110c2eed105SBrooks Davis 
111c2eed105SBrooks Davis /*
112c2eed105SBrooks Davis  * Receive data
113c2eed105SBrooks Davis  */
114c2eed105SBrooks Davis static int
115c2eed105SBrooks Davis ngipi_rcvdata(hook_p hook, item_p item)
116c2eed105SBrooks Davis {
117c2eed105SBrooks Davis 	struct mbuf *m;
118c2eed105SBrooks Davis 
119c2eed105SBrooks Davis 	NGI_GET_M(item, m);
120c2eed105SBrooks Davis 	NG_FREE_ITEM(item);
1211cafed39SJonathan Lemon 	netisr_dispatch(NETISR_IP, m);
122c2eed105SBrooks Davis 	return 0;
123c2eed105SBrooks Davis }
124c2eed105SBrooks Davis 
125c2eed105SBrooks Davis /*
126c2eed105SBrooks Davis  * Hook disconnection
127c2eed105SBrooks Davis  */
128c2eed105SBrooks Davis static int
129c2eed105SBrooks Davis ngipi_disconnect(hook_p hook)
130c2eed105SBrooks Davis {
131c2eed105SBrooks Davis 	if (NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
132c2eed105SBrooks Davis 		ng_rmnode_self(NG_HOOK_NODE(hook));
133c2eed105SBrooks Davis 	return (0);
134c2eed105SBrooks Davis }
135