From glebius@cell.sick.ru  Tue Feb 24 11:49:13 2004
Return-Path: <glebius@cell.sick.ru>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id BB85E16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 24 Feb 2004 11:49:13 -0800 (PST)
Received: from cell.sick.ru (cell.sick.ru [217.72.144.68])
	by mx1.FreeBSD.org (Postfix) with ESMTP id CCD7A43D1F
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 24 Feb 2004 11:49:12 -0800 (PST)
	(envelope-from glebius@cell.sick.ru)
Received: from cell.sick.ru (glebius@localhost [127.0.0.1])
	by cell.sick.ru (8.12.9/8.12.8) with ESMTP id i1OJn9QE081090
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 24 Feb 2004 22:49:10 +0300 (MSK)
	(envelope-from glebius@cell.sick.ru)
Received: (from glebius@localhost)
	by cell.sick.ru (8.12.9/8.12.6/Submit) id i1OJn9V7081089;
	Tue, 24 Feb 2004 22:49:09 +0300 (MSK)
Message-Id: <200402241949.i1OJn9V7081089@cell.sick.ru>
Date: Tue, 24 Feb 2004 22:49:09 +0300 (MSK)
From: Gleb Smirnoff <glebius@cell.sick.ru>
Reply-To: Gleb Smirnoff <glebius@cell.sick.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] make ng_ether(4) support "lower" and "orphans" simultaneously
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         63317
>Category:       kern
>Synopsis:       [patch] make ng_ether(4) support "lower" and "orphans" simultaneously
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 24 11:50:12 PST 2004
>Closed-Date:    Sun May 16 12:33:48 PDT 2004
>Last-Modified:  Sun May 16 12:33:48 PDT 2004
>Originator:     Gleb Smirnoff
>Release:        FreeBSD 4.9-PRERELEASE i386
>Organization:
Oilspace, Inc.
>Environment:
System: FreeBSD cell.sick.ru 4.9-PRERELEASE FreeBSD 4.9-PRERELEASE #0: Fri Sep 19 10:22:46 MSD 2003 root@fade.bestcom.ru:/usr/obj/usr/src/sys/NUCLEUS i386
>Description:
	
	It is mentioned in manpage ng_ether.4, that ng_ether node has
	a limitation:

     The orphans hook is equivalent to lower, except that only unrecognized
     packets (that would otherwise be discarded) are written to the hook, and
     normal incoming traffic is unaffected.  At most one of orphans and lower
     may be connected at any time.

	In some cases it is necessary to use both hooks. Examining code
	haven't revealed any obstacles for me, so I still can't guess
	what was the purpose of such a limitation. May be developers
	will point me at some underwater stone.

>How-To-Repeat:

	Try to connect both "lower" and "orphans" at one time.

>Fix:

	A patch for CURRENT follows. A patch for STABLE
	can be found here:

	http://cell.sick.ru/~glebius/patches/netgraph/ng_ether_lowerorphan/ng_ether.c.diff.STABLE

	The patch for STABLE was successfully used at production
	router for ~ 2 weeks.

--- ng_ether.c.orig	Mon Feb 23 15:18:14 2004
+++ ng_ether.c	Mon Feb 23 15:26:20 2004
@@ -71,8 +71,8 @@
 struct private {
 	struct ifnet	*ifp;		/* associated interface */
 	hook_p		upper;		/* upper hook connection */
-	hook_p		lower;		/* lower OR orphan hook connection */
-	u_char		lowerOrphan;	/* whether lower is lower or orphan */
+	hook_p		lower;		/* lower hook connection */
+	hook_p		orphan;		/* orphan hook connection */
 	u_char		autoSrcAddr;	/* always overwrite source address */
 	u_char		promisc;	/* promiscuous mode enabled */
 	u_long		hwassist;	/* hardware checksum capabilities */
@@ -95,7 +95,7 @@
 static void	ng_ether_detach(struct ifnet *ifp); 
 
 /* Other functions */
-static void	ng_ether_input2(node_p node, struct mbuf **mp);
+static void	ng_ether_input2(hook_p hook, struct mbuf **mp);
 static int	ng_ether_rcv_lower(node_p node, struct mbuf *m, meta_p meta);
 static int	ng_ether_rcv_upper(node_p node, struct mbuf *m, meta_p meta);
 
@@ -204,9 +204,9 @@
 	const priv_p priv = NG_NODE_PRIVATE(node);
 
 	/* If "lower" hook not connected, let packet continue */
-	if (priv->lower == NULL || priv->lowerOrphan)
+	if (priv->lower == NULL)
 		return;
-	ng_ether_input2(node, mp);
+	ng_ether_input2(priv->lower, mp);
 }
 
 /*
@@ -222,11 +222,11 @@
 	const priv_p priv = NG_NODE_PRIVATE(node);
 
 	/* If "orphan" hook not connected, let packet continue */
