Skip to content

Commit

Permalink
Add the SCTP_SUPPORT kernel option.
Browse files Browse the repository at this point in the history
This is in preparation for enabling a loadable SCTP stack.  Analogous to
IPSEC/IPSEC_SUPPORT, the SCTP_SUPPORT kernel option must be configured
in order to support a loadable SCTP implementation.

Discussed with:	tuexen
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
  • Loading branch information
markjdb committed Jun 18, 2020
1 parent ead7e10 commit 95033af
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 34 deletions.
5 changes: 4 additions & 1 deletion share/man/man4/sctp.4
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
.\"
.\" $FreeBSD$
.\"
.Dd January 4, 2020
.Dd June 18, 2020
.Dt SCTP 4
.Os
.Sh NAME
.Nm sctp
.Nd Internet Stream Control Transmission Protocol
.Sh SYNOPSIS
.Cd "options SCTP"
.Cd "options SCTP_SUPPORT"
.Pp
.In sys/types.h
.In sys/socket.h
.In netinet/sctp.h
Expand Down
7 changes: 6 additions & 1 deletion sys/conf/NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,12 @@ options LIBALIAS
# the V6 and V4.. since an association can span
# both a V6 and V4 address at the SAME time :-)
#
# The SCTP_SUPPORT option does not enable SCTP, but provides the necessary
# support for loading SCTP as a loadable kernel module.
#
options SCTP
options SCTP_SUPPORT

# There are bunches of options:
# this one turns on all sorts of
# nastily printing that you can
Expand All @@ -710,6 +715,7 @@ options SCTP
# bits and prints.. which makes the code run
# faster.. if you are not debugging don't use.
options SCTP_DEBUG

#
# All that options after that turn on specific types of
# logging. You can monitor CWND growth, flight size
Expand All @@ -733,7 +739,6 @@ options SCTP_PACKET_LOGGING
options SCTP_LTRACE_CHUNKS
options SCTP_LTRACE_ERRORS


# altq(9). Enable the base part of the hooks with the ALTQ option.
# Individual disciplines must be built into the base system and can not be
# loaded as modules at this point. ALTQ requires a stable TSC so if yours is
Expand Down
1 change: 1 addition & 0 deletions sys/conf/options
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ XBONEHACK
# SCTP
#
SCTP opt_sctp.h
SCTP_SUPPORT opt_sctp.h
SCTP_DEBUG opt_sctp.h # Enable debug printfs
SCTP_LOCK_LOGGING opt_sctp.h # Log to KTR lock activity
SCTP_MBUF_LOGGING opt_sctp.h # Log to KTR general mbuf aloc/free
Expand Down
2 changes: 1 addition & 1 deletion sys/kern/uipc_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ sonewconn(struct socket *head, int connstatus)
return (so);
}

#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
/*
* Socket part of sctp_peeloff(). Detach a new socket from an
* association. The new socket is returned with a reference.
Expand Down
4 changes: 2 additions & 2 deletions sys/netinet/in_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static struct pr_usrreqs nousrreqs;
#include <netinet/sctp_pcb.h>
#include <netinet/sctp.h>
#include <netinet/sctp_var.h>
#endif /* SCTP */
#endif

FEATURE(inet, "Internet Protocol version 4");

Expand Down Expand Up @@ -324,7 +324,7 @@ SYSCTL_NODE(_net_inet, IPPROTO_UDP, udp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"UDP");
SYSCTL_NODE(_net_inet, IPPROTO_TCP, tcp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"TCP");
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
SYSCTL_NODE(_net_inet, IPPROTO_SCTP, sctp, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"SCTP");
#endif
Expand Down
4 changes: 2 additions & 2 deletions sys/netinet/ip_divert.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ __FBSDID("$FreeBSD$");
#include <netinet/ip6.h>
#include <netinet6/ip6_var.h>
#endif
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
#include <netinet/sctp_crc32.h>
#endif

