Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp159850lqh; Mon, 6 May 2024 14:54:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX2ne1y5Pkg3XSFCMXguYpxQm1Uko7G9dPIaLLM2KN7zCNYO9ntNMZtx/goM+agNqiajEtGsS65J+LoC/JGVr4Q0bPwDcXQOTHIkYbNjw== X-Google-Smtp-Source: AGHT+IFoCzBoBAwQds23jMA6qqG918MBBvI67UzWekVnWja+5bRDvMQ9OEmTvEoKECCjz1x9fVE7 X-Received: by 2002:a17:907:3f18:b0:a59:cbff:a04 with SMTP id hq24-20020a1709073f1800b00a59cbff0a04mr3687153ejc.7.1715032476107; Mon, 06 May 2024 14:54:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715032476; cv=pass; d=google.com; s=arc-20160816; b=R1DZBtWjJGxZToujK7mj376SivkQrsLH3rymyjKaI4INOj4IGbkksvDYlF3k9/IMUr NHDmw92oy3SjOR9Vf0mzea2UAzzNeHCsGZJ4XaO6gwlpshLxJ9/LQ4JtouLVUUq2xkiT 5RKFOqrgSCXw59lN4k83u59avz4R8AkCxu53A763R6Ust5BYGkEvXerprCAwVPHeULpY u5zPQfcTrtIP+WzpEK3FEH4L+uuB3xVdwqK/I+ouv5f0M1xqSaAuHG3zwM9RZBmlC1GK t9kHXpQSuHYHU4AHz//iEnTtXq3hGRP+1MLuTbLTNYB+7lOnZ8qKNnrINXTRtrkgAXmf 1tGw== 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=fF2sEd/tw4pc7vIs2IIdH4TItuV/rNnSZgKd8crECXM=; fh=ssAZqjvCZTsf+h4KEdoknixWYKzgtEBEaDMVT3PgLLE=; b=FV42qcfEFYLoac6uu0nbbVJn2XkMkGvtgwvoEKf3xMgfhP2EvF/AFN4TWr6D8K7lH3 vGoJ2sEU2VfqrKaZ2ATRNv+xpSxzOEmDWPsmGmFqIdIsWRPv4EjCZejWiLh3wIgHkijw 0zOS3hcog1LElZnzynNxLemiAeejJg0CrX+xbc5WZfbsILHwiNFywx05OHQxdvZUDz9Z TU94KhU97Ex0jOr4zlg3/p6Qm81H8BvjkAf14ThWbua62KdTAW3X9EgtV+Y/UdKiyAOk KYatMx4IFy9RXfGzi8CkOfmNwMM5r3sKJQ/cQXPvcUv9DzsaDDsuwc7T1YeE0W5TAwI4 YfBQ==; 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-170454-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170454-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ay1-20020a170906d28100b00a55b2e95067si5397372ejb.58.2024.05.06.14.54.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 14:54:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170454-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-170454-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170454-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D17361F2309C for ; Mon, 6 May 2024 21:54:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36D7215E1FF; Mon, 6 May 2024 21:53:41 +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 B8EAF15D5B2; Mon, 6 May 2024 21:53:38 +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=1715032420; cv=none; b=t3NG3KGvkiAMq/7NHMQTIkc/+GU2HjWzaDbUDxa77cL3NhDCj9xJlkVBpQX5lPv2gId1Zt51wzr5Rf9mwM+aO9cqhKA/KcjiWEdS4Hc+/LlXmN1mVOqbTUOWB5yzmHLeUiSKNbToeFPtOaJIjRY7wO1lOtdD541kfV4SCAaSUe0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715032420; c=relaxed/simple; bh=5xqcT/MJ1k3KNGL3OEgnotxtEh49wE6sTfZDKNY7miQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=g142zy9gVJP0d6dwyFScVADRC3u9Yi2IvmdDBJPmWczfUlqT23wk09W9rO+I8aZeO26wvwO1t0wokMyEORDcY5TbaEB6MJVYrQ77hlt2isy1fMMmeuULql7tphiSAen6xsGf/I9CvmBAEElOMOWLpUZOwK8zQKb7kaEbJLuMKMU= 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 BE3D9A02C2; Mon, 6 May 2024 23:53:36 +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 U6r1Mwcz0gl0; Mon, 6 May 2024 23:53:36 +0200 (CEST) Received: from begin.home (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 9CB1EA02A3; Mon, 6 May 2024 23:53:36 +0200 (CEST) Received: from samy by begin.home with local (Exim 4.97) (envelope-from ) id 1s46HA-00000006AQP-0N5S; Mon, 06 May 2024 23:53:36 +0200 From: Samuel Thibault To: tparkin@katalix.com, Eric Dumazet , Jakub Kicinski , Paolo Abeni , James Chapman Cc: Samuel Thibault , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCHv2] l2tp: Support several sockets with same IP/port quadruple Date: Mon, 6 May 2024 23:53:35 +0200 Message-ID: <20240506215336.1470009-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 --- Diff from v1: - do not check for tunnel->l2tp_net != NULL, it cannot not be - check for tunnel version 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..2ab45e3f48bf 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) { + /* 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 || alt_tunnel->version != L2TP_HDR_VER_2) + 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