From: Nuno Antunes Date: Sun, 21 Jun 2009 12:58:01 +0000 (+0100) Subject: Apply netgraph7 megapatch. X-Git-Tag: v3.0.0~140 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/0147868ed7917851594b33d2d64fdac33ef85dc6 Apply netgraph7 megapatch. * Translate objcache calls. * Translate uma_zone to objcache. * Introduce libnetgraph7 (is compiled when WANT_NETGRAPH7 is defined). * Welcome ng_socket. * Convert netgraph netisr to a real taskqueue. This fixes a deadlock specific to dragonfly. * Welcome ng_async. * Welcome ng_UI. * Welcome ng_ether. * Fix mtx_assert translation. * Welcome ng_hole. * Welcome ng_cisco. * Welcome ng_iface. * Welcome ng_tee. * Welcome ng_atmllc. * Welcome ng_bpf. * Welcome ng_vjc. --- diff --git a/etc/mtree/BSD.include.dist b/etc/mtree/BSD.include.dist index d77caf068e..d98c9d37e4 100644 --- a/etc/mtree/BSD.include.dist +++ b/etc/mtree/BSD.include.dist @@ -205,6 +205,30 @@ vjc .. .. + netgraph7 + UI + .. + async + .. + atmllc + .. + bpf + .. + cisco + .. + ether + .. + hole + .. + iface + .. + socket + .. + tee + .. + vjc + .. + .. netinet .. netinet6 diff --git a/include/Makefile b/include/Makefile index 2caf19dfb3..6f2f51f9a6 100644 --- a/include/Makefile +++ b/include/Makefile @@ -44,7 +44,7 @@ LHDRS= aio.h errno.h fcntl.h linker_set.h poll.h sched.h \ # Other directories, like 'bus' and 'netproto', are created using mtree. # # XXX allow these directories to not contain header files. -LDIRS= net netbt netgraph netinet netinet6 sys vm +LDIRS= net netbt netgraph netgraph7 netinet netinet6 sys vm # Subdirectories containing header files to copy. In symlink mode # the subdirectory will be symlinked. Care must be taken to adjust @@ -82,7 +82,7 @@ LSUBDIRS= bus/cam bus/cam/scsi \ # For SHARED=symlinks, bus/cam and netproto/atm are symlinks, so cam/scsi # and netproto/atm/* are taken care of -LSYMSUBDIRS= ${LSUBDIRS:Nbus/cam/scsi:Nnetproto/atm/*:Nnet/*:Nnetgraph/*} +LSYMSUBDIRS= ${LSUBDIRS:Nbus/cam/scsi:Nnetproto/atm/*:Nnet/*:Nnetgraph/*:Nnetgraph7/*} # For obsolete headers which need to be removed RMHEADERS= machine/ansi.h sys/inttypes.h diff --git a/lib/libnetgraph7/Makefile b/lib/libnetgraph7/Makefile new file mode 100644 index 0000000000..04dfb32f7b --- /dev/null +++ b/lib/libnetgraph7/Makefile @@ -0,0 +1,31 @@ +# $FreeBSD: src/lib/libnetgraph/Makefile,v 1.4.2.2 2001/04/25 10:04:35 ru Exp $ +# $DragonFly: src/lib/libnetgraph/Makefile,v 1.5 2008/10/28 16:54:09 swildner Exp $ +# $Whistle: Makefile,v 1.4 1999/01/17 03:41:02 julian Exp $ + +LIB= netgraph +WARNS?= 3 +MAN= netgraph.3 + +SHLIB_MAJOR= 3 + +SRCS= sock.c msg.c debug.c +INCS= netgraph.h + +WARNS?= 6 + +MLINKS+= netgraph.3 NgMkSockNode.3 +MLINKS+= netgraph.3 NgNameNode.3 +MLINKS+= netgraph.3 NgSendMsg.3 +MLINKS+= netgraph.3 NgSendAsciiMsg.3 +MLINKS+= netgraph.3 NgSendReplyMsg.3 +MLINKS+= netgraph.3 NgRecvMsg.3 +MLINKS+= netgraph.3 NgAllocRecvMsg.3 +MLINKS+= netgraph.3 NgRecvAsciiMsg.3 +MLINKS+= netgraph.3 NgAllocRecvAsciiMsg.3 +MLINKS+= netgraph.3 NgSendData.3 +MLINKS+= netgraph.3 NgRecvData.3 +MLINKS+= netgraph.3 NgAllocRecvData.3 +MLINKS+= netgraph.3 NgSetDebug.3 +MLINKS+= netgraph.3 NgSetErrLog.3 + +.include diff --git a/lib/libnetgraph7/debug.c b/lib/libnetgraph7/debug.c new file mode 100644 index 0000000000..3f5ec10e9d --- /dev/null +++ b/lib/libnetgraph7/debug.c @@ -0,0 +1,357 @@ +/* + * debug.c + * + * Copyright (c) 1996-1999 Whistle Communications, Inc. + * All rights reserved. + * + * Subject to the following obligations and disclaimer of warranty, use and + * redistribution of this software, in source or object code forms, with or + * without modifications are expressly permitted by Whistle Communications; + * provided, however, that: + * 1. Any and all reproductions of the source or object code must include the + * copyright notice above and the following disclaimer of warranties; and + * 2. No rights are granted, in any manner or form, to use Whistle + * Communications, Inc. trademarks, including the mark "WHISTLE + * COMMUNICATIONS" on advertising, endorsements, or otherwise except as + * such appears in the above copyright notice or in the software. + * + * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO + * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, + * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY + * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS + * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. + * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES + * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING + * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * Author: Archie Cobbs + * + * $FreeBSD: src/lib/libnetgraph/debug.c,v 1.9 2005/10/25 20:58:30 ru Exp $ + * $DragonFly: src/lib/libnetgraph/debug.c,v 1.4 2007/06/17 20:33:14 swildner Exp $ + * $Whistle: debug.c,v 1.24 1999/01/24 01:15:33 archie Exp $ + */ + +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include "netgraph.h" +#include "internal.h" + +#include +#include +#include +#include +/* +#include +*/ +#include +/* +#include +#include +#include +*/ +#include +/* +#include +#include +*/ +#include +/* +#include +*/ +#include +/* +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +*/ +#include +/* +#include +*/ +#include +#ifdef WHISTLE +#include +#include +#include +#include +#include +#include +#endif + +/* Global debug level */ +int _gNgDebugLevel = 0; + +/* Debug printing functions */ +void (*_NgLog) (const char *fmt,...) = warn; +void (*_NgLogx) (const char *fmt,...) = warnx; + +/* Internal functions */ +static const char *NgCookie(int cookie); + +/* Known typecookie list */ +struct ng_cookie { + int cookie; + const char *type; +}; + +#define COOKIE(c) { NGM_ ## c ## _COOKIE, #c } + +/* List of known cookies */ +static const struct ng_cookie cookies[] = { + COOKIE(UI), + COOKIE(ASYNC), + COOKIE(ATMLLC), + COOKIE(BPF), +/* + COOKIE(BRIDGE), +*/ + COOKIE(CISCO), +/* + COOKIE(ECHO), + COOKIE(EIFACE), + COOKIE(ETF), +*/ + COOKIE(ETHER), +/* + COOKIE(FEC), + COOKIE(FRAMERELAY), + COOKIE(GENERIC), +*/ + COOKIE(HOLE), +/* + COOKIE(HUB), +*/ + COOKIE(IFACE), +/* + COOKIE(IP_INPUT), + COOKIE(KSOCKET), + COOKIE(L2TP), + COOKIE(LMI), + COOKIE(MPPC), + COOKIE(ONE2MANY), + COOKIE(PPP), + COOKIE(PPPOE), + COOKIE(PPTPGRE), + COOKIE(RFC1490), +*/ + COOKIE(SOCKET), +/* + COOKIE(SOURCE), + COOKIE(SPLIT), + COOKIE(TCPMSS), +*/ + COOKIE(TEE), +/* + COOKIE(TTY), +*/ + COOKIE(VJC), +#ifdef WHISTLE + COOKIE(DF), + COOKIE(IPAC), + COOKIE(TN), + COOKIE(WFRA), +#endif + { 0, NULL } +}; + +/* + * Set debug level, ie, verbosity, if "level" is non-negative. + * Returns old debug level. + */ +int +NgSetDebug(int level) +{ + int old = _gNgDebugLevel; + + if (level < 0) + level = old; + _gNgDebugLevel = level; + return (old); +} + +/* + * Set debug logging functions. + */ +void +NgSetErrLog(void (*log) (const char *fmt,...), + void (*logx) (const char *fmt,...)) +{ + _NgLog = log; + _NgLogx = logx; +} + +/* + * Display a netgraph sockaddr + */ +void +_NgDebugSockaddr(const struct sockaddr_ng *sg) +{ + NGLOGX("SOCKADDR: { fam=%d len=%d addr=\"%s\" }", + sg->sg_family, sg->sg_len, sg->sg_data); +} + +#define ARGS_BUFSIZE 2048 +#define RECURSIVE_DEBUG_ADJUST 4 + +/* + * Display a negraph message + */ +void +_NgDebugMsg(const struct ng_mesg *msg, const char *path) +{ + u_char buf[2 * sizeof(struct ng_mesg) + ARGS_BUFSIZE]; + struct ng_mesg *const req = (struct ng_mesg *)buf; + struct ng_mesg *const bin = (struct ng_mesg *)req->data; + int arglen, csock = -1; + + /* Display header stuff */ + NGLOGX("NG_MESG :"); + NGLOGX(" vers %d", msg->header.version); + NGLOGX(" arglen %d", msg->header.arglen); + NGLOGX(" flags %ld", msg->header.flags); + NGLOGX(" token %lu", (u_long)msg->header.token); + NGLOGX(" cookie %s (%d)", + NgCookie(msg->header.typecookie), msg->header.typecookie); + + /* At lower debugging levels, skip ASCII translation */ + if (_gNgDebugLevel <= 2) + goto fail2; + + /* If path is not absolute, don't bother trying to use relative + address on a different socket for the ASCII translation */ + if (strchr(path, ':') == NULL) + goto fail2; + + /* Get a temporary socket */ + if (NgMkSockNode(NULL, &csock, NULL) < 0) + goto fail; + + /* Copy binary message into request message payload */ + arglen = msg->header.arglen; + if (arglen > ARGS_BUFSIZE) + arglen = ARGS_BUFSIZE; + memcpy(bin, msg, sizeof(*msg) + arglen); + bin->header.arglen = arglen; + + /* Lower debugging to avoid infinite recursion */ + _gNgDebugLevel -= RECURSIVE_DEBUG_ADJUST; + + /* Ask the node to translate the binary message to ASCII for us */ + if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, + NGM_BINARY2ASCII, bin, sizeof(*bin) + bin->header.arglen) < 0) { + _gNgDebugLevel += RECURSIVE_DEBUG_ADJUST; + goto fail; + } + if (NgRecvMsg(csock, req, sizeof(buf), NULL) < 0) { + _gNgDebugLevel += RECURSIVE_DEBUG_ADJUST; + goto fail; + } + + /* Restore debugging level */ + _gNgDebugLevel += RECURSIVE_DEBUG_ADJUST; + + /* Display command string and arguments */ + NGLOGX(" cmd %s (%d)", bin->header.cmdstr, bin->header.cmd); + NGLOGX(" args %s", bin->data); + goto done; + +fail: + /* Just display binary version */ + NGLOGX(" [error decoding message: %s]", strerror(errno)); +fail2: + NGLOGX(" cmd %d", msg->header.cmd); + NGLOGX(" args (%d bytes)", msg->header.arglen); + _NgDebugBytes((u_char *)msg->data, msg->header.arglen); + +done: + if (csock != -1) + (void)close(csock); +} + +/* + * Return the name of the node type corresponding to the cookie + */ +static const char * +NgCookie(int cookie) +{ + int k; + + for (k = 0; cookies[k].cookie != 0; k++) { + if (cookies[k].cookie == cookie) + return cookies[k].type; + } + return "??"; +} + +/* + * Dump bytes in hex + */ +void +_NgDebugBytes(const u_char *ptr, int len) +{ + char buf[100]; + int k, count; + +#define BYPERLINE 16 + + for (count = 0; count < len; ptr += BYPERLINE, count += BYPERLINE) { + + /* Do hex */ + snprintf(buf, sizeof(buf), "%04x: ", count); + for (k = 0; k < BYPERLINE; k++, count++) + if (count < len) + snprintf(buf + strlen(buf), + sizeof(buf) - strlen(buf), "%02x ", ptr[k]); + else + snprintf(buf + strlen(buf), + sizeof(buf) - strlen(buf), " "); + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " "); + count -= BYPERLINE; + + /* Do ASCII */ + for (k = 0; k < BYPERLINE; k++, count++) + if (count < len) + snprintf(buf + strlen(buf), + sizeof(buf) - strlen(buf), + "%c", isprint(ptr[k]) ? ptr[k] : '.'); + else + snprintf(buf + strlen(buf), + sizeof(buf) - strlen(buf), " "); + count -= BYPERLINE; + + /* Print it */ + NGLOGX("%s", buf); + } +} + diff --git a/sys/netgraph7/ng_iface.h b/lib/libnetgraph7/internal.h similarity index 64% copy from sys/netgraph7/ng_iface.h copy to lib/libnetgraph7/internal.h index b064e292b3..a7bb35920b 100644 --- a/sys/netgraph7/ng_iface.h +++ b/lib/libnetgraph7/internal.h @@ -1,8 +1,7 @@ -/* - * ng_iface.h - */ -/*- +/* + * internal.h + * * Copyright (c) 1996-1999 Whistle Communications, Inc. * All rights reserved. * @@ -35,42 +34,42 @@ * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * - * Author: Archie Cobbs + * Author: Archie Cobbs * - * $FreeBSD: src/sys/netgraph/ng_iface.h,v 1.9 2005/02/13 16:36:41 archie Exp $ - * $DragonFly: src/sys/netgraph7/ng_iface.h,v 1.2 2008/06/26 23:05:35 dillon Exp $ - * $Whistle: ng_iface.h,v 1.5 1999/01/20 00:22:13 archie Exp $ + * $FreeBSD: src/lib/libnetgraph/internal.h,v 1.5 2007/05/14 14:18:41 mav Exp $ + * $DragonFly: src/lib/libnetgraph/internal.h,v 1.2 2003/06/17 04:26:50 dillon Exp $ + * $Whistle: internal.h,v 1.5 1999/01/20 00:57:22 archie Exp $ */ -#ifndef _NETGRAPH_NG_IFACE_H_ -#define _NETGRAPH_NG_IFACE_H_ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include -/* Node type name and magic cookie */ -#define NG_IFACE_NODE_TYPE "iface" -#define NGM_IFACE_COOKIE 1108312559 +/* the 'sockaddr overhead' for a netgraph address. This is everything before + * the string that constitutes the address. */ +#define NGSA_OVERHEAD (offsetof(struct sockaddr_ng, sg_data)) -/* Interface base name */ -#define NG_IFACE_IFACE_NAME "ng" +extern int _gNgDebugLevel; -/* My hook names */ -#define NG_IFACE_HOOK_INET "inet" -#define NG_IFACE_HOOK_INET6 "inet6" -#define NG_IFACE_HOOK_ATALK "atalk" /* AppleTalk phase 2 */ -#define NG_IFACE_HOOK_IPX "ipx" -#define NG_IFACE_HOOK_ATM "atm" -#define NG_IFACE_HOOK_NATM "natm" +extern void (*_NgLog)(const char *fmt, ...); +extern void (*_NgLogx)(const char *fmt, ...); -/* MTU bounds */ -#define NG_IFACE_MTU_MIN 72 -#define NG_IFACE_MTU_MAX 65535 -#define NG_IFACE_MTU_DEFAULT 1500 +#define NGLOG (*_NgLog) +#define NGLOGX (*_NgLogx) -/* Netgraph commands */ -enum { - NGM_IFACE_GET_IFNAME = 1, - NGM_IFACE_POINT2POINT, - NGM_IFACE_BROADCAST, - NGM_IFACE_GET_IFINDEX, -}; +extern void _NgDebugSockaddr(const struct sockaddr_ng *sg); +extern void _NgDebugMsg(const struct ng_mesg *msg, const char *path); +extern void _NgDebugBytes(const u_char *ptr, int size); -#endif /* _NETGRAPH_NG_IFACE_H_ */ diff --git a/lib/libnetgraph7/msg.c b/lib/libnetgraph7/msg.c new file mode 100644 index 0000000000..9d12fc1f70 --- /dev/null +++ b/lib/libnetgraph7/msg.c @@ -0,0 +1,379 @@ +/* + * msg.c + * + * Copyright (c) 1996-1999 Whistle Communications, Inc. + * All rights reserved. + * + * Subject to the following obligations and disclaimer of warranty, use and + * redistribution of this software, in source or object code forms, with or + * without modifications are expressly permitted by Whistle Communications; + * provided, however, that: + * 1. Any and all reproductions of the source or object code must include the + * copyright notice above and the following disclaimer of warranties; and + * 2. No rights are granted, in any manner or form, to use Whistle + * Communications, Inc. trademarks, including the mark "WHISTLE + * COMMUNICATIONS" on advertising, endorsements, or otherwise except as + * such appears in the above copyright notice or in the software. + * + * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO + * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, + * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY + * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS + * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. + * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES + * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING + * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * Author: Archie Cobbs + * + * $FreeBSD: src/lib/libnetgraph/msg.c,v 1.14 2007/05/14 14:18:41 mav Exp $ + * $DragonFly: src/lib/libnetgraph/msg.c,v 1.4 2007/06/03 23:41:25 swildner Exp $ + * $Whistle: msg.c,v 1.9 1999/01/20 00:57:23 archie Exp $ + */ + +#include +#include +#include +#include +#include + +#include "netgraph.h" +#include "internal.h" + +/* Next message token value */ +static int gMsgId; + +/* For delivering both messages and replies */ +static int NgDeliverMsg(int cs, const char *path, + const struct ng_mesg *hdr, const void *args, size_t arglen); + +/* + * Send a message to a node using control socket node "cs". + * Returns -1 if error and sets errno appropriately. + * If successful, returns the message ID (token) used. + */ +int +NgSendMsg(int cs, const char *path, + int cookie, int cmd, const void *args, size_t arglen) +{ + struct ng_mesg msg; + + /* Prepare message header */ + memset(&msg, 0, sizeof(msg)); + msg.header.version = NG_VERSION; + msg.header.typecookie = cookie; + if (++gMsgId < 0) + gMsgId = 1; + msg.header.token = gMsgId; + msg.header.flags = NGF_ORIG; + msg.header.cmd = cmd; + snprintf((char *)msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd); + + /* Deliver message */ + if (NgDeliverMsg(cs, path, &msg, args, arglen) < 0) + return (-1); + return (msg.header.token); +} + +/* + * Send a message given in ASCII format. We first ask the node to translate + * the command into binary, and then we send the binary. + */ +int +NgSendAsciiMsg(int cs, const char *path, const char *fmt, ...) +{ + struct ng_mesg *reply, *binary, *ascii; + char *buf, *cmd, *args; + va_list fmtargs; + int token; + + /* Parse out command and arguments */ + va_start(fmtargs, fmt); + vasprintf(&buf, fmt, fmtargs); + va_end(fmtargs); + if (buf == NULL) + return (-1); + + /* Parse out command, arguments */ + for (cmd = buf; isspace(*cmd); cmd++) + ; + for (args = cmd; *args != '\0' && !isspace(*args); args++) + ; + if (*args != '\0') { + while (isspace(*args)) + *args++ = '\0'; + } + + /* Get a bigger buffer to hold inner message header plus arg string */ + if ((ascii = malloc(sizeof(struct ng_mesg) + + strlen(args) + 1)) == NULL) { + free(buf); + return (-1); + } + memset(ascii, 0, sizeof(*ascii)); + + /* Build inner header (only need cmdstr, arglen, and data fields) */ + strncpy((char *)ascii->header.cmdstr, cmd, + sizeof(ascii->header.cmdstr) - 1); + strcpy(ascii->data, args); + ascii->header.arglen = strlen(ascii->data) + 1; + free(buf); + + /* Send node a request to convert ASCII to binary */ + if (NgSendMsg(cs, path, NGM_GENERIC_COOKIE, NGM_ASCII2BINARY, + (u_char *)ascii, sizeof(*ascii) + ascii->header.arglen) < 0) { + free(ascii); + return (-1); + } + free(ascii); + + /* Get reply */ + if (NgAllocRecvMsg(cs, &reply, NULL) < 0) + return (-1); + + /* Now send binary version */ + binary = (struct ng_mesg *)reply->data; + if (++gMsgId < 0) + gMsgId = 1; + binary->header.token = gMsgId; + binary->header.version = NG_VERSION; + if (NgDeliverMsg(cs, + path, binary, binary->data, binary->header.arglen) < 0) { + free(reply); + return (-1); + } + token = binary->header.token; + free(reply); + return (token); +} + +/* + * Send a message that is a reply to a previously received message. + * Returns -1 and sets errno on error, otherwise returns zero. + */ +int +NgSendReplyMsg(int cs, const char *path, + const struct ng_mesg *msg, const void *args, size_t arglen) +{ + struct ng_mesg rep; + + /* Prepare message header */ + rep = *msg; + rep.header.flags = NGF_RESP; + + /* Deliver message */ + return (NgDeliverMsg(cs, path, &rep, args, arglen)); +} + +/* + * Send a message to a node using control socket node "cs". + * Returns -1 if error and sets errno appropriately, otherwise zero. + */ +static int +NgDeliverMsg(int cs, const char *path, + const struct ng_mesg *hdr, const void *args, size_t arglen) +{ + u_char sgbuf[NG_PATHSIZ + NGSA_OVERHEAD]; + struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf; + u_char *buf = NULL; + struct ng_mesg *msg; + int errnosv = 0; + int rtn = 0; + + /* Sanity check */ + if (args == NULL) + arglen = 0; + + /* Get buffer */ + if ((buf = malloc(sizeof(*msg) + arglen)) == NULL) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("malloc"); + rtn = -1; + goto done; + } + msg = (struct ng_mesg *) buf; + + /* Finalize message */ + *msg = *hdr; + msg->header.arglen = arglen; + memcpy(msg->data, args, arglen); + + /* Prepare socket address */ + sg->sg_family = AF_NETGRAPH; + /* XXX handle overflow */ + strlcpy(sg->sg_data, path, NG_PATHSIZ); + sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD; + + /* Debugging */ + if (_gNgDebugLevel >= 2) { + NGLOGX("SENDING %s:", + (msg->header.flags & NGF_RESP) ? "RESPONSE" : "MESSAGE"); + _NgDebugSockaddr(sg); + _NgDebugMsg(msg, sg->sg_data); + } + + /* Send it */ + if (sendto(cs, msg, sizeof(*msg) + arglen, + 0, (struct sockaddr *) sg, sg->sg_len) < 0) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("sendto(%s)", sg->sg_data); + rtn = -1; + goto done; + } + + /* Wait for reply if there should be one. */ + if (msg->header.cmd & NGM_HASREPLY) { + struct pollfd rfds; + int n; + + rfds.fd = cs; + rfds.events = POLLIN; + rfds.revents = 0; + n = poll(&rfds, 1, INFTIM); + if (n == -1) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("poll"); + rtn = -1; + } + } + +done: + /* Done */ + free(buf); /* OK if buf is NULL */ + errno = errnosv; + return (rtn); +} + +/* + * Receive a control message. + * + * On error, this returns -1 and sets errno. + * Otherwise, it returns the length of the received reply. + */ +int +NgRecvMsg(int cs, struct ng_mesg *rep, size_t replen, char *path) +{ + u_char sgbuf[NG_PATHSIZ + NGSA_OVERHEAD]; + struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf; + socklen_t sglen = sizeof(sgbuf); + int len, errnosv; + + /* Read reply */ + len = recvfrom(cs, rep, replen, 0, (struct sockaddr *) sg, &sglen); + if (len < 0) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("recvfrom"); + goto errout; + } + if (path != NULL) + strlcpy(path, sg->sg_data, NG_PATHSIZ); + + /* Debugging */ + if (_gNgDebugLevel >= 2) { + NGLOGX("RECEIVED %s:", + (rep->header.flags & NGF_RESP) ? "RESPONSE" : "MESSAGE"); + _NgDebugSockaddr(sg); + _NgDebugMsg(rep, sg->sg_data); + } + + /* Done */ + return (len); + +errout: + errno = errnosv; + return (-1); +} + +/* + * Identical to NgRecvMsg() except buffer is dynamically allocated. + */ +int +NgAllocRecvMsg(int cs, struct ng_mesg **rep, char *path) +{ + int len; + socklen_t optlen; + + optlen = sizeof(len); + if (getsockopt(cs, SOL_SOCKET, SO_RCVBUF, &len, &optlen) == -1 || + (*rep = malloc(len)) == NULL) + return (-1); + if ((len = NgRecvMsg(cs, *rep, len, path)) < 0) + free(*rep); + return (len); +} + +/* + * Receive a control message and convert the arguments to ASCII + */ +int +NgRecvAsciiMsg(int cs, struct ng_mesg *reply, size_t replen, char *path) +{ + struct ng_mesg *msg, *ascii; + int bufSize, errnosv; + u_char *buf; + + /* Allocate buffer */ + bufSize = 2 * sizeof(*reply) + replen; + if ((buf = malloc(bufSize)) == NULL) + return (-1); + msg = (struct ng_mesg *)buf; + ascii = (struct ng_mesg *)msg->data; + + /* Get binary message */ + if (NgRecvMsg(cs, msg, bufSize, path) < 0) + goto fail; + memcpy(reply, msg, sizeof(*msg)); + + /* Ask originating node to convert the arguments to ASCII */ + if (NgSendMsg(cs, path, NGM_GENERIC_COOKIE, + NGM_BINARY2ASCII, msg, sizeof(*msg) + msg->header.arglen) < 0) + goto fail; + if (NgRecvMsg(cs, msg, bufSize, NULL) < 0) + goto fail; + + /* Copy result to client buffer */ + if (sizeof(*ascii) + ascii->header.arglen > replen) { + errno = ERANGE; +fail: + errnosv = errno; + free(buf); + errno = errnosv; + return (-1); + } + strncpy(reply->data, ascii->data, ascii->header.arglen); + + /* Done */ + free(buf); + return (0); +} + +/* + * Identical to NgRecvAsciiMsg() except buffer is dynamically allocated. + */ +int +NgAllocRecvAsciiMsg(int cs, struct ng_mesg **reply, char *path) +{ + int len; + socklen_t optlen; + + optlen = sizeof(len); + if (getsockopt(cs, SOL_SOCKET, SO_RCVBUF, &len, &optlen) == -1 || + (*reply = malloc(len)) == NULL) + return (-1); + if ((len = NgRecvAsciiMsg(cs, *reply, len, path)) < 0) + free(*reply); + return (len); +} diff --git a/lib/libnetgraph7/netgraph.3 b/lib/libnetgraph7/netgraph.3 new file mode 100644 index 0000000000..364e759d20 --- /dev/null +++ b/lib/libnetgraph7/netgraph.3 @@ -0,0 +1,399 @@ +.\" Copyright (c) 1996-1999 Whistle Communications, Inc. +.\" All rights reserved. +.\" +.\" Subject to the following obligations and disclaimer of warranty, use and +.\" redistribution of this software, in source or object code forms, with or +.\" without modifications are expressly permitted by Whistle Communications; +.\" provided, however, that: +.\" 1. Any and all reproductions of the source or object code must include the +.\" copyright notice above and the following disclaimer of warranties; and +.\" 2. No rights are granted, in any manner or form, to use Whistle +.\" Communications, Inc. trademarks, including the mark "WHISTLE +.\" COMMUNICATIONS" on advertising, endorsements, or otherwise except as +.\" such appears in the above copyright notice or in the software. +.\" +.\" THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND +.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO +.\" REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, +.\" INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. +.\" WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY +.\" REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS +.\" SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. +.\" IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES +.\" RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING +.\" WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +.\" PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR +.\" SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY +.\" OF SUCH DAMAGE. +.\" +.\" Author: Archie Cobbs +.\" +.\" $FreeBSD: src/lib/libnetgraph/netgraph.3,v 1.4.2.10 2002/12/29 16:35:36 schweikh Exp $ +.\" $DragonFly: src/lib/libnetgraph/netgraph.3,v 1.5 2007/06/03 23:41:25 swildner Exp $ +.\" $Whistle: netgraph.3,v 1.7 1999/01/25 07:14:06 archie Exp $ +.\" +.Dd January 27, 2004 +.Dt NETGRAPH 3 +.Os +.Sh NAME +.Nm NgMkSockNode , +.Nm NgNameNode , +.Nm NgSendMsg , +.Nm NgSendAsciiMsg , +.Nm NgSendReplyMsg , +.Nm NgRecvMsg , +.Nm NgAllocRecvMsg , +.Nm NgRecvAsciiMsg , +.Nm NgAllocRecvAsciiMsg , +.Nm NgSendData , +.Nm NgRecvData , +.Nm NgAllocRecvData , +.Nm NgSetDebug , +.Nm NgSetErrLog +.Nd netgraph user library +.Sh LIBRARY +.Lb libnetgraph +.Sh SYNOPSIS +.In netgraph.h +.Ft int +.Fn NgMkSockNode "const char *name" "int *csp" "int *dsp" +.Ft int +.Fn NgNameNode "int cs" "const char *path" "const char *fmt" ... +.Ft int +.Fo NgSendMsg +.Fa "int cs" "const char *path" "int cookie" "int cmd" "const void *arg" +.Fa "size_t arglen" +.Fc +.Ft int +.Fn NgSendAsciiMsg "int cs" "const char *path" "const char *fmt" ... +.Ft int +.Fo NgSendReplyMsg +.Fa "int cs" "const char *path" "struct ng_mesg *msg" "const void *arg" +.Fa "size_t arglen" +.Fc +.Ft int +.Fn NgRecvMsg "int cs" "struct ng_mesg *rep" "size_t replen" "char *path" +.Ft int +.Fn NgAllocRecvMsg "int cs" "struct ng_mesg **rep" "char *path" +.Ft int +.Fn NgRecvAsciiMsg "int cs" "struct ng_mesg *rep" "size_t replen" "char *path" +.Ft int +.Fn NgAllocRecvAsciiMsg "int cs" "struct ng_mesg **rep" "char *path" +.Ft int +.Fn NgSendData "int ds" "const char *hook" "const u_char *buf" "size_t len" +.Ft int +.Fn NgRecvData "int ds" "u_char *buf" "size_t len" "char *hook" +.Ft int +.Fn NgAllocRecvData "int ds" "u_char **buf" "char *hook" +.Ft int +.Fn NgSetDebug "int level" +.Ft void +.Fo NgSetErrLog +.Fa "void \*[lp]*log\*[rp]\*[lp]const char *fmt, ...\*[rp]" +.Fa "void \*[lp]*logx\*[rp]\*[lp]const char *fmt, ...\*[rp]" +.Fc +.Sh DESCRIPTION +These functions facilitate user-mode program participation in the kernel +.Xr netgraph 4 +graph-based networking system, by utilizing the netgraph +.Vt socket +node type (see +.Xr ng_socket 4 ) . +.Pp +The +.Fn NgMkSockNode +function should be called first, to create a new +.Vt socket +type netgraph node with associated control and data sockets. +If +.Fa name +is +.No non- Ns Dv NULL , +the node will have that global name assigned to it. +The +.Fa csp +and +.Fa dsp +arguments will be set to the newly opened control and data sockets +associated with the node; either +.Fa csp +or +.Fa dsp +may be +.Dv NULL +if only one socket is desired. +The +.Fn NgMkSockNode +function loads the +.Vt socket +node type KLD if it is not already loaded. +.Pp +The +.Fn NgNameNode +function assigns a global name to the node addressed by +.Fa path . +.Pp +The +.Fn NgSendMsg +function sends a binary control message from the +.Vt socket +node associated with control socket +.Fa cs +to the node addressed by +.Fa path . +The +.Fa cookie +indicates how to interpret +.Fa cmd , +which indicates a specific command. +Extra argument data (if any) is specified by +.Fa arg +and +.Fa arglen . +The +.Fa cookie , cmd , +and argument data are defined by the header file corresponding +to the type of the node being addressed. +The unique, non-negative token value chosen for use in the message +header is returned. +This value is typically used to associate replies. +.Pp +Use +.Fn NgSendReplyMsg +to send reply to a previously received control message. +The original message header should be pointed to by +.Fa msg . +.Pp +The +.Fn NgSendAsciiMsg +function performs the same function as +.Fn NgSendMsg , +but adds support for +.Tn ASCII +encoding of control messages. +The +.Fn NgSendAsciiMsg +function formats its input a la +.Xr printf 3 +and then sends the resulting +.Tn ASCII +string to the node in a +.Dv NGM_ASCII2BINARY +control message. +The node returns a binary version of the +message, which is then sent back to the node just as with +.Fn NgSendMsg . +As with +.Fn NgSendMsg , +the message token value is returned. +Note that +.Tn ASCII +conversion may not be supported by all node types. +.Pp +The +.Fn NgRecvMsg +function reads the next control message received by the node associated with +control socket +.Fa cs . +The message and any extra argument data must fit in +.Fa replen +bytes. +If +.Fa path +is +.No non- Ns Dv NULL , +it must point to a buffer of at least +.Dv NG_PATHSIZ +bytes, which will be filled in (and +.Dv NUL +terminated) with the path to +the node from which the message was received. +.Pp +The length of the control message is returned. +A return value of zero indicates that the socket was closed. +.Pp +The +.Fn NgAllocRecvMsg +function works exactly like +.Fn NgRecvMsg , +except that the buffer for a message is dynamically allocated +to guarantee that a message is not truncated. +The size of the buffer is equal to the socket's receive buffer size. +The caller is responsible for freeing the buffer when it is no longer required. +.Pp +The +.Fn NgRecvAsciiMsg +function works exactly like +.Fn NgRecvMsg , +except that after the message is received, any binary arguments +are converted to +.Tn ASCII +by sending a +.Dv NGM_BINARY2ASCII +request back to the originating node. +The result is the same as +.Fn NgRecvMsg , +with the exception that the reply arguments field will contain a +.Dv NUL Ns -terminated +.Tn ASCII +version of the arguments (and the reply +header argument length field will be adjusted). +.Pp +The +.Fn NgAllocRecvAsciiMsg +function works exactly like +.Fn NgRecvAsciiMsg , +except that the buffer for a message is dynamically allocated +to guarantee that a message is not truncated. +The size of the buffer is equal to the socket's receive buffer size. +The caller is responsible for freeing the buffer when it is no longer required. +.Pp +The +.Fn NgSendData +function writes a data packet out on the specified hook of the node +corresponding to data socket +.Fa ds . +The node must already be connected to some other node via that hook. +.Pp +The +.Fn NgRecvData +function reads the next data packet (of up to +.Fa len +bytes) received by the node corresponding to data socket +.Fa ds +and stores it in +.Fa buf , +which must be large enough to hold the entire packet. +If +.Fa hook +is +.No non- Ns Dv NULL , +it must point to a buffer of at least +.Dv NG_HOOKSIZ +bytes, which will be filled in (and +.Dv NUL +terminated) with the name of +the hook on which the data was received. +.Pp +The length of the packet is returned. +A return value of zero indicates that the socket was closed. +.Pp +The +.Fn NgAllocRecvData +function works exactly like +.Fn NgRecvData , +except that the buffer for a data packet is dynamically allocated +to guarantee that a data packet is not truncated. +The size of the buffer is equal to the socket's receive buffer size. +The caller is responsible for freeing the buffer when it is no longer required. +.Pp +The +.Fn NgSetDebug +and +.Fn NgSetErrLog +functions are used for debugging. +The +.Fn NgSetDebug +function sets the debug level (if non-negative), and returns the old setting. +Higher debug levels result in more verbosity. +The default is zero. +All debug and error messages are logged via the functions +specified in the most recent call to +.Fn NgSetErrLog . +The default logging functions are +.Xr vwarn 3 +and +.Xr vwarnx 3 . +.Pp +At debug level 3, the library attempts to display control message arguments +in +.Tn ASCII +format; however, this results in additional messages being +sent which may interfere with debugging. +At even higher levels, +even these additional messages will be displayed, etc. +.Pp +Note that +.Xr select 2 +can be used on the data and the control sockets to detect the presence of +incoming data and control messages, respectively. +Data and control packets are always written and read atomically, i.e., +in one whole piece. +.Pp +User mode programs must be linked with the +.Fl l Ns Li netgraph +flag to link in this library. +.Sh INITIALIZATION +To enable netgraph in your kernel, either your kernel must be +compiled with +.Cd "options NETGRAPH" +in the kernel configuration +file, or else the +.Xr netgraph 4 +and +.Xr ng_socket 4 +KLD modules must have been loaded via +.Xr kldload 8 . +.Sh RETURN VALUES +The +.Fn NgSetDebug +function returns the previous debug setting. +.Pp +The +.Fn NgSetErrLog +function has no return value. +.Pp +All other functions return \-1 if there was an error and set +.Va errno +accordingly. +.Pp +A return value of zero from +.Fn NgRecvMsg +or +.Fn NgRecvData +indicates that the netgraph socket has been closed. +.Pp +For +.Fn NgSendAsciiMsg +and +.Fn NgRecvAsciiMsg , +the following additional errors are possible: +.Bl -tag -width Er +.It Bq Er ENOSYS +The node type does not know how to encode or decode the control message. +.It Bq Er ERANGE +The encoded or decoded arguments were too long for the supplied buffer. +.It Bq Er ENOENT +An unknown structure field was seen in an +.Tn ASCII +control message. +.It Bq Er EALREADY +The same structure field was specified twice in an +.Tn ASCII +control message. +.It Bq Er EINVAL +.Tn ASCII +control message parse error or illegal value. +.It Bq Er E2BIG +ASCII control message array or fixed width string buffer overflow. +.El +.Sh SEE ALSO +.Xr select 2 , +.Xr socket 2 , +.Xr warnx 3 , +.Xr kld 4 , +.Xr netgraph 4 , +.Xr ng_socket 4 +.Sh HISTORY +The +.Nm netgraph +system was designed and first implemented at Whistle Communications, Inc.\& in +a version of +.Fx 2.2 +customized for the Whistle InterJet. +.Sh AUTHORS +.An "Archie Cobbs" Aq archie@FreeBSD.org diff --git a/sys/netgraph7/ng_socketvar.h b/lib/libnetgraph7/netgraph.h similarity index 61% copy from sys/netgraph7/ng_socketvar.h copy to lib/libnetgraph7/netgraph.h index d886432f9c..aa3f0b7710 100644 --- a/sys/netgraph7/ng_socketvar.h +++ b/lib/libnetgraph7/netgraph.h @@ -1,8 +1,7 @@ + /* * netgraph.h - */ - -/*- + * * Copyright (c) 1996-1999 Whistle Communications, Inc. * All rights reserved. * @@ -35,35 +34,37 @@ * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * - * Author: Julian Elischer + * Author: Archie Cobbs * - * $FreeBSD: src/sys/netgraph/ng_socketvar.h,v 1.10 2005/07/05 17:35:20 glebius Exp $ - * $DragonFly: src/sys/netgraph7/ng_socketvar.h,v 1.2 2008/06/26 23:05:35 dillon Exp $ - * $Whistle: ng_socketvar.h,v 1.1 1999/01/20 21:35:39 archie Exp $ + * $FreeBSD: src/lib/libnetgraph/netgraph.h,v 1.4 2004/01/27 20:25:14 ru Exp $ + * $DragonFly: src/lib/libnetgraph/netgraph.h,v 1.2 2003/06/17 04:26:50 dillon Exp $ + * $Whistle: netgraph.h,v 1.7 1999/01/20 00:57:23 archie Exp $ */ -#ifndef _NETGRAPH_NG_SOCKETVAR_H_ -#define _NETGRAPH_NG_SOCKETVAR_H_ +#ifndef _NETGRAPH_H_ +#define _NETGRAPH_H_ -/* Netgraph protocol control block for each socket */ -struct ngpcb { - struct socket *ng_socket; /* the socket */ - struct ngsock *sockdata; /* netgraph info */ - LIST_ENTRY(ngpcb) socks; /* linked list of sockets */ - int type; /* NG_CONTROL or NG_DATA */ -}; +#include +#include -/* Per-node private data */ -struct ngsock { - struct ng_node *node; /* the associated netgraph node */ - struct ngpcb *datasock; /* optional data socket */ - struct ngpcb *ctlsock; /* optional control socket */ - int flags; - int refs; - struct mtx mtx; /* mtx to wait on */ - int error; /* place to store error */ -}; -#define NGS_FLAG_NOLINGER 1 /* close with last hook */ +__BEGIN_DECLS +int NgMkSockNode(const char *, int *, int *); +int NgNameNode(int, const char *, const char *, ...) __printflike(3, 4); +int NgSendMsg(int, const char *, int, int, const void *, size_t); +int NgSendAsciiMsg(int, const char *, const char *, ...) __printflike(3, 4); +int NgSendReplyMsg(int, const char *, + const struct ng_mesg *, const void *, size_t); +int NgRecvMsg(int, struct ng_mesg *, size_t, char *); +int NgAllocRecvMsg(int, struct ng_mesg **, char *); +int NgRecvAsciiMsg(int, struct ng_mesg *, size_t, char *); +int NgAllocRecvAsciiMsg(int, struct ng_mesg **, char *); +int NgSendData(int, const char *, const u_char *, size_t); +int NgRecvData(int, u_char *, size_t, char *); +int NgAllocRecvData(int, u_char **, char *); +int NgSetDebug(int); +void NgSetErrLog(void (*)(const char *fmt, ...), + void (*)(const char *fmt, ...)); +__END_DECLS -#endif /* _NETGRAPH_NG_SOCKETVAR_H_ */ +#endif diff --git a/lib/libnetgraph7/sock.c b/lib/libnetgraph7/sock.c new file mode 100644 index 0000000000..318a469e70 --- /dev/null +++ b/lib/libnetgraph7/sock.c @@ -0,0 +1,300 @@ +/* + * sock.c + * + * Copyright (c) 1996-1999 Whistle Communications, Inc. + * All rights reserved. + * + * Subject to the following obligations and disclaimer of warranty, use and + * redistribution of this software, in source or object code forms, with or + * without modifications are expressly permitted by Whistle Communications; + * provided, however, that: + * 1. Any and all reproductions of the source or object code must include the + * copyright notice above and the following disclaimer of warranties; and + * 2. No rights are granted, in any manner or form, to use Whistle + * Communications, Inc. trademarks, including the mark "WHISTLE + * COMMUNICATIONS" on advertising, endorsements, or otherwise except as + * such appears in the above copyright notice or in the software. + * + * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND + * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO + * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, + * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. + * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY + * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS + * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE. + * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES + * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING + * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * Author: Archie Cobbs + * + * $FreeBSD: src/lib/libnetgraph/sock.c,v 1.9 2006/10/17 16:56:29 glebius Exp $ + * $DragonFly: src/lib/libnetgraph/sock.c,v 1.5 2007/06/03 23:41:25 swildner Exp $ + * $Whistle: sock.c,v 1.12 1999/01/20 00:57:23 archie Exp $ + */ + +#include +#include +#include +#include +#include + +#include "netgraph.h" +#include "internal.h" + +/* The socket node type KLD */ +#define NG_SOCKET_KLD "ng_socket.ko" + +/* + * Create a socket type node and give it the supplied name. + * Return data and control sockets corresponding to the node. + * Returns -1 if error and sets errno. + */ +int +NgMkSockNode(const char *name, int *csp, int *dsp) +{ + char namebuf[NG_NODESIZ]; + int cs = -1; /* control socket */ + int ds = -1; /* data socket */ + int errnosv; + + /* Empty name means no name */ + if (name && *name == 0) + name = NULL; + + /* Create control socket; this also creates the netgraph node. + If we get an EPROTONOSUPPORT then the socket node type is + not loaded, so load it and try again. */ + if ((cs = socket(AF_NETGRAPH, SOCK_DGRAM, NG_CONTROL)) < 0) { + if (errno == EPROTONOSUPPORT) { + if (kldload(NG_SOCKET_KLD) < 0) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("can't load %s", NG_SOCKET_KLD); + goto errout; + } + cs = socket(AF_NETGRAPH, SOCK_DGRAM, NG_CONTROL); + if (cs >= 0) + goto gotNode; + } + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("socket"); + goto errout; + } + +gotNode: + /* Assign the node the desired name, if any */ + if (name != NULL) { + u_char sbuf[NG_NODESIZ + NGSA_OVERHEAD]; + struct sockaddr_ng *const sg = (struct sockaddr_ng *) sbuf; + + /* Assign name */ + strlcpy(sg->sg_data, name, NG_NODESIZ); + sg->sg_family = AF_NETGRAPH; + sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD; + if (bind(cs, (struct sockaddr *) sg, sg->sg_len) < 0) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("bind(%s)", sg->sg_data); + goto errout; + } + + /* Save node name */ + strlcpy(namebuf, name, sizeof(namebuf)); + } else if (dsp != NULL) { + u_char rbuf[sizeof(struct ng_mesg) + sizeof(struct nodeinfo)]; + struct ng_mesg *const resp = (struct ng_mesg *) rbuf; + struct nodeinfo *const ni = (struct nodeinfo *) resp->data; + + /* Find out the node ID */ + if (NgSendMsg(cs, ".", NGM_GENERIC_COOKIE, + NGM_NODEINFO, NULL, 0) < 0) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("send nodeinfo"); + goto errout; + } + if (NgRecvMsg(cs, resp, sizeof(rbuf), NULL) < 0) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("recv nodeinfo"); + goto errout; + } + + /* Save node "name" */ + snprintf(namebuf, sizeof(namebuf), "[%lx]", (u_long) ni->id); + } + + /* Create data socket if desired */ + if (dsp != NULL) { + u_char sbuf[NG_NODESIZ + 1 + NGSA_OVERHEAD]; + struct sockaddr_ng *const sg = (struct sockaddr_ng *) sbuf; + + /* Create data socket, initially just "floating" */ + if ((ds = socket(AF_NETGRAPH, SOCK_DGRAM, NG_DATA)) < 0) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("socket"); + goto errout; + } + + /* Associate the data socket with the node */ + snprintf(sg->sg_data, NG_NODESIZ + 1, "%s:", namebuf); + sg->sg_family = AF_NETGRAPH; + sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD; + if (connect(ds, (struct sockaddr *) sg, sg->sg_len) < 0) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("connect(%s)", sg->sg_data); + goto errout; + } + } + + /* Return the socket(s) */ + if (csp) + *csp = cs; + else + close(cs); + if (dsp) + *dsp = ds; + return (0); + +errout: + /* Failed */ + if (cs >= 0) + close(cs); + if (ds >= 0) + close(ds); + errno = errnosv; + return (-1); +} + +/* + * Assign a globally unique name to a node + * Returns -1 if error and sets errno. + */ +int +NgNameNode(int cs, const char *path, const char *fmt, ...) +{ + struct ngm_name ngn; + va_list args; + + /* Build message arg */ + va_start(args, fmt); + vsnprintf(ngn.name, sizeof(ngn.name), fmt, args); + va_end(args); + + /* Send message */ + if (NgSendMsg(cs, path, + NGM_GENERIC_COOKIE, NGM_NAME, &ngn, sizeof(ngn)) < 0) { + if (_gNgDebugLevel >= 1) + NGLOGX("%s: failed", __func__); + return (-1); + } + + /* Done */ + return (0); +} + +/* + * Read a packet from a data socket + * Returns -1 if error and sets errno. + */ +int +NgRecvData(int ds, u_char * buf, size_t len, char *hook) +{ + u_char frombuf[NG_HOOKSIZ + NGSA_OVERHEAD]; + struct sockaddr_ng *const from = (struct sockaddr_ng *) frombuf; + socklen_t fromlen = sizeof(frombuf); + int rtn, errnosv; + + /* Read packet */ + rtn = recvfrom(ds, buf, len, 0, (struct sockaddr *) from, &fromlen); + if (rtn < 0) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("recvfrom"); + errno = errnosv; + return (-1); + } + + /* Copy hook name */ + if (hook != NULL) + strlcpy(hook, from->sg_data, NG_HOOKSIZ); + + /* Debugging */ + if (_gNgDebugLevel >= 2) { + NGLOGX("READ %s from hook \"%s\" (%d bytes)", + rtn ? "PACKET" : "EOF", from->sg_data, rtn); + if (_gNgDebugLevel >= 3) + _NgDebugBytes(buf, rtn); + } + + /* Done */ + return (rtn); +} + +/* + * Identical to NgRecvData() except buffer is dynamically allocated. + */ +int +NgAllocRecvData(int ds, u_char **buf, char *hook) +{ + int len; + socklen_t optlen; + + optlen = sizeof(len); + if (getsockopt(ds, SOL_SOCKET, SO_RCVBUF, &len, &optlen) == -1 || + (*buf = malloc(len)) == NULL) + return (-1); + if ((len = NgRecvData(ds, *buf, len, hook)) < 0) + free(*buf); + return (len); +} + +/* + * Write a packet to a data socket. The packet will be sent + * out the corresponding node on the specified hook. + * Returns -1 if error and sets errno. + */ +int +NgSendData(int ds, const char *hook, const u_char * buf, size_t len) +{ + u_char sgbuf[NG_HOOKSIZ + NGSA_OVERHEAD]; + struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf; + int errnosv; + + /* Set up destination hook */ + sg->sg_family = AF_NETGRAPH; + strlcpy(sg->sg_data, hook, NG_HOOKSIZ); + sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD; + + /* Debugging */ + if (_gNgDebugLevel >= 2) { + NGLOGX("WRITE PACKET to hook \"%s\" (%d bytes)", hook, len); + _NgDebugSockaddr(sg); + if (_gNgDebugLevel >= 3) + _NgDebugBytes(buf, len); + } + + /* Send packet */ + if (sendto(ds, buf, len, 0, (struct sockaddr *) sg, sg->sg_len) < 0) { + errnosv = errno; + if (_gNgDebugLevel >= 1) + NGLOG("sendto(%s)", sg->sg_data); + errno = errnosv; + return (-1); + } + + /* Done */ + return (0); +} + diff --git a/sys/Makefile b/sys/Makefile index 06dca54f50..3c662361bb 100644 --- a/sys/Makefile +++ b/sys/Makefile @@ -12,7 +12,7 @@ SUBDIR= boot .if defined(MODULES_OVERRIDE) SUBDIR+=${MODULES_OVERRIDE} .else -SUBDIR+=bus crypto emulation dev kern net netbt netgraph netproto vfs +SUBDIR+=bus crypto emulation dev kern net netbt netgraph netgraph7 netproto vfs SUBDIR+=libiconv .endif .endif diff --git a/sys/Makefile.modules b/sys/Makefile.modules index 242fbbe63c..7871e15707 100644 --- a/sys/Makefile.modules +++ b/sys/Makefile.modules @@ -7,7 +7,7 @@ SUBDIR=${MODULES_OVERRIDE} .if ${MACHINE_PLATFORM} != "vkernel" && ${MACHINE_PLATFORM} != "vkernel64" SUBDIR=bus .endif -SUBDIR+=crypto emulation dev gnu kern net netbt netgraph netproto vfs +SUBDIR+=crypto emulation dev gnu kern net netbt netgraph netgraph7 netproto vfs SUBDIR+=libiconv .endif diff --git a/sys/conf/files b/sys/conf/files index 1919d84caa..80bc08254e 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1299,25 +1299,26 @@ netgraph7/bluetooth/socket/ng_btsocket_l2cap_raw.c optional netgraph7_bluetooth_ netgraph7/bluetooth/socket/ng_btsocket_rfcomm.c optional netgraph7_bluetooth_socket netgraph7/netflow/netflow.c optional netgraph7_netflow netgraph7/netflow/ng_netflow.c optional netgraph7_netflow -netgraph7/ng_UI.c optional netgraph7_UI -netgraph7/ng_async.c optional netgraph7_async -netgraph7/ng_atmllc.c optional netgraph7_atmllc -netgraph7/ng_base.c optional netgraph7 -netgraph7/ng_bpf.c optional netgraph7_bpf +netgraph7/dragonfly.c optional netgraph7 +netgraph7/UI/ng_UI.c optional netgraph7_UI +netgraph7/async/ng_async.c optional netgraph7_async +netgraph7/atmllc/ng_atmllc.c optional netgraph7_atmllc +netgraph7/netgraph/ng_base.c optional netgraph7 +netgraph7/bpf/ng_bpf.c optional netgraph7_bpf netgraph7/ng_bridge.c optional netgraph7_bridge netgraph7/ng_car.c optional netgraph7_car -netgraph7/ng_cisco.c optional netgraph7_cisco +netgraph7/cisco/ng_cisco.c optional netgraph7_cisco netgraph7/ng_deflate.c optional netgraph7_deflate netgraph7/ng_device.c optional netgraph7_device netgraph7/ng_echo.c optional netgraph7_echo netgraph7/ng_eiface.c optional netgraph7_eiface -netgraph7/ng_ether.c optional netgraph7_ether +netgraph7/ether/ng_ether.c optional netgraph7_ether netgraph7/ng_fec.c optional netgraph7_fec netgraph7/ng_frame_relay.c optional netgraph7_frame_relay netgraph7/ng_gif.c optional netgraph7_gif netgraph7/ng_gif_demux.c optional netgraph7_gif_demux -netgraph7/ng_hole.c optional netgraph7_hole -netgraph7/ng_iface.c optional netgraph7_iface +netgraph7/hole/ng_hole.c optional netgraph7_hole +netgraph7/iface/ng_iface.c optional netgraph7_iface netgraph7/ng_ip_input.c optional netgraph7_ip_input netgraph7/ng_ipfw.c optional netgraph7_ipfw netgraph7/ng_ksocket.c optional netgraph7_ksocket @@ -1327,20 +1328,20 @@ netgraph7/ng_mppc.c optional netgraph7_mppc_compression netgraph7/ng_mppc.c optional netgraph7_mppc_encryption netgraph7/ng_nat.c optional netgraph7_nat netgraph7/ng_one2many.c optional netgraph7_one2many -netgraph7/ng_parse.c optional netgraph7 +netgraph7/netgraph/ng_parse.c optional netgraph7 netgraph7/ng_ppp.c optional netgraph7_ppp netgraph7/ng_pppoe.c optional netgraph7_pppoe netgraph7/ng_pptpgre.c optional netgraph7_pptpgre netgraph7/ng_pred1.c optional netgraph7_pred1 netgraph7/ng_rfc1490.c optional netgraph7_rfc1490 -netgraph7/ng_socket.c optional netgraph7_socket +netgraph7/socket/ng_socket.c optional netgraph7_socket netgraph7/ng_split.c optional netgraph7_split netgraph7/ng_sppp.c optional netgraph7_sppp netgraph7/ng_tag.c optional netgraph7_tag netgraph7/ng_tcpmss.c optional netgraph7_tcpmss -netgraph7/ng_tee.c optional netgraph7_tee +netgraph7/tee/ng_tee.c optional netgraph7_tee netgraph7/ng_tty.c optional netgraph7_tty -netgraph7/ng_vjc.c optional netgraph7_vjc +netgraph7/vjc/ng_vjc.c optional netgraph7_vjc netinet/libalias/alias.c optional netgraph7_nat netinet/libalias/alias_db.c optional netgraph7_nat @@ -1356,8 +1357,8 @@ net/if_spppfr.c optional netgraph7_sppp net/if_spppsubr.c optional netgraph7_sppp net/mppcc.c optional netgraph7_mppc_compression net/mppcd.c optional netgraph7_mppc_compression -net/slcompress.c optional netgraph7_vjc -net/slcompress.c optional netgraph7_sppp +net/ppp_layer/slcompress.c optional netgraph7_vjc +net/ppp_layer/slcompress.c optional netgraph7_sppp net/zlib.c optional netgraph7_deflate # Original netgraph diff --git a/sys/net/ethernet.h b/sys/net/ethernet.h index 4aa9ea2f24..48c9a374a8 100644 --- a/sys/net/ethernet.h +++ b/sys/net/ethernet.h @@ -372,8 +372,7 @@ struct mbuf; struct mbuf_chain; extern void (*ng_ether_input_p)(struct ifnet *ifp, struct mbuf **mp); -extern void (*ng_ether_input_orphan_p)(struct ifnet *ifp, - struct mbuf *m, const struct ether_header *eh); +extern void (*ng_ether_input_orphan_p)(struct ifnet *ifp, struct mbuf *m); extern int (*ng_ether_output_p)(struct ifnet *ifp, struct mbuf **mp); extern void (*ng_ether_attach_p)(struct ifnet *ifp); extern void (*ng_ether_detach_p)(struct ifnet *ifp); diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 3a68835153..8f498e6eaf 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -101,8 +101,7 @@ int (*ef_outputp)(struct ifnet *ifp, struct mbuf **mp, struct sockaddr *dst, /* netgraph node hooks for ng_ether(4) */ void (*ng_ether_input_p)(struct ifnet *ifp, struct mbuf **mp); -void (*ng_ether_input_orphan_p)(struct ifnet *ifp, - struct mbuf *m, const struct ether_header *eh); +void (*ng_ether_input_orphan_p)(struct ifnet *ifp, struct mbuf *m); int (*ng_ether_output_p)(struct ifnet *ifp, struct mbuf **mp); void (*ng_ether_attach_p)(struct ifnet *ifp); void (*ng_ether_detach_p)(struct ifnet *ifp); @@ -1203,7 +1202,7 @@ post_stats: */ get_mplock(); if (ng_ether_input_orphan_p != NULL) { - ng_ether_input_orphan_p(ifp, m, eh); + ng_ether_input_orphan_p(ifp, m); rel_mplock(); return; } diff --git a/sys/netgraph7/Makefile b/sys/netgraph7/Makefile new file mode 100644 index 0000000000..0a6351e034 --- /dev/null +++ b/sys/netgraph7/Makefile @@ -0,0 +1,41 @@ +# $Whistle: Makefile,v 1.5 1999/01/24 06:48:37 archie Exp $ +# $FreeBSD: src/sys/modules/netgraph/Makefile,v 1.8.2.8 2002/08/20 23:48:15 archie Exp $ +# $DragonFly$ + +SUBDIR= UI \ + async \ + atmllc \ + bpf \ + cisco \ + ether \ + hole \ + iface \ + netgraph \ + socket \ + tee \ + vjc +# bridge \ +# echo \ +# eiface \ +# etf \ +# fec \ +# frame_relay \ +# ksocket \ +# l2tp \ +# lmi \ +# netgraph \ +# one2many \ +# ppp \ +# pppoe \ +# pptpgre \ +# rfc1490 \ +# socket \ +# sync_ar \ +# sync_sr \ +# tty \ + +.if !defined(NO_CRYPT) && exists(${.CURDIR}/../crypto/rc4/rc4.c) +#SUBDIR+= mppc +.endif + +.include diff --git a/sys/netgraph7/Makefile.inc b/sys/netgraph7/Makefile.inc new file mode 100644 index 0000000000..a3527b00a4 --- /dev/null +++ b/sys/netgraph7/Makefile.inc @@ -0,0 +1,8 @@ +# $FreeBSD: src/sys/modules/netgraph/Makefile.inc,v 1.1 1999/10/21 09:05:28 julian Exp $ +# $DragonFly$ +# $Whistle: Makefile.inc,v 1.4 1999/01/19 23:46:16 archie Exp $ + +# .PATH: ${.CURDIR}/../../../netgraph +CFLAGS+= -Wall + + diff --git a/sys/netgraph7/UI/Makefile b/sys/netgraph7/UI/Makefile new file mode 100644 index 0000000000..73b70bd28a --- /dev/null +++ b/sys/netgraph7/UI/Makefile @@ -0,0 +1,9 @@ +# $FreeBSD: src/sys/modules/netgraph/UI/Makefile,v 1.1.4.3 2001/12/21 09:00:47 ru Exp $ +# $DragonFly: src/sys/netgraph/UI/Makefile,v 1.2 2003/06/17 04:28:45 dillon Exp $ +# $Whistle: Makefile,v 1.2 1999/01/19 19:39:20 archie Exp $ + +KMOD= ng_UI +SRCS= ng_UI.c +KMODDEPS= netgraph + +.include diff --git a/sys/netgraph7/ng_UI.c b/sys/netgraph7/UI/ng_UI.c similarity index 99% rename from sys/netgraph7/ng_UI.c rename to sys/netgraph7/UI/ng_UI.c index e98596de7b..d996480e0d 100644 --- a/sys/netgraph7/ng_UI.c +++ b/sys/netgraph7/UI/ng_UI.c @@ -51,8 +51,8 @@ #include -#include "ng_message.h" -#include "netgraph.h" +#include +#include #include "ng_UI.h" /* diff --git a/sys/netgraph7/ng_UI.h b/sys/netgraph7/UI/ng_UI.h similarity index 100% rename from sys/netgraph7/ng_UI.h rename to sys/netgraph7/UI/ng_UI.h diff --git a/sys/netgraph7/async/Makefile b/sys/netgraph7/async/Makefile new file mode 100644 index 0000000000..2f38cd6393 --- /dev/null +++ b/sys/netgraph7/async/Makefile @@ -0,0 +1,9 @@ +# $FreeBSD: src/sys/modules/netgraph/async/Makefile,v 1.1.4.3 2001/12/21 09:00:47 ru Exp $ +# $DragonFly$ +# $Whistle: Makefile,v 1.2 1999/01/19 19:39:20 archie Exp $ + +KMOD= ng_async +SRCS= ng_async.c +KMODDEPS= netgraph + +.include diff --git a/sys/netgraph7/ng_async.c b/sys/netgraph7/async/ng_async.c similarity index 99% rename from sys/netgraph7/ng_async.c rename to sys/netgraph7/async/ng_async.c index 1bacaa3498..a07bd04091 100644 --- a/sys/netgraph7/ng_async.c +++ b/sys/netgraph7/async/ng_async.c @@ -53,12 +53,12 @@ #include #include -#include "ng_message.h" -#include "netgraph.h" +#include +#include #include "ng_async.h" -#include "ng_parse.h" +#include -#include +#include #ifdef NG_SEPARATE_MALLOC MALLOC_DEFINE(M_NETGRAPH_ASYNC, "netgraph_async", "netgraph async node "); diff --git a/sys/netgraph7/ng_async.h b/sys/netgraph7/async/ng_async.h similarity index 100% rename from sys/netgraph7/ng_async.h rename to sys/netgraph7/async/ng_async.h diff --git a/sys/netgraph7/atmllc/Makefile b/sys/netgraph7/atmllc/Makefile new file mode 100644 index 0000000000..a346142dc9 --- /dev/null +++ b/sys/netgraph7/atmllc/Makefile @@ -0,0 +1,9 @@ +# $FreeBSD: src/sys/modules/netgraph/async/Makefile,v 1.1.4.3 2001/12/21 09:00:47 ru Exp $ +# $DragonFly$ +# $Whistle: Makefile,v 1.2 1999/01/19 19:39:20 archie Exp $ + +KMOD= ng_atmllc +SRCS= ng_atmllc.c +KMODDEPS= netgraph + +.include diff --git a/sys/netgraph7/ng_atmllc.c b/sys/netgraph7/atmllc/ng_atmllc.c similarity index 97% rename from sys/netgraph7/ng_atmllc.c rename to sys/netgraph7/atmllc/ng_atmllc.c index b7ce9f8481..a1faf46e6a 100644 --- a/sys/netgraph7/ng_atmllc.c +++ b/sys/netgraph7/atmllc/ng_atmllc.c @@ -35,8 +35,8 @@ #include #include -#include "ng_message.h" -#include "netgraph.h" +#include +#include #include "ng_atmllc.h" #include @@ -183,13 +183,13 @@ ng_atmllc_rcvdata(hook_p hook, item_p item) /* Decode the LLC header. */ hdr = mtod(m, struct atmllc *); if (ATM_LLC_TYPE(hdr) == NG_ATMLLC_TYPE_ETHERNET_NOFCS) { - m->m_flags &= ~M_HASFCS; outhook = priv->ether; padding = 2; } else if (ATM_LLC_TYPE(hdr) == NG_ATMLLC_TYPE_ETHERNET_FCS) { - m->m_flags |= M_HASFCS; + m_adj(m, -ETHER_CRC_LEN); outhook = priv->ether; padding = 2; +#if 0 } else if (ATM_LLC_TYPE(hdr) == NG_ATMLLC_TYPE_FDDI_NOFCS) { m->m_flags &= ~M_HASFCS; outhook = priv->fddi; @@ -198,6 +198,7 @@ ng_atmllc_rcvdata(hook_p hook, item_p item) m->m_flags |= M_HASFCS; outhook = priv->fddi; padding = 3; +#endif } else { printf("ng_atmllc: unknown type: %x\n", ATM_LLC_TYPE(hdr)); @@ -216,11 +217,15 @@ ng_atmllc_rcvdata(hook_p hook, item_p item) hdr = mtod(m, struct atmllc *); bzero((void *)hdr, sizeof(struct atmllc) + 2); bcopy(NG_ATMLLC_HEADER, hdr->llchdr, 6); +#if 0 if ((m->m_flags & M_HASFCS) != 0) { ATM_LLC_SETTYPE(hdr, NG_ATMLLC_TYPE_ETHERNET_FCS); } else { +#endif ATM_LLC_SETTYPE(hdr, NG_ATMLLC_TYPE_ETHERNET_NOFCS); +#if 0 } +#endif outhook = priv->atm; } else if (hook == priv->fddi) { /* Add the LLC header */ @@ -233,11 +238,15 @@ ng_atmllc_rcvdata(hook_p hook, item_p item) hdr = mtod(m, struct atmllc *); bzero((void *)hdr, sizeof(struct atmllc) + 3); bcopy(NG_ATMLLC_HEADER, hdr->llchdr, 6); +#if 0 if ((m->m_flags & M_HASFCS) != 0) { ATM_LLC_SETTYPE(hdr, NG_ATMLLC_TYPE_FDDI_FCS); } else { +#endif ATM_LLC_SETTYPE(hdr, NG_ATMLLC_TYPE_FDDI_NOFCS); +#if 0 } +#endif outhook = priv->atm; } diff --git a/sys/netgraph7/ng_atmllc.h b/sys/netgraph7/atmllc/ng_atmllc.h similarity index 100% rename from sys/netgraph7/ng_atmllc.h rename to sys/netgraph7/atmllc/ng_atmllc.h diff --git a/sys/netgraph7/bpf/Makefile b/sys/netgraph7/bpf/Makefile new file mode 100644 index 0000000000..8e7128a781 --- /dev/null +++ b/sys/netgraph7/bpf/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD: src/sys/modules/netgraph/bpf/Makefile,v 1.2.4.3 2001/12/21 09:00:47 ru Exp $ +# $DragonFly: src/sys/netgraph/bpf/Makefile,v 1.3 2003/08/14 23:26:36 dillon Exp $ +# $Whistle: Makefile,v 1.1 1999/12/03 01:44:28 archie Exp $ + +KMOD= ng_bpf +SRCS= ng_bpf.c bpf_filter.c +KMODDEPS= netgraph + +.PATH: ${.CURDIR}/../../net + +.include diff --git a/sys/netgraph7/ng_bpf.c b/sys/netgraph7/bpf/ng_bpf.c similarity index 99% rename from sys/netgraph7/ng_bpf.c rename to sys/netgraph7/bpf/ng_bpf.c index 0b9b75730b..a1abc01ba0 100644 --- a/sys/netgraph7/ng_bpf.c +++ b/sys/netgraph7/bpf/ng_bpf.c @@ -55,8 +55,6 @@ * Each hook also keeps statistics about how many packets have matched, etc. */ -#include "opt_bpf.h" - #include #include #include @@ -69,9 +67,9 @@ #include #endif -#include "ng_message.h" -#include "netgraph.h" -#include "ng_parse.h" +#include +#include +#include #include "ng_bpf.h" #ifdef NG_SEPARATE_MALLOC diff --git a/sys/netgraph7/ng_bpf.h b/sys/netgraph7/bpf/ng_bpf.h similarity index 100% rename from sys/netgraph7/ng_bpf.h rename to sys/netgraph7/bpf/ng_bpf.h diff --git a/sys/netgraph7/cisco/Makefile b/sys/netgraph7/cisco/Makefile new file mode 100644 index 0000000000..82e32bdcac --- /dev/null +++ b/sys/netgraph7/cisco/Makefile @@ -0,0 +1,9 @@ +# $FreeBSD: src/sys/modules/netgraph/cisco/Makefile,v 1.2.2.4 2001/12/21 09:00:48 ru Exp $ +# $DragonFly: src/sys/netgraph/cisco/Makefile,v 1.2 2003/06/17 04:28:45 dillon Exp $ +# $Whistle: Makefile,v 1.2 1999/01/19 19:39:20 archie Exp $ + +KMOD= ng_cisco +SRCS= ng_cisco.c +KMODDEPS= netgraph + +.include diff --git a/sys/netgraph7/ng_cisco.c b/sys/netgraph7/cisco/ng_cisco.c similarity index 98% rename from sys/netgraph7/ng_cisco.c rename to sys/netgraph7/cisco/ng_cisco.c index 933504704f..78217d7785 100644 --- a/sys/netgraph7/ng_cisco.c +++ b/sys/netgraph7/cisco/ng_cisco.c @@ -55,12 +55,12 @@ #include #include -#include -#include +#include +#include -#include "ng_message.h" -#include "netgraph.h" -#include "ng_parse.h" +#include +#include +#include #include "ng_cisco.h" #define CISCO_MULTICAST 0x8f /* Cisco multicast address */ diff --git a/sys/netgraph7/ng_cisco.h b/sys/netgraph7/cisco/ng_cisco.h similarity index 100% rename from sys/netgraph7/ng_cisco.h rename to sys/netgraph7/cisco/ng_cisco.h diff --git a/sys/netgraph7/dragonfly.c b/sys/netgraph7/dragonfly.c new file mode 100644 index 0000000000..7f3e1d61b0 --- /dev/null +++ b/sys/netgraph7/dragonfly.c @@ -0,0 +1,113 @@ +#include + +#include +#include +#include +#include + +#include "dragonfly.h" + +/* Temporary lock stuff. */ +#include +/* End Temporary lock stuff. */ + +int +linker_api_available(void) +{ + /* linker_* API won't work without a process context */ + if (curproc == NULL) + return 0; + /* + * nlookup_init() relies on namei_oc to be initialized, + * but it's not when the netgraph module is loaded during boot. + */ + if (namei_oc == NULL) + return 0; + return 1; +} + +int +ng_load_module(const char *name) +{ + char *path, filename[NG_TYPESIZ + 3]; + linker_file_t lf; + int error; + + if (!linker_api_available()) + return (ENXIO); + + /* Not found, try to load it as a loadable module */ + ksnprintf(filename, sizeof(filename), "ng_%s.ko", name); + if ((path = linker_search_path(filename)) == NULL) + return (ENXIO); + error = linker_load_file(path, &lf); + FREE(path, M_LINKER); + if (error == 0) + lf->userrefs++; /* pretend kldload'ed */ + return (error); +} + +int +ng_unload_module(const char *name) +{ + char filename[NG_TYPESIZ + 3]; + linker_file_t lf; + int error; + + if (!linker_api_available()) + return (ENXIO); + + /* Not found, try to load it as a loadable module */ + ksnprintf(filename, sizeof(filename), "ng_%s.ko", name); + if ((lf = linker_find_file_by_name(filename)) == NULL) + return (ENXIO); + error = linker_file_unload(lf); + + if (error == 0) + lf->userrefs--; /* pretend kldunload'ed */ + return (error); +} + + + +/* Locking stuff. */ + + +int +lockstatus_owned(struct lock *lkp, struct thread *td) +{ + int lock_type = 0; + + if (lkp->lk_exclusivecount != 0) { + if (td == NULL || lkp->lk_lockholder == td) + lock_type = LK_EXCLUSIVE; + else + lock_type = LK_EXCLOTHER; + } else if (lkp->lk_sharecount != 0) { + lock_type = LK_SHARED; + } + return (lock_type); +} + +/* + * Atomically drop a lockmgr lock and go to sleep. The lock is reacquired + * before returning from this function. Passes on the value returned by + * tsleep(). + */ +int +lock_sleep(void *ident, int flags, const char *wmesg, int timo, + struct lock *lk) +{ + int err, mode; + + mode = lockstatus_owned(lk, curthread); + KKASSERT((mode == LK_EXCLUSIVE) || (mode == LK_SHARED)); + + crit_enter(); + tsleep_interlock(ident); + lockmgr(lk, LK_RELEASE); + err = tsleep(ident, flags, wmesg, timo); + crit_exit(); + lockmgr(lk, mode); + return err; +} diff --git a/sys/netgraph7/dragonfly.h b/sys/netgraph7/dragonfly.h index aca15dc126..9f391be3ee 100644 --- a/sys/netgraph7/dragonfly.h +++ b/sys/netgraph7/dragonfly.h @@ -37,16 +37,34 @@ #include #include +#ifndef _VA_LIST_DECLARED +#define _VA_LIST_DECLARED +typedef __va_list va_list; +#endif +#define va_start(ap,last) __va_start(ap,last) +#define va_end(ap) __va_end(ap) + +int linker_api_available(void); +int ng_load_module(const char *); +int ng_unload_module(const char *); + +/* Temporary lock stuff */ +int lock_sleep(void *, int, const char *, int, struct lock *); +int lockstatus_owned(struct lock *, struct thread *); +/* End Temporary lock stuff */ + struct mtx { struct lock lock; }; +#define MA_OWNED LK_EXCLUSIVE +#define MA_NOTOWNED 0 #define mtx_contested(mtx) 0 #define mtx_lock(mtx) lockmgr(&(mtx)->lock, LK_EXCLUSIVE|LK_RETRY) #define mtx_unlock(mtx) lockmgr(&(mtx)->lock, LK_RELEASE) -#define mtx_assert(mtx, unused) \ - (lockstatus(&(mtx)->lock, curthread) == LK_EXCLUSIVE) +#define mtx_assert(mtx, mode) \ + KKASSERT(lockstatus(&(mtx)->lock, curthread) == mode) #define mtx_init(mtx, name, something, type) \ lockinit(&(mtx)->lock, name, 0, 0) #define mtx_destroy(mtx) \ @@ -54,11 +72,36 @@ struct mtx { #define mtx_trylock(mtx) \ (lockmgr(&(mtx)->lock, LK_EXCLUSIVE|LK_NOWAIT) == 0) +#define IFNET_RLOCK() crit_enter() +#define IFNET_RUNLOCK() crit_exit() + +#define IFQ_LOCK(ifp) lwkt_serialize_enter(&(ifp)->altq_lock) +#define IFQ_UNLOCK(ifp) lwkt_serialize_exit(&(ifp)->altq_lock) + #define printf kprintf +#define sprintf ksprintf #define snprintf ksnprintf +#define vsnprintf kvsnprintf typedef struct objcache *objcache_t; #define uma_zone_t objcache_t +typedef void * uma_ctor; +typedef void * uma_dtor; +typedef void * uma_init; +typedef void * uma_fini; + +#define UMA_ALIGN_CACHE 0 + +#define uma_zcreate(name, size, ctor, dtor, uminit, fini, align, flags) \ + objcache_create_mbacked(M_NETGRAPH, size, \ + NULL, 0, \ + bzero_ctor, NULL, \ + NULL) +#define uma_zalloc(zone, flags) \ + objcache_get(zone, flags) +#define uma_zfree(zone, item) \ + objcache_put(zone, item) +#define uma_zone_set_max(zone, nitems) #define CTR1(ktr_line, ...) #define CTR2(ktr_line, ...) @@ -71,3 +114,6 @@ typedef struct objcache *objcache_t; #define splnet() 0 #define splx(v) +#define CTLFLAG_RDTUN CTLFLAG_RD + +#define SI_SUB_NETGRAPH SI_SUB_DRIVERS diff --git a/sys/netgraph7/ether/Makefile b/sys/netgraph7/ether/Makefile new file mode 100644 index 0000000000..b585e9b744 --- /dev/null +++ b/sys/netgraph7/ether/Makefile @@ -0,0 +1,8 @@ +# $FreeBSD: src/sys/modules/netgraph/ether/Makefile,v 1.1.2.1 2000/07/11 20:46:55 archie Exp $ +# $DragonFly: src/sys/netgraph/ether/Makefile,v 1.2 2003/06/17 04:28:46 dillon Exp $ + +KMOD= ng_ether +SRCS= ng_ether.c +KMODDEPS= netgraph + +.include diff --git a/sys/netgraph7/ng_ether.c b/sys/netgraph7/ether/ng_ether.c similarity index 96% rename from sys/netgraph7/ng_ether.c rename to sys/netgraph7/ether/ng_ether.c index 7640ffff3d..6ac18487a5 100644 --- a/sys/netgraph7/ng_ether.c +++ b/sys/netgraph7/ether/ng_ether.c @@ -62,14 +62,15 @@ #include #include #include -#include +#include -#include "ng_message.h" -#include "netgraph.h" -#include "ng_parse.h" +#include +#include +#include #include "ng_ether.h" -#define IFP2NG(ifp) (IFP2AC((ifp))->ac_netgraph) +#define IFP2AC(ifp) ((struct arpcom *)ifp) +#define IFP2NG(ifp) (IFP2AC((ifp))->ac_netgraph) /* Per-node private data */ struct private { @@ -84,21 +85,15 @@ struct private { }; typedef struct private *priv_p; -/* Hook pointers used by if_ethersubr.c to callback to netgraph */ -extern void (*ng_ether_input_p)(struct ifnet *ifp, struct mbuf **mp); -extern void (*ng_ether_input_orphan_p)(struct ifnet *ifp, struct mbuf *m); -extern int (*ng_ether_output_p)(struct ifnet *ifp, struct mbuf **mp); -extern void (*ng_ether_attach_p)(struct ifnet *ifp); -extern void (*ng_ether_detach_p)(struct ifnet *ifp); -extern void (*ng_ether_link_state_p)(struct ifnet *ifp, int state); - /* Functional hooks called from if_ethersubr.c */ static void ng_ether_input(struct ifnet *ifp, struct mbuf **mp); static void ng_ether_input_orphan(struct ifnet *ifp, struct mbuf *m); static int ng_ether_output(struct ifnet *ifp, struct mbuf **mp); static void ng_ether_attach(struct ifnet *ifp); static void ng_ether_detach(struct ifnet *ifp); +#if 0 static void ng_ether_link_state(struct ifnet *ifp, int state); +#endif /* Other functions */ static int ng_ether_rcv_lower(node_p node, struct mbuf *m); @@ -333,6 +328,7 @@ ng_ether_detach(struct ifnet *ifp) ng_rmnode_self(node); /* remove all netgraph parts */ } +#if 0 /* * Notify graph about link event. * if_link_state_change() has already checked that the state has changed. @@ -359,7 +355,7 @@ ng_ether_link_state(struct ifnet *ifp, int state) if (msg != NULL) NG_SEND_MSG_HOOK(dummy_error, node, msg, priv->lower, 0); } - +#endif /****************************************************************** NETGRAPH NODE METHODS ******************************************************************/ @@ -500,6 +496,7 @@ ng_ether_rcvmsg(node_p node, item_p item, hook_p lasthook) } priv->autoSrcAddr = !!*((u_int32_t *)msg->data); break; +#if 0 case NGM_ETHER_ADD_MULTI: { struct sockaddr_dl sa_dl; @@ -534,6 +531,7 @@ ng_ether_rcvmsg(node_p node, item_p item, hook_p lasthook) } break; } +#endif case NGM_ETHER_DEL_MULTI: { struct sockaddr_dl sa_dl; @@ -603,7 +601,7 @@ ng_ether_rcv_lower(node_p node, struct mbuf *m) /* Check whether interface is ready for packets */ if (!((ifp->if_flags & IFF_UP) && - (ifp->if_drv_flags & IFF_DRV_RUNNING))) { + (ifp->if_flags & IFF_RUNNING))) { NG_FREE_M(m); return (ENETDOWN); } @@ -638,11 +636,13 @@ ng_ether_rcv_lower(node_p node, struct mbuf *m) /* * Handle an mbuf received on the "upper" hook. */ +extern struct mbuf *bridge_input_p(struct ifnet *, struct mbuf *); static int ng_ether_rcv_upper(node_p node, struct mbuf *m) { const priv_p priv = NG_NODE_PRIVATE(node); struct ifnet *ifp = priv->ifp; + struct ether_header *eh; /* Check length and pull off header */ if (m->m_pkthdr.len < sizeof(struct ether_header)) { @@ -657,13 +657,14 @@ ng_ether_rcv_upper(node_p node, struct mbuf *m) /* Pass the packet to the bridge, it may come back to us */ if (ifp->if_bridge) { - BRIDGE_INPUT(ifp, m); + bridge_input_p(ifp, m); if (m == NULL) return (0); } /* Route packet back in */ - ether_demux(ifp, m); + eh = mtod(m, struct ether_header *); + ether_demux_oncpu(ifp, m); return (0); } @@ -734,9 +735,8 @@ ng_ether_mod_event(module_t mod, int event, void *data) { struct ifnet *ifp; int error = 0; - int s; - s = splnet(); + crit_enter(); switch (event) { case MOD_LOAD: @@ -750,7 +750,9 @@ ng_ether_mod_event(module_t mod, int event, void *data) ng_ether_output_p = ng_ether_output; ng_ether_input_p = ng_ether_input; ng_ether_input_orphan_p = ng_ether_input_orphan; +#if 0 ng_ether_link_state_p = ng_ether_link_state; +#endif /* Create nodes for any already-existing Ethernet interfaces */ IFNET_RLOCK(); @@ -778,14 +780,16 @@ ng_ether_mod_event(module_t mod, int event, void *data) ng_ether_output_p = NULL; ng_ether_input_p = NULL; ng_ether_input_orphan_p = NULL; +#if 0 ng_ether_link_state_p = NULL; +#endif break; default: error = EOPNOTSUPP; break; } - splx(s); + crit_exit(); return (error); } diff --git a/sys/netgraph7/ng_ether.h b/sys/netgraph7/ether/ng_ether.h similarity index 100% rename from sys/netgraph7/ng_ether.h rename to sys/netgraph7/ether/ng_ether.h diff --git a/sys/netgraph7/hole/Makefile b/sys/netgraph7/hole/Makefile new file mode 100644 index 0000000000..030e9b52b9 --- /dev/null +++ b/sys/netgraph7/hole/Makefile @@ -0,0 +1,9 @@ +# $FreeBSD: src/sys/modules/netgraph/hole/Makefile,v 1.1.4.3 2001/12/21 09:00:48 ru Exp $ +# $DragonFly: src/sys/netgraph/hole/Makefile,v 1.2 2003/06/17 04:28:46 dillon Exp $ +# $Whistle: Makefile,v 1.2 1999/01/19 19:39:21 archie Exp $ + +KMOD= ng_hole +SRCS= ng_hole.c +KMODDEPS= netgraph + +.include diff --git a/sys/netgraph7/ng_hole.c b/sys/netgraph7/hole/ng_hole.c similarity index 98% rename from sys/netgraph7/ng_hole.c rename to sys/netgraph7/hole/ng_hole.c index 9e1a84fab2..4aec79c7ba 100644 --- a/sys/netgraph7/ng_hole.c +++ b/sys/netgraph7/hole/ng_hole.c @@ -51,9 +51,9 @@ #include #include #include -#include "ng_message.h" -#include "netgraph.h" -#include "ng_parse.h" +#include +#include +#include #include "ng_hole.h" /* Per hook private info. */ diff --git a/sys/netgraph7/ng_hole.h b/sys/netgraph7/hole/ng_hole.h similarity index 100% rename from sys/netgraph7/ng_hole.h rename to sys/netgraph7/hole/ng_hole.h diff --git a/sys/netgraph7/iface/Makefile b/sys/netgraph7/iface/Makefile new file mode 100644 index 0000000000..0b7188383a --- /dev/null +++ b/sys/netgraph7/iface/Makefile @@ -0,0 +1,23 @@ +# $FreeBSD: src/sys/modules/netgraph/iface/Makefile,v 1.5.2.4 2001/12/21 09:00:48 ru Exp $ +# $DragonFly: src/sys/netgraph/iface/Makefile,v 1.4 2005/02/18 11:41:42 corecode Exp $ +# $Whistle: Makefile,v 1.2 1999/01/19 19:39:21 archie Exp $ + +KMOD= ng_iface +SRCS= ng_iface.c opt_atalk.h opt_inet.h opt_inet6.h opt_ipx.h +KMODDEPS= netgraph + +.if !defined(BUILDING_WITH_KERNEL) +opt_inet.h: + echo "#define INET 1" > opt_inet.h + +opt_inet6.h: + echo "#define INET6 1" > opt_inet6.h + +opt_atalk.h: + echo "#define NETATALK 1" > opt_atalk.h + +opt_ipx.h: + echo "#define IPX 1" > opt_ipx.h +.endif + +.include diff --git a/sys/netgraph7/ng_iface.c b/sys/netgraph7/iface/ng_iface.c similarity index 83% rename from sys/netgraph7/ng_iface.c rename to sys/netgraph7/iface/ng_iface.c index f0a41b6ad6..d6d7d21332 100644 --- a/sys/netgraph7/ng_iface.c +++ b/sys/netgraph7/iface/ng_iface.c @@ -71,16 +71,17 @@ #include #include +#include #include #include #include -#include "ng_message.h" -#include "netgraph.h" -#include "ng_parse.h" +#include +#include +#include +#include #include "ng_iface.h" -#include "ng_cisco.h" #ifdef NG_SEPARATE_MALLOC MALLOC_DEFINE(M_NETGRAPH_IFACE, "netgraph_iface", "netgraph iface node "); @@ -116,7 +117,8 @@ typedef struct ng_iface_private *priv_p; /* Interface methods */ static void ng_iface_start(struct ifnet *ifp); -static int ng_iface_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data); +static int ng_iface_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, + struct ucred *cr); static int ng_iface_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst, struct rtentry *rt0); static void ng_iface_bpftap(struct ifnet *ifp, @@ -205,7 +207,13 @@ static struct ng_type typestruct = { }; NETGRAPH_INIT(iface, &typestruct); -static struct unrhdr *ng_iface_unit; +/* We keep a bitmap indicating which unit numbers are free. + One means the unit number is free, zero means it's taken. */ +static int *ng_iface_units = NULL; +static int ng_iface_units_len = 0; + +#define UNITS_BITSPERWORD (sizeof(*ng_iface_units) * NBBY) + /************************************************************************ HELPER STUFF @@ -269,6 +277,63 @@ get_iffam_from_name(const char *name) return (NULL); } +/* + * Find the first free unit number for a new interface. + * Increase the size of the unit bitmap as necessary. + */ +static __inline__ int +ng_iface_get_unit(int *unit) +{ + int index, bit; + + for (index = 0; index < ng_iface_units_len + && ng_iface_units[index] == 0; index++); + if (index == ng_iface_units_len) { /* extend array */ + int i, *newarray, newlen; + + newlen = (2 * ng_iface_units_len) + 4; + MALLOC(newarray, int *, newlen * sizeof(*ng_iface_units), + M_NETGRAPH_IFACE, M_NOWAIT); + if (newarray == NULL) + return (ENOMEM); + bcopy(ng_iface_units, newarray, + ng_iface_units_len * sizeof(*ng_iface_units)); + for (i = ng_iface_units_len; i < newlen; i++) + newarray[i] = ~0; + if (ng_iface_units != NULL) + FREE(ng_iface_units, M_NETGRAPH_IFACE); + ng_iface_units = newarray; + ng_iface_units_len = newlen; + } + bit = ffs(ng_iface_units[index]) - 1; + KASSERT(bit >= 0 && bit <= UNITS_BITSPERWORD - 1, + ("%s: word=%d bit=%d", __func__, ng_iface_units[index], bit)); + ng_iface_units[index] &= ~(1 << bit); + *unit = (index * UNITS_BITSPERWORD) + bit; + return (0); +} + +/* + * Free a no longer needed unit number. + */ +static __inline__ void +ng_iface_free_unit(int unit) +{ + int index, bit; + + index = unit / UNITS_BITSPERWORD; + bit = unit % UNITS_BITSPERWORD; + KASSERT(index < ng_iface_units_len, + ("%s: unit=%d len=%d", __func__, unit, ng_iface_units_len)); + KASSERT((ng_iface_units[index] & (1 << bit)) == 0, + ("%s: unit=%d is free", __func__, unit)); + ng_iface_units[index] |= (1 << bit); + /* + * XXX We could think about reducing the size of ng_iface_units[] + * XXX here if the last portion is all ones + */ +} + /************************************************************************ INTERFACE STUFF ************************************************************************/ @@ -277,22 +342,23 @@ get_iffam_from_name(const char *name) * Process an ioctl for the virtual interface */ static int -ng_iface_ioctl(struct ifnet *ifp, u_long command, caddr_t data) +ng_iface_ioctl(struct ifnet *ifp, u_long command, caddr_t data, + struct ucred *cr) { struct ifreq *const ifr = (struct ifreq *) data; - int s, error = 0; + int error = 0; #ifdef DEBUG ng_iface_print_ioctl(ifp, command, data); #endif - s = splimp(); + crit_enter(); switch (command) { /* These two are mostly handled at a higher layer */ case SIOCSIFADDR: ifp->if_flags |= IFF_UP; - ifp->if_drv_flags |= IFF_DRV_RUNNING; - ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE); + ifp->if_flags |= IFF_RUNNING; + ifp->if_flags &= ~(IFF_OACTIVE); break; case SIOCGIFADDR: break; @@ -304,14 +370,13 @@ ng_iface_ioctl(struct ifnet *ifp, u_long command, caddr_t data) * If it is marked down and running, then stop it. */ if (ifr->ifr_flags & IFF_UP) { - if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { - ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE); - ifp->if_drv_flags |= IFF_DRV_RUNNING; + if (!(ifp->if_flags & IFF_RUNNING)) { + ifp->if_flags &= ~(IFF_OACTIVE); + ifp->if_flags |= IFF_RUNNING; } } else { - if (ifp->if_drv_flags & IFF_DRV_RUNNING) - ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | - IFF_DRV_OACTIVE); + if (ifp->if_flags & IFF_RUNNING) + ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE); } break; @@ -337,7 +402,7 @@ ng_iface_ioctl(struct ifnet *ifp, u_long command, caddr_t data) error = EINVAL; break; } - (void) splx(s); + crit_exit(); return (error); } @@ -355,8 +420,7 @@ ng_iface_output(struct ifnet *ifp, struct mbuf *m, int error; /* Check interface flags */ - if (!((ifp->if_flags & IFF_UP) && - (ifp->if_drv_flags & IFF_DRV_RUNNING))) { + if (!((ifp->if_flags & IFF_UP) && (ifp->if_flags & IFF_RUNNING))) { m_freem(m); return (ENETDOWN); } @@ -370,17 +434,17 @@ ng_iface_output(struct ifnet *ifp, struct mbuf *m, /* Berkeley packet filter */ ng_iface_bpftap(ifp, m, dst->sa_family); - if (ALTQ_IS_ENABLED(&ifp->if_snd)) { + if (ifq_is_enabled(&ifp->if_snd)) { M_PREPEND(m, sizeof(sa_family_t), MB_DONTWAIT); if (m == NULL) { IFQ_LOCK(&ifp->if_snd); - IFQ_INC_DROPS(&ifp->if_snd); + IF_DROP(&ifp->if_snd); IFQ_UNLOCK(&ifp->if_snd); ifp->if_oerrors++; return (ENOBUFS); } *(sa_family_t *)m->m_data = dst->sa_family; - IFQ_HANDOFF(ifp, m, error); + error = ifq_handoff(ifp, m, 0); } else error = ng_iface_send(ifp, m, dst->sa_family); @@ -396,10 +460,10 @@ ng_iface_start(struct ifnet *ifp) struct mbuf *m; sa_family_t sa; - KASSERT(ALTQ_IS_ENABLED(&ifp->if_snd), ("%s without ALTQ", __func__)); + KASSERT(ifq_is_enabled(&ifp->if_snd), ("%s without ALTQ", __func__)); for(;;) { - IFQ_DRV_DEQUEUE(&ifp->if_snd, m); + m = ifq_dequeue(&ifp->if_snd, m); if (m == NULL) break; sa = *mtod(m, sa_family_t *); @@ -415,11 +479,12 @@ ng_iface_start(struct ifnet *ifp) static void ng_iface_bpftap(struct ifnet *ifp, struct mbuf *m, sa_family_t family) { + int32_t family4 = (int32_t)family; + KASSERT(family != AF_UNSPEC, ("%s: family=AF_UNSPEC", __func__)); - if (bpf_peers_present(ifp->if_bpf)) { - int32_t family4 = (int32_t)family; - bpf_mtap2(ifp->if_bpf, &family4, sizeof(family4), m); - } + + if (ifp->if_bpf) + bpf_ptap(ifp->if_bpf, m, &family4, sizeof(family4)); } /* @@ -505,13 +570,14 @@ ng_iface_constructor(node_p node) { struct ifnet *ifp; priv_p priv; + int error; /* Allocate node and interface private structures */ priv = kmalloc(sizeof(*priv), M_NETGRAPH_IFACE, M_WAITOK | M_NULLOK | M_ZERO); if (priv == NULL) return (ENOMEM); - ifp = if_alloc(IFT_PROPVIRTUAL); + MALLOC(ifp, struct ifnet *, sizeof(*ifp), M_NETGRAPH_IFACE, M_WAITOK | M_NULLOK | M_ZERO); if (ifp == NULL) { kfree(priv, M_NETGRAPH_IFACE); return (ENOMEM); @@ -522,7 +588,12 @@ ng_iface_constructor(node_p node) priv->ifp = ifp; /* Get an interface unit number */ - priv->unit = alloc_unr(ng_iface_unit); + if ((error = ng_iface_get_unit(&priv->unit)) != 0) { + FREE(ifp, M_NETGRAPH_IFACE); + FREE(priv, M_NETGRAPH_IFACE); + return (error); + } + /* Link together node and private info */ NG_NODE_SET_PRIVATE(node, priv); @@ -540,9 +611,9 @@ ng_iface_constructor(node_p node) ifp->if_addrlen = 0; /* XXX */ ifp->if_hdrlen = 0; /* XXX */ ifp->if_baudrate = 64000; /* XXX */ - IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); - ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN; - IFQ_SET_READY(&ifp->if_snd); + ifq_set_maxlen(&ifp->if_snd, IFQ_MAXLEN); + ifp->if_snd.ifq_maxlen = IFQ_MAXLEN; + ifq_set_ready(&ifp->if_snd); /* Give this node the same name as the interface (if possible) */ if (ng_name_node(node, ifp->if_xname) != 0) @@ -550,7 +621,7 @@ ng_iface_constructor(node_p node) ifp->if_xname); /* Attach the interface */ - if_attach(ifp); + if_attach(ifp, NULL); bpfattach(ifp, DLT_NULL, sizeof(u_int32_t)); /* Done */ @@ -641,10 +712,11 @@ ng_iface_rcvmsg(node_p node, item_p item, hook_p lasthook) switch (msg->header.cmd) { case NGM_CISCO_GET_IPADDR: /* we understand this too */ { - struct ifaddr *ifa; + struct ifaddr_container *ifac; /* Return the first configured IP address */ - TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { + TAILQ_FOREACH(ifac, &ifp->if_addrheads[mycpuid], ifa_link) { + struct ifaddr *ifa = ifac->ifa; struct ng_cisco_ipaddr *ips; if (ifa->ifa_addr->sa_family != AF_INET) @@ -663,7 +735,7 @@ ng_iface_rcvmsg(node_p node, item_p item, hook_p lasthook) } /* No IP addresses on this interface? */ - if (ifa == NULL) + if (ifac == NULL) error = EADDRNOTAVAIL; break; } @@ -675,10 +747,10 @@ ng_iface_rcvmsg(node_p node, item_p item, hook_p lasthook) case NGM_FLOW_COOKIE: switch (msg->header.cmd) { case NGM_LINK_IS_UP: - ifp->if_drv_flags |= IFF_DRV_RUNNING; + ifp->if_flags |= IFF_RUNNING; break; case NGM_LINK_IS_DOWN: - ifp->if_drv_flags &= ~IFF_DRV_RUNNING; + ifp->if_flags &= ~IFF_RUNNING; break; default: break; @@ -746,9 +818,11 @@ ng_iface_rcvdata(hook_p hook, item_p item) m_freem(m); return (EAFNOSUPPORT); } +#if 0 /* First chunk of an mbuf contains good junk */ if (harvest.point_to_point) random_harvest(m, 16, 3, 0, RANDOM_NET); +#endif netisr_queue(isr, m); return (0); } @@ -763,9 +837,9 @@ ng_iface_shutdown(node_p node) bpfdetach(priv->ifp); if_detach(priv->ifp); - if_free(priv->ifp); + FREE(priv->ifp, M_NETGRAPH_IFACE); priv->ifp = NULL; - free_unr(ng_iface_unit, priv->unit); + ng_iface_free_unit(priv->unit); kfree(priv, M_NETGRAPH_IFACE); NG_NODE_SET_PRIVATE(node, NULL); NG_NODE_UNREF(node); @@ -798,10 +872,8 @@ ng_iface_mod_event(module_t mod, int event, void *data) switch (event) { case MOD_LOAD: - ng_iface_unit = new_unrhdr(0, 0xffff, NULL); break; case MOD_UNLOAD: - delete_unrhdr(ng_iface_unit); break; default: error = EOPNOTSUPP; diff --git a/sys/netgraph7/ng_iface.h b/sys/netgraph7/iface/ng_iface.h similarity index 100% rename from sys/netgraph7/ng_iface.h rename to sys/netgraph7/iface/ng_iface.h diff --git a/sys/netgraph7/netgraph.h b/sys/netgraph7/netgraph.h index 6e73f55692..02be5065bc 100644 --- a/sys/netgraph7/netgraph.h +++ b/sys/netgraph7/netgraph.h @@ -1144,7 +1144,7 @@ int ng_send_fn2(node_p node, hook_p hook, item_p pitem, ng_item_fn2 *fn, int ng_uncallout(struct callout *c, node_p node); int ng_callout(struct callout *c, node_p node, hook_p hook, int ticks, ng_item_fn *fn, void * arg1, int arg2); -#define ng_callout_init(c) callout_init(c, CALLOUT_MPSAFE) +#define ng_callout_init(c) callout_init(c) /* Flags for netgraph functions. */ #define NG_NOFLAGS 0x00000000 /* no special options */ diff --git a/sys/netgraph7/netgraph/Makefile b/sys/netgraph7/netgraph/Makefile new file mode 100644 index 0000000000..6c6078195f --- /dev/null +++ b/sys/netgraph7/netgraph/Makefile @@ -0,0 +1,8 @@ +# $FreeBSD: src/sys/modules/netgraph/netgraph/Makefile,v 1.2.2.2 2001/12/21 09:00:49 ru Exp $ +# $DragonFly$ +# $Whistle: Makefile,v 1.2 1999/01/19 19:39:22 archie Exp $ + +KMOD= netgraph +SRCS= ng_base.c ng_parse.c + +.include diff --git a/sys/netgraph7/ng_base.c b/sys/netgraph7/netgraph/ng_base.c similarity index 99% rename from sys/netgraph7/ng_base.c rename to sys/netgraph7/netgraph/ng_base.c index 123eaffc23..274c16c2c9 100644 --- a/sys/netgraph7/ng_base.c +++ b/sys/netgraph7/netgraph/ng_base.c @@ -57,18 +57,20 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include -#include "ng_message.h" -#include "netgraph.h" -#include "ng_parse.h" +#include +#include +#include MODULE_VERSION(netgraph, NG_ABI_VERSION); @@ -203,7 +205,7 @@ static int ng_generic_msg(node_p here, item_p item, hook_p lasthook); static ng_ID_t ng_decodeidname(const char *name); static int ngb_mod_event(module_t mod, int event, void *data); static void ng_worklist_add(node_p node); -static void ngintr(void); +static void ngintr(void *, int); static int ng_apply_item(node_p node, item_p item, int rw); static void ng_flush_input_queue(node_p node); static node_p ng_ID2noderef(ng_ID_t ID); @@ -213,6 +215,7 @@ static int ng_con_part2(node_p node, item_p item, hook_p hook); static int ng_con_part3(node_p node, item_p item, hook_p hook); static int ng_mkpeer(node_p node, const char *name, const char *name2, char *type); +static boolean_t bzero_ctor(void *obj, void *private, int ocflags); /* Imported, these used to be externally visible, some may go back. */ void ng_destroy_hook(hook_p hook); @@ -2879,7 +2882,7 @@ ng_alloc_item(int type, int flags) ("%s: incorrect item type: %d", __func__, type)); item = uma_zalloc((type == NGQF_DATA)?ng_qdzone:ng_qzone, - ((flags & NG_WAITOK) ? M_WAITOK : M_NOWAIT) | M_ZERO); + (flags & NG_WAITOK) ? M_WAITOK : M_NOWAIT ); if (item) { item->el_flags = type; @@ -3232,7 +3235,7 @@ SYSCTL_PROC(_debug, OID_AUTO, ng_dump_items, CTLTYPE_INT | CTLFLAG_RW, * If there are no more, remove the node from the list. */ static void -ngintr(void) +ngintr(void *context, int pending) { XXX replymsg XXX for (;;) { @@ -3291,6 +3294,8 @@ ng_worklist_add(node_p node) mtx_assert(&node->nd_input_queue.q_mtx, MA_OWNED); if ((node->nd_input_queue.q_flags2 & NGQ2_WORKQ) == 0) { + static struct task ng_task; + /* * If we are not already on the work queue, * then put us on. @@ -3300,7 +3305,8 @@ ng_worklist_add(node_p node) NG_WORKLIST_LOCK(); STAILQ_INSERT_TAIL(&ng_worklist, node, nd_input_queue.q_work); NG_WORKLIST_UNLOCK(); - schednetisr(NETISR_NETGRAPH); + TASK_INIT(&ng_task, 0, ngintr, NULL); + taskqueue_enqueue(taskqueue_swi, &ng_task); CTR3(KTR_NET, "%20s: node [%x] (%p) put on worklist", __func__, node->nd_ID, node); } else { @@ -3633,9 +3639,7 @@ ng_callout(struct callout *c, node_p node, hook_p hook, int ticks, NGI_ARG1(item) = arg1; NGI_ARG2(item) = arg2; oitem = c->c_arg; - if (callout_reset(c, ticks, &ng_callout_trampoline, item) == 1 && - oitem != NULL) - NG_FREE_ITEM(oitem); + callout_reset(c, ticks, &ng_callout_trampoline, item); return (0); } @@ -3683,6 +3687,15 @@ ng_replace_retaddr(node_p here, item_p item, ng_ID_t retaddr) } } +static boolean_t +bzero_ctor(void *obj, void *private, int ocflags) +{ + struct ng_item *i = obj; + + bzero(i, sizeof(struct ng_item)); + return(TRUE); +} + #define TESTING #ifdef TESTING /* just test all the macros */ diff --git a/sys/netgraph7/ng_parse.c b/sys/netgraph7/netgraph/ng_parse.c similarity index 99% rename from sys/netgraph7/ng_parse.c rename to sys/netgraph7/netgraph/ng_parse.c index 507c48f613..f862f3910b 100644 --- a/sys/netgraph7/ng_parse.c +++ b/sys/netgraph7/netgraph/ng_parse.c @@ -58,9 +58,9 @@ #include -#include "ng_message.h" -#include "netgraph.h" -#include "ng_parse.h" +#include +#include +#include #ifdef NG_SEPARATE_MALLOC MALLOC_DEFINE(M_NETGRAPH_PARSE, "netgraph_parse", "netgraph parse info"); diff --git a/sys/netgraph7/socket/Makefile b/sys/netgraph7/socket/Makefile new file mode 100644 index 0000000000..f4175cedb2 --- /dev/null +++ b/sys/netgraph7/socket/Makefile @@ -0,0 +1,9 @@ +# $FreeBSD: src/sys/modules/netgraph/socket/Makefile,v 1.1.4.3 2001/12/21 09:00:50 ru Exp $ +# $DragonFly: src/sys/netgraph/socket/Makefile,v 1.2 2003/06/17 04:28:46 dillon Exp $ +# $Whistle: Makefile,v 1.2 1999/01/19 19:39:22 archie Exp $ + +KMOD= ng_socket +SRCS= ng_socket.c +KMODDEPS= netgraph + +.include diff --git a/sys/netgraph7/ng_socket.c b/sys/netgraph7/socket/ng_socket.c similarity index 95% rename from sys/netgraph7/ng_socket.c rename to sys/netgraph7/socket/ng_socket.c index 1103b77251..d8b4527bad 100644 --- a/sys/netgraph7/ng_socket.c +++ b/sys/netgraph7/socket/ng_socket.c @@ -56,19 +56,24 @@ #include #include #include +/* #include +*/ #include +#include #include #include #include #include +/* #include +*/ #include #ifdef NOTYET #include #endif -#include "ng_message.h" -#include "netgraph.h" +#include +#include #include "ng_socketvar.h" #include "ng_socket.h" @@ -165,26 +170,25 @@ SYSCTL_INT(_net_graph, OID_AUTO, recvspace, CTLFLAG_RW, ***************************************************************/ static int -ngc_attach(struct socket *so, int proto, struct thread *td) +ngc_attach(struct socket *so, int proto, struct pru_attach_info *ai) { struct ngpcb *const pcbp = sotongpcb(so); - int error; - error = priv_check(td, PRIV_NETGRAPH_CONTROL); - if (error) - return (error); + if (priv_check_cred(ai->p_ucred, PRIV_ROOT, NULL_CRED_OKAY) != 0) + return (EPERM); if (pcbp != NULL) return (EISCONN); return (ng_attach_cntl(so)); } -static void +static int ngc_detach(struct socket *so) { struct ngpcb *const pcbp = sotongpcb(so); KASSERT(pcbp != NULL, ("ngc_detach: pcbp == NULL")); ng_detach_common(pcbp, NG_CONTROL); + return (0); } static int @@ -263,12 +267,15 @@ ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, if ((type = ng_findtype(mkp->type)) == NULL) { char filename[NG_TYPESIZ + 3]; - int fileid; + linker_file_t fileid; + + if (!linker_api_available()) + return (ENXIO); /* Not found, try to load it as a loadable module. */ - snprintf(filename, sizeof(filename), "ng_%s", + snprintf(filename, sizeof(filename), "ng_%s.ko", mkp->type); - error = kern_kldload(curthread, filename, &fileid); + error = linker_load_file(filename, &fileid); if (error != 0) { kfree(msg, M_NETGRAPH_MSG); goto release; @@ -277,8 +284,7 @@ ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, /* See if type has been loaded successfully. */ if ((type = ng_findtype(mkp->type)) == NULL) { kfree(msg, M_NETGRAPH_MSG); - (void)kern_kldunload(curthread, fileid, - LINKER_UNLOAD_NORMAL); + (void)linker_file_unload(fileid); error = ENXIO; goto release; } @@ -323,7 +329,8 @@ ngc_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, mtx_lock(&priv->mtx); if (priv->error == -1) - msleep(priv, &priv->mtx, 0, "ngsock", 0); + lock_sleep(priv, 0, "ngsock", 0, + (struct lock *)&priv->mtx); mtx_unlock(&priv->mtx); KASSERT(priv->error != -1, ("ng_socket: priv->error wasn't updated")); @@ -365,7 +372,7 @@ ngc_connect(struct socket *so, struct sockaddr *nam, struct thread *td) ***************************************************************/ static int -ngd_attach(struct socket *so, int proto, struct thread *td) +ngd_attach(struct socket *so, int proto, struct pru_attach_info *ai) { struct ngpcb *const pcbp = sotongpcb(so); @@ -374,13 +381,14 @@ ngd_attach(struct socket *so, int proto, struct thread *td) return (ng_attach_data(so)); } -static void +static int ngd_detach(struct socket *so) { struct ngpcb *const pcbp = sotongpcb(so); KASSERT(pcbp != NULL, ("ngd_detach: pcbp == NULL")); ng_detach_common(pcbp, NG_DATA); + return (0); } static int @@ -570,7 +578,7 @@ ng_attach_common(struct socket *so, int type) int error; /* Standard socket setup stuff. */ - error = soreserve(so, ngpdg_sendspace, ngpdg_recvspace); + error = soreserve(so, ngpdg_sendspace, ngpdg_recvspace, NULL); if (error) return (error); @@ -916,7 +924,7 @@ ngs_rcvmsg(node_p node, item_p item, hook_p lasthook) } /* Send it up to the socket. */ - if (sbappendaddr(&so->so_rcv, (struct sockaddr *)&addr, m, NULL) == 0) { + if (sbappendaddr((struct sockbuf *)&so->so_rcv, (struct sockaddr *)&addr, m, NULL) == 0) { TRAP_ERROR; m_freem(m); return (ENOBUFS); @@ -959,7 +967,7 @@ ngs_rcvdata(hook_p hook, item_p item) addr->sg_data[addrlen] = '\0'; /* Try to tell the socket which hook it came in on. */ - if (sbappendaddr(&so->so_rcv, (struct sockaddr *)addr, m, NULL) == 0) { + if (sbappendaddr((struct sockbuf *)&so->so_rcv, (struct sockaddr *)addr, m, NULL) == 0) { m_freem(m); TRAP_ERROR; return (ENOBUFS); @@ -1055,7 +1063,10 @@ static struct pr_usrreqs ngc_usrreqs = { .pru_send = ngc_send, .pru_shutdown = NULL, .pru_sockaddr = ng_getsockaddr, - .pru_close = NULL, + .pru_sopoll = sopoll, + .pru_sosend = sosend, + .pru_soreceive = soreceive, + /* .pru_close = NULL, */ }; static struct pr_usrreqs ngd_usrreqs = { @@ -1069,7 +1080,10 @@ static struct pr_usrreqs ngd_usrreqs = { .pru_send = ngd_send, .pru_shutdown = NULL, .pru_sockaddr = ng_getsockaddr, - .pru_close = NULL, + .pru_sopoll = sopoll, + .pru_sosend = sosend, + .pru_soreceive = soreceive, + /* .pru_close = NULL, */ }; /* @@ -1084,6 +1098,7 @@ static struct protosw ngsw[] = { .pr_domain = &ngdomain, .pr_protocol = NG_CONTROL, .pr_flags = PR_ATOMIC | PR_ADDR /* | PR_RIGHTS */, + .pr_mport = cpu0_soport, .pr_usrreqs = &ngc_usrreqs }, { @@ -1091,6 +1106,7 @@ static struct protosw ngsw[] = { .pr_domain = &ngdomain, .pr_protocol = NG_DATA, .pr_flags = PR_ATOMIC | PR_ADDR, + .pr_mport = cpu0_soport, .pr_usrreqs = &ngd_usrreqs } }; diff --git a/sys/netgraph7/ng_socket.h b/sys/netgraph7/socket/ng_socket.h similarity index 99% rename from sys/netgraph7/ng_socket.h rename to sys/netgraph7/socket/ng_socket.h index 308c0e34d9..c46f346e83 100644 --- a/sys/netgraph7/ng_socket.h +++ b/sys/netgraph7/socket/ng_socket.h @@ -45,6 +45,8 @@ #ifndef _NETGRAPH_NG_SOCKET_H_ #define _NETGRAPH_NG_SOCKET_H_ +#include + /* Netgraph node type name and cookie */ #define NG_SOCKET_NODE_TYPE "socket" #define NGM_SOCKET_COOKIE 851601233 diff --git a/sys/netgraph7/ng_socketvar.h b/sys/netgraph7/socket/ng_socketvar.h similarity index 100% rename from sys/netgraph7/ng_socketvar.h rename to sys/netgraph7/socket/ng_socketvar.h diff --git a/sys/netgraph7/tee/Makefile b/sys/netgraph7/tee/Makefile new file mode 100644 index 0000000000..818ed4fc1f --- /dev/null +++ b/sys/netgraph7/tee/Makefile @@ -0,0 +1,9 @@ +# $FreeBSD: src/sys/modules/netgraph/tee/Makefile,v 1.1.4.3 2001/12/21 09:00:50 ru Exp $ +# $DragonFly: src/sys/netgraph/tee/Makefile,v 1.2 2003/06/17 04:28:46 dillon Exp $ +# $Whistle: Makefile,v 1.2 1999/01/19 19:39:22 archie Exp $ + +KMOD= ng_tee +SRCS= ng_tee.c +KMODDEPS= netgraph + +.include diff --git a/sys/netgraph7/ng_tee.c b/sys/netgraph7/tee/ng_tee.c similarity index 99% rename from sys/netgraph7/ng_tee.c rename to sys/netgraph7/tee/ng_tee.c index 45d91acd9b..9dba7d9511 100644 --- a/sys/netgraph7/ng_tee.c +++ b/sys/netgraph7/tee/ng_tee.c @@ -58,9 +58,9 @@ #include #include #include -#include "ng_message.h" -#include "netgraph.h" -#include "ng_parse.h" +#include +#include +#include #include "ng_tee.h" /* Per hook info */ diff --git a/sys/netgraph7/ng_tee.h b/sys/netgraph7/tee/ng_tee.h similarity index 100% rename from sys/netgraph7/ng_tee.h rename to sys/netgraph7/tee/ng_tee.h diff --git a/sys/netgraph7/vjc/Makefile b/sys/netgraph7/vjc/Makefile new file mode 100644 index 0000000000..d4d40b10c2 --- /dev/null +++ b/sys/netgraph7/vjc/Makefile @@ -0,0 +1,11 @@ +# $FreeBSD: src/sys/modules/netgraph/vjc/Makefile,v 1.2.2.3 2001/12/21 09:00:50 ru Exp $ +# $DragonFly: src/sys/netgraph/vjc/Makefile,v 1.3 2003/08/14 23:26:45 dillon Exp $ +# $Whistle: Makefile,v 1.1 1999/01/24 06:48:07 archie Exp $ + +KMOD= ng_vjc +SRCS= ng_vjc.c slcompress.c +KMODDEPS= netgraph + +.PATH: ${.CURDIR}/../../net/ppp_layer + +.include diff --git a/sys/netgraph7/ng_vjc.c b/sys/netgraph7/vjc/ng_vjc.c similarity index 99% rename from sys/netgraph7/ng_vjc.c rename to sys/netgraph7/vjc/ng_vjc.c index 9634387bc6..2cdccac097 100644 --- a/sys/netgraph7/ng_vjc.c +++ b/sys/netgraph7/vjc/ng_vjc.c @@ -56,9 +56,9 @@ #include #include -#include "ng_message.h" -#include "netgraph.h" -#include "ng_parse.h" +#include +#include +#include #include "ng_vjc.h" #include diff --git a/sys/netgraph7/ng_vjc.h b/sys/netgraph7/vjc/ng_vjc.h similarity index 100% rename from sys/netgraph7/ng_vjc.h rename to sys/netgraph7/vjc/ng_vjc.h