aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/man/man4/ng_split.488
-rw-r--r--sys/modules/netgraph/split/Makefile8
-rw-r--r--sys/netgraph/ng_split.c227
-rw-r--r--sys/netgraph/ng_split.h45
4 files changed, 368 insertions, 0 deletions
diff --git a/share/man/man4/ng_split.4 b/share/man/man4/ng_split.4
new file mode 100644
index 000000000000..3593794b03f3
--- /dev/null
+++ b/share/man/man4/ng_split.4
@@ -0,0 +1,88 @@
+.\" Copyright (c) 2001 FreeBSD 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 FreeBSD Inc.;
+.\" 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 FreeBSD
+.\" Inc., Inc. trademarks, including the mark "FREEBSD
+.\" INC." on advertising, endorsements, or otherwise except as
+.\" such appears in the above copyright notice or in the software.
+.\"
+.\" THIS SOFTWARE IS BEING PROVIDED BY FREEBSD INC. "AS IS", AND
+.\" TO THE MAXIMUM EXTENT PERMITTED BY LAW, FreeBSD Inc. 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.
+.\" FreeBSD Inc. 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 FreeBSD Inc. 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 FreeBSD Inc. IS ADVISED OF THE POSSIBILITY
+.\" OF SUCH DAMAGE.
+.\"
+.\" Author: Julian Elischer <julian@FreeBSD.org>
+.\"
+.\" $FreeBSD$
+.\"
+.Dd February 19, 2001
+.Dt NG_SPLIT 4
+.Os FreeBSD
+.Sh NAME
+.Nm ng_split
+.Nd Netgraph node to separate incoming and outgoing flows.
+.Sh SYNOPSIS
+.Fd #include <netgraph/ng_split.h>
+.Sh DESCRIPTION
+The
+.Nm split
+node type is used to split a bidirectional stream of packets into
+two separate unidirectional streams of packets.
+.Pp
+.Sh HOOKS
+This node type supports the following three hooks:
+.Pp
+.Bl -tag -width foobar
+.It Dv in
+Packets received on
+.Em in
+are forwarded to
+.Em mixed .
+.It Dv out
+Packets received on
+.Em out
+will be discarded as illegal.
+.It Dv mixed
+Packets received on
+.Em mixed
+are forwarded to
+.Em out .
+.El
+.Sh CONTROL MESSAGES
+This node type supports only the generic control messages.
+.Sh SHUTDOWN
+This node shuts down upon receipt of a
+.Dv NGM_SHUTDOWN
+control message, or when all hooks have been disconnected.
+.Sh SEE ALSO
+.Xr netgraph 4 ,
+.Xr ngctl 8
+.Sh HISTORY
+The
+.Nm
+node type was implemented in
+.Fx 3.5
+but incorprated into FreeBSD in
+.Fx 5.0 .
+.Sh AUTHORS
+.An Julian Elischer Aq julian@FreeBSD.org
+.An Vitaly V. Belekhov Aq vitaly@riss-telecom.ru
diff --git a/sys/modules/netgraph/split/Makefile b/sys/modules/netgraph/split/Makefile
new file mode 100644
index 000000000000..90226c0f809a
--- /dev/null
+++ b/sys/modules/netgraph/split/Makefile
@@ -0,0 +1,8 @@
+# $FreeBSD$
+#
+
+KMOD= ng_split
+SRCS= ng_split.c
+NOMAN=
+
+.include <bsd.kmod.mk>
diff --git a/sys/netgraph/ng_split.c b/sys/netgraph/ng_split.c
new file mode 100644
index 000000000000..d42ee9806df9
--- /dev/null
+++ b/sys/netgraph/ng_split.c
@@ -0,0 +1,227 @@
+/*-
+ *
+ * Copyright (c) 1999-2000, Vitaly V Belekhov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON 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 ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/errno.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.h>
+#include <sys/errno.h>
+#include <sys/sockio.h>
+#include <sys/socket.h>
+#include <sys/syslog.h>
+
+#include <netgraph/ng_message.h>
+#include <netgraph/netgraph.h>
+#include <netgraph/ng_split.h>
+
+/* Netgraph methods */
+static ng_constructor_t ng_split_constructor;
+static ng_rcvmsg_t ng_split_rcvmsg;
+static ng_shutdown_t ng_split_rmnode;
+static ng_newhook_t ng_split_newhook;
+static ng_rcvdata_t ng_split_rcvdata;
+static ng_connect_t ng_split_connect;
+static ng_disconnect_t ng_split_disconnect;
+
+/* Node type descriptor */
+static struct ng_type typestruct = {
+ NG_ABI_VERSION,
+ NG_SPLIT_NODE_TYPE,
+ NULL,
+ ng_split_constructor,
+ ng_split_rcvmsg,
+ ng_split_rmnode,
+ ng_split_newhook,
+ NULL,
+ ng_split_connect,
+ ng_split_rcvdata,
+ ng_split_disconnect,
+ NULL
+};
+NETGRAPH_INIT(ng_split, &typestruct);
+
+/* Node private data */
+struct ng_split_private {
+ hook_p outhook;
+ hook_p inhook;
+ hook_p mixed;
+ node_p node; /* Our netgraph node */
+};
+typedef struct ng_split_private *priv_p;
+
+/************************************************************************
+ NETGRAPH NODE STUFF
+ ************************************************************************/
+
+/*
+ * Constructor for a node
+ */
+static int
+ng_split_constructor(node_p node)
+{
+ priv_p priv;
+
+ /* Allocate node */
+ MALLOC(priv, priv_p, sizeof(*priv), M_NETGRAPH, M_ZERO | M_NOWAIT);
+ if (priv == NULL)
+ return (ENOMEM);
+ bzero(priv, sizeof(*priv));
+
+ /* Link together node and private info */
+ NG_NODE_SET_PRIVATE(node, priv);
+ priv->node = node;
+
+ /* Done */
+ return (0);
+}
+
+/*
+ * Give our ok for a hook to be added
+ */
+static int
+ng_split_newhook(node_p node, hook_p hook, const char *name)
+{
+ priv_p priv = NG_NODE_PRIVATE(node);
+
+ if (strcmp(name, NG_SPLIT_HOOK_MIXED)) {
+ if (strcmp(name, NG_SPLIT_HOOK_INHOOK)) {
+ if (strcmp(name, NG_SPLIT_HOOK_OUTHOOK))
+ return (EPFNOSUPPORT);
+ else {
+ if (priv->outhook != NULL)
+ return (EISCONN);
+ priv->outhook = hook;
+ NG_HOOK_SET_PRIVATE(hook, &(priv->outhook));
+ }
+ } else {
+ if (priv->inhook != NULL)
+ return (EISCONN);
+ priv->inhook = hook;
+ NG_HOOK_SET_PRIVATE(hook, &(priv->inhook));
+ }
+ } else {
+ if (priv->mixed != NULL)
+ return (EISCONN);
+ priv->mixed = hook;
+ NG_HOOK_SET_PRIVATE(hook, &(priv->mixed));
+ }
+
+ return (0);
+}
+
+/*
+ * Receive a control message
+ */
+static int
+ng_split_rcvmsg(node_p node, item_p item, hook_p lasthook)
+{
+ NG_FREE_ITEM(item);
+ return (EINVAL);
+}
+
+/*
+ * Recive data from a hook.
+ */
+static int
+ng_split_rcvdata(hook_p hook, item_p item)
+{
+ meta_p meta;
+ const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
+ int error = 0;
+
+ if (hook == priv->outhook) {
+ printf("ng_split: got packet from outhook!\n");
+ NG_FREE_ITEM(item);
+ return (EINVAL);
+ }
+#if 0 /* should never happen */
+ if (NGI_M(item) == NULL) {
+ printf("ng_split: mbuf is null.\n");
+ NG_FREE_ITEM(item);
+ return (EINVAL);
+ }
+#endif
+ /*
+ * XXX Really here we should just remove metadata we understand.
+ */
+ NGI_GET_META(item, meta);
+ NG_FREE_META(meta);
+ if ((hook == priv->inhook) && (priv->mixed)) {
+ NG_FWD_ITEM_HOOK(error, item, priv->mixed);
+ } else if ((hook == priv->mixed) && (priv->outhook)) {
+ NG_FWD_ITEM_HOOK(error, item, priv->outhook);
+ }
+ return (error);
+}
+
+static int
+ng_split_rmnode(node_p node)
+{
+ const priv_p priv = NG_NODE_PRIVATE(node);
+
+ NG_NODE_SET_PRIVATE(node, NULL);
+ NG_NODE_UNREF(node);
+ FREE(priv, M_NETGRAPH);
+
+ return (0);
+}
+
+
+/*
+ * This is called once we've already connected a new hook to the other node.
+ * It gives us a chance to balk at the last minute.
+ */
+static int
+ng_split_connect(hook_p hook)
+{
+ /* be really amiable and just say "YUP that's OK by me! " */
+ return (0);
+}
+
+/*
+ * Hook disconnection
+ */
+static int
+ng_split_disconnect(hook_p hook)
+{
+ if (NG_HOOK_PRIVATE(hook)) {
+ *((hook_p *)NG_HOOK_PRIVATE(hook)) = (hook_p)0;
+ }
+
+ if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
+ && (NG_NODE_IS_VALID(NG_HOOK_NODE(hook)))) {
+ ng_rmnode_self(NG_HOOK_NODE(hook));
+ }
+
+ return (0);
+}
diff --git a/sys/netgraph/ng_split.h b/sys/netgraph/ng_split.h
new file mode 100644
index 000000000000..a8b66d5c6d53
--- /dev/null
+++ b/sys/netgraph/ng_split.h
@@ -0,0 +1,45 @@
+/*
+ *
+ * Copyright (c) 1999-2000, Vitaly V Belekhov
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice unmodified, this list of conditions, and the following
+ * disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON 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 ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ *
+ */
+
+
+#ifndef _NG_SPLIT_H
+#define _NG_SPLIT_H
+
+/* Node type name and magic cookie */
+#define NG_SPLIT_NODE_TYPE "ng_split"
+#define NGM_NG_SPLIT_COOKIE 949409402
+
+/* My hook names */
+#define NG_SPLIT_HOOK_MIXED "mixed" /* Mixed stream (in/out) */
+#define NG_SPLIT_HOOK_OUTHOOK "out" /* Output to outhook (sending out) */
+#define NG_SPLIT_HOOK_INHOOK "in" /* Input from inhook (recieving) */
+
+#endif /* _NG_SPLIT_H */