Static-port outbound NAT drops UDP/5060 packets with map-failed...

Started by anomaly0617, November 14, 2026, 04:21:44 PM

Previous topic - Next topic
OPNsense 26.7.8_1: static-port outbound NAT drops UDP/5060 packets with map-failed when a WAN redirect uses the reverse tuple


Environment

  • OPNsense 26.7.8_1 (opnsense-26.7.8_1)
  • FreeBSD 15.1-RELEASE-p6, stable/26.7-n284176-c962f76493b6, amd64
  • WAN ix0, LAN ix1
  • WAN VIP 203.0.113.10; LAN VIP 192.0.2.1
  • PF state limits were not exhausted; the preserved snapshots show zero memory exhaustion.
  • Exact PF userland/source revision: unknown in the preserved evidence.

Topology
SIP carrier                      OPNsense                        PBX
198.51.100.128:5060  <---- ix0/WAN ---- ix1/LAN ---->  192.0.2.11:5060
                                    WAN VIP
                                  203.0.113.10:5060

The WAN UDP/5060-5063 port forward redirects inbound traffic to the PBX UDP/5060. A manual outbound NAT rule for the PBX uses the same WAN VIP with static-port.

Problem statement

Independent PBX-originated SIP OPTIONS packets reach the LAN interface and are accepted by PF, but PF fails to create the outbound NAT mapping. No corresponding request leaves the WAN. The LAN-created state has no translated tuple and remains NO_TRAFFIC:SINGLE. PF's global map-failed counter increments once per failed packet, while the dedicated outbound NAT rule's packet and state counters do not change.

At the same time, inbound carrier transactions to the WAN VIP UDP/5060 continue to be redirected to the PBX and replies continue to leave the WAN.

Observed evidence

Capture interval: 2026-11-13T18:10:37Z through 2026-11-13T18:12:37Z. Packet display timestamps were local EST and are normalized to UTC below.
Measurement                                                    Before  After  Delta
LAN ix1 PBX 192.0.2.11:5060 -> 198.51.100.128:5060 packets  -      21      +21
WAN ix0 matching PBX-originated OPTIONS                    -      0      0
PF global map-failed                                          5431    5452    +21
Rule 164 state packets                                          55      76      +21
Rule 5 NAT packets                                              10387  10387  0
Rule 5 NAT active states                                        0      0      0
Rule 5 NAT evaluations                                          498732  500117  +1385

The 21 LAN packets are retransmissions spanning two unique outbound SIP Call-IDs. Four inbound carrier transactions used four other Call-IDs; the outbound and inbound Call-ID sets did not intersect. Exact Call-ID values are omitted.

The first failed LAN packet was observed at 2026-11-13T18:11:08.397959Z; the last was observed at 2026-11-13T18:12:35.898063Z.

Representative successful inbound correlation:
UTC time          Interface  Packet
18:11:04.134366  ix0      198.51.100.128:5060 -> 203.0.113.10:5060 OPTIONS
18:11:04.134379  ix1      198.51.100.128:58653 -> 192.0.2.11:5060 redirected request
18:11:04.136388  ix1      192.0.2.11:5060 -> 198.51.100.128:58653 200 OK
18:11:04.136398  ix0      203.0.113.10:5060 -> 198.51.100.128:5060 translated 200 OK

The two-interface timestamps differ by 13 microseconds on the inbound redirection and 10 microseconds on the reverse path, supporting synchronized capture rather than a capture mismatch.

Expected behavior

The independent PBX flow should match the dedicated outbound static-port NAT rule and leave ix0 as:
203.0.113.10:5060 -> 198.51.100.128:5060
The generated state should contain a valid translated tuple, and the reply should return to the PBX.

Actual behavior

The LAN filter accepts the packets and creates this state:
all udp 198.51.100.128:5060 <- 192.0.2.11:5060  NO_TRAFFIC:SINGLE
age 00:06:59, 76:0 pkts, 35775:0 bytes, rule 164
origif: ix1

There is no translated tuple in the state, no WAN request, and no reply. map-failed increases by the same number as the LAN packets.

The simultaneously valid inbound state is:
all udp 192.0.2.11:5060 (203.0.113.10:5060)
  <- 198.51.100.128:58653 (198.51.100.128:5060)  MULTIPLE:MULTIPLE

This inbound state's working external endpoint pair uses the same two host:port endpoints in the opposite direction from the desired outbound static NAT tuple.

Hypothesis under test

The leading hypothesis is that PF's fixed-port outbound mapping cannot create the desired tuple while the active WAN redirect state occupies the reverse endpoint tuple, or that this configuration reaches a first-packet NAT/state ordering edge case. This is not proven.

The following are not established:

  • that this is an OPNsense-specific defect;
  • that this is a FreeBSD PF defect;
  • that the behavior is intentional PF behavior;
  • that CARP or pfsync contributed;
  • that the exact internal branch responsible for map-failed has been identified.

