summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/ng_one2many.c
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>2001-01-28 15:37:06 +0000
committerjulian <julian@FreeBSD.org>2001-01-28 15:37:06 +0000
commit501d5b3f2033d0054d7b9b6d70d20d959ce74f02 (patch)
treebab247e05a8e2e5a2a1a19c92ecda16435148102 /sys/netgraph/ng_one2many.c
parentba9a1fe1a95e88cca498b342048056405f5022b7 (diff)
downloadFreeBSD-src-501d5b3f2033d0054d7b9b6d70d20d959ce74f02.zip
FreeBSD-src-501d5b3f2033d0054d7b9b6d70d20d959ce74f02.tar.gz
Add a new distribution algorythm to the 'one2many' node type.
The new method is 'flood' (in addition to the old round-robin) in which incoming packets are sent to more than one outgoing hook. (I'm not sure what Rogier is using this for but it seems generally useful and isn't much extra) Submitted by: Rogier R. Mulhuijzen (drwilco@drwilco.net )
Diffstat (limited to 'sys/netgraph/ng_one2many.c')
-rw-r--r--sys/netgraph/ng_one2many.c54
1 files changed, 51 insertions, 3 deletions
diff --git a/sys/netgraph/ng_one2many.c b/sys/netgraph/ng_one2many.c
index 89d1927..e78f92e 100644
--- a/sys/netgraph/ng_one2many.c
+++ b/sys/netgraph/ng_one2many.c
@@ -43,7 +43,7 @@
* ng_one2many(4) netgraph node type
*
* Packets received on the "one" hook are sent out each of the
- * "many" hooks in round-robin fashion. Packets received on any
+ * "many" hooks accoring to an algorithm. Packets received on any
* "many" hook are always delivered to the "one" hook.
*/
@@ -278,6 +278,7 @@ ng_one2many_rcvmsg(node_p node, item_p item, hook_p lasthook)
conf = (struct ng_one2many_config *)msg->data;
switch (conf->xmitAlg) {
case NG_ONE2MANY_XMIT_ROUNDROBIN:
+ case NG_ONE2MANY_XMIT_ALL:
break;
default:
error = EINVAL;
@@ -381,7 +382,9 @@ ng_one2many_rcvdata(hook_p hook, item_p item)
struct ng_one2many_link *dst;
int error = 0;
int linkNum;
+ int i;
struct mbuf *m;
+ meta_p meta;
m = NGI_M(item); /* just peaking, mbuf still owned by item */
/* Get link number */
@@ -405,8 +408,51 @@ ng_one2many_rcvdata(hook_p hook, item_p item)
NG_FREE_ITEM(item);
return (ENOTCONN);
}
- dst = &priv->many[priv->activeMany[priv->nextMany]];
- priv->nextMany = (priv->nextMany + 1) % priv->numActiveMany;
+ switch(priv->conf.xmitAlg) {
+ case NG_ONE2MANY_XMIT_ROUNDROBIN:
+ dst = &priv->many[priv->activeMany[priv->nextMany]];
+ priv->nextMany = (priv->nextMany + 1) % priv->numActiveMany;
+ break;
+ case NG_ONE2MANY_XMIT_ALL:
+ meta = NGI_META(item); /* peek.. */
+ /* no need to copy data for the 1st one */
+ dst = &priv->many[priv->activeMany[0]];
+
+ /* make copies of data and send for all links
+ * except the first one, which we'll do last
+ */
+ for (i = 1; i < priv->numActiveMany; i++) {
+ meta_p meta2 = NULL;
+ struct mbuf *m2;
+ struct ng_one2many_link *mdst;
+
+ mdst = &priv->many[priv->activeMany[i]];
+ m2 = m_dup(m, M_NOWAIT); /* XXX m_copypacket() */
+ if (m2 == NULL) {
+ mdst->stats.memoryFailures++;
+ NG_FREE_ITEM(item);
+ NG_FREE_M(m);
+ return (ENOBUFS);
+ }
+ if (meta != NULL
+ && (meta2 = ng_copy_meta(meta)) == NULL) {
+ mdst->stats.memoryFailures++;
+ m_freem(m2);
+ NG_FREE_ITEM(item);
+ NG_FREE_M(m);
+ return (ENOMEM);
+ }
+ /* Update transmit stats */
+ mdst->stats.xmitPackets++;
+ mdst->stats.xmitOctets += m->m_pkthdr.len;
+ NG_SEND_DATA(error, mdst->hook, m2, meta2);
+ }
+ break;
+#ifdef INVARIANTS
+ default:
+ panic("%s: invalid xmitAlg", __FUNCTION__);
+#endif
+ }
} else
dst = &priv->one;
@@ -502,6 +548,8 @@ ng_one2many_update_many(priv_p priv)
if (priv->numActiveMany > 0)
priv->nextMany %= priv->numActiveMany;
break;
+ case NG_ONE2MANY_XMIT_ALL:
+ break;
#ifdef INVARIANTS
default:
panic("%s: invalid xmitAlg", __FUNCTION__);
OpenPOWER on IntegriCloud