Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Sep 2000 17:06:04 -0700 (PDT)
From:      Archie Cobbs <archie@whistle.com>
To:        freebsd-net@freebsd.org
Subject:   ng_bridge(4) patch..
Message-ID:  <200009180006.RAA91358@bubba.whistle.com>

next in thread | raw e-mail | index | archive | help
To anyone who's playing with the new ng_bridge(4) node, here is an
untested patch that should quiet the ARP messages about receving
packets on the wrong interface; feedback warmly welcomed..

-Archie

___________________________________________________________________________
Archie Cobbs   *   Whistle Communications, Inc.  *   http://www.whistle.com

Index: ng_bridge.c
===================================================================
RCS file: /home/ncvs/src/sys/netgraph/ng_bridge.c,v
retrieving revision 1.1
diff -u -r1.1 ng_bridge.c
--- ng_bridge.c	2000/09/01 01:37:13	1.1
+++ ng_bridge.c	2000/09/18 00:04:27
@@ -68,6 +68,7 @@
 #include <sys/ctype.h>
 
 #include <net/if.h>
+#include <net/if_var.h>
 #include <net/ethernet.h>
 
 #include <netinet/in.h>
@@ -83,6 +84,7 @@
 struct ng_bridge_link {
 	hook_p				hook;		/* netgraph hook */
 	u_int16_t			loopCount;	/* loop ignore timer */
+	struct ifnet			*ifp;		/* ether interface */
 	struct ng_bridge_link_stats	stats;		/* link stats */
 };
 
@@ -115,6 +117,7 @@
 static ng_shutdown_t	ng_bridge_rmnode;
 static ng_newhook_t	ng_bridge_newhook;
 static ng_rcvdata_t	ng_bridge_rcvdata;
+static ng_connect_t	ng_bridge_connect;
 static ng_disconnect_t	ng_bridge_disconnect;
 
 /* Other internal functions */
@@ -274,7 +277,7 @@
 	ng_bridge_rmnode,
 	ng_bridge_newhook,
 	NULL,
-	NULL,
+	ng_bridge_connect,
 	ng_bridge_rcvdata,
 	ng_bridge_rcvdata,
 	ng_bridge_disconnect,
@@ -373,6 +376,44 @@
 }
 
 /*
+ * Final confirmation of hook connection. At this point we identify
+ * the peer node, and set a flag if it's an ng_ether(4) node and
+ * we're connected to it's "upper" hook. This is so we can make
+ * mbuf's sent to the peer all appear as if they arrived on the
+ * Ethernet interface. This avoids annoying ARP messages complaining
+ * about ARP packets arriving on the wrong interface.
+ */
+static int
+ng_bridge_connect(hook_p hook)
+{
+	const node_p node = hook->node;
+	const node_p peer = hook->peer->node;
+	const priv_p priv = node->private;
+	const int linkNum = LINK_NUM(hook);
+
+	/* Check for ng_ether(4) "upper" hook */
+	if (strcmp(peer->type->name, NG_ETHER_NODE_TYPE) == 0
+	    && strcmp(hook->peer->name, NG_ETHER_HOOK_UPPER) == 0) {
+		struct ng_mesg *msg, *resp = NULL;
+		char path[32];
+
+		snprintf(path, sizeof(path),
+		    "[%lx]:", (u_long)ng_node2ID(peer));
+		NG_MKMESSAGE(msg, NGM_ETHER_COOKIE,
+		    NGM_ETHER_GET_IFNAME, 0, M_NOWAIT);
+		if (msg == NULL)
+			return (ENOMEM);
+		if (ng_send_msg(node, msg, path, &resp) != 0)
+			return (0);
+		if (resp != NULL) {
+			priv->links[linkNum]->ifp = ifunit((char *)resp->data);
+			FREE(resp, M_NETGRAPH);
+		}
+	}
+	return (0);
+}
+
+/*
  * Receive a control message
  */
 static int
@@ -649,6 +690,10 @@
 				return (0);
 			}
 
+			/* Modify packet's receive interface if appropriate */
+			if (destLink->ifp != NULL)
+				m->m_pkthdr.rcvif = destLink->ifp;
+
 			/* Deliver packet out the destination link */
 			destLink->stats.xmitPackets++;
 			destLink->stats.xmitOctets += m->m_pkthdr.len;
@@ -703,6 +748,10 @@
 			destLink->stats.xmitBroadcasts++;
 			break;
 		}
+
+		/* Modify packet's receive interface if appropriate */
+		if (destLink->ifp != NULL)
+			m->m_pkthdr.rcvif = destLink->ifp;
 
 		/* Send packet */
 		NG_SEND_DATA(error, destLink->hook, m2, meta2);


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200009180006.RAA91358>