2009-06-24 22:21:30 +00:00
|
|
|
/*-
|
2017-11-27 15:23:17 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2009-06-24 22:21:30 +00:00
|
|
|
* Copyright (c) 2008 The FreeBSD Foundation
|
2010-03-06 21:22:28 +00:00
|
|
|
* Copyright (c) 2009-2010 Bjoern A. Zeeb <bz@FreeBSD.org>
|
2009-06-24 22:21:30 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by CK Software GmbH under sponsorship
|
|
|
|
* from the FreeBSD Foundation.
|
|
|
|
*
|
|
|
|
* 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, 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2009-07-26 12:20:07 +00:00
|
|
|
* A pair of virtual back-to-back connected ethernet like interfaces
|
|
|
|
* (``two interfaces with a virtual cross-over cable'').
|
|
|
|
*
|
2009-06-24 22:21:30 +00:00
|
|
|
* This is mostly intended to be used to provide connectivity between
|
|
|
|
* different virtual network stack instances.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Things to re-think once we have more experience:
|
2009-07-26 12:20:07 +00:00
|
|
|
* - ifp->if_reassign function once we can test with vimage. Depending on
|
2009-08-01 19:26:27 +00:00
|
|
|
* how if_vmove() is going to be improved.
|
2009-07-26 12:20:07 +00:00
|
|
|
* - Real random etheraddrs that are checked to be uniquish; we would need
|
|
|
|
* to re-do them in case we move the interface between network stacks
|
|
|
|
* in a private if_reassign function.
|
|
|
|
* In case we bridge to a real interface/network or between indepedent
|
|
|
|
* epairs on multiple stacks/machines, we may need this.
|
|
|
|
* For now let the user handle that case.
|
2009-06-24 22:21:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2018-05-23 13:10:57 +00:00
|
|
|
#include <sys/hash.h>
|
|
|
|
#include <sys/jail.h>
|
2009-06-24 22:21:30 +00:00
|
|
|
#include <sys/kernel.h>
|
2018-05-23 13:10:57 +00:00
|
|
|
#include <sys/libkern.h>
|
2016-02-01 17:41:21 +00:00
|
|
|
#include <sys/malloc.h>
|
2009-06-24 22:21:30 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/module.h>
|
2018-05-23 13:10:57 +00:00
|
|
|
#include <sys/proc.h>
|
2009-06-24 22:21:30 +00:00
|
|
|
#include <sys/refcount.h>
|
|
|
|
#include <sys/queue.h>
|
2009-07-26 12:20:07 +00:00
|
|
|
#include <sys/smp.h>
|
2009-06-24 22:21:30 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if.h>
|
2013-10-26 17:58:36 +00:00
|
|
|
#include <net/if_var.h>
|
2009-06-24 22:21:30 +00:00
|
|
|
#include <net/if_clone.h>
|
2011-05-24 07:57:28 +00:00
|
|
|
#include <net/if_media.h>
|
2009-06-24 22:21:30 +00:00
|
|
|
#include <net/if_var.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/netisr.h>
|
2009-08-01 19:26:27 +00:00
|
|
|
#include <net/vnet.h>
|
2009-06-24 22:21:30 +00:00
|
|
|
|
|
|
|
SYSCTL_DECL(_net_link);
|
2020-02-26 14:26:36 +00:00
|
|
|
static SYSCTL_NODE(_net_link, OID_AUTO, epair, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
|
|
|
|
"epair sysctl");
|
2009-07-26 12:20:07 +00:00
|
|
|
|
|
|
|
#ifdef EPAIR_DEBUG
|
|
|
|
static int epair_debug = 0;
|
2010-11-21 19:33:19 +00:00
|
|
|
SYSCTL_INT(_net_link_epair, OID_AUTO, epair_debug, CTLFLAG_RW,
|
2009-06-24 22:21:30 +00:00
|
|
|
&epair_debug, 0, "if_epair(4) debugging.");
|
2009-07-26 12:20:07 +00:00
|
|
|
#define DPRINTF(fmt, arg...) \
|
|
|
|
if (epair_debug) \
|
|
|
|
printf("[%s:%d] " fmt, __func__, __LINE__, ##arg)
|
2009-06-24 22:21:30 +00:00
|
|
|
#else
|
|
|
|
#define DPRINTF(fmt, arg...)
|
|
|
|
#endif
|
|
|
|
|
2009-07-26 12:20:07 +00:00
|
|
|
static void epair_nh_sintr(struct mbuf *);
|
|
|
|
static struct mbuf *epair_nh_m2cpuid(struct mbuf *, uintptr_t, u_int *);
|
|
|
|
static void epair_nh_drainedcpu(u_int);
|
|
|
|
|
|
|
|
static void epair_start_locked(struct ifnet *);
|
2011-05-24 07:57:28 +00:00
|
|
|
static int epair_media_change(struct ifnet *);
|
|
|
|
static void epair_media_status(struct ifnet *, struct ifmediareq *);
|
2009-07-26 12:20:07 +00:00
|
|
|
|
|
|
|
static int epair_clone_match(struct if_clone *, const char *);
|
|
|
|
static int epair_clone_create(struct if_clone *, char *, size_t, caddr_t);
|
|
|
|
static int epair_clone_destroy(struct if_clone *, struct ifnet *);
|
|
|
|
|
2012-10-16 13:37:54 +00:00
|
|
|
static const char epairname[] = "epair";
|
2018-07-23 07:11:58 +00:00
|
|
|
static unsigned int next_index = 0;
|
2012-10-16 13:37:54 +00:00
|
|
|
|
2014-10-10 06:45:13 +00:00
|
|
|
/* Netisr related definitions and sysctl. */
|
2009-07-26 12:20:07 +00:00
|
|
|
static struct netisr_handler epair_nh = {
|
2012-10-16 13:37:54 +00:00
|
|
|
.nh_name = epairname,
|
2009-07-26 12:20:07 +00:00
|
|
|
.nh_proto = NETISR_EPAIR,
|
|
|
|
.nh_policy = NETISR_POLICY_CPU,
|
|
|
|
.nh_handler = epair_nh_sintr,
|
|
|
|
.nh_m2cpuid = epair_nh_m2cpuid,
|
|
|
|
.nh_drainedcpu = epair_nh_drainedcpu,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
sysctl_epair_netisr_maxqlen(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int error, qlimit;
|
|
|
|
|
|
|
|
netisr_getqlimit(&epair_nh, &qlimit);
|
|
|
|
error = sysctl_handle_int(oidp, &qlimit, 0, req);
|
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
|
|
|
if (qlimit < 1)
|
|
|
|
return (EINVAL);
|
|
|
|
return (netisr_setqlimit(&epair_nh, qlimit));
|
|
|
|
}
|
2020-02-26 14:26:36 +00:00
|
|
|
SYSCTL_PROC(_net_link_epair, OID_AUTO, netisr_maxqlen,
|
|
|
|
CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, 0, 0,
|
|
|
|
sysctl_epair_netisr_maxqlen, "I",
|
2009-07-26 12:20:07 +00:00
|
|
|
"Maximum if_epair(4) netisr \"hw\" queue length");
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
struct epair_softc {
|
2009-07-26 12:20:07 +00:00
|
|
|
struct ifnet *ifp; /* This ifp. */
|
|
|
|
struct ifnet *oifp; /* other ifp of pair. */
|
2011-05-24 07:57:28 +00:00
|
|
|
struct ifmedia media; /* Media config (fake). */
|
2009-07-26 12:20:07 +00:00
|
|
|
u_int refcount; /* # of mbufs in flight. */
|
|
|
|
u_int cpuid; /* CPU ID assigned upon creation. */
|
2009-06-24 22:21:30 +00:00
|
|
|
void (*if_qflush)(struct ifnet *);
|
2009-07-26 12:20:07 +00:00
|
|
|
/* Original if_qflush routine. */
|
2009-06-24 22:21:30 +00:00
|
|
|
};
|
|
|
|
|
2009-07-26 12:20:07 +00:00
|
|
|
/*
|
|
|
|
* Per-CPU list of ifps with data in the ifq that needs to be flushed
|
|
|
|
* to the netisr ``hw'' queue before we allow any further direct queuing
|
|
|
|
* to the ``hw'' queue.
|
|
|
|
*/
|
2009-06-24 22:21:30 +00:00
|
|
|
struct epair_ifp_drain {
|
|
|
|
STAILQ_ENTRY(epair_ifp_drain) ifp_next;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
};
|
2009-07-26 12:20:07 +00:00
|
|
|
STAILQ_HEAD(eid_list, epair_ifp_drain);
|
|
|
|
|
|
|
|
#define EPAIR_LOCK_INIT(dpcpu) mtx_init(&(dpcpu)->if_epair_mtx, \
|
|
|
|
"if_epair", NULL, MTX_DEF)
|
|
|
|
#define EPAIR_LOCK_DESTROY(dpcpu) mtx_destroy(&(dpcpu)->if_epair_mtx)
|
|
|
|
#define EPAIR_LOCK_ASSERT(dpcpu) mtx_assert(&(dpcpu)->if_epair_mtx, \
|
|
|
|
MA_OWNED)
|
|
|
|
#define EPAIR_LOCK(dpcpu) mtx_lock(&(dpcpu)->if_epair_mtx)
|
|
|
|
#define EPAIR_UNLOCK(dpcpu) mtx_unlock(&(dpcpu)->if_epair_mtx)
|
|
|
|
|
|
|
|
#ifdef INVARIANTS
|
|
|
|
#define EPAIR_REFCOUNT_INIT(r, v) refcount_init((r), (v))
|
|
|
|
#define EPAIR_REFCOUNT_AQUIRE(r) refcount_acquire((r))
|
|
|
|
#define EPAIR_REFCOUNT_RELEASE(r) refcount_release((r))
|
|
|
|
#define EPAIR_REFCOUNT_ASSERT(a, p) KASSERT(a, p)
|
|
|
|
#else
|
|
|
|
#define EPAIR_REFCOUNT_INIT(r, v)
|
|
|
|
#define EPAIR_REFCOUNT_AQUIRE(r)
|
|
|
|
#define EPAIR_REFCOUNT_RELEASE(r)
|
|
|
|
#define EPAIR_REFCOUNT_ASSERT(a, p)
|
|
|
|
#endif
|
2009-06-24 22:21:30 +00:00
|
|
|
|
2012-10-16 13:37:54 +00:00
|
|
|
static MALLOC_DEFINE(M_EPAIR, epairname,
|
2009-06-24 22:21:30 +00:00
|
|
|
"Pair of virtual cross-over connected Ethernet-like interfaces");
|
|
|
|
|
2018-07-24 16:35:52 +00:00
|
|
|
VNET_DEFINE_STATIC(struct if_clone *, epair_cloner);
|
2014-10-10 06:45:13 +00:00
|
|
|
#define V_epair_cloner VNET(epair_cloner)
|
2009-06-24 22:21:30 +00:00
|
|
|
|
2009-07-26 12:20:07 +00:00
|
|
|
/*
|
|
|
|
* DPCPU area and functions.
|
|
|
|
*/
|
|
|
|
struct epair_dpcpu {
|
|
|
|
struct mtx if_epair_mtx; /* Per-CPU locking. */
|
|
|
|
int epair_drv_flags; /* Per-CPU ``hw'' drv flags. */
|
|
|
|
struct eid_list epair_ifp_drain_list; /* Per-CPU list of ifps with
|
|
|
|
* data in the ifq. */
|
|
|
|
};
|
|
|
|
DPCPU_DEFINE(struct epair_dpcpu, epair_dpcpu);
|
|
|
|
|
2021-10-26 07:57:56 +00:00
|
|
|
static void
|
|
|
|
epair_clear_mbuf(struct mbuf *m)
|
|
|
|
{
|
|
|
|
/* Remove any CSUM_SND_TAG as ether_input will barf. */
|
|
|
|
if (m->m_pkthdr.csum_flags & CSUM_SND_TAG) {
|
|
|
|
m_snd_tag_rele(m->m_pkthdr.snd_tag);
|
|
|
|
m->m_pkthdr.snd_tag = NULL;
|
|
|
|
m->m_pkthdr.csum_flags &= ~CSUM_SND_TAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_tag_delete_nonpersistent(m);
|
|
|
|
}
|
|
|
|
|
2009-07-26 12:20:07 +00:00
|
|
|
static void
|
|
|
|
epair_dpcpu_init(void)
|
|
|
|
{
|
|
|
|
struct epair_dpcpu *epair_dpcpu;
|
|
|
|
struct eid_list *s;
|
|
|
|
u_int cpuid;
|
|
|
|
|
2010-06-11 18:46:34 +00:00
|
|
|
CPU_FOREACH(cpuid) {
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_dpcpu = DPCPU_ID_PTR(cpuid, epair_dpcpu);
|
|
|
|
|
|
|
|
/* Initialize per-cpu lock. */
|
|
|
|
EPAIR_LOCK_INIT(epair_dpcpu);
|
|
|
|
|
|
|
|
/* Driver flags are per-cpu as are our netisr "hw" queues. */
|
|
|
|
epair_dpcpu->epair_drv_flags = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize per-cpu drain list.
|
|
|
|
* Manually do what STAILQ_HEAD_INITIALIZER would do.
|
|
|
|
*/
|
|
|
|
s = &epair_dpcpu->epair_ifp_drain_list;
|
|
|
|
s->stqh_first = NULL;
|
|
|
|
s->stqh_last = &s->stqh_first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
epair_dpcpu_detach(void)
|
|
|
|
{
|
|
|
|
struct epair_dpcpu *epair_dpcpu;
|
|
|
|
u_int cpuid;
|
|
|
|
|
2010-06-11 18:46:34 +00:00
|
|
|
CPU_FOREACH(cpuid) {
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_dpcpu = DPCPU_ID_PTR(cpuid, epair_dpcpu);
|
|
|
|
|
|
|
|
/* Destroy per-cpu lock. */
|
|
|
|
EPAIR_LOCK_DESTROY(epair_dpcpu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper functions.
|
|
|
|
*/
|
|
|
|
static u_int
|
|
|
|
cpuid_from_ifp(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct epair_softc *sc;
|
|
|
|
|
|
|
|
if (ifp == NULL)
|
|
|
|
return (0);
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
|
|
|
|
return (sc->cpuid);
|
|
|
|
}
|
2009-06-24 22:21:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Netisr handler functions.
|
|
|
|
*/
|
|
|
|
static void
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_nh_sintr(struct mbuf *m)
|
2009-06-24 22:21:30 +00:00
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
2018-05-19 05:27:49 +00:00
|
|
|
struct epair_softc *sc __unused;
|
2009-06-24 22:21:30 +00:00
|
|
|
|
|
|
|
ifp = m->m_pkthdr.rcvif;
|
|
|
|
(*ifp->if_input)(ifp, m);
|
|
|
|
sc = ifp->if_softc;
|
2009-07-26 12:20:07 +00:00
|
|
|
EPAIR_REFCOUNT_RELEASE(&sc->refcount);
|
2010-03-06 21:22:28 +00:00
|
|
|
EPAIR_REFCOUNT_ASSERT((int)sc->refcount >= 1,
|
|
|
|
("%s: ifp=%p sc->refcount not >= 1: %d",
|
|
|
|
__func__, ifp, sc->refcount));
|
2009-06-24 22:21:30 +00:00
|
|
|
DPRINTF("ifp=%p refcount=%u\n", ifp, sc->refcount);
|
|
|
|
}
|
|
|
|
|
2009-07-26 12:20:07 +00:00
|
|
|
static struct mbuf *
|
|
|
|
epair_nh_m2cpuid(struct mbuf *m, uintptr_t source, u_int *cpuid)
|
|
|
|
{
|
|
|
|
|
|
|
|
*cpuid = cpuid_from_ifp(m->m_pkthdr.rcvif);
|
|
|
|
|
|
|
|
return (m);
|
|
|
|
}
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
static void
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_nh_drainedcpu(u_int cpuid)
|
2009-06-24 22:21:30 +00:00
|
|
|
{
|
2009-07-26 12:20:07 +00:00
|
|
|
struct epair_dpcpu *epair_dpcpu;
|
2009-06-24 22:21:30 +00:00
|
|
|
struct epair_ifp_drain *elm, *tvar;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_dpcpu = DPCPU_ID_PTR(cpuid, epair_dpcpu);
|
|
|
|
EPAIR_LOCK(epair_dpcpu);
|
2009-06-24 22:21:30 +00:00
|
|
|
/*
|
|
|
|
* Assume our "hw" queue and possibly ifq will be emptied
|
|
|
|
* again. In case we will overflow the "hw" queue while
|
|
|
|
* draining, epair_start_locked will set IFF_DRV_OACTIVE
|
|
|
|
* again and we will stop and return.
|
|
|
|
*/
|
2009-07-26 12:20:07 +00:00
|
|
|
STAILQ_FOREACH_SAFE(elm, &epair_dpcpu->epair_ifp_drain_list,
|
|
|
|
ifp_next, tvar) {
|
2009-06-24 22:21:30 +00:00
|
|
|
ifp = elm->ifp;
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_dpcpu->epair_drv_flags &= ~IFF_DRV_OACTIVE;
|
2009-06-24 22:21:30 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
|
|
|
epair_start_locked(ifp);
|
|
|
|
|
|
|
|
IFQ_LOCK(&ifp->if_snd);
|
|
|
|
if (IFQ_IS_EMPTY(&ifp->if_snd)) {
|
2018-05-19 05:27:49 +00:00
|
|
|
struct epair_softc *sc __unused;
|
2010-03-06 21:22:28 +00:00
|
|
|
|
2009-07-26 12:20:07 +00:00
|
|
|
STAILQ_REMOVE(&epair_dpcpu->epair_ifp_drain_list,
|
|
|
|
elm, epair_ifp_drain, ifp_next);
|
2010-03-06 21:22:28 +00:00
|
|
|
/* The cached ifp goes off the list. */
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
EPAIR_REFCOUNT_RELEASE(&sc->refcount);
|
|
|
|
EPAIR_REFCOUNT_ASSERT((int)sc->refcount >= 1,
|
|
|
|
("%s: ifp=%p sc->refcount not >= 1: %d",
|
|
|
|
__func__, ifp, sc->refcount));
|
2009-06-24 22:21:30 +00:00
|
|
|
free(elm, M_EPAIR);
|
|
|
|
}
|
|
|
|
IFQ_UNLOCK(&ifp->if_snd);
|
|
|
|
|
|
|
|
if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) != 0) {
|
|
|
|
/* Our "hw"q overflew again. */
|
2010-11-21 19:33:19 +00:00
|
|
|
epair_dpcpu->epair_drv_flags |= IFF_DRV_OACTIVE;
|
2009-06-24 22:21:30 +00:00
|
|
|
DPRINTF("hw queue length overflow at %u\n",
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_nh.nh_qlimit);
|
2009-06-24 22:21:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-07-26 12:20:07 +00:00
|
|
|
EPAIR_UNLOCK(epair_dpcpu);
|
2009-06-24 22:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Network interface (`if') related functions.
|
|
|
|
*/
|
2010-03-06 21:22:28 +00:00
|
|
|
static void
|
|
|
|
epair_remove_ifp_from_draining(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct epair_dpcpu *epair_dpcpu;
|
|
|
|
struct epair_ifp_drain *elm, *tvar;
|
|
|
|
u_int cpuid;
|
|
|
|
|
2010-06-11 18:46:34 +00:00
|
|
|
CPU_FOREACH(cpuid) {
|
2010-03-06 21:22:28 +00:00
|
|
|
epair_dpcpu = DPCPU_ID_PTR(cpuid, epair_dpcpu);
|
|
|
|
EPAIR_LOCK(epair_dpcpu);
|
|
|
|
STAILQ_FOREACH_SAFE(elm, &epair_dpcpu->epair_ifp_drain_list,
|
|
|
|
ifp_next, tvar) {
|
|
|
|
if (ifp == elm->ifp) {
|
2018-05-19 05:27:49 +00:00
|
|
|
struct epair_softc *sc __unused;
|
2010-03-06 21:22:28 +00:00
|
|
|
|
|
|
|
STAILQ_REMOVE(
|
|
|
|
&epair_dpcpu->epair_ifp_drain_list, elm,
|
|
|
|
epair_ifp_drain, ifp_next);
|
|
|
|
/* The cached ifp goes off the list. */
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
EPAIR_REFCOUNT_RELEASE(&sc->refcount);
|
|
|
|
EPAIR_REFCOUNT_ASSERT((int)sc->refcount >= 1,
|
|
|
|
("%s: ifp=%p sc->refcount not >= 1: %d",
|
|
|
|
__func__, ifp, sc->refcount));
|
|
|
|
free(elm, M_EPAIR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EPAIR_UNLOCK(epair_dpcpu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-26 12:20:07 +00:00
|
|
|
static int
|
|
|
|
epair_add_ifp_for_draining(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct epair_dpcpu *epair_dpcpu;
|
2010-03-06 21:22:28 +00:00
|
|
|
struct epair_softc *sc;
|
2009-07-26 12:20:07 +00:00
|
|
|
struct epair_ifp_drain *elm = NULL;
|
|
|
|
|
2010-03-06 21:22:28 +00:00
|
|
|
sc = ifp->if_softc;
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_dpcpu = DPCPU_ID_PTR(sc->cpuid, epair_dpcpu);
|
2010-03-06 21:22:28 +00:00
|
|
|
EPAIR_LOCK_ASSERT(epair_dpcpu);
|
2009-07-26 12:20:07 +00:00
|
|
|
STAILQ_FOREACH(elm, &epair_dpcpu->epair_ifp_drain_list, ifp_next)
|
|
|
|
if (elm->ifp == ifp)
|
|
|
|
break;
|
2010-01-10 12:03:53 +00:00
|
|
|
/* If the ifp is there already, return success. */
|
2009-07-26 12:20:07 +00:00
|
|
|
if (elm != NULL)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
elm = malloc(sizeof(struct epair_ifp_drain), M_EPAIR, M_NOWAIT|M_ZERO);
|
|
|
|
if (elm == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
elm->ifp = ifp;
|
2010-03-06 21:22:28 +00:00
|
|
|
/* Add a reference for the ifp pointer on the list. */
|
|
|
|
EPAIR_REFCOUNT_AQUIRE(&sc->refcount);
|
2009-07-26 12:20:07 +00:00
|
|
|
STAILQ_INSERT_TAIL(&epair_dpcpu->epair_ifp_drain_list, elm, ifp_next);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
static void
|
|
|
|
epair_start_locked(struct ifnet *ifp)
|
|
|
|
{
|
2009-07-26 12:20:07 +00:00
|
|
|
struct epair_dpcpu *epair_dpcpu;
|
2009-06-24 22:21:30 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
struct epair_softc *sc;
|
|
|
|
struct ifnet *oifp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
DPRINTF("ifp=%p\n", ifp);
|
2009-07-26 12:20:07 +00:00
|
|
|
sc = ifp->if_softc;
|
|
|
|
epair_dpcpu = DPCPU_ID_PTR(sc->cpuid, epair_dpcpu);
|
|
|
|
EPAIR_LOCK_ASSERT(epair_dpcpu);
|
2009-06-24 22:21:30 +00:00
|
|
|
|
|
|
|
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
|
|
|
|
return;
|
|
|
|
if ((ifp->if_flags & IFF_UP) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
2017-04-08 04:45:52 +00:00
|
|
|
* We get packets here from ether_output via if_handoff()
|
2017-04-08 04:50:50 +00:00
|
|
|
* and need to put them into the input queue of the oifp
|
2009-06-24 22:21:30 +00:00
|
|
|
* and call oifp->if_input() via netisr/epair_sintr().
|
|
|
|
*/
|
|
|
|
oifp = sc->oifp;
|
|
|
|
sc = oifp->if_softc;
|
|
|
|
for (;;) {
|
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
|
|
|
if (m == NULL)
|
|
|
|
break;
|
|
|
|
BPF_MTAP(ifp, m);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In case the outgoing interface is not usable,
|
|
|
|
* drop the packet.
|
|
|
|
*/
|
|
|
|
if ((oifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ||
|
|
|
|
(oifp->if_flags & IFF_UP) ==0) {
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
|
2009-06-24 22:21:30 +00:00
|
|
|
m_freem(m);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DPRINTF("packet %s -> %s\n", ifp->if_xname, oifp->if_xname);
|
|
|
|
|
2021-10-26 07:57:56 +00:00
|
|
|
epair_clear_mbuf(m);
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
/*
|
|
|
|
* Add a reference so the interface cannot go while the
|
|
|
|
* packet is in transit as we rely on rcvif to stay valid.
|
|
|
|
*/
|
2009-07-26 12:20:07 +00:00
|
|
|
EPAIR_REFCOUNT_AQUIRE(&sc->refcount);
|
2009-06-24 22:21:30 +00:00
|
|
|
m->m_pkthdr.rcvif = oifp;
|
|
|
|
CURVNET_SET_QUIET(oifp->if_vnet);
|
|
|
|
error = netisr_queue(NETISR_EPAIR, m);
|
|
|
|
CURVNET_RESTORE();
|
|
|
|
if (!error) {
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
|
2009-06-24 22:21:30 +00:00
|
|
|
/* Someone else received the packet. */
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(oifp, IFCOUNTER_IPACKETS, 1);
|
2009-06-24 22:21:30 +00:00
|
|
|
} else {
|
2010-03-06 21:22:28 +00:00
|
|
|
/* The packet was freed already. */
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_dpcpu->epair_drv_flags |= IFF_DRV_OACTIVE;
|
2009-06-24 22:21:30 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
2010-03-06 21:22:28 +00:00
|
|
|
(void) epair_add_ifp_for_draining(ifp);
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
|
2009-07-26 12:20:07 +00:00
|
|
|
EPAIR_REFCOUNT_RELEASE(&sc->refcount);
|
2010-03-06 21:22:28 +00:00
|
|
|
EPAIR_REFCOUNT_ASSERT((int)sc->refcount >= 1,
|
|
|
|
("%s: ifp=%p sc->refcount not >= 1: %d",
|
|
|
|
__func__, oifp, sc->refcount));
|
2009-06-24 22:21:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
epair_start(struct ifnet *ifp)
|
|
|
|
{
|
2009-07-26 12:20:07 +00:00
|
|
|
struct epair_dpcpu *epair_dpcpu;
|
2009-06-24 22:21:30 +00:00
|
|
|
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_dpcpu = DPCPU_ID_PTR(cpuid_from_ifp(ifp), epair_dpcpu);
|
|
|
|
EPAIR_LOCK(epair_dpcpu);
|
2009-06-24 22:21:30 +00:00
|
|
|
epair_start_locked(ifp);
|
2009-07-26 12:20:07 +00:00
|
|
|
EPAIR_UNLOCK(epair_dpcpu);
|
2009-06-24 22:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
epair_transmit_locked(struct ifnet *ifp, struct mbuf *m)
|
|
|
|
{
|
2009-07-26 12:20:07 +00:00
|
|
|
struct epair_dpcpu *epair_dpcpu;
|
2009-06-24 22:21:30 +00:00
|
|
|
struct epair_softc *sc;
|
|
|
|
struct ifnet *oifp;
|
|
|
|
int error, len;
|
|
|
|
short mflags;
|
|
|
|
|
|
|
|
DPRINTF("ifp=%p m=%p\n", ifp, m);
|
2009-07-26 12:20:07 +00:00
|
|
|
sc = ifp->if_softc;
|
|
|
|
epair_dpcpu = DPCPU_ID_PTR(sc->cpuid, epair_dpcpu);
|
|
|
|
EPAIR_LOCK_ASSERT(epair_dpcpu);
|
2009-06-24 22:21:30 +00:00
|
|
|
|
|
|
|
if (m == NULL)
|
|
|
|
return (0);
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
/*
|
|
|
|
* We are not going to use the interface en/dequeue mechanism
|
|
|
|
* on the TX side. We are called from ether_output_frame()
|
|
|
|
* and will put the packet into the incoming queue of the
|
|
|
|
* other interface of our pair via the netsir.
|
|
|
|
*/
|
|
|
|
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
|
|
|
|
m_freem(m);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
if ((ifp->if_flags & IFF_UP) == 0) {
|
|
|
|
m_freem(m);
|
|
|
|
return (ENETDOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
BPF_MTAP(ifp, m);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In case the outgoing interface is not usable,
|
|
|
|
* drop the packet.
|
|
|
|
*/
|
|
|
|
oifp = sc->oifp;
|
|
|
|
if ((oifp->if_drv_flags & IFF_DRV_RUNNING) == 0 ||
|
|
|
|
(oifp->if_flags & IFF_UP) ==0) {
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
|
2009-06-24 22:21:30 +00:00
|
|
|
m_freem(m);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
len = m->m_pkthdr.len;
|
|
|
|
mflags = m->m_flags;
|
|
|
|
DPRINTF("packet %s -> %s\n", ifp->if_xname, oifp->if_xname);
|
|
|
|
|
|
|
|
#ifdef ALTQ
|
2016-05-03 18:05:43 +00:00
|
|
|
/* Support ALTQ via the classic if_start() path. */
|
2009-06-24 22:21:30 +00:00
|
|
|
IF_LOCK(&ifp->if_snd);
|
|
|
|
if (ALTQ_IS_ENABLED(&ifp->if_snd)) {
|
|
|
|
ALTQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
|
|
|
|
if (error)
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OQDROPS, 1);
|
2009-06-24 22:21:30 +00:00
|
|
|
IF_UNLOCK(&ifp->if_snd);
|
|
|
|
if (!error) {
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OBYTES, len);
|
2009-06-24 22:21:30 +00:00
|
|
|
if (mflags & (M_BCAST|M_MCAST))
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OMCASTS, 1);
|
2009-06-24 22:21:30 +00:00
|
|
|
|
|
|
|
if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0)
|
|
|
|
epair_start_locked(ifp);
|
|
|
|
else
|
2009-07-26 12:20:07 +00:00
|
|
|
(void)epair_add_ifp_for_draining(ifp);
|
2009-06-24 22:21:30 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
IF_UNLOCK(&ifp->if_snd);
|
|
|
|
#endif
|
|
|
|
|
2009-07-26 12:20:07 +00:00
|
|
|
if ((epair_dpcpu->epair_drv_flags & IFF_DRV_OACTIVE) != 0) {
|
2009-06-24 22:21:30 +00:00
|
|
|
/*
|
|
|
|
* Our hardware queue is full, try to fall back
|
|
|
|
* queuing to the ifq but do not call ifp->if_start.
|
|
|
|
* Either we are lucky or the packet is gone.
|
|
|
|
*/
|
|
|
|
IFQ_ENQUEUE(&ifp->if_snd, m, error);
|
|
|
|
if (!error)
|
2009-07-26 12:20:07 +00:00
|
|
|
(void)epair_add_ifp_for_draining(ifp);
|
2009-06-24 22:21:30 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2021-10-26 07:57:56 +00:00
|
|
|
|
|
|
|
epair_clear_mbuf(m);
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
sc = oifp->if_softc;
|
|
|
|
/*
|
|
|
|
* Add a reference so the interface cannot go while the
|
|
|
|
* packet is in transit as we rely on rcvif to stay valid.
|
|
|
|
*/
|
2009-07-26 12:20:07 +00:00
|
|
|
EPAIR_REFCOUNT_AQUIRE(&sc->refcount);
|
2009-06-24 22:21:30 +00:00
|
|
|
m->m_pkthdr.rcvif = oifp;
|
|
|
|
CURVNET_SET_QUIET(oifp->if_vnet);
|
|
|
|
error = netisr_queue(NETISR_EPAIR, m);
|
|
|
|
CURVNET_RESTORE();
|
|
|
|
if (!error) {
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
|
2009-06-24 22:21:30 +00:00
|
|
|
/*
|
|
|
|
* IFQ_HANDOFF_ADJ/ip_handoff() update statistics,
|
|
|
|
* but as we bypass all this we have to duplicate
|
|
|
|
* the logic another time.
|
|
|
|
*/
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OBYTES, len);
|
2009-06-24 22:21:30 +00:00
|
|
|
if (mflags & (M_BCAST|M_MCAST))
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OMCASTS, 1);
|
2009-06-24 22:21:30 +00:00
|
|
|
/* Someone else received the packet. */
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(oifp, IFCOUNTER_IPACKETS, 1);
|
2009-06-24 22:21:30 +00:00
|
|
|
} else {
|
|
|
|
/* The packet was freed already. */
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_dpcpu->epair_drv_flags |= IFF_DRV_OACTIVE;
|
2009-06-24 22:21:30 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
2014-09-19 10:39:58 +00:00
|
|
|
if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
|
2010-03-06 21:22:28 +00:00
|
|
|
EPAIR_REFCOUNT_RELEASE(&sc->refcount);
|
|
|
|
EPAIR_REFCOUNT_ASSERT((int)sc->refcount >= 1,
|
|
|
|
("%s: ifp=%p sc->refcount not >= 1: %d",
|
|
|
|
__func__, oifp, sc->refcount));
|
2009-06-24 22:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
epair_transmit(struct ifnet *ifp, struct mbuf *m)
|
|
|
|
{
|
2009-07-26 12:20:07 +00:00
|
|
|
struct epair_dpcpu *epair_dpcpu;
|
2009-06-24 22:21:30 +00:00
|
|
|
int error;
|
|
|
|
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_dpcpu = DPCPU_ID_PTR(cpuid_from_ifp(ifp), epair_dpcpu);
|
|
|
|
EPAIR_LOCK(epair_dpcpu);
|
2009-06-24 22:21:30 +00:00
|
|
|
error = epair_transmit_locked(ifp, m);
|
2009-07-26 12:20:07 +00:00
|
|
|
EPAIR_UNLOCK(epair_dpcpu);
|
2009-06-24 22:21:30 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
epair_qflush(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct epair_softc *sc;
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
sc = ifp->if_softc;
|
2020-12-01 16:34:43 +00:00
|
|
|
KASSERT(sc != NULL, ("%s: ifp=%p, epair_softc gone? sc=%p\n",
|
|
|
|
__func__, ifp, sc));
|
2009-06-24 22:21:30 +00:00
|
|
|
/*
|
2010-03-06 21:22:28 +00:00
|
|
|
* Remove this ifp from all backpointer lists. The interface will not
|
|
|
|
* usable for flushing anyway nor should it have anything to flush
|
|
|
|
* after if_qflush().
|
2009-06-24 22:21:30 +00:00
|
|
|
*/
|
2010-03-06 21:22:28 +00:00
|
|
|
epair_remove_ifp_from_draining(ifp);
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
if (sc->if_qflush)
|
|
|
|
sc->if_qflush(ifp);
|
|
|
|
}
|
|
|
|
|
2011-05-24 07:57:28 +00:00
|
|
|
static int
|
|
|
|
epair_media_change(struct ifnet *ifp __unused)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Do nothing. */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
epair_media_status(struct ifnet *ifp __unused, struct ifmediareq *imr)
|
|
|
|
{
|
|
|
|
|
|
|
|
imr->ifm_status = IFM_AVALID | IFM_ACTIVE;
|
|
|
|
imr->ifm_active = IFM_ETHER | IFM_10G_T | IFM_FDX;
|
|
|
|
}
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
static int
|
|
|
|
epair_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
|
|
|
{
|
2011-05-24 07:57:28 +00:00
|
|
|
struct epair_softc *sc;
|
2009-06-24 22:21:30 +00:00
|
|
|
struct ifreq *ifr;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ifr = (struct ifreq *)data;
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
|
2011-05-24 07:57:28 +00:00
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->media, cmd);
|
|
|
|
break;
|
|
|
|
|
2009-07-26 12:20:07 +00:00
|
|
|
case SIOCSIFMTU:
|
|
|
|
/* We basically allow all kinds of MTUs. */
|
|
|
|
ifp->if_mtu = ifr->ifr_mtu;
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
default:
|
|
|
|
/* Let the common ethernet handler process this. */
|
|
|
|
error = ether_ioctl(ifp, cmd, data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
epair_init(void *dummy __unused)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interface cloning functions.
|
|
|
|
* We use our private ones so that we can create/destroy our secondary
|
|
|
|
* device along with the primary one.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
epair_clone_match(struct if_clone *ifc, const char *name)
|
|
|
|
{
|
|
|
|
const char *cp;
|
|
|
|
|
|
|
|
DPRINTF("name='%s'\n", name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our base name is epair.
|
|
|
|
* Our interfaces will be named epair<n>[ab].
|
|
|
|
* So accept anything of the following list:
|
|
|
|
* - epair
|
|
|
|
* - epair<n>
|
|
|
|
* but not the epair<n>[ab] versions.
|
|
|
|
*/
|
2012-10-16 13:37:54 +00:00
|
|
|
if (strncmp(epairname, name, sizeof(epairname)-1) != 0)
|
2009-06-24 22:21:30 +00:00
|
|
|
return (0);
|
|
|
|
|
2012-10-16 13:37:54 +00:00
|
|
|
for (cp = name + sizeof(epairname) - 1; *cp != '\0'; cp++) {
|
2009-06-24 22:21:30 +00:00
|
|
|
if (*cp < '0' || *cp > '9')
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2020-01-28 22:44:24 +00:00
|
|
|
static void
|
|
|
|
epair_clone_add(struct if_clone *ifc, struct epair_softc *scb)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
uint8_t eaddr[ETHER_ADDR_LEN]; /* 00:00:00:00:00:00 */
|
|
|
|
|
|
|
|
ifp = scb->ifp;
|
|
|
|
/* Copy epairNa etheraddr and change the last byte. */
|
|
|
|
memcpy(eaddr, scb->oifp->if_hw_addr, ETHER_ADDR_LEN);
|
|
|
|
eaddr[5] = 0x0b;
|
|
|
|
ether_ifattach(ifp, eaddr);
|
|
|
|
|
|
|
|
if_clone_addif(ifc, ifp);
|
|
|
|
}
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
static int
|
|
|
|
epair_clone_create(struct if_clone *ifc, char *name, size_t len, caddr_t params)
|
|
|
|
{
|
|
|
|
struct epair_softc *sca, *scb;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
char *dp;
|
|
|
|
int error, unit, wildcard;
|
2018-05-23 13:10:57 +00:00
|
|
|
uint64_t hostid;
|
|
|
|
uint32_t key[3];
|
|
|
|
uint32_t hash;
|
2009-06-24 22:21:30 +00:00
|
|
|
uint8_t eaddr[ETHER_ADDR_LEN]; /* 00:00:00:00:00:00 */
|
|
|
|
|
|
|
|
/* Try to see if a special unit was requested. */
|
|
|
|
error = ifc_name2unit(name, &unit);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
wildcard = (unit < 0);
|
|
|
|
|
|
|
|
error = ifc_alloc_unit(ifc, &unit);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If no unit had been given, we need to adjust the ifName.
|
|
|
|
* Also make sure there is space for our extra [ab] suffix.
|
|
|
|
*/
|
|
|
|
for (dp = name; *dp != '\0'; dp++);
|
|
|
|
if (wildcard) {
|
|
|
|
error = snprintf(dp, len - (dp - name), "%d", unit);
|
|
|
|
if (error > len - (dp - name) - 1) {
|
|
|
|
/* ifName too long. */
|
|
|
|
ifc_free_unit(ifc, unit);
|
|
|
|
return (ENOSPC);
|
|
|
|
}
|
|
|
|
dp += error;
|
|
|
|
}
|
|
|
|
if (len - (dp - name) - 1 < 1) {
|
|
|
|
/* No space left for our [ab] suffix. */
|
|
|
|
ifc_free_unit(ifc, unit);
|
|
|
|
return (ENOSPC);
|
|
|
|
}
|
2014-10-10 06:45:13 +00:00
|
|
|
*dp = 'b';
|
2009-06-24 22:21:30 +00:00
|
|
|
/* Must not change dp so we can replace 'a' by 'b' later. */
|
|
|
|
*(dp+1) = '\0';
|
|
|
|
|
2014-10-10 06:45:13 +00:00
|
|
|
/* Check if 'a' and 'b' interfaces already exist. */
|
|
|
|
if (ifunit(name) != NULL)
|
|
|
|
return (EEXIST);
|
|
|
|
*dp = 'a';
|
|
|
|
if (ifunit(name) != NULL)
|
|
|
|
return (EEXIST);
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
/* Allocate memory for both [ab] interfaces */
|
|
|
|
sca = malloc(sizeof(struct epair_softc), M_EPAIR, M_WAITOK | M_ZERO);
|
2009-07-26 12:20:07 +00:00
|
|
|
EPAIR_REFCOUNT_INIT(&sca->refcount, 1);
|
2009-06-24 22:21:30 +00:00
|
|
|
sca->ifp = if_alloc(IFT_ETHER);
|
|
|
|
if (sca->ifp == NULL) {
|
|
|
|
free(sca, M_EPAIR);
|
|
|
|
ifc_free_unit(ifc, unit);
|
|
|
|
return (ENOSPC);
|
|
|
|
}
|
|
|
|
|
|
|
|
scb = malloc(sizeof(struct epair_softc), M_EPAIR, M_WAITOK | M_ZERO);
|
2009-07-26 12:20:07 +00:00
|
|
|
EPAIR_REFCOUNT_INIT(&scb->refcount, 1);
|
2009-06-24 22:21:30 +00:00
|
|
|
scb->ifp = if_alloc(IFT_ETHER);
|
|
|
|
if (scb->ifp == NULL) {
|
|
|
|
free(scb, M_EPAIR);
|
|
|
|
if_free(sca->ifp);
|
|
|
|
free(sca, M_EPAIR);
|
|
|
|
ifc_free_unit(ifc, unit);
|
|
|
|
return (ENOSPC);
|
|
|
|
}
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
/*
|
|
|
|
* Cross-reference the interfaces so we will be able to free both.
|
|
|
|
*/
|
|
|
|
sca->oifp = scb->ifp;
|
|
|
|
scb->oifp = sca->ifp;
|
2009-07-26 12:20:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the cpuid for netisr queueing based on the
|
|
|
|
* ifIndex of the interfaces. As long as we cannot configure
|
|
|
|
* this or use cpuset information easily we cannot guarantee
|
|
|
|
* cache locality but we can at least allow parallelism.
|
|
|
|
*/
|
|
|
|
sca->cpuid =
|
2016-08-17 20:21:33 +00:00
|
|
|
netisr_get_cpuid(sca->ifp->if_index);
|
2009-07-26 12:20:07 +00:00
|
|
|
scb->cpuid =
|
2016-08-17 20:21:33 +00:00
|
|
|
netisr_get_cpuid(scb->ifp->if_index);
|
2015-09-02 16:30:45 +00:00
|
|
|
|
|
|
|
/* Initialise pseudo media types. */
|
|
|
|
ifmedia_init(&sca->media, 0, epair_media_change, epair_media_status);
|
|
|
|
ifmedia_add(&sca->media, IFM_ETHER | IFM_10G_T, 0, NULL);
|
|
|
|
ifmedia_set(&sca->media, IFM_ETHER | IFM_10G_T);
|
|
|
|
ifmedia_init(&scb->media, 0, epair_media_change, epair_media_status);
|
|
|
|
ifmedia_add(&scb->media, IFM_ETHER | IFM_10G_T, 0, NULL);
|
|
|
|
ifmedia_set(&scb->media, IFM_ETHER | IFM_10G_T);
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
/* Finish initialization of interface <n>a. */
|
|
|
|
ifp = sca->ifp;
|
|
|
|
ifp->if_softc = sca;
|
|
|
|
strlcpy(ifp->if_xname, name, IFNAMSIZ);
|
2012-10-16 13:37:54 +00:00
|
|
|
ifp->if_dname = epairname;
|
2009-06-24 22:21:30 +00:00
|
|
|
ifp->if_dunit = unit;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
2011-05-24 08:02:55 +00:00
|
|
|
ifp->if_capabilities = IFCAP_VLAN_MTU;
|
|
|
|
ifp->if_capenable = IFCAP_VLAN_MTU;
|
2009-06-24 22:21:30 +00:00
|
|
|
ifp->if_start = epair_start;
|
|
|
|
ifp->if_ioctl = epair_ioctl;
|
|
|
|
ifp->if_init = epair_init;
|
2017-03-24 00:55:16 +00:00
|
|
|
if_setsendqlen(ifp, ifqmaxlen);
|
|
|
|
if_setsendqready(ifp);
|
2018-05-23 13:10:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the etheraddr hashing the hostid and the
|
2018-07-23 07:11:58 +00:00
|
|
|
* interface index. The result would be hopefully unique.
|
|
|
|
* Note that the "a" component of an epair instance may get moved
|
|
|
|
* to a different VNET after creation. In that case its index
|
|
|
|
* will be freed and the index can get reused by new epair instance.
|
|
|
|
* Make sure we do not create same etheraddr again.
|
2018-05-23 13:10:57 +00:00
|
|
|
*/
|
|
|
|
getcredhostid(curthread->td_ucred, (unsigned long *)&hostid);
|
|
|
|
if (hostid == 0)
|
|
|
|
arc4rand(&hostid, sizeof(hostid), 0);
|
2018-07-23 07:11:58 +00:00
|
|
|
|
|
|
|
if (ifp->if_index > next_index)
|
|
|
|
next_index = ifp->if_index;
|
|
|
|
else
|
|
|
|
next_index++;
|
|
|
|
|
|
|
|
key[0] = (uint32_t)next_index;
|
2018-05-23 13:10:57 +00:00
|
|
|
key[1] = (uint32_t)(hostid & 0xffffffff);
|
|
|
|
key[2] = (uint32_t)((hostid >> 32) & 0xfffffffff);
|
|
|
|
hash = jenkins_hash32(key, 3, 0);
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
eaddr[0] = 0x02;
|
2018-05-23 13:10:57 +00:00
|
|
|
memcpy(&eaddr[1], &hash, 4);
|
2009-06-24 22:21:30 +00:00
|
|
|
eaddr[5] = 0x0a;
|
|
|
|
ether_ifattach(ifp, eaddr);
|
|
|
|
sca->if_qflush = ifp->if_qflush;
|
|
|
|
ifp->if_qflush = epair_qflush;
|
|
|
|
ifp->if_transmit = epair_transmit;
|
2014-03-13 03:42:24 +00:00
|
|
|
ifp->if_baudrate = IF_Gbps(10); /* arbitrary maximum */
|
2009-06-24 22:21:30 +00:00
|
|
|
|
|
|
|
/* Swap the name and finish initialization of interface <n>b. */
|
|
|
|
*dp = 'b';
|
|
|
|
|
|
|
|
ifp = scb->ifp;
|
|
|
|
ifp->if_softc = scb;
|
|
|
|
strlcpy(ifp->if_xname, name, IFNAMSIZ);
|
2012-10-16 13:37:54 +00:00
|
|
|
ifp->if_dname = epairname;
|
2009-06-24 22:21:30 +00:00
|
|
|
ifp->if_dunit = unit;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
2011-05-24 08:02:55 +00:00
|
|
|
ifp->if_capabilities = IFCAP_VLAN_MTU;
|
|
|
|
ifp->if_capenable = IFCAP_VLAN_MTU;
|
2009-06-24 22:21:30 +00:00
|
|
|
ifp->if_start = epair_start;
|
|
|
|
ifp->if_ioctl = epair_ioctl;
|
|
|
|
ifp->if_init = epair_init;
|
2017-03-24 00:55:16 +00:00
|
|
|
if_setsendqlen(ifp, ifqmaxlen);
|
|
|
|
if_setsendqready(ifp);
|
2009-06-24 22:21:30 +00:00
|
|
|
/* We need to play some tricks here for the second interface. */
|
2012-10-16 13:37:54 +00:00
|
|
|
strlcpy(name, epairname, len);
|
2020-01-28 22:44:24 +00:00
|
|
|
|
|
|
|
/* Correctly set the name for the cloner list. */
|
|
|
|
strlcpy(name, scb->ifp->if_xname, len);
|
|
|
|
epair_clone_add(ifc, scb);
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
scb->if_qflush = ifp->if_qflush;
|
|
|
|
ifp->if_qflush = epair_qflush;
|
|
|
|
ifp->if_transmit = epair_transmit;
|
2014-03-13 03:42:24 +00:00
|
|
|
ifp->if_baudrate = IF_Gbps(10); /* arbitrary maximum */
|
2009-06-24 22:21:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore name to <n>a as the ifp for this will go into the
|
|
|
|
* cloner list for the initial call.
|
|
|
|
*/
|
|
|
|
strlcpy(name, sca->ifp->if_xname, len);
|
|
|
|
DPRINTF("name='%s/%db' created sca=%p scb=%p\n", name, unit, sca, scb);
|
|
|
|
|
|
|
|
/* Tell the world, that we are ready to rock. */
|
|
|
|
sca->ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
|
|
|
scb->ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
2010-08-27 23:22:58 +00:00
|
|
|
if_link_state_change(sca->ifp, LINK_STATE_UP);
|
|
|
|
if_link_state_change(scb->ifp, LINK_STATE_UP);
|
2009-06-24 22:21:30 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
epair_clone_destroy(struct if_clone *ifc, struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct ifnet *oifp;
|
|
|
|
struct epair_softc *sca, *scb;
|
|
|
|
int unit, error;
|
|
|
|
|
|
|
|
DPRINTF("ifp=%p\n", ifp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In case we called into if_clone_destroyif() ourselves
|
|
|
|
* again to remove the second interface, the softc will be
|
|
|
|
* NULL. In that case so not do anything but return success.
|
|
|
|
*/
|
|
|
|
if (ifp->if_softc == NULL)
|
|
|
|
return (0);
|
2020-09-01 21:19:14 +00:00
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
unit = ifp->if_dunit;
|
|
|
|
sca = ifp->if_softc;
|
|
|
|
oifp = sca->oifp;
|
|
|
|
scb = oifp->if_softc;
|
|
|
|
|
|
|
|
DPRINTF("ifp=%p oifp=%p\n", ifp, oifp);
|
2010-08-27 23:22:58 +00:00
|
|
|
if_link_state_change(ifp, LINK_STATE_DOWN);
|
|
|
|
if_link_state_change(oifp, LINK_STATE_DOWN);
|
2009-06-24 22:21:30 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
|
|
|
oifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
2012-07-09 20:38:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get rid of our second half. As the other of the two
|
|
|
|
* interfaces may reside in a different vnet, we need to
|
|
|
|
* switch before freeing them.
|
|
|
|
*/
|
|
|
|
CURVNET_SET_QUIET(oifp->if_vnet);
|
2009-06-24 22:21:30 +00:00
|
|
|
ether_ifdetach(oifp);
|
|
|
|
/*
|
|
|
|
* Wait for all packets to be dispatched to if_input.
|
2012-07-09 20:38:18 +00:00
|
|
|
* The numbers can only go down as the interface is
|
2009-06-24 22:21:30 +00:00
|
|
|
* detached so there is no need to use atomics.
|
|
|
|
*/
|
2012-07-09 20:38:18 +00:00
|
|
|
DPRINTF("scb refcnt=%u\n", scb->refcount);
|
|
|
|
EPAIR_REFCOUNT_ASSERT(scb->refcount == 1,
|
|
|
|
("%s: ifp=%p scb->refcount!=1: %d", __func__, oifp, scb->refcount));
|
2009-06-24 22:21:30 +00:00
|
|
|
oifp->if_softc = NULL;
|
|
|
|
error = if_clone_destroyif(ifc, oifp);
|
|
|
|
if (error)
|
|
|
|
panic("%s: if_clone_destroyif() for our 2nd iface failed: %d",
|
|
|
|
__func__, error);
|
2012-07-09 20:38:18 +00:00
|
|
|
if_free(oifp);
|
|
|
|
ifmedia_removeall(&scb->media);
|
|
|
|
free(scb, M_EPAIR);
|
|
|
|
CURVNET_RESTORE();
|
2009-06-24 22:21:30 +00:00
|
|
|
|
2012-07-09 20:38:18 +00:00
|
|
|
ether_ifdetach(ifp);
|
2009-07-26 12:20:07 +00:00
|
|
|
/*
|
2012-07-09 20:38:18 +00:00
|
|
|
* Wait for all packets to be dispatched to if_input.
|
2009-07-26 12:20:07 +00:00
|
|
|
*/
|
2012-07-09 20:38:18 +00:00
|
|
|
DPRINTF("sca refcnt=%u\n", sca->refcount);
|
|
|
|
EPAIR_REFCOUNT_ASSERT(sca->refcount == 1,
|
|
|
|
("%s: ifp=%p sca->refcount!=1: %d", __func__, ifp, sca->refcount));
|
2010-09-02 16:11:12 +00:00
|
|
|
if_free(ifp);
|
2011-05-24 07:57:28 +00:00
|
|
|
ifmedia_removeall(&sca->media);
|
2009-06-24 22:21:30 +00:00
|
|
|
free(sca, M_EPAIR);
|
|
|
|
ifc_free_unit(ifc, unit);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2014-10-10 06:45:13 +00:00
|
|
|
static void
|
|
|
|
vnet_epair_init(const void *unused __unused)
|
|
|
|
{
|
|
|
|
|
|
|
|
V_epair_cloner = if_clone_advanced(epairname, 0,
|
|
|
|
epair_clone_match, epair_clone_create, epair_clone_destroy);
|
2016-06-03 13:57:10 +00:00
|
|
|
#ifdef VIMAGE
|
|
|
|
netisr_register_vnet(&epair_nh);
|
|
|
|
#endif
|
2014-10-10 06:45:13 +00:00
|
|
|
}
|
Get closer to a VIMAGE network stack teardown from top to bottom rather
than removing the network interfaces first. This change is rather larger
and convoluted as the ordering requirements cannot be separated.
Move the pfil(9) framework to SI_SUB_PROTO_PFIL, move Firewalls and
related modules to their own SI_SUB_PROTO_FIREWALL.
Move initialization of "physical" interfaces to SI_SUB_DRIVERS,
move virtual (cloned) interfaces to SI_SUB_PSEUDO.
Move Multicast to SI_SUB_PROTO_MC.
Re-work parts of multicast initialisation and teardown, not taking the
huge amount of memory into account if used as a module yet.
For interface teardown we try to do as many of them as we can on
SI_SUB_INIT_IF, but for some this makes no sense, e.g., when tunnelling
over a higher layer protocol such as IP. In that case the interface
has to go along (or before) the higher layer protocol is shutdown.
Kernel hhooks need to go last on teardown as they may be used at various
higher layers and we cannot remove them before we cleaned up the higher
layers.
For interface teardown there are multiple paths:
(a) a cloned interface is destroyed (inside a VIMAGE or in the base system),
(b) any interface is moved from a virtual network stack to a different
network stack ("vmove"), or (c) a virtual network stack is being shut down.
All code paths go through if_detach_internal() where we, depending on the
vmove flag or the vnet state, make a decision on how much to shut down;
in case we are destroying a VNET the individual protocol layers will
cleanup their own parts thus we cannot do so again for each interface as
we end up with, e.g., double-frees, destroying locks twice or acquiring
already destroyed locks.
When calling into protocol cleanups we equally have to tell them
whether they need to detach upper layer protocols ("ulp") or not
(e.g., in6_ifdetach()).
Provide or enahnce helper functions to do proper cleanup at a protocol
rather than at an interface level.
Approved by: re (hrs)
Obtained from: projects/vnet
Reviewed by: gnn, jhb
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D6747
2016-06-21 13:48:49 +00:00
|
|
|
VNET_SYSINIT(vnet_epair_init, SI_SUB_PSEUDO, SI_ORDER_ANY,
|
2014-10-10 06:45:13 +00:00
|
|
|
vnet_epair_init, NULL);
|
|
|
|
|
|
|
|
static void
|
|
|
|
vnet_epair_uninit(const void *unused __unused)
|
|
|
|
{
|
|
|
|
|
2016-06-03 13:57:10 +00:00
|
|
|
#ifdef VIMAGE
|
|
|
|
netisr_unregister_vnet(&epair_nh);
|
|
|
|
#endif
|
2014-10-10 06:45:13 +00:00
|
|
|
if_clone_detach(V_epair_cloner);
|
|
|
|
}
|
Get closer to a VIMAGE network stack teardown from top to bottom rather
than removing the network interfaces first. This change is rather larger
and convoluted as the ordering requirements cannot be separated.
Move the pfil(9) framework to SI_SUB_PROTO_PFIL, move Firewalls and
related modules to their own SI_SUB_PROTO_FIREWALL.
Move initialization of "physical" interfaces to SI_SUB_DRIVERS,
move virtual (cloned) interfaces to SI_SUB_PSEUDO.
Move Multicast to SI_SUB_PROTO_MC.
Re-work parts of multicast initialisation and teardown, not taking the
huge amount of memory into account if used as a module yet.
For interface teardown we try to do as many of them as we can on
SI_SUB_INIT_IF, but for some this makes no sense, e.g., when tunnelling
over a higher layer protocol such as IP. In that case the interface
has to go along (or before) the higher layer protocol is shutdown.
Kernel hhooks need to go last on teardown as they may be used at various
higher layers and we cannot remove them before we cleaned up the higher
layers.
For interface teardown there are multiple paths:
(a) a cloned interface is destroyed (inside a VIMAGE or in the base system),
(b) any interface is moved from a virtual network stack to a different
network stack ("vmove"), or (c) a virtual network stack is being shut down.
All code paths go through if_detach_internal() where we, depending on the
vmove flag or the vnet state, make a decision on how much to shut down;
in case we are destroying a VNET the individual protocol layers will
cleanup their own parts thus we cannot do so again for each interface as
we end up with, e.g., double-frees, destroying locks twice or acquiring
already destroyed locks.
When calling into protocol cleanups we equally have to tell them
whether they need to detach upper layer protocols ("ulp") or not
(e.g., in6_ifdetach()).
Provide or enahnce helper functions to do proper cleanup at a protocol
rather than at an interface level.
Approved by: re (hrs)
Obtained from: projects/vnet
Reviewed by: gnn, jhb
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D6747
2016-06-21 13:48:49 +00:00
|
|
|
VNET_SYSUNINIT(vnet_epair_uninit, SI_SUB_INIT_IF, SI_ORDER_ANY,
|
2014-10-10 06:45:13 +00:00
|
|
|
vnet_epair_uninit, NULL);
|
|
|
|
|
2017-11-01 14:27:26 +00:00
|
|
|
static void
|
|
|
|
epair_uninit(const void *unused __unused)
|
|
|
|
{
|
|
|
|
netisr_unregister(&epair_nh);
|
|
|
|
epair_dpcpu_detach();
|
|
|
|
if (bootverbose)
|
|
|
|
printf("%s unloaded.\n", epairname);
|
|
|
|
}
|
|
|
|
SYSUNINIT(epair_uninit, SI_SUB_INIT_IF, SI_ORDER_MIDDLE,
|
|
|
|
epair_uninit, NULL);
|
|
|
|
|
2009-06-24 22:21:30 +00:00
|
|
|
static int
|
|
|
|
epair_modevent(module_t mod, int type, void *data)
|
|
|
|
{
|
2009-07-26 12:20:07 +00:00
|
|
|
int qlimit;
|
2009-06-24 22:21:30 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
/* For now limit us to one global mutex and one inq. */
|
2009-07-26 12:20:07 +00:00
|
|
|
epair_dpcpu_init();
|
|
|
|
epair_nh.nh_qlimit = 42 * ifqmaxlen; /* 42 shall be the number. */
|
|
|
|
if (TUNABLE_INT_FETCH("net.link.epair.netisr_maxqlen", &qlimit))
|
|
|
|
epair_nh.nh_qlimit = qlimit;
|
|
|
|
netisr_register(&epair_nh);
|
2009-06-24 22:21:30 +00:00
|
|
|
if (bootverbose)
|
2012-10-16 13:37:54 +00:00
|
|
|
printf("%s initialized.\n", epairname);
|
2009-06-24 22:21:30 +00:00
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
2017-11-01 14:27:26 +00:00
|
|
|
/* Handled in epair_uninit() */
|
2009-06-24 22:21:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static moduledata_t epair_mod = {
|
|
|
|
"if_epair",
|
|
|
|
epair_modevent,
|
2012-10-10 08:36:38 +00:00
|
|
|
0
|
2009-06-24 22:21:30 +00:00
|
|
|
};
|
|
|
|
|
Get closer to a VIMAGE network stack teardown from top to bottom rather
than removing the network interfaces first. This change is rather larger
and convoluted as the ordering requirements cannot be separated.
Move the pfil(9) framework to SI_SUB_PROTO_PFIL, move Firewalls and
related modules to their own SI_SUB_PROTO_FIREWALL.
Move initialization of "physical" interfaces to SI_SUB_DRIVERS,
move virtual (cloned) interfaces to SI_SUB_PSEUDO.
Move Multicast to SI_SUB_PROTO_MC.
Re-work parts of multicast initialisation and teardown, not taking the
huge amount of memory into account if used as a module yet.
For interface teardown we try to do as many of them as we can on
SI_SUB_INIT_IF, but for some this makes no sense, e.g., when tunnelling
over a higher layer protocol such as IP. In that case the interface
has to go along (or before) the higher layer protocol is shutdown.
Kernel hhooks need to go last on teardown as they may be used at various
higher layers and we cannot remove them before we cleaned up the higher
layers.
For interface teardown there are multiple paths:
(a) a cloned interface is destroyed (inside a VIMAGE or in the base system),
(b) any interface is moved from a virtual network stack to a different
network stack ("vmove"), or (c) a virtual network stack is being shut down.
All code paths go through if_detach_internal() where we, depending on the
vmove flag or the vnet state, make a decision on how much to shut down;
in case we are destroying a VNET the individual protocol layers will
cleanup their own parts thus we cannot do so again for each interface as
we end up with, e.g., double-frees, destroying locks twice or acquiring
already destroyed locks.
When calling into protocol cleanups we equally have to tell them
whether they need to detach upper layer protocols ("ulp") or not
(e.g., in6_ifdetach()).
Provide or enahnce helper functions to do proper cleanup at a protocol
rather than at an interface level.
Approved by: re (hrs)
Obtained from: projects/vnet
Reviewed by: gnn, jhb
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D6747
2016-06-21 13:48:49 +00:00
|
|
|
DECLARE_MODULE(if_epair, epair_mod, SI_SUB_PSEUDO, SI_ORDER_MIDDLE);
|
2009-06-24 22:21:30 +00:00
|
|
|
MODULE_VERSION(if_epair, 1);
|