-	if (priv->lower == NULL || !priv->lowerOrphan) {
+	if (priv->orphan == NULL ) {
 		m_freem(m);
 		return;
 	}
-	ng_ether_input2(node, &m);
+	ng_ether_input2(priv->orphan, &m);
 	if (m != NULL)
 		m_freem(m);
 }
@@ -239,13 +239,12 @@
  * NOTE: this function will get called at splimp()
  */
 static void
-ng_ether_input2(node_p node, struct mbuf **mp)
+ng_ether_input2(hook_p hook, struct mbuf **mp)
 {
-	const priv_p priv = NG_NODE_PRIVATE(node);
 	int error;
 
 	/* Send out lower/orphan hook */
-	NG_SEND_DATA_ONLY(error, priv->lower, *mp);
+	NG_SEND_DATA_ONLY(error, hook, *mp);
 	*mp = NULL;
 }
 
@@ -353,7 +352,6 @@
 ng_ether_newhook(node_p node, hook_p hook, const char *name)
 {
 	const priv_p priv = NG_NODE_PRIVATE(node);
-	u_char orphan = priv->lowerOrphan;
 	hook_p *hookptr;
 
 	/* Divert hook is an alias for lower */
@@ -365,10 +363,8 @@
 		hookptr = &priv->upper;
 	else if (strcmp(name, NG_ETHER_HOOK_LOWER) == 0) {
 		hookptr = &priv->lower;
-		orphan = 0;
 	} else if (strcmp(name, NG_ETHER_HOOK_ORPHAN) == 0) {
-		hookptr = &priv->lower;
-		orphan = 1;
+		hookptr = &priv->orphan;
 	} else
 		return (EINVAL);
 
@@ -382,7 +378,6 @@
 
 	/* OK */
 	*hookptr = hook;
-	priv->lowerOrphan = orphan;
 	return (0);
 }
 
@@ -515,7 +510,7 @@
 	NGI_GET_M(item, m);
 	NGI_GET_META(item, meta);
 	NG_FREE_ITEM(item);
-	if (hook == priv->lower)
+	if (hook == priv->lower || hook == priv->orphan)
 		return ng_ether_rcv_lower(node, m, meta);
 	if (hook == priv->upper)
 		return ng_ether_rcv_upper(node, m, meta);
@@ -632,7 +627,8 @@
 			priv->ifp->if_hwassist = priv->hwassist;
 	} else if (hook == priv->lower) {
 		priv->lower = NULL;
-		priv->lowerOrphan = 0;
+	} else if (hook == priv->orphan) {
+		priv->orphan = NULL;
 	} else
 		panic("%s: weird hook", __func__);
 	if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
>Release-Note:
>Audit-Trail:

From: "Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net>
To: Gleb Smirnoff <glebius@cell.sick.ru>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/63317: [patch] make ng_ether(4) support "lower" and "orphans"
 simultaneously
Date: Wed, 25 Feb 2004 06:19:42 +0000 (UTC)

 On Tue, 24 Feb 2004, Gleb Smirnoff wrote:
 
 Hi,
 
 > >Number:         63317
 > >Category:       kern
 > >Synopsis:       [patch] make ng_ether(4) support "lower" and "orphans" simultaneously
 >
 > 	It is mentioned in manpage ng_ether.4, that ng_ether node has
 > 	a limitation:
 >
 >      The orphans hook is equivalent to lower, except that only unrecognized
 >      packets (that would otherwise be discarded) are written to the hook, and
 >      normal incoming traffic is unaffected.  At most one of orphans and lower
 >      may be connected at any time.
 >
 > 	In some cases it is necessary to use both hooks. Examining code
 
 can you please give an example ?
 
 lower = everything
 orphans = lower - protocols known how to handle
 
 So everything you see at orphans you already have seen at lower IMHO.
 
 -- 
 Bjoern A. Zeeb				bzeeb at Zabbadoz dot NeT
 56 69 73 69 74				http://www.zabbadoz.net/

