aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2023-07-07 08:04:51 +0000
committerKristof Provost <kp@FreeBSD.org>2023-08-11 12:13:09 +0000
commit836dc3507e0da06a60762eca8f98c80530eb7173 (patch)
treeff6883e4e20114645842b02d81d318db35cea9b6
parent97cbac33c6d223617b0084a64bd55b0e3b8ec549 (diff)
downloadsrc-836dc3507e0da06a60762eca8f98c80530eb7173.tar.gz
src-836dc3507e0da06a60762eca8f98c80530eb7173.zip
pf: use sctp_calculate_cksum()
This function is always available, even if the SCTP or SCTP_SUPPORT options are not set. That lets us remove an ifdef, and also means we improve pf's SCTP handling when the options are not set. MFC after: 3 weeks Sponsored by: Orange Business Services Differential Revision: https://reviews.freebsd.org/D40911 (cherry picked from commit 61e22e9b2905f405170c249a2239f324229b60d1)
-rw-r--r--sys/netpfil/pf/pf.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index c9c0995cc4e7..57c9bb3bf3b1 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -104,9 +104,8 @@ __FBSDID("$FreeBSD$");
#include <netinet6/scope6_var.h>
#endif /* INET6 */
-#if defined(SCTP) || defined(SCTP_SUPPORT)
+#include <netinet/sctp_header.h>
#include <netinet/sctp_crc32.h>
-#endif
#include <machine/in_cksum.h>
#include <security/mac/mac_framework.h>
@@ -412,6 +411,21 @@ VNET_DEFINE(struct intr_event *, pf_swi_ie);
VNET_DEFINE(uint32_t, pf_hashseed);
#define V_pf_hashseed VNET(pf_hashseed)
+static void
+pf_sctp_checksum(struct mbuf *m, int off)
+{
+ uint32_t sum = 0;
+
+ /* Zero out the checksum, to enable recalculation. */
+ m_copyback(m, off + offsetof(struct sctphdr, checksum),
+ sizeof(sum), (caddr_t)&sum);
+
+ sum = sctp_calculate_cksum(m, off);
+
+ m_copyback(m, off + offsetof(struct sctphdr, checksum),
+ sizeof(sum), (caddr_t)&sum);
+}
+
int
pf_addr_cmp(struct pf_addr *a, struct pf_addr *b, sa_family_t af)
{
@@ -5977,12 +5991,10 @@ pf_route(struct mbuf **m, struct pf_krule *r, int dir, struct ifnet *oifp,
in_delayed_cksum(m0);
m0->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA;
}
-#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));
+ pf_sctp_checksum(m0, (uint32_t)(ip->ip_hl << 2));
m0->m_pkthdr.csum_flags &= ~CSUM_SCTP;
}
-#endif
/*
* If small enough for interface, or the interface will take