git: 21c2318d667f - stable/14 - ipfilter: Remove erroneous ntohs()

From: Cy Schubert <cy_at_FreeBSD.org>
Date: Fri, 13 Nov 2026 19:33:15 UTC
The branch stable/14 has been updated by cy:

URL: https://cgit.FreeBSD.org/src/commit/?id=21c2318d667fea7ed8c7a2e4ae9bafa5409ee8c1

commit 21c2318d667fea7ed8c7a2e4ae9bafa5409ee8c1
Author:     Cy Schubert <cy@FreeBSD.org>
AuthorDate: 2026-11-09 23:13:21 +0000
Commit:     Cy Schubert <cy@FreeBSD.org>
CommitDate: 2026-11-13 19:33:05 +0000

    ipfilter: Remove erroneous ntohs()
    
    The original commit was wrong.  ipf_nat_builddivertmp() builds the UDP
    template with the length in host byte order
    
    M_DUP() copies that value unchanged. The old code was therefore correct.
    It added fin_plen in host order and then did a single htons().
    
    The original patch was discussed with Co-Pilot, which pointed out the
    original bug. claude-opus-5-5 discovered the ntohs() error that
    co-pilot suggested.
    
    Interestingly this code had been running here for a couple of months.
    
    Reported by:    llm-postcr
    Fixes:          72cc9e3766f4
    (cherry picked from commit 86861520613f99c85b5fbdf92b5c955a13ed6624)
---
 sys/netpfil/ipfilter/netinet/ip_nat.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/sys/netpfil/ipfilter/netinet/ip_nat.c b/sys/netpfil/ipfilter/netinet/ip_nat.c
index 8e6c3107c782..311968746c10 100644
--- a/sys/netpfil/ipfilter/netinet/ip_nat.c
+++ b/sys/netpfil/ipfilter/netinet/ip_nat.c
@@ -5160,7 +5160,6 @@ ipf_nat_out(fr_info_t *fin, nat_t *nat, int natadd, u_32_t nflags)
 
 		if (ip->ip_p == IPPROTO_UDP) {
 			uh = (udphdr_t *)(ip + 1);
-			uh->uh_ulen = ntohs(uh->uh_ulen);
 			uh->uh_ulen += fin->fin_plen;
 			uh->uh_ulen = htons(uh->uh_ulen);
 		}