From: Gleb Smirnoff <glebius@cell.sick.ru>
To: "Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/63317: [patch] make ng_ether(4) support "lower" and "orphans" simultaneously
Date: Wed, 25 Feb 2004 10:37:55 +0300

 On Wed, Feb 25, 2004 at 06:19:42AM +0000, Bjoern A. Zeeb wrote:
 B> > 	In some cases it is necessary to use both hooks. Examining code
 B> 
 B> can you please give an example ?
 B> 
 B> lower = everything
 B> orphans = lower - protocols known how to handle
 B> 
 B> So everything you see at orphans you already have seen at lower IMHO.
 
 Imagine situation when you need to handle IP and "protocols known how to handle"
 separately. For example when you have got pppoed(8) hanging on orphans, you
 can't attach anything to lower.
 
 -- 
 Totus tuus, Glebius.
 GLEBIUS-RIPN GLEB-RIPE

From: Archie Cobbs <archie@dellroad.org>
To: Maxim Konovalov <maxim@macomnet.ru>
Cc: glebius@cell.sick.ru, bzeeb-lists@lists.zabbadoz.net,
	FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/63317: make ng_ether(4) support "lower" and "orphans"simultaneously
Date: Fri, 23 Apr 2004 10:22:59 -0500 (CDT)

 Maxim Konovalov wrote:
 > If you manage to get a couple of spared minutes could you please take
 > a look at the patch in kern/63317?
 
 So just to make sure I understand: the new semantics of having both
 hooks connected is that lower gets all packets and orphans would not 
 see any packets unless packets are also written into the upper hook
 (e.g., if the node connected to lower "passes through" to upper).
 
 -Archie
 
 __________________________________________________________________________
 Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

From: Gleb Smirnoff <glebius@cell.sick.ru>
To: Archie Cobbs <archie@dellroad.org>
Cc: Maxim Konovalov <maxim@macomnet.ru>,
	bzeeb-lists@lists.zabbadoz.net, FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/63317: make ng_ether(4) support "lower" and "orphans"simultaneously
Date: Mon, 26 Apr 2004 11:21:01 +0400

 On Fri, Apr 23, 2004 at 10:22:59AM -0500, Archie Cobbs wrote:
 A> Maxim Konovalov wrote:
 A> > If you manage to get a couple of spared minutes could you please take
 A> > a look at the patch in kern/63317?
 A> 
 A> So just to make sure I understand: the new semantics of having both
 A> hooks connected is that lower gets all packets and orphans would not 
 A> see any packets unless packets are also written into the upper hook
 A> (e.g., if the node connected to lower "passes through" to upper).
 
 No. Lower gets all packets which in normal way would travel into upper
 protocol stack. Orphans gets all packets which in normal way would be
 discarded. Nothing depends on behavior of the node connected to lower.
 
 The functionality of hooks does not change at all. The new behavior is
 the same as in current manpage:
 
      The lower hook is a connection to the raw Ethernet device.  When con-
      nected, all incoming packets are diverted out this hook. 
 
      The orphans hook is equivalent to lower, except that only unrecognized
      packets (that would otherwise be discarded) are written to the hook, and
      normal incoming traffic is unaffected.
 
 The only difference is that the sentence
 
      At most one of orphans and lower may be connected at any time.
 
 is not the truth anymore.
 
 -- 
 Totus tuus, Glebius.
 GLEBIUS-RIPN GLEB-RIPE

From: Archie Cobbs <archie@dellroad.org>
To: Gleb Smirnoff <glebius@cell.sick.ru>
Cc: Archie Cobbs <archie@dellroad.org>,
	Maxim Konovalov <maxim@macomnet.ru>, bzeeb-lists@lists.zabbadoz.net,
	FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/63317: make ng_ether(4) support "lower" and "orphans"simultaneously
