1 // SPDX-License-Identifier: GPL-2.0
3 * NETLINK Generic Netlink Family
5 * Authors: Jamal Hadi Salim
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/errno.h>
14 #include <linux/types.h>
15 #include <linux/socket.h>
16 #include <linux/string_helpers.h>
17 #include <linux/skbuff.h>
18 #include <linux/mutex.h>
19 #include <linux/bitmap.h>
20 #include <linux/rwsem.h>
21 #include <linux/idr.h>
23 #include <net/genetlink.h>
25 #include "genetlink.h"
27 static DEFINE_MUTEX(genl_mutex); /* serialization of message processing */
28 static DECLARE_RWSEM(cb_lock);
30 atomic_t genl_sk_destructing_cnt = ATOMIC_INIT(0);
31 DECLARE_WAIT_QUEUE_HEAD(genl_sk_destructing_waitq);
35 mutex_lock(&genl_mutex);
37 EXPORT_SYMBOL(genl_lock);
39 void genl_unlock(void)
41 mutex_unlock(&genl_mutex);
43 EXPORT_SYMBOL(genl_unlock);
45 static void genl_lock_all(void)
51 static void genl_unlock_all(void)
57 static void genl_op_lock(const struct genl_family *family)
59 if (!family->parallel_ops)
63 static void genl_op_unlock(const struct genl_family *family)
65 if (!family->parallel_ops)
69 static DEFINE_IDR(genl_fam_idr);
72 * Bitmap of multicast groups that are currently in use.
74 * To avoid an allocation at boot of just one unsigned long,
75 * declare it global instead.
76 * Bit 0 is marked as already used since group 0 is invalid.
77 * Bit 1 is marked as already used since the drop-monitor code
78 * abuses the API and thinks it can statically use group 1.
79 * That group will typically conflict with other groups that
80 * any proper users use.
81 * Bit 16 is marked as used since it's used for generic netlink
82 * and the code no longer marks pre-reserved IDs as used.
83 * Bit 17 is marked as already used since the VFS quota code
84 * also abused this API and relied on family == group ID, we
85 * cater to that by giving it a static family and group ID.
86 * Bit 18 is marked as already used since the PMCRAID driver
87 * did the same thing as the VFS quota code (maybe copied?)
89 static unsigned long mc_group_start = 0x3 | BIT(GENL_ID_CTRL) |
90 BIT(GENL_ID_VFS_DQUOT) |
92 static unsigned long *mc_groups = &mc_group_start;
93 static unsigned long mc_groups_longs = 1;
95 /* We need the last attribute with non-zero ID therefore a 2-entry array */
96 static struct nla_policy genl_policy_reject_all[] = {
97 { .type = NLA_REJECT },
98 { .type = NLA_REJECT },
101 static int genl_ctrl_event(int event, const struct genl_family *family,
102 const struct genl_multicast_group *grp,
106 genl_op_fill_in_reject_policy(const struct genl_family *family,
109 BUILD_BUG_ON(ARRAY_SIZE(genl_policy_reject_all) - 1 != 1);
111 if (op->policy || op->cmd < family->resv_start_op)
114 op->policy = genl_policy_reject_all;
119 genl_op_fill_in_reject_policy_split(const struct genl_family *family,
120 struct genl_split_ops *op)
125 op->policy = genl_policy_reject_all;
129 static const struct genl_family *genl_family_find_byid(unsigned int id)
131 return idr_find(&genl_fam_idr, id);
134 static const struct genl_family *genl_family_find_byname(char *name)
136 const struct genl_family *family;
139 idr_for_each_entry(&genl_fam_idr, family, id)
140 if (strcmp(family->name, name) == 0)
146 struct genl_op_iter {
147 const struct genl_family *family;
148 struct genl_split_ops doit;
149 struct genl_split_ops dumpit;
156 static void genl_op_from_full(const struct genl_family *family,
157 unsigned int i, struct genl_ops *op)
159 *op = family->ops[i];
162 op->maxattr = family->maxattr;
164 op->policy = family->policy;
166 genl_op_fill_in_reject_policy(family, op);
169 static int genl_get_cmd_full(u32 cmd, const struct genl_family *family,
174 for (i = 0; i < family->n_ops; i++)
175 if (family->ops[i].cmd == cmd) {
176 genl_op_from_full(family, i, op);
183 static void genl_op_from_small(const struct genl_family *family,
184 unsigned int i, struct genl_ops *op)
186 memset(op, 0, sizeof(*op));
187 op->doit = family->small_ops[i].doit;
188 op->dumpit = family->small_ops[i].dumpit;
189 op->cmd = family->small_ops[i].cmd;
190 op->internal_flags = family->small_ops[i].internal_flags;
191 op->flags = family->small_ops[i].flags;
192 op->validate = family->small_ops[i].validate;
194 op->maxattr = family->maxattr;
195 op->policy = family->policy;
197 genl_op_fill_in_reject_policy(family, op);
200 static int genl_get_cmd_small(u32 cmd, const struct genl_family *family,
205 for (i = 0; i < family->n_small_ops; i++)
206 if (family->small_ops[i].cmd == cmd) {
207 genl_op_from_small(family, i, op);
214 static void genl_op_from_split(struct genl_op_iter *iter)
216 const struct genl_family *family = iter->family;
219 i = iter->entry_idx - family->n_ops - family->n_small_ops;
221 if (family->split_ops[i + cnt].flags & GENL_CMD_CAP_DO) {
222 iter->doit = family->split_ops[i + cnt];
223 genl_op_fill_in_reject_policy_split(family, &iter->doit);
226 memset(&iter->doit, 0, sizeof(iter->doit));
229 if (i + cnt < family->n_split_ops &&
230 family->split_ops[i + cnt].flags & GENL_CMD_CAP_DUMP &&
231 (!cnt || family->split_ops[i + cnt].cmd == iter->doit.cmd)) {
232 iter->dumpit = family->split_ops[i + cnt];
233 genl_op_fill_in_reject_policy_split(family, &iter->dumpit);
236 memset(&iter->dumpit, 0, sizeof(iter->dumpit));
240 iter->entry_idx += cnt;
244 genl_get_cmd_split(u32 cmd, u8 flag, const struct genl_family *family,
245 struct genl_split_ops *op)
249 for (i = 0; i < family->n_split_ops; i++)
250 if (family->split_ops[i].cmd == cmd &&
251 family->split_ops[i].flags & flag) {
252 *op = family->split_ops[i];
260 genl_cmd_full_to_split(struct genl_split_ops *op,
261 const struct genl_family *family,
262 const struct genl_ops *full, u8 flags)
264 if ((flags & GENL_CMD_CAP_DO && !full->doit) ||
265 (flags & GENL_CMD_CAP_DUMP && !full->dumpit)) {
266 memset(op, 0, sizeof(*op));
270 if (flags & GENL_CMD_CAP_DUMP) {
271 op->start = full->start;
272 op->dumpit = full->dumpit;
273 op->done = full->done;
275 op->pre_doit = family->pre_doit;
276 op->doit = full->doit;
277 op->post_doit = family->post_doit;
280 if (flags & GENL_CMD_CAP_DUMP &&
281 full->validate & GENL_DONT_VALIDATE_DUMP) {
285 op->policy = full->policy;
286 op->maxattr = full->maxattr;
290 op->internal_flags = full->internal_flags;
291 op->flags = full->flags;
292 op->validate = full->validate;
294 /* Make sure flags include the GENL_CMD_CAP_DO / GENL_CMD_CAP_DUMP */
300 /* Must make sure that op is initialized to 0 on failure */
302 genl_get_cmd(u32 cmd, u8 flags, const struct genl_family *family,
303 struct genl_split_ops *op)
305 struct genl_ops full;
308 err = genl_get_cmd_full(cmd, family, &full);
310 err = genl_get_cmd_small(cmd, family, &full);
311 /* Found one of legacy forms */
313 return genl_cmd_full_to_split(op, family, &full, flags);
315 err = genl_get_cmd_split(cmd, flags, family, op);
317 memset(op, 0, sizeof(*op));
321 /* For policy dumping only, get ops of both do and dump.
322 * Fail if both are missing, genl_get_cmd() will zero-init in case of failure.
325 genl_get_cmd_both(u32 cmd, const struct genl_family *family,
326 struct genl_split_ops *doit, struct genl_split_ops *dumpit)
330 err1 = genl_get_cmd(cmd, GENL_CMD_CAP_DO, family, doit);
331 err2 = genl_get_cmd(cmd, GENL_CMD_CAP_DUMP, family, dumpit);
333 return err1 && err2 ? -ENOENT : 0;
337 genl_op_iter_init(const struct genl_family *family, struct genl_op_iter *iter)
339 iter->family = family;
345 return iter->family->n_ops +
346 iter->family->n_small_ops +
347 iter->family->n_split_ops;
350 static bool genl_op_iter_next(struct genl_op_iter *iter)
352 const struct genl_family *family = iter->family;
353 bool legacy_op = true;
356 if (iter->entry_idx < family->n_ops) {
357 genl_op_from_full(family, iter->entry_idx, &op);
358 } else if (iter->entry_idx < family->n_ops + family->n_small_ops) {
359 genl_op_from_small(family, iter->entry_idx - family->n_ops,
361 } else if (iter->entry_idx <
362 family->n_ops + family->n_small_ops + family->n_split_ops) {
364 /* updates entry_idx */
365 genl_op_from_split(iter);
375 genl_cmd_full_to_split(&iter->doit, family,
376 &op, GENL_CMD_CAP_DO);
377 genl_cmd_full_to_split(&iter->dumpit, family,
378 &op, GENL_CMD_CAP_DUMP);
381 iter->cmd = iter->doit.cmd | iter->dumpit.cmd;
382 iter->flags = iter->doit.flags | iter->dumpit.flags;
388 genl_op_iter_copy(struct genl_op_iter *dst, struct genl_op_iter *src)
393 static unsigned int genl_op_iter_idx(struct genl_op_iter *iter)
395 return iter->cmd_idx;
398 static int genl_allocate_reserve_groups(int n_groups, int *first_id)
400 unsigned long *new_groups;
408 id = find_first_zero_bit(mc_groups,
412 id = find_next_zero_bit(mc_groups,
413 mc_groups_longs * BITS_PER_LONG,
418 i < min_t(int, id + n_groups,
419 mc_groups_longs * BITS_PER_LONG);
421 if (test_bit(i, mc_groups)) {
428 if (id + n_groups > mc_groups_longs * BITS_PER_LONG) {
429 unsigned long new_longs = mc_groups_longs +
430 BITS_TO_LONGS(n_groups);
431 size_t nlen = new_longs * sizeof(unsigned long);
433 if (mc_groups == &mc_group_start) {
434 new_groups = kzalloc(nlen, GFP_KERNEL);
437 mc_groups = new_groups;
438 *mc_groups = mc_group_start;
440 new_groups = krealloc(mc_groups, nlen,
444 mc_groups = new_groups;
445 for (i = 0; i < BITS_TO_LONGS(n_groups); i++)
446 mc_groups[mc_groups_longs + i] = 0;
448 mc_groups_longs = new_longs;
452 for (i = id; i < id + n_groups; i++)
453 set_bit(i, mc_groups);
458 static struct genl_family genl_ctrl;
460 static int genl_validate_assign_mc_groups(struct genl_family *family)
463 int n_groups = family->n_mcgrps;
465 bool groups_allocated = false;
470 for (i = 0; i < n_groups; i++) {
471 const struct genl_multicast_group *grp = &family->mcgrps[i];
473 if (WARN_ON(grp->name[0] == '\0'))
475 if (WARN_ON(!string_is_terminated(grp->name, GENL_NAMSIZ)))
479 /* special-case our own group and hacks */
480 if (family == &genl_ctrl) {
481 first_id = GENL_ID_CTRL;
482 BUG_ON(n_groups != 1);
483 } else if (strcmp(family->name, "NET_DM") == 0) {
485 BUG_ON(n_groups != 1);
486 } else if (family->id == GENL_ID_VFS_DQUOT) {
487 first_id = GENL_ID_VFS_DQUOT;
488 BUG_ON(n_groups != 1);
489 } else if (family->id == GENL_ID_PMCRAID) {
490 first_id = GENL_ID_PMCRAID;
491 BUG_ON(n_groups != 1);
493 groups_allocated = true;
494 err = genl_allocate_reserve_groups(n_groups, &first_id);
499 family->mcgrp_offset = first_id;
501 /* if still initializing, can't and don't need to realloc bitmaps */
502 if (!init_net.genl_sock)
505 if (family->netnsok) {
508 netlink_table_grab();
510 for_each_net_rcu(net) {
511 err = __netlink_change_ngroups(net->genl_sock,
512 mc_groups_longs * BITS_PER_LONG);
515 * No need to roll back, can only fail if
516 * memory allocation fails and then the
517 * number of _possible_ groups has been
518 * increased on some sockets which is ok.
524 netlink_table_ungrab();
526 err = netlink_change_ngroups(init_net.genl_sock,
527 mc_groups_longs * BITS_PER_LONG);
530 if (groups_allocated && err) {
531 for (i = 0; i < family->n_mcgrps; i++)
532 clear_bit(family->mcgrp_offset + i, mc_groups);
538 static void genl_unregister_mc_groups(const struct genl_family *family)
543 netlink_table_grab();
545 for_each_net_rcu(net) {
546 for (i = 0; i < family->n_mcgrps; i++)
547 __netlink_clear_multicast_users(
548 net->genl_sock, family->mcgrp_offset + i);
551 netlink_table_ungrab();
553 for (i = 0; i < family->n_mcgrps; i++) {
554 int grp_id = family->mcgrp_offset + i;
557 clear_bit(grp_id, mc_groups);
558 genl_ctrl_event(CTRL_CMD_DELMCAST_GRP, family,
559 &family->mcgrps[i], grp_id);
563 static bool genl_split_op_check(const struct genl_split_ops *op)
565 if (WARN_ON(hweight8(op->flags & (GENL_CMD_CAP_DO |
566 GENL_CMD_CAP_DUMP)) != 1))
571 static int genl_validate_ops(const struct genl_family *family)
573 struct genl_op_iter i, j;
576 if (WARN_ON(family->n_ops && !family->ops) ||
577 WARN_ON(family->n_small_ops && !family->small_ops) ||
578 WARN_ON(family->n_split_ops && !family->split_ops))
581 for (genl_op_iter_init(family, &i); genl_op_iter_next(&i); ) {
582 if (!(i.flags & (GENL_CMD_CAP_DO | GENL_CMD_CAP_DUMP)))
585 if (WARN_ON(i.cmd >= family->resv_start_op &&
586 (i.doit.validate || i.dumpit.validate)))
589 genl_op_iter_copy(&j, &i);
590 while (genl_op_iter_next(&j)) {
596 if (family->n_split_ops) {
597 if (genl_split_op_check(&family->split_ops[0]))
601 for (s = 1; s < family->n_split_ops; s++) {
602 const struct genl_split_ops *a, *b;
604 a = &family->split_ops[s - 1];
605 b = &family->split_ops[s];
607 if (genl_split_op_check(b))
610 /* Check sort order */
611 if (a->cmd < b->cmd) {
613 } else if (a->cmd > b->cmd) {
618 if (a->internal_flags != b->internal_flags ||
619 ((a->flags ^ b->flags) & ~(GENL_CMD_CAP_DO |
620 GENL_CMD_CAP_DUMP))) {
625 if ((a->flags & GENL_CMD_CAP_DO) &&
626 (b->flags & GENL_CMD_CAP_DUMP))
636 static void *genl_sk_priv_alloc(struct genl_family *family)
640 priv = kzalloc(family->sock_priv_size, GFP_KERNEL);
642 return ERR_PTR(-ENOMEM);
644 if (family->sock_priv_init)
645 family->sock_priv_init(priv);
650 static void genl_sk_priv_free(const struct genl_family *family, void *priv)
652 if (family->sock_priv_destroy)
653 family->sock_priv_destroy(priv);
657 static int genl_sk_privs_alloc(struct genl_family *family)
659 if (!family->sock_priv_size)
662 family->sock_privs = kzalloc(sizeof(*family->sock_privs), GFP_KERNEL);
663 if (!family->sock_privs)
665 xa_init(family->sock_privs);
669 static void genl_sk_privs_free(const struct genl_family *family)
674 if (!family->sock_priv_size)
677 xa_for_each(family->sock_privs, id, priv)
678 genl_sk_priv_free(family, priv);
680 xa_destroy(family->sock_privs);
681 kfree(family->sock_privs);
684 static void genl_sk_priv_free_by_sock(struct genl_family *family,
689 if (!family->sock_priv_size)
691 priv = xa_erase(family->sock_privs, (unsigned long) sk);
694 genl_sk_priv_free(family, priv);
697 static void genl_release(struct sock *sk, unsigned long *groups)
699 struct genl_family *family;
704 idr_for_each_entry(&genl_fam_idr, family, id)
705 genl_sk_priv_free_by_sock(family, sk);
711 * __genl_sk_priv_get - Get family private pointer for socket, if exists
716 * Lookup a private memory for a Generic netlink family and specified socket.
718 * Caller should make sure this is called in RCU read locked section.
720 * Return: valid pointer on success, otherwise negative error value
721 * encoded by ERR_PTR(), NULL in case priv does not exist.
723 void *__genl_sk_priv_get(struct genl_family *family, struct sock *sk)
725 if (WARN_ON_ONCE(!family->sock_privs))
726 return ERR_PTR(-EINVAL);
727 return xa_load(family->sock_privs, (unsigned long) sk);
731 * genl_sk_priv_get - Get family private pointer for socket
736 * Lookup a private memory for a Generic netlink family and specified socket.
737 * Allocate the private memory in case it was not already done.
739 * Return: valid pointer on success, otherwise negative error value
740 * encoded by ERR_PTR().
742 void *genl_sk_priv_get(struct genl_family *family, struct sock *sk)
744 void *priv, *old_priv;
746 priv = __genl_sk_priv_get(family, sk);
750 /* priv for the family does not exist so far, create it. */
752 priv = genl_sk_priv_alloc(family);
754 return ERR_CAST(priv);
756 old_priv = xa_cmpxchg(family->sock_privs, (unsigned long) sk, NULL,
759 genl_sk_priv_free(family, priv);
760 if (xa_is_err(old_priv))
761 return ERR_PTR(xa_err(old_priv));
762 /* Race happened, priv for the socket was already inserted. */
769 * genl_register_family - register a generic netlink family
770 * @family: generic netlink family
772 * Registers the specified family after validating it first. Only one
773 * family may be registered with the same family name or identifier.
775 * The family's ops, multicast groups and module pointer must already
778 * Return 0 on success or a negative error code.
780 int genl_register_family(struct genl_family *family)
783 int start = GENL_START_ALLOC, end = GENL_MAX_ID;
785 err = genl_validate_ops(family);
791 if (genl_family_find_byname(family->name)) {
796 err = genl_sk_privs_alloc(family);
801 * Sadly, a few cases need to be special-cased
802 * due to them having previously abused the API
803 * and having used their family ID also as their
804 * multicast group ID, so we use reserved IDs
805 * for both to be sure we can do that mapping.
807 if (family == &genl_ctrl) {
808 /* and this needs to be special for initial family lookups */
809 start = end = GENL_ID_CTRL;
810 } else if (strcmp(family->name, "pmcraid") == 0) {
811 start = end = GENL_ID_PMCRAID;
812 } else if (strcmp(family->name, "VFS_DQUOT") == 0) {
813 start = end = GENL_ID_VFS_DQUOT;
816 family->id = idr_alloc_cyclic(&genl_fam_idr, family,
817 start, end + 1, GFP_KERNEL);
818 if (family->id < 0) {
820 goto errout_sk_privs_free;
823 err = genl_validate_assign_mc_groups(family);
829 /* send all events */
830 genl_ctrl_event(CTRL_CMD_NEWFAMILY, family, NULL, 0);
831 for (i = 0; i < family->n_mcgrps; i++)
832 genl_ctrl_event(CTRL_CMD_NEWMCAST_GRP, family,
833 &family->mcgrps[i], family->mcgrp_offset + i);
838 idr_remove(&genl_fam_idr, family->id);
839 errout_sk_privs_free:
840 genl_sk_privs_free(family);
845 EXPORT_SYMBOL(genl_register_family);
848 * genl_unregister_family - unregister generic netlink family
849 * @family: generic netlink family
851 * Unregisters the specified family.
853 * Returns 0 on success or a negative error code.
855 int genl_unregister_family(const struct genl_family *family)
859 if (!genl_family_find_byid(family->id)) {
864 genl_unregister_mc_groups(family);
866 idr_remove(&genl_fam_idr, family->id);
869 wait_event(genl_sk_destructing_waitq,
870 atomic_read(&genl_sk_destructing_cnt) == 0);
872 genl_sk_privs_free(family);
876 genl_ctrl_event(CTRL_CMD_DELFAMILY, family, NULL, 0);
880 EXPORT_SYMBOL(genl_unregister_family);
883 * genlmsg_put - Add generic netlink header to netlink message
884 * @skb: socket buffer holding the message
885 * @portid: netlink portid the message is addressed to
886 * @seq: sequence number (usually the one of the sender)
887 * @family: generic netlink family
888 * @flags: netlink message flags
889 * @cmd: generic netlink command
891 * Returns pointer to user specific header
893 void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
894 const struct genl_family *family, int flags, u8 cmd)
896 struct nlmsghdr *nlh;
897 struct genlmsghdr *hdr;
899 nlh = nlmsg_put(skb, portid, seq, family->id, GENL_HDRLEN +
900 family->hdrsize, flags);
904 hdr = nlmsg_data(nlh);
906 hdr->version = family->version;
909 return (char *) hdr + GENL_HDRLEN;
911 EXPORT_SYMBOL(genlmsg_put);
913 static struct genl_dumpit_info *genl_dumpit_info_alloc(void)
915 return kmalloc(sizeof(struct genl_dumpit_info), GFP_KERNEL);
918 static void genl_dumpit_info_free(const struct genl_dumpit_info *info)
923 static struct nlattr **
924 genl_family_rcv_msg_attrs_parse(const struct genl_family *family,
925 struct nlmsghdr *nlh,
926 struct netlink_ext_ack *extack,
927 const struct genl_split_ops *ops,
929 enum genl_validate_flags no_strict_flag)
931 enum netlink_validation validate = ops->validate & no_strict_flag ?
932 NL_VALIDATE_LIBERAL :
934 struct nlattr **attrbuf;
940 attrbuf = kmalloc_array(ops->maxattr + 1,
941 sizeof(struct nlattr *), GFP_KERNEL);
943 return ERR_PTR(-ENOMEM);
945 err = __nlmsg_parse(nlh, hdrlen, attrbuf, ops->maxattr, ops->policy,
954 static void genl_family_rcv_msg_attrs_free(struct nlattr **attrbuf)
959 struct genl_start_context {
960 const struct genl_family *family;
961 struct nlmsghdr *nlh;
962 struct netlink_ext_ack *extack;
963 const struct genl_split_ops *ops;
967 static int genl_start(struct netlink_callback *cb)
969 struct genl_start_context *ctx = cb->data;
970 const struct genl_split_ops *ops;
971 struct genl_dumpit_info *info;
972 struct nlattr **attrs = NULL;
976 if (!(ops->validate & GENL_DONT_VALIDATE_DUMP) &&
977 ctx->nlh->nlmsg_len < nlmsg_msg_size(ctx->hdrlen))
980 attrs = genl_family_rcv_msg_attrs_parse(ctx->family, ctx->nlh, ctx->extack,
982 GENL_DONT_VALIDATE_DUMP_STRICT);
984 return PTR_ERR(attrs);
986 info = genl_dumpit_info_alloc();
988 genl_family_rcv_msg_attrs_free(attrs);
992 info->info.family = ctx->family;
993 info->info.snd_seq = cb->nlh->nlmsg_seq;
994 info->info.snd_portid = NETLINK_CB(cb->skb).portid;
995 info->info.nlhdr = cb->nlh;
996 info->info.genlhdr = nlmsg_data(cb->nlh);
997 info->info.attrs = attrs;
998 genl_info_net_set(&info->info, sock_net(cb->skb->sk));
999 info->info.extack = cb->extack;
1000 memset(&info->info.ctx, 0, sizeof(info->info.ctx));
1004 genl_op_lock(ctx->family);
1005 rc = ops->start(cb);
1006 genl_op_unlock(ctx->family);
1010 genl_family_rcv_msg_attrs_free(info->info.attrs);
1011 genl_dumpit_info_free(info);
1017 static int genl_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
1019 struct genl_dumpit_info *dump_info = cb->data;
1020 const struct genl_split_ops *ops = &dump_info->op;
1021 struct genl_info *info = &dump_info->info;
1024 info->extack = cb->extack;
1026 genl_op_lock(info->family);
1027 rc = ops->dumpit(skb, cb);
1028 genl_op_unlock(info->family);
1032 static int genl_done(struct netlink_callback *cb)
1034 struct genl_dumpit_info *dump_info = cb->data;
1035 const struct genl_split_ops *ops = &dump_info->op;
1036 struct genl_info *info = &dump_info->info;
1039 info->extack = cb->extack;
1042 genl_op_lock(info->family);
1044 genl_op_unlock(info->family);
1046 genl_family_rcv_msg_attrs_free(info->attrs);
1047 genl_dumpit_info_free(dump_info);
1051 static int genl_family_rcv_msg_dumpit(const struct genl_family *family,
1052 struct sk_buff *skb,
1053 struct nlmsghdr *nlh,
1054 struct netlink_ext_ack *extack,
1055 const struct genl_split_ops *ops,
1056 int hdrlen, struct net *net)
1058 struct genl_start_context ctx;
1059 struct netlink_dump_control c = {
1060 .module = family->module,
1062 .start = genl_start,
1063 .dump = genl_dumpit,
1069 ctx.family = family;
1071 ctx.extack = extack;
1073 ctx.hdrlen = hdrlen;
1075 genl_op_unlock(family);
1076 err = __netlink_dump_start(net->genl_sock, skb, nlh, &c);
1077 genl_op_lock(family);
1082 static int genl_family_rcv_msg_doit(const struct genl_family *family,
1083 struct sk_buff *skb,
1084 struct nlmsghdr *nlh,
1085 struct netlink_ext_ack *extack,
1086 const struct genl_split_ops *ops,
1087 int hdrlen, struct net *net)
1089 struct nlattr **attrbuf;
1090 struct genl_info info;
1093 attrbuf = genl_family_rcv_msg_attrs_parse(family, nlh, extack,
1095 GENL_DONT_VALIDATE_STRICT);
1096 if (IS_ERR(attrbuf))
1097 return PTR_ERR(attrbuf);
1099 info.snd_seq = nlh->nlmsg_seq;
1100 info.snd_portid = NETLINK_CB(skb).portid;
1101 info.family = family;
1103 info.genlhdr = nlmsg_data(nlh);
1104 info.attrs = attrbuf;
1105 info.extack = extack;
1106 genl_info_net_set(&info, net);
1107 memset(&info.ctx, 0, sizeof(info.ctx));
1109 if (ops->pre_doit) {
1110 err = ops->pre_doit(ops, skb, &info);
1115 err = ops->doit(skb, &info);
1118 ops->post_doit(ops, skb, &info);
1121 genl_family_rcv_msg_attrs_free(attrbuf);
1126 static int genl_header_check(const struct genl_family *family,
1127 struct nlmsghdr *nlh, struct genlmsghdr *hdr,
1128 struct netlink_ext_ack *extack)
1132 /* Only for commands added after we started validating */
1133 if (hdr->cmd < family->resv_start_op)
1136 if (hdr->reserved) {
1137 NL_SET_ERR_MSG(extack, "genlmsghdr.reserved field is not 0");
1141 /* Old netlink flags have pretty loose semantics, allow only the flags
1142 * consumed by the core where we can enforce the meaning.
1144 flags = nlh->nlmsg_flags;
1145 if ((flags & NLM_F_DUMP) == NLM_F_DUMP) /* DUMP is 2 bits */
1146 flags &= ~NLM_F_DUMP;
1147 if (flags & ~(NLM_F_REQUEST | NLM_F_ACK | NLM_F_ECHO)) {
1148 NL_SET_ERR_MSG(extack,
1149 "ambiguous or reserved bits set in nlmsg_flags");
1156 static int genl_family_rcv_msg(const struct genl_family *family,
1157 struct sk_buff *skb,
1158 struct nlmsghdr *nlh,
1159 struct netlink_ext_ack *extack)
1161 struct net *net = sock_net(skb->sk);
1162 struct genlmsghdr *hdr = nlmsg_data(nlh);
1163 struct genl_split_ops op;
1167 /* this family doesn't exist in this netns */
1168 if (!family->netnsok && !net_eq(net, &init_net))
1171 hdrlen = GENL_HDRLEN + family->hdrsize;
1172 if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen))
1175 if (genl_header_check(family, nlh, hdr, extack))
1178 flags = (nlh->nlmsg_flags & NLM_F_DUMP) == NLM_F_DUMP ?
1179 GENL_CMD_CAP_DUMP : GENL_CMD_CAP_DO;
1180 if (genl_get_cmd(hdr->cmd, flags, family, &op))
1183 if ((op.flags & GENL_ADMIN_PERM) &&
1184 !netlink_capable(skb, CAP_NET_ADMIN))
1187 if ((op.flags & GENL_UNS_ADMIN_PERM) &&
1188 !netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
1191 if (flags & GENL_CMD_CAP_DUMP)
1192 return genl_family_rcv_msg_dumpit(family, skb, nlh, extack,
1195 return genl_family_rcv_msg_doit(family, skb, nlh, extack,
1199 static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
1200 struct netlink_ext_ack *extack)
1202 const struct genl_family *family;
1205 family = genl_family_find_byid(nlh->nlmsg_type);
1209 genl_op_lock(family);
1210 err = genl_family_rcv_msg(family, skb, nlh, extack);
1211 genl_op_unlock(family);
1216 static void genl_rcv(struct sk_buff *skb)
1218 down_read(&cb_lock);
1219 netlink_rcv_skb(skb, &genl_rcv_msg);
1223 /**************************************************************************
1225 **************************************************************************/
1227 static struct genl_family genl_ctrl;
1229 static int ctrl_fill_info(const struct genl_family *family, u32 portid, u32 seq,
1230 u32 flags, struct sk_buff *skb, u8 cmd)
1232 struct genl_op_iter i;
1235 hdr = genlmsg_put(skb, portid, seq, &genl_ctrl, flags, cmd);
1239 if (nla_put_string(skb, CTRL_ATTR_FAMILY_NAME, family->name) ||
1240 nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, family->id) ||
1241 nla_put_u32(skb, CTRL_ATTR_VERSION, family->version) ||
1242 nla_put_u32(skb, CTRL_ATTR_HDRSIZE, family->hdrsize) ||
1243 nla_put_u32(skb, CTRL_ATTR_MAXATTR, family->maxattr))
1244 goto nla_put_failure;
1246 if (genl_op_iter_init(family, &i)) {
1247 struct nlattr *nla_ops;
1249 nla_ops = nla_nest_start_noflag(skb, CTRL_ATTR_OPS);
1250 if (nla_ops == NULL)
1251 goto nla_put_failure;
1253 while (genl_op_iter_next(&i)) {
1254 struct nlattr *nest;
1258 if (i.doit.policy || i.dumpit.policy)
1259 op_flags |= GENL_CMD_CAP_HASPOL;
1261 nest = nla_nest_start_noflag(skb, genl_op_iter_idx(&i));
1263 goto nla_put_failure;
1265 if (nla_put_u32(skb, CTRL_ATTR_OP_ID, i.cmd) ||
1266 nla_put_u32(skb, CTRL_ATTR_OP_FLAGS, op_flags))
1267 goto nla_put_failure;
1269 nla_nest_end(skb, nest);
1272 nla_nest_end(skb, nla_ops);
1275 if (family->n_mcgrps) {
1276 struct nlattr *nla_grps;
1279 nla_grps = nla_nest_start_noflag(skb, CTRL_ATTR_MCAST_GROUPS);
1280 if (nla_grps == NULL)
1281 goto nla_put_failure;
1283 for (i = 0; i < family->n_mcgrps; i++) {
1284 struct nlattr *nest;
1285 const struct genl_multicast_group *grp;
1287 grp = &family->mcgrps[i];
1289 nest = nla_nest_start_noflag(skb, i + 1);
1291 goto nla_put_failure;
1293 if (nla_put_u32(skb, CTRL_ATTR_MCAST_GRP_ID,
1294 family->mcgrp_offset + i) ||
1295 nla_put_string(skb, CTRL_ATTR_MCAST_GRP_NAME,
1297 goto nla_put_failure;
1299 nla_nest_end(skb, nest);
1301 nla_nest_end(skb, nla_grps);
1304 genlmsg_end(skb, hdr);
1308 genlmsg_cancel(skb, hdr);
1312 static int ctrl_fill_mcgrp_info(const struct genl_family *family,
1313 const struct genl_multicast_group *grp,
1314 int grp_id, u32 portid, u32 seq, u32 flags,
1315 struct sk_buff *skb, u8 cmd)
1318 struct nlattr *nla_grps;
1319 struct nlattr *nest;
1321 hdr = genlmsg_put(skb, portid, seq, &genl_ctrl, flags, cmd);
1325 if (nla_put_string(skb, CTRL_ATTR_FAMILY_NAME, family->name) ||
1326 nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, family->id))
1327 goto nla_put_failure;
1329 nla_grps = nla_nest_start_noflag(skb, CTRL_ATTR_MCAST_GROUPS);
1330 if (nla_grps == NULL)
1331 goto nla_put_failure;
1333 nest = nla_nest_start_noflag(skb, 1);
1335 goto nla_put_failure;
1337 if (nla_put_u32(skb, CTRL_ATTR_MCAST_GRP_ID, grp_id) ||
1338 nla_put_string(skb, CTRL_ATTR_MCAST_GRP_NAME,
1340 goto nla_put_failure;
1342 nla_nest_end(skb, nest);
1343 nla_nest_end(skb, nla_grps);
1345 genlmsg_end(skb, hdr);
1349 genlmsg_cancel(skb, hdr);
1353 static int ctrl_dumpfamily(struct sk_buff *skb, struct netlink_callback *cb)
1356 struct genl_family *rt;
1357 struct net *net = sock_net(skb->sk);
1358 int fams_to_skip = cb->args[0];
1362 idr_for_each_entry(&genl_fam_idr, rt, id) {
1363 if (!rt->netnsok && !net_eq(net, &init_net))
1366 if (n++ < fams_to_skip)
1369 err = ctrl_fill_info(rt, NETLINK_CB(cb->skb).portid,
1370 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1371 skb, CTRL_CMD_NEWFAMILY);
1382 static struct sk_buff *ctrl_build_family_msg(const struct genl_family *family,
1383 u32 portid, int seq, u8 cmd)
1385 struct sk_buff *skb;
1388 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1390 return ERR_PTR(-ENOBUFS);
1392 err = ctrl_fill_info(family, portid, seq, 0, skb, cmd);
1395 return ERR_PTR(err);
1401 static struct sk_buff *
1402 ctrl_build_mcgrp_msg(const struct genl_family *family,
1403 const struct genl_multicast_group *grp,
1404 int grp_id, u32 portid, int seq, u8 cmd)
1406 struct sk_buff *skb;
1409 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1411 return ERR_PTR(-ENOBUFS);
1413 err = ctrl_fill_mcgrp_info(family, grp, grp_id, portid,
1417 return ERR_PTR(err);
1423 static const struct nla_policy ctrl_policy_family[] = {
1424 [CTRL_ATTR_FAMILY_ID] = { .type = NLA_U16 },
1425 [CTRL_ATTR_FAMILY_NAME] = { .type = NLA_NUL_STRING,
1426 .len = GENL_NAMSIZ - 1 },
1429 static int ctrl_getfamily(struct sk_buff *skb, struct genl_info *info)
1431 struct sk_buff *msg;
1432 const struct genl_family *res = NULL;
1435 if (info->attrs[CTRL_ATTR_FAMILY_ID]) {
1436 u16 id = nla_get_u16(info->attrs[CTRL_ATTR_FAMILY_ID]);
1437 res = genl_family_find_byid(id);
1441 if (info->attrs[CTRL_ATTR_FAMILY_NAME]) {
1444 name = nla_data(info->attrs[CTRL_ATTR_FAMILY_NAME]);
1445 res = genl_family_find_byname(name);
1446 #ifdef CONFIG_MODULES
1450 request_module("net-pf-%d-proto-%d-family-%s",
1451 PF_NETLINK, NETLINK_GENERIC, name);
1452 down_read(&cb_lock);
1454 res = genl_family_find_byname(name);
1463 if (!res->netnsok && !net_eq(genl_info_net(info), &init_net)) {
1464 /* family doesn't exist here */
1468 msg = ctrl_build_family_msg(res, info->snd_portid, info->snd_seq,
1469 CTRL_CMD_NEWFAMILY);
1471 return PTR_ERR(msg);
1473 return genlmsg_reply(msg, info);
1476 static int genl_ctrl_event(int event, const struct genl_family *family,
1477 const struct genl_multicast_group *grp,
1480 struct sk_buff *msg;
1482 /* genl is still initialising */
1483 if (!init_net.genl_sock)
1487 case CTRL_CMD_NEWFAMILY:
1488 case CTRL_CMD_DELFAMILY:
1490 msg = ctrl_build_family_msg(family, 0, 0, event);
1492 case CTRL_CMD_NEWMCAST_GRP:
1493 case CTRL_CMD_DELMCAST_GRP:
1495 msg = ctrl_build_mcgrp_msg(family, grp, grp_id, 0, 0, event);
1502 return PTR_ERR(msg);
1504 if (!family->netnsok)
1505 genlmsg_multicast_netns(&genl_ctrl, &init_net, msg, 0,
1508 genlmsg_multicast_allns(&genl_ctrl, msg, 0, 0);
1513 struct ctrl_dump_policy_ctx {
1514 struct netlink_policy_dump_state *state;
1515 const struct genl_family *rt;
1516 struct genl_op_iter *op_iter;
1523 static const struct nla_policy ctrl_policy_policy[] = {
1524 [CTRL_ATTR_FAMILY_ID] = { .type = NLA_U16 },
1525 [CTRL_ATTR_FAMILY_NAME] = { .type = NLA_NUL_STRING,
1526 .len = GENL_NAMSIZ - 1 },
1527 [CTRL_ATTR_OP] = { .type = NLA_U32 },
1530 static int ctrl_dumppolicy_start(struct netlink_callback *cb)
1532 const struct genl_dumpit_info *info = genl_dumpit_info(cb);
1533 struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
1534 struct nlattr **tb = info->info.attrs;
1535 const struct genl_family *rt;
1536 struct genl_op_iter i;
1539 BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx));
1541 if (!tb[CTRL_ATTR_FAMILY_ID] && !tb[CTRL_ATTR_FAMILY_NAME])
1544 if (tb[CTRL_ATTR_FAMILY_ID]) {
1545 ctx->fam_id = nla_get_u16(tb[CTRL_ATTR_FAMILY_ID]);
1547 rt = genl_family_find_byname(
1548 nla_data(tb[CTRL_ATTR_FAMILY_NAME]));
1551 ctx->fam_id = rt->id;
1554 rt = genl_family_find_byid(ctx->fam_id);
1560 if (tb[CTRL_ATTR_OP]) {
1561 struct genl_split_ops doit, dump;
1563 ctx->single_op = true;
1564 ctx->op = nla_get_u32(tb[CTRL_ATTR_OP]);
1566 err = genl_get_cmd_both(ctx->op, rt, &doit, &dump);
1568 NL_SET_BAD_ATTR(cb->extack, tb[CTRL_ATTR_OP]);
1573 err = netlink_policy_dump_add_policy(&ctx->state,
1577 goto err_free_state;
1580 err = netlink_policy_dump_add_policy(&ctx->state,
1584 goto err_free_state;
1594 ctx->op_iter = kmalloc(sizeof(*ctx->op_iter), GFP_KERNEL);
1598 genl_op_iter_init(rt, ctx->op_iter);
1599 ctx->dump_map = genl_op_iter_next(ctx->op_iter);
1601 for (genl_op_iter_init(rt, &i); genl_op_iter_next(&i); ) {
1602 if (i.doit.policy) {
1603 err = netlink_policy_dump_add_policy(&ctx->state,
1607 goto err_free_state;
1609 if (i.dumpit.policy) {
1610 err = netlink_policy_dump_add_policy(&ctx->state,
1614 goto err_free_state;
1620 goto err_free_op_iter;
1625 netlink_policy_dump_free(ctx->state);
1627 kfree(ctx->op_iter);
1631 static void *ctrl_dumppolicy_prep(struct sk_buff *skb,
1632 struct netlink_callback *cb)
1634 struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
1637 hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
1638 cb->nlh->nlmsg_seq, &genl_ctrl,
1639 NLM_F_MULTI, CTRL_CMD_GETPOLICY);
1643 if (nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, ctx->fam_id))
1649 static int ctrl_dumppolicy_put_op(struct sk_buff *skb,
1650 struct netlink_callback *cb,
1651 struct genl_split_ops *doit,
1652 struct genl_split_ops *dumpit)
1654 struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
1655 struct nlattr *nest_pol, *nest_op;
1659 /* skip if we have nothing to show */
1660 if (!doit->policy && !dumpit->policy)
1663 hdr = ctrl_dumppolicy_prep(skb, cb);
1667 nest_pol = nla_nest_start(skb, CTRL_ATTR_OP_POLICY);
1671 nest_op = nla_nest_start(skb, doit->cmd);
1676 idx = netlink_policy_dump_get_policy_idx(ctx->state,
1680 if (nla_put_u32(skb, CTRL_ATTR_POLICY_DO, idx))
1683 if (dumpit->policy) {
1684 idx = netlink_policy_dump_get_policy_idx(ctx->state,
1688 if (nla_put_u32(skb, CTRL_ATTR_POLICY_DUMP, idx))
1692 nla_nest_end(skb, nest_op);
1693 nla_nest_end(skb, nest_pol);
1694 genlmsg_end(skb, hdr);
1698 genlmsg_cancel(skb, hdr);
1702 static int ctrl_dumppolicy(struct sk_buff *skb, struct netlink_callback *cb)
1704 struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
1707 if (ctx->dump_map) {
1708 if (ctx->single_op) {
1709 struct genl_split_ops doit, dumpit;
1711 if (WARN_ON(genl_get_cmd_both(ctx->op, ctx->rt,
1715 if (ctrl_dumppolicy_put_op(skb, cb, &doit, &dumpit))
1718 /* done with the per-op policy index list */
1722 while (ctx->dump_map) {
1723 if (ctrl_dumppolicy_put_op(skb, cb,
1724 &ctx->op_iter->doit,
1725 &ctx->op_iter->dumpit))
1728 ctx->dump_map = genl_op_iter_next(ctx->op_iter);
1732 while (netlink_policy_dump_loop(ctx->state)) {
1733 struct nlattr *nest;
1735 hdr = ctrl_dumppolicy_prep(skb, cb);
1737 goto nla_put_failure;
1739 nest = nla_nest_start(skb, CTRL_ATTR_POLICY);
1741 goto nla_put_failure;
1743 if (netlink_policy_dump_write(skb, ctx->state))
1744 goto nla_put_failure;
1746 nla_nest_end(skb, nest);
1748 genlmsg_end(skb, hdr);
1754 genlmsg_cancel(skb, hdr);
1758 static int ctrl_dumppolicy_done(struct netlink_callback *cb)
1760 struct ctrl_dump_policy_ctx *ctx = (void *)cb->ctx;
1762 kfree(ctx->op_iter);
1763 netlink_policy_dump_free(ctx->state);
1767 static const struct genl_split_ops genl_ctrl_ops[] = {
1769 .cmd = CTRL_CMD_GETFAMILY,
1770 .validate = GENL_DONT_VALIDATE_STRICT,
1771 .policy = ctrl_policy_family,
1772 .maxattr = ARRAY_SIZE(ctrl_policy_family) - 1,
1773 .doit = ctrl_getfamily,
1774 .flags = GENL_CMD_CAP_DO,
1777 .cmd = CTRL_CMD_GETFAMILY,
1778 .validate = GENL_DONT_VALIDATE_DUMP,
1779 .policy = ctrl_policy_family,
1780 .maxattr = ARRAY_SIZE(ctrl_policy_family) - 1,
1781 .dumpit = ctrl_dumpfamily,
1782 .flags = GENL_CMD_CAP_DUMP,
1785 .cmd = CTRL_CMD_GETPOLICY,
1786 .policy = ctrl_policy_policy,
1787 .maxattr = ARRAY_SIZE(ctrl_policy_policy) - 1,
1788 .start = ctrl_dumppolicy_start,
1789 .dumpit = ctrl_dumppolicy,
1790 .done = ctrl_dumppolicy_done,
1791 .flags = GENL_CMD_CAP_DUMP,
1795 static const struct genl_multicast_group genl_ctrl_groups[] = {
1796 { .name = "notify", },
1799 static struct genl_family genl_ctrl __ro_after_init = {
1800 .module = THIS_MODULE,
1801 .split_ops = genl_ctrl_ops,
1802 .n_split_ops = ARRAY_SIZE(genl_ctrl_ops),
1803 .resv_start_op = CTRL_CMD_GETPOLICY + 1,
1804 .mcgrps = genl_ctrl_groups,
1805 .n_mcgrps = ARRAY_SIZE(genl_ctrl_groups),
1812 static int genl_bind(struct net *net, int group)
1814 const struct genl_family *family;
1818 down_read(&cb_lock);
1820 idr_for_each_entry(&genl_fam_idr, family, id) {
1821 const struct genl_multicast_group *grp;
1824 if (family->n_mcgrps == 0)
1827 i = group - family->mcgrp_offset;
1828 if (i < 0 || i >= family->n_mcgrps)
1831 grp = &family->mcgrps[i];
1832 if ((grp->flags & GENL_MCAST_CAP_NET_ADMIN) &&
1833 !ns_capable(net->user_ns, CAP_NET_ADMIN))
1835 if ((grp->flags & GENL_MCAST_CAP_SYS_ADMIN) &&
1836 !ns_capable(net->user_ns, CAP_SYS_ADMIN))
1849 static void genl_unbind(struct net *net, int group)
1851 const struct genl_family *family;
1854 down_read(&cb_lock);
1856 idr_for_each_entry(&genl_fam_idr, family, id) {
1859 if (family->n_mcgrps == 0)
1862 i = group - family->mcgrp_offset;
1863 if (i < 0 || i >= family->n_mcgrps)
1875 static int __net_init genl_pernet_init(struct net *net)
1877 struct netlink_kernel_cfg cfg = {
1879 .flags = NL_CFG_F_NONROOT_RECV,
1881 .unbind = genl_unbind,
1882 .release = genl_release,
1885 /* we'll bump the group number right afterwards */
1886 net->genl_sock = netlink_kernel_create(net, NETLINK_GENERIC, &cfg);
1888 if (!net->genl_sock && net_eq(net, &init_net))
1889 panic("GENL: Cannot initialize generic netlink\n");
1891 if (!net->genl_sock)
1897 static void __net_exit genl_pernet_exit(struct net *net)
1899 netlink_kernel_release(net->genl_sock);
1900 net->genl_sock = NULL;
1903 static struct pernet_operations genl_pernet_ops = {
1904 .init = genl_pernet_init,
1905 .exit = genl_pernet_exit,
1908 static int __init genl_init(void)
1912 err = genl_register_family(&genl_ctrl);
1916 err = register_pernet_subsys(&genl_pernet_ops);
1923 panic("GENL: Cannot register controller: %d\n", err);
1926 core_initcall(genl_init);
1928 static int genlmsg_mcast(struct sk_buff *skb, u32 portid, unsigned long group)
1930 struct sk_buff *tmp;
1931 struct net *net, *prev = NULL;
1932 bool delivered = false;
1936 for_each_net_rcu(net) {
1938 tmp = skb_clone(skb, GFP_ATOMIC);
1943 err = nlmsg_multicast(prev->genl_sock, tmp,
1944 portid, group, GFP_ATOMIC);
1947 else if (err != -ESRCH)
1953 err = nlmsg_multicast(prev->genl_sock, skb, portid, group, GFP_ATOMIC);
1959 else if (err != -ESRCH)
1961 return delivered ? 0 : -ESRCH;
1969 int genlmsg_multicast_allns(const struct genl_family *family,
1970 struct sk_buff *skb, u32 portid,
1973 if (WARN_ON_ONCE(group >= family->n_mcgrps))
1976 group = family->mcgrp_offset + group;
1977 return genlmsg_mcast(skb, portid, group);
1979 EXPORT_SYMBOL(genlmsg_multicast_allns);
1981 void genl_notify(const struct genl_family *family, struct sk_buff *skb,
1982 struct genl_info *info, u32 group, gfp_t flags)
1984 struct net *net = genl_info_net(info);
1985 struct sock *sk = net->genl_sock;
1987 if (WARN_ON_ONCE(group >= family->n_mcgrps))
1990 group = family->mcgrp_offset + group;
1991 nlmsg_notify(sk, skb, info->snd_portid, group,
1992 nlmsg_report(info->nlhdr), flags);
1994 EXPORT_SYMBOL(genl_notify);