Community discussions

MikroTik App
 
User avatar
eugenevdm
Member Candidate
Member Candidate
Topic Author
Posts: 208
Joined: Tue Jun 01, 2004 12:23 pm
Location: Stellenbosch, South Africa
Contact:

RouterOS IPsec Client Fortigate VPN Endpoint

Thu Dec 05, 2013 9:59 am

We have a client with 6 sites using IPsec. Every now and again, possibly once a week, sometimes once a month, IPsec just stops working randomly at one of the sites.

In order to demonstrate the symptoms of the problem I have attached a diagram. On the diagram Installed SAs tab you will notice a source IP address x.x.186.50 trying to communicate with x.x.7.3 but 0 current bytes. x.x.186.50 is the client's remote Fortigate IPsec server, and x.x.7.73 is a MikroTik based IPsec endpoint. It appears data from the remote side to us is not always flowing.

Phase 1 is always established, but Phase 2 fails randomly.

We tried various things over time, such as rebooting, setting clocks, dabbling with configuration, rechecking and rechecking configuration but it appears the problem is entirely random. And sometimes random things fixes it. At one stage I had a theory that if the tunnel is initiated from their side it works, but fiddling with "Send Initial Contact" has not made any difference.

We've had many chats to the client about this but they have many more international IPsec VPNs and only our MikroTik configuration is failing.

I have also included a log file. It's difficult to say exactly where the negotiation is failing but it loops at the "received a valid R-U-THERE, ACK sent"

Log file:
echo: ipsec,debug,packet 84 bytes from x.x.7.183[500] to x.x.186.50[500]
echo: ipsec,debug,packet sockname x.x.7.183[500]
echo: ipsec,debug,packet send packet from x.x.7.183[500]
echo: ipsec,debug,packet send packet to x.x.186.50[500]
echo: ipsec,debug,packet src4 x.x.7.183[500]
echo: ipsec,debug,packet dst4 x.x.186.50[500]
echo: ipsec,debug,packet 1 times of 84 bytes message will be sent to x.x.186.50[500]
echo: ipsec,debug,packet 62dcfc38 78ca950b 119e7a34 83711b25 08100501 bc29fe11 00000054 fa115faf
echo: ipsec,debug,packet cd5023fe f8e261f5 ef8c0231 038144a1 b859c80b 456c8e1a 075f6be3 53ec3979
echo: ipsec,debug,packet 6526e5a0 7bdb1c58 e5714988 471da760 2e644cf8
echo: ipsec,debug,packet sendto Information notify.
echo: ipsec,debug,packet received a valid R-U-THERE, ACK sent
You do not have the required permissions to view the files attached to this post.
Last edited by eugenevdm on Sat Dec 07, 2013 9:02 am, edited 2 times in total.
 
User avatar
tomaskir
Trainer
Trainer
Posts: 1162
Joined: Sat Sep 24, 2011 2:32 pm
Location: Slovakia

Re: IPsec Phase Two Refuses to Start Up Intermittently

Thu Dec 05, 2013 12:27 pm

Make sure the IPSec responder has both passive=yes and send-initial-contact=no set.

That should solve your problems.
 
User avatar
eugenevdm
Member Candidate
Member Candidate
Topic Author
Posts: 208
Joined: Tue Jun 01, 2004 12:23 pm
Location: Stellenbosch, South Africa
Contact:

Re: RouterOS IPsec Client Fortigate VPN Endpoint

Sat Dec 07, 2013 8:28 am

EDIT:

I changed the title of this post from "phase 2 intermittently refuses to start" to a more generic title because it appears actually Phase 2 is starting. However, traffic is not flowing from the remote endpoint to the local router as described in my first post.

We received additional information from the client that their Fortigate log shows this
Received ESP packet with unknown SPI.
Fortigate has an article in their knowledgebase explaining that this could be because the SPIs don't agree. http://kb.fortinet.com/kb/microsites/mi ... alId=11654

The workaround appears to be enabling dead peer detection on both sides, but we cannot do this, only on our side. The certainly seems plausible becauseI can see these constant "sendto information notify" messages.

Our situation is greatly compounded that 5 other sites are working and that the client's firewall is under change control. The setup also always worked for many years, so they claim it cannot be a configuration error on their side.
Make sure the IPSec responder has both passive=yes and send-initial-contact=no set.
I looked up some Fortigate documentation and I cannot find a passive setting nor send initial contact.
You do not have the required permissions to view the files attached to this post.
 
User avatar
tomaskir
Trainer
Trainer
Posts: 1162
Joined: Sat Sep 24, 2011 2:32 pm
Location: Slovakia

