Skip to contentSkip to conversation

L2TP protocol source port number changed

DISCUSSION ChungLiang 3 participants 8 messages May 22, 2003 – May 23, 2003 netfilter

lore
Share & tools
lore

ChungLiang

author
#0 lore raw

Hello,

I have tried L2TP protocol under netfiler and it seems the second
connection's source port will be changed to 1024 from 1071.

But I remember seeing some build having both connection having the
source port staying at 1071. Does anybody have any comment on this issue? What should be done at the compile time to let multiple connection use the same outgoing port? Thanks a lot.

Best regards,
ChungLiang

#1 lore raw
Quoted 4 lines

I have tried L2TP protocol under netfiler and it seems the second
connection's source port will be changed to 1024 from 1071.

From reading the RFC for L2TP, it is clear that only the first,

initial packet establishing a new tunnel, will have 1701 (not 1071, that was probably a typo?) as the _destination_ port. By answering with different ports, a LNS can switch the operational tunnel around onto other ports - and even onto a different endpoint IP address!

The RFC even alludes to problems with NAT devices (and consequently stateful tracking).

In practise, at least between ERX and Cisco systems, this appears to be avoided, and communication runs source/dest port 1701. However, by misconfiguring the Cisco LNS, I could clearly see the endpoint IP address switching. It is not unlikely that once the 2^16 session IDs of a single tunnel run out, that the Cisco will switch to an additional tunnel on nonstandard ports.

For a proper solution, somebody would need to write a conntrack helper for L2TP, to setup expectations / create RELATED connections, by analyzing the tunnel establishment. As far as I can see, such a setup would then provide a security hole enabling an attacker to permit more or less arbitrary UDP traffic, if they can hand-craft a suitable packet. So one needs to be very careful. NOTE: that's a vague feeling of mine, I have not analysed this deeply.

best regards
Patrick

author
#2 lore raw

Dear Patrick,

Thanks for your reply and I am sorry for my typo.

Maybe I did not state my question clearly enough so I will do it again.

Quoted 1 line

From what I seem on the packets, it seems that microsoft L2TP server

will only response with both source and destination port set to 1701.

And I have seen linux build which works. This means that for different
computers connecting through this linux route's netfilter to have 1701 as both source and destination port number. So it works.

Now I have build my own linux router and found out the second computer
will not have the source port staying at 1701 but changing to 1024 by the NAT. I am wondering what should I do to make this go away and stay at 1701. Thanks.

Best regards,
ChungLiang

Quoted 32 lines · Patrick Schaaf
Quoted 5 lines

I have tried L2TP protocol under netfiler and it seems the second
connection's source port will be changed to 1024 from 1071.

From reading the RFC for L2TP, it is clear that only the first,

initial packet establishing a new tunnel, will have 1701 (not 1071, that was probably a typo?) as the _destination_ port. By answering with different ports, a LNS can switch the operational tunnel around onto other ports - and even onto a different endpoint IP address!

The RFC even alludes to problems with NAT devices (and consequently stateful tracking).

In practise, at least between ERX and Cisco systems, this appears to be avoided, and communication runs source/dest port 1701. However, by misconfiguring the Cisco LNS, I could clearly see the endpoint IP address switching. It is not unlikely that once the 2^16 session IDs of a single tunnel run out, that the Cisco will switch to an additional tunnel on nonstandard ports.

For a proper solution, somebody would need to write a conntrack helper for L2TP, to setup expectations / create RELATED connections, by analyzing the tunnel establishment. As far as I can see, such a setup would then provide a security hole enabling an attacker to permit more or less arbitrary UDP traffic, if they can hand-craft a suitable packet. So one needs to be very careful. NOTE: that's a vague feeling of mine, I have not analysed this deeply.

best regards
Patrick

#3 lore raw
Quoted 4 lines

Now I have build my own linux router and found out the second computer
will not have the source port staying at 1701 but changing to 1024 by the NAT. I am wondering what should I do to make this go away and stay at 1701. Thanks.

NOW I get you. Easy: change your NAT rules suitably. All decisions about WHAT should be NATted, are made by YOUR rules.

If you don't know how to do that, please go ask the [email protected] mailing list. It is now not a _development_ question.

best regards
Patrick

author
#4 lore raw

Dear Patrick,

Yes, that could be done in the rules one way or another. What I am
wondering is that the rules are the same in both routers with same kernel version. So I am curious what compiler option or something needs to be set to achieve the result. Thanks.

Best regards,
ChungLiang

Quoted 17 lines · Patrick Schaaf
Quoted 4 lines

Now I have build my own linux router and found out the second computer
will not have the source port staying at 1701 but changing to 1024 by the NAT. I am wondering what should I do to make this go away and stay at 1701. Thanks.

NOW I get you. Easy: change your NAT rules suitably. All decisions about WHAT should be NATted, are made by YOUR rules.

If you don't know how to do that, please go ask the [email protected] mailing list. It is now not a _development_ question.

best regards
Patrick

#5 lore raw
Quoted 3 lines

Yes, that could be done in the rules one way or another. What I am
wondering is that the rules are the same in both routers with same kernel version.

Do you have both working and nonworking routers available, and you can reproduce both working and nonworking operations? Does a diff between the two rulesets really show identical rules?

If I understand you correctly, the L2TP peers (your Windows box on one end, something at the other) are one and the same in both setups? You only vary the box in between?

Can you put a HUB between the Windows box and the working vs. nonworking NAT router, and use a third box to sniff the traffic in both cases?

If that's all true, then you have a really interesting situation. I have no idea what to make of it, and I cannot imagine, both kernels being the same, that any amount of compile time options could help.

best regards
Patrick

#6 lore raw
In reply to ChungLiang

ChungLiang & all,

my previous mail was a bit wrong on the real problem with L2TP:

Seeing the initial tunnel establishment packet from LAC to LNS, one can NOT infer the IP address and port that the LNS will use for the second, acknowledging, packet. The LNS is free to choose one, it just has to answer back to the LAC and the port the LAC used in the initial packet.

Thus, no exact expectation can be set up by inspecting the initial packet; you need to capture any UDP traffic flowing back to the initial LAC IP/port, and use the source information of that captured packet to then set up the expectation.

Does the current NAT core allow such a partial expectation setup?

best regards
Patrick

#7 lore raw
Quoted 10 lines · Patrick Schaaf

ChungLiang & all,

my previous mail was a bit wrong on the real problem with L2TP:

Seeing the initial tunnel establishment packet from LAC to LNS, one can NOT infer the IP address and port that the LNS will use for the second, acknowledging, packet. The LNS is free to choose one, it just has to answer back to the LAC and the port the LAC used in the initial packet.

Quoted 6 lines

Thus, no exact expectation can be set up by inspecting the initial packet; you need to capture any UDP traffic flowing back to the initial LAC IP/port, and use the source information of that captured packet to then set up the expectation.

Does the current NAT core allow such a partial expectation setup?

you have a tuple and a mask. you can easily set up an expectation for any unknown srcip/srcport to a specific dstip/dstport.

This is what ip_conntrack_irc does for DCC, for example.

Quoted 2 lines

best regards
Patrick

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie