From patchwork Thu Jun 8 13:20:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13272334 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 9A566947B for ; Thu, 8 Jun 2023 13:21:14 +0000 (UTC) Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E57E7210C for ; Thu, 8 Jun 2023 06:21:12 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3f6d7abe934so3960075e9.2 for ; Thu, 08 Jun 2023 06:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1686230471; x=1688822471; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=KhaoeTZksIn80amAPN23tQL1E6Mg1h/yTJF6X95xsdA=; b=z84ZpGUZD+SoR2l0mm/WX8KCJV1wk0b43QiO/RkCyFd50gka6DenhY2SkjvX95BTJ9 /WyuVZmLaiSm34TCH17AS4AdNWMWEhIgVpnTw3ltoTeI+DHO39BvqbLMuY8EMAKmaaky paobvax5r5jrirXch9eXe4rxOg6x1K7d1m7YWmfOyOIKgdIP/+oA0TJwE6jWovzkkdX7 pVa5BdoLcV3ix17y79ttEusCbrZeIeKth4TcZWw9Ym0SYizKWoSceJjhG2R8KGTBdBV9 ac6EU6WW0/Vz1BSFZCj07vHK+qp4iiV8epk++pot0fCMcPU1X/gc2fzHlbOJV7vXBnQg UD0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686230471; x=1688822471; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KhaoeTZksIn80amAPN23tQL1E6Mg1h/yTJF6X95xsdA=; b=PDa0x1NRlid9aAU0aRhZ1uK5pLsNV8Wcxgj9FbTLWgAoZ8NghoVhka7uK4vrhVjJ/A AwXmrJ+cd2YUv+b/MtfsaPEjYGh4iblDjY9zWrgKhadc/nCvD73ElhqaNKJ7w+BqLsvN RzzhZKdJbNJS06WZbT31Lw+aIVI/BP3L//ncAJXdeFBlyR2VZ4VkYHJ9UGoN7/IJw7xK uPdo0OEtIWmMWqfvxl2cnz6rC03oElFhbK+nJhfs4g8rRNMejwhPvOaifU20lgc0kpnz s5NJdqOuTp3+ZYIHG71o+ctrEvRg8qhF0BI3RQaaeZWUCDnfUGvlZWm0gLxO+M4yRcDa lhiA== X-Gm-Message-State: AC+VfDwvm3gyLF7p/b5z273CmYgy9vKpFHyWtUWlRzHA3gY+Vd13aS15 PJc50Courwu/skVVciR5N6+0lA== X-Google-Smtp-Source: ACHHUZ72dlqjioyOZFlnptxRBoQkTm7II3R7lfsutEe7KQL1uH+xB/XrKBPxFMYJ5TYjmxpPVHRPYw== X-Received: by 2002:a05:600c:2148:b0:3f6:e13:b268 with SMTP id v8-20020a05600c214800b003f60e13b268mr1466363wml.22.1686230471465; Thu, 08 Jun 2023 06:21:11 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id 16-20020a05600c021000b003f7f1b3aff1sm5001100wmi.26.2023.06.08.06.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 06:21:10 -0700 (PDT) From: Matthieu Baerts Date: Thu, 08 Jun 2023 15:20:49 +0200 Subject: [PATCH net-next 1/4] mptcp: export local_address Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-1-b301717c9ff5@tessares.net> References: <20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-0-b301717c9ff5@tessares.net> In-Reply-To: <20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-0-b301717c9ff5@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Geliang Tang , Matthieu Baerts X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3955; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=l/jGQDI6Wt0DGeE+EQbUTZRRGJNBQ8M0TmciTMimsH0=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBkgdXF2dATrt1k6R8plFmN8YuqD23J2mPMTIU61 TUKbXRcPKiJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZIHVxQAKCRD2t4JPQmmg czfBEACo7eQ0NVkbvNrezSrhGOLT4aK9BfzKo+4EB8n96i3gUZ2j++5wVPgkILBk5SIjysunUSL T/E+lXs0BNDicXhww6kGFQjltK66kKcCNaV5/h8z6dZof62rYRLjSKZOggD8ct3y/3JLSUvahNt KGbYtgVqt8q7S9R1MWkBivbFQufl9irsI6KV68uK6evPOl6wlaL4R42p7BcM2OxqFrYI/cB/ib8 GTH3gp8vtwKdNOlknU+KzOlAkjR7amGO7FSHdki683JNae/ZK/v3vwC6ZCAtlp3WIYtM2No8fFS pDpiB3olHMgqzTDOvOkNdJa/DTodXX5wy8kf7jjBePHSqoGWZMniApm0heE/Ise9CREbK8ucaGC kQYgIbc7DcavGlIoStQjNP30IxJ7LTAWozqD8Mc5twi5YkEduXO+96F8py4y2dTjgTmPvx3J7Xj 9VeDjiZlN59VBT8yHDDu8Wjb8zB05lO76hsL6pXCls/4eR88mggOhjY2u8/esfJjzQGqa+dLzis WPqRIQyBXql7TlL60VCPfCNjUp6npDVEu4V9IN2ANcD3H+3bNJF8+6VJWtnqhm/tWFNZzEYZofS Ecy1kkIXEEMcsvwvSb8acPhZk8rTamJuXuC3Kl0wft/QoWuDOJNa6ToQlbxaq2/Cr7lToV06Li1 lJNm86sxNBNu+6g== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Geliang Tang Rename local_address() with "mptcp_" prefix and export it in protocol.h. This function will be re-used in the common PM code (pm.c) in the following commit. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts Signed-off-by: Matthieu Baerts Reviewed-by: Larysa Zaremba --- net/mptcp/pm_netlink.c | 17 ++++++++--------- net/mptcp/protocol.h | 1 + 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index bc343dab5e3f..c55ed3dda0d8 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -86,8 +86,7 @@ bool mptcp_addresses_equal(const struct mptcp_addr_info *a, return a->port == b->port; } -static void local_address(const struct sock_common *skc, - struct mptcp_addr_info *addr) +void mptcp_local_address(const struct sock_common *skc, struct mptcp_addr_info *addr) { addr->family = skc->skc_family; addr->port = htons(skc->skc_num); @@ -122,7 +121,7 @@ static bool lookup_subflow_by_saddr(const struct list_head *list, list_for_each_entry(subflow, list, node) { skc = (struct sock_common *)mptcp_subflow_tcp_sock(subflow); - local_address(skc, &cur); + mptcp_local_address(skc, &cur); if (mptcp_addresses_equal(&cur, saddr, saddr->port)) return true; } @@ -263,7 +262,7 @@ bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk) struct mptcp_addr_info saddr; bool ret = false; - local_address((struct sock_common *)sk, &saddr); + mptcp_local_address((struct sock_common *)sk, &saddr); spin_lock_bh(&msk->pm.lock); list_for_each_entry(entry, &msk->pm.anno_list, list) { @@ -541,7 +540,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) struct mptcp_addr_info mpc_addr; bool backup = false; - local_address((struct sock_common *)msk->first, &mpc_addr); + mptcp_local_address((struct sock_common *)msk->first, &mpc_addr); rcu_read_lock(); entry = __lookup_addr(pernet, &mpc_addr, false); if (entry) { @@ -752,7 +751,7 @@ int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk, struct sock *ssk = mptcp_subflow_tcp_sock(subflow); struct mptcp_addr_info local, remote; - local_address((struct sock_common *)ssk, &local); + mptcp_local_address((struct sock_common *)ssk, &local); if (!mptcp_addresses_equal(&local, addr, addr->port)) continue; @@ -1070,8 +1069,8 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) /* The 0 ID mapping is defined by the first subflow, copied into the msk * addr */ - local_address((struct sock_common *)msk, &msk_local); - local_address((struct sock_common *)skc, &skc_local); + mptcp_local_address((struct sock_common *)msk, &msk_local); + mptcp_local_address((struct sock_common *)skc, &skc_local); if (mptcp_addresses_equal(&msk_local, &skc_local, false)) return 0; @@ -1491,7 +1490,7 @@ static int mptcp_nl_remove_id_zero_address(struct net *net, if (list_empty(&msk->conn_list) || mptcp_pm_is_userspace(msk)) goto next; - local_address((struct sock_common *)msk, &msk_local); + mptcp_local_address((struct sock_common *)msk, &msk_local); if (!mptcp_addresses_equal(&msk_local, addr, addr->port)) goto next; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index c5255258bfb3..6e6cffc04ced 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -638,6 +638,7 @@ void mptcp_set_owner_r(struct sk_buff *skb, struct sock *sk); bool mptcp_addresses_equal(const struct mptcp_addr_info *a, const struct mptcp_addr_info *b, bool use_port); +void mptcp_local_address(const struct sock_common *skc, struct mptcp_addr_info *addr); /* called with sk socket lock held */ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, From patchwork Thu Jun 8 13:20:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13272335 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 3038B12B9C for ; Thu, 8 Jun 2023 13:21:17 +0000 (UTC) Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 262231BD6 for ; Thu, 8 Jun 2023 06:21:14 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f735259fa0so5313315e9.1 for ; Thu, 08 Jun 2023 06:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1686230472; x=1688822472; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7gFKa9O69PK+PsR17eSXRUsf4u+mlPVa86DBx+jj43Q=; b=E4kfzjF6nZ0wF9rrV3h9waQUQbC8N5mNdnn0mcMbM9TUZROyPEHiCRi76MCUAG4PbN sQIO50wLECEwLs9Wsh8PKXc7zvdYY6yLyd2vg8oeX0QJawQHYkZYerI4OG+sdc/uxQje KHpjbjFGOYKBD+qXAIXZGLYrM1rKbCdxP25iSLmBRzAsosajIalZhcjaayjG1twYXAuD CZETdSOCevHUe3sa4Ef9mbOPRiWaiMgbOuHxyiNg1w5DTzWRsaEH5Tx1pH7tCWgo+DvQ HxoZBFuH8u8ZTvz01ckLgVM006o5aDAthiwYbpZgRiiGh22L/rH2k4DJmwKRD1Y8ernG WO5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686230472; x=1688822472; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7gFKa9O69PK+PsR17eSXRUsf4u+mlPVa86DBx+jj43Q=; b=Kc+zb16H2TkhiPSBUM+51vOU1UsMK+hVAHj3KCRsJysk7Y3wB+eO79yuLU3rU09m60 j1KHYvpDAYcCgC30s6EUhXnbl3soxMOyfswXw/fAVzGKj2C/pWr1I+tDrIFvcj8Cg9Ru Likh6WLyN1MOhIVnPr0UqIv/4LU5pB+DGm9mpEJZq72DSPjF71XjdM1hyjopO5rWZoQ2 0rmtJjiGr/i1dqzpC4vb63mKA/d8lpNwBG7R6MzvwszfNJvo2F73qUKN2j6WvnQoUyi1 Nl7Lo3DlYyXnw+xcDU2a24VZsZQG2MpAmA+g9BPD+z1voIi2dCnWdeFMmFf8R4P2DN8A 0y3Q== X-Gm-Message-State: AC+VfDzC8WgbZsFnD/NSYEZH39xfD+fpAd4dz7Bu8UZqmWv1fOG0c2pR HdeKOp5DQNRfeE5a3ujAnJ1oVA== X-Google-Smtp-Source: ACHHUZ5ErMlFWY/OUjQNaAn65tolW2rwc31vqqkChytC/yutpz7gKV7MkASYD4fE/0/YptelSMwxmw== X-Received: by 2002:a7b:c84c:0:b0:3f6:128:36a5 with SMTP id c12-20020a7bc84c000000b003f6012836a5mr1381810wml.10.1686230472470; Thu, 08 Jun 2023 06:21:12 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id 16-20020a05600c021000b003f7f1b3aff1sm5001100wmi.26.2023.06.08.06.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 06:21:12 -0700 (PDT) From: Matthieu Baerts Date: Thu, 08 Jun 2023 15:20:50 +0200 Subject: [PATCH net-next 2/4] mptcp: unify pm get_local_id interfaces Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-2-b301717c9ff5@tessares.net> References: <20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-0-b301717c9ff5@tessares.net> In-Reply-To: <20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-0-b301717c9ff5@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Geliang Tang , Matthieu Baerts X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4622; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=tn1Eikl6cGHxV4McPMlmq9kj3EGuMT4TIu0o5dG+VYc=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBkgdXFFY+V5/S/ntKomdIzFWXBuGXZ1FTeoQ+Zf 40xdMwPeT+JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZIHVxQAKCRD2t4JPQmmg c43TD/4+6+HGmxLfwEtatupGtboJRGks2iO20DsIlcDpFqXOHDlTEM4gR2ArlgKdVOFJmfdS+YE Q+xyN+VNYoNeAnHF6OXNStzwihTKHEBEE+hMXo/OD1RmIhCrrhSAIoeomLSr765OfvH6q+/8DAg kJJv3jJUjhDTTpfhL5meqYp3T/E0gSycklY4EM0dvEzUa2STYrri9BE14zJVYLTsKb7DicnvXwZ m6R0QxoT/eR9stCmqH2gi8Q//7lSZuRRPWTDh+zAKDvz0SsJyyfkhrZQw7puJJnPb7nlUcvHtfR vT04u2vYC+18dkGrVJJxiTq4gkkkXk4xd65QAWJxegRuoEU50Y/ZXg9++Fl4eUorIrRipBPou9i M0vqbDBaC74oUP5Te6gWwMzlaEU/ZROkHlHa1NqDFIgL+0jwujr4jFI3Hhq9iRGWMI8Xa1CGQLA OauclSl8BTUIn8hY6IsiLzLrXgHsRujKPTnCcQh6CHmc5I76G9D1Q8TeGG1mtYYKMLgJXqL8XOJ dHoSkDg0Q+j2Oya1TO/rNjOMqnDtw5rRmL0UjxYEiseixoolbUZIOovxIWz47BQY9w9PidV114G l7cBS58jIqrqb7e2TqyOpnLiTxzzSZdndnuGfcRscF+E5Hy/u0enLjUAYk+GHCNNN9u0zqSTXb3 6T9BwH+atG1C46Q== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Geliang Tang This patch unifies the three PM get_local_id() interfaces: mptcp_pm_nl_get_local_id() in mptcp/pm_netlink.c for the in-kernel PM and mptcp_userspace_pm_get_local_id() in mptcp/pm_userspace.c for the userspace PM. They'll be switched in the common PM infterface mptcp_pm_get_local_id() in mptcp/pm.c based on whether mptcp_pm_is_userspace() or not. Also put together the declarations of these three functions in protocol.h. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts Signed-off-by: Matthieu Baerts Reviewed-by: Larysa Zaremba --- net/mptcp/pm.c | 18 +++++++++++++++++- net/mptcp/pm_netlink.c | 22 +++------------------- net/mptcp/protocol.h | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 7d03b5fd8200..5a027a46196c 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -400,7 +400,23 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) { - return mptcp_pm_nl_get_local_id(msk, skc); + struct mptcp_addr_info skc_local; + struct mptcp_addr_info msk_local; + + if (WARN_ON_ONCE(!msk)) + return -1; + + /* The 0 ID mapping is defined by the first subflow, copied into the msk + * addr + */ + mptcp_local_address((struct sock_common *)msk, &msk_local); + mptcp_local_address((struct sock_common *)skc, &skc_local); + if (mptcp_addresses_equal(&msk_local, &skc_local, false)) + return 0; + + if (mptcp_pm_is_userspace(msk)) + return mptcp_userspace_pm_get_local_id(msk, &skc_local); + return mptcp_pm_nl_get_local_id(msk, &skc_local); } void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index c55ed3dda0d8..315ad669eb3c 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1055,33 +1055,17 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, return 0; } -int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) +int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc) { struct mptcp_pm_addr_entry *entry; - struct mptcp_addr_info skc_local; - struct mptcp_addr_info msk_local; struct pm_nl_pernet *pernet; int ret = -1; - if (WARN_ON_ONCE(!msk)) - return -1; - - /* The 0 ID mapping is defined by the first subflow, copied into the msk - * addr - */ - mptcp_local_address((struct sock_common *)msk, &msk_local); - mptcp_local_address((struct sock_common *)skc, &skc_local); - if (mptcp_addresses_equal(&msk_local, &skc_local, false)) - return 0; - - if (mptcp_pm_is_userspace(msk)) - return mptcp_userspace_pm_get_local_id(msk, &skc_local); - pernet = pm_nl_get_pernet_from_msk(msk); rcu_read_lock(); list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) { - if (mptcp_addresses_equal(&entry->addr, &skc_local, entry->addr.port)) { + if (mptcp_addresses_equal(&entry->addr, skc, entry->addr.port)) { ret = entry->addr.id; break; } @@ -1095,7 +1079,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) if (!entry) return -ENOMEM; - entry->addr = skc_local; + entry->addr = *skc; entry->addr.id = 0; entry->addr.port = 0; entry->ifindex = 0; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 6e6cffc04ced..8a2e01d10582 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -916,13 +916,13 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, const struct sk_buff *skb, bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, struct mptcp_rm_list *rm_list); int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); +int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc); int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc); void __init mptcp_pm_nl_init(void); void mptcp_pm_nl_work(struct mptcp_sock *msk); void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list); -int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); unsigned int mptcp_pm_get_add_addr_signal_max(const struct mptcp_sock *msk); unsigned int mptcp_pm_get_add_addr_accept_max(const struct mptcp_sock *msk); unsigned int mptcp_pm_get_subflows_max(const struct mptcp_sock *msk); From patchwork Thu Jun 8 13:20:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13272336 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 5058813ADC for ; Thu, 8 Jun 2023 13:21:19 +0000 (UTC) Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3834526B3 for ; Thu, 8 Jun 2023 06:21:15 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f735bfcbbbso3902775e9.2 for ; Thu, 08 Jun 2023 06:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1686230473; x=1688822473; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NSwaV8frgP+BsYdMJSEI28hJ+VH7kpitse/TkoXMDpU=; b=rilF142TtI9Re4yJ+CLPrruyPWByld4nvPKVBApP6xKp7kfR/KIPO7c/SrdtN47Q2t mC5TJOAvOuCUI8WGcjXz9Tm88ijvKDPIbP+3JC/hb/Zy87bgCL3c44YDbMA8WNFW9Kzo fE71XZWZ8NBkgj1pFJGWeSfTbDSSEnOIg5QaYpq4ZK+vK/AQ3ZcCSsm5aMcC2PbQUXUW 0KhA8ueN+rZ+pPOuOo5ym32tsBWQGQjOhBzrC5Uk7i0NWeaudcsFVC5UBH8X22aa5VSA 6liaOy2NBmOsNouz/JU8m6rLnBcVroho8ZxBWJ2m5NElSDZZpjVZRbkIhfko52Wg4u/8 OPiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686230473; x=1688822473; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NSwaV8frgP+BsYdMJSEI28hJ+VH7kpitse/TkoXMDpU=; b=Vw2T/IfVq++ZlmSkPVupOF87dN1g25mpKENqsYb2Ak7sksld81F7AFRDowSrRb/44f 50oJfhyf5Ld7ms70CAORpSmBw4gBNNYcrpTqZLAJ9hxzDxe+agrkiIAp6IbBDgw6WMh9 JIoXMdalBCgKXVY8IfSDQaAJO/GETfab4RWVK8Y8LVEq++4og/IrPW938H8nRaw+oMHI 5mttgZB6k7mg6n7yB8OV5+ZRazhOtgMa7hDupAPuhqE5rnm7/b0YahbRODFp1WeFUFgu Ml/apSq/nZ25PZC+hy3NVAJcIgyss1DDrvx3h0AHebXHumKL/t1gVvughgoEovhVypum Q97Q== X-Gm-Message-State: AC+VfDxe5+PYFBkI1Y37bIGdRo0KaW5dc+fRozjm9TCZBnAcgLc5E+W2 xdzd5en5RkByqf1lTohsBYA/xw== X-Google-Smtp-Source: ACHHUZ4ENJUz1YdroCW/FRdhUz0xLpU9qz/hy7P4iAZi3MrjLSaexl/UcNwLN69N/+sQbEAHDeFZGA== X-Received: by 2002:a1c:7c0d:0:b0:3f6:f152:1183 with SMTP id x13-20020a1c7c0d000000b003f6f1521183mr1441901wmc.37.1686230473699; Thu, 08 Jun 2023 06:21:13 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id 16-20020a05600c021000b003f7f1b3aff1sm5001100wmi.26.2023.06.08.06.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 06:21:13 -0700 (PDT) From: Matthieu Baerts Date: Thu, 08 Jun 2023 15:20:51 +0200 Subject: [PATCH net-next 3/4] mptcp: unify pm get_flags_and_ifindex_by_id Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-3-b301717c9ff5@tessares.net> References: <20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-0-b301717c9ff5@tessares.net> In-Reply-To: <20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-0-b301717c9ff5@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Geliang Tang , Matthieu Baerts X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4069; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=5nDr9M7v5Mf80NDixMM7FPrdaFJMIldEDth/6RZgYhg=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBkgdXFgoTtiSJCP9CGOJ/S5Y8wlsdZcfEsuGk0z vqPlL1i0HOJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZIHVxQAKCRD2t4JPQmmg c+sWD/91DLbuH2odrwHtoGbvYHh6JKcUMBF4JZuuj8Kqa91+9NrVaGqdy0inki2k9/vpH46Rvqu O0kABJTas7MMPwIYvxVQoY2VBdwNnKh65ADv4UCzElb/jIph6yr0EEQrAOZ8FhnhiQyfP1pLglP lsGwBvPrIUJkLMsWt8aaYBHb3Sg+dXN4OehZGULDnl2KbE633yMRr8+hn9hsHf0S0Y5sjIfJLGF pokZUAhDySwtRC284Oq/ea5AXYmrmzT7Js0I+dIFk3nTbw7JwMP3aZ8UPeC2dbZL/+WxSbyFQXF aXkEUkorTeesliyUHgx13TaEO45kUWECEhxQndDiIN/eXE5OBxn0CeyRXt82OAcwQs/INUQksON PbGW1Hnbxnzj6bvVNG+jHKVBs70D/r4watCKjJYRVqeoC++ndJ4HrDJuPdP1HFnbuW3HKUpTYw5 tKYQarydPhmD2btUaqUQB/aXPyegTC0RGAklanVIB8NLbKuRdcfKYJm1bhV8dKGYaI6F/WvNxnK yH765OZy6x667VWlcWdOrWufpAl9aJKSmjIQOxP6PaJNvZYpTnjlZRhQ+Uta5odYgyIYE8xyQ+p HHHOdad02GNDw4Fy5hraX1YRnBat/kScnEw9dXLkrT2BZaBLCYxw1WvyjnnFmJHtgOugXCCoUjL kXa3DTfQ6B062Lw== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Geliang Tang This patch unifies the three PM get_flags_and_ifindex_by_id() interfaces: mptcp_pm_nl_get_flags_and_ifindex_by_id() in mptcp/pm_netlink.c for the in-kernel PM and mptcp_userspace_pm_get_flags_and_ifindex_by_id() in mptcp/pm_userspace.c for the userspace PM. They'll be switched in the common PM infterface mptcp_pm_get_flags_and_ifindex_by_id() in mptcp/pm.c based on whether mptcp_pm_is_userspace() or not. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts Signed-off-by: Matthieu Baerts Reviewed-by: Larysa Zaremba --- net/mptcp/pm.c | 14 ++++++++++++++ net/mptcp/pm_netlink.c | 27 ++++++++------------------- net/mptcp/pm_userspace.c | 3 --- net/mptcp/protocol.h | 2 ++ 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 5a027a46196c..2d04598dde05 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -419,6 +419,20 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) return mptcp_pm_nl_get_local_id(msk, &skc_local); } +int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id, + u8 *flags, int *ifindex) +{ + *flags = 0; + *ifindex = 0; + + if (!id) + return 0; + + if (mptcp_pm_is_userspace(msk)) + return mptcp_userspace_pm_get_flags_and_ifindex_by_id(msk, id, flags, ifindex); + return mptcp_pm_nl_get_flags_and_ifindex_by_id(msk, id, flags, ifindex); +} + void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) { struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 315ad669eb3c..e8b32d369f11 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1356,31 +1356,20 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info) return ret; } -int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id, - u8 *flags, int *ifindex) +int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id, + u8 *flags, int *ifindex) { struct mptcp_pm_addr_entry *entry; struct sock *sk = (struct sock *)msk; struct net *net = sock_net(sk); - *flags = 0; - *ifindex = 0; - - if (id) { - if (mptcp_pm_is_userspace(msk)) - return mptcp_userspace_pm_get_flags_and_ifindex_by_id(msk, - id, - flags, - ifindex); - - rcu_read_lock(); - entry = __lookup_addr_by_id(pm_nl_get_pernet(net), id); - if (entry) { - *flags = entry->flags; - *ifindex = entry->ifindex; - } - rcu_read_unlock(); + rcu_read_lock(); + entry = __lookup_addr_by_id(pm_nl_get_pernet(net), id); + if (entry) { + *flags = entry->flags; + *ifindex = entry->ifindex; } + rcu_read_unlock(); return 0; } diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 27a275805c06..e1df3a4a4f23 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -85,9 +85,6 @@ int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, { struct mptcp_pm_addr_entry *entry, *match = NULL; - *flags = 0; - *ifindex = 0; - spin_lock_bh(&msk->pm.lock); list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { if (id == entry->addr.id) { diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 8a2e01d10582..607cbd2ccb98 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -822,6 +822,8 @@ mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk, int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id, u8 *flags, int *ifindex); +int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id, + u8 *flags, int *ifindex); int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id, u8 *flags, int *ifindex); From patchwork Thu Jun 8 13:20:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 13272337 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 C373614271 for ; Thu, 8 Jun 2023 13:21:19 +0000 (UTC) Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33B5C2718 for ; Thu, 8 Jun 2023 06:21:16 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3f735259fa0so5313665e9.1 for ; Thu, 08 Jun 2023 06:21:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; t=1686230474; x=1688822474; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5dgkaWGIfYIbjljhSSlh7Bmui4uwpN0SWAU+QRT80As=; b=qVAR2ecucVW+p4KXptaFvsaVrHzHixMpWlKsxEGJts241bm/oGRDCL1YLdMk7NZlka c16QlEhOhb8Xok7xMrxaLudpRz5AioYlJqP6RKZtwORKwyqWuRO6ydKSGlSQ+0Hrw13F iE855DdN7YYdoEtLEHn0GSSjAq+NTa1uVvWAocNBhMojymEbsxj3zjmUfhSM8CI8L3M7 UHttyyevHVgcUnAPGH3o6YvlrqMIiIj/PRX02FESZJqggOR3gU01o5+Nzqjat3GISqjL t9yo+J7RIiSAI16EgWM7bpAeEQDhPbcPWP/eUrzXdgvJGsWP2Iwsk8aAflxOTEPGaOjB pjSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686230474; x=1688822474; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5dgkaWGIfYIbjljhSSlh7Bmui4uwpN0SWAU+QRT80As=; b=PGJciNybFh75qtrnwcE1RmfCccgX42pTqa+4DWbQbK3QGHD5A/LS1T+4IZcthG821o M+fpufsyvdkxZr9GS6ZBqDrX01jRCqAWUo/N85NZjMezzzAfg9CF2DrRoIJD/ubfG9ph i+KHPcQtm5thM3zGqyz5SBD3mWhLmk24fU1duHvGHJmgXQgPHZJvOV6k69Q4QDWlJRvr vt4jqLtMclLbYl94WPhGvKNSHrE/0ZcoVRznIecF6ixjzM658Iw5nWrX3PSDt3sn40g+ Gekj/nWF/xuEN6+aeB2t9JXPm1/wlXHzmBRf8DzeNi6nMCwk8yc4ahnMNoIBlvnfwZ4D kbOQ== X-Gm-Message-State: AC+VfDyHMsQtgXV+7AzVDWv60XkFpwUyh+L1ndJqiuAHyPK3W1CLLdNX rRR+p4FFHONLbVbGcso9gIEkYw== X-Google-Smtp-Source: ACHHUZ7GKhT4PGtrRwd2EjBY7POS6tiFhG/vYnfkIR8eZzcVxZVyeRyLRmYaK/m2Lo+UOWjBhvqiBA== X-Received: by 2002:a7b:c019:0:b0:3f7:f884:7be4 with SMTP id c25-20020a7bc019000000b003f7f8847be4mr1412169wmb.21.1686230474701; Thu, 08 Jun 2023 06:21:14 -0700 (PDT) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id 16-20020a05600c021000b003f7f1b3aff1sm5001100wmi.26.2023.06.08.06.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 06:21:14 -0700 (PDT) From: Matthieu Baerts Date: Thu, 08 Jun 2023 15:20:52 +0200 Subject: [PATCH net-next 4/4] mptcp: unify pm set_flags interfaces Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-4-b301717c9ff5@tessares.net> References: <20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-0-b301717c9ff5@tessares.net> In-Reply-To: <20230608-upstream-net-next-20230608-mptcp-unify-pm-interfaces-v1-0-b301717c9ff5@tessares.net> To: mptcp@lists.linux.dev, Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Geliang Tang , Matthieu Baerts X-Mailer: b4 0.12.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5515; i=matthieu.baerts@tessares.net; h=from:subject:message-id; bh=nAiGoxd4O08hlaui72f0yC95azIdQnaelnxY4OLX1JU=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBkgdXFAQhBRtbu0GqjM4u9CPn+H7ZdGkwZJFZpk Fge/YuAqXCJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZIHVxQAKCRD2t4JPQmmg czUoD/48REKp6Kc18uG+cTTanHAy8TD8YOPHfsBVfzp8iXOdGJrzHrvKaRllLEOIKNk9XMLEtBF hu5b+Fz5MftBaMTRX1WRjRF/zwZ+XcB74rSt0vvm6GxwXTqdD0XN9jBPAHyNmMl55mFXCPnma4c O1PhcLJ4fbuivb5JdIw6D8XLDovfPrB4tKqxPK5hSi2q63uEFSnRU4pdgs3Z7djtxHPNcl6WNyF 3Hy7SQHDnmEhIxgA3MKDMQhoM4dsWl+XDUdwETLHVmxHhneIc5jZRpL71h3yV5WNH2VNAqjo3R6 erxFonYMx1LsV2sisNO05Z9oG2BmJYFdFiMk3+NqQpdFaTHBK9gaCMUp3MpqlHazQFjDobUGy0o 22SjA3QugvXcorEBskWRvfaHLj/PvSjf31GXoSIY+PifxXDH13Dt56YeGLmwuaA4ZJrFYZ23C0C B16P3w193SPyZRaYvpggSr6XARWYhFw0szX2wNCWY/ZTBnc9UriVeeaNeBa4jEO+0wWdmeREnPi AE+lc8/MQIsFkIOBH6mg9cXciLLQRXJF3U6R9f2Y+HAHrMrGqkcGYxwRde+Nc2E00VV681sj77l FCX0QW8EOlPvgCdZ3ke5W46s1tbkdjnNsRueVKA1nSLLQxAvMjX4GNdfCjJqd0rH0YoHNZfUo7i 5HguWofxWARmYNw== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Geliang Tang This patch unifies the three PM set_flags() interfaces: mptcp_pm_nl_set_flags() in mptcp/pm_netlink.c for the in-kernel PM and mptcp_userspace_pm_set_flags() in mptcp/pm_userspace.c for the userspace PM. They'll be switched in the common PM infterface mptcp_pm_set_flags() in mptcp/pm.c based on whether token is NULL or not. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts Signed-off-by: Matthieu Baerts Reviewed-by: Larysa Zaremba --- net/mptcp/pm.c | 9 +++++++ net/mptcp/pm_netlink.c | 70 +++++++++++++++++++++++++++----------------------- net/mptcp/protocol.h | 4 +++ 3 files changed, 51 insertions(+), 32 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 2d04598dde05..36bf9196168b 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -433,6 +433,15 @@ int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id return mptcp_pm_nl_get_flags_and_ifindex_by_id(msk, id, flags, ifindex); } +int mptcp_pm_set_flags(struct net *net, struct nlattr *token, + struct mptcp_pm_addr_entry *loc, + struct mptcp_pm_addr_entry *rem, u8 bkup) +{ + if (token) + return mptcp_userspace_pm_set_flags(net, token, loc, rem, bkup); + return mptcp_pm_nl_set_flags(net, loc, bkup); +} + void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) { struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index e8b32d369f11..13be9205d36d 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1864,18 +1864,50 @@ static int mptcp_nl_set_flags(struct net *net, return ret; } +int mptcp_pm_nl_set_flags(struct net *net, struct mptcp_pm_addr_entry *addr, u8 bkup) +{ + struct pm_nl_pernet *pernet = pm_nl_get_pernet(net); + u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP | + MPTCP_PM_ADDR_FLAG_FULLMESH; + struct mptcp_pm_addr_entry *entry; + u8 lookup_by_id = 0; + + if (addr->addr.family == AF_UNSPEC) { + lookup_by_id = 1; + if (!addr->addr.id) + return -EOPNOTSUPP; + } + + spin_lock_bh(&pernet->lock); + entry = __lookup_addr(pernet, &addr->addr, lookup_by_id); + if (!entry) { + spin_unlock_bh(&pernet->lock); + return -EINVAL; + } + if ((addr->flags & MPTCP_PM_ADDR_FLAG_FULLMESH) && + (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { + spin_unlock_bh(&pernet->lock); + return -EINVAL; + } + + changed = (addr->flags ^ entry->flags) & mask; + entry->flags = (entry->flags & ~mask) | (addr->flags & mask); + *addr = *entry; + spin_unlock_bh(&pernet->lock); + + mptcp_nl_set_flags(net, &addr->addr, bkup, changed); + return 0; +} + static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info) { - struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }, *entry; struct mptcp_pm_addr_entry remote = { .addr = { .family = AF_UNSPEC }, }; + struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }; struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; - struct pm_nl_pernet *pernet = genl_info_pm_nl(info); - u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP | - MPTCP_PM_ADDR_FLAG_FULLMESH; struct net *net = sock_net(skb->sk); - u8 bkup = 0, lookup_by_id = 0; + u8 bkup = 0; int ret; ret = mptcp_pm_parse_entry(attr, info, false, &addr); @@ -1890,34 +1922,8 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info) if (addr.flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup = 1; - if (addr.addr.family == AF_UNSPEC) { - lookup_by_id = 1; - if (!addr.addr.id) - return -EOPNOTSUPP; - } - if (token) - return mptcp_userspace_pm_set_flags(net, token, &addr, &remote, bkup); - - spin_lock_bh(&pernet->lock); - entry = __lookup_addr(pernet, &addr.addr, lookup_by_id); - if (!entry) { - spin_unlock_bh(&pernet->lock); - return -EINVAL; - } - if ((addr.flags & MPTCP_PM_ADDR_FLAG_FULLMESH) && - (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) { - spin_unlock_bh(&pernet->lock); - return -EINVAL; - } - - changed = (addr.flags ^ entry->flags) & mask; - entry->flags = (entry->flags & ~mask) | (addr.flags & mask); - addr = *entry; - spin_unlock_bh(&pernet->lock); - - mptcp_nl_set_flags(net, &addr.addr, bkup, changed); - return 0; + return mptcp_pm_set_flags(net, token, &addr, &remote, bkup); } static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 607cbd2ccb98..1e7465bb66d5 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -827,6 +827,10 @@ int mptcp_pm_nl_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id, u8 *flags, int *ifindex); +int mptcp_pm_set_flags(struct net *net, struct nlattr *token, + struct mptcp_pm_addr_entry *loc, + struct mptcp_pm_addr_entry *rem, u8 bkup); +int mptcp_pm_nl_set_flags(struct net *net, struct mptcp_pm_addr_entry *addr, u8 bkup); int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token, struct mptcp_pm_addr_entry *loc, struct mptcp_pm_addr_entry *rem, u8 bkup);