2000-06-26 23:34:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ng_ether.c
|
2005-01-07 01:45:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
2000-06-26 23:34:54 +00:00
|
|
|
* Copyright (c) 1996-2000 Whistle Communications, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Subject to the following obligations and disclaimer of warranty, use and
|
|
|
|
* redistribution of this software, in source or object code forms, with or
|
|
|
|
* without modifications are expressly permitted by Whistle Communications;
|
|
|
|
* provided, however, that:
|
|
|
|
* 1. Any and all reproductions of the source or object code must include the
|
|
|
|
* copyright notice above and the following disclaimer of warranties; and
|
|
|
|
* 2. No rights are granted, in any manner or form, to use Whistle
|
|
|
|
* Communications, Inc. trademarks, including the mark "WHISTLE
|
|
|
|
* COMMUNICATIONS" on advertising, endorsements, or otherwise except as
|
|
|
|
* such appears in the above copyright notice or in the software.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
|
|
|
|
* TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
|
|
|
|
* REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
|
|
|
|
* INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
|
|
|
|
* WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
|
|
|
|
* REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
|
|
|
|
* SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
|
|
|
|
* IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
|
|
|
|
* RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
|
|
|
|
* WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
|
|
* PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
|
|
|
|
* OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Authors: Archie Cobbs <archie@freebsd.org>
|
|
|
|
* Julian Elischer <julian@freebsd.org>
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ng_ether(4) netgraph node type
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/socket.h>
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
#include <sys/vimage.h>
|
2000-06-26 23:34:54 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
2005-02-12 11:41:32 +00:00
|
|
|
#include <net/if_dl.h>
|
2000-06-26 23:34:54 +00:00
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/if_var.h>
|
|
|
|
#include <net/ethernet.h>
|
2005-10-14 02:38:47 +00:00
|
|
|
#include <net/if_bridgevar.h>
|
2008-12-02 21:37:28 +00:00
|
|
|
#include <net/vnet.h>
|
2000-06-26 23:34:54 +00:00
|
|
|
|
|
|
|
#include <netgraph/ng_message.h>
|
|
|
|
#include <netgraph/netgraph.h>
|
|
|
|
#include <netgraph/ng_parse.h>
|
|
|
|
#include <netgraph/ng_ether.h>
|
|
|
|
|
2005-11-09 13:34:43 +00:00
|
|
|
#define IFP2NG(ifp) (IFP2AC((ifp))->ac_netgraph)
|
2000-06-26 23:34:54 +00:00
|
|
|
|
2009-04-26 07:14:50 +00:00
|
|
|
static vnet_attach_fn ng_ether_iattach;
|
|
|
|
|
|
|
|
#ifndef VIMAGE_GLOBALS
|
|
|
|
static vnet_modinfo_t vnet_ng_ether_modinfo = {
|
|
|
|
.vmi_id = VNET_MOD_NG_ETHER,
|
|
|
|
.vmi_name = "ng_ether",
|
|
|
|
.vmi_dependson = VNET_MOD_NETGRAPH,
|
|
|
|
.vmi_iattach = ng_ether_iattach,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2004-02-20 08:26:27 +00:00
|
|
|
/* Per-node private data */
|
|
|
|
struct private {
|
|
|
|
struct ifnet *ifp; /* associated interface */
|
|
|
|
hook_p upper; /* upper hook connection */
|
2004-05-16 19:31:35 +00:00
|
|
|
hook_p lower; /* lower hook connection */
|
|
|
|
hook_p orphan; /* orphan hook connection */
|
2004-02-20 08:26:27 +00:00
|
|
|
u_char autoSrcAddr; /* always overwrite source address */
|
|
|
|
u_char promisc; /* promiscuous mode enabled */
|
|
|
|
u_long hwassist; /* hardware checksum capabilities */
|
|
|
|
u_int flags; /* flags e.g. really die */
|
|
|
|
};
|
|
|
|
typedef struct private *priv_p;
|
2000-06-26 23:34:54 +00:00
|
|
|
|
2002-11-14 23:44:37 +00:00
|
|
|
/* Hook pointers used by if_ethersubr.c to callback to netgraph */
|
|
|
|
extern void (*ng_ether_input_p)(struct ifnet *ifp, struct mbuf **mp);
|
|
|
|
extern void (*ng_ether_input_orphan_p)(struct ifnet *ifp, struct mbuf *m);
|
|
|
|
extern int (*ng_ether_output_p)(struct ifnet *ifp, struct mbuf **mp);
|
|
|
|
extern void (*ng_ether_attach_p)(struct ifnet *ifp);
|
|
|
|
extern void (*ng_ether_detach_p)(struct ifnet *ifp);
|
2005-01-08 12:42:03 +00:00
|
|
|
extern void (*ng_ether_link_state_p)(struct ifnet *ifp, int state);
|
2002-11-14 23:44:37 +00:00
|
|
|
|
2000-06-26 23:34:54 +00:00
|
|
|
/* Functional hooks called from if_ethersubr.c */
|
2002-11-14 23:44:37 +00:00
|
|
|
static void ng_ether_input(struct ifnet *ifp, struct mbuf **mp);
|
|
|
|
static void ng_ether_input_orphan(struct ifnet *ifp, struct mbuf *m);
|
2000-06-26 23:34:54 +00:00
|
|
|
static int ng_ether_output(struct ifnet *ifp, struct mbuf **mp);
|
|
|
|
static void ng_ether_attach(struct ifnet *ifp);
|
|
|
|
static void ng_ether_detach(struct ifnet *ifp);
|
2005-01-08 12:42:03 +00:00
|
|
|
static void ng_ether_link_state(struct ifnet *ifp, int state);
|
2000-06-26 23:34:54 +00:00
|
|
|
|
|
|
|
/* Other functions */
|
2008-12-25 09:02:55 +00:00
|
|
|
static int ng_ether_rcv_lower(hook_p node, item_p item);
|
|
|
|
static int ng_ether_rcv_upper(hook_p node, item_p item);
|
2000-06-26 23:34:54 +00:00
|
|
|
|
|
|
|
/* Netgraph node methods */
|
|
|
|
static ng_constructor_t ng_ether_constructor;
|
|
|
|
static ng_rcvmsg_t ng_ether_rcvmsg;
|
2001-01-06 00:46:47 +00:00
|
|
|
static ng_shutdown_t ng_ether_shutdown;
|
2000-06-26 23:34:54 +00:00
|
|
|
static ng_newhook_t ng_ether_newhook;
|
|
|
|
static ng_rcvdata_t ng_ether_rcvdata;
|
|
|
|
static ng_disconnect_t ng_ether_disconnect;
|
|
|
|
static int ng_ether_mod_event(module_t mod, int event, void *data);
|
|
|
|
|
|
|
|
/* List of commands and how to convert arguments to/from ASCII */
|
|
|
|
static const struct ng_cmdlist ng_ether_cmdlist[] = {
|
|
|
|
{
|
|
|
|
NGM_ETHER_COOKIE,
|
|
|
|
NGM_ETHER_GET_IFNAME,
|
|
|
|
"getifname",
|
|
|
|
NULL,
|
|
|
|
&ng_parse_string_type
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGM_ETHER_COOKIE,
|
|
|
|
NGM_ETHER_GET_IFINDEX,
|
|
|
|
"getifindex",
|
|
|
|
NULL,
|
|
|
|
&ng_parse_int32_type
|
|
|
|
},
|
2000-08-07 18:52:26 +00:00
|
|
|
{
|
|
|
|
NGM_ETHER_COOKIE,
|
|
|
|
NGM_ETHER_GET_ENADDR,
|
|
|
|
"getenaddr",
|
|
|
|
NULL,
|
2003-12-17 12:40:34 +00:00
|
|
|
&ng_parse_enaddr_type
|
2000-08-07 18:52:26 +00:00
|
|
|
},
|
2000-08-15 01:05:50 +00:00
|
|
|
{
|
|
|
|
NGM_ETHER_COOKIE,
|
|
|
|
NGM_ETHER_SET_ENADDR,
|
|
|
|
"setenaddr",
|
2003-12-17 12:40:34 +00:00
|
|
|
&ng_parse_enaddr_type,
|
2000-08-15 01:05:50 +00:00
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGM_ETHER_COOKIE,
|
|
|
|
NGM_ETHER_GET_PROMISC,
|
|
|
|
"getpromisc",
|
|
|
|
NULL,
|
|
|
|
&ng_parse_int32_type
|
|
|
|
},
|
2000-08-07 18:52:26 +00:00
|
|
|
{
|
|
|
|
NGM_ETHER_COOKIE,
|
|
|
|
NGM_ETHER_SET_PROMISC,
|
|
|
|
"setpromisc",
|
|
|
|
&ng_parse_int32_type,
|
|
|
|
NULL
|
|
|
|
},
|
2000-08-15 01:05:50 +00:00
|
|
|
{
|
|
|
|
NGM_ETHER_COOKIE,
|
|
|
|
NGM_ETHER_GET_AUTOSRC,
|
|
|
|
"getautosrc",
|
|
|
|
NULL,
|
|
|
|
&ng_parse_int32_type
|
|
|
|
},
|
2000-08-07 18:52:26 +00:00
|
|
|
{
|
|
|
|
NGM_ETHER_COOKIE,
|
|
|
|
NGM_ETHER_SET_AUTOSRC,
|
|
|
|
"setautosrc",
|
|
|
|
&ng_parse_int32_type,
|
|
|
|
NULL
|
|
|
|
},
|
2005-02-12 11:41:32 +00:00
|
|
|
{
|
|
|
|
NGM_ETHER_COOKIE,
|
|
|
|
NGM_ETHER_ADD_MULTI,
|
|
|
|
"addmulti",
|
|
|
|
&ng_parse_enaddr_type,
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGM_ETHER_COOKIE,
|
|
|
|
NGM_ETHER_DEL_MULTI,
|
|
|
|
"delmulti",
|
|
|
|
&ng_parse_enaddr_type,
|
|
|
|
NULL
|
|
|
|
},
|
2005-02-14 12:01:09 +00:00
|
|
|
{
|
|
|
|
NGM_ETHER_COOKIE,
|
|
|
|
NGM_ETHER_DETACH,
|
|
|
|
"detach",
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
},
|
2000-06-26 23:34:54 +00:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct ng_type ng_ether_typestruct = {
|
2004-05-29 00:51:19 +00:00
|
|
|
.version = NG_ABI_VERSION,
|
|
|
|
.name = NG_ETHER_NODE_TYPE,
|
|
|
|
.mod_event = ng_ether_mod_event,
|
|
|
|
.constructor = ng_ether_constructor,
|
|
|
|
.rcvmsg = ng_ether_rcvmsg,
|
|
|
|
.shutdown = ng_ether_shutdown,
|
|
|
|
.newhook = ng_ether_newhook,
|
|
|
|
.rcvdata = ng_ether_rcvdata,
|
|
|
|
.disconnect = ng_ether_disconnect,
|
|
|
|
.cmdlist = ng_ether_cmdlist,
|
2000-06-26 23:34:54 +00:00
|
|
|
};
|
|
|
|
NETGRAPH_INIT(ether, &ng_ether_typestruct);
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
ETHERNET FUNCTION HOOKS
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle a packet that has come in on an interface. We get to
|
|
|
|
* look at it here before any upper layer protocols do.
|
|
|
|
*
|
|
|
|
* NOTE: this function will get called at splimp()
|
|
|
|
*/
|
|
|
|
static void
|
2002-11-14 23:44:37 +00:00
|
|
|
ng_ether_input(struct ifnet *ifp, struct mbuf **mp)
|
2000-06-26 23:34:54 +00:00
|
|
|
{
|
|
|
|
const node_p node = IFP2NG(ifp);
|
2001-01-08 05:34:06 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
2004-05-16 19:31:35 +00:00
|
|
|
int error;
|
2000-06-26 23:34:54 +00:00
|
|
|
|
|
|
|
/* If "lower" hook not connected, let packet continue */
|
2004-05-16 19:31:35 +00:00
|
|
|
if (priv->lower == NULL)
|
2000-06-26 23:34:54 +00:00
|
|
|
return;
|
2004-05-16 19:31:35 +00:00
|
|
|
NG_SEND_DATA_ONLY(error, priv->lower, *mp); /* sets *mp = NULL */
|
2000-06-26 23:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle a packet that has come in on an interface, and which
|
|
|
|
* does not match any of our known protocols (an ``orphan'').
|
|
|
|
*
|
|
|
|
* NOTE: this function will get called at splimp()
|
|
|
|
*/
|
|
|
|
static void
|
2002-11-14 23:44:37 +00:00
|
|
|
ng_ether_input_orphan(struct ifnet *ifp, struct mbuf *m)
|
2000-06-26 23:34:54 +00:00
|
|
|
{
|
|
|
|
const node_p node = IFP2NG(ifp);
|
2001-01-08 05:34:06 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
2004-05-16 19:31:35 +00:00
|
|
|
int error;
|
2000-06-26 23:34:54 +00:00
|
|
|
|
2004-05-16 19:31:35 +00:00
|
|
|
/* If "orphan" hook not connected, discard packet */
|
|
|
|
if (priv->orphan == NULL) {
|
2000-06-26 23:34:54 +00:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
2004-05-16 19:31:35 +00:00
|
|
|
NG_SEND_DATA_ONLY(error, priv->orphan, m);
|
2000-06-26 23:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle a packet that is going out on an interface.
|
|
|
|
* The Ethernet header is already attached to the mbuf.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_ether_output(struct ifnet *ifp, struct mbuf **mp)
|
|
|
|
{
|
|
|
|
const node_p node = IFP2NG(ifp);
|
2001-01-08 05:34:06 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
2000-06-26 23:34:54 +00:00
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
/* If "upper" hook not connected, let packet continue */
|
|
|
|
if (priv->upper == NULL)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Send it out "upper" hook */
|
Introduce a mechanism for detecting calls from outbound path of the
network stack when reentering the inbound path from netgraph, and
force queueing of mbufs at the outbound netgraph node.
The mechanism relies on two components. First, in netgraph nodes
where outbound path of the network stack calls into netgraph, the
current thread has to be appropriately marked using the new
NG_OUTBOUND_THREAD_REF() macro before proceeding to call further
into the netgraph topology, and unmarked using the
NG_OUTBOUND_THREAD_UNREF() macro before returning to the caller.
Second, netgraph nodes which can potentially reenter the network
stack in the inbound path have to mark their inbound hooks using
NG_HOOK_SET_TO_INBOUND() macro. The netgraph framework will then
detect when there is a danger of a call graph looping back from
outbound to inbound path via netgraph, and defer handing off the
mbufs to the "inbound" node to a worker thread with a clean stack.
In this first pass only the most obvious netgraph nodes have been
updated to ensure no outbound to inbound calls can occur. Nodes
such as ng_ipfw, ng_gif etc. should be further examined whether a
potential for outbound to inbound call looping exists.
This commit changes the layout of struct thread, but due to
__FreeBSD_version number shortage a version bump has been omitted
at this time, nevertheless kernel and modules have to be rebuilt.
Reviewed by: julian, rwatson, bz
Approved by: julian (mentor)
2009-06-11 16:50:49 +00:00
|
|
|
NG_OUTBOUND_THREAD_REF();
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_SEND_DATA_ONLY(error, priv->upper, *mp);
|
Introduce a mechanism for detecting calls from outbound path of the
network stack when reentering the inbound path from netgraph, and
force queueing of mbufs at the outbound netgraph node.
The mechanism relies on two components. First, in netgraph nodes
where outbound path of the network stack calls into netgraph, the
current thread has to be appropriately marked using the new
NG_OUTBOUND_THREAD_REF() macro before proceeding to call further
into the netgraph topology, and unmarked using the
NG_OUTBOUND_THREAD_UNREF() macro before returning to the caller.
Second, netgraph nodes which can potentially reenter the network
stack in the inbound path have to mark their inbound hooks using
NG_HOOK_SET_TO_INBOUND() macro. The netgraph framework will then
detect when there is a danger of a call graph looping back from
outbound to inbound path via netgraph, and defer handing off the
mbufs to the "inbound" node to a worker thread with a clean stack.
In this first pass only the most obvious netgraph nodes have been
updated to ensure no outbound to inbound calls can occur. Nodes
such as ng_ipfw, ng_gif etc. should be further examined whether a
potential for outbound to inbound call looping exists.
This commit changes the layout of struct thread, but due to
__FreeBSD_version number shortage a version bump has been omitted
at this time, nevertheless kernel and modules have to be rebuilt.
Reviewed by: julian, rwatson, bz
Approved by: julian (mentor)
2009-06-11 16:50:49 +00:00
|
|
|
NG_OUTBOUND_THREAD_UNREF();
|
2000-06-26 23:34:54 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A new Ethernet interface has been attached.
|
|
|
|
* Create a new node for it, etc.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ng_ether_attach(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
priv_p priv;
|
|
|
|
node_p node;
|
|
|
|
|
2009-04-26 07:14:50 +00:00
|
|
|
/*
|
|
|
|
* Do not create / attach an ether node to this ifnet if
|
|
|
|
* a netgraph node with the same name already exists.
|
|
|
|
* This should prevent ether nodes to become attached to
|
|
|
|
* eiface nodes, which may be problematic due to naming
|
|
|
|
* clashes.
|
|
|
|
*/
|
|
|
|
if ((node = ng_name2noderef(NULL, ifp->if_xname)) != NULL) {
|
|
|
|
NG_NODE_UNREF(node);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-26 23:34:54 +00:00
|
|
|
/* Create node */
|
2001-12-10 08:09:49 +00:00
|
|
|
KASSERT(!IFP2NG(ifp), ("%s: node already exists?", __func__));
|
2000-06-26 23:34:54 +00:00
|
|
|
if (ng_make_node_common(&ng_ether_typestruct, &node) != 0) {
|
|
|
|
log(LOG_ERR, "%s: can't %s for %s\n",
|
2003-10-31 18:32:15 +00:00
|
|
|
__func__, "create node", ifp->if_xname);
|
2000-06-26 23:34:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate private data */
|
2008-10-23 15:53:51 +00:00
|
|
|
priv = malloc(sizeof(*priv), M_NETGRAPH, M_NOWAIT | M_ZERO);
|
2000-06-26 23:34:54 +00:00
|
|
|
if (priv == NULL) {
|
|
|
|
log(LOG_ERR, "%s: can't %s for %s\n",
|
2003-10-31 18:32:15 +00:00
|
|
|
__func__, "allocate memory", ifp->if_xname);
|
2001-01-08 05:34:06 +00:00
|
|
|
NG_NODE_UNREF(node);
|
2000-06-26 23:34:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-01-08 05:34:06 +00:00
|
|
|
NG_NODE_SET_PRIVATE(node, priv);
|
2000-06-26 23:34:54 +00:00
|
|
|
priv->ifp = ifp;
|
2005-11-09 13:34:43 +00:00
|
|
|
IFP2NG(ifp) = node;
|
2002-02-05 18:27:30 +00:00
|
|
|
priv->hwassist = ifp->if_hwassist;
|
2000-06-26 23:34:54 +00:00
|
|
|
|
|
|
|
/* Try to give the node the same name as the interface */
|
2003-10-31 18:32:15 +00:00
|
|
|
if (ng_name_node(node, ifp->if_xname) != 0) {
|
2000-06-26 23:34:54 +00:00
|
|
|
log(LOG_WARNING, "%s: can't name node %s\n",
|
2003-10-31 18:32:15 +00:00
|
|
|
__func__, ifp->if_xname);
|
2000-06-26 23:34:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An Ethernet interface is being detached.
|
2001-01-30 20:51:52 +00:00
|
|
|
* REALLY Destroy its node.
|
2000-06-26 23:34:54 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ng_ether_detach(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
const node_p node = IFP2NG(ifp);
|
2001-01-30 20:51:52 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
2000-06-26 23:34:54 +00:00
|
|
|
|
2001-01-30 20:51:52 +00:00
|
|
|
NG_NODE_REALLY_DIE(node); /* Force real removal of node */
|
|
|
|
/*
|
|
|
|
* We can't assume the ifnet is still around when we run shutdown
|
|
|
|
* So zap it now. XXX We HOPE that anything running at this time
|
|
|
|
* handles it (as it should in the non netgraph case).
|
|
|
|
*/
|
2005-11-09 13:34:43 +00:00
|
|
|
IFP2NG(ifp) = NULL;
|
2001-01-30 20:51:52 +00:00
|
|
|
priv->ifp = NULL; /* XXX race if interrupted an output packet */
|
|
|
|
ng_rmnode_self(node); /* remove all netgraph parts */
|
2000-06-26 23:34:54 +00:00
|
|
|
}
|
|
|
|
|
2005-01-08 12:42:03 +00:00
|
|
|
/*
|
|
|
|
* Notify graph about link event.
|
|
|
|
* if_link_state_change() has already checked that the state has changed.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ng_ether_link_state(struct ifnet *ifp, int state)
|
|
|
|
{
|
|
|
|
const node_p node = IFP2NG(ifp);
|
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
|
|
|
struct ng_mesg *msg;
|
|
|
|
int cmd, dummy_error = 0;
|
|
|
|
|
|
|
|
if (priv->lower == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (state == LINK_STATE_UP)
|
|
|
|
cmd = NGM_LINK_IS_UP;
|
|
|
|
else if (state == LINK_STATE_DOWN)
|
|
|
|
cmd = NGM_LINK_IS_DOWN;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
NG_MKMESSAGE(msg, NGM_FLOW_COOKIE, cmd, 0, M_NOWAIT);
|
|
|
|
if (msg != NULL)
|
|
|
|
NG_SEND_MSG_HOOK(dummy_error, node, msg, priv->lower, 0);
|
|
|
|
}
|
|
|
|
|
2000-06-26 23:34:54 +00:00
|
|
|
/******************************************************************
|
|
|
|
NETGRAPH NODE METHODS
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It is not possible or allowable to create a node of this type.
|
|
|
|
* Nodes get created when the interface is attached (or, when
|
|
|
|
* this node type's KLD is loaded).
|
|
|
|
*/
|
|
|
|
static int
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_ether_constructor(node_p node)
|
2000-06-26 23:34:54 +00:00
|
|
|
{
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for attaching a new hook.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_ether_newhook(node_p node, hook_p hook, const char *name)
|
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
2000-06-26 23:34:54 +00:00
|
|
|
hook_p *hookptr;
|
|
|
|
|
|
|
|
/* Divert hook is an alias for lower */
|
|
|
|
if (strcmp(name, NG_ETHER_HOOK_DIVERT) == 0)
|
|
|
|
name = NG_ETHER_HOOK_LOWER;
|
|
|
|
|
|
|
|
/* Which hook? */
|
2008-12-25 09:02:55 +00:00
|
|
|
if (strcmp(name, NG_ETHER_HOOK_UPPER) == 0) {
|
2000-06-26 23:34:54 +00:00
|
|
|
hookptr = &priv->upper;
|
2008-12-25 09:02:55 +00:00
|
|
|
NG_HOOK_SET_RCVDATA(hook, ng_ether_rcv_upper);
|
Introduce a mechanism for detecting calls from outbound path of the
network stack when reentering the inbound path from netgraph, and
force queueing of mbufs at the outbound netgraph node.
The mechanism relies on two components. First, in netgraph nodes
where outbound path of the network stack calls into netgraph, the
current thread has to be appropriately marked using the new
NG_OUTBOUND_THREAD_REF() macro before proceeding to call further
into the netgraph topology, and unmarked using the
NG_OUTBOUND_THREAD_UNREF() macro before returning to the caller.
Second, netgraph nodes which can potentially reenter the network
stack in the inbound path have to mark their inbound hooks using
NG_HOOK_SET_TO_INBOUND() macro. The netgraph framework will then
detect when there is a danger of a call graph looping back from
outbound to inbound path via netgraph, and defer handing off the
mbufs to the "inbound" node to a worker thread with a clean stack.
In this first pass only the most obvious netgraph nodes have been
updated to ensure no outbound to inbound calls can occur. Nodes
such as ng_ipfw, ng_gif etc. should be further examined whether a
potential for outbound to inbound call looping exists.
This commit changes the layout of struct thread, but due to
__FreeBSD_version number shortage a version bump has been omitted
at this time, nevertheless kernel and modules have to be rebuilt.
Reviewed by: julian, rwatson, bz
Approved by: julian (mentor)
2009-06-11 16:50:49 +00:00
|
|
|
NG_HOOK_SET_TO_INBOUND(hook);
|
2008-12-25 09:02:55 +00:00
|
|
|
} else if (strcmp(name, NG_ETHER_HOOK_LOWER) == 0) {
|
2000-06-26 23:34:54 +00:00
|
|
|
hookptr = &priv->lower;
|
2008-12-25 09:02:55 +00:00
|
|
|
NG_HOOK_SET_RCVDATA(hook, ng_ether_rcv_lower);
|
|
|
|
} else if (strcmp(name, NG_ETHER_HOOK_ORPHAN) == 0) {
|
2004-05-16 19:31:35 +00:00
|
|
|
hookptr = &priv->orphan;
|
2008-12-25 09:02:55 +00:00
|
|
|
NG_HOOK_SET_RCVDATA(hook, ng_ether_rcv_lower);
|
|
|
|
} else
|
2000-06-26 23:34:54 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* Check if already connected (shouldn't be, but doesn't hurt) */
|
|
|
|
if (*hookptr != NULL)
|
|
|
|
return (EISCONN);
|
|
|
|
|
2002-02-05 18:27:30 +00:00
|
|
|
/* Disable hardware checksums while 'upper' hook is connected */
|
|
|
|
if (hookptr == &priv->upper)
|
|
|
|
priv->ifp->if_hwassist = 0;
|
2009-06-23 12:30:21 +00:00
|
|
|
NG_HOOK_HI_STACK(hook);
|
2000-06-26 23:34:54 +00:00
|
|
|
/* OK */
|
|
|
|
*hookptr = hook;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive an incoming control message.
|
|
|
|
*/
|
|
|
|
static int
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_ether_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
2000-06-26 23:34:54 +00:00
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
2000-06-26 23:34:54 +00:00
|
|
|
struct ng_mesg *resp = NULL;
|
|
|
|
int error = 0;
|
2001-01-06 00:46:47 +00:00
|
|
|
struct ng_mesg *msg;
|
2000-06-26 23:34:54 +00:00
|
|
|
|
2001-01-06 00:46:47 +00:00
|
|
|
NGI_GET_MSG(item, msg);
|
2000-06-26 23:34:54 +00:00
|
|
|
switch (msg->header.typecookie) {
|
|
|
|
case NGM_ETHER_COOKIE:
|
|
|
|
switch (msg->header.cmd) {
|
|
|
|
case NGM_ETHER_GET_IFNAME:
|
2005-02-03 12:50:10 +00:00
|
|
|
NG_MKRESPONSE(resp, msg, IFNAMSIZ, M_NOWAIT);
|
2000-06-26 23:34:54 +00:00
|
|
|
if (resp == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2005-02-03 12:50:10 +00:00
|
|
|
strlcpy(resp->data, priv->ifp->if_xname, IFNAMSIZ);
|
2000-06-26 23:34:54 +00:00
|
|
|
break;
|
|
|
|
case NGM_ETHER_GET_IFINDEX:
|
|
|
|
NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT);
|
|
|
|
if (resp == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*((u_int32_t *)resp->data) = priv->ifp->if_index;
|
|
|
|
break;
|
2000-08-07 18:52:26 +00:00
|
|
|
case NGM_ETHER_GET_ENADDR:
|
|
|
|
NG_MKRESPONSE(resp, msg, ETHER_ADDR_LEN, M_NOWAIT);
|
|
|
|
if (resp == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2005-11-11 16:04:59 +00:00
|
|
|
bcopy(IF_LLADDR(priv->ifp),
|
2000-08-07 18:52:26 +00:00
|
|
|
resp->data, ETHER_ADDR_LEN);
|
|
|
|
break;
|
2000-08-15 01:05:50 +00:00
|
|
|
case NGM_ETHER_SET_ENADDR:
|
|
|
|
{
|
|
|
|
if (msg->header.arglen != ETHER_ADDR_LEN) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = if_setlladdr(priv->ifp,
|
|
|
|
(u_char *)msg->data, ETHER_ADDR_LEN);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NGM_ETHER_GET_PROMISC:
|
|
|
|
NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT);
|
|
|
|
if (resp == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*((u_int32_t *)resp->data) = priv->promisc;
|
|
|
|
break;
|
2000-08-07 18:52:26 +00:00
|
|
|
case NGM_ETHER_SET_PROMISC:
|
|
|
|
{
|
|
|
|
u_char want;
|
|
|
|
|
|
|
|
if (msg->header.arglen != sizeof(u_int32_t)) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
want = !!*((u_int32_t *)msg->data);
|
|
|
|
if (want ^ priv->promisc) {
|
|
|
|
if ((error = ifpromisc(priv->ifp, want)) != 0)
|
|
|
|
break;
|
|
|
|
priv->promisc = want;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2000-08-15 01:05:50 +00:00
|
|
|
case NGM_ETHER_GET_AUTOSRC:
|
|
|
|
NG_MKRESPONSE(resp, msg, sizeof(u_int32_t), M_NOWAIT);
|
|
|
|
if (resp == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*((u_int32_t *)resp->data) = priv->autoSrcAddr;
|
|
|
|
break;
|
2000-08-07 18:52:26 +00:00
|
|
|
case NGM_ETHER_SET_AUTOSRC:
|
|
|
|
if (msg->header.arglen != sizeof(u_int32_t)) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
priv->autoSrcAddr = !!*((u_int32_t *)msg->data);
|
|
|
|
break;
|
2005-02-12 11:41:32 +00:00
|
|
|
case NGM_ETHER_ADD_MULTI:
|
|
|
|
{
|
|
|
|
struct sockaddr_dl sa_dl;
|
2007-03-20 00:36:10 +00:00
|
|
|
struct ifmultiaddr *ifma;
|
2005-02-12 11:41:32 +00:00
|
|
|
|
|
|
|
if (msg->header.arglen != ETHER_ADDR_LEN) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2005-02-12 19:19:29 +00:00
|
|
|
bzero(&sa_dl, sizeof(struct sockaddr_dl));
|
2005-02-12 11:41:32 +00:00
|
|
|
sa_dl.sdl_len = sizeof(struct sockaddr_dl);
|
|
|
|
sa_dl.sdl_family = AF_LINK;
|
2005-02-12 19:19:29 +00:00
|
|
|
sa_dl.sdl_alen = ETHER_ADDR_LEN;
|
2005-02-12 11:41:32 +00:00
|
|
|
bcopy((void *)msg->data, LLADDR(&sa_dl),
|
|
|
|
ETHER_ADDR_LEN);
|
2007-03-20 00:36:10 +00:00
|
|
|
/*
|
|
|
|
* Netgraph is only permitted to join groups once
|
|
|
|
* via the if_addmulti() KPI, because it cannot hold
|
|
|
|
* struct ifmultiaddr * between calls. It may also
|
|
|
|
* lose a race while we check if the membership
|
|
|
|
* already exists.
|
|
|
|
*/
|
2009-06-26 11:45:06 +00:00
|
|
|
if_maddr_rlock(priv->ifp);
|
2007-03-20 00:36:10 +00:00
|
|
|
ifma = if_findmulti(priv->ifp,
|
|
|
|
(struct sockaddr *)&sa_dl);
|
2009-06-26 11:45:06 +00:00
|
|
|
if_maddr_runlock(priv->ifp);
|
2007-03-20 00:36:10 +00:00
|
|
|
if (ifma != NULL) {
|
|
|
|
error = EADDRINUSE;
|
|
|
|
} else {
|
|
|
|
error = if_addmulti(priv->ifp,
|
|
|
|
(struct sockaddr *)&sa_dl, &ifma);
|
|
|
|
}
|
2005-02-12 11:41:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NGM_ETHER_DEL_MULTI:
|
|
|
|
{
|
|
|
|
struct sockaddr_dl sa_dl;
|
|
|
|
|
|
|
|
if (msg->header.arglen != ETHER_ADDR_LEN) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2005-02-12 19:19:29 +00:00
|
|
|
bzero(&sa_dl, sizeof(struct sockaddr_dl));
|
2005-02-12 11:41:32 +00:00
|
|
|
sa_dl.sdl_len = sizeof(struct sockaddr_dl);
|
|
|
|
sa_dl.sdl_family = AF_LINK;
|
2005-02-12 19:19:29 +00:00
|
|
|
sa_dl.sdl_alen = ETHER_ADDR_LEN;
|
2005-02-12 11:41:32 +00:00
|
|
|
bcopy((void *)msg->data, LLADDR(&sa_dl),
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
error = if_delmulti(priv->ifp,
|
|
|
|
(struct sockaddr *)&sa_dl);
|
|
|
|
break;
|
|
|
|
}
|
2005-02-14 12:01:09 +00:00
|
|
|
case NGM_ETHER_DETACH:
|
|
|
|
ng_ether_detach(priv->ifp);
|
|
|
|
break;
|
2000-06-26 23:34:54 +00:00
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_RESPOND_MSG(error, node, item, resp);
|
|
|
|
NG_FREE_MSG(msg);
|
2000-06-26 23:34:54 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive data on a hook.
|
2008-12-25 09:02:55 +00:00
|
|
|
* Since we use per-hook recveive methods this should never be called.
|
2000-06-26 23:34:54 +00:00
|
|
|
*/
|
|
|
|
static int
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_ether_rcvdata(hook_p hook, item_p item)
|
2000-06-26 23:34:54 +00:00
|
|
|
{
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_FREE_ITEM(item);
|
2004-06-26 22:24:16 +00:00
|
|
|
|
2001-12-10 08:09:49 +00:00
|
|
|
panic("%s: weird hook", __func__);
|
2004-05-16 19:31:35 +00:00
|
|
|
#ifdef RESTARTABLE_PANICS /* so we don't get an error msg in LINT */
|
2004-10-09 14:20:18 +00:00
|
|
|
return (0);
|
2001-09-12 08:38:13 +00:00
|
|
|
#endif
|
2000-06-26 23:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-05-16 19:31:35 +00:00
|
|
|
* Handle an mbuf received on the "lower" or "orphan" hook.
|
2000-06-26 23:34:54 +00:00
|
|
|
*/
|
|
|
|
static int
|
2008-12-25 09:02:55 +00:00
|
|
|
ng_ether_rcv_lower(hook_p hook, item_p item)
|
2000-06-26 23:34:54 +00:00
|
|
|
{
|
2008-12-25 09:02:55 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
const node_p node = NG_HOOK_NODE(hook);
|
2001-01-08 05:34:06 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
2002-05-09 20:19:00 +00:00
|
|
|
struct ifnet *const ifp = priv->ifp;
|
|
|
|
|
2008-12-25 09:02:55 +00:00
|
|
|
NGI_GET_M(item, m);
|
|
|
|
NG_FREE_ITEM(item);
|
|
|
|
|
2002-05-09 20:19:00 +00:00
|
|
|
/* Check whether interface is ready for packets */
|
2008-12-25 09:02:55 +00:00
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
if (!((ifp->if_flags & IFF_UP) &&
|
|
|
|
(ifp->if_drv_flags & IFF_DRV_RUNNING))) {
|
2002-05-09 20:19:00 +00:00
|
|
|
NG_FREE_M(m);
|
|
|
|
return (ENETDOWN);
|
|
|
|
}
|
2000-06-26 23:34:54 +00:00
|
|
|
|
|
|
|
/* Make sure header is fully pulled up */
|
|
|
|
if (m->m_pkthdr.len < sizeof(struct ether_header)) {
|
2001-01-06 00:46:47 +00:00
|
|
|
NG_FREE_M(m);
|
2000-06-26 23:34:54 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if (m->m_len < sizeof(struct ether_header)
|
2002-06-05 23:32:56 +00:00
|
|
|
&& (m = m_pullup(m, sizeof(struct ether_header))) == NULL)
|
2000-06-26 23:34:54 +00:00
|
|
|
return (ENOBUFS);
|
|
|
|
|
2000-08-07 18:52:26 +00:00
|
|
|
/* Drop in the MAC address if desired */
|
|
|
|
if (priv->autoSrcAddr) {
|
2002-06-05 23:32:56 +00:00
|
|
|
|
|
|
|
/* Make the mbuf writable if it's not already */
|
|
|
|
if (!M_WRITABLE(m)
|
|
|
|
&& (m = m_pullup(m, sizeof(struct ether_header))) == NULL)
|
|
|
|
return (ENOBUFS);
|
|
|
|
|
|
|
|
/* Overwrite source MAC address */
|
2005-11-11 16:04:59 +00:00
|
|
|
bcopy(IF_LLADDR(ifp),
|
2000-08-07 18:52:26 +00:00
|
|
|
mtod(m, struct ether_header *)->ether_shost,
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
}
|
2000-07-06 15:35:59 +00:00
|
|
|
|
2000-06-26 23:34:54 +00:00
|
|
|
/* Send it on its way */
|
2002-05-09 20:19:00 +00:00
|
|
|
return ether_output_frame(ifp, m);
|
2000-06-26 23:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle an mbuf received on the "upper" hook.
|
|
|
|
*/
|
|
|
|
static int
|
2008-12-25 09:02:55 +00:00
|
|
|
ng_ether_rcv_upper(hook_p hook, item_p item)
|
2000-06-26 23:34:54 +00:00
|
|
|
{
|
2008-12-25 09:02:55 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
const node_p node = NG_HOOK_NODE(hook);
|
2001-01-08 05:34:06 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
2005-10-07 14:14:47 +00:00
|
|
|
struct ifnet *ifp = priv->ifp;
|
|
|
|
|
2008-12-25 09:02:55 +00:00
|
|
|
NGI_GET_M(item, m);
|
|
|
|
NG_FREE_ITEM(item);
|
|
|
|
|
2005-11-03 07:46:04 +00:00
|
|
|
/* Check length and pull off header */
|
|
|
|
if (m->m_pkthdr.len < sizeof(struct ether_header)) {
|
|
|
|
NG_FREE_M(m);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if (m->m_len < sizeof(struct ether_header) &&
|
|
|
|
(m = m_pullup(m, sizeof(struct ether_header))) == NULL)
|
|
|
|
return (ENOBUFS);
|
|
|
|
|
2005-10-07 14:14:47 +00:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
2000-06-26 23:34:54 +00:00
|
|
|
|
2005-10-14 02:38:47 +00:00
|
|
|
/* Pass the packet to the bridge, it may come back to us */
|
2005-10-07 14:14:47 +00:00
|
|
|
if (ifp->if_bridge) {
|
2005-10-14 02:38:47 +00:00
|
|
|
BRIDGE_INPUT(ifp, m);
|
2005-10-07 14:14:47 +00:00
|
|
|
if (m == NULL)
|
|
|
|
return (0);
|
|
|
|
}
|
2004-10-12 10:33:42 +00:00
|
|
|
|
2000-06-26 23:34:54 +00:00
|
|
|
/* Route packet back in */
|
2005-10-14 02:38:47 +00:00
|
|
|
ether_demux(ifp, m);
|
2000-06-26 23:34:54 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-01-30 20:51:52 +00:00
|
|
|
* Shutdown node. This resets the node but does not remove it
|
|
|
|
* unless the REALLY_DIE flag is set.
|
2000-06-26 23:34:54 +00:00
|
|
|
*/
|
|
|
|
static int
|
2001-01-06 00:46:47 +00:00
|
|
|
ng_ether_shutdown(node_p node)
|
2000-06-26 23:34:54 +00:00
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
2000-08-07 18:52:26 +00:00
|
|
|
|
2004-07-20 17:15:38 +00:00
|
|
|
if (node->nd_flags & NGF_REALLY_DIE) {
|
2001-01-30 20:51:52 +00:00
|
|
|
/*
|
|
|
|
* WE came here because the ethernet card is being unloaded,
|
|
|
|
* so stop being persistant.
|
|
|
|
* Actually undo all the things we did on creation.
|
|
|
|
* Assume the ifp has already been freed.
|
|
|
|
*/
|
|
|
|
NG_NODE_SET_PRIVATE(node, NULL);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(priv, M_NETGRAPH);
|
2001-01-30 20:51:52 +00:00
|
|
|
NG_NODE_UNREF(node); /* free node itself */
|
|
|
|
return (0);
|
2001-01-06 00:46:47 +00:00
|
|
|
}
|
2004-01-09 00:41:45 +00:00
|
|
|
if (priv->promisc) { /* disable promiscuous mode */
|
|
|
|
(void)ifpromisc(priv->ifp, 0);
|
|
|
|
priv->promisc = 0;
|
|
|
|
}
|
2000-08-07 18:52:26 +00:00
|
|
|
priv->autoSrcAddr = 1; /* reset auto-src-addr flag */
|
2004-07-20 17:15:38 +00:00
|
|
|
NG_NODE_REVIVE(node); /* Signal ng_rmnode we are persisant */
|
|
|
|
|
2000-06-26 23:34:54 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hook disconnection.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_ether_disconnect(hook_p hook)
|
|
|
|
{
|
2001-01-08 05:34:06 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
|
2000-06-26 23:34:54 +00:00
|
|
|
|
2002-02-05 18:27:30 +00:00
|
|
|
if (hook == priv->upper) {
|
2000-06-26 23:34:54 +00:00
|
|
|
priv->upper = NULL;
|
2004-01-09 02:03:24 +00:00
|
|
|
if (priv->ifp != NULL) /* restore h/w csum */
|
|
|
|
priv->ifp->if_hwassist = priv->hwassist;
|
2004-05-16 19:31:35 +00:00
|
|
|
} else if (hook == priv->lower)
|
2000-06-26 23:34:54 +00:00
|
|
|
priv->lower = NULL;
|
2004-05-16 19:31:35 +00:00
|
|
|
else if (hook == priv->orphan)
|
|
|
|
priv->orphan = NULL;
|
|
|
|
else
|
2001-12-10 08:09:49 +00:00
|
|
|
panic("%s: weird hook", __func__);
|
2001-01-08 05:34:06 +00:00
|
|
|
if ((NG_NODE_NUMHOOKS(NG_HOOK_NODE(hook)) == 0)
|
|
|
|
&& (NG_NODE_IS_VALID(NG_HOOK_NODE(hook))))
|
|
|
|
ng_rmnode_self(NG_HOOK_NODE(hook)); /* reset node */
|
2000-06-26 23:34:54 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
INITIALIZATION
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle loading and unloading for this node type.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_ether_mod_event(module_t mod, int event, void *data)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
switch (event) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
|
|
|
|
/* Register function hooks */
|
|
|
|
if (ng_ether_attach_p != NULL) {
|
|
|
|
error = EEXIST;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ng_ether_attach_p = ng_ether_attach;
|
|
|
|
ng_ether_detach_p = ng_ether_detach;
|
|
|
|
ng_ether_output_p = ng_ether_output;
|
|
|
|
ng_ether_input_p = ng_ether_input;
|
|
|
|
ng_ether_input_orphan_p = ng_ether_input_orphan;
|
2005-01-08 12:42:03 +00:00
|
|
|
ng_ether_link_state_p = ng_ether_link_state;
|
2000-06-26 23:34:54 +00:00
|
|
|
|
2009-04-26 07:14:50 +00:00
|
|
|
#ifndef VIMAGE_GLOBALS
|
|
|
|
vnet_mod_register(&vnet_ng_ether_modinfo);
|
|
|
|
#else
|
|
|
|
error = ng_ether_iattach(NULL);
|
|
|
|
#endif
|
2000-06-26 23:34:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that the base code won't try to unload us until
|
|
|
|
* all nodes have been removed, and that can't happen
|
|
|
|
* until all Ethernet interfaces are removed. In any
|
|
|
|
* case, we know there are no nodes left if the action
|
|
|
|
* is MOD_UNLOAD, so there's no need to detach any nodes.
|
|
|
|
*/
|
|
|
|
|
2009-04-26 07:14:50 +00:00
|
|
|
#ifndef VIMAGE_GLOBALS
|
|
|
|
vnet_mod_deregister(&vnet_ng_ether_modinfo);
|
|
|
|
#endif
|
|
|
|
|
2000-06-26 23:34:54 +00:00
|
|
|
/* Unregister function hooks */
|
|
|
|
ng_ether_attach_p = NULL;
|
|
|
|
ng_ether_detach_p = NULL;
|
|
|
|
ng_ether_output_p = NULL;
|
|
|
|
ng_ether_input_p = NULL;
|
|
|
|
ng_ether_input_orphan_p = NULL;
|
2005-01-08 12:42:03 +00:00
|
|
|
ng_ether_link_state_p = NULL;
|
2000-06-26 23:34:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2009-04-26 07:14:50 +00:00
|
|
|
static int ng_ether_iattach(const void *unused)
|
|
|
|
{
|
|
|
|
INIT_VNET_NET(curvnet);
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
/* Create nodes for any already-existing Ethernet interfaces. */
|
|
|
|
IFNET_RLOCK();
|
|
|
|
TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
|
|
|
|
if (ifp->if_type == IFT_ETHER
|
|
|
|
|| ifp->if_type == IFT_L2VLAN)
|
|
|
|
ng_ether_attach(ifp);
|
|
|
|
}
|
|
|
|
IFNET_RUNLOCK();
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|