git: 61e22e9b2905 - main - pf: use sctp_calculate_cksum()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 21 Jul 2023 10:32:35 UTC
The branch main has been updated by kp:
URL: https://cgit.FreeBSD.org/src/commit/?id=61e22e9b2905f405170c249a2239f324229b60d1
commit 61e22e9b2905f405170c249a2239f324229b60d1
Author: Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2023-07-07 08:04:51 +0000
Commit: Kristof Provost <kp@FreeBSD.org>
CommitDate: 2023-07-21 10:32:17 +0000
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
---
sys/netpfil/pf/pf.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index 2a1813d6aadd..490a4130f025 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -112,9 +112,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>
@@ -438,6 +437,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)
{
@@ -6569,12 +6583,10 @@ pf_route(struct mbuf **m, struct pf_krule *r, 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