From nobody Wed Feb 19 10:41:38 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YyXxv0rbGz5p9gZ; Wed, 19 Feb 2025 10:41:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YyXxt3lSZz3lZH; Wed, 19 Feb 2025 10:41:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1739961698; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6XVWIQ6liotqQ+uKEW6R2W27ndPwzQgcW166DxtfbH8=; b=l/wyGtbCgCMbQFLoK9Q2fPi1ZaX4VhtKlei7a0HKknKIg2GDxhwz0REMGH/Np4O9fFA2zu RgIDlZJJArFcaWomKrleKRIYf6H9P9kMT9PtyUs9H+W6ZP8+vpXrAbLl57+j7E9TjYbba3 MI027z7BqE9JBSDUXIdppWmAVg/u4BUVMm3IbKjRxPDaf1bGcaszDd+7/kb9Pip0Ili6E3 PWH0FU4NmMlAkJMJ1MvdmaEUEhWBFBkIaY/6r6X/AINFpaJTL3/RcT0VJxzwX4t4wtA0Y5 U0Rs+Z3U6g+Vx2UuhXxsCCk4n0yzf/m0E1z0MAOfMPVjMjCYl31D1SsXvz983A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1739961698; a=rsa-sha256; cv=none; b=kWiVv4VO5abZL1HBTK7yFBuOIbfuhNFhRUanmmDbbuGQM5KKu9CoSEvxAXCaWcnO82JVHp 39gOdtA1TzBD/IjbYbzTbFRNSmqCPKnyJwcBcDD9lkAEoPn/PwhR2Cjs7uy8ZgMueKjsig S7IylRw+yq8A2OmgQ64P5tlXgYDfmSdaYeg0MsWzPftnCf0zdUtpEIxH5DoaJBG662BNZJ 8yCAg6p2+YukeIER5+dvJTt0FK2it8OKkHRGge4uGmuVp/IQgjdyIpKGOUudRAXkC43eyc GtF4Y9+yC8ATXlYu/IfBALPLBerKiCuFqHTo3jn5llZSCS5k+8OFU+bxh8gEyw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1739961698; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6XVWIQ6liotqQ+uKEW6R2W27ndPwzQgcW166DxtfbH8=; b=hgzqfKqV70Uul0UR+Ty8419tX54KU2HCdkqtjNSS9HzmcSkOZgitkqD6CIjHUVS/3RFdwb UKKtXi+k/zNTszUcOeNZNqGJnVHvGvEo3itEkcdTi/xKi8oqa8OW/tgFtuIaiawgz13+nF vrQNrSn/akmGvrf6l8dm1q5FSj7RG25xfCoG0JuNGmFm+uDJWyVnpZmDtEkJwtkJ7cgaiY y1keSmnq6h0hFwkydd8XjPkQqdP4okJkHlOAaOGxCwIRx8MotoYPxJSJ6O2bEFjK8lCj9b lCgjFJg5v4ifqOMyYfLc6dlUGha/7AsEFte5ZN5wlICzi9J4EviFTuuTSWLryQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YyXxt3LZbz12gb; Wed, 19 Feb 2025 10:41:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 51JAfch8035335; Wed, 19 Feb 2025 10:41:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51JAfcCB035332; Wed, 19 Feb 2025 10:41:38 GMT (envelope-from git) Date: Wed, 19 Feb 2025 10:41:38 GMT Message-Id: <202502191041.51JAfcCB035332@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 8aa098b46914 - main - pf: pf_send_tcp: ask the stack to do the cksum instead of doing it manually List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8aa098b469144e56517b1e59302d918151cd04a1 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=8aa098b469144e56517b1e59302d918151cd04a1 commit 8aa098b469144e56517b1e59302d918151cd04a1 Author: Kristof Provost AuthorDate: 2025-02-11 15:09:53 +0000 Commit: Kristof Provost CommitDate: 2025-02-19 10:41:09 +0000 pf: pf_send_tcp: ask the stack to do the cksum instead of doing it manually ok benno lteo naddy (back in january) Obtained from: OpenBSD, henning , 674c6722fd Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/netpfil/pf/pf.c | 55 ++++++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 30 deletions(-) diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index da741364d372..2a1ee73b3aef 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -2354,7 +2354,9 @@ pf_intr(void *v) pfse->pfse_m->m_flags |= M_SKIP_FIREWALL; pfse->pfse_m->m_pkthdr.csum_flags |= - CSUM_IP_VALID | CSUM_IP_CHECKED; + CSUM_IP_VALID | CSUM_IP_CHECKED | + CSUM_DATA_VALID | CSUM_PSEUDO_HDR; + pfse->pfse_m->m_pkthdr.csum_data = 0xffff; ip_input(pfse->pfse_m); } else { ip_output(pfse->pfse_m, NULL, NULL, 0, NULL, @@ -2375,6 +2377,9 @@ pf_intr(void *v) pfse->pfse_m->m_flags |= M_SKIP_FIREWALL | M_LOOP; + pfse->pfse_m->m_pkthdr.csum_flags |= + CSUM_DATA_VALID | CSUM_PSEUDO_HDR; + pfse->pfse_m->m_pkthdr.csum_data = 0xffff; ip6_input(pfse->pfse_m); } else { ip6_output(pfse->pfse_m, NULL, NULL, 0, NULL, @@ -4003,28 +4008,46 @@ pf_build_tcp(const struct pf_krule *r, sa_family_t af, switch (af) { #ifdef INET case AF_INET: + m->m_pkthdr.csum_flags |= CSUM_TCP; + m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum); + h = mtod(m, struct ip *); - /* IP header fields included in the TCP checksum */ h->ip_p = IPPROTO_TCP; h->ip_len = htons(tlen); + h->ip_v = 4; + h->ip_hl = sizeof(*h) >> 2; + h->ip_tos = IPTOS_LOWDELAY; + h->ip_len = htons(len); + h->ip_off = htons(V_path_mtu_discovery ? IP_DF : 0); + h->ip_ttl = ttl ? ttl : V_ip_defttl; + h->ip_sum = 0; h->ip_src.s_addr = saddr->v4.s_addr; h->ip_dst.s_addr = daddr->v4.s_addr; th = (struct tcphdr *)((caddr_t)h + sizeof(struct ip)); + th->th_sum = in_pseudo(h->ip_src.s_addr, h->ip_dst.s_addr, + htons(len - sizeof(struct ip) + IPPROTO_TCP)); break; #endif /* INET */ #ifdef INET6 case AF_INET6: + m->m_pkthdr.csum_flags |= CSUM_TCP_IPV6; + m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum); + h6 = mtod(m, struct ip6_hdr *); /* IP header fields included in the TCP checksum */ h6->ip6_nxt = IPPROTO_TCP; h6->ip6_plen = htons(tlen); + h6->ip6_vfc |= IPV6_VERSION; + h6->ip6_hlim = V_ip6_defhlim; memcpy(&h6->ip6_src, &saddr->v6, sizeof(struct in6_addr)); memcpy(&h6->ip6_dst, &daddr->v6, sizeof(struct in6_addr)); th = (struct tcphdr *)((caddr_t)h6 + sizeof(struct ip6_hdr)); + th->th_sum = in6_cksum_pseudo(h6, len - sizeof(struct ip6_hdr), + IPPROTO_TCP, 0); break; #endif /* INET6 */ } @@ -4046,34 +4069,6 @@ pf_build_tcp(const struct pf_krule *r, sa_family_t af, memcpy((opt + 2), &mss, 2); } - switch (af) { -#ifdef INET - case AF_INET: - /* TCP checksum */ - th->th_sum = in_cksum(m, len); - - /* Finish the IP header */ - h->ip_v = 4; - h->ip_hl = sizeof(*h) >> 2; - h->ip_tos = IPTOS_LOWDELAY; - h->ip_off = htons(V_path_mtu_discovery ? IP_DF : 0); - h->ip_len = htons(len); - h->ip_ttl = ttl ? ttl : V_ip_defttl; - h->ip_sum = 0; - break; -#endif /* INET */ -#ifdef INET6 - case AF_INET6: - /* TCP checksum */ - th->th_sum = in6_cksum(m, IPPROTO_TCP, - sizeof(struct ip6_hdr), tlen); - - h6->ip6_vfc |= IPV6_VERSION; - h6->ip6_hlim = IPV6_DEFHLIM; - break; -#endif /* INET6 */ - } - return (m); }