Re: RouterOS IPsec Client Fortigate VPN Endpoint

Sat Dec 07, 2013 12:29 pm

Which device is the initiator and which device is the responder?
 
User avatar
payday
Member Candidate
Member Candidate
Posts: 233
Joined: Thu Aug 16, 2012 11:05 pm

Re: RouterOS IPsec Client Fortigate VPN Endpoint

Sat Dec 07, 2013 12:58 pm

What ROS version are your MikroTiks running?
 
andriys
Forum Guru
Forum Guru
Posts: 1546
Joined: Thu Nov 24, 2011 1:59 pm
Location: Kharkiv, Ukraine

Re: RouterOS IPsec Client Fortigate VPN Endpoint

Sun Dec 08, 2013 11:28 am

The workaround appears to be enabling dead peer detection on both sides, but we cannot do this, only on our side.
DPD setting is not negotiable, so you can safely turn it on on your side only (with whatever DPD interval you feel appropriate) without risking to break the either phase negotiation. And chances are it is enabled on the other side actually.
 
User avatar
eugenevdm
Member Candidate
Member Candidate
Topic Author
Posts: 208
Joined: Tue Jun 01, 2004 12:23 pm
Location: Stellenbosch, South Africa
Contact:

Re: RouterOS IPsec Client Fortigate VPN Endpoint

Mon Dec 09, 2013 4:19 pm

Which device is the initiator and which device is the responder?
If send initial contact is any indicator the MikroTik is the initiator. The client first told us their Fortigate can be both initiator and responder but when we questioned them again they said there is no such setting.
What ROS version are your MikroTiks running?
We were on v6.5 but tried downgrading to v5.26. We then upgraded to v6.7 so currently it's v6.7.
DPD setting is not negotiable, so you can safely turn it on on your side only (with whatever DPD interval you feel appropriate) without risking to break the either phase negotiation. And chances are it is enabled on the other side actually.
Thanks. We've experimented with DPD trying various values. It's on both the remote side (Fortigate) and the near side (MikroTik).

I have pasted their config for your perusal. I have also started a bounty on Server Fault because we are about to loose this client.
http://serverfault.com/questions/559820 ... nknown-spi
You do not have the required permissions to view the files attached to this post.
 
andriys
Forum Guru
Forum Guru
Posts: 1546
Joined: Thu Nov 24, 2011 1:59 pm
Location: Kharkiv, Ukraine

Re: RouterOS IPsec Client Fortigate VPN Endpoint

Mon Dec 09, 2013 5:21 pm

First thing to note, phase1 lifetime settings do not match. You have 1day while they have 8 hours (28800 second). Make them match. Also make sure everything else matches as well. Set proposal check setting to strict, it will ensure everything matches (otherwise tunnel will stop working).
 
User avatar
eugenevdm
Member Candidate
Member Candidate
Topic Author
Posts: 208
Joined: Tue Jun 01, 2004 12:23 pm
Location: Stellenbosch, South Africa
Contact:

Re: RouterOS IPsec Client Fortigate VPN Endpoint

Wed Dec 11, 2013 2:47 pm

First thing to note, phase1 lifetime settings do not match. You have 1day while they have 8 hours (28800 second). Make them match. Also make sure everything else matches as well. Set proposal check setting to strict, it will ensure everything matches (otherwise tunnel will stop working).
Thank you. We have tried setting it to 8 hours as well but at this point of the frustration the entry was the MikroTik default of 24 hours.

So here is the solution, which again, is completely random and does not make sense. I have attached another diagram inline to show you what happened.

We fixed it by:

1. Turning off PPPoE at client.
2. Installing completely new router (Router B) and tested at Border. It worked at Border.
3. Switching off new router B at border.

AND THEN, WITHOUT MAKING A SINGLE CHANGE, the client's end-point Router A started working. So just adding a duplicate router at the border and taking this router offline again made the original router work.


So add this fix to the list of things we've done:

1. Reboot. That worked once.
2. Create new tunnel with new IP. That worked once but only once. After changing IP back client endpoint came live again.
3. Change time servers.
4. Fiddle with every possible setting.
5. Wait. Once, after a day, it just came right. This time, even after days, nothing came right.

So I postulate that there is an incompatibility on either Fortigate or MikroTik side which only happens at very random situations. The only things we haven't been able to try is upgrade firmware on Fortigate. Maybe there is hidden corrupt configuration value or timing issue invisible to configurer.

I further speculate that the issue is caused by random timing issues causing SPI mismatch. That justs happens randomly. I'll add to this post when it happens again.
You do not have the required permissions to view the files attached to this post.