Commit 13d68a16 authored by Paolo Abeni's avatar Paolo Abeni Committed by Jakub Kicinski
Browse files

genetlink: extend info user-storage to match NL cb ctx



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: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Link: https://patch.msgid.link/1130cc2896626b84587a2a5f96a5c6829638f4da.1728460186.git.pabeni@redhat.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 80c549cd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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),
+3 −2
Original line number Diff line number Diff line
@@ -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))

+6 −2
Original line number Diff line number Diff line
@@ -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;
	union {
		u8		ctx[NETLINK_CTX_SIZE];
		void *		user_ptr[2];
	};
	struct netlink_ext_ack *extack;
};

+1 −1
Original line number Diff line number Diff line
@@ -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;
}
+1 −1
Original line number Diff line number Diff line
@@ -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);
Loading