Provide support for building SCTP as a loadable module.
With this change, a kernel compiled with "options SCTP_SUPPORT" and without "options SCTP" supports dynamic loading of the SCTP stack. Currently sctp.ko cannot be unloaded since some prerequisite teardown logic is not yet implemented. Attempts to unload the module will return EOPNOTSUPP. Discussed with: tuexen MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D21997
This commit is contained in:
parent
7ecaecc7c2
commit
866d79bd83
@ -26,7 +26,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 18, 2020
|
||||
.Dd July 9, 2020
|
||||
.Dt SCTP 4
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -144,8 +144,18 @@ The
|
||||
transport protocol also provides a unordered service as well.
|
||||
The unordered service allows a message to be sent and delivered
|
||||
with no regard to the ordering of any other message.
|
||||
.Pp
|
||||
The
|
||||
.Tn SCTP
|
||||
kernel implementation may either be compiled into the kernel, or loaded
|
||||
dynamically as a module.
|
||||
To support dynamic loading of the stack, the kernel must be compiled
|
||||
with
|
||||
.Cd "options SCTP_SUPPORT" .
|
||||
.Ss Extensions
|
||||
The FreeBSD implementation of
|
||||
The
|
||||
.Fx
|
||||
implementation of
|
||||
.Tn SCTP
|
||||
also supports the following extensions:
|
||||
.Bl -tag -width "sctp partial reliability"
|
||||
@ -609,3 +619,7 @@ Maximum outgoing SCTP buffer size.
|
||||
.Xr sctp_recvmsg 3 ,
|
||||
.Xr sctp_sendmsg 3 ,
|
||||
.Xr blackhole 4
|
||||
.Sh BUGS
|
||||
The
|
||||
.Nm
|
||||
kernel module cannot be unloaded.
|
||||
|
@ -319,6 +319,7 @@ SUBDIR= \
|
||||
${_safe} \
|
||||
${_sbni} \
|
||||
scc \
|
||||
${_sctp} \
|
||||
sdhci \
|
||||
${_sdhci_acpi} \
|
||||
sdhci_pci \
|
||||
@ -430,6 +431,9 @@ _ipfw_pmod= ipfw_pmod
|
||||
.if ${KERN_OPTS:MIPSEC_SUPPORT} && !${KERN_OPTS:MIPSEC}
|
||||
_ipsec= ipsec
|
||||
.endif
|
||||
.if ${KERN_OPTS:MSCTP_SUPPORT} || ${KERN_OPTS:MSCTP}
|
||||
_sctp= sctp
|
||||
.endif
|
||||
.endif
|
||||
|
||||
.if (${MK_INET_SUPPORT} != "no" && ${MK_INET6_SUPPORT} != "no") || \
|
||||
|
30
sys/modules/sctp/Makefile
Normal file
30
sys/modules/sctp/Makefile
Normal file
@ -0,0 +1,30 @@
|
||||
# $FreeBSD$
|
||||
|
||||
.PATH: ${SRCTOP}/sys/netinet
|
||||
.PATH: ${SRCTOP}/sys/netinet6
|
||||
|
||||
KMOD= sctp
|
||||
SRCS= sctp_asconf.c \
|
||||
sctp_auth.c \
|
||||
sctp_bsd_addr.c \
|
||||
sctp_cc_functions.c \
|
||||
sctp_crc32.c \
|
||||
sctp_indata.c \
|
||||
sctp_input.c \
|
||||
sctp_kdtrace.c \
|
||||
sctp_module.c \
|
||||
sctp_output.c \
|
||||
sctp_pcb.c \
|
||||
sctp_peeloff.c \
|
||||
sctp_ss_functions.c \
|
||||
sctp_syscalls.c \
|
||||
sctp_sysctl.c \
|
||||
sctp_timer.c \
|
||||
sctp_usrreq.c \
|
||||
sctp6_usrreq.c \
|
||||
sctputil.c
|
||||
|
||||
SRCS+= device_if.h bus_if.h vnode_if.h
|
||||
SRCS+= opt_capsicum.h opt_ktrace.h opt_inet.h opt_inet6.h opt_sctp.h
|
||||
|
||||
.include <bsd.kmod.mk>
|
197
sys/netinet/sctp_module.c
Normal file
197
sys/netinet/sctp_module.c
Normal file
@ -0,0 +1,197 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
||||
*
|
||||
* Copyright (c) 2019-2020 The FreeBSD Foundation
|
||||
*
|
||||
* This software was developed by Mark Johnston 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "opt_inet.h"
|
||||
#include "opt_inet6.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/protosw.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_var.h>
|
||||
#include <netinet/sctp.h>
|
||||
#include <netinet/sctp_pcb.h>
|
||||
#include <netinet/sctp_var.h>
|
||||
#include <netinet/sctp_os_bsd.h>
|
||||
|
||||
#include <netinet6/ip6_var.h>
|
||||
#include <netinet6/sctp6_var.h>
|
||||
|
||||
#ifdef INET
|
||||
extern struct domain inetdomain;
|
||||
|
||||
struct protosw sctp_stream_protosw = {
|
||||
.pr_type = SOCK_STREAM,
|
||||
.pr_domain = &inetdomain,
|
||||
.pr_protocol = IPPROTO_SCTP,
|
||||
.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LASTHDR,
|
||||
.pr_input = sctp_input,
|
||||
.pr_ctlinput = sctp_ctlinput,
|
||||
.pr_ctloutput = sctp_ctloutput,
|
||||
.pr_drain = sctp_drain,
|
||||
.pr_usrreqs = &sctp_usrreqs,
|
||||
};
|
||||
|
||||
struct protosw sctp_seqpacket_protosw = {
|
||||
.pr_type = SOCK_SEQPACKET,
|
||||
.pr_domain = &inetdomain,
|
||||
.pr_protocol = IPPROTO_SCTP,
|
||||
.pr_flags = PR_WANTRCVD|PR_LASTHDR,
|
||||
.pr_input = sctp_input,
|
||||
.pr_ctlinput = sctp_ctlinput,
|
||||
.pr_ctloutput = sctp_ctloutput,
|
||||
.pr_drain = sctp_drain,
|
||||
.pr_usrreqs = &sctp_usrreqs,
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef INET6
|
||||
extern struct domain inet6domain;
|
||||
|
||||
struct protosw sctp6_stream_protosw = {
|
||||
.pr_type = SOCK_STREAM,
|
||||
.pr_domain = &inet6domain,
|
||||
.pr_protocol = IPPROTO_SCTP,
|
||||
.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_LASTHDR,
|
||||
.pr_input = sctp6_input,
|
||||
.pr_ctlinput = sctp6_ctlinput,
|
||||
.pr_ctloutput = sctp_ctloutput,
|
||||
.pr_init = sctp_init,
|
||||
.pr_drain = sctp_drain,
|
||||
.pr_usrreqs = &sctp6_usrreqs,
|
||||
};
|
||||
|
||||
struct protosw sctp6_seqpacket_protosw = {
|
||||
.pr_type = SOCK_SEQPACKET,
|
||||
.pr_domain = &inet6domain,
|
||||
.pr_protocol = IPPROTO_SCTP,
|
||||
.pr_flags = PR_WANTRCVD|PR_LASTHDR,
|
||||
.pr_input = sctp6_input,
|
||||
.pr_ctlinput = sctp6_ctlinput,
|
||||
.pr_ctloutput = sctp_ctloutput,
|
||||
#ifndef INET /* Do not call initialization and drain routines twice. */
|
||||
.pr_init = sctp_init,
|
||||
.pr_drain = sctp_drain,
|
||||
#endif
|
||||
.pr_usrreqs = &sctp6_usrreqs,
|
||||
};
|
||||
#endif
|
||||
|
||||
static int
|
||||
sctp_module_load(void)
|
||||
{
|
||||
int error;
|
||||
|
||||
#ifdef INET
|
||||
error = pf_proto_register(PF_INET, &sctp_stream_protosw);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
error = pf_proto_register(PF_INET, &sctp_seqpacket_protosw);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
error = ipproto_register(IPPROTO_SCTP);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
#endif
|
||||
#ifdef INET6
|
||||
error = pf_proto_register(PF_INET6, &sctp6_stream_protosw);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
error = pf_proto_register(PF_INET6, &sctp6_seqpacket_protosw);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
error = ip6proto_register(IPPROTO_SCTP);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
#endif
|
||||
error = sctp_syscalls_init();
|
||||
if (error != 0)
|
||||
return (error);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int __unused
|
||||
sctp_module_unload(void)
|
||||
{
|
||||
|
||||
(void)sctp_syscalls_uninit();
|
||||
|
||||
#ifdef INET
|
||||
(void)ipproto_unregister(IPPROTO_SCTP);
|
||||
(void)pf_proto_unregister(PF_INET, IPPROTO_SCTP, SOCK_STREAM);
|
||||
(void)pf_proto_unregister(PF_INET, IPPROTO_SCTP, SOCK_SEQPACKET);
|
||||
#endif
|
||||
#ifdef INET6
|
||||
(void)ip6proto_unregister(IPPROTO_SCTP);
|
||||
(void)pf_proto_unregister(PF_INET6, IPPROTO_SCTP, SOCK_STREAM);
|
||||
(void)pf_proto_unregister(PF_INET6, IPPROTO_SCTP, SOCK_SEQPACKET);
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
sctp_modload(struct module *module, int cmd, void *arg)
|
||||
{
|
||||
int error;
|
||||
|
||||
switch (cmd) {
|
||||
case MOD_LOAD:
|
||||
error = sctp_module_load();
|
||||
break;
|
||||
case MOD_UNLOAD:
|
||||
/*
|
||||
* Unloading SCTP is currently unsupported. Currently, SCTP
|
||||
* iterator threads are not stopped during unload.
|
||||
*/
|
||||
error = EOPNOTSUPP;
|
||||
break;
|
||||
default:
|
||||
error = 0;
|
||||
break;
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
|
||||
static moduledata_t sctp_mod = {
|
||||
"sctp",
|
||||
&sctp_modload,
|
||||
NULL,
|
||||
};
|
||||
|
||||
DECLARE_MODULE(sctp, sctp_mod, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY);
|
||||
MODULE_VERSION(sctp, 1);
|
@ -45,9 +45,12 @@ __FBSDID("$FreeBSD$");
|
||||
#include "opt_sctp.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/domain.h>
|
||||
#include <sys/eventhandler.h>
|
||||
#include <sys/ktr.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/mbuf.h>
|
||||
@ -85,7 +88,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <netinet/icmp_var.h>
|
||||
|
||||
#ifdef INET6
|
||||
#include <sys/domain.h>
|
||||
#include <netinet/ip6.h>
|
||||
#include <netinet6/in6_fib.h>
|
||||
#include <netinet6/ip6_var.h>
|
||||
@ -477,4 +479,7 @@ sctp_get_mbuf_for_msg(unsigned int space_needed,
|
||||
|
||||
#define SCTP_IS_LISTENING(inp) ((inp->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING) != 0)
|
||||
|
||||
int sctp_syscalls_init(void);
|
||||
int sctp_syscalls_uninit(void);
|
||||
|
||||
#endif
|
||||
|
@ -69,6 +69,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/ktrace.h>
|
||||
#endif
|
||||
#ifdef COMPAT_FREEBSD32
|
||||
#include <compat/freebsd32/freebsd32.h>
|
||||
#include <compat/freebsd32/freebsd32_syscall.h>
|
||||
#include <compat/freebsd32/freebsd32_util.h>
|
||||
#endif
|
||||
|
||||
@ -78,6 +80,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <security/mac/mac_framework.h>
|
||||
|
||||
#include <netinet/sctp.h>
|
||||
#include <netinet/sctp_os_bsd.h>
|
||||
#include <netinet/sctp_peeloff.h>
|
||||
|
||||
static struct syscall_helper_data sctp_syscalls[] = {
|
||||
@ -88,28 +91,52 @@ static struct syscall_helper_data sctp_syscalls[] = {
|
||||
SYSCALL_INIT_LAST
|
||||
};
|
||||
|
||||
static void
|
||||
sctp_syscalls_init(void *unused __unused)
|
||||
{
|
||||
int error __unused;
|
||||
|
||||
error = syscall_helper_register(sctp_syscalls, SY_THR_STATIC);
|
||||
KASSERT((error == 0),
|
||||
("%s: syscall_helper_register failed for sctp syscalls", __func__));
|
||||
#ifdef COMPAT_FREEBSD32
|
||||
error = syscall32_helper_register(sctp_syscalls, SY_THR_STATIC);
|
||||
KASSERT((error == 0),
|
||||
("%s: syscall32_helper_register failed for sctp syscalls",
|
||||
__func__));
|
||||
static struct syscall_helper_data sctp32_syscalls[] = {
|
||||
SYSCALL32_INIT_HELPER_COMPAT(sctp_peeloff),
|
||||
SYSCALL32_INIT_HELPER_COMPAT(sctp_generic_sendmsg),
|
||||
SYSCALL32_INIT_HELPER_COMPAT(sctp_generic_sendmsg_iov),
|
||||
SYSCALL32_INIT_HELPER_COMPAT(sctp_generic_recvmsg),
|
||||
SYSCALL_INIT_LAST
|
||||
};
|
||||
#endif
|
||||
|
||||
int
|
||||
sctp_syscalls_init(void)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = syscall_helper_register(sctp_syscalls, SY_THR_STATIC_KLD);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
#ifdef COMPAT_FREEBSD32
|
||||
error = syscall32_helper_register(sctp32_syscalls, SY_THR_STATIC_KLD);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
sctp_syscalls_uninit(void)
|
||||
{
|
||||
int error;
|
||||
|
||||
#ifdef COMPAT_FREEBSD32
|
||||
error = syscall32_helper_unregister(sctp32_syscalls);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
#endif
|
||||
error = syscall_helper_unregister(sctp_syscalls);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
return (0);
|
||||
}
|
||||
SYSINIT(sctp_syscalls, SI_SUB_SYSCALLS, SI_ORDER_ANY, sctp_syscalls_init, NULL);
|
||||
|
||||
/*
|
||||
* SCTP syscalls.
|
||||
* Functionality only compiled in if SCTP is defined in the kernel Makefile,
|
||||
* otherwise all return EOPNOTSUPP.
|
||||
* XXX: We should make this loadable one day.
|
||||
*/
|
||||
int
|
||||
sys_sctp_peeloff(td, uap)
|
||||
@ -119,7 +146,7 @@ sys_sctp_peeloff(td, uap)
|
||||
caddr_t name;
|
||||
} */ *uap;
|
||||
{
|
||||
#if (defined(INET) || defined(INET6)) && defined(SCTP)
|
||||
#if defined(INET) || defined(INET6)
|
||||
struct file *headfp, *nfp = NULL;
|
||||
struct socket *head, *so;
|
||||
cap_rights_t rights;
|
||||
@ -181,9 +208,7 @@ sys_sctp_peeloff(td, uap)
|
||||
fdrop(headfp, td);
|
||||
done2:
|
||||
return (error);
|
||||
#else /* SCTP */
|
||||
return (EOPNOTSUPP);
|
||||
#endif /* SCTP */
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
@ -199,7 +224,7 @@ sys_sctp_generic_sendmsg (td, uap)
|
||||
int flags
|
||||
} */ *uap;
|
||||
{
|
||||
#if (defined(INET) || defined(INET6)) && defined(SCTP)
|
||||
#if defined(INET) || defined(INET6)
|
||||
struct sctp_sndrcvinfo sinfo, *u_sinfo = NULL;
|
||||
struct socket *so;
|
||||
struct file *fp = NULL;
|
||||
@ -294,9 +319,7 @@ sys_sctp_generic_sendmsg (td, uap)
|
||||
sctp_bad2:
|
||||
free(to, M_SONAME);
|
||||
return (error);
|
||||
#else /* SCTP */
|
||||
return (EOPNOTSUPP);
|
||||
#endif /* SCTP */
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
@ -312,7 +335,7 @@ sys_sctp_generic_sendmsg_iov(td, uap)
|
||||
int flags
|
||||
} */ *uap;
|
||||
{
|
||||
#if (defined(INET) || defined(INET6)) && defined(SCTP)
|
||||
#if defined(INET) || defined(INET6)
|
||||
struct sctp_sndrcvinfo sinfo, *u_sinfo = NULL;
|
||||
struct socket *so;
|
||||
struct file *fp = NULL;
|
||||
@ -424,9 +447,7 @@ sys_sctp_generic_sendmsg_iov(td, uap)
|
||||
sctp_bad2:
|
||||
free(to, M_SONAME);
|
||||
return (error);
|
||||
#else /* SCTP */
|
||||
return (EOPNOTSUPP);
|
||||
#endif /* SCTP */
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
@ -442,7 +463,7 @@ sys_sctp_generic_recvmsg(td, uap)
|
||||
int *msg_flags
|
||||
} */ *uap;
|
||||
{
|
||||
#if (defined(INET) || defined(INET6)) && defined(SCTP)
|
||||
#if defined(INET) || defined(INET6)
|
||||
uint8_t sockbufstore[256];
|
||||
struct uio auio;
|
||||
struct iovec *iov, *tiov;
|
||||
@ -572,7 +593,5 @@ sys_sctp_generic_recvmsg(td, uap)
|
||||
fdrop(fp, td);
|
||||
|
||||
return (error);
|
||||
#else /* SCTP */
|
||||
return (EOPNOTSUPP);
|
||||
#endif /* SCTP */
|
||||
#endif
|
||||
}
|
||||
|
@ -97,9 +97,9 @@ sctp_init(void)
|
||||
static void
|
||||
sctp_finish(void *unused __unused)
|
||||
{
|
||||
EVENTHANDLER_DEREGISTER(rt_addrmsg, SCTP_BASE_VAR(eh_tag));
|
||||
sctp_pcb_finish();
|
||||
}
|
||||
|
||||
VNET_SYSUNINIT(sctp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, sctp_finish, NULL);
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user