/*1* ng_echo.c2*/34/*-5* Copyright (c) 1996-1999 Whistle Communications, Inc.6* All rights reserved.7*8* Subject to the following obligations and disclaimer of warranty, use and9* redistribution of this software, in source or object code forms, with or10* without modifications are expressly permitted by Whistle Communications;11* provided, however, that:12* 1. Any and all reproductions of the source or object code must include the13* copyright notice above and the following disclaimer of warranties; and14* 2. No rights are granted, in any manner or form, to use Whistle15* Communications, Inc. trademarks, including the mark "WHISTLE16* COMMUNICATIONS" on advertising, endorsements, or otherwise except as17* such appears in the above copyright notice or in the software.18*19* THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND20* TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO21* REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,22* INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF23* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.24* WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY25* REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS26* SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.27* IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES28* RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING29* WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,30* PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR31* SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY32* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT33* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF34* THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY35* OF SUCH DAMAGE.36*37* Author: Julian Elisher <[email protected]>38* $Whistle: ng_echo.c,v 1.13 1999/11/01 09:24:51 julian Exp $39*/4041/*42* Netgraph "echo" node43*44* This node simply bounces data and messages back to whence they came.45*/4647#include <sys/param.h>48#include <sys/systm.h>49#include <sys/kernel.h>50#include <sys/malloc.h>51#include <sys/mbuf.h>52#include <netgraph/ng_message.h>53#include <netgraph/netgraph.h>54#include <netgraph/ng_echo.h>5556/* Netgraph methods */57static ng_constructor_t nge_cons;58static ng_rcvmsg_t nge_rcvmsg;59static ng_rcvdata_t nge_rcvdata;60static ng_disconnect_t nge_disconnect;6162/* Netgraph type */63static struct ng_type typestruct = {64.version = NG_ABI_VERSION,65.name = NG_ECHO_NODE_TYPE,66.constructor = nge_cons,67.rcvmsg = nge_rcvmsg,68.rcvdata = nge_rcvdata,69.disconnect = nge_disconnect,70};71NETGRAPH_INIT(echo, &typestruct);7273static int74nge_cons(node_p node)75{76return (0);77}7879/*80* Receive control message. We just bounce it back as a reply.81*/82static int83nge_rcvmsg(node_p node, item_p item, hook_p lasthook)84{85struct ng_mesg *msg;86int error = 0;8788NGI_GET_MSG(item, msg);89msg->header.flags |= NGF_RESP;90NG_RESPOND_MSG(error, node, item, msg);91return (error);92}9394/*95* Receive data96*/97static int98nge_rcvdata(hook_p hook, item_p item)99{100int error;101102NG_FWD_ITEM_HOOK(error, item, hook);103return (error);104}105106/*107* Removal of the last link destroys the nodeo108*/109static int110nge_disconnect(hook_p hook)111{112if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)113&& (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) {114ng_rmnode_self(NG_HOOK_NODE(hook));115}116return (0);117}118119120