[Drbd-dev] drbd_nl.c:drbd_adm_prepare() indexes drbd_genl_ops[] by cmd number

Lars Ellenberg lars.ellenberg at linbit.com
Mon Jun 3 11:21:18 CEST 2019


On Fri, May 31, 2019 at 01:01:24PM -0600, David Butterfield wrote:
> (Is this the right place to send comments on the source code such as this one?)
> 
> In drbd_nl.c:
> 
>   static int drbd_adm_prepare(struct drbd_config_context *adm_ctx,
>   	struct sk_buff *skb, struct genl_info *info, unsigned flags)
>   {
>   	struct drbd_genlmsghdr *d_in = info->userhdr;
>   	const u8 cmd = info->genlhdr->cmd;
>   	int err;
>   
>   	memset(adm_ctx, 0, sizeof(*adm_ctx));
>   
> + 	//XXX I do not think you can find the ops for a command number by indexing this array.
> + 	//XXX The array is unordered and packed.  I think it must search like genl_get_cmd().


drbd_genl_ops is a static struct genl_ops [], indexed by cmd.

family->ops is a struct genl_ops*, pointing to an array
indexed by "i" [0 .. (family->n_ops - 1)]

Any specific reason you are spending time with this code in particular?

>   	/*
>   	 * genl_rcv_msg() only checks if commands with the GENL_ADMIN_PERM flag
>   	 * set have CAP_NET_ADMIN; we also require CAP_SYS_ADMIN for
>   	 * administrative commands.
>   	 */
>   	if ((drbd_genl_ops[cmd].flags & GENL_ADMIN_PERM) &&
>   	    drbd_security_netlink_recv(skb, CAP_SYS_ADMIN))
>   		return -EPERM;
>   
>   	adm_ctx->reply_skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
>   	if (!adm_ctx->reply_skb) {
>   		err = -ENOMEM;
>   		goto fail;
>   	}

-- 
: Lars Ellenberg
: LINBIT | Keeping the Digital World Running
: DRBD -- Heartbeat -- Corosync -- Pacemaker
: R&D, Integration, Ops, Consulting, Support

DRBD® and LINBIT® are registered trademarks of LINBIT


More information about the drbd-dev mailing list