]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mptcp: pm: avoid computing rm_addr size twice
authorMatthieu Baerts (NGI0) <matttbe@kernel.org>
Fri, 5 Jun 2026 09:21:46 +0000 (19:21 +1000)
committerJakub Kicinski <kuba@kernel.org>
Thu, 11 Jun 2026 22:33:37 +0000 (15:33 -0700)
mptcp_rm_addr_len helper was called twice: in mptcp_pm_rm_addr_signal,
then just after in mptcp_established_options_rm_addr. Both to check the
remaining space.

The second call is not needed: if there is not enough space,
mptcp_pm_rm_addr_signal will return false, and the caller,
mptcp_established_options_rm_addr, will do the same without re-checking
the size again. Instead, mptcp_pm_rm_addr_signal can directly set the
size.

While at it, move mptcp_rm_addr_len to pm.c, as it is now only used
there, once.

Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20260605-net-next-mptcp-add-addr6-port-ts-v2-2-758e7ca73f4d@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/mptcp/options.c
net/mptcp/pm.c
net/mptcp/protocol.h

index fd972047fdf7c7c7db1744a3ccdc3f278c0000bb..e44db4768f6cf2d0ada5588b9882988c7511e2c3 100644 (file)
@@ -711,19 +711,12 @@ static bool mptcp_established_options_rm_addr(struct sock *sk, int *size,
        struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
        struct mptcp_sock *msk = mptcp_sk(subflow->conn);
        struct mptcp_rm_list rm_list;
-       int i, len;
+       int i;
 
        if (!mptcp_pm_should_rm_signal(msk) ||
-           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list)))
+           !(mptcp_pm_rm_addr_signal(msk, remaining, &rm_list, size)))
                return false;
 
-       len = mptcp_rm_addr_len(&rm_list);
-       if (len < 0)
-               return false;
-       if (remaining < len)
-               return false;
-
-       *size = len;
        opts->suboptions |= OPTION_MPTCP_RM_ADDR;
        opts->rm_list = rm_list;
 
index 470501470fe5430781a46f4035e3b38ef8a2e42f..4bc380c6f0e153fc47c5b989df33e930b22bb0f6 100644 (file)
@@ -953,8 +953,16 @@ out_unlock:
        return ret;
 }
 
+static int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
+{
+       if (rm_list->nr == 0 || rm_list->nr > MPTCP_RM_IDS_MAX)
+               return -EINVAL;
+
+       return TCPOLEN_MPTCP_RM_ADDR_BASE + roundup(rm_list->nr - 1, 4) + 1;
+}
+
 bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-                            struct mptcp_rm_list *rm_list)
+                            struct mptcp_rm_list *rm_list, int *size)
 {
        int ret = false, len;
        u8 rm_addr;
@@ -974,6 +982,7 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
        if (remaining < len)
                goto out_unlock;
 
+       *size = len;
        *rm_list = msk->pm.rm_list_tx;
        WRITE_ONCE(msk->pm.addr_signal, rm_addr);
        ret = true;
index b93b878478d2620a4731a4d8ba15bf3be8cb0a04..75c5faaf4486e0d09f3493820b674821c7122a2b 100644 (file)
@@ -1221,19 +1221,11 @@ static inline unsigned int mptcp_add_addr_len(int family, bool echo, bool port)
        return len;
 }
 
-static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
-{
-       if (rm_list->nr == 0 || rm_list->nr > MPTCP_RM_IDS_MAX)
-               return -EINVAL;
-
-       return TCPOLEN_MPTCP_RM_ADDR_BASE + roundup(rm_list->nr - 1, 4) + 1;
-}
-
 bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, unsigned int opt_size,
                              unsigned int remaining,
                              struct mptcp_addr_info *addr, bool *echo);
 bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
-                            struct mptcp_rm_list *rm_list);
+                            struct mptcp_rm_list *rm_list, int *len);
 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_pm_addr_entry *skc);