1217134Sjilles/* 2217134Sjilles * ng_echo.c 3217134Sjilles */ 4217134Sjilles 5217134Sjilles/*- 6217134Sjilles * Copyright (c) 1996-1999 Whistle Communications, Inc. 7217134Sjilles * All rights reserved. 8217134Sjilles * 9217134Sjilles * Subject to the following obligations and disclaimer of warranty, use and 10217134Sjilles * redistribution of this software, in source or object code forms, with or 11217134Sjilles * without modifications are expressly permitted by Whistle Communications; 12217134Sjilles * provided, however, that: 13217134Sjilles * 1. Any and all reproductions of the source or object code must include the 14217134Sjilles * copyright notice above and the following disclaimer of warranties; and 15217134Sjilles * 2. No rights are granted, in any manner or form, to use Whistle 16217134Sjilles * Communications, Inc. trademarks, including the mark "WHISTLE 17217134Sjilles * COMMUNICATIONS" on advertising, endorsements, or otherwise except as 18217134Sjilles * such appears in the above copyright notice or in the software. 19217134Sjilles * 20217134Sjilles * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND 21217134Sjilles * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO 22217134Sjilles * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, 23217134Sjilles * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF 24217134Sjilles * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. 25217134Sjilles * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY 26217134Sjilles * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS 27217134Sjilles * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. 28217134Sjilles * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES 29217134Sjilles * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING 30217134Sjilles * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 31217134Sjilles * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR 32217134Sjilles * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY 33217134Sjilles * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34217134Sjilles * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35217134Sjilles * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 36217134Sjilles * OF SUCH DAMAGE. 37217134Sjilles * 38217134Sjilles * Author: Julian Elisher <julian@freebsd.org> 39217134Sjilles * 40217134Sjilles * $FreeBSD: releng/10.3/sys/netgraph/ng_echo.c 145101 2005-04-15 10:14:00Z glebius $ 41217134Sjilles * $Whistle: ng_echo.c,v 1.13 1999/11/01 09:24:51 julian Exp $ 42217134Sjilles */ 43217134Sjilles 44217134Sjilles/* 45217134Sjilles * Netgraph "echo" node 46217134Sjilles * 47217134Sjilles * This node simply bounces data and messages back to whence they came. 48217134Sjilles */ 49217134Sjilles 50217134Sjilles#include <sys/param.h> 51217134Sjilles#include <sys/systm.h> 52217134Sjilles#include <sys/kernel.h> 53217134Sjilles#include <sys/malloc.h> 54217134Sjilles#include <sys/mbuf.h> 55217134Sjilles#include <netgraph/ng_message.h> 56217134Sjilles#include <netgraph/netgraph.h> 57217134Sjilles#include <netgraph/ng_echo.h> 58217134Sjilles 59217134Sjilles/* Netgraph methods */ 60217134Sjillesstatic ng_constructor_t nge_cons; 61217134Sjillesstatic ng_rcvmsg_t nge_rcvmsg; 62217134Sjillesstatic ng_rcvdata_t nge_rcvdata; 63217134Sjillesstatic ng_disconnect_t nge_disconnect; 64217134Sjilles 65217134Sjilles/* Netgraph type */ 66217134Sjillesstatic struct ng_type typestruct = { 67217134Sjilles .version = NG_ABI_VERSION, 68217134Sjilles .name = NG_ECHO_NODE_TYPE, 69217134Sjilles .constructor = nge_cons, 70217134Sjilles .rcvmsg = nge_rcvmsg, 71217134Sjilles .rcvdata = nge_rcvdata, 72217134Sjilles .disconnect = nge_disconnect, 73217134Sjilles}; 74217134SjillesNETGRAPH_INIT(echo, &typestruct); 75217134Sjilles 76217134Sjillesstatic int 77217134Sjillesnge_cons(node_p node) 78217134Sjilles{ 79217134Sjilles return (0); 80217134Sjilles} 81217134Sjilles 82217134Sjilles/* 83217134Sjilles * Receive control message. We just bounce it back as a reply. 84 */ 85static int 86nge_rcvmsg(node_p node, item_p item, hook_p lasthook) 87{ 88 struct ng_mesg *msg; 89 int error = 0; 90 91 NGI_GET_MSG(item, msg); 92 msg->header.flags |= NGF_RESP; 93 NG_RESPOND_MSG(error, node, item, msg); 94 return (error); 95} 96 97/* 98 * Receive data 99 */ 100static int 101nge_rcvdata(hook_p hook, item_p item) 102{ 103 int error; 104 105 NG_FWD_ITEM_HOOK(error, item, hook); 106 return (error); 107} 108 109/* 110 * Removal of the last link destroys the nodeo 111 */ 112static int 113nge_disconnect(hook_p hook) 114{ 115 if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0) 116 && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) { 117 ng_rmnode_self(NG_HOOK_NODE(hook)); 118 } 119 return (0); 120} 121 122