]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
genetlink: extend info user-storage to match NL cb ctx
authorPaolo Abeni <pabeni@redhat.com>
Wed, 9 Oct 2024 08:09:47 +0000 (10:09 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 10 Oct 2024 15:30:21 +0000 (08:30 -0700)
This allows a more uniform implementation of non-dump and dump
operations, and will be used later in the series to avoid some
per-operation allocation.

Additionally rename the NL_ASSERT_DUMP_CTX_FITS macro, to
fit a more extended usage.

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Link: https://patch.msgid.link/1130cc2896626b84587a2a5f96a5c6829638f4da.1728460186.git.pabeni@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/vxlan/vxlan_mdb.c
include/linux/netlink.h
include/net/genetlink.h
net/core/netdev-genl.c
net/core/rtnetlink.c
net/devlink/devl_internal.h
net/ethtool/rss.c
net/netfilter/nf_conntrack_netlink.c
net/netlink/genetlink.c

index 60eb95a06d551c629d2a0ee4c9a769e3e159f9a0..ebed05a2804cf83294adaeb63fa82cdb4746bfdf 100644 (file)
@@ -284,7 +284,7 @@ int vxlan_mdb_dump(struct net_device *dev, struct sk_buff *skb,
 
        ASSERT_RTNL();
 
-       NL_ASSERT_DUMP_CTX_FITS(struct vxlan_mdb_dump_ctx);
+       NL_ASSERT_CTX_FITS(struct vxlan_mdb_dump_ctx);
 
        nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid,
                        cb->nlh->nlmsg_seq, RTM_NEWMDB, sizeof(*bpm),
index b332c2048c75576cd265a2f7940d8cab715beacd..a3ca198a3a9efd4341c3b11cb061bfe1ca29c80c 100644 (file)
@@ -34,6 +34,7 @@ struct netlink_skb_parms {
 
 #define NETLINK_CB(skb)                (*(struct netlink_skb_parms*)&((skb)->cb))
 #define NETLINK_CREDS(skb)     (&NETLINK_CB((skb)).creds)
+#define NETLINK_CTX_SIZE       48
 
 
 void netlink_table_grab(void);
@@ -293,7 +294,7 @@ struct netlink_callback {
        int                     flags;
        bool                    strict_check;
        union {
-               u8              ctx[48];
+               u8              ctx[NETLINK_CTX_SIZE];
 
                /* args is deprecated. Cast a struct over ctx instead
                 * for proper type safety.
@@ -302,7 +303,7 @@ struct netlink_callback {
        };
 };
 
-#define NL_ASSERT_DUMP_CTX_FITS(type_name)                             \
+#define NL_ASSERT_CTX_FITS(type_name)                                  \
        BUILD_BUG_ON(sizeof(type_name) >                                \
                     sizeof_field(struct netlink_callback, ctx))
 
index 9ab49bfeae789afc11338ac1c89bb081566554a8..9d3726e8f90eb15db989cc5fb27a560a9ff86b8d 100644 (file)
@@ -124,7 +124,8 @@ struct genl_family {
  * @genlhdr: generic netlink message header
  * @attrs: netlink attributes
  * @_net: network namespace
- * @user_ptr: user pointers
+ * @ctx: storage space for the use by the family
+ * @user_ptr: user pointers (deprecated, use ctx instead)
  * @extack: extended ACK report struct
  */
 struct genl_info {
@@ -135,7 +136,10 @@ struct genl_info {
        struct genlmsghdr *     genlhdr;
        struct nlattr **        attrs;
        possible_net_t          _net;
-       void *                  user_ptr[2];
+       union {
+               u8              ctx[NETLINK_CTX_SIZE];
+               void *          user_ptr[2];
+       };
        struct netlink_ext_ack *extack;
 };
 
index 1cb954f2d39e8248bffd854cdf27eceb25293425..358cba2487967333e0e9b1efce9e9151f4cc67c5 100644 (file)
@@ -24,7 +24,7 @@ struct netdev_nl_dump_ctx {
 
 static struct netdev_nl_dump_ctx *netdev_dump_ctx(struct netlink_callback *cb)
 {
-       NL_ASSERT_DUMP_CTX_FITS(struct netdev_nl_dump_ctx);
+       NL_ASSERT_CTX_FITS(struct netdev_nl_dump_ctx);
 
        return (struct netdev_nl_dump_ctx *)cb->ctx;
 }
index 6d68247aea70e311a09669013126f3de8a68c916..a9b81b7d9746d2d582fc4cf9a435bda55b7529d1 100644 (file)
@@ -6243,7 +6243,7 @@ static int rtnl_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
        int idx, s_idx;
        int err;
 
-       NL_ASSERT_DUMP_CTX_FITS(struct rtnl_mdb_dump_ctx);
+       NL_ASSERT_CTX_FITS(struct rtnl_mdb_dump_ctx);
 
        if (cb->strict_check) {
                err = rtnl_mdb_valid_dump_req(cb->nlh, cb->extack);
index c7a8e13f917cfa70b4775f3abcb7bace0d853470..a9f064ab9ed9b9a9d6ae9d150c74e7550ed48af2 100644 (file)
@@ -166,7 +166,7 @@ int devlink_nl_dumpit(struct sk_buff *msg, struct netlink_callback *cb,
 static inline struct devlink_nl_dump_state *
 devlink_dump_state(struct netlink_callback *cb)
 {
-       NL_ASSERT_DUMP_CTX_FITS(struct devlink_nl_dump_state);
+       NL_ASSERT_CTX_FITS(struct devlink_nl_dump_state);
 
        return (struct devlink_nl_dump_state *)cb->ctx;
 }
index e07386275e142dff35af40f2b45bee5e41968ada..7cb106b590aba1f8437a33046abe135f64df55bf 100644 (file)
@@ -224,7 +224,7 @@ struct rss_nl_dump_ctx {
 
 static struct rss_nl_dump_ctx *rss_dump_ctx(struct netlink_callback *cb)
 {
-       NL_ASSERT_DUMP_CTX_FITS(struct rss_nl_dump_ctx);
+       NL_ASSERT_CTX_FITS(struct rss_nl_dump_ctx);
 
        return (struct rss_nl_dump_ctx *)cb->ctx;
 }
index 6a1239433830fb7988286e1ece2f370e91895314..36168f8b6efa3c7d69320aa091df12e43179aec8 100644 (file)
@@ -3870,7 +3870,7 @@ static int __init ctnetlink_init(void)
 {
        int ret;
 
-       NL_ASSERT_DUMP_CTX_FITS(struct ctnetlink_list_dump_ctx);
+       NL_ASSERT_CTX_FITS(struct ctnetlink_list_dump_ctx);
 
        ret = nfnetlink_subsys_register(&ctnl_subsys);
        if (ret < 0) {
index feb54c63a1165f25bdeb95daa11080374ad91761..29387b605f3eb9624b55d4327a1022cc9b3495f7 100644 (file)
@@ -997,7 +997,7 @@ static int genl_start(struct netlink_callback *cb)
        info->info.attrs        = attrs;
        genl_info_net_set(&info->info, sock_net(cb->skb->sk));
        info->info.extack       = cb->extack;
-       memset(&info->info.user_ptr, 0, sizeof(info->info.user_ptr));
+       memset(&info->info.ctx, 0, sizeof(info->info.ctx));
 
        cb->data = info;
        if (ops->start) {
@@ -1104,7 +1104,7 @@ static int genl_family_rcv_msg_doit(const struct genl_family *family,
        info.attrs = attrbuf;
        info.extack = extack;
        genl_info_net_set(&info, net);
-       memset(&info.user_ptr, 0, sizeof(info.user_ptr));
+       memset(&info.ctx, 0, sizeof(info.ctx));
 
        if (ops->pre_doit) {
                err = ops->pre_doit(ops, skb, &info);