I do have an idea. ROS and NAT-T just don't work together.
Simple test:
[Client|192.168.84.2]------[192.168.84.1|NAT Router|nn.nn.nn.nn]------[ss.ss.ss.ss|Server]
Client runs Windows 7.
NAT Router is doing nothing special, just masquerading the traffic.
Server is RouterOS with IPSec peer 0.0.0.0/0 and auto generate policy.
On client there's IPSec policy to encrypt ICMP to ss.ss.ss.ss.
ping -t ss.ss.ss.ss is running on client.
This is tcpdump output from nn.nn.nn.nn interface on NAT Router:
// this is how it looks before IPSec policy is enabled: 17:53:35.742256 nn.nn.nn.nn > ss.ss.ss.ss: icmp: echo request 17:53:35.762503 ss.ss.ss.ss > nn.nn.nn.nn: icmp: echo reply 17:53:36.740564 nn.nn.nn.nn > ss.ss.ss.ss: icmp: echo request 17:53:36.763472 ss.ss.ss.ss > nn.nn.nn.nn: icmp: echo reply // now it was enabled: 17:53:37.742869 nn.nn.nn.nn.500 > ss.ss.ss.ss.500: isakmp: phase 1 I ident: [|sa] 17:53:37.774797 ss.ss.ss.ss.500 > nn.nn.nn.nn.500: isakmp: phase 1 R ident: [|sa] (DF) 17:53:37.786527 nn.nn.nn.nn.500 > ss.ss.ss.ss.500: isakmp: phase 1 I ident: [|ke] 17:53:38.060922 ss.ss.ss.ss.500 > nn.nn.nn.nn.500: isakmp: phase 1 R ident: [|ke] (DF) // and you can see that NAT was detected and IPSec is correctly encapsulated in udp (NAT-T): 17:53:38.066047 nn.nn.nn.nn.4500 > ss.ss.ss.ss.4500: udp 72 17:53:38.299549 ss.ss.ss.ss.4500 > nn.nn.nn.nn.4500: udp 72 (DF) 17:53:38.302290 nn.nn.nn.nn.4500 > ss.ss.ss.ss.4500: udp 200 17:53:38.341726 ss.ss.ss.ss.4500 > nn.nn.nn.nn.4500: udp 152 (DF) 17:53:38.343059 nn.nn.nn.nn.4500 > ss.ss.ss.ss.4500: udp 76 17:53:38.343336 nn.nn.nn.nn.4500 > ss.ss.ss.ss.4500: udp 64 17:53:42.496674 nn.nn.nn.nn.4500 > ss.ss.ss.ss.4500: udp 76 // and here's the problem, ROS sends the reply to public IP of NAT Router: 17:53:42.519239 ss.ss.ss.ss > nn.nn.nn.nn: icmp: echo reply 17:53:47.488391 nn.nn.nn.nn.4500 > ss.ss.ss.ss.4500: udp 76 17:53:47.510976 ss.ss.ss.ss > nn.nn.nn.nn: icmp: echo reply
This is how it looks on Server:
17:53:37 ipsec respond new phase 1 negotiation: ss.ss.ss.ss[500]<=>nn.nn.nn.nn[500] 17:53:37 ipsec begin Identity Protection mode. 17:53:37 ipsec received broken Microsoft ID: MS NT5 ISAKMPOAKLEY 17:53:37 ipsec received Vendor ID: RFC 3947 17:53:37 ipsec received Vendor ID: draft-ietf-ipsec-nat-t-ike-02 17:53:37 ipsec 17:53:37 ipsec received Vendor ID: FRAGMENTATION 17:53:37 ipsec Selected NAT-T version: RFC 3947 17:53:37 ipsec Hashing ss.ss.ss.ss[500] with algo #2 17:53:37 ipsec NAT-D payload #0 verified 17:53:37 ipsec Hashing nn.nn.nn.nn[500] with algo #2 17:53:37 ipsec NAT-D payload #1 doesn't match 17:53:37 ipsec NAT detected: PEER 17:53:38 ipsec Hashing nn.nn.nn.nn[500] with algo #2 17:53:38 ipsec Hashing ss.ss.ss.ss[500] with algo #2 17:53:38 ipsec Adding remote and local NAT-D payloads. 17:53:38 ipsec NAT-T: ports changed to: nn.nn.nn.nn[4500]<->ss.ss.ss.ss[4500] 17:53:38 ipsec KA list add: ss.ss.ss.ss[4500]->nn.nn.nn.nn[4500] 17:53:38 ipsec ISAKMP-SA established ss.ss.ss.ss[4500]-nn.nn.nn.nn[4500] spi:ade1d76b90eb17a8:6f90143abe23e16f 17:53:38 ipsec respond new phase 2 negotiation: ss.ss.ss.ss[4500]<=>nn.nn.nn.nn[4500] 17:53:38 ipsec no policy found, try to generate the policy : 192.168.84.2/32[0] ss.ss.ss.ss/32[0] proto=icmp dir=in 17:53:38 ipsec Adjusting my encmode UDP-Transport->Transport 17:53:38 ipsec Adjusting peer's encmode UDP-Transport(4)->Transport(2) 17:53:38 ipsec IPsec-SA established: ESP/Transport nn.nn.nn.nn[4500]->ss.ss.ss.ss[4500] spi=5091372(0x4db02c) 17:53:38 ipsec IPsec-SA established: ESP/Transport ss.ss.ss.ss[4500]->nn.nn.nn.nn[4500] spi=2918330273(0xadf22fa1)
And logging of output icmp packets from router looks like this:
17:53:42 firewall,info output: in:(none) out:public, proto ICMP (type 0, code 0), ss.ss.ss.ss->nn.nn.nn.nn, len 40 17:53:47 firewall,info output: in:(none) out:public, proto ICMP (type 0, code 0), ss.ss.ss.ss->nn.nn.nn.nn, len 40
They go straight to nn.nn.nn.nn instead of to correct 192.168.84.2.