Expand Down Expand Up @@ -215,7 +215,7 @@ divert_packet(struct mbuf *m, bool incoming)
in_delayed_cksum(m);
m->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA;
}
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
if (m->m_pkthdr.csum_flags & CSUM_SCTP) {
sctp_delayed_cksum(m, (uint32_t)(ip->ip_hl << 2));
m->m_pkthdr.csum_flags &= ~CSUM_SCTP;
Expand Down
10 changes: 5 additions & 5 deletions sys/netinet/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ __FBSDID("$FreeBSD$");
#include <netinet/udp.h>
#include <netinet/udp_var.h>

#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
#include <netinet/sctp.h>
#include <netinet/sctp_crc32.h>
#endif
Expand Down Expand Up @@ -154,7 +154,7 @@ ip_output_pfil(struct mbuf **mp, struct ifnet *ifp, int flags,
}
m->m_pkthdr.csum_flags |=
CSUM_IP_CHECKED | CSUM_IP_VALID;
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
if (m->m_pkthdr.csum_flags & CSUM_SCTP)
m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID;
#endif
Expand Down Expand Up @@ -185,7 +185,7 @@ ip_output_pfil(struct mbuf **mp, struct ifnet *ifp, int flags,
CSUM_DATA_VALID | CSUM_PSEUDO_HDR;
m->m_pkthdr.csum_data = 0xffff;
}
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
if (m->m_pkthdr.csum_flags & CSUM_SCTP)
m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID;
#endif
Expand Down Expand Up @@ -753,7 +753,7 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags,
goto bad;
}
}
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
if (m->m_pkthdr.csum_flags & CSUM_SCTP & ~ifp->if_hwassist) {
m = mb_unmapped_to_ext(m);
if (m == NULL) {
Expand Down Expand Up @@ -905,7 +905,7 @@ ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu,
in_delayed_cksum(m0);
m0->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA;
}
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
if (m0->m_pkthdr.csum_flags & CSUM_SCTP) {
m0 = mb_unmapped_to_ext(m0);
if (m0 == NULL) {
Expand Down
17 changes: 9 additions & 8 deletions sys/netinet/sctp_crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,17 @@ __FBSDID("$FreeBSD$");

#include "opt_sctp.h"

#include <sys/gsb_crc32.h>
#ifdef SCTP
#include <netinet/sctp_os.h>
#include <netinet/sctp.h>
#include <netinet/sctp_crc32.h>
#include <netinet/sctp_pcb.h>
#else
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/gsb_crc32.h>
#include <sys/mbuf.h>

#include <netinet/sctp.h>
#include <netinet/sctp_crc32.h>
#ifdef SCTP
#include <netinet/sctp_os.h>
#include <netinet/sctp_crc32.h>
#include <netinet/sctp_pcb.h>
#endif

static uint32_t
Expand Down Expand Up @@ -117,7 +116,7 @@ sctp_calculate_cksum(struct mbuf *m, uint32_t offset)
return (base);
}

#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
/*
* Compute and insert the SCTP checksum in network byte order for a given
* mbuf chain m which contains an SCTP packet starting at offset.
Expand All @@ -128,8 +127,10 @@ sctp_delayed_cksum(struct mbuf *m, uint32_t offset)
uint32_t checksum;

checksum = sctp_calculate_cksum(m, offset);
#ifdef SCTP
SCTP_STAT_DECR(sctps_sendhwcrc);
SCTP_STAT_INCR(sctps_sendswcrc);
#endif
offset += offsetof(struct sctphdr, checksum);

if (offset + sizeof(uint32_t) > (uint32_t)(m->m_pkthdr.len)) {
Expand Down
2 changes: 1 addition & 1 deletion sys/netinet/sctp_crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ __FBSDID("$FreeBSD$");

#if defined(_KERNEL)
uint32_t sctp_calculate_cksum(struct mbuf *, uint32_t);
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
void sctp_delayed_cksum(struct mbuf *, uint32_t offset);
#endif
#endif /* _KERNEL */
Expand Down
2 changes: 1 addition & 1 deletion sys/netinet6/in6_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ SYSCTL_NODE(_net_inet6, IPPROTO_UDP, udp6, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"UDP6");
SYSCTL_NODE(_net_inet6, IPPROTO_TCP, tcp6, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"TCP6");
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
SYSCTL_NODE(_net_inet6, IPPROTO_SCTP, sctp6, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
"SCTP6");
#endif
Expand Down
2 changes: 1 addition & 1 deletion sys/netinet6/ip6_forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ ip6_forward(struct mbuf *m, int srcrt)
CSUM_DATA_VALID_IPV6 | CSUM_PSEUDO_HDR;
m->m_pkthdr.csum_data = 0xffff;
}
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
if (m->m_pkthdr.csum_flags & CSUM_SCTP_IPV6)
m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID;
#endif
Expand Down
10 changes: 5 additions & 5 deletions sys/netinet6/ip6_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ __FBSDID("$FreeBSD$");
#include <netinet6/in6_rss.h>

#include <netipsec/ipsec_support.h>
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
#include <netinet/sctp.h>
#include <netinet/sctp_crc32.h>
#endif
Expand Down Expand Up @@ -221,7 +221,7 @@ ip6_output_delayed_csum(struct mbuf *m, struct ifnet *ifp, int csum_flags,
__func__, __LINE__, plen, optlen, m, ifp, csum_flags, frag));

