-
Notifications
You must be signed in to change notification settings - Fork 759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IPSec faulty routing with multiple phase 2 tunnels and NAT #2173
Comments
|
Support for manually defined spd entries was added by @AdSchellevis in 814d18a for #440 |
|
@AdSchellevis apparently as you discussed in this comment in the #440 issue you thought about doing it with unique:<id> but got convinced that it wasn't necessary and didn't do it. Something in my setup apparently breaks the assumption that using require is enough :( |
|
@joakim666 yes, that was indeed the case. As far as I know you can't control the internal spd's, which makes it quite hard to setup a policy which will work guaranteed (sensitive to race conditions). Eventually during our testing it didn't seem necessary to bind to specific tunnels. What does your setup look like? what nets are you trying to route? |
|
Basically it's local lan NAT:ed behind single IP to two remote subnets. So nothing that much out of the ordinary.
Using IKEv2, one Phase 1 entry with multiple Phase 2 entries. I replaced the public ips below. I hope it's still understandable: a.b.c.d = remote peer public ip 192.168.122.0/24 = local lan added under Manual SPD entries in GUI Output of setkey -DP: Given the above, all traffic will go through the If I remove the SPD entries OPNsense added (that uses require) and add new ones using either |
|
At the moment I don't have time to build a test setup, not sure if the current construction can work for this. If traffic from 192.168.122.0/24 -> 172.16.0.0/16 doesn't use the second tunnel [4] we might need to bind it explicit, although that will require more complex logic to keep it in sync. |
|
For now I removed the added 'Manual SPD entries' through the GUI and add them manually (using unique to point to the correct p2-tunnel) with a script through ssh. But that's not an optimal solution. |
|
@joakim666 Excuse me if I'm wrong, but doesn't this sound similar to #1773? |
|
@fraenki sorry for the late reply but it does indeed sound similar, but in your described case it's the ip-address that gets wrong and for me it's the require vs unique:x part. But maybe the core issue is the same? |
|
@joakim666 can you send me the script you use with SSH? I'd like to work on it to get it to core or first as a plugin. |
|
@mimugmail I'm afraid the script got lost when we changed to terminate the IPSec tunnels in strongswan directly and stopped using OPNsense for this. But if I remember correctly I executed the script every few minutes from cron and it basically just checked which ipsec tunnels were up and for each tunnel if it has SPD entries with require remove those and add new SPD entries using unique instead. |
|
hi @mimugmail I have just run into same problem, and for me I wrote a script to help me This solves my problem, it is not generic one. |
|
Wow .. it seems this one fixes it. Got a confirmation of affected customer that adding NAT IP to WAN as an Alias works (but only for outgoing nat and not BINAT). |
|
@joakim666 @mikipn this is now working out of the box starting with 21.1 RC1 .. maybe you have time to test :) |
|
Please update the documentation at https://docs.opnsense.org/manual/how-tos/ipsec-s2s-binat.html: the note at the bottom still mentions a limitation. |
|
@cluck you know contributing is also an option ? (https://github.com/opnsense/docs) |
|
I already contributed what I can herein. I haven't contributed the fix nor do I have studied the original use case, so I don't feel competent to revise the documentation. But I feel competent enough to notice the discrepancy. Kind instructions on various options for contributing to the quality of the documentation would be best placed in the documentation footer itself. |
When tunneling multiple subnets through an IPSec tunnel I have a problem that all traffic gets routed through one of the p2-tunnels.
I can see the bytes out counter increase on one of the p2-tunnels and by tcpdumping on the WAN-interface I can see that the ESP-packets all go out with the same SPI-identifier no matter the destination subnet.
After lots of troubleshooting I tracked it down to how the manually added SPD entries in the GUI are added to the kernel. As I'm using NAT to get all outbound traffic behind one IP no matter the subnet I enter the same LAN subnet as 'Manual SPD entries' for all phase 2 tunnels.
In ipsec.inc these manually added SPD entries are added to the kernel like this:
"spdadd -%s %s %s any -P out ipsec %s/tunnel/%s-%s/require;",But for me %s/tunnel/%s-%s/require isn't exact enough and will apparently match all (or rather just the last) of the outbound SPD entries added by Strongswan.
I find the man-page for setkey a bit unclear:
But I do know that if I remove the SPD entries added by OPNsense and add new ones using the unique level like this:
spdadd -%s %s %s any -P out ipsec %s/tunnel/%s-%s/unique:<id of matching outbound Strongswan added SPD for given destination subnet>;it works and the traffic to the different destination subnets get routed through the correct p2-tunnel.
However, I'm not sure how to fix this correctly in OPNsense.
I can help out with a patch for this problem, but given that I don't know the thoughts and ideas behind the current implementation I feel I need some guidance!
The text was updated successfully, but these errors were encountered: