2 * NETLINK Generic Netlink Family
4 * Authors: Jamal Hadi Salim
5 * Thomas Graf <tgraf@suug.ch>
6 * Johannes Berg <johannes@sipsolutions.net>
9 #include <linux/module.h>
10 #include <linux/kernel.h>
11 #include <linux/slab.h>
12 #include <linux/errno.h>
13 #include <linux/types.h>
14 #include <linux/socket.h>
15 #include <linux/string.h>
16 #include <linux/skbuff.h>
17 #include <linux/mutex.h>
18 #include <linux/bitmap.h>
19 #include <linux/rwsem.h>
21 #include <net/genetlink.h>
23 static DEFINE_MUTEX(genl_mutex
); /* serialization of message processing */
24 static DECLARE_RWSEM(cb_lock
);
28 mutex_lock(&genl_mutex
);
30 EXPORT_SYMBOL(genl_lock
);
32 void genl_unlock(void)
34 mutex_unlock(&genl_mutex
);
36 EXPORT_SYMBOL(genl_unlock
);
39 int lockdep_genl_is_held(void)
41 return lockdep_is_held(&genl_mutex
);
43 EXPORT_SYMBOL(lockdep_genl_is_held
);
46 static void genl_lock_all(void)
52 static void genl_unlock_all(void)
58 #define GENL_FAM_TAB_SIZE 16
59 #define GENL_FAM_TAB_MASK (GENL_FAM_TAB_SIZE - 1)
61 static struct list_head family_ht
[GENL_FAM_TAB_SIZE
];
63 * Bitmap of multicast groups that are currently in use.
65 * To avoid an allocation at boot of just one unsigned long,
66 * declare it global instead.
67 * Bit 0 is marked as already used since group 0 is invalid.
68 * Bit 1 is marked as already used since the drop-monitor code
69 * abuses the API and thinks it can statically use group 1.
70 * That group will typically conflict with other groups that
71 * any proper users use.
72 * Bit 17 is marked as already used since the VFS quota code
73 * also abused this API and relied on family == group ID, we
74 * cater to that by giving it a static family and group ID.
76 static unsigned long mc_group_start
= 0x3 | BIT(GENL_ID_VFS_DQUOT
);
77 static unsigned long *mc_groups
= &mc_group_start
;
78 static unsigned long mc_groups_longs
= 1;
80 static int genl_ctrl_event(int event
, void *data
);
82 static inline unsigned int genl_family_hash(unsigned int id
)
84 return id
& GENL_FAM_TAB_MASK
;
87 static inline struct list_head
*genl_family_chain(unsigned int id
)
89 return &family_ht
[genl_family_hash(id
)];
92 static struct genl_family
*genl_family_find_byid(unsigned int id
)
94 struct genl_family
*f
;
96 list_for_each_entry(f
, genl_family_chain(id
), family_list
)
103 static struct genl_family
*genl_family_find_byname(char *name
)
105 struct genl_family
*f
;
108 for (i
= 0; i
< GENL_FAM_TAB_SIZE
; i
++)
109 list_for_each_entry(f
, genl_family_chain(i
), family_list
)
110 if (strcmp(f
->name
, name
) == 0)
116 static const struct genl_ops
*genl_get_cmd(u8 cmd
, struct genl_family
*family
)
120 for (i
= 0; i
< family
->n_ops
; i
++)
121 if (family
->ops
[i
].cmd
== cmd
)
122 return &family
->ops
[i
];
127 /* Of course we are going to have problems once we hit
128 * 2^16 alive types, but that can only happen by year 2K
130 static u16
genl_generate_id(void)
132 static u16 id_gen_idx
= GENL_MIN_ID
;
135 for (i
= 0; i
<= GENL_MAX_ID
- GENL_MIN_ID
; i
++) {
136 if (id_gen_idx
!= GENL_ID_VFS_DQUOT
&&
137 !genl_family_find_byid(id_gen_idx
))
139 if (++id_gen_idx
> GENL_MAX_ID
)
140 id_gen_idx
= GENL_MIN_ID
;
146 static struct genl_multicast_group notify_grp
;
149 * genl_register_mc_group - register a multicast group
151 * Registers the specified multicast group and notifies userspace
152 * about the new group.
154 * Returns 0 on success or a negative error code.
156 * @family: The generic netlink family the group shall be registered for.
157 * @grp: The group to register, must have a name.
159 int genl_register_mc_group(struct genl_family
*family
,
160 struct genl_multicast_group
*grp
)
163 unsigned long *new_groups
;
166 BUG_ON(grp
->name
[0] == '\0');
167 BUG_ON(memchr(grp
->name
, '\0', GENL_NAMSIZ
) == NULL
);
171 /* special-case our own group and hacks */
172 if (grp
== ¬ify_grp
)
174 else if (strcmp(family
->name
, "NET_DM") == 0)
176 else if (strcmp(family
->name
, "VFS_DQUOT") == 0)
177 id
= GENL_ID_VFS_DQUOT
;
179 id
= find_first_zero_bit(mc_groups
,
180 mc_groups_longs
* BITS_PER_LONG
);
183 if (id
>= mc_groups_longs
* BITS_PER_LONG
) {
184 size_t nlen
= (mc_groups_longs
+ 1) * sizeof(unsigned long);
186 if (mc_groups
== &mc_group_start
) {
187 new_groups
= kzalloc(nlen
, GFP_KERNEL
);
192 mc_groups
= new_groups
;
193 *mc_groups
= mc_group_start
;
195 new_groups
= krealloc(mc_groups
, nlen
, GFP_KERNEL
);
200 mc_groups
= new_groups
;
201 mc_groups
[mc_groups_longs
] = 0;
206 if (family
->netnsok
) {
209 netlink_table_grab();
211 for_each_net_rcu(net
) {
212 err
= __netlink_change_ngroups(net
->genl_sock
,
213 mc_groups_longs
* BITS_PER_LONG
);
216 * No need to roll back, can only fail if
217 * memory allocation fails and then the
218 * number of _possible_ groups has been
219 * increased on some sockets which is ok.
222 netlink_table_ungrab();
227 netlink_table_ungrab();
229 err
= netlink_change_ngroups(init_net
.genl_sock
,
230 mc_groups_longs
* BITS_PER_LONG
);
236 set_bit(id
, mc_groups
);
237 list_add_tail(&grp
->list
, &family
->mcast_groups
);
238 grp
->family
= family
;
240 genl_ctrl_event(CTRL_CMD_NEWMCAST_GRP
, grp
);
245 EXPORT_SYMBOL(genl_register_mc_group
);
247 static void __genl_unregister_mc_group(struct genl_family
*family
,
248 struct genl_multicast_group
*grp
)
251 BUG_ON(grp
->family
!= family
);
253 netlink_table_grab();
255 for_each_net_rcu(net
)
256 __netlink_clear_multicast_users(net
->genl_sock
, grp
->id
);
258 netlink_table_ungrab();
261 clear_bit(grp
->id
, mc_groups
);
262 list_del(&grp
->list
);
263 genl_ctrl_event(CTRL_CMD_DELMCAST_GRP
, grp
);
269 * genl_unregister_mc_group - unregister a multicast group
271 * Unregisters the specified multicast group and notifies userspace
272 * about it. All current listeners on the group are removed.
274 * Note: It is not necessary to unregister all multicast groups before
275 * unregistering the family, unregistering the family will cause
276 * all assigned multicast groups to be unregistered automatically.
278 * @family: Generic netlink family the group belongs to.
279 * @grp: The group to unregister, must have been registered successfully
282 void genl_unregister_mc_group(struct genl_family
*family
,
283 struct genl_multicast_group
*grp
)
286 __genl_unregister_mc_group(family
, grp
);
289 EXPORT_SYMBOL(genl_unregister_mc_group
);
291 static void genl_unregister_mc_groups(struct genl_family
*family
)
293 struct genl_multicast_group
*grp
, *tmp
;
295 list_for_each_entry_safe(grp
, tmp
, &family
->mcast_groups
, list
)
296 __genl_unregister_mc_group(family
, grp
);
299 static int genl_validate_ops(struct genl_family
*family
)
301 const struct genl_ops
*ops
= family
->ops
;
302 unsigned int n_ops
= family
->n_ops
;
305 if (WARN_ON(n_ops
&& !ops
))
311 for (i
= 0; i
< n_ops
; i
++) {
312 if (ops
[i
].dumpit
== NULL
&& ops
[i
].doit
== NULL
)
314 for (j
= i
+ 1; j
< n_ops
; j
++)
315 if (ops
[i
].cmd
== ops
[j
].cmd
)
319 /* family is not registered yet, so no locking needed */
321 family
->n_ops
= n_ops
;
327 * __genl_register_family - register a generic netlink family
328 * @family: generic netlink family
330 * Registers the specified family after validating it first. Only one
331 * family may be registered with the same family name or identifier.
332 * The family id may equal GENL_ID_GENERATE causing an unique id to
333 * be automatically generated and assigned.
335 * The family's ops array must already be assigned, you can use the
336 * genl_register_family_with_ops() helper function.
338 * Return 0 on success or a negative error code.
340 int __genl_register_family(struct genl_family
*family
)
344 if (family
->id
&& family
->id
< GENL_MIN_ID
)
347 if (family
->id
> GENL_MAX_ID
)
350 err
= genl_validate_ops(family
);
354 INIT_LIST_HEAD(&family
->mcast_groups
);
358 if (genl_family_find_byname(family
->name
)) {
363 if (family
->id
== GENL_ID_GENERATE
) {
364 u16 newid
= genl_generate_id();
372 } else if (genl_family_find_byid(family
->id
)) {
377 if (family
->maxattr
&& !family
->parallel_ops
) {
378 family
->attrbuf
= kmalloc((family
->maxattr
+1) *
379 sizeof(struct nlattr
*), GFP_KERNEL
);
380 if (family
->attrbuf
== NULL
) {
385 family
->attrbuf
= NULL
;
387 list_add_tail(&family
->family_list
, genl_family_chain(family
->id
));
390 genl_ctrl_event(CTRL_CMD_NEWFAMILY
, family
);
399 EXPORT_SYMBOL(__genl_register_family
);
402 * genl_unregister_family - unregister generic netlink family
403 * @family: generic netlink family
405 * Unregisters the specified family.
407 * Returns 0 on success or a negative error code.
409 int genl_unregister_family(struct genl_family
*family
)
411 struct genl_family
*rc
;
415 genl_unregister_mc_groups(family
);
417 list_for_each_entry(rc
, genl_family_chain(family
->id
), family_list
) {
418 if (family
->id
!= rc
->id
|| strcmp(rc
->name
, family
->name
))
421 list_del(&rc
->family_list
);
425 kfree(family
->attrbuf
);
426 genl_ctrl_event(CTRL_CMD_DELFAMILY
, family
);
434 EXPORT_SYMBOL(genl_unregister_family
);
437 * genlmsg_put - Add generic netlink header to netlink message
438 * @skb: socket buffer holding the message
439 * @portid: netlink portid the message is addressed to
440 * @seq: sequence number (usually the one of the sender)
441 * @family: generic netlink family
442 * @flags: netlink message flags
443 * @cmd: generic netlink command
445 * Returns pointer to user specific header
447 void *genlmsg_put(struct sk_buff
*skb
, u32 portid
, u32 seq
,
448 struct genl_family
*family
, int flags
, u8 cmd
)
450 struct nlmsghdr
*nlh
;
451 struct genlmsghdr
*hdr
;
453 nlh
= nlmsg_put(skb
, portid
, seq
, family
->id
, GENL_HDRLEN
+
454 family
->hdrsize
, flags
);
458 hdr
= nlmsg_data(nlh
);
460 hdr
->version
= family
->version
;
463 return (char *) hdr
+ GENL_HDRLEN
;
465 EXPORT_SYMBOL(genlmsg_put
);
467 static int genl_lock_dumpit(struct sk_buff
*skb
, struct netlink_callback
*cb
)
469 /* our ops are always const - netlink API doesn't propagate that */
470 const struct genl_ops
*ops
= cb
->data
;
474 rc
= ops
->dumpit(skb
, cb
);
479 static int genl_lock_done(struct netlink_callback
*cb
)
481 /* our ops are always const - netlink API doesn't propagate that */
482 const struct genl_ops
*ops
= cb
->data
;
493 static int genl_family_rcv_msg(struct genl_family
*family
,
495 struct nlmsghdr
*nlh
)
497 const struct genl_ops
*ops
;
498 struct net
*net
= sock_net(skb
->sk
);
499 struct genl_info info
;
500 struct genlmsghdr
*hdr
= nlmsg_data(nlh
);
501 struct nlattr
**attrbuf
;
504 /* this family doesn't exist in this netns */
505 if (!family
->netnsok
&& !net_eq(net
, &init_net
))
508 hdrlen
= GENL_HDRLEN
+ family
->hdrsize
;
509 if (nlh
->nlmsg_len
< nlmsg_msg_size(hdrlen
))
512 ops
= genl_get_cmd(hdr
->cmd
, family
);
516 if ((ops
->flags
& GENL_ADMIN_PERM
) &&
517 !capable(CAP_NET_ADMIN
))
520 if ((nlh
->nlmsg_flags
& NLM_F_DUMP
) == NLM_F_DUMP
) {
523 if (ops
->dumpit
== NULL
)
526 if (!family
->parallel_ops
) {
527 struct netlink_dump_control c
= {
528 .module
= family
->module
,
529 /* we have const, but the netlink API doesn't */
531 .dump
= genl_lock_dumpit
,
532 .done
= genl_lock_done
,
536 rc
= __netlink_dump_start(net
->genl_sock
, skb
, nlh
, &c
);
540 struct netlink_dump_control c
= {
541 .module
= family
->module
,
546 rc
= __netlink_dump_start(net
->genl_sock
, skb
, nlh
, &c
);
552 if (ops
->doit
== NULL
)
555 if (family
->maxattr
&& family
->parallel_ops
) {
556 attrbuf
= kmalloc((family
->maxattr
+1) *
557 sizeof(struct nlattr
*), GFP_KERNEL
);
561 attrbuf
= family
->attrbuf
;
564 err
= nlmsg_parse(nlh
, hdrlen
, attrbuf
, family
->maxattr
,
570 info
.snd_seq
= nlh
->nlmsg_seq
;
571 info
.snd_portid
= NETLINK_CB(skb
).portid
;
573 info
.genlhdr
= nlmsg_data(nlh
);
574 info
.userhdr
= nlmsg_data(nlh
) + GENL_HDRLEN
;
575 info
.attrs
= attrbuf
;
576 genl_info_net_set(&info
, net
);
577 memset(&info
.user_ptr
, 0, sizeof(info
.user_ptr
));
579 if (family
->pre_doit
) {
580 err
= family
->pre_doit(ops
, skb
, &info
);
585 err
= ops
->doit(skb
, &info
);
587 if (family
->post_doit
)
588 family
->post_doit(ops
, skb
, &info
);
591 if (family
->parallel_ops
)
597 static int genl_rcv_msg(struct sk_buff
*skb
, struct nlmsghdr
*nlh
)
599 struct genl_family
*family
;
602 family
= genl_family_find_byid(nlh
->nlmsg_type
);
606 if (!family
->parallel_ops
)
609 err
= genl_family_rcv_msg(family
, skb
, nlh
);
611 if (!family
->parallel_ops
)
617 static void genl_rcv(struct sk_buff
*skb
)
620 netlink_rcv_skb(skb
, &genl_rcv_msg
);
624 /**************************************************************************
626 **************************************************************************/
628 static struct genl_family genl_ctrl
= {
632 .maxattr
= CTRL_ATTR_MAX
,
636 static int ctrl_fill_info(struct genl_family
*family
, u32 portid
, u32 seq
,
637 u32 flags
, struct sk_buff
*skb
, u8 cmd
)
641 hdr
= genlmsg_put(skb
, portid
, seq
, &genl_ctrl
, flags
, cmd
);
645 if (nla_put_string(skb
, CTRL_ATTR_FAMILY_NAME
, family
->name
) ||
646 nla_put_u16(skb
, CTRL_ATTR_FAMILY_ID
, family
->id
) ||
647 nla_put_u32(skb
, CTRL_ATTR_VERSION
, family
->version
) ||
648 nla_put_u32(skb
, CTRL_ATTR_HDRSIZE
, family
->hdrsize
) ||
649 nla_put_u32(skb
, CTRL_ATTR_MAXATTR
, family
->maxattr
))
650 goto nla_put_failure
;
653 struct nlattr
*nla_ops
;
656 nla_ops
= nla_nest_start(skb
, CTRL_ATTR_OPS
);
658 goto nla_put_failure
;
660 for (i
= 0; i
< family
->n_ops
; i
++) {
662 const struct genl_ops
*ops
= &family
->ops
[i
];
663 u32 op_flags
= ops
->flags
;
666 op_flags
|= GENL_CMD_CAP_DUMP
;
668 op_flags
|= GENL_CMD_CAP_DO
;
670 op_flags
|= GENL_CMD_CAP_HASPOL
;
672 nest
= nla_nest_start(skb
, i
+ 1);
674 goto nla_put_failure
;
676 if (nla_put_u32(skb
, CTRL_ATTR_OP_ID
, ops
->cmd
) ||
677 nla_put_u32(skb
, CTRL_ATTR_OP_FLAGS
, op_flags
))
678 goto nla_put_failure
;
680 nla_nest_end(skb
, nest
);
683 nla_nest_end(skb
, nla_ops
);
686 if (!list_empty(&family
->mcast_groups
)) {
687 struct genl_multicast_group
*grp
;
688 struct nlattr
*nla_grps
;
691 nla_grps
= nla_nest_start(skb
, CTRL_ATTR_MCAST_GROUPS
);
692 if (nla_grps
== NULL
)
693 goto nla_put_failure
;
695 list_for_each_entry(grp
, &family
->mcast_groups
, list
) {
698 nest
= nla_nest_start(skb
, idx
++);
700 goto nla_put_failure
;
702 if (nla_put_u32(skb
, CTRL_ATTR_MCAST_GRP_ID
, grp
->id
) ||
703 nla_put_string(skb
, CTRL_ATTR_MCAST_GRP_NAME
,
705 goto nla_put_failure
;
707 nla_nest_end(skb
, nest
);
709 nla_nest_end(skb
, nla_grps
);
712 return genlmsg_end(skb
, hdr
);
715 genlmsg_cancel(skb
, hdr
);
719 static int ctrl_fill_mcgrp_info(struct genl_multicast_group
*grp
, u32 portid
,
720 u32 seq
, u32 flags
, struct sk_buff
*skb
,
724 struct nlattr
*nla_grps
;
727 hdr
= genlmsg_put(skb
, portid
, seq
, &genl_ctrl
, flags
, cmd
);
731 if (nla_put_string(skb
, CTRL_ATTR_FAMILY_NAME
, grp
->family
->name
) ||
732 nla_put_u16(skb
, CTRL_ATTR_FAMILY_ID
, grp
->family
->id
))
733 goto nla_put_failure
;
735 nla_grps
= nla_nest_start(skb
, CTRL_ATTR_MCAST_GROUPS
);
736 if (nla_grps
== NULL
)
737 goto nla_put_failure
;
739 nest
= nla_nest_start(skb
, 1);
741 goto nla_put_failure
;
743 if (nla_put_u32(skb
, CTRL_ATTR_MCAST_GRP_ID
, grp
->id
) ||
744 nla_put_string(skb
, CTRL_ATTR_MCAST_GRP_NAME
,
746 goto nla_put_failure
;
748 nla_nest_end(skb
, nest
);
749 nla_nest_end(skb
, nla_grps
);
751 return genlmsg_end(skb
, hdr
);
754 genlmsg_cancel(skb
, hdr
);
758 static int ctrl_dumpfamily(struct sk_buff
*skb
, struct netlink_callback
*cb
)
762 struct genl_family
*rt
;
763 struct net
*net
= sock_net(skb
->sk
);
764 int chains_to_skip
= cb
->args
[0];
765 int fams_to_skip
= cb
->args
[1];
767 for (i
= chains_to_skip
; i
< GENL_FAM_TAB_SIZE
; i
++) {
769 list_for_each_entry(rt
, genl_family_chain(i
), family_list
) {
770 if (!rt
->netnsok
&& !net_eq(net
, &init_net
))
772 if (++n
< fams_to_skip
)
774 if (ctrl_fill_info(rt
, NETLINK_CB(cb
->skb
).portid
,
775 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
776 skb
, CTRL_CMD_NEWFAMILY
) < 0)
790 static struct sk_buff
*ctrl_build_family_msg(struct genl_family
*family
,
791 u32 portid
, int seq
, u8 cmd
)
796 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
798 return ERR_PTR(-ENOBUFS
);
800 err
= ctrl_fill_info(family
, portid
, seq
, 0, skb
, cmd
);
809 static struct sk_buff
*ctrl_build_mcgrp_msg(struct genl_multicast_group
*grp
,
810 u32 portid
, int seq
, u8 cmd
)
815 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
817 return ERR_PTR(-ENOBUFS
);
819 err
= ctrl_fill_mcgrp_info(grp
, portid
, seq
, 0, skb
, cmd
);
828 static const struct nla_policy ctrl_policy
[CTRL_ATTR_MAX
+1] = {
829 [CTRL_ATTR_FAMILY_ID
] = { .type
= NLA_U16
},
830 [CTRL_ATTR_FAMILY_NAME
] = { .type
= NLA_NUL_STRING
,
831 .len
= GENL_NAMSIZ
- 1 },
834 static int ctrl_getfamily(struct sk_buff
*skb
, struct genl_info
*info
)
837 struct genl_family
*res
= NULL
;
840 if (info
->attrs
[CTRL_ATTR_FAMILY_ID
]) {
841 u16 id
= nla_get_u16(info
->attrs
[CTRL_ATTR_FAMILY_ID
]);
842 res
= genl_family_find_byid(id
);
846 if (info
->attrs
[CTRL_ATTR_FAMILY_NAME
]) {
849 name
= nla_data(info
->attrs
[CTRL_ATTR_FAMILY_NAME
]);
850 res
= genl_family_find_byname(name
);
851 #ifdef CONFIG_MODULES
855 request_module("net-pf-%d-proto-%d-family-%s",
856 PF_NETLINK
, NETLINK_GENERIC
, name
);
859 res
= genl_family_find_byname(name
);
868 if (!res
->netnsok
&& !net_eq(genl_info_net(info
), &init_net
)) {
869 /* family doesn't exist here */
873 msg
= ctrl_build_family_msg(res
, info
->snd_portid
, info
->snd_seq
,
878 return genlmsg_reply(msg
, info
);
881 static int genl_ctrl_event(int event
, void *data
)
884 struct genl_family
*family
;
885 struct genl_multicast_group
*grp
;
887 /* genl is still initialising */
888 if (!init_net
.genl_sock
)
892 case CTRL_CMD_NEWFAMILY
:
893 case CTRL_CMD_DELFAMILY
:
895 msg
= ctrl_build_family_msg(family
, 0, 0, event
);
897 case CTRL_CMD_NEWMCAST_GRP
:
898 case CTRL_CMD_DELMCAST_GRP
:
900 family
= grp
->family
;
901 msg
= ctrl_build_mcgrp_msg(data
, 0, 0, event
);
910 if (!family
->netnsok
) {
911 genlmsg_multicast_netns(&init_net
, msg
, 0,
912 GENL_ID_CTRL
, GFP_KERNEL
);
915 genlmsg_multicast_allns(msg
, 0, GENL_ID_CTRL
, GFP_ATOMIC
);
922 static struct genl_ops genl_ctrl_ops
[] = {
924 .cmd
= CTRL_CMD_GETFAMILY
,
925 .doit
= ctrl_getfamily
,
926 .dumpit
= ctrl_dumpfamily
,
927 .policy
= ctrl_policy
,
931 static struct genl_multicast_group notify_grp
= {
935 static int __net_init
genl_pernet_init(struct net
*net
)
937 struct netlink_kernel_cfg cfg
= {
939 .flags
= NL_CFG_F_NONROOT_RECV
,
942 /* we'll bump the group number right afterwards */
943 net
->genl_sock
= netlink_kernel_create(net
, NETLINK_GENERIC
, &cfg
);
945 if (!net
->genl_sock
&& net_eq(net
, &init_net
))
946 panic("GENL: Cannot initialize generic netlink\n");
954 static void __net_exit
genl_pernet_exit(struct net
*net
)
956 netlink_kernel_release(net
->genl_sock
);
957 net
->genl_sock
= NULL
;
960 static struct pernet_operations genl_pernet_ops
= {
961 .init
= genl_pernet_init
,
962 .exit
= genl_pernet_exit
,
965 static int __init
genl_init(void)
969 for (i
= 0; i
< GENL_FAM_TAB_SIZE
; i
++)
970 INIT_LIST_HEAD(&family_ht
[i
]);
972 err
= genl_register_family_with_ops(&genl_ctrl
, genl_ctrl_ops
);
976 err
= register_pernet_subsys(&genl_pernet_ops
);
980 err
= genl_register_mc_group(&genl_ctrl
, ¬ify_grp
);
987 panic("GENL: Cannot register controller: %d\n", err
);
990 subsys_initcall(genl_init
);
992 static int genlmsg_mcast(struct sk_buff
*skb
, u32 portid
, unsigned long group
,
996 struct net
*net
, *prev
= NULL
;
999 for_each_net_rcu(net
) {
1001 tmp
= skb_clone(skb
, flags
);
1006 err
= nlmsg_multicast(prev
->genl_sock
, tmp
,
1007 portid
, group
, flags
);
1015 return nlmsg_multicast(prev
->genl_sock
, skb
, portid
, group
, flags
);
1021 int genlmsg_multicast_allns(struct sk_buff
*skb
, u32 portid
, unsigned int group
,
1024 return genlmsg_mcast(skb
, portid
, group
, flags
);
1026 EXPORT_SYMBOL(genlmsg_multicast_allns
);
1028 void genl_notify(struct sk_buff
*skb
, struct net
*net
, u32 portid
, u32 group
,
1029 struct nlmsghdr
*nlh
, gfp_t flags
)
1031 struct sock
*sk
= net
->genl_sock
;
1035 report
= nlmsg_report(nlh
);
1037 nlmsg_notify(sk
, skb
, portid
, group
, report
, flags
);
1039 EXPORT_SYMBOL(genl_notify
);