From owner-freebsd-net Sun Sep 17 17: 6:36 2000 Delivered-To: freebsd-net@freebsd.org Received: from whistle.com (s205m131.whistle.com [207.76.205.131]) by hub.freebsd.org (Postfix) with ESMTP id 8ECEA37B422 for ; Sun, 17 Sep 2000 17:06:33 -0700 (PDT) Received: (from smap@localhost) by whistle.com (8.10.0/8.10.0) id e8I06XD24619 for ; Sun, 17 Sep 2000 17:06:33 -0700 (PDT) Received: from bubba.whistle.com( 207.76.205.7) by whistle.com via smap (V2.0) id xma024616; Sun, 17 Sep 2000 17:06:04 -0700 Received: (from archie@localhost) by bubba.whistle.com (8.9.3/8.9.3) id RAA91358 for freebsd-net@freebsd.org; Sun, 17 Sep 2000 17:06:04 -0700 (PDT) (envelope-from archie) From: Archie Cobbs Message-Id: <200009180006.RAA91358@bubba.whistle.com> Subject: ng_bridge(4) patch.. To: freebsd-net@freebsd.org Date: Sun, 17 Sep 2000 17:06:04 -0700 (PDT) X-Mailer: ELM [version 2.4ME+ PL82 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org 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 #include +#include #include #include @@ -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