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