Spent a good part of the day fighting with a route-based IPsec tunnel between a MikroTik CCR2116 and a UniFi UDM Pro Max.
Eventually got it working, so I figured I'd share what I found in case someone else runs into the same problem. There's still not a whole lot of documentation on XFRM in RouterOS, especially when dealing with third-party devices.
The setup
-
MikroTik CCR2116 running RouterOS 7.25 stable
-
UniFi UDM Pro Max
-
IKEv2 with PSK
-
Phase 1: AES-256-CBC, SHA256, DH14
-
Phase 2: AES-256-CBC, SHA256, no PFS
-
Route-based IPsec using XFRM
-
Traffic selectors:
0.0.0.0/0 <=> 0.0.0.0/0 -
Static route pointing to the remote LAN through the XFRM interface
What was happening
The tunnel came up without much trouble. Phase 1 established, Phase 2 established, XFRM interface running, static route active.
So far, so good.
Except absolutely nothing was going through it.
Every ping returned host unreachable. Looking at the interface statistics, I noticed TX drops on the XFRM interface. Even more interesting, the IPsec out-no-states counter was increasing by exactly one for every failed ping.
The outbound ESP SA was installed, but it wasn't actually processing any traffic.
On the other hand, the inbound SA was receiving packets, yet the XFRM interface showed zero RX packets.
At that point, I started going through pretty much everything I could think of; Routes, NAT, firewall rules, IPsec proposals, traffic selectors, policy groups, installed SAs. Nothing immediately stood out.
What made it particularly annoying was that everything looked established. If you just checked the active peers and installed SAs, you'd think the tunnel was fine.
What finally got it working
I came across a MikroTik forum discussion showing a working route-based XFRM configuration and noticed something different in how the IPsec identity was configured.
Mine had:
generate-policy=no
So I changed mine to:
/ip ipsec identity
set [find where peer="REMOTE-PEER"] \
generate-policy=port-strict \
policy-template-group=REMOTE-XFRM
The policy group was already associated with the XFRM interface:
/ip ipsec policy group
add name=REMOTE-XFRM interface=xfrm-remote
And I already had a static policy using the broad traffic selectors:
/ip ipsec policy
add peer=REMOTE-PEER \
tunnel=yes \
group=REMOTE-XFRM \
src-address=0.0.0.0/0 \
dst-address=0.0.0.0/0 \
action=encrypt \
level=require \
proposal=REMOTE-ESP
I didn't add another policy with template=yes.
After making that change, the IKEv2 tunnel renegotiated. Interestingly, this time the MikroTik was the initiator instead of the responder.
And suddenly, traffic started moving.
Well, not quite immediately. The first thing I noticed was that pings stopped returning local host unreachable errors and started timing out instead.
That was actually progress.
The outbound ESP counters were finally increasing, and after sending four test pings, the out-no-states counter hadn't increased at all.
Then I started seeing inbound ESP traffic being processed, RX and TX counters increasing on XFRM, and no new TX drops.
Eventually, actual LAN-to-LAN connectivity was working.
Tested the following:
-
ICMP: successful, 0% packet loss
-
TCP 445 (SMB): successful
-
TCP 389 (LDAP): successful
So what was the actual problem?
That's the part I'm still not 100% sure about.
Changing generate-policy=no to generate-policy=port-strict and assigning the correct policy template group is what finally got things moving.
But the tunnel also renegotiated at the same time, with the MikroTik becoming the initiator. So I can't say with absolute certainty whether the policy generation setting was the entire problem or whether the new negotiation also played a role.
What I can say is that before the change, I had an established CHILD_SA, an active XFRM interface, and a static IPsec policy, but no usable outbound ESP traffic.
After the change, the counters started behaving normally and LAN-to-LAN connectivity worked.
If you're troubleshooting something similar, these commands were particularly helpful:
/ip ipsec installed-sa print detail
/ip ipsec statistics print
/interface print stats
Pay attention to out-no-states, XFRM TX drops, and whether your outbound ESP SA actually gets the S flag indicating it has seen traffic.
Also, just because Phase 2 says established doesn't mean your traffic is actually being encrypted and forwarded.
Anyway, has anyone else run into this on RouterOS 7.25, particularly with UniFi or another third-party IPsec implementation?
I'm especially curious whether generate-policy=port-strict is actually expected to be necessary for this type of setup or whether there's something else going on with XFRM and policy matching.
Would be interested in hearing from anyone who's had more experience with RouterOS XFRM.
Note: I used AI to help clean up the formatting and sanitize sensitive configuration details. The troubleshooting and findings are my own.


