Article View: muc.lists.freebsd.bugs
Article #334[Bug 300461] pf: af-to inet → inet6 never maps ICMP echo type, so echo replies from NAT64 don't match the state
From: bugzilla-noreply
Date: Mon, 02 Nov 2026 22:16
Date: Mon, 02 Nov 2026 22:16
113 lines
6291 bytes
6291 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300461
Bug ID: 300461
Summary: pf: af-to inet → inet6 never maps ICMP echo type, so
echo replies from NAT64 don't match the state
Product: Base System
Version: 15.1-RELEASE
Hardware: amd64
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: charles@wozi.com
Created attachment 276925
--> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=276925&action=edit
Fix ICMP echo type mapping for af-to inet -> inet6
**Version:** 15.1-RELEASE-p5 (amd64). The code is the same in main.
**Setup:** a LAN host's IPv4 traffic is translated to IPv6 for a provider's
NAT64 (T-Mobile US):
pass in quick on ix2 inet from 192.168.1.169 to any \
scrub (max-mss 1412) af-to inet6 from 2607:fb91:2268:4408::464 to
64:ff9b::/96
TCP and UDP work through this rule: HTTPS, DNS and multi-MB transfers. ICMP
echo from the LAN host doesn't: 0 replies.
**Observed:** tcpdump on the IPv6 side shows the translated echo request going
out and the ICMPv6 echo reply coming back:
IP6 2607:fb91:2268:4408::464 > 64:ff9b::101:101: ICMP6, echo request, id
52163, seq 101
IP6 64:ff9b::101:101 > 2607:fb91:2268:4408::464: ICMP6, echo reply, id
52163, seq 101
The reply is never translated back. `pfctl -ss` shows why: the IPv6-side key of
the af-to state still carries the ICMPv4 echo type (8), and the reply then
creates a separate state through an ordinary icmp6 pass rule, keyed with the
ICMPv6 type (128):
all icmp 2607:fb91:2268:4408::464[52163] (192.168.1.169:52163) ->
64:ff9b::101:101[8] (1.1.1.1:52163) 0:0
all ipv6-icmp 2607:fb91:2268:4408::464[52163] <- 64:ff9b::101:101[128]
NO_TRAFFIC:NO_TRAFFIC
**Cause:** in `pf_get_transaddr_af()` (sys/netpfil/pf/pf_lb.c), the inet →
inet6 branch byte-swaps `nsport` but then compares and assigns `ndport`:
} else if (pd->proto == IPPROTO_ICMP && pd->naf == AF_INET6) {
pd->nsport = ntohs(pd->nsport);
if (pd->ndport == ICMP_ECHO)
pd->ndport = ICMP6_ECHO_REQUEST;
else if (pd->ndport == ICMP_ECHOREPLY)
pd->ndport = ICMP6_ECHO_REPLY;
pd->nsport = htons(pd->nsport);
}
`ndport` is still in network byte order, so on little-endian it is never equal
to `ICMP_ECHO`. The type is not mapped and the state key keeps 8. The inet6 →
inet branch just above converts `ndport` correctly.
It looks like a porting slip. OpenBSD's version (sys/net/pf_lb.c,
`pf_get_transaddr_af()`) splits each branch on `pd->dir`: `PF_IN` converts and
maps `ndport`, and `PF_OUT` converts and maps `nsport`. FreeBSD only allows
af-to on inbound rules and keeps one body per branch. The inet6 → inet branch
kept OpenBSD's `PF_IN` body, but the inet → inet6 branch combined the `PF_OUT`
byte swaps (`nsport`) with the `PF_IN` comparison (`ndport`). The patch makes
it OpenBSD's `PF_IN` body verbatim.
**Fix:** the attached patch converts `ndport` instead of `nsport` in that
branch. It is a two-line change.
**Testing:** I haven't built a kernel with the patch, so it is untested. The
cause is from reading the source and matches the observed state key exactly. A
regression test would help: tests/sys/netpfil/pf/nat64.sh only covers the inet6
→ inet direction (`pass in ... inet6 ... af-to inet`), so the inet → inet6
direction has no coverage. An `icmp_echo` case would catch this: a client ping
through `pass in on <v4 if> inet af-to inet6 from <rtr v6> to 64:ff9b::/96`,
against an IPv6 destination that answers for the 64:ff9b::/96 address.
Possibly related: 284944 and D49143 (ICMP error translation in af-to), 291617
(af-to does not generate ICMPv6 packet too big).
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID:
<bug-300461-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 300461] pf: af-to inet → inet6 never maps ICMP echo type, so echo replies from NAT64 don't match the state Date: Mon, 02 Nov 2026 22:16:29 +0000 Organization: Newsgate at muc.de e.V. Sender: owner-freebsd-bugs@FreeBSD.org Approved: news-admin@muc.de Distribution: world Message-ID: <bug-300461-227@https.bugs.freebsd.org/bugzilla/> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="32880"; mail-complaints-to="news-admin@muc.de" X-Original-To: bugs@mlmmj.nyi.freebsd.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793657788; 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=o3jUxoSSbOIDPqa8swPMQNtZNN33mvnNhJD2TtjHPfw=; b=nXw4ycQtUPg8GmnAUt4QqWZvbyVIH1WrzxJldnHAchVNh347V74AXK9BlQQM0teH8mskXQ cqrvnDlrtdsjAT+j8gzBLCCJXUh8fySVtJyXwzJrkA+Dvl08c+XZ/2/LgBPU3y848y4a0C TI5oVHSakePkMyuxTz6hSH+qvwHiHBsTXQmOaAEZqeX9cAQeDOhxx3gwrz4UILFsqdeUXd FMrqE8gytGs1dmg2Q+vcoY2aiDwXUaMqC3MRHb95C+FU8unupC1GrAqjulsrUuR+OnEZ7N iFyxMTZpw2rz4gyTKecjltiSydgwcUa7uqKs7tbQXf2uBeMpMJjlWBIeyFG3IQ== X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f Auto-Submitted: auto-generated Precedence: list X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes