Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1464755lqm; Thu, 2 May 2024 16:20:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUWQGYRF3gymnM+OgriPo9Rzguxi5rNtOTUMf9wo63Xewq7Y8ogUbvQ15K1ejJyC1O8lKbkHzAVKYtgTeRrhwTK7VNNf5JElasXouwZBw== X-Google-Smtp-Source: AGHT+IGK/G+noE46nRiDx/hSiW4vAtuVVlq3117YS6ub1Di2KZVs6tRslkZfNECKPaUm1KYJQov4 X-Received: by 2002:a05:6a20:9187:b0:1a7:5e8f:8707 with SMTP id v7-20020a056a20918700b001a75e8f8707mr1557804pzd.26.1714692040700; Thu, 02 May 2024 16:20:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714692040; cv=pass; d=google.com; s=arc-20160816; b=SkYmu7zEwBppbwv56yDEdMR9XAf3vVu3W+lQpyhDjCeeqSFmIfwWGWpVh6n/e1+uvf aET6Mv41JNWNSX4MM94HzcVW/BITWYFi2GeNRpJuWiBMFhT5Y0Q93y7OVwouShxEizOw F5yfOb7PWSXccONHolu5cj1iIJ8tlA5qFaqgKqM+veYXxidGfYCvJtur91Zn+3aVThOJ Wn4qCKf6+c6NmzV75ym+EV8mAlyqmi8pPlvOeJYo+MfFzXV94oNSS098bCF0oBXjsYGe dYz68Kntq8ti66fz+lZeHZ5b7eyivL+1vVzuLzP6voSxbiQcuj/SeVA9Jg6t78ioNzTx wRpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=Bdsy35gqbTOmODBEVQYlXWRM5DkW5yrHAJlSlklOHvQ=; fh=FqGWMM1v22+ST7vuXlkbTKbQKoXXCZAbgk1nbeEpLbs=; b=HzGYIsSfrRcOM8LqLkARlb7cY7FPhx9yx5EuS7lDivBwSjcXJkvi2/igrZu3On8RMR 5fzsUYLjsSiCByEcYFXHfCVshT610VTxu2l28jkXmA4dBv2qk7hsx5N0KAn38Pd0k2S+ p2GJ/O8r0zX9t4vRfAvr4ldQe4yhaSEeSOU0VP6nx7mE48PDa+pT3YwKexWeZclN5uSd SsbTPBKYeV72XsXK04yYDYdDOjb0x4D21G2y8rVwK+dxFFIpx5d+Zu7v5XdumGa8Ck/M w19wLkZ7/M2rsYgFhKAk/WIeCPOA5dBGJDjYT4Z/EelPlHARQhwHMUPVaDaajznYC/Ph ryAA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=bounce.ens-lyon.org); spf=pass (google.com: domain of linux-kernel+bounces-167050-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167050-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y7-20020a056a00180700b006ecf85e6addsi2005460pfa.14.2024.05.02.16.20.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 16:20:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167050-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=bounce.ens-lyon.org); spf=pass (google.com: domain of linux-kernel+bounces-167050-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167050-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 511D528524F for ; Thu, 2 May 2024 23:20:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 31EB6200C7; Thu, 2 May 2024 23:20:30 +0000 (UTC) Received: from sonata.ens-lyon.org (domu-toccata.ens-lyon.fr [140.77.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4EDE57C91; Thu, 2 May 2024 23:20:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.77.166.138 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714692029; cv=none; b=f4DblNArMWx6Lt60PsB1GO3ndxM2/evMozKR4C8ertqABezdOGFQNuGiHzdgfI1EYLyAaMlwSGNaR/kPOySORJW9gjwUh+uEj4FVAjN5RLPZSaVAt+d0PZAQbp8bp9ErXNDni2gHW0WUoGaLDaVSc3EnNQNb3isU3jHwH2VaHFY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714692029; c=relaxed/simple; bh=qSzC0oiYTVV82GdoLnMNIv8MQ1QTk/aV9rcuITMmS/Y=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=SIXPU1LY8lQAITeSOKn3nGw5vPBLVEoZ8d09Zjb1zDXe0GXiNs9uXnodTgXY6MSDgy90XuqIm+CvYxUaiwggbjcSmTmgaFNxfmDUASdIw1R//Xg2MSE1oNoegcU4A3sVM7X12PutOFwwDILnTCFk4nznxoL2igoXC2Oi9sVwF0M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org; arc=none smtp.client-ip=140.77.166.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id F1358A0361; Fri, 3 May 2024 01:14:19 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id plRL_BNJxDKg; Fri, 3 May 2024 01:14:19 +0200 (CEST) Received: from begin (aamiens-653-1-111-57.w83-192.abo.wanadoo.fr [83.192.234.57]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id C8A42A0360; Fri, 3 May 2024 01:14:19 +0200 (CEST) Received: from samy by begin with local (Exim 4.97) (envelope-from ) id 1s2fd5-0000000CJFV-15bS; Fri, 03 May 2024 01:14:19 +0200 From: Samuel Thibault To: Tom Parkin , Eric Dumazet , Jakub Kicinski , Paolo Abeni , James Chapman Cc: Samuel Thibault , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH] l2tp: Support several sockets with same IP/port quadruple Date: Fri, 3 May 2024 01:14:18 +0200 Message-ID: <20240502231418.2933925-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Some l2tp providers will use 1701 as origin port and open several tunnels for the same origin and target. On the Linux side, this may mean opening several sockets, but then trafic will go to only one of them, losing the trafic for the tunnel of the other socket (or leaving it up to userland, consuming a lot of cpu%). This can also happen when the l2tp provider uses a cluster, and load-balancing happens to migrate from one origin IP to another one, for which a socket was already established. Managing reassigning tunnels from one socket to another would be very hairy for userland. Lastly, as documented in l2tpconfig(1), as client it may be necessary to use 1701 as origin port for odd firewalls reasons, which could prevent from establishing several tunnels to a l2tp server, for the same reason: trafic would get only on one of the two sockets. With the V2 protocol it is however easy to route trafic to the proper tunnel, by looking up the tunnel number in the network namespace. This fixes the three cases altogether. Signed-off-by: Samuel Thibault --- net/l2tp/l2tp_core.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index 8d21ff25f160..128f1146c135 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -794,6 +794,7 @@ static void l2tp_session_queue_purge(struct l2tp_session *session) static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb) { struct l2tp_session *session = NULL; + struct l2tp_tunnel *orig_tunnel = tunnel; unsigned char *ptr, *optr; u16 hdrflags; u32 tunnel_id, session_id; @@ -845,6 +846,20 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb) /* Extract tunnel and session ID */ tunnel_id = ntohs(*(__be16 *)ptr); ptr += 2; + + if (tunnel_id != tunnel->tunnel_id && tunnel->l2tp_net) { + /* We are receiving trafic for another tunnel, probably + * because we have several tunnels between the same + * IP/port quadruple, look it up. + */ + struct l2tp_tunnel *alt_tunnel; + + alt_tunnel = l2tp_tunnel_get(tunnel->l2tp_net, tunnel_id); + if (!alt_tunnel) + goto pass; + tunnel = alt_tunnel; + } + session_id = ntohs(*(__be16 *)ptr); ptr += 2; } else { @@ -875,6 +890,9 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb) l2tp_recv_common(session, skb, ptr, optr, hdrflags, length); l2tp_session_dec_refcount(session); + if (tunnel != orig_tunnel) + l2tp_tunnel_dec_refcount(tunnel); + return 0; invalid: @@ -884,6 +902,9 @@ static int l2tp_udp_recv_core(struct l2tp_tunnel *tunnel, struct sk_buff *skb) /* Put UDP header back */ __skb_push(skb, sizeof(struct udphdr)); + if (tunnel != orig_tunnel) + l2tp_tunnel_dec_refcount(tunnel); + return 1; } -- 2.43.0