2001-02-25 05:46:52 +00:00
|
|
|
/*-
|
|
|
|
*
|
|
|
|
* Copyright (c) 1999-2001, Vitaly V Belekhov
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice unmodified, this list of conditions, and the following
|
|
|
|
* disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON 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 ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/errno.h>
|
2009-08-01 19:26:27 +00:00
|
|
|
#include <sys/proc.h>
|
2001-02-25 05:46:52 +00:00
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
2011-05-24 14:10:33 +00:00
|
|
|
#include <net/if_media.h>
|
2001-02-25 05:46:52 +00:00
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/netisr.h>
|
2008-12-02 21:37:28 +00:00
|
|
|
#include <net/route.h>
|
Introduce and use a sysinit-based initialization scheme for virtual
network stacks, VNET_SYSINIT:
- Add VNET_SYSINIT and VNET_SYSUNINIT macros to declare events that will
occur each time a network stack is instantiated and destroyed. In the
!VIMAGE case, these are simply mapped into regular SYSINIT/SYSUNINIT.
For the VIMAGE case, we instead use SYSINIT's to track their order and
properties on registration, using them for each vnet when created/
destroyed, or immediately on module load for already-started vnets.
- Remove vnet_modinfo mechanism that existed to serve this purpose
previously, as well as its dependency scheme: we now just use the
SYSINIT ordering scheme.
- Implement VNET_DOMAIN_SET() to allow protocol domains to declare that
they want init functions to be called for each virtual network stack
rather than just once at boot, compiling down to DOMAIN_SET() in the
non-VIMAGE case.
- Walk all virtualized kernel subsystems and make use of these instead
of modinfo or DOMAIN_SET() for init/uninit events. In some cases,
convert modular components from using modevent to using sysinit (where
appropriate). In some cases, do minor rejuggling of SYSINIT ordering
to make room for or better manage events.
Portions submitted by: jhb (VNET_SYSINIT), bz (cleanup)
Discussed with: jhb, bz, julian, zec
Reviewed by: bz
Approved by: re (VIMAGE blanket)
2009-07-23 20:46:49 +00:00
|
|
|
#include <net/vnet.h>
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
#include <netgraph/ng_message.h>
|
|
|
|
#include <netgraph/netgraph.h>
|
|
|
|
#include <netgraph/ng_parse.h>
|
|
|
|
#include <netgraph/ng_eiface.h>
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
|
2001-02-25 16:49:04 +00:00
|
|
|
static const struct ng_cmdlist ng_eiface_cmdlist[] = {
|
2005-02-03 11:52:42 +00:00
|
|
|
{
|
|
|
|
NGM_EIFACE_COOKIE,
|
|
|
|
NGM_EIFACE_GET_IFNAME,
|
|
|
|
"getifname",
|
|
|
|
NULL,
|
|
|
|
&ng_parse_string_type
|
|
|
|
},
|
2001-02-25 16:49:04 +00:00
|
|
|
{
|
|
|
|
NGM_EIFACE_COOKIE,
|
|
|
|
NGM_EIFACE_SET,
|
|
|
|
"set",
|
2003-12-17 13:03:32 +00:00
|
|
|
&ng_parse_enaddr_type,
|
2001-02-25 16:49:04 +00:00
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
2001-02-25 05:46:52 +00:00
|
|
|
/* Node private data */
|
|
|
|
struct ng_eiface_private {
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp; /* per-interface network data */
|
2011-05-24 14:10:33 +00:00
|
|
|
struct ifmedia media; /* (fake) media information */
|
|
|
|
int link_status; /* fake */
|
2005-02-02 13:27:03 +00:00
|
|
|
int unit; /* Interface unit number */
|
|
|
|
node_p node; /* Our netgraph node */
|
|
|
|
hook_p ether; /* Hook for ethernet stream */
|
2001-02-25 05:46:52 +00:00
|
|
|
};
|
|
|
|
typedef struct ng_eiface_private *priv_p;
|
|
|
|
|
|
|
|
/* Interface methods */
|
2005-02-02 13:27:03 +00:00
|
|
|
static void ng_eiface_init(void *xsc);
|
|
|
|
static void ng_eiface_start(struct ifnet *ifp);
|
|
|
|
static int ng_eiface_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data);
|
2001-02-25 05:46:52 +00:00
|
|
|
#ifdef DEBUG
|
2005-02-02 13:27:03 +00:00
|
|
|
static void ng_eiface_print_ioctl(struct ifnet *ifp, int cmd, caddr_t data);
|
2001-02-25 05:46:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Netgraph methods */
|
2005-02-05 08:28:36 +00:00
|
|
|
static int ng_eiface_mod_event(module_t, int, void *);
|
2005-02-02 13:27:03 +00:00
|
|
|
static ng_constructor_t ng_eiface_constructor;
|
|
|
|
static ng_rcvmsg_t ng_eiface_rcvmsg;
|
|
|
|
static ng_shutdown_t ng_eiface_rmnode;
|
|
|
|
static ng_newhook_t ng_eiface_newhook;
|
|
|
|
static ng_rcvdata_t ng_eiface_rcvdata;
|
|
|
|
static ng_disconnect_t ng_eiface_disconnect;
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
/* Node type descriptor */
|
|
|
|
static struct ng_type typestruct = {
|
2004-05-29 00:51:19 +00:00
|
|
|
.version = NG_ABI_VERSION,
|
|
|
|
.name = NG_EIFACE_NODE_TYPE,
|
2005-02-05 08:28:36 +00:00
|
|
|
.mod_event = ng_eiface_mod_event,
|
2004-05-29 00:51:19 +00:00
|
|
|
.constructor = ng_eiface_constructor,
|
|
|
|
.rcvmsg = ng_eiface_rcvmsg,
|
|
|
|
.shutdown = ng_eiface_rmnode,
|
|
|
|
.newhook = ng_eiface_newhook,
|
|
|
|
.rcvdata = ng_eiface_rcvdata,
|
|
|
|
.disconnect = ng_eiface_disconnect,
|
|
|
|
.cmdlist = ng_eiface_cmdlist
|
2001-02-25 05:46:52 +00:00
|
|
|
};
|
|
|
|
NETGRAPH_INIT(eiface, &typestruct);
|
|
|
|
|
2010-11-22 19:32:54 +00:00
|
|
|
static VNET_DEFINE(struct unrhdr *, ng_eiface_unit);
|
2009-07-16 21:13:04 +00:00
|
|
|
#define V_ng_eiface_unit VNET(ng_eiface_unit)
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
INTERFACE STUFF
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl for the virtual interface
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_eiface_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
|
|
|
|
{
|
2011-05-24 14:10:33 +00:00
|
|
|
const priv_p priv = (priv_p)ifp->if_softc;
|
2005-02-02 13:27:03 +00:00
|
|
|
struct ifreq *const ifr = (struct ifreq *)data;
|
2012-10-18 13:57:24 +00:00
|
|
|
int error = 0;
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
ng_eiface_print_ioctl(ifp, command, data);
|
|
|
|
#endif
|
2005-02-02 13:27:03 +00:00
|
|
|
switch (command) {
|
|
|
|
|
2001-02-25 05:46:52 +00:00
|
|
|
/* These two are mostly handled at a higher layer */
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
error = ether_ioctl(ifp, command, data);
|
|
|
|
break;
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Set flags */
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
/*
|
2005-02-02 13:27:03 +00:00
|
|
|
* If the interface is marked up and stopped, then start it.
|
|
|
|
* If it is marked down and running, then stop it.
|
2001-02-25 05:46:52 +00:00
|
|
|
*/
|
2006-09-15 15:53:09 +00:00
|
|
|
if (ifp->if_flags & IFF_UP) {
|
2005-08-09 10:20:02 +00:00
|
|
|
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
|
|
|
|
ifp->if_drv_flags &= ~(IFF_DRV_OACTIVE);
|
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
2001-02-25 05:46:52 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING)
|
|
|
|
ifp->if_drv_flags &= ~(IFF_DRV_RUNNING |
|
|
|
|
IFF_DRV_OACTIVE);
|
2001-02-25 05:46:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Set the interface MTU */
|
|
|
|
case SIOCSIFMTU:
|
2005-02-02 13:27:03 +00:00
|
|
|
if (ifr->ifr_mtu > NG_EIFACE_MTU_MAX ||
|
|
|
|
ifr->ifr_mtu < NG_EIFACE_MTU_MIN)
|
2001-02-25 05:46:52 +00:00
|
|
|
error = EINVAL;
|
|
|
|
else
|
|
|
|
ifp->if_mtu = ifr->ifr_mtu;
|
|
|
|
break;
|
|
|
|
|
2011-05-24 14:10:33 +00:00
|
|
|
/* (Fake) media type manipulation */
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &priv->media, command);
|
|
|
|
break;
|
|
|
|
|
2001-02-25 05:46:52 +00:00
|
|
|
/* Stuff that's not supported */
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case SIOCSIFPHYS:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ng_eiface_init(void *xsc)
|
|
|
|
{
|
2005-02-02 13:27:03 +00:00
|
|
|
priv_p sc = xsc;
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
2001-02-25 05:46:52 +00:00
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
2001-02-25 05:46:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-02-02 14:02:40 +00:00
|
|
|
* We simply relay the packet to the "ether" hook, if it is connected.
|
|
|
|
* We have been through the netgraph locking and are guaranteed to
|
2001-02-25 16:49:04 +00:00
|
|
|
* be the only code running in this node at this time.
|
2001-02-25 05:46:52 +00:00
|
|
|
*/
|
|
|
|
static void
|
2001-02-25 16:49:04 +00:00
|
|
|
ng_eiface_start2(node_p node, hook_p hook, void *arg1, int arg2)
|
2001-02-25 05:46:52 +00:00
|
|
|
{
|
2001-02-25 16:49:04 +00:00
|
|
|
struct ifnet *ifp = arg1;
|
2005-02-02 13:27:03 +00:00
|
|
|
const priv_p priv = (priv_p)ifp->if_softc;
|
2006-02-11 20:25:00 +00:00
|
|
|
int error = 0;
|
2005-02-02 13:27:03 +00:00
|
|
|
struct mbuf *m;
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
/* Check interface flags */
|
2005-08-09 10:20:02 +00:00
|
|
|
|
|
|
|
if (!((ifp->if_flags & IFF_UP) &&
|
|
|
|
(ifp->if_drv_flags & IFF_DRV_RUNNING)))
|
2001-02-25 05:46:52 +00:00
|
|
|
return;
|
|
|
|
|
2006-02-06 14:30:21 +00:00
|
|
|
for (;;) {
|
|
|
|
/*
|
|
|
|
* Grab a packet to transmit.
|
|
|
|
*/
|
|
|
|
IF_DEQUEUE(&ifp->if_snd, m);
|
2001-02-25 05:46:52 +00:00
|
|
|
|
2006-02-06 14:30:21 +00:00
|
|
|
/* If there's nothing to send, break. */
|
|
|
|
if (m == NULL)
|
|
|
|
break;
|
2001-02-25 05:46:52 +00:00
|
|
|
|
2006-02-06 14:30:21 +00:00
|
|
|
/*
|
|
|
|
* Berkeley packet filter.
|
|
|
|
* Pass packet to bpf if there is a listener.
|
|
|
|
* XXX is this safe? locking?
|
|
|
|
*/
|
|
|
|
BPF_MTAP(ifp, m);
|
2001-02-25 05:46:52 +00:00
|
|
|
|
2007-07-26 10:54:33 +00:00
|
|
|
if (ifp->if_flags & IFF_MONITOR) {
|
|
|
|
ifp->if_ipackets++;
|
|
|
|
m_freem(m);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-02-06 14:30:21 +00:00
|
|
|
/*
|
|
|
|
* Send packet; if hook is not connected, mbuf will get
|
|
|
|
* freed.
|
|
|
|
*/
|
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();
|
2006-02-06 14:30:21 +00:00
|
|
|
NG_SEND_DATA_ONLY(error, priv->ether, m);
|
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();
|
2006-02-06 14:30:21 +00:00
|
|
|
|
|
|
|
/* Update stats */
|
2006-02-11 20:25:00 +00:00
|
|
|
if (error == 0)
|
2006-02-06 14:30:21 +00:00
|
|
|
ifp->if_opackets++;
|
2006-02-11 20:25:00 +00:00
|
|
|
else
|
|
|
|
ifp->if_oerrors++;
|
2001-02-25 05:46:52 +00:00
|
|
|
}
|
2005-02-02 13:27:03 +00:00
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
2005-02-02 13:27:03 +00:00
|
|
|
|
2001-02-25 05:46:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-02-25 16:49:04 +00:00
|
|
|
/*
|
|
|
|
* This routine is called to deliver a packet out the interface.
|
|
|
|
* We simply queue the netgraph version to be called when netgraph locking
|
|
|
|
* allows it to happen.
|
|
|
|
* Until we know what the rest of the networking code is doing for
|
|
|
|
* locking, we don't know how we will interact with it.
|
|
|
|
* Take comfort from the fact that the ifnet struct is part of our
|
|
|
|
* private info and can't go away while we are queued.
|
|
|
|
* [Though we don't know it is still there now....]
|
|
|
|
* it is possible we don't gain anything from this because
|
|
|
|
* we would like to get the mbuf and queue it as data
|
|
|
|
* somehow, but we can't and if we did would we solve anything?
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ng_eiface_start(struct ifnet *ifp)
|
|
|
|
{
|
2005-02-02 13:27:03 +00:00
|
|
|
const priv_p priv = (priv_p)ifp->if_softc;
|
2001-02-25 16:49:04 +00:00
|
|
|
|
2006-02-06 14:30:21 +00:00
|
|
|
/* Don't do anything if output is active */
|
|
|
|
if (ifp->if_drv_flags & IFF_DRV_OACTIVE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
|
|
|
|
2007-03-08 21:10:53 +00:00
|
|
|
if (ng_send_fn(priv->node, NULL, &ng_eiface_start2, ifp, 0) != 0)
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
2001-02-25 16:49:04 +00:00
|
|
|
}
|
|
|
|
|
2001-02-25 05:46:52 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
|
|
|
* Display an ioctl to the virtual interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2005-02-02 13:27:03 +00:00
|
|
|
ng_eiface_print_ioctl(struct ifnet *ifp, int command, caddr_t data)
|
|
|
|
{
|
|
|
|
char *str;
|
2001-02-25 05:46:52 +00:00
|
|
|
|
2005-02-02 13:27:03 +00:00
|
|
|
switch (command & IOC_DIRMASK) {
|
2001-02-25 05:46:52 +00:00
|
|
|
case IOC_VOID:
|
|
|
|
str = "IO";
|
|
|
|
break;
|
|
|
|
case IOC_OUT:
|
|
|
|
str = "IOR";
|
|
|
|
break;
|
|
|
|
case IOC_IN:
|
|
|
|
str = "IOW";
|
|
|
|
break;
|
|
|
|
case IOC_INOUT:
|
|
|
|
str = "IORW";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
str = "IO??";
|
|
|
|
}
|
2003-10-31 18:32:15 +00:00
|
|
|
log(LOG_DEBUG, "%s: %s('%c', %d, char[%d])\n",
|
2005-02-02 13:27:03 +00:00
|
|
|
ifp->if_xname,
|
|
|
|
str,
|
|
|
|
IOCGROUP(command),
|
|
|
|
command & 0xff,
|
|
|
|
IOCPARM_LEN(command));
|
2001-02-25 05:46:52 +00:00
|
|
|
}
|
2005-02-02 13:27:03 +00:00
|
|
|
#endif /* DEBUG */
|
2001-02-25 05:46:52 +00:00
|
|
|
|
2011-05-24 14:10:33 +00:00
|
|
|
/*
|
|
|
|
* ifmedia stuff
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_eiface_mediachange(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
const priv_p priv = (priv_p)ifp->if_softc;
|
|
|
|
struct ifmedia *ifm = &priv->media;
|
|
|
|
|
|
|
|
if (IFM_TYPE(ifm->ifm_media) != IFM_ETHER)
|
|
|
|
return (EINVAL);
|
|
|
|
if (IFM_SUBTYPE(ifm->ifm_media) == IFM_AUTO)
|
|
|
|
ifp->if_baudrate = ifmedia_baudrate(IFM_ETHER | IFM_1000_T);
|
|
|
|
else
|
|
|
|
ifp->if_baudrate = ifmedia_baudrate(ifm->ifm_media);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ng_eiface_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
|
|
|
|
{
|
|
|
|
const priv_p priv = (priv_p)ifp->if_softc;
|
|
|
|
struct ifmedia *ifm = &priv->media;
|
|
|
|
|
|
|
|
if (ifm->ifm_cur->ifm_media == (IFM_ETHER | IFM_AUTO) &&
|
|
|
|
(priv->link_status & IFM_ACTIVE))
|
|
|
|
ifmr->ifm_active = IFM_ETHER | IFM_1000_T | IFM_FDX;
|
|
|
|
else
|
|
|
|
ifmr->ifm_active = ifm->ifm_cur->ifm_media;
|
|
|
|
ifmr->ifm_status = priv->link_status;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-02-25 05:46:52 +00:00
|
|
|
/************************************************************************
|
|
|
|
NETGRAPH NODE STUFF
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constructor for a node
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_eiface_constructor(node_p node)
|
|
|
|
{
|
2005-02-02 13:27:03 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
priv_p priv;
|
2005-06-10 16:49:24 +00:00
|
|
|
u_char eaddr[6] = {0,0,0,0,0,0};
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
/* Allocate node and interface private structures */
|
2011-04-18 09:12:27 +00:00
|
|
|
priv = malloc(sizeof(*priv), M_NETGRAPH, M_WAITOK | M_ZERO);
|
2001-02-25 05:46:52 +00:00
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = priv->ifp = if_alloc(IFT_ETHER);
|
|
|
|
if (ifp == NULL) {
|
|
|
|
free(priv, M_NETGRAPH);
|
|
|
|
return (ENOSPC);
|
|
|
|
}
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
/* Link them together */
|
|
|
|
ifp->if_softc = priv;
|
|
|
|
|
|
|
|
/* Get an interface unit number */
|
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
|
|
|
priv->unit = alloc_unr(V_ng_eiface_unit);
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
/* Link together node and private info */
|
|
|
|
NG_NODE_SET_PRIVATE(node, priv);
|
|
|
|
priv->node = node;
|
|
|
|
|
|
|
|
/* Initialize interface structure */
|
2003-10-31 18:32:15 +00:00
|
|
|
if_initname(ifp, NG_EIFACE_EIFACE_NAME, priv->unit);
|
2001-02-25 05:46:52 +00:00
|
|
|
ifp->if_init = ng_eiface_init;
|
|
|
|
ifp->if_output = ether_output;
|
|
|
|
ifp->if_start = ng_eiface_start;
|
|
|
|
ifp->if_ioctl = ng_eiface_ioctl;
|
2010-05-03 07:32:50 +00:00
|
|
|
ifp->if_snd.ifq_maxlen = ifqmaxlen;
|
2001-02-25 05:46:52 +00:00
|
|
|
ifp->if_flags = (IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST);
|
2010-11-22 12:32:19 +00:00
|
|
|
ifp->if_capabilities = IFCAP_VLAN_MTU | IFCAP_JUMBO_MTU;
|
|
|
|
ifp->if_capenable = IFCAP_VLAN_MTU | IFCAP_JUMBO_MTU;
|
2011-05-24 14:10:33 +00:00
|
|
|
ifmedia_init(&priv->media, 0, ng_eiface_mediachange,
|
|
|
|
ng_eiface_mediastatus);
|
|
|
|
ifmedia_add(&priv->media, IFM_ETHER | IFM_10_T, 0, NULL);
|
|
|
|
ifmedia_add(&priv->media, IFM_ETHER | IFM_10_T | IFM_FDX, 0, NULL);
|
|
|
|
ifmedia_add(&priv->media, IFM_ETHER | IFM_100_TX, 0, NULL);
|
|
|
|
ifmedia_add(&priv->media, IFM_ETHER | IFM_100_TX | IFM_FDX, 0, NULL);
|
|
|
|
ifmedia_add(&priv->media, IFM_ETHER | IFM_1000_T, 0, NULL);
|
|
|
|
ifmedia_add(&priv->media, IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL);
|
|
|
|
ifmedia_add(&priv->media, IFM_ETHER | IFM_10G_T | IFM_FDX, 0, NULL);
|
|
|
|
ifmedia_add(&priv->media, IFM_ETHER | IFM_AUTO, 0, NULL);
|
|
|
|
ifmedia_set(&priv->media, IFM_ETHER | IFM_AUTO);
|
|
|
|
priv->link_status = IFM_AVALID;
|
2001-02-25 05:46:52 +00:00
|
|
|
|
2009-06-12 09:20:31 +00:00
|
|
|
/* Give this node the same name as the interface (if possible) */
|
|
|
|
if (ng_name_node(node, ifp->if_xname) != 0)
|
|
|
|
log(LOG_WARNING, "%s: can't acquire netgraph name\n",
|
|
|
|
ifp->if_xname);
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
/* Attach the interface */
|
2005-06-10 16:49:24 +00:00
|
|
|
ether_ifattach(ifp, eaddr);
|
2011-05-24 14:10:33 +00:00
|
|
|
ifp->if_baudrate = ifmedia_baudrate(IFM_ETHER | IFM_1000_T);
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
/* Done */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give our ok for a hook to be added
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_eiface_newhook(node_p node, hook_p hook, const char *name)
|
|
|
|
{
|
2005-02-02 13:27:03 +00:00
|
|
|
priv_p priv = NG_NODE_PRIVATE(node);
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = priv->ifp;
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
if (strcmp(name, NG_EIFACE_HOOK_ETHER))
|
|
|
|
return (EPFNOSUPPORT);
|
|
|
|
if (priv->ether != NULL)
|
|
|
|
return (EISCONN);
|
|
|
|
priv->ether = hook;
|
|
|
|
NG_HOOK_SET_PRIVATE(hook, &priv->ether);
|
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);
|
2001-02-25 05:46:52 +00:00
|
|
|
|
2011-05-24 14:10:33 +00:00
|
|
|
priv->link_status |= IFM_ACTIVE;
|
|
|
|
CURVNET_SET_QUIET(ifp->if_vnet);
|
2005-04-20 14:22:13 +00:00
|
|
|
if_link_state_change(ifp, LINK_STATE_UP);
|
2011-05-24 14:10:33 +00:00
|
|
|
CURVNET_RESTORE();
|
2005-04-20 14:22:13 +00:00
|
|
|
|
2001-02-25 05:46:52 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive a control message
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_eiface_rcvmsg(node_p node, item_p item, hook_p lasthook)
|
|
|
|
{
|
2005-02-02 13:27:03 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *const ifp = priv->ifp;
|
2001-02-25 05:46:52 +00:00
|
|
|
struct ng_mesg *resp = NULL;
|
2005-02-02 13:27:03 +00:00
|
|
|
int error = 0;
|
2001-02-25 05:46:52 +00:00
|
|
|
struct ng_mesg *msg;
|
|
|
|
|
|
|
|
NGI_GET_MSG(item, msg);
|
2005-02-02 13:27:03 +00:00
|
|
|
switch (msg->header.typecookie) {
|
2001-02-25 05:46:52 +00:00
|
|
|
case NGM_EIFACE_COOKIE:
|
|
|
|
switch (msg->header.cmd) {
|
2005-02-02 13:27:03 +00:00
|
|
|
|
2001-02-25 05:46:52 +00:00
|
|
|
case NGM_EIFACE_SET:
|
2005-02-02 13:27:03 +00:00
|
|
|
{
|
2005-11-08 09:03:06 +00:00
|
|
|
if (msg->header.arglen != ETHER_ADDR_LEN) {
|
2001-02-25 05:46:52 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2005-11-08 09:03:06 +00:00
|
|
|
error = if_setlladdr(priv->ifp,
|
|
|
|
(u_char *)msg->data, ETHER_ADDR_LEN);
|
2010-01-18 20:34:00 +00:00
|
|
|
EVENTHANDLER_INVOKE(iflladdr_event, priv->ifp);
|
2001-02-25 05:46:52 +00:00
|
|
|
break;
|
2005-02-02 13:27:03 +00:00
|
|
|
}
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
case NGM_EIFACE_GET_IFNAME:
|
2005-02-03 12:50:10 +00:00
|
|
|
NG_MKRESPONSE(resp, msg, IFNAMSIZ, M_NOWAIT);
|
2001-02-25 05:46:52 +00:00
|
|
|
if (resp == NULL) {
|
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2005-02-03 12:50:10 +00:00
|
|
|
strlcpy(resp->data, ifp->if_xname, IFNAMSIZ);
|
2001-02-25 05:46:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NGM_EIFACE_GET_IFADDRS:
|
2005-02-02 13:27:03 +00:00
|
|
|
{
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
caddr_t ptr;
|
|
|
|
int buflen;
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
/* Determine size of response and allocate it */
|
|
|
|
buflen = 0;
|
2009-06-26 00:49:12 +00:00
|
|
|
if_addr_rlock(ifp);
|
2001-02-25 05:46:52 +00:00
|
|
|
TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)
|
2005-02-02 13:27:03 +00:00
|
|
|
buflen += SA_SIZE(ifa->ifa_addr);
|
2001-02-25 05:46:52 +00:00
|
|
|
NG_MKRESPONSE(resp, msg, buflen, M_NOWAIT);
|
|
|
|
if (resp == NULL) {
|
2009-06-26 00:49:12 +00:00
|
|
|
if_addr_runlock(ifp);
|
2001-02-25 05:46:52 +00:00
|
|
|
error = ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2005-02-02 13:27:03 +00:00
|
|
|
|
2001-02-25 05:46:52 +00:00
|
|
|
/* Add addresses */
|
|
|
|
ptr = resp->data;
|
|
|
|
TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
|
2005-02-02 13:27:03 +00:00
|
|
|
const int len = SA_SIZE(ifa->ifa_addr);
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
if (buflen < len) {
|
2003-10-31 18:32:15 +00:00
|
|
|
log(LOG_ERR, "%s: len changed?\n",
|
2005-02-02 13:27:03 +00:00
|
|
|
ifp->if_xname);
|
2001-02-25 05:46:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
bcopy(ifa->ifa_addr, ptr, len);
|
|
|
|
ptr += len;
|
|
|
|
buflen -= len;
|
|
|
|
}
|
2009-06-26 00:49:12 +00:00
|
|
|
if_addr_runlock(ifp);
|
2001-02-25 05:46:52 +00:00
|
|
|
break;
|
2005-02-02 13:27:03 +00:00
|
|
|
}
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
} /* end of inner switch() */
|
|
|
|
break;
|
2005-01-14 11:55:07 +00:00
|
|
|
case NGM_FLOW_COOKIE:
|
2011-05-24 14:10:33 +00:00
|
|
|
CURVNET_SET_QUIET(ifp->if_vnet);
|
2005-01-14 11:55:07 +00:00
|
|
|
switch (msg->header.cmd) {
|
|
|
|
case NGM_LINK_IS_UP:
|
2011-05-24 14:10:33 +00:00
|
|
|
priv->link_status |= IFM_ACTIVE;
|
2005-04-20 14:22:13 +00:00
|
|
|
if_link_state_change(ifp, LINK_STATE_UP);
|
2005-01-14 11:55:07 +00:00
|
|
|
break;
|
|
|
|
case NGM_LINK_IS_DOWN:
|
2011-05-24 14:10:33 +00:00
|
|
|
priv->link_status &= ~IFM_ACTIVE;
|
2005-04-20 14:22:13 +00:00
|
|
|
if_link_state_change(ifp, LINK_STATE_DOWN);
|
2005-01-14 11:55:07 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-05-24 14:10:33 +00:00
|
|
|
CURVNET_RESTORE();
|
2005-01-14 11:55:07 +00:00
|
|
|
break;
|
2001-02-25 05:46:52 +00:00
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NG_RESPOND_MSG(error, node, item, resp);
|
|
|
|
NG_FREE_MSG(msg);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-02-02 13:27:03 +00:00
|
|
|
* Receive data from a hook. Pass the packet to the ether_input routine.
|
2001-02-25 05:46:52 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_eiface_rcvdata(hook_p hook, item_p item)
|
|
|
|
{
|
2005-02-02 13:27:03 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *const ifp = priv->ifp;
|
2001-02-25 05:46:52 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
|
|
|
|
NGI_GET_M(item, m);
|
2005-02-02 13:27:03 +00:00
|
|
|
NG_FREE_ITEM(item);
|
2001-02-25 05:46:52 +00:00
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
if (!((ifp->if_flags & IFF_UP) &&
|
|
|
|
(ifp->if_drv_flags & IFF_DRV_RUNNING))) {
|
2003-11-17 19:13:01 +00:00
|
|
|
NG_FREE_M(m);
|
2001-02-25 05:46:52 +00:00
|
|
|
return (ENETDOWN);
|
|
|
|
}
|
|
|
|
|
2005-03-01 19:39:57 +00:00
|
|
|
if (m->m_len < ETHER_HDR_LEN) {
|
|
|
|
m = m_pullup(m, ETHER_HDR_LEN);
|
|
|
|
if (m == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
2001-02-25 05:46:52 +00:00
|
|
|
/* Note receiving interface */
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
|
|
|
|
/* Update interface stats */
|
|
|
|
ifp->if_ipackets++;
|
|
|
|
|
2002-11-14 23:44:37 +00:00
|
|
|
(*ifp->if_input)(ifp, m);
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
/* Done */
|
2002-11-14 23:44:37 +00:00
|
|
|
return (0);
|
2001-02-25 05:46:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-02-02 13:27:03 +00:00
|
|
|
* Shutdown processing.
|
2001-02-25 05:46:52 +00:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_eiface_rmnode(node_p node)
|
|
|
|
{
|
2005-02-02 13:27:03 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(node);
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *const ifp = priv->ifp;
|
2001-02-25 05:46:52 +00:00
|
|
|
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
/*
|
|
|
|
* the ifnet may be in a different vnet than the netgraph node,
|
|
|
|
* hence we have to change the current vnet context here.
|
|
|
|
*/
|
|
|
|
CURVNET_SET_QUIET(ifp->if_vnet);
|
2011-05-24 14:10:33 +00:00
|
|
|
ifmedia_removeall(&priv->media);
|
2002-11-14 23:44:37 +00:00
|
|
|
ether_ifdetach(ifp);
|
2005-06-10 16:49:24 +00:00
|
|
|
if_free(ifp);
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
CURVNET_RESTORE();
|
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
|
|
|
free_unr(V_ng_eiface_unit, priv->unit);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(priv, M_NETGRAPH);
|
2001-02-25 05:46:52 +00:00
|
|
|
NG_NODE_SET_PRIVATE(node, NULL);
|
|
|
|
NG_NODE_UNREF(node);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hook disconnection
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_eiface_disconnect(hook_p hook)
|
|
|
|
{
|
2005-02-02 13:27:03 +00:00
|
|
|
const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
|
2001-02-25 05:46:52 +00:00
|
|
|
|
|
|
|
priv->ether = NULL;
|
2011-05-24 14:10:33 +00:00
|
|
|
priv->link_status &= ~IFM_ACTIVE;
|
|
|
|
CURVNET_SET_QUIET(priv->ifp->if_vnet);
|
|
|
|
if_link_state_change(priv->ifp, LINK_STATE_DOWN);
|
|
|
|
CURVNET_RESTORE();
|
2001-02-25 05:46:52 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2005-02-05 08:28:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle loading and unloading for this node type.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ng_eiface_mod_event(module_t mod, int event, void *data)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
2009-04-26 07:14:50 +00:00
|
|
|
|
Introduce and use a sysinit-based initialization scheme for virtual
network stacks, VNET_SYSINIT:
- Add VNET_SYSINIT and VNET_SYSUNINIT macros to declare events that will
occur each time a network stack is instantiated and destroyed. In the
!VIMAGE case, these are simply mapped into regular SYSINIT/SYSUNINIT.
For the VIMAGE case, we instead use SYSINIT's to track their order and
properties on registration, using them for each vnet when created/
destroyed, or immediately on module load for already-started vnets.
- Remove vnet_modinfo mechanism that existed to serve this purpose
previously, as well as its dependency scheme: we now just use the
SYSINIT ordering scheme.
- Implement VNET_DOMAIN_SET() to allow protocol domains to declare that
they want init functions to be called for each virtual network stack
rather than just once at boot, compiling down to DOMAIN_SET() in the
non-VIMAGE case.
- Walk all virtualized kernel subsystems and make use of these instead
of modinfo or DOMAIN_SET() for init/uninit events. In some cases,
convert modular components from using modevent to using sysinit (where
appropriate). In some cases, do minor rejuggling of SYSINIT ordering
to make room for or better manage events.
Portions submitted by: jhb (VNET_SYSINIT), bz (cleanup)
Discussed with: jhb, bz, julian, zec
Reviewed by: bz
Approved by: re (VIMAGE blanket)
2009-07-23 20:46:49 +00:00
|
|
|
static void
|
|
|
|
vnet_ng_eiface_init(const void *unused)
|
2009-04-26 07:14:50 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
V_ng_eiface_unit = new_unrhdr(0, 0xffff, NULL);
|
|
|
|
}
|
Introduce and use a sysinit-based initialization scheme for virtual
network stacks, VNET_SYSINIT:
- Add VNET_SYSINIT and VNET_SYSUNINIT macros to declare events that will
occur each time a network stack is instantiated and destroyed. In the
!VIMAGE case, these are simply mapped into regular SYSINIT/SYSUNINIT.
For the VIMAGE case, we instead use SYSINIT's to track their order and
properties on registration, using them for each vnet when created/
destroyed, or immediately on module load for already-started vnets.
- Remove vnet_modinfo mechanism that existed to serve this purpose
previously, as well as its dependency scheme: we now just use the
SYSINIT ordering scheme.
- Implement VNET_DOMAIN_SET() to allow protocol domains to declare that
they want init functions to be called for each virtual network stack
rather than just once at boot, compiling down to DOMAIN_SET() in the
non-VIMAGE case.
- Walk all virtualized kernel subsystems and make use of these instead
of modinfo or DOMAIN_SET() for init/uninit events. In some cases,
convert modular components from using modevent to using sysinit (where
appropriate). In some cases, do minor rejuggling of SYSINIT ordering
to make room for or better manage events.
Portions submitted by: jhb (VNET_SYSINIT), bz (cleanup)
Discussed with: jhb, bz, julian, zec
Reviewed by: bz
Approved by: re (VIMAGE blanket)
2009-07-23 20:46:49 +00:00
|
|
|
VNET_SYSINIT(vnet_ng_eiface_init, SI_SUB_PSEUDO, SI_ORDER_ANY,
|
|
|
|
vnet_ng_eiface_init, NULL);
|
2009-04-26 07:14:50 +00:00
|
|
|
|
Introduce and use a sysinit-based initialization scheme for virtual
network stacks, VNET_SYSINIT:
- Add VNET_SYSINIT and VNET_SYSUNINIT macros to declare events that will
occur each time a network stack is instantiated and destroyed. In the
!VIMAGE case, these are simply mapped into regular SYSINIT/SYSUNINIT.
For the VIMAGE case, we instead use SYSINIT's to track their order and
properties on registration, using them for each vnet when created/
destroyed, or immediately on module load for already-started vnets.
- Remove vnet_modinfo mechanism that existed to serve this purpose
previously, as well as its dependency scheme: we now just use the
SYSINIT ordering scheme.
- Implement VNET_DOMAIN_SET() to allow protocol domains to declare that
they want init functions to be called for each virtual network stack
rather than just once at boot, compiling down to DOMAIN_SET() in the
non-VIMAGE case.
- Walk all virtualized kernel subsystems and make use of these instead
of modinfo or DOMAIN_SET() for init/uninit events. In some cases,
convert modular components from using modevent to using sysinit (where
appropriate). In some cases, do minor rejuggling of SYSINIT ordering
to make room for or better manage events.
Portions submitted by: jhb (VNET_SYSINIT), bz (cleanup)
Discussed with: jhb, bz, julian, zec
Reviewed by: bz
Approved by: re (VIMAGE blanket)
2009-07-23 20:46:49 +00:00
|
|
|
static void
|
|
|
|
vnet_ng_eiface_uninit(const void *unused)
|
2009-04-26 07:14:50 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
delete_unrhdr(V_ng_eiface_unit);
|
|
|
|
}
|
Introduce and use a sysinit-based initialization scheme for virtual
network stacks, VNET_SYSINIT:
- Add VNET_SYSINIT and VNET_SYSUNINIT macros to declare events that will
occur each time a network stack is instantiated and destroyed. In the
!VIMAGE case, these are simply mapped into regular SYSINIT/SYSUNINIT.
For the VIMAGE case, we instead use SYSINIT's to track their order and
properties on registration, using them for each vnet when created/
destroyed, or immediately on module load for already-started vnets.
- Remove vnet_modinfo mechanism that existed to serve this purpose
previously, as well as its dependency scheme: we now just use the
SYSINIT ordering scheme.
- Implement VNET_DOMAIN_SET() to allow protocol domains to declare that
they want init functions to be called for each virtual network stack
rather than just once at boot, compiling down to DOMAIN_SET() in the
non-VIMAGE case.
- Walk all virtualized kernel subsystems and make use of these instead
of modinfo or DOMAIN_SET() for init/uninit events. In some cases,
convert modular components from using modevent to using sysinit (where
appropriate). In some cases, do minor rejuggling of SYSINIT ordering
to make room for or better manage events.
Portions submitted by: jhb (VNET_SYSINIT), bz (cleanup)
Discussed with: jhb, bz, julian, zec
Reviewed by: bz
Approved by: re (VIMAGE blanket)
2009-07-23 20:46:49 +00:00
|
|
|
VNET_SYSUNINIT(vnet_ng_eiface_uninit, SI_SUB_PSEUDO, SI_ORDER_ANY,
|
|
|
|
vnet_ng_eiface_uninit, NULL);
|