Packet gets lost: how to debug?

Hi all,

I’m trying to set up a IPSec connection between AWS (10.5.0.0/16, test machine at 10.5.1.14) and my company network (10.0.10.0/24, test machine at 10.0.10.2, router is at 10.0.10.254). I’ve set up everything and routes are propagated correctly.

What I’m seeing: from 10.0.10.2 I’m pinging 10.5.1.14. On 10.5.1.14: packet is received (icmp echo request), response is sent (icmp echo reply).

On my router, the icmp reply is received in the prerouting chain:
in:ether1-gateway out:(none), src-mac ::**, proto ICMP (type 8, code 0), 10.5.1.14->10.0.10.2, len 84

Then, I can see it in the dst-nat chain (action=accept, no rewriting is done). After that, I cannot find the packet anymore. I’ve put passthrough (with src=10.5.0.0/16) rules on my fw input, fw forward and postrouting chain, but it never shows up anymore.

How do I have to read the Packet Flow diagram?

Bump: anyone that has an idea of where my packets are going?

Anybody? If I need to provide more details, let me know. I’m really at a loss here.

Post your export of:
/ip ipsec exp
/ip fi filt exp
/ip fi nat exp
/ip fi mang exp
/ip rou exp

/ip ipsec proposal
set [ find default=yes ] enc-algorithms=3des,aes-128-cbc,aes-192-cbc,aes-256-cbc lifetime=1h
add lifetime=1h name=proposal-aws



/ip ipsec peer
add address=54.239.63.111/32 disabled=yes dpd-interval=10s dpd-maximum-failures=3 enc-algorithm=aes-128 lifetime=8h secret=verysecret1
add address=54.239.63.222/32 disabled=yes dpd-interval=10s dpd-maximum-failures=3 enc-algorithm=aes-128 lifetime=8h secret=verysecret2
add address=54.239.63.111/32 dpd-interval=10s dpd-maximum-failures=3 enc-algorithm=aes-128 lifetime=8h secret=verysecret1
add address=54.239.63.222/32 dpd-interval=10s dpd-maximum-failures=3 enc-algorithm=aes-128 lifetime=8h secret=verysecret2



/ip ipsec policy
add dst-address=10.5.0.0/16 level=unique proposal=proposal-aws sa-dst-address=54.239.63.111 sa-src-address=[my wan ip] src-address=0.0.0.0/0 tunnel=yes
add dst-address=10.5.0.0/16 level=unique proposal=proposal-aws sa-dst-address=54.239.63.222 sa-src-address=[my wan ip] src-address=0.0.0.0/0 tunnel=yes
add dst-address=169.254.237.17/32 level=unique proposal=proposal-aws sa-dst-address=54.239.63.111 sa-src-address=[my wan ip] src-address=0.0.0.0/0 tunnel=yes
add dst-address=169.254.237.21/32 level=unique proposal=proposal-aws sa-dst-address=54.239.63.222 sa-src-address=[my wan ip] src-address=0.0.0.0/0 tunnel=yes



/ip firewall filter
add chain=input comment="allow from aws customer gateways" src-address=169.254.237.16/30
add chain=input src-address=169.254.237.20/30

add chain=input comment="allow related" connection-state=related in-interface=ether1-gateway
add chain=input connection-state=related in-interface=ether2-gateway
add chain=input comment="allow established" connection-state=established in-interface=ether1-gateway
add chain=input connection-state=established in-interface=ether2-gateway

add chain=input comment="allow ping" in-interface=ether1-gateway protocol=icmp
add chain=input in-interface=ether2-gateway log-prefix=icmp protocol=icmp

add action=drop chain=input comment="drop invalid" connection-state=invalid in-interface=ether1-gateway
add action=drop chain=input connection-state=invalid in-interface=ether2-gateway
add action=drop chain=forward connection-state=invalid in-interface=ether1-gateway
add action=drop chain=forward connection-state=invalid in-interface=ether2-gateway
add action=drop chain=input comment="drop everything" in-interface=ether1-gateway
add action=drop chain=input in-interface=ether2-gateway



/ip firewall nat
add chain=srcnat comment="do not masquerade traffic between mikrotik and aws" dst-address=10.5.0.0/16 action=accept
add chain=dstnat src-address=10.5.0.0/16 action=accept

add action=masquerade chain=srcnat comment="masquerade outgoing traffic" log-prefix=masq out-interface=ether1-gateway to-addresses=0.0.0.0
add action=masquerade chain=srcnat out-interface=ether2-gateway



/ip firewall mangle
add chain=prerouting log-prefix=prerouting src-address=10.5.0.0/16
add chain=input action=passthrough log=yes log-prefix="mangle inp" protocol=icmp



/ip route
[ nothing relevant, just a check-gateway rule ]

I’ve removed some unrelated firewall rules.

Just right now, while logging both the prerouting and mangle input chain, saw these two lines:

prerouting in:ether1-gateway out:(none), src-mac e4:48:ab:ab:ab:ab, proto ICMP (type 8, code 0), 10.5.1.14->10.0.10.2, len 84
mangle inp input: in:ether1-gateway out:(none), src-mac e4:48:ab:ab:ab:ab, proto ICMP (type 8, code 0), [aws wan]->[my wan ip], len 84

So the src-mac addresses are the same, but the ip addresses are translated to wan ips. Wouldn’t expect that, as I have a accept rule for traffic from 10.5.0.0/16 in my /ip firewall nat.

First of all, from these exports, your IPSec should not work at all, since the policies dont match the peers:

/ip ipsec peer
add address=54.239.63.154/32 ...
add address=54.239.63.155/32 ...

/ip ipsec policy
add ... sa-dst-address=54.239.63.111 ...
add ... sa-dst-address=54.239.63.222 ...
add ... sa-dst-address=54.239.63.111 ...
add ... sa-dst-address=54.239.63.222 ...

