/*1* ng_ip_input.c2*/34/*-5* SPDX-License-Identifier: BSD-3-Clause AND BSD-2-Clause6*7* Copyright 2001 The Aerospace Corporation. All rights reserved.8*9* Redistribution and use in source and binary forms, with or without10* modification, are permitted provided that the following conditions11* are met:12*13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions, and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions, and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18* 3. The name of The Aerospace Corporation may not be used to endorse or19* promote products derived from this software.20*21* THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "AS IS" AND22* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24* ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE25* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL26* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS27* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT29* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY30* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*33* Copyright (c) 1996-1999 Whistle Communications, Inc.34* All rights reserved.35*36* Subject to the following obligations and disclaimer of warranty, use and37* redistribution of this software, in source or object code forms, with or38* without modifications are expressly permitted by Whistle Communications;39* provided, however, that:40* 1. Any and all reproductions of the source or object code must include the41* copyright notice above and the following disclaimer of warranties; and42* 2. No rights are granted, in any manner or form, to use Whistle43* Communications, Inc. trademarks, including the mark "WHISTLE44* COMMUNICATIONS" on advertising, endorsements, or otherwise except as45* such appears in the above copyright notice or in the software.46*47* THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND48* TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO49* REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,50* INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF51* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.52* WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY53* REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS54* SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.55* IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES56* RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING57* WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,58* PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR59* SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY60* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT61* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF62* THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY63* OF SUCH DAMAGE.64*65* Author: Brooks Davis <[email protected]>66* Derived from: ng_hole.c67*/6869/*70* This node simply takes IP packets and calls ip_input on them71*/7273#include <sys/param.h>74#include <sys/systm.h>75#include <sys/kernel.h>76#include <sys/malloc.h>77#include <sys/mbuf.h>78#include <sys/socket.h>79#include <sys/proc.h>80#include <net/if.h>81#include <net/if_types.h>82#include <net/if_var.h>83#include <netinet/in.h>84#include <netinet/in_var.h>85#include <net/netisr.h>86#include <netgraph/ng_message.h>87#include <netgraph/netgraph.h>88#include <netgraph/ng_ip_input.h>8990/* Netgraph methods */91static ng_constructor_t ngipi_cons;92static ng_rcvdata_t ngipi_rcvdata;93static ng_disconnect_t ngipi_disconnect;9495static struct ng_type typestruct = {96.version = NG_ABI_VERSION,97.name = NG_IP_INPUT_NODE_TYPE,98.constructor = ngipi_cons,99.rcvdata = ngipi_rcvdata,100.disconnect = ngipi_disconnect,101};102NETGRAPH_INIT(ip_input, &typestruct);103104/*105* Be obliging. but no work to do.106*/107static int108ngipi_cons(node_p node)109{110return(0);111}112113/*114* Receive data115*/116static int117ngipi_rcvdata(hook_p hook, item_p item)118{119struct mbuf *m;120121NGI_GET_M(item, m);122NG_FREE_ITEM(item);123if (curthread->td_ng_outbound)124netisr_queue(NETISR_IP, m);125else {126struct epoch_tracker et;127128NET_EPOCH_ENTER(et);129netisr_dispatch(NETISR_IP, m);130NET_EPOCH_EXIT(et);131}132return 0;133}134135/*136* Hook disconnection137*/138static int139ngipi_disconnect(hook_p hook)140{141if (NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)142ng_rmnode_self(NG_HOOK_NODE(hook));143return (0);144}145146147