2005-01-06 23:35:40 +00:00
|
|
|
/*-
|
2017-11-20 19:43:44 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1994-05-24 10:09:53 +00:00
|
|
|
* Copyright (c) 1982, 1986, 1993
|
|
|
|
* The Regents of the University of California. 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, 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.
|
2016-09-15 13:16:20 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-24 10:09:53 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
*
|
|
|
|
* @(#)uipc_domain.c 8.2 (Berkeley) 10/18/93
|
|
|
|
*/
|
|
|
|
|
2003-06-11 00:56:59 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/param.h>
|
2002-05-31 11:52:35 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/protosw.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/domain.h>
|
2006-04-21 09:25:40 +00:00
|
|
|
#include <sys/eventhandler.h>
|
2020-01-15 03:34:21 +00:00
|
|
|
#include <sys/epoch.h>
|
2002-05-20 05:41:09 +00:00
|
|
|
#include <sys/mbuf.h>
|
2002-05-31 11:52:35 +00:00
|
|
|
#include <sys/kernel.h>
|
2003-09-01 05:01:55 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2021-08-15 21:41:47 +00:00
|
|
|
#include <sys/rmlock.h>
|
1998-05-15 20:11:40 +00:00
|
|
|
#include <sys/socketvar.h>
|
1994-05-24 10:09:53 +00:00
|
|
|
#include <sys/systm.h>
|
2009-08-01 19:26:27 +00:00
|
|
|
|
2020-06-26 02:38:27 +00:00
|
|
|
#include <machine/atomic.h>
|
|
|
|
|
2009-08-01 19:26:27 +00:00
|
|
|
#include <net/vnet.h>
|
|
|
|
|
1995-08-28 09:19:25 +00:00
|
|
|
/*
|
|
|
|
* System initialization
|
|
|
|
*
|
2001-12-08 04:20:54 +00:00
|
|
|
* Note: domain initialization takes place on a per domain basis
|
|
|
|
* as a result of traversing a SYSINIT linker set. Most likely,
|
|
|
|
* each domain would want to call DOMAIN_SET(9) itself, which
|
|
|
|
* would cause the domain to be added just after domaininit()
|
|
|
|
* is called during startup.
|
1995-08-28 09:19:25 +00:00
|
|
|
*
|
2001-12-08 04:20:54 +00:00
|
|
|
* See DOMAIN_SET(9) for details on its use.
|
1995-08-28 09:19:25 +00:00
|
|
|
*/
|
|
|
|
|
2002-03-19 21:25:46 +00:00
|
|
|
static void domaininit(void *);
|
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
|
|
|
SYSINIT(domain, SI_SUB_PROTO_DOMAININIT, SI_ORDER_ANY, domaininit, NULL);
|
1995-08-28 09:19:25 +00:00
|
|
|
|
2004-11-30 22:38:37 +00:00
|
|
|
static void domainfinalize(void *);
|
|
|
|
SYSINIT(domainfin, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_FIRST, domainfinalize,
|
2008-03-16 10:58:09 +00:00
|
|
|
NULL);
|
2004-11-30 22:38:37 +00:00
|
|
|
|
2003-09-01 05:01:55 +00:00
|
|
|
struct domain *domains; /* registered protocol domains */
|
2004-11-30 22:38:37 +00:00
|
|
|
int domain_init_status = 0;
|
2009-01-04 19:22:53 +00:00
|
|
|
static struct mtx dom_mtx; /* domain list lock */
|
2003-09-02 20:59:23 +00:00
|
|
|
MTX_SYSINIT(domain, &dom_mtx, "domain list", MTX_DEF);
|
1995-05-11 00:13:26 +00:00
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
static int
|
|
|
|
pr_accept_notsupp(struct socket *so, struct sockaddr **nam)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_aio_queue_notsupp(struct socket *so, struct kaiocb *job)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_bind_notsupp(struct socket *so, struct sockaddr *nam, struct thread *td)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_bindat_notsupp(int fd, struct socket *so, struct sockaddr *nam,
|
|
|
|
struct thread *td)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_connect_notsupp(struct socket *so, struct sockaddr *nam, struct thread *td)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_connectat_notsupp(int fd, struct socket *so, struct sockaddr *nam,
|
|
|
|
struct thread *td)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_connect2_notsupp(struct socket *so1, struct socket *so2)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_control_notsupp(struct socket *so, u_long cmd, void *data,
|
|
|
|
struct ifnet *ifp, struct thread *td)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_disconnect_notsupp(struct socket *so)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_listen_notsupp(struct socket *so, int backlog, struct thread *td)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_peeraddr_notsupp(struct socket *so, struct sockaddr **nam)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_rcvd_notsupp(struct socket *so, int flags)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_rcvoob_notsupp(struct socket *so, struct mbuf *m, int flags)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_send_notsupp(struct socket *so, int flags, struct mbuf *m,
|
|
|
|
struct sockaddr *addr, struct mbuf *control, struct thread *td)
|
|
|
|
{
|
|
|
|
if (control != NULL)
|
|
|
|
m_freem(control);
|
|
|
|
if ((flags & PRUS_NOTREADY) == 0)
|
|
|
|
m_freem(m);
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_ready_notsupp(struct socket *so, struct mbuf *m, int count)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_shutdown_notsupp(struct socket *so)
|
2004-11-11 19:19:54 +00:00
|
|
|
{
|
2022-08-17 18:50:32 +00:00
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
2004-11-11 19:19:54 +00:00
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
static int
|
|
|
|
pr_sockaddr_notsupp(struct socket *so, struct sockaddr **nam)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
2004-11-11 19:19:54 +00:00
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
static int
|
|
|
|
pr_sosend_notsupp(struct socket *so, struct sockaddr *addr, struct uio *uio,
|
|
|
|
struct mbuf *top, struct mbuf *control, int flags, struct thread *td)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
2008-12-25 11:32:38 +00:00
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
static int
|
|
|
|
pr_soreceive_notsupp(struct socket *so, struct sockaddr **paddr,
|
|
|
|
struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, int *flagsp)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pr_sopoll_notsupp(struct socket *so, int events, struct ucred *cred,
|
|
|
|
struct thread *td)
|
|
|
|
{
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pr_init(struct protosw *pr)
|
|
|
|
{
|
|
|
|
|
|
|
|
KASSERT(pr->pr_attach != NULL,
|
|
|
|
("%s: protocol doesn't have pr_attach", __func__));
|
|
|
|
|
|
|
|
#define DEFAULT(foo, bar) if (pr->foo == NULL) pr->foo = bar
|
|
|
|
DEFAULT(pr_sosend, sosend_generic);
|
|
|
|
DEFAULT(pr_soreceive, soreceive_generic);
|
|
|
|
DEFAULT(pr_sopoll, sopoll_generic);
|
|
|
|
|
|
|
|
#define NOTSUPP(foo) if (pr->foo == NULL) pr->foo = foo ## _notsupp
|
|
|
|
NOTSUPP(pr_accept);
|
|
|
|
NOTSUPP(pr_aio_queue);
|
|
|
|
NOTSUPP(pr_bind);
|
|
|
|
NOTSUPP(pr_bindat);
|
|
|
|
NOTSUPP(pr_connect);
|
|
|
|
NOTSUPP(pr_connect2);
|
|
|
|
NOTSUPP(pr_connectat);
|
|
|
|
NOTSUPP(pr_control);
|
|
|
|
NOTSUPP(pr_disconnect);
|
|
|
|
NOTSUPP(pr_listen);
|
|
|
|
NOTSUPP(pr_peeraddr);
|
|
|
|
NOTSUPP(pr_rcvd);
|
|
|
|
NOTSUPP(pr_rcvoob);
|
|
|
|
NOTSUPP(pr_send);
|
|
|
|
NOTSUPP(pr_shutdown);
|
|
|
|
NOTSUPP(pr_sockaddr);
|
|
|
|
NOTSUPP(pr_sosend);
|
|
|
|
NOTSUPP(pr_soreceive);
|
|
|
|
NOTSUPP(pr_sopoll);
|
|
|
|
NOTSUPP(pr_ready);
|
2004-11-11 19:19:54 +00:00
|
|
|
}
|
|
|
|
|
1999-01-21 00:26:41 +00:00
|
|
|
/*
|
|
|
|
* Add a new protocol domain to the list of supported domains
|
2004-10-19 15:13:30 +00:00
|
|
|
* Note: you cant unload it again because a socket may be using it.
|
1999-01-21 00:26:41 +00:00
|
|
|
* XXX can't fail at this time.
|
|
|
|
*/
|
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
|
|
|
void
|
|
|
|
domain_init(void *arg)
|
1999-01-21 00:26:41 +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
|
|
|
struct domain *dp = arg;
|
2003-09-01 05:01:55 +00:00
|
|
|
struct protosw *pr;
|
2020-06-26 02:17:47 +00:00
|
|
|
int flags;
|
1999-01-21 00:26:41 +00:00
|
|
|
|
2022-01-03 18:15:22 +00:00
|
|
|
MPASS(IS_DEFAULT_VNET(curvnet));
|
|
|
|
|
2020-06-26 02:17:47 +00:00
|
|
|
flags = atomic_load_acq_int(&dp->dom_flags);
|
|
|
|
if ((flags & DOMF_SUPPORTED) == 0)
|
|
|
|
return;
|
2022-01-03 18:15:22 +00:00
|
|
|
MPASS((flags & DOMF_INITED) == 0);
|
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
for (int i = 0; i < dp->dom_nprotosw; i++)
|
|
|
|
if ((pr = dp->dom_protosw[i]) != NULL) {
|
|
|
|
pr->pr_domain = dp;
|
|
|
|
pr_init(pr);
|
|
|
|
}
|
2021-08-15 21:41:47 +00:00
|
|
|
|
1999-01-21 00:26:41 +00:00
|
|
|
/*
|
2003-03-07 22:47:32 +00:00
|
|
|
* update global information about maximums
|
1999-01-21 00:26:41 +00:00
|
|
|
*/
|
|
|
|
max_hdr = max_linkhdr + max_protohdr;
|
|
|
|
max_datalen = MHLEN - max_hdr;
|
2006-02-18 17:16:18 +00:00
|
|
|
if (max_datalen < 1)
|
|
|
|
panic("%s: max_datalen < 1", __func__);
|
2022-01-03 18:15:22 +00:00
|
|
|
atomic_set_rel_int(&dp->dom_flags, DOMF_INITED);
|
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
|
|
|
}
|
|
|
|
|
1999-01-21 00:26:41 +00:00
|
|
|
/*
|
|
|
|
* Add a new protocol domain to the list of supported domains
|
2004-10-19 15:13:30 +00:00
|
|
|
* Note: you cant unload it again because a socket may be using it.
|
1999-01-21 00:26:41 +00:00
|
|
|
* XXX can't fail at this time.
|
|
|
|
*/
|
1999-04-26 08:56:09 +00:00
|
|
|
void
|
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
|
|
|
domain_add(void *data)
|
1999-01-21 00:26:41 +00:00
|
|
|
{
|
1999-04-26 08:56:09 +00:00
|
|
|
struct domain *dp;
|
1999-01-21 00:26:41 +00:00
|
|
|
|
1999-04-26 08:56:09 +00:00
|
|
|
dp = (struct domain *)data;
|
2020-06-26 02:17:47 +00:00
|
|
|
if (dp->dom_probe != NULL && (*dp->dom_probe)() != 0)
|
|
|
|
return;
|
|
|
|
atomic_set_rel_int(&dp->dom_flags, DOMF_SUPPORTED);
|
2003-09-01 05:01:55 +00:00
|
|
|
mtx_lock(&dom_mtx);
|
1999-01-21 00:26:41 +00:00
|
|
|
dp->dom_next = domains;
|
|
|
|
domains = dp;
|
2004-11-30 22:38:37 +00:00
|
|
|
|
|
|
|
KASSERT(domain_init_status >= 1,
|
2012-02-23 17:47:19 +00:00
|
|
|
("attempt to domain_add(%s) before domaininit()",
|
2004-11-30 22:38:37 +00:00
|
|
|
dp->dom_name));
|
|
|
|
#ifndef INVARIANTS
|
2004-12-02 15:47:15 +00:00
|
|
|
if (domain_init_status < 1)
|
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
|
|
|
printf("WARNING: attempt to domain_add(%s) before "
|
2004-11-30 22:38:37 +00:00
|
|
|
"domaininit()\n", dp->dom_name);
|
|
|
|
#endif
|
2003-09-01 05:01:55 +00:00
|
|
|
mtx_unlock(&dom_mtx);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
2022-08-12 13:36:53 +00:00
|
|
|
void
|
|
|
|
domain_remove(void *data)
|
|
|
|
{
|
|
|
|
struct domain *dp = (struct domain *)data;
|
|
|
|
|
|
|
|
if ((dp->dom_flags & DOMF_UNLOADABLE) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mtx_lock(&dom_mtx);
|
|
|
|
if (domains == dp) {
|
|
|
|
domains = dp->dom_next;
|
|
|
|
} else {
|
|
|
|
struct domain *curr;
|
|
|
|
for (curr = domains; curr != NULL; curr = curr->dom_next) {
|
|
|
|
if (curr->dom_next == dp) {
|
|
|
|
curr->dom_next = dp->dom_next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mtx_unlock(&dom_mtx);
|
|
|
|
}
|
|
|
|
|
1995-08-28 09:19:25 +00:00
|
|
|
/* ARGSUSED*/
|
|
|
|
static void
|
1999-01-21 00:26:41 +00:00
|
|
|
domaininit(void *dummy)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2007-05-16 20:41:08 +00:00
|
|
|
|
1999-01-21 00:26:41 +00:00
|
|
|
if (max_linkhdr < 16) /* XXX */
|
|
|
|
max_linkhdr = 16;
|
|
|
|
|
2004-11-30 22:38:37 +00:00
|
|
|
mtx_lock(&dom_mtx);
|
|
|
|
KASSERT(domain_init_status == 0, ("domaininit called too late!"));
|
|
|
|
domain_init_status = 1;
|
|
|
|
mtx_unlock(&dom_mtx);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
2004-11-30 22:38:37 +00:00
|
|
|
/* ARGSUSED*/
|
|
|
|
static void
|
|
|
|
domainfinalize(void *dummy)
|
|
|
|
{
|
2007-05-16 20:41:08 +00:00
|
|
|
|
2004-11-30 22:38:37 +00:00
|
|
|
mtx_lock(&dom_mtx);
|
|
|
|
KASSERT(domain_init_status == 1, ("domainfinalize called too late!"));
|
|
|
|
domain_init_status = 2;
|
|
|
|
mtx_unlock(&dom_mtx);
|
|
|
|
}
|
1995-08-28 09:19:25 +00:00
|
|
|
|
2012-12-07 02:22:48 +00:00
|
|
|
struct domain *
|
|
|
|
pffinddomain(int family)
|
|
|
|
{
|
|
|
|
struct domain *dp;
|
|
|
|
|
|
|
|
for (dp = domains; dp != NULL; dp = dp->dom_next)
|
|
|
|
if (dp->dom_family == family)
|
|
|
|
return (dp);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
1994-05-24 10:09:53 +00:00
|
|
|
struct protosw *
|
2007-05-16 20:41:08 +00:00
|
|
|
pffindtype(int family, int type)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2007-05-16 20:41:08 +00:00
|
|
|
struct domain *dp;
|
|
|
|
struct protosw *pr;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2012-12-07 02:22:48 +00:00
|
|
|
dp = pffinddomain(family);
|
|
|
|
if (dp == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
for (int i = 0; i < dp->dom_nprotosw; i++)
|
|
|
|
if ((pr = dp->dom_protosw[i]) != NULL && pr->pr_type == type)
|
1994-05-24 10:09:53 +00:00
|
|
|
return (pr);
|
2022-08-17 18:50:32 +00:00
|
|
|
|
2012-12-07 02:22:48 +00:00
|
|
|
return (NULL);
|
1994-05-24 10:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct protosw *
|
2007-05-16 20:41:08 +00:00
|
|
|
pffindproto(int family, int protocol, int type)
|
1994-05-24 10:09:53 +00:00
|
|
|
{
|
2007-05-16 20:41:08 +00:00
|
|
|
struct domain *dp;
|
|
|
|
struct protosw *pr;
|
2012-12-07 02:22:48 +00:00
|
|
|
struct protosw *maybe;
|
1994-05-24 10:09:53 +00:00
|
|
|
|
2012-12-07 02:22:48 +00:00
|
|
|
dp = pffinddomain(family);
|
|
|
|
if (dp == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
maybe = NULL;
|
|
|
|
for (int i = 0; i < dp->dom_nprotosw; i++) {
|
|
|
|
if ((pr = dp->dom_protosw[i]) == NULL)
|
|
|
|
continue;
|
1994-05-24 10:09:53 +00:00
|
|
|
if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
|
|
|
|
return (pr);
|
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
/* XXX: raw catches all. Why? */
|
1994-05-24 10:09:53 +00:00
|
|
|
if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
|
2012-12-07 02:22:48 +00:00
|
|
|
pr->pr_protocol == 0 && maybe == NULL)
|
1994-05-24 10:09:53 +00:00
|
|
|
maybe = pr;
|
|
|
|
}
|
|
|
|
return (maybe);
|
|
|
|
}
|
|
|
|
|
2004-10-19 15:13:30 +00:00
|
|
|
/*
|
|
|
|
* The caller must make sure that the new protocol is fully set up and ready to
|
|
|
|
* accept requests before it is registered.
|
|
|
|
*/
|
|
|
|
int
|
2022-08-17 18:50:32 +00:00
|
|
|
protosw_register(struct domain *dp, struct protosw *npr)
|
2004-10-19 15:13:30 +00:00
|
|
|
{
|
2022-08-17 18:50:32 +00:00
|
|
|
struct protosw **prp;
|
2004-10-19 15:13:30 +00:00
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
MPASS(dp);
|
|
|
|
MPASS(npr && npr->pr_type > 0 && npr->pr_protocol > 0);
|
2004-10-19 15:13:30 +00:00
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
prp = NULL;
|
2004-10-23 18:52:06 +00:00
|
|
|
/*
|
|
|
|
* Protect us against races when two protocol registrations for
|
|
|
|
* the same protocol happen at the same time.
|
|
|
|
*/
|
2009-01-04 19:22:53 +00:00
|
|
|
mtx_lock(&dom_mtx);
|
2022-08-17 18:50:32 +00:00
|
|
|
for (int i = 0; i < dp->dom_nprotosw; i++) {
|
|
|
|
if (dp->dom_protosw[i] == NULL) {
|
|
|
|
/* Remember the first free spacer. */
|
|
|
|
if (prp == NULL)
|
|
|
|
prp = &dp->dom_protosw[i];
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The new protocol must not yet exist.
|
|
|
|
* XXXAO: Check only protocol?
|
|
|
|
* XXXGL: Maybe assert that it doesn't exist?
|
|
|
|
*/
|
|
|
|
if ((dp->dom_protosw[i]->pr_type == npr->pr_type) &&
|
|
|
|
(dp->dom_protosw[i]->pr_protocol ==
|
|
|
|
npr->pr_protocol)) {
|
|
|
|
mtx_unlock(&dom_mtx);
|
|
|
|
return (EEXIST);
|
|
|
|
}
|
2004-10-23 18:52:06 +00:00
|
|
|
|
|
|
|
}
|
2004-10-19 15:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If no free spacer is found we can't add the new protocol. */
|
2022-08-17 18:50:32 +00:00
|
|
|
if (prp == NULL) {
|
2009-01-04 19:22:53 +00:00
|
|
|
mtx_unlock(&dom_mtx);
|
2004-10-19 15:13:30 +00:00
|
|
|
return (ENOMEM);
|
2004-10-23 18:52:06 +00:00
|
|
|
}
|
2004-10-19 15:13:30 +00:00
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
npr->pr_domain = dp;
|
|
|
|
pr_init(npr);
|
|
|
|
*prp = npr;
|
2009-01-04 19:22:53 +00:00
|
|
|
mtx_unlock(&dom_mtx);
|
2004-10-23 18:52:06 +00:00
|
|
|
|
2004-10-19 15:13:30 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The caller must make sure the protocol and its functions correctly shut down
|
|
|
|
* all sockets and release all locks and memory references.
|
|
|
|
*/
|
|
|
|
int
|
2022-08-17 18:50:32 +00:00
|
|
|
protosw_unregister(struct protosw *pr)
|
2004-10-19 15:13:30 +00:00
|
|
|
{
|
|
|
|
struct domain *dp;
|
2022-08-17 18:50:32 +00:00
|
|
|
struct protosw **prp;
|
2004-10-19 15:13:30 +00:00
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
dp = pr->pr_domain;
|
|
|
|
prp = NULL;
|
2004-10-19 15:13:30 +00:00
|
|
|
|
2009-01-04 19:22:53 +00:00
|
|
|
mtx_lock(&dom_mtx);
|
2004-10-19 15:13:30 +00:00
|
|
|
/* The protocol must exist and only once. */
|
2022-08-17 18:50:32 +00:00
|
|
|
for (int i = 0; i < dp->dom_nprotosw; i++) {
|
|
|
|
if (dp->dom_protosw[i] == pr) {
|
|
|
|
KASSERT(prp == NULL,
|
|
|
|
("%s: domain %p protocol %p registered twice\n",
|
|
|
|
__func__, dp, pr));
|
|
|
|
prp = &dp->dom_protosw[i];
|
2004-10-19 15:13:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 18:50:32 +00:00
|
|
|
/* Protocol does not exist. XXXGL: assert that it does? */
|
|
|
|
if (prp == NULL) {
|
2009-01-04 19:22:53 +00:00
|
|
|
mtx_unlock(&dom_mtx);
|
2004-10-19 15:13:30 +00:00
|
|
|
return (EPROTONOSUPPORT);
|
2004-10-23 18:52:06 +00:00
|
|
|
}
|
2004-10-19 15:13:30 +00:00
|
|
|
|
|
|
|
/* De-orbit the protocol and make the slot available again. */
|
2022-08-17 18:50:32 +00:00
|
|
|
*prp = NULL;
|
2009-01-04 19:22:53 +00:00
|
|
|
mtx_unlock(&dom_mtx);
|
2004-10-23 18:52:06 +00:00
|
|
|
|
2004-10-19 15:13:30 +00:00
|
|
|
return (0);
|
|
|
|
}
|