Questions for maintainers

  • Is a static-port outbound mapping expected to fail when an active port redirect creates the reverse WAN endpoint tuple?
  • If this is expected, where is that restriction documented, and which read-only diagnostic should distinguish a fixed-port collision from other map-failed causes?
  • Which NAT state or rule evaluation is attempted after the LAN keep state rule has accepted the packet but before the outbound NAT counter advances?
  • Is the unchanged packet/state count on the matched NAT rule, while the global evaluation counter advances, expected for failed fixed-port allocation?
  • Does PF intentionally rewrite the redirect-side source port but reject or decline the inverse static-port mapping? If so, what prevents allocation of an alternate outbound source port when static-port is present?
  • Can PF debug logging expose the precise mapping conflict without packet modification? Which counter, zone, anchor, or log should maintainers expect to identify it?
  • Is the kernel revision stable/26.7-n284176-c962f76493b6 affected by a known fix, limitation, or source change involving fixed-port NAT and reverse redirect state?
  • Would a vanilla FreeBSD installation with equivalent manually loaded PF rules be expected to behave identically?

Reproduction request

Please reproduce in an isolated lab using:

  • the exact OPNsense build above;
  • WAN 203.0.113.10 and PBX 192.0.2.11;
  • WAN UDP/5060-5063 redirect to PBX UDP/5060;
  • outbound NAT from the PBX to 203.0.113.10 with static-port;
  • one inbound carrier packet from 198.51.100.128:5060 to the VIP to establish the redirect state;
  • one independent PBX packet from 192.0.2.11:5060 to 198.51.100.128:5060;
  • captures on WAN, LAN, and the carrier simulator;
  • before/after pfctl -si, pfctl -sn -vv, pfctl -sr -vv, pfctl -ss -vv, and pfctl -sl -vv.

Repeat without the redirect, with PBX source port 5062, without static-port, and with equivalent rules on vanilla FreeBSD. The annex contains the full control matrix and expected discriminators.

Disclosure

AI tools were used to correlate preserved read-only captures, PF state, NAT rules, counters, routing, interface, and CARP evidence and to prepare this draft. A human reporter has reviewed the final evidence, confirmed the sanitized address substitutions, and approved any submission.

You or your AI don't set out the fw/NAT rules involved, but given the PBX internal IP is not RFC1918, do you have a typo somewhere in your opnsense config?

No, the AI anonymized/redacted information before providing the final report. The internal network is RFC1918, the external network is appropriately set static with a valid static IP, and some traffic makes it through, just not all of it. This is most frustrating because it means "sometimes" outbound calling works, and sometimes it does not. I could tell the SIP provider to accept both the default outbound IP and the one designated for VoIP, but that doesn't really resolve the underlying issue.

I've been testing on this for a few days now to make sure it's not something internal or external to the firewall, but the config prior to upgrading to 26.7 was stable for years. So this is something new in the 26.x line, it's just a question of whether it's an OPNsense problem, a PF problem, or a FreeBSD problem.

Destination NAT and static source NAT rules I use for internal PBX are working OK on 26.7.9_1. I only forward and static NAT the specific UDP port range used by the PBX (which I have reduced considerably from the default) rather than the entire unprivileged UDP port range. However I don't believe that should matter as there can be no conflict with other internal IPs AIUI.

Sorry, TL;DR.

If you have more than one public IP address on your service, you could use One-to-One NAT (BINAT) between your ITSP and your internal PBX and see if that changes the behaviour.

I've read various postings about port-forwarding to the internal PBX. I have not encountered a situation where this has been a requirement. Firewall configurations I've used rely upon the connection for the outgoing registration as the channel with which incoming calls will arrive from the ITSP.

In your environment, and prior to 26.7.8_1, what problem does forwarding inbound connections for port range 5060-5063 resolve for you?

In my environment I have set up DNS redirection on some networks. I've observed a rule which passes the traffic to the firewall occasionally reports a connection is blocked - an oddity when the rule in question is configured to pass the traffic, though I suspect there is a simple explanation why this is occurring.

The blocked and logged connections appear to occur when a DNS query is made from an IP address using the same source port to establish a connection to two different DNS server IP addresses. The two connections get redirected internally (Destination NAT) to the same internal IP address. The firewall isn't happy when setting up the second connection and drops it. I may look into this quirk one day and see if changing the Firewall rule setting under advanced mode of the Destination NAT entry from Manual to Register rule.

Perhaps you are seeing something similar with your VoIP traffic.

I was under the impression that a port forward for at least SIP was needed. If there's no SIP traffic for the duration of the firewall's UDP session timeout (which is 60s by default), session expires and incoming SIP may be dropped until client issues a SIP options or some other keepalive. In my set up, I had problems with calls sometimes dropping after 900+ seconds. I mistakenly thought this was related to UDP session timeout. So I began port-forwarding (and static source NAT) SIP and the full RTP range used by my PBX (subsequently reduced mainly for that purpose). However the problem was finally (months later!) narrowed down to the ATA I was using. It did not like the remote changing RTP packet size midway through a call and this typically occurred after ~15 minutes on those problem calls. I switched ATAs and issue solved. Nothing to do with the firewall. Some of those rules, that remain in place, may be redundant. But I am fairly sure I would miss incoming calls if it were not for at least a SIP port forward.

