ng_ip_input.c revision 111888
184053Sbrooks/* 284053Sbrooks * ng_ip_input.c 384053Sbrooks * 484053Sbrooks * Copyright 2001 The Aerospace Corporation. All rights reserved. 584053Sbrooks * 684053Sbrooks * Redistribution and use in source and binary forms, with or without 784053Sbrooks * modification, are permitted provided that the following conditions 884053Sbrooks * are met: 984053Sbrooks * 1084053Sbrooks * 1. Redistributions of source code must retain the above copyright 1184053Sbrooks * notice, this list of conditions, and the following disclaimer. 1284053Sbrooks * 2. Redistributions in binary form must reproduce the above copyright 1384053Sbrooks * notice, this list of conditions, and the following disclaimer in the 1484053Sbrooks * documentation and/or other materials provided with the distribution. 1584053Sbrooks * 3. The name of The Aerospace Corporation may not be used to endorse or 1684053Sbrooks * promote products derived from this software. 1784053Sbrooks * 1884053Sbrooks * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "AS IS" AND 1984053Sbrooks * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2084053Sbrooks * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2184053Sbrooks * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE 2284053Sbrooks * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2384053Sbrooks * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2484053Sbrooks * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2584053Sbrooks * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2684053Sbrooks * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2784053Sbrooks * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2884053Sbrooks * SUCH DAMAGE. 2984053Sbrooks * 3084053Sbrooks * Copyright (c) 1996-1999 Whistle Communications, Inc. 3184053Sbrooks * All rights reserved. 3284053Sbrooks * 3384053Sbrooks * Subject to the following obligations and disclaimer of warranty, use and 3484053Sbrooks * redistribution of this software, in source or object code forms, with or 3584053Sbrooks * without modifications are expressly permitted by Whistle Communications; 3684053Sbrooks * provided, however, that: 3784053Sbrooks * 1. Any and all reproductions of the source or object code must include the 3884053Sbrooks * copyright notice above and the following disclaimer of warranties; and 3984053Sbrooks * 2. No rights are granted, in any manner or form, to use Whistle 4084053Sbrooks * Communications, Inc. trademarks, including the mark "WHISTLE 4184053Sbrooks * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 4284053Sbrooks * such appears in the above copyright notice or in the software. 4384053Sbrooks * 4484053Sbrooks * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 4584053Sbrooks * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 4684053Sbrooks * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 4784053Sbrooks * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 4884053Sbrooks * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 4984053Sbrooks * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 5084053Sbrooks * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 5184053Sbrooks * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 5284053Sbrooks * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 5384053Sbrooks * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 5484053Sbrooks * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 5584053Sbrooks * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 5684053Sbrooks * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 5784053Sbrooks * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 5884053Sbrooks * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 5984053Sbrooks * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 6084053Sbrooks * OF SUCH DAMAGE. 6184053Sbrooks * 6284053Sbrooks * Author: Brooks Davis <brooks@FreeBSD.org> 6384053Sbrooks * Derived from: ng_hole.c 6484053Sbrooks * 6584053Sbrooks * $FreeBSD: head/sys/netgraph/ng_ip_input.c 111888 2003-03-04 23:19:55Z jlemon $ 6684053Sbrooks */ 6784053Sbrooks 6884053Sbrooks/* 6984053Sbrooks * This node simply takes IP packets and calls ip_input on them 7084053Sbrooks */ 7184053Sbrooks 7284053Sbrooks#include <sys/param.h> 7384053Sbrooks#include <sys/systm.h> 7484053Sbrooks#include <sys/kernel.h> 7584053Sbrooks#include <sys/malloc.h> 7684053Sbrooks#include <sys/mbuf.h> 7784053Sbrooks#include <sys/socket.h> 7884053Sbrooks#include <net/if.h> 7984053Sbrooks#include <net/if_types.h> 8084053Sbrooks#include <net/if_var.h> 8184053Sbrooks#include <netinet/in.h> 8284053Sbrooks#include <netinet/in_var.h> 8384053Sbrooks#include <net/netisr.h> 8484053Sbrooks#include <netgraph/ng_message.h> 8584053Sbrooks#include <netgraph/netgraph.h> 8684053Sbrooks#include <netgraph/ng_ip_input.h> 8784053Sbrooks 8884053Sbrooks/* Netgraph methods */ 8984053Sbrooksstatic ng_constructor_t ngipi_cons; 9084053Sbrooksstatic ng_rcvdata_t ngipi_rcvdata; 9184053Sbrooksstatic ng_disconnect_t ngipi_disconnect; 9284053Sbrooks 9384053Sbrooksstatic struct ng_type typestruct = { 9484053Sbrooks NG_ABI_VERSION, 9584053Sbrooks NG_IP_INPUT_NODE_TYPE, 9684053Sbrooks NULL, /* modeventhand_t */ 9784053Sbrooks ngipi_cons, /* ng_constructor_t */ 9884053Sbrooks NULL, /* ng_rcvmsg_t */ 9984053Sbrooks NULL, /* ng_shutdown_t */ 10084053Sbrooks NULL, /* ng_newhook_t */ 10184053Sbrooks NULL, /* ng_findhook_t */ 10284053Sbrooks NULL, /* ng_connect_t */ 10384053Sbrooks ngipi_rcvdata, /* ng_rcvdata_t */ 10484053Sbrooks ngipi_disconnect, /* ng_disconnect_t */ 10584053Sbrooks NULL /* ng_cmdlist */ 10684053Sbrooks}; 10784053SbrooksNETGRAPH_INIT(ip_input, &typestruct); 10884053Sbrooks 10984053Sbrooks/* 11084053Sbrooks * Be obliging. but no work to do. 11184053Sbrooks */ 11284053Sbrooksstatic int 11384053Sbrooksngipi_cons(node_p node) 11484053Sbrooks{ 11584053Sbrooks return(0); 11684053Sbrooks} 11784053Sbrooks 11884053Sbrooks/* 11984053Sbrooks * Receive data 12084053Sbrooks */ 12184053Sbrooksstatic int 12284053Sbrooksngipi_rcvdata(hook_p hook, item_p item) 12384053Sbrooks{ 12484053Sbrooks struct mbuf *m; 12584053Sbrooks 12684053Sbrooks NGI_GET_M(item, m); 12784053Sbrooks NG_FREE_ITEM(item); 128111888Sjlemon netisr_dispatch(NETISR_IP, m); 12984053Sbrooks return 0; 13084053Sbrooks} 13184053Sbrooks 13284053Sbrooks/* 13384053Sbrooks * Hook disconnection 13484053Sbrooks */ 13584053Sbrooksstatic int 13684053Sbrooksngipi_disconnect(hook_p hook) 13784053Sbrooks{ 13884053Sbrooks if (NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0) 13984053Sbrooks ng_rmnode_self(NG_HOOK_NODE(hook)); 14084053Sbrooks return (0); 14184053Sbrooks} 142