Date: Mon, 26 Apr 2004 08:53:23 -0500 (CDT)

 Gleb Smirnoff wrote:
 > A> So just to make sure I understand: the new semantics of having both
 > A> hooks connected is that lower gets all packets and orphans would not 
 > A> see any packets unless packets are also written into the upper hook
 > A> (e.g., if the node connected to lower "passes through" to upper).
 > 
 > No. Lower gets all packets which in normal way would travel into upper
 > protocol stack. Orphans gets all packets which in normal way would be
 > discarded. Nothing depends on behavior of the node connected to lower.
 > 
 > The functionality of hooks does not change at all. The new behavior is
 > the same as in current manpage:
 > 
 >      The lower hook is a connection to the raw Ethernet device.  When con-
 >      nected, all incoming packets are diverted out this hook. 
 > 
 >      The orphans hook is equivalent to lower, except that only unrecognized
 >      packets (that would otherwise be discarded) are written to the hook, and
 >      normal incoming traffic is unaffected.
 > 
 > The only difference is that the sentence
 > 
 >      At most one of orphans and lower may be connected at any time.
 > 
 > is not the truth anymore.
 
 Let me be more specific. Suppose both lower and orphans are connected.
 A packet is received from the Ethernet hardware with ethertype
 0x1234 (i.e., unrecognized). Which hook(s) (lower and/or orphans)
 does that packet get written to?  Then: same question applied to a
 packet received from the upper hook.
 
 -Archie
 
 __________________________________________________________________________
 Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

From: Gleb Smirnoff <glebius@cell.sick.ru>
To: Archie Cobbs <archie@dellroad.org>
Cc: Maxim Konovalov <maxim@macomnet.ru>,
	bzeeb-lists@lists.zabbadoz.net, FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: kern/63317: make ng_ether(4) support "lower" and "orphans"simultaneously
Date: Mon, 26 Apr 2004 22:31:34 +0400

 On Mon, Apr 26, 2004 at 08:53:23AM -0500, Archie Cobbs wrote:
 A> Let me be more specific. Suppose both lower and orphans are connected.
 A> A packet is received from the Ethernet hardware with ethertype
 A> 0x1234 (i.e., unrecognized). Which hook(s) (lower and/or orphans)
 A> does that packet get written to?
 
 It'll be written to orphans surely.
 
 A>  Then: same question applied to a packet received from the upper hook.
 
 Any packet received on the upper will go to upper protocol stack. The "upper"
 behavior is not touched.
 
 -- 
 Totus tuus, Glebius.
 GLEBIUS-RIPN GLEB-RIPE

From: Gleb Smirnoff <glebius@cell.sick.ru>
To: Archie Cobbs <archie@dellroad.org>
Cc: Maxim Konovalov <maxim@macomnet.ru>,
	bzeeb-lists@lists.zabbadoz.net, FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/63317: make ng_ether(4) support "lower" and "orphans"simultaneously
Date: Tue, 27 Apr 2004 10:33:34 +0400

 On Mon, Apr 26, 2004 at 04:49:48PM -0500, Archie Cobbs wrote:
 A> Gleb Smirnoff wrote:
 A> > A> Let me be more specific. Suppose both lower and orphans are connected.
 A> > A> A packet is received from the Ethernet hardware with ethertype
 A> > A> 0x1234 (i.e., unrecognized). Which hook(s) (lower and/or orphans)
 A> > A> does that packet get written to?
 A> > 
 A> > It'll be written to orphans surely.
 A> 
 A> OK, then this is a change in semantics: whereas before, connecting
 A> to lower meant always getting all packets, now connecting to lower
 A> means always getting all packets UNLESS somebody else is connected
 A> to orphans... could be a completely different and unknown process.
 
 It is said in current manpage, that ng_ether sends all packets to lower,
 however code reveals the truth. Here is a sniplet from ng_ether_input_orphan(),
 which is a hook called by ethernet stack:
 
         /* If "orphan" hook not connected, let packet continue */
         if (priv->lower == NULL || !priv->lowerOrphan) {
                 m_freem(m);
                 return;
         }
 
 To make sure, I've made an experiment. I have a notebook in a network where many IPX
 broadcasts live. So I typed:
 
 + mkpeer fxp0: etf lower downstream
 + name fxp0:lower etf
 + connect etf: dummy ipx
 + msg etf: setfilter { matchhook="ipx" ethertype=0x8137 }
 
 I've waited for half a minute, and no packets arrived. Then, I've typed:
 
 + shutdown etf:
 + shutdown fxp0:
 + mkpeer fxp0: etf orphans downstream
 + name fxp0:orphans etf
 + connect etf: dummy ipx
 + msg etf: setfilter { matchhook="ipx" ethertype=0x8137 }
 
 And I began receiving packets on dummy.
 
 A> To preserve the existing behavior, the node would need to duplicate
 A> the orphanable packets and send them to BOTH connected hooks.
 
 So behavior didn't change. Even we have found some inexactitude in
 manpage.
 
 A> Also, will this change cause packets to go up into the protocol
 A> stack that previously would not have? E.g., before, if lower were
 A> connected, then no packets ever reach the protocol stack... is that
 A> still going to be true?
 
 Yes, since "orphaned" packets won't reach it anyway.
 
 -- 
 Totus tuus, Glebius.
 GLEBIUS-RIPN GLEB-RIPE