Quote from: keeka on <strong>Today</strong> at 08:10:16 AMIf there's no SIP traffic for the duration of the firewall's UDP session timeout (which is 60s by default)

Usually with the registration timeout of 60 seconds, the re-register will occur around 15 seconds before it expires. An established UDP connection through PF will have a default timeout of 60 seconds, so chances are the registration would remain active through the original connection.

I had a similar problem with one of my SIP providers many years ago who had a variable registration time ranging from 45 - 235 seconds (last verified to still occur on the 1st of December 2025). Going way back, to alleviate the problem and to keep the session alive I enabled the keepalive option in Asterisk's sip.conf and set it to 30 seconds.

Early this year I set up a new Asterisk box. Looking at my notes in the PJSIP configuration for this provider, I did not include the keepalive option, instead I tweaked the timeout settings in the SIP firewall rules for this connection by setting udp.multiple
& udp.single to 220 seconds. This is 15 seconds short of the maximum registration time observed with this provider and Asterisk re-registration would occur 15-seconds before it was due to expire, thus the connection remained active and able to receive incoming calls. I've since amalgamated my rules for my VoIP providers.

I recently moved a number to another SIP provider and the connection is using TLS for the signalling. In the firewall rule of TLS (TCP port 5061) I've set the TCP established timeout to 1800 seconds. This is so that when the connection dies abnormally, such as when the provider performs maintenance, the session doesn't hang around unnecessarily, though the registration retry count is set to 100 at 60 second intervals.

Quote from: keeka on <strong>Today</strong> at 08:10:16 AMI had problems with calls sometimes dropping after 900+ seconds

May years ago, I had this problem too where the call would drop out - from memory it would be about 30 - 45 minutes into a call. The problem was related to Session-Timers for the call. Looking at my very old configuration, to overcome the problem I set the session-timers option in sip.conf for this provider to accept.

I have used a variety of ATA's with fax-modems and have not experienced any problems. ATA's, like hard phones, have an option to keep a session alive when using NAT. I expect this option is in soft phones too.

Quote from: keeka on <strong>Today</strong> at 08:10:16 AMthe ATA I was using. It did not like the remote changing RTP packet size midway through a call

I've never noticed packet sizes changing during a call as the parameters for the session are negotiated and established at the beginning of a call.

These parameters are likely to affect packet size:

- 1) Packetisation Time - typically 20ms
- 2) Changing Codec
- 3) Voice Activity detection

I don't know what would change these during a call. The most likely triggers I can think of could be transferring a call or going to music-on-hold, or something like that.

Voice Activity Detection (VAD), if enabled, would result in no packets being sent when silence is detected. I don't ever enable VAD, though, I expect that if it was enabled and there was more than 60 seconds of silence, the RTP stateful connection would close if rtpkeepalive isn't enabled. I would also expect a new state to be created once the RTP stream resumes sending packets.


Today at 11:01:13 AM #7 Last Edit: Today at 11:25:55 AM by keeka Reason: add info
In my home setup (my only experience of VOIP), each phone hardware (Cisco ATA192 and Gigaset N300) were at various times registered to a local asterisk server and directly to the SIP provider. After capturing all SIP/RTP traffic on the WAN and the local VOIP network for a few weeks, I eventually found a correlation. When the Gigaset N300 received an RTP psize change (from 20ms to 30ms I think it was), it stopped playing the incoming RTP stream. RTP packets were still arriving at the device (i.e. no router/firewall issue) but the device itself played no further audio. The Cisco ATA handled the same OK. I don't know which link in the chain changed psize, but it was north of my SIP provider. So the remote user's phone or their SIP provider network.
Re SIP registration interval and keepalive SIP options. I thought a port forward favourable to either extending udp session lifetime or increasing SIP chatter.
Trust me, the participants in the phone call would not have been silent for 60 seconds ;-)
I managed to find the notes I made at the time:
    • Initial Handshake: The N300-IP sends a SIP INVITE explicitly requesting a=ptime:20 and PCMA.
    • Initial RTP Stream: For the first 15 minutes, the incoming RTP stream is stable with a frame size of 214 bytes (consistent with 20ms G.711a).
    • The Trigger: At 15 minutes, the remote side sends an RTP packet with the Marker (M) bit set.
    • Simultaneously, the incoming RTP frame size jumps from 214 bytes to 374 bytes (indicating a switch to ~40ms packetization?). There is no SIP re-INVITE or UPDATE signaling this change.
    • Hardware Response: The N300-IP immediately logs the following hardware exceptions and drops the audio path:
    Except=0x2=S_EXCEPTCLASS_ERROR Place=0x51=S_EXCEPTPLACE_SC_LAN Code=0xD4=SLE_EXC_CODE_INT_RX_RT_LNG_ERR PrcNr=23 LinkAdr=0x0 File=sc/middleware/lan/sl_.exc
    • Status: RTP packets continue to arrive at the N300 at the new 374-byte size, and the N300 repeats the log for each RTP packet received from that point on.