You also have 2 policies for the same traffic, to different peers. This is probably wrong, atleast I dont think that is what you want to do…

/ip ipsec policy
add dst-address=10.5.0.0/16 ...
add dst-address=10.5.0.0/16 ...

Your firewall is also a mess. You arent accepting IPSec traffic from your IPSec peers at all in the input chain.
You have:

/ip firewall filter
add chain=input comment="allow from aws customer gateways" src-address=169.254.237.16/30
add chain=input src-address=169.254.237.20/30

But these are not your IPSec peers according to “/ip ipsec peer” export.

As for mangle and nat, you can remove mangle rules entirely, and you can remove 2nd nat rule.

Regarding the packets you notice, those are not a problem, those are just the Amazon VPN gateways checking if you are alive with ICMP (ping).
These packets are fine and should be like that.

IPsec is working (but only one tunnel, the .111 one), AWS is reporting that the tunnel is up (and routes to 10.0.10.0/24 are advertised via BGP). The addresses being incorrect and missing incoming ipsec firewall rule was a copy-paste mistake on my end. Sorry for the confusion.

I can also confirm traffic is arriving at 10.5.1.14 when pinging from 10.0.10.2. Replies from 10.5.1.14 arrive at the router again, but never find their way to 10.0.10.2.

The policies are correct afaik. AWS uses a double-endpoint for their VPN connections (in different availability zones), so there’s a redundant connection between the mikrotik and AWS. There’s a limitation in RouterOS (last paragraph) which prevents ipsec policies with the same src- and dst-addresses from being active at the same time (but their sa-dst-address is different). I guess this isn’t a problem though, at least one connection should be up.

Thanks for thinking along, much appreciated :slight_smile:

That is why I said it would not work with the previously posted config.

There must be other config that prevents this, firewall and NAT and mangle are OK from what you posted.

This is exactly what I meant. 2nd peer will never come up, as the 2nd policy will never be used.
If you are aware of this, then ok. Just know that this is not failover, nor redundancy.

Simply, the 2nd policy will NEVER be used, and therefore the 2nd peer will NEVER be used.

I removed the superfluous rules from my nat/filter chains, still no luck though.

There must be other config that prevents this, firewall and NAT and mangle are OK from what you posted.

And they should be in either the /ip firewall mangle or filter, right? I have no rules in those chains that explicitly drop this traffic, and if I turn on logging for my drop rules, I do not see the dropped packets either. If I add rules such as chain=input|forward|output src=10.5.0.0/16 action=accept (and put them first in the list), it doesn’t catch any traffic. The counters just stay 0. I would expect, based on the packet flow diagram, packets to be either in the input or forward chain (second diagram, enter at I, after routing decision packets should be in input or forward).

So what could be happening is that there is some sort of masq/…? going on that rewrites traffic coming from 10.5.0.0/16 to a wan ip, and therefor the counters do not increase. Maybe I can accept/log by mac address to see if that triggers.

P.s.: as for the second peer/policy: you’re totally right. I’ve just added these so when Mikrotik decides to fix this, I can just enable them in my config.

You mentioned in your previous posts you can properly see the return traffic in mangle pre-routing:

prerouting in:ether1-gateway out:(none), src-mac e4:48:ab:ab:ab:ab, proto ICMP (type 8, code 0), 10.5.1.14->10.0.10.2, len 84

This means the encrypted traffic is properly coming in and being decrypted.

I suggest putting these rules into your mangle:

/ip fi mang
add chain=prerout src-address=10.5.0.0/16 action=log log-prefix=prerouting
add chain=forward src-address=10.5.0.0/16 action=log log-prefix=forward
add chain=postrout src-address=10.5.0.0/16 action=log log-prefix=postrouting
add chain=input src-address=10.5.0.0/16 action=log log-prefix=input
/ip fi filt
add chain=forward src-address=10.5.0.0/16 action=log log-prefix=forward place-before=0
add chain=input src-address=10.5.0.0/16 action=log log-prefix=input place-before=0

What do the logs show?

Only a single line appears in the logs, for the prerouting chain:

prerouting prerouting: in:ether1-gateway out:(none), src-mac e4:48:c7> :ab:> ab:ab, proto ICMP (type 8, code 0), 10.5.1.14->10.0.10.2, len 84

Post your “/ip rou exp” please.

There are 2 things I can see happening:

  1. routing engine dropping packets because of no route or a blackhole route
  2. packets are arriving with TTL of 1, therefore are being dropped

I also advise sniffing the traffic (there is an action in prerouting that can do that for you) and looking at the packets directly in wireshark to analyze more.

These are my routes:

/ip route
add distance=15 gateway=[next hop wan 2] routing-mark=to-xs4all
add check-gateway=ping distance=5 gateway=[next hop wan 1]
add check-gateway=ping distance=10 gateway=[next hop wan 2]

There is also a dynamicly generated route for 10.0.10.0/24 (pref source 10.0.10.254 with gateway bridge-vlan10). I sniffed the traffic in Wireshark, TTL is 255 for the incoming packets.

Well, without getting access to the system and playing with it directly, I dont see why it doesnt work.

You can contact me at tomas[at]atris[dot]sk if you want more direct help.
Or maybe someone else can help you.

After a short screen sharing session with tomaskir, it turned out AWS relies on IPSec VTI being available when using your VPN connection with BGP instead of static routes (I hope I’m saying this correctly :slight_smile:).

After I reconfigured the VPN connection to use static routes, everything started working as expected. I just needed to add a simple rule that allows input traffic with protocol 50 from AWS IPs.

Issue resolved, hopefully this helps somebody in the future who’s seeing the same issues as I did.