if ((csum_flags & CSUM_DELAY_DATA_IPV6) ||
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
(csum_flags & CSUM_SCTP_IPV6) ||
#endif
(!frag && (ifp->if_capenable & IFCAP_NOMAP) == 0)) {
Expand All @@ -238,7 +238,7 @@ ip6_output_delayed_csum(struct mbuf *m, struct ifnet *ifp, int csum_flags,
sizeof(struct ip6_hdr) + optlen);
m->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA_IPV6;
}
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
if (csum_flags & CSUM_SCTP_IPV6) {
sctp_delayed_cksum(m, sizeof(struct ip6_hdr) + optlen);
m->m_pkthdr.csum_flags &= ~CSUM_SCTP_IPV6;
Expand Down Expand Up @@ -1041,7 +1041,7 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt,
CSUM_DATA_VALID_IPV6 | CSUM_PSEUDO_HDR;
m->m_pkthdr.csum_data = 0xffff;
}
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
if (m->m_pkthdr.csum_flags & CSUM_SCTP_IPV6)
m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID;
#endif
Expand Down Expand Up @@ -1073,7 +1073,7 @@ ip6_output(struct mbuf *m0, struct ip6_pktopts *opt,
CSUM_DATA_VALID_IPV6 | CSUM_PSEUDO_HDR;
m->m_pkthdr.csum_data = 0xffff;
}
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
if (m->m_pkthdr.csum_flags & CSUM_SCTP_IPV6)
m->m_pkthdr.csum_flags |= CSUM_SCTP_VALID;
#endif
Expand Down
6 changes: 3 additions & 3 deletions sys/netipsec/ipsec_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#ifdef INET6
#include <netinet/icmp6.h>
#endif
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
#include <netinet/sctp_crc32.h>
#endif

Expand Down Expand Up @@ -326,7 +326,7 @@ ipsec4_common_output(struct mbuf *m, struct inpcb *inp, int forwarding)
in_delayed_cksum(m);
m->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA;
}
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
if (m->m_pkthdr.csum_flags & CSUM_SCTP) {
struct ip *ip = mtod(m, struct ip *);

Expand Down Expand Up @@ -621,7 +621,7 @@ ipsec6_common_output(struct mbuf *m, struct inpcb *inp, int forwarding)
sizeof(struct ip6_hdr), sizeof(struct ip6_hdr));
m->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA_IPV6;
}
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
if (m->m_pkthdr.csum_flags & CSUM_SCTP_IPV6) {
sctp_delayed_cksum(m, sizeof(struct ip6_hdr));
m->m_pkthdr.csum_flags &= ~CSUM_SCTP_IPV6;
Expand Down
6 changes: 3 additions & 3 deletions sys/netpfil/pf/pf.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include "opt_bpf.h"
#include "opt_inet.h"
#include "opt_inet6.h"
#include "opt_bpf.h"
#include "opt_pf.h"
#include "opt_sctp.h"

Expand Down Expand Up @@ -103,7 +103,7 @@ __FBSDID("$FreeBSD$");
#include <netinet6/scope6_var.h>
#endif /* INET6 */

#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
#include <netinet/sctp_crc32.h>
#endif

Expand Down Expand Up @@ -5474,7 +5474,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp,
in_delayed_cksum(m0);
m0->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA;
}
#ifdef SCTP
#if defined(SCTP) || defined(SCTP_SUPPORT)
if (m0->m_pkthdr.csum_flags & CSUM_SCTP & ~ifp->if_hwassist) {
sctp_delayed_cksum(m0, (uint32_t)(ip->ip_hl << 2));
m0->m_pkthdr.csum_flags &= ~CSUM_SCTP;
Expand Down

0 comments on commit 95033af

Please sign in to comment.