Open Climax777 opened 9 years ago
Pieter Jordaan notifications@github.com wrote:
I want to ask how to configure/use xl2tpd with strongswan in the scenario that there are multiple clients connecting from behind the same NAT.
> What happens now is that when multiple units connect, one or more of
> them stop working and time out. Packet traces show that no packets come
> in after a while.
Yes, so with L2TP, there are transport mode IPsec tunnels, and they occur from the IP address of the machine behind the NAT. So they all come from "192.168.1.101" (the first IP that a linksys router usually gives out), and they conflict.
The answer is that you have to have kernel code that can sort it out (KLIPS), or you can now do some netfilter magic to make it happen.
I suggest that you look into what libreswan documents today for the netfilter magic.
> I use mark=%unique with strongswan and the rules are being applied. How
> can I configure x2ltpd to use these marks to forward to the correct
> NATed client?
> Currently all of them connect to xl2tpd with the same public ip with
> source port 1701.
I don't know what mark=%unique does.
] Never tell me the odds! | ipv6 mesh networks [ ] Michael Richardson, Sandelman Software Works | network architect [ ] mcr@sandelman.ca http://www.sandelman.ca/ | ruby on rails [
The Ipsec part is sorted out by the mark=%unique settings. This enables special netfilter entries to be made that fixes the problem. https://wiki.strongswan.org/projects/strongswan/wiki/Connmark
However I'm not sure if it just works with xl2tp or if some special sauce is needed, because after decapsulation the source ip is the public ip of the nat with 1701 as source port.
So I'm not sure where packets sent to this address will go because all natted clients will have that same ip/port except for the netfilter marks.
Here is an excerpt from the iptables after connmark usage:
*mangle :PREROUTING ACCEPT [1765:398811] :INPUT ACCEPT [1485:299604] :FORWARD ACCEPT [278:98818] :OUTPUT ACCEPT [1406:319822] :POSTROUTING ACCEPT [1684:418640] -A PREROUTING -s 41.13.28.224/32 -d 172.30.0.143/32 -p udp -m udp --sport 54696 --dport 4500 -j MARK --set-xmark 0x1dd/0xffffffff -A PREROUTING -s 197.77.18.170/32 -d 172.30.0.143/32 -p udp -m udp --sport 10518 --dport 4500 -j MARK --set-xmark 0x1dc/0xffffffff -A INPUT -s 41.13.28.224/32 -d 172.30.0.143/32 -m policy --dir in --pol ipsec --spi 0x81329dc3 -j CONNMARK --set-xmark 0x1dd/0xffffffff -A INPUT -s 197.77.18.170/32 -d 172.30.0.143/32 -m policy --dir in --pol ipsec --spi 0x489ba5cf -j CONNMARK --set-xmark 0x1dc/0xffffffff -A OUTPUT -s 172.30.0.143/32 -d 41.13.28.224/32 -j CONNMARK --restore-mark --nfmask 0xffffffff --ctmask 0xffffffff -A OUTPUT -s 172.30.0.143/32 -d 197.77.18.170/32 -j CONNMARK --restore-mark --nfmask 0xffffffff --ctmask 0xffffffff
Hi,
I've managed to make this working. There's a few issues on the strongswan side, which I have sorted out (see issues 1212, 1229, 1230 on the strongswan tracker) but xl2tpd also needs to support it. Fortunately unlike SAref, no kernel patching is needed.
What is needed is setting up NFQUEUE and parsing control packets inside xl2tpd so that netfilter mark is matched to a specific tunnel. After correct mark is extracted from the incoming packets, the same mark is used on replies (using SO_MARK on the socket).
Here's my WIP patch that sets up NFQUEUE handling and sending packets with proper mark. You also need to add iptables rule that will redirect l2tp control packets into proper NFQUEUE:
iptables -t mangle -A INPUT -p udp -m l2tp --type control --dport 1701 -m policy --strict --dir in --pol ipsec --proto esp -j NFQUEUE --queue-num 0 --queue-bypass
(l2tp match is in the kernel, but it's not in iptables - I had to patch that separately...xl2tpd could be made to directly insert rule into the kernel in which case iptables would not have to be patched; additionally a config option for setting a NFQUEUE number could be set ;-) )
Is there any interest in this? I'm willing to work on the code further...but I don't know that much about l2tp protocol.
There's still some potential problems I see:
@shussain Did you have a chance to review this...it would be great if xl2tpd would support this setup :-)
@gulikoza I am interested in integrating this but right now I am a bit busy. I am hoping to make time later this week to further look at the commit.
@gulikoza Is 999-nfqueue.txt the latest version of your code?
I think it could be integrated as a configuration or possibly preproc. That way, the performance implications do not impact regular users. Would you be able to do that?
That is the latest version, more or less...I think I've updated it for 1.3.9 recently, but just minor changes because of differences in existing code.
I don't think there should be any performance implications. If nfqueue is not set (for which a config option should be added), the hook is not set in init_network() and no other code runs (apart for 1 'if()' in udp_xmit). The performance implications I mentioned are when nfqueue is active (because each control packet in then queued by iptables and processed by nfq_q_handle()).
I don't really like parsing control packets for tunel_id in the nfq_q_handle()...is there any better way to do it? :)
I'll prepare some changes and do a PR.
We are using strongSwan version 5.5.3 along with xl2tpd version 1.3.10 as an L2TP server. We are using the strongSwan connmark plugin, so it now handles multiple windows clients behind the same NAT IP from an IPSec point of view. But even with the 999-nfqueue patch applied to xl2tpd I can not connect 2 L2TP clients and have them both stay up. Behavior varies, but usually the second one attempting to connect will hang 'Verifying user and password', and eventually the xl2tpd on the server will report 'Maximum retries exceeded for tunnel...' and will terminate the pppd. Sometimes they will both connect for a period of time but one or both will eventually get disconnected. So I am curious what the status of this strongSwan integration issue (this issue and #123) is, and would appreciate any suggestions.
@bradjohn We don't specifically test for StrongSwan integration.
@bradjohn Did you setup the NFQUEUE iptables rule? Although I have experienced intermittent disconnects as well...haven't had the time yet to diagnose the issue that's why I haven't posted a PR yet...
@gulikoza yes, thanks. I see now I am missing some things. I have no kernel xt_l2tp module, and I'm not sure of the iptables l2tp patch I'm using, found here: https://patchwork.ozlabs.org/patch/307177/
So I have some work to do before being able to fully use the NFQUEUE
Hi All
I Have been reading this thread with great interest as I am in need of the nfqeueue patch. I have a fully running IPSEC/L2TP server running using Libreswan as the IPSEC server but I've never had to patch anything like this before would someone please be able to tell me how i can patch this
Hi @gulikoza @shussain , Thank you for this xl2tpd patch, and I have tested it in Linux-3.10.0-514, it works very good. 👍 But when I tested it in CentOS6.9(Linux-2.6.32-696), it failed to establish l2tp connection while ipsec is established successfully. xl2tpd receive packet SCCRQ, and send back packet SCCRP, but l2tp SCCRP packet is sent directly to client, and not in ESP, that is to say the first l2tp packet form server to client is not go through XFRM. So my question is :
Thank you very much.
Hi,
If the packet is not marked, then the default strongswan CONNMARK rule should be able to match and mark it appropriately. If you check the mangle table, the connmark strongswan module inserts a bunch of rules, one of them should be:
Chain OUTPUT (policy ACCEPT 99130 packets, 32M bytes)
pkts bytes target prot opt in out source destination
0 0 CONNMARK all -- * * xx.xx.xx.xx xx.xx.xx.xx mark match 0x0 CONNMARK restore
So the idea is that the first packet is handled by these default rules until the packets can be explicitly marked in xl2tpd. I don't think the patch should be kernel specific. What strongswan version do you use?
Hi @gulikoza @shussain , It looks like the patch doesn't work with actual packages. My VPS with CentOS 7 has the following installed (IPSec PSK + L2TP):
./configure --prefix=/usr --sysconfdir=/etc --enable-connmark
iptables -t mangle -A INPUT -p udp -m l2tp --type control --dport 1701 -m policy --strict --dir in --pol ipsec --proto esp -j NFQUEUE --queue-num 0 --queue-bypass
When I connect one windows computer and an unlimited number of ios devices at the same time, VPN works perfectly on all devices. When connecting a second windows computer, xl2tpd gives a lot of errors write_packet: tty is not open yet
and resets the connection of the first computer.
I have been trying to solve this problem for several days now. Help me please. Maybe needed a new version of the xl2tpd patch or I made a mistake in the config?
Below are my configs and outputs when connecting two windows computers. X.X.X.X - IP of VPS Y.Y.Y.Y - IP of my home router
There was an additional issue with disconnects after some time that I've discovered and tried to fix, but the whole setup was not reliable over a large amount of clients.
I've migrated to OpenVPN long time ago....
Please tell me where the following configuration files corresponding to the connmark plug-in need to be configured. Help me see that I can't start strongswan now that I'm configured
`connections {
transport-connmark {
children {
transport-connmark {
mode = transport
mark = %unique
#...
}
}
}`
Sorry to call less}
Hello
I want to ask how to configure/use xl2tpd with strongswan in the scenario that there are multiple clients connecting from behind the same NAT.
What happens now is that when multiple units connect, one or more of them stop working and time out. Packet traces show that no packets come in after a while.
I use
mark=%unique
with strongswan and the rules are being applied. How can I configure x2ltpd to use these marks to forward to the correct NATed client?Currently all of them connect to xl2tpd with the same public ip with source port 1701.
Can I use some mangling rule or something to mangle the source ip/port? Can I use SAref or connmark directly in xl2tpd?
Currently the strongswan phase is working perfectly, I just can't get the second phase (L2TP) stable.