On Tue, Aug 27, 2002 at 11:54:30PM -0400, [EMAIL PROTECTED] wrote: > > I'm actually going to throw up a 5.0-current box <groan :)> and start > playing. By the time done what I need, there'll probably be a release of > it. :) > > It looks like a more than trivial backport, at least for my ability and > general sleepless state.
Here you go. It's untested other then compiling, but the diff applied
almost directly so I'd guess it works.
-- Brooks
Index: ng_one2many.c
===================================================================
RCS file: /usr/cvs/src/sys/netgraph/ng_one2many.c,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 ng_one2many.c
--- ng_one2many.c 2 Jul 2002 23:44:02 -0000 1.1.2.2
+++ ng_one2many.c 28 Aug 2002 04:47:32 -0000
@@ -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.
*/
@@ -284,6 +284,7 @@ ng_one2many_rcvmsg(node_p node, struct n
conf = (struct ng_one2many_config *)msg->data;
switch (conf->xmitAlg) {
case NG_ONE2MANY_XMIT_ROUNDROBIN:
+ case NG_ONE2MANY_XMIT_ALL:
break;
default:
error = EINVAL;
@@ -390,6 +391,7 @@ ng_one2many_rcvdata(hook_p hook, struct
struct ng_one2many_link *dst;
int error = 0;
int linkNum;
+ int i;
/* Get link number */
linkNum = LINK_NUM(hook);
@@ -412,8 +414,48 @@ ng_one2many_rcvdata(hook_p hook, struct
NG_FREE_DATA(m, meta);
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:
+ /* 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_DATA(m, meta);
+ return (ENOBUFS);
+ }
+ if (meta != NULL
+ && (meta2 = ng_copy_meta(meta)) == NULL) {
+ mdst->stats.memoryFailures++;
+ m_freem(m2);
+ NG_FREE_DATA(m, meta);
+ 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;
@@ -509,6 +551,8 @@ ng_one2many_update_many(priv_p priv)
case NG_ONE2MANY_XMIT_ROUNDROBIN:
if (priv->numActiveMany > 0)
priv->nextMany %= priv->numActiveMany;
+ break;
+ case NG_ONE2MANY_XMIT_ALL:
break;
#ifdef INVARIANTS
default:
Index: ng_one2many.h
===================================================================
RCS file: /usr/cvs/src/sys/netgraph/ng_one2many.h,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 ng_one2many.h
--- ng_one2many.h 2 Jul 2002 23:44:02 -0000 1.1.2.3
+++ ng_one2many.h 28 Aug 2002 04:47:33 -0000
@@ -59,6 +59,7 @@
/* Algorithms for outgoing packet distribution (XXX only one so far) */
#define NG_ONE2MANY_XMIT_ROUNDROBIN 1 /* round-robin delivery */
+#define NG_ONE2MANY_XMIT_ALL 2 /* send packets to all many hooks */
/* Algorithms for detecting link failure (XXX only one so far) */
#define NG_ONE2MANY_FAIL_MANUAL 1 /* use enabledLinks[] array */
@@ -84,6 +85,7 @@ struct ng_one2many_link_stats {
u_int64_t recvPackets; /* total pkts rec'd on link */
u_int64_t xmitOctets; /* total octets xmit'd on link */
u_int64_t xmitPackets; /* total pkts xmit'd on link */
+ u_int64_t memoryFailures; /* times couldn't get mem or mbuf */
};
/* Keep this in sync with the above structure definition */
@@ -92,6 +94,7 @@ struct ng_one2many_link_stats {
{ "recvPackets", &ng_parse_uint64_type }, \
{ "xmitOctets", &ng_parse_uint64_type }, \
{ "xmitPackets", &ng_parse_uint64_type }, \
+ { "memoryFailures", &ng_parse_uint64_type }, \
{ NULL } \
}
--
Any statement of the form "X is the one, true Y" is FALSE.
PGP fingerprint 655D 519C 26A7 82E7 2529 9BF0 5D8E 8BE9 F238 1AD4
msg36540/pgp00000.pgp
Description: PGP signature

