]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mptcp: pm: add mptcp_pm_genl_fill_addr helper
authorGeliang Tang <tanggeliang@kylinos.cn>
Fri, 21 Feb 2025 15:43:57 +0000 (16:43 +0100)
committerJakub Kicinski <kuba@kernel.org>
Tue, 25 Feb 2025 02:23:43 +0000 (18:23 -0800)
To save some redundant code in dump_addr() interfaces of both the
netlink PM and userspace PM, the code that calls netlink message
helpers (genlmsg_put/cancel/end) and mptcp_nl_fill_addr() is wrapped
into a new helper mptcp_pm_genl_fill_addr().

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20250221-net-next-mptcp-pm-misc-cleanup-3-v1-4-2b70ab1cee79@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/mptcp/pm.c
net/mptcp/pm_netlink.c
net/mptcp/pm_userspace.c
net/mptcp/protocol.h

index b1f36dc1a09113594324ef0547093a5447664181..16cacce6c10fe86467aa7ef8e588f9f535b586fb 100644 (file)
@@ -489,6 +489,27 @@ fail:
        return ret;
 }
 
+int mptcp_pm_genl_fill_addr(struct sk_buff *msg,
+                           struct netlink_callback *cb,
+                           struct mptcp_pm_addr_entry *entry)
+{
+       void *hdr;
+
+       hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
+                         cb->nlh->nlmsg_seq, &mptcp_genl_family,
+                         NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
+       if (!hdr)
+               return -EINVAL;
+
+       if (mptcp_nl_fill_addr(msg, entry) < 0) {
+               genlmsg_cancel(msg, hdr);
+               return -EINVAL;
+       }
+
+       genlmsg_end(msg, hdr);
+       return 0;
+}
+
 static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb)
 {
        const struct genl_info *info = genl_info_dump(cb);
index 1a0695e087af02347678b9b6914d303554bcf1f3..98fcbf8b1465649961c568c6f8978e91d0a53668 100644 (file)
@@ -1798,7 +1798,6 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
        struct mptcp_pm_addr_entry *entry;
        struct pm_nl_pernet *pernet;
        int id = cb->args[0];
-       void *hdr;
        int i;
 
        pernet = pm_nl_get_pernet(net);
@@ -1813,19 +1812,10 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
                        if (entry->addr.id <= id)
                                continue;
 
-                       hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
-                                         cb->nlh->nlmsg_seq, &mptcp_genl_family,
-                                         NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
-                       if (!hdr)
+                       if (mptcp_pm_genl_fill_addr(msg, cb, entry) < 0)
                                break;
 
-                       if (mptcp_nl_fill_addr(msg, entry) < 0) {
-                               genlmsg_cancel(msg, hdr);
-                               break;
-                       }
-
                        id = entry->addr.id;
-                       genlmsg_end(msg, hdr);
                }
        }
        rcu_read_unlock();
index b69fb5b18130cb3abd08e3ef47004f599895486a..bedd6f9ebc8b07871d317dfaf65135342cdeeeee 100644 (file)
@@ -641,7 +641,6 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
        struct mptcp_sock *msk;
        int ret = -EINVAL;
        struct sock *sk;
-       void *hdr;
 
        BUILD_BUG_ON(sizeof(struct id_bitmap) > sizeof(cb->ctx));
 
@@ -659,19 +658,10 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
                if (test_bit(entry->addr.id, bitmap->map))
                        continue;
 
-               hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
-                                 cb->nlh->nlmsg_seq, &mptcp_genl_family,
-                                 NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR);
-               if (!hdr)
+               if (mptcp_pm_genl_fill_addr(msg, cb, entry) < 0)
                        break;
 
-               if (mptcp_nl_fill_addr(msg, entry) < 0) {
-                       genlmsg_cancel(msg, hdr);
-                       break;
-               }
-
                __set_bit(entry->addr.id, bitmap->map);
-               genlmsg_end(msg, hdr);
        }
        spin_unlock_bh(&msk->pm.lock);
        release_sock(sk);
index ca65f8bff632ff806fe761f86e9aa065b0657d1e..256677c43ca6514bf487a6d897240ae012b6128e 100644 (file)
@@ -1057,6 +1057,9 @@ void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subf
                                              struct request_sock *req);
 int mptcp_nl_fill_addr(struct sk_buff *skb,
                       struct mptcp_pm_addr_entry *entry);
+int mptcp_pm_genl_fill_addr(struct sk_buff *msg,
+                           struct netlink_callback *cb,
+                           struct mptcp_pm_addr_entry *entry);
 
 static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk)
 {