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