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