Skip to content

Commit 3647980

Browse files
sthibaulkuba-moo
authored andcommitted
l2tp: Support different protocol versions with same IP/port quadruple
628bc3e ("l2tp: Support several sockets with same IP/port quadruple") added support for several L2TPv2 tunnels using the same IP/port quadruple, but if an L2TPv3 socket exists it could eat all the trafic. We thus have to first use the version from the packet to get the proper tunnel, and only then check that the version matches. Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org> Reviewed-by: James Chapman <jchapman@katalix.com> Link: https://lore.kernel.org/r/20240509205812.4063198-1-samuel.thibault@ens-lyon.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent ec8c257 commit 3647980

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

net/l2tp/l2tp_core.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -820,13 +820,8 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb)
820820
/* Get L2TP header flags */
821821
hdrflags = ntohs(*(__be16 *)ptr);
822822

823-
/* Check protocol version */
823+
/* Get protocol version */
824824
version = hdrflags & L2TP_HDR_VER_MASK;
825-
if (version != tunnel->version) {
826-
pr_debug_ratelimited("%s: recv protocol version mismatch: got %d expected %d\n",
827-
tunnel->name, version, tunnel->version);
828-
goto invalid;
829-
}
830825

831826
/* Get length of L2TP packet */
832827
length = skb->len;
@@ -838,7 +833,7 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb)
838833
/* Skip flags */
839834
ptr += 2;
840835

841-
if (tunnel->version == L2TP_HDR_VER_2) {
836+
if (version == L2TP_HDR_VER_2) {
842837
/* If length is present, skip it */
843838
if (hdrflags & L2TP_HDRFLAG_L)
844839
ptr += 2;
@@ -855,7 +850,7 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb)
855850
struct l2tp_tunnel *alt_tunnel;
856851

857852
alt_tunnel = l2tp_tunnel_get(tunnel->l2tp_net, tunnel_id);
858-
if (!alt_tunnel || alt_tunnel->version != L2TP_HDR_VER_2)
853+
if (!alt_tunnel)
859854
goto pass;
860855
tunnel = alt_tunnel;
861856
}
@@ -869,6 +864,13 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb)
869864
ptr += 4;
870865
}
871866

867+
/* Check protocol version */
868+
if (version != tunnel->version) {
869+
pr_debug_ratelimited("%s: recv protocol version mismatch: got %d expected %d\n",
870+
tunnel->name, version, tunnel->version);
871+
goto invalid;
872+
}
873+
872874
/* Find the session context */
873875
session = l2tp_tunnel_get_session(tunnel, session_id);
874876
if (!session || !session->recv_skb) {

0 commit comments

Comments
 (0)