From: Archie Cobbs <archie@dellroad.org>
To: Gleb Smirnoff <glebius@cell.sick.ru>
Cc: Archie Cobbs <archie@dellroad.org>,
	Maxim Konovalov <maxim@macomnet.ru>, bzeeb-lists@lists.zabbadoz.net,
	FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/63317: make ng_ether(4) support "lower" and "orphans"simultaneously
Date: Tue, 27 Apr 2004 09:18:58 -0500 (CDT)

 Gleb Smirnoff wrote:
 > A> OK, then this is a change in semantics: whereas before, connecting
 > A> to lower meant always getting all packets, now connecting to lower
 > A> means always getting all packets UNLESS somebody else is connected
 > A> to orphans... could be a completely different and unknown process.
 > 
 > It is said in current manpage, that ng_ether sends all packets to lower,
 > however code reveals the truth. Here is a sniplet from ng_ether_input_orphan(),
 > which is a hook called by ethernet stack:
 > 
 >         /* If "orphan" hook not connected, let packet continue */
 >         if (priv->lower == NULL || !priv->lowerOrphan) {
 >                 m_freem(m);
 >                 return;
 >         }
 
 What is your point? This function is only called for orphan packets.
 In the current code, if the 'lower' hook is connected, this function will
 never be called (all packets will get sent to 'lower') (note: in the current
 code, 'priv->lower' is used for both 'lower' and 'orphans' hooks).
 
 > To make sure, I've made an experiment. I have a notebook in a network where many IPX
 > broadcasts live. So I typed:
 > 
 > + mkpeer fxp0: etf lower downstream
 > + name fxp0:lower etf
 > + connect etf: dummy ipx
 > + msg etf: setfilter { matchhook="ipx" ethertype=0x8137 }
 > 
 > I've waited for half a minute, and no packets arrived. Then, I've typed:
 
 Is this with your modified node? If so, then it demonstrates how you have
 changed the semantics.
 
 You should see ALL packets on the 'lower' hook. This has been working fine
 for years in the current code.
 
 Try a simpler experiment: "connect fxp0: dummy lower" and you should
 see ALL packets, including IPX packets.
 
 > A> To preserve the existing behavior, the node would need to duplicate
 > A> the orphanable packets and send them to BOTH connected hooks.
 > 
 > So behavior didn't change. Even we have found some inexactitude in
 > manpage.
 
 The current behavior is: if node X is connected to 'lower', then
 ALL packets received from the hardware are delivered to node X.
 It appears you have changed this (?)
 
 -Archie
 
 __________________________________________________________________________
 Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

From: Gleb Smirnoff <glebius@cell.sick.ru>
To: Archie Cobbs <archie@dellroad.org>
Cc: Maxim Konovalov <maxim@macomnet.ru>,
	bzeeb-lists@lists.zabbadoz.net, FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/63317: make ng_ether(4) support "lower" and "orphans"simultaneously
Date: Wed, 28 Apr 2004 11:00:42 +0400

 On Tue, Apr 27, 2004 at 09:18:58AM -0500, Archie Cobbs wrote:
 A> > It is said in current manpage, that ng_ether sends all packets to lower,
 A> > however code reveals the truth. Here is a sniplet from ng_ether_input_orphan(),
 A> > which is a hook called by ethernet stack:
 A> > 
 A> >         /* If "orphan" hook not connected, let packet continue */
 A> >         if (priv->lower == NULL || !priv->lowerOrphan) {
 A> >                 m_freem(m);
 A> >                 return;
 A> >         }
 A> 
 A> What is your point? This function is only called for orphan packets.
 A> In the current code, if the 'lower' hook is connected, this function will
 A> never be called (all packets will get sent to 'lower') (note: in the current
 A> code, 'priv->lower' is used for both 'lower' and 'orphans' hooks).
 
 Yes, you are right. I've looked into if_ethersubr.c and understood this. Sorry.
 I have repeated my experiment, and it showed that all packets are received on lower.
 Yesterday it was a coincidence, that no IPX packet broadcasted during a minute.
 
 A> > A> To preserve the existing behavior, the node would need to duplicate
 A> > A> the orphanable packets and send them to BOTH connected hooks.
 
 What about this behavoir?
 
 - if lower is connected, send ALL packets to it (like now)
 - if orphans is connected send orphaned packets to it (like now)
 - if both are connected, send non-orphaned to lower and orphaned to orphans
 
 Since, the third option is not available now at all, we won't break any current
 configurations.
 
 -- 
 Totus tuus, Glebius.
 GLEBIUS-RIPN GLEB-RIPE

From: Gleb Smirnoff <glebius@cell.sick.ru>
To: Archie Cobbs <archie@dellroad.org>
Cc: Maxim Konovalov <maxim@macomnet.ru>,
	bzeeb-lists@lists.zabbadoz.net, FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/63317: make ng_ether(4) support "lower" and "orphans"simultaneously
Date: Wed, 28 Apr 2004 13:13:41 +0400

 On Mon, Apr 26, 2004 at 04:49:48PM -0500, Archie Cobbs wrote:
 A> To preserve the existing behavior, the node would need to duplicate
 A> the orphanable packets and send them to BOTH connected hooks.
 
 I have spent some time drawing relationship between if_ethersubr.c and
 ng_ether.c. Now, I have pointed out, that new node will preserve
 an old behavior in case of 'lower' or 'orphans' connected one at a
 time.
 
 In case of both 'lower' and 'orphans' hooks connected, the node
 will write ALL packets to 'lower', and no packets to 'orphans'.
 This may seem useless. However, packets received on 'upper' will
 travel to upper protocol stack, and those unrecognized will return
 on 'orphans'.
 
 This is useful when someone needs to sniff IP traffic into netgraph
 and use some "orphan" etherproto on the same interface. For example
 I use it for serving PPPoE, and counting raw IP traffic on the same
 interface. In this case a ng_tee node is put on top of ng_ether,
 connecting its 'lower' and 'upper' together.
 
 And you get IP traffic on tee's hooks, and orphaned packet on 'orphans'.
 
 Here is some ASCII art:
 
      ether stack    .     ng_ether                     .   netgraph
                     .                                  .
                     .                                  .
    ether_input()    . ,-- ng_ether_rcvdata() <------------ 'upper' -<--,
             |\      ./                                 .                \ ng_tee
             | \     /                                  .                /
             |  '---/----> ng_ether_input() --------------> 'lower' -->-`
             |     / .                                  .
             |    /  .                                  .
             |   /   .                                  .
             v  v    .                                  .
       ether_demux()-----> ng_ether_input_orphan() -------> 'orphans'
             |       .                                  .
             v
           upper
           stacks
 
 -- 
 Totus tuus, Glebius.
 GLEBIUS-RIPN GLEB-RIPE

From: "Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net>
To: Gleb Smirnoff <glebius@cell.sick.ru>
Cc: Archie Cobbs <archie@dellroad.org>,
	FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/63317: make ng_ether(4) support "lower" and "orphans"simultaneously
Date: Wed, 28 Apr 2004 09:41:15 +0000 (UTC)

 On Wed, 28 Apr 2004, Gleb Smirnoff wrote:
 
 > This is useful when someone needs to sniff IP traffic into netgraph
 
 i am using following patch for this (which got lately updated after
 man page cleanups ... hope it is still ok):
 
 http://sources.zabbadoz.net/freebsd/patchset/10005-net-netgraph-ether.diff
 
 -- 
 Bjoern A. Zeeb				bzeeb at Zabbadoz dot NeT
 56 69 73 69 74				http://www.zabbadoz.net/

From: Gleb Smirnoff <glebius@cell.sick.ru>
To: "Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net>
Cc: Archie Cobbs <archie@dellroad.org>,
	FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/63317: make ng_ether(4) support "lower" and "orphans"simultaneously
Date: Wed, 28 Apr 2004 14:28:59 +0400

 On Wed, Apr 28, 2004 at 09:41:15AM +0000, Bjoern A. Zeeb wrote:
 B> On Wed, 28 Apr 2004, Gleb Smirnoff wrote:
 B> 
 B> > This is useful when someone needs to sniff IP traffic into netgraph
 B> 
 B> i am using following patch for this (which got lately updated after
 B> man page cleanups ... hope it is still ok):
 B> 
 B> http://sources.zabbadoz.net/freebsd/patchset/10005-net-netgraph-ether.diff
 
 Sorry, saying "sniff" I din't meant sniffing all in procmiscuous mode. I meant
 copy packets travelling thru interface to netgraph.
 
 -- 
 Totus tuus, Glebius.
 GLEBIUS-RIPN GLEB-RIPE

From: Gleb Smirnoff <glebius@cell.sick.ru>
To: Archie Cobbs <archie@dellroad.org>
Cc: Maxim Konovalov <maxim@macomnet.ru>,
	bzeeb-lists@lists.zabbadoz.net, FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/63317: make ng_ether(4) support "lower" and "orphans"simultaneously
Date: Wed, 28 Apr 2004 19:51:36 +0400

 On Wed, Apr 28, 2004 at 10:20:37AM -0500, Archie Cobbs wrote:
 A> Now we're back to my original question :-)
 A> 
 A> Ideally I think that we should duplicate packets when both hooks are connected.
 A> Here's the simple reason why: Today the following statements are true:
 A> 
 A>     1. If you connect to lower, you get ALL packets
 A>     2. If you connect to orphans, you get ALL orphan packets
 A> 
 A> We'd want both statements to continue to be true. Therefore, when both
 A> lower and orphans are connected, the node must duplicate orphan packets.
 A> 
 A> Unfortunately doing this is probably tricky because the determination of
 A> whether a packet is an orphan is done in if_ethersubr.c, not ng_ether.c.
 A> Same thing applies to your proposal above.
 
 Moreover it is not only tricky, it is dangerous. If we use a 'pass thru' node
 on top of ng_ether, then an orphaned packet goes into infinite loop passing
 upper,ether_demux(),lower. I have tried it and got a freezed machine :)
 
 A> Remember that lower gets packets before they go through ether_demux(),
 A> while orphans gets them after. So there's two different places where
 A> packets are intercepted by ng_ether for lower vs. orphans.
 A> 
 A> So I suggest a simpler (to implement) solution:
 A> 
 A> - if lower is connected, send ALL packets to it (like now)
 A> - if orphans is connected send orphaned packets to it (like now)
 A> - if both are connected, send ALL packets to lower
 A> 
 A> Note: in case #3 orhan packets written to upper will flow out of the
 A> orphans hook. So if the node connected to lower is a 'pass thru' to
 A> upper then the orphans hook will still see orphan packets!
 A> 
 A> To implement this, we simply remove the restriction that both orpans
 A> and lower can't be connected at the same time and keep all the existing
 A> logic the same as it is.
 
 Exactly this does the original patch. :)
 
 And we should also add to manpage:
 
 	Packets received on 'upper', and not recognized by upper level
 	stack are send back out of 'orphans' hook if it exists.
 
 -- 
 Totus tuus, Glebius.
 GLEBIUS-RIPN GLEB-RIPE
State-Changed-From-To: open->closed 
State-Changed-By: archie 
State-Changed-When: Sun May 16 12:33:18 PDT 2004 
State-Changed-Why:  
Support added in -current; -stable to follow in a couple of weeks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=63317 
>Unformatted:
