1052c5ec4SMark Johnston /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3052c5ec4SMark Johnston *
4052c5ec4SMark Johnston * Copyright (c) 2019-2020 The FreeBSD Foundation
5052c5ec4SMark Johnston *
6052c5ec4SMark Johnston * This software was developed by Mark Johnston under sponsorship from
7052c5ec4SMark Johnston * the FreeBSD Foundation.
8052c5ec4SMark Johnston *
9052c5ec4SMark Johnston * Redistribution and use in source and binary forms, with or without
10052c5ec4SMark Johnston * modification, are permitted provided that the following conditions are
11052c5ec4SMark Johnston * met:
12052c5ec4SMark Johnston * 1. Redistributions of source code must retain the above copyright
13052c5ec4SMark Johnston * notice, this list of conditions and the following disclaimer.
14052c5ec4SMark Johnston * 2. Redistributions in binary form must reproduce the above copyright
15052c5ec4SMark Johnston * notice, this list of conditions and the following disclaimer in
16052c5ec4SMark Johnston * the documentation and/or other materials provided with the distribution.
17052c5ec4SMark Johnston *
18052c5ec4SMark Johnston * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19052c5ec4SMark Johnston * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20052c5ec4SMark Johnston * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21052c5ec4SMark Johnston * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22052c5ec4SMark Johnston * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23052c5ec4SMark Johnston * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24052c5ec4SMark Johnston * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25052c5ec4SMark Johnston * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26052c5ec4SMark Johnston * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27052c5ec4SMark Johnston * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28052c5ec4SMark Johnston * SUCH DAMAGE.
29052c5ec4SMark Johnston */
30052c5ec4SMark Johnston
31052c5ec4SMark Johnston #include <sys/cdefs.h>
32052c5ec4SMark Johnston #include "opt_inet.h"
33052c5ec4SMark Johnston #include "opt_inet6.h"
34052c5ec4SMark Johnston
35052c5ec4SMark Johnston #include <sys/param.h>
36052c5ec4SMark Johnston #include <sys/systm.h>
37052c5ec4SMark Johnston #include <sys/kernel.h>
38052c5ec4SMark Johnston #include <sys/module.h>
39052c5ec4SMark Johnston #include <sys/protosw.h>
40052c5ec4SMark Johnston #include <sys/socket.h>
41052c5ec4SMark Johnston
42052c5ec4SMark Johnston #include <netinet/in.h>
43052c5ec4SMark Johnston #include <netinet/ip.h>
44052c5ec4SMark Johnston #include <netinet/ip_var.h>
45052c5ec4SMark Johnston #include <netinet/sctp.h>
46052c5ec4SMark Johnston #include <netinet/sctp_pcb.h>
47052c5ec4SMark Johnston #include <netinet/sctp_var.h>
48052c5ec4SMark Johnston #include <netinet/sctp_os_bsd.h>
49052c5ec4SMark Johnston
50052c5ec4SMark Johnston #include <netinet6/ip6_var.h>
51052c5ec4SMark Johnston #include <netinet6/sctp6_var.h>
52052c5ec4SMark Johnston
53052c5ec4SMark Johnston static int
sctp_module_load(void)54052c5ec4SMark Johnston sctp_module_load(void)
55052c5ec4SMark Johnston {
56052c5ec4SMark Johnston int error;
57052c5ec4SMark Johnston
58052c5ec4SMark Johnston #ifdef INET
59e7d02be1SGleb Smirnoff error = protosw_register(&inetdomain, &sctp_stream_protosw);
60052c5ec4SMark Johnston if (error != 0)
61052c5ec4SMark Johnston return (error);
62e7d02be1SGleb Smirnoff error = protosw_register(&inetdomain, &sctp_seqpacket_protosw);
63052c5ec4SMark Johnston if (error != 0)
64052c5ec4SMark Johnston return (error);
6578b1fc05SGleb Smirnoff error = ipproto_register(IPPROTO_SCTP, sctp_input, sctp_ctlinput);
66052c5ec4SMark Johnston if (error != 0)
67052c5ec4SMark Johnston return (error);
68052c5ec4SMark Johnston #endif
69052c5ec4SMark Johnston #ifdef INET6
70e7d02be1SGleb Smirnoff error = protosw_register(&inet6domain, &sctp6_stream_protosw);
71052c5ec4SMark Johnston if (error != 0)
72052c5ec4SMark Johnston return (error);
73e7d02be1SGleb Smirnoff error = protosw_register(&inet6domain, &sctp6_seqpacket_protosw);
74052c5ec4SMark Johnston if (error != 0)
75052c5ec4SMark Johnston return (error);
7678b1fc05SGleb Smirnoff error = ip6proto_register(IPPROTO_SCTP, sctp6_input, sctp6_ctlinput);
77052c5ec4SMark Johnston if (error != 0)
78052c5ec4SMark Johnston return (error);
79052c5ec4SMark Johnston #endif
80052c5ec4SMark Johnston error = sctp_syscalls_init();
81052c5ec4SMark Johnston if (error != 0)
82052c5ec4SMark Johnston return (error);
83052c5ec4SMark Johnston return (0);
84052c5ec4SMark Johnston }
85052c5ec4SMark Johnston
86052c5ec4SMark Johnston static int __unused
sctp_module_unload(void)87052c5ec4SMark Johnston sctp_module_unload(void)
88052c5ec4SMark Johnston {
89052c5ec4SMark Johnston
90052c5ec4SMark Johnston (void)sctp_syscalls_uninit();
91052c5ec4SMark Johnston
92052c5ec4SMark Johnston #ifdef INET
93052c5ec4SMark Johnston (void)ipproto_unregister(IPPROTO_SCTP);
94e7d02be1SGleb Smirnoff (void)protosw_unregister(&sctp_seqpacket_protosw);
95e7d02be1SGleb Smirnoff (void)protosw_unregister(&sctp_stream_protosw);
96052c5ec4SMark Johnston #endif
97052c5ec4SMark Johnston #ifdef INET6
98052c5ec4SMark Johnston (void)ip6proto_unregister(IPPROTO_SCTP);
99e7d02be1SGleb Smirnoff (void)protosw_unregister(&sctp6_seqpacket_protosw);
100e7d02be1SGleb Smirnoff (void)protosw_unregister(&sctp6_stream_protosw);
101052c5ec4SMark Johnston #endif
102052c5ec4SMark Johnston return (0);
103052c5ec4SMark Johnston }
104052c5ec4SMark Johnston
105052c5ec4SMark Johnston static int
sctp_modload(struct module * module,int cmd,void * arg)106052c5ec4SMark Johnston sctp_modload(struct module *module, int cmd, void *arg)
107052c5ec4SMark Johnston {
108052c5ec4SMark Johnston int error;
109052c5ec4SMark Johnston
110052c5ec4SMark Johnston switch (cmd) {
111052c5ec4SMark Johnston case MOD_LOAD:
112052c5ec4SMark Johnston error = sctp_module_load();
113052c5ec4SMark Johnston break;
114052c5ec4SMark Johnston case MOD_UNLOAD:
115052c5ec4SMark Johnston /*
116052c5ec4SMark Johnston * Unloading SCTP is currently unsupported. Currently, SCTP
117052c5ec4SMark Johnston * iterator threads are not stopped during unload.
118052c5ec4SMark Johnston */
119052c5ec4SMark Johnston error = EOPNOTSUPP;
120052c5ec4SMark Johnston break;
121052c5ec4SMark Johnston default:
122052c5ec4SMark Johnston error = 0;
123052c5ec4SMark Johnston break;
124052c5ec4SMark Johnston }
125052c5ec4SMark Johnston return (error);
126052c5ec4SMark Johnston }
127052c5ec4SMark Johnston
128052c5ec4SMark Johnston static moduledata_t sctp_mod = {
129052c5ec4SMark Johnston "sctp",
130052c5ec4SMark Johnston &sctp_modload,
131052c5ec4SMark Johnston NULL,
132052c5ec4SMark Johnston };
133052c5ec4SMark Johnston
134052c5ec4SMark Johnston DECLARE_MODULE(sctp, sctp_mod, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY);
135052c5ec4SMark Johnston MODULE_VERSION(sctp, 1);
136