Lines Matching full:family

3  * NETLINK      Generic Netlink Family
70 * also abused this API and relied on family == group ID, we
71 * cater to that by giving it a static family and group ID.
87 static int genl_ctrl_event(int event, const struct genl_family *family,
92 genl_op_fill_in_reject_policy(const struct genl_family *family, in genl_op_fill_in_reject_policy() argument
97 if (op->policy || op->cmd < family->resv_start_op) in genl_op_fill_in_reject_policy()
111 const struct genl_family *family; in genl_family_find_byname() local
114 idr_for_each_entry(&genl_fam_idr, family, id) in genl_family_find_byname()
115 if (strcmp(family->name, name) == 0) in genl_family_find_byname()
116 return family; in genl_family_find_byname()
121 static int genl_get_cmd_cnt(const struct genl_family *family) in genl_get_cmd_cnt() argument
123 return family->n_ops + family->n_small_ops; in genl_get_cmd_cnt()
126 static void genl_op_from_full(const struct genl_family *family, in genl_op_from_full() argument
129 *op = family->ops[i]; in genl_op_from_full()
132 op->maxattr = family->maxattr; in genl_op_from_full()
134 op->policy = family->policy; in genl_op_from_full()
136 genl_op_fill_in_reject_policy(family, op); in genl_op_from_full()
139 static int genl_get_cmd_full(u32 cmd, const struct genl_family *family, in genl_get_cmd_full() argument
144 for (i = 0; i < family->n_ops; i++) in genl_get_cmd_full()
145 if (family->ops[i].cmd == cmd) { in genl_get_cmd_full()
146 genl_op_from_full(family, i, op); in genl_get_cmd_full()
153 static void genl_op_from_small(const struct genl_family *family, in genl_op_from_small() argument
157 op->doit = family->small_ops[i].doit; in genl_op_from_small()
158 op->dumpit = family->small_ops[i].dumpit; in genl_op_from_small()
159 op->cmd = family->small_ops[i].cmd; in genl_op_from_small()
160 op->internal_flags = family->small_ops[i].internal_flags; in genl_op_from_small()
161 op->flags = family->small_ops[i].flags; in genl_op_from_small()
162 op->validate = family->small_ops[i].validate; in genl_op_from_small()
164 op->maxattr = family->maxattr; in genl_op_from_small()
165 op->policy = family->policy; in genl_op_from_small()
167 genl_op_fill_in_reject_policy(family, op); in genl_op_from_small()
170 static int genl_get_cmd_small(u32 cmd, const struct genl_family *family, in genl_get_cmd_small() argument
175 for (i = 0; i < family->n_small_ops; i++) in genl_get_cmd_small()
176 if (family->small_ops[i].cmd == cmd) { in genl_get_cmd_small()
177 genl_op_from_small(family, i, op); in genl_get_cmd_small()
184 static int genl_get_cmd(u32 cmd, const struct genl_family *family, in genl_get_cmd() argument
187 if (!genl_get_cmd_full(cmd, family, op)) in genl_get_cmd()
189 return genl_get_cmd_small(cmd, family, op); in genl_get_cmd()
193 const struct genl_family *family, in genl_get_cmd_by_index() argument
196 if (i < family->n_ops) in genl_get_cmd_by_index()
197 genl_op_from_full(family, i, op); in genl_get_cmd_by_index()
198 else if (i < family->n_ops + family->n_small_ops) in genl_get_cmd_by_index()
199 genl_op_from_small(family, i - family->n_ops, op); in genl_get_cmd_by_index()
266 static int genl_validate_assign_mc_groups(struct genl_family *family) in genl_validate_assign_mc_groups() argument
269 int n_groups = family->n_mcgrps; in genl_validate_assign_mc_groups()
277 const struct genl_multicast_group *grp = &family->mcgrps[i]; in genl_validate_assign_mc_groups()
286 if (family == &genl_ctrl) { in genl_validate_assign_mc_groups()
289 } else if (strcmp(family->name, "NET_DM") == 0) { in genl_validate_assign_mc_groups()
292 } else if (family->id == GENL_ID_VFS_DQUOT) { in genl_validate_assign_mc_groups()
295 } else if (family->id == GENL_ID_PMCRAID) { in genl_validate_assign_mc_groups()
305 family->mcgrp_offset = first_id; in genl_validate_assign_mc_groups()
311 if (family->netnsok) { in genl_validate_assign_mc_groups()
337 for (i = 0; i < family->n_mcgrps; i++) in genl_validate_assign_mc_groups()
338 clear_bit(family->mcgrp_offset + i, mc_groups); in genl_validate_assign_mc_groups()
344 static void genl_unregister_mc_groups(const struct genl_family *family) in genl_unregister_mc_groups() argument
352 for (i = 0; i < family->n_mcgrps; i++) in genl_unregister_mc_groups()
354 net->genl_sock, family->mcgrp_offset + i); in genl_unregister_mc_groups()
359 for (i = 0; i < family->n_mcgrps; i++) { in genl_unregister_mc_groups()
360 int grp_id = family->mcgrp_offset + i; in genl_unregister_mc_groups()
364 genl_ctrl_event(CTRL_CMD_DELMCAST_GRP, family, in genl_unregister_mc_groups()
365 &family->mcgrps[i], grp_id); in genl_unregister_mc_groups()
369 static int genl_validate_ops(const struct genl_family *family) in genl_validate_ops() argument
373 if (WARN_ON(family->n_ops && !family->ops) || in genl_validate_ops()
374 WARN_ON(family->n_small_ops && !family->small_ops)) in genl_validate_ops()
377 for (i = 0; i < genl_get_cmd_cnt(family); i++) { in genl_validate_ops()
380 genl_get_cmd_by_index(i, family, &op); in genl_validate_ops()
383 if (WARN_ON(op.cmd >= family->resv_start_op && op.validate)) in genl_validate_ops()
385 for (j = i + 1; j < genl_get_cmd_cnt(family); j++) { in genl_validate_ops()
388 genl_get_cmd_by_index(j, family, &op2); in genl_validate_ops()
398 * genl_register_family - register a generic netlink family
399 * @family: generic netlink family
401 * Registers the specified family after validating it first. Only one
402 * family may be registered with the same family name or identifier.
404 * The family's ops, multicast groups and module pointer must already
409 int genl_register_family(struct genl_family *family) in genl_register_family() argument
414 err = genl_validate_ops(family); in genl_register_family()
420 if (genl_family_find_byname(family->name)) { in genl_register_family()
428 * and having used their family ID also as their in genl_register_family()
432 if (family == &genl_ctrl) { in genl_register_family()
433 /* and this needs to be special for initial family lookups */ in genl_register_family()
435 } else if (strcmp(family->name, "pmcraid") == 0) { in genl_register_family()
437 } else if (strcmp(family->name, "VFS_DQUOT") == 0) { in genl_register_family()
441 family->id = idr_alloc_cyclic(&genl_fam_idr, family, in genl_register_family()
443 if (family->id < 0) { in genl_register_family()
444 err = family->id; in genl_register_family()
448 err = genl_validate_assign_mc_groups(family); in genl_register_family()
455 genl_ctrl_event(CTRL_CMD_NEWFAMILY, family, NULL, 0); in genl_register_family()
456 for (i = 0; i < family->n_mcgrps; i++) in genl_register_family()
457 genl_ctrl_event(CTRL_CMD_NEWMCAST_GRP, family, in genl_register_family()
458 &family->mcgrps[i], family->mcgrp_offset + i); in genl_register_family()
463 idr_remove(&genl_fam_idr, family->id); in genl_register_family()
471 * genl_unregister_family - unregister generic netlink family
472 * @family: generic netlink family
474 * Unregisters the specified family.
478 int genl_unregister_family(const struct genl_family *family) in genl_unregister_family() argument
482 if (!genl_family_find_byid(family->id)) { in genl_unregister_family()
487 genl_unregister_mc_groups(family); in genl_unregister_family()
489 idr_remove(&genl_fam_idr, family->id); in genl_unregister_family()
496 genl_ctrl_event(CTRL_CMD_DELFAMILY, family, NULL, 0); in genl_unregister_family()
507 * @family: generic netlink family
514 const struct genl_family *family, int flags, u8 cmd) in genlmsg_put() argument
519 nlh = nlmsg_put(skb, portid, seq, family->id, GENL_HDRLEN + in genlmsg_put()
520 family->hdrsize, flags); in genlmsg_put()
526 hdr->version = family->version; in genlmsg_put()
544 genl_family_rcv_msg_attrs_parse(const struct genl_family *family, in genl_family_rcv_msg_attrs_parse() argument
580 const struct genl_family *family; member
601 attrs = genl_family_rcv_msg_attrs_parse(ctx->family, ctx->nlh, ctx->extack, in genl_start()
613 info->family = ctx->family; in genl_start()
619 if (!ctx->family->parallel_ops) in genl_start()
622 if (!ctx->family->parallel_ops) in genl_start()
674 static int genl_family_rcv_msg_dumpit(const struct genl_family *family, in genl_family_rcv_msg_dumpit() argument
687 ctx.family = family; in genl_family_rcv_msg_dumpit()
693 if (!family->parallel_ops) { in genl_family_rcv_msg_dumpit()
695 .module = family->module, in genl_family_rcv_msg_dumpit()
707 .module = family->module, in genl_family_rcv_msg_dumpit()
720 static int genl_family_rcv_msg_doit(const struct genl_family *family, in genl_family_rcv_msg_doit() argument
734 attrbuf = genl_family_rcv_msg_attrs_parse(family, nlh, extack, in genl_family_rcv_msg_doit()
750 if (family->pre_doit) { in genl_family_rcv_msg_doit()
751 err = family->pre_doit(ops, skb, &info); in genl_family_rcv_msg_doit()
758 if (family->post_doit) in genl_family_rcv_msg_doit()
759 family->post_doit(ops, skb, &info); in genl_family_rcv_msg_doit()
767 static int genl_header_check(const struct genl_family *family, in genl_header_check() argument
774 if (hdr->cmd < family->resv_start_op) in genl_header_check()
797 static int genl_family_rcv_msg(const struct genl_family *family, in genl_family_rcv_msg() argument
807 /* this family doesn't exist in this netns */ in genl_family_rcv_msg()
808 if (!family->netnsok && !net_eq(net, &init_net)) in genl_family_rcv_msg()
811 hdrlen = GENL_HDRLEN + family->hdrsize; in genl_family_rcv_msg()
815 if (genl_header_check(family, nlh, hdr, extack)) in genl_family_rcv_msg()
818 if (genl_get_cmd(hdr->cmd, family, &op)) in genl_family_rcv_msg()
830 return genl_family_rcv_msg_dumpit(family, skb, nlh, extack, in genl_family_rcv_msg()
833 return genl_family_rcv_msg_doit(family, skb, nlh, extack, in genl_family_rcv_msg()
840 const struct genl_family *family; in genl_rcv_msg() local
843 family = genl_family_find_byid(nlh->nlmsg_type); in genl_rcv_msg()
844 if (family == NULL) in genl_rcv_msg()
847 if (!family->parallel_ops) in genl_rcv_msg()
850 err = genl_family_rcv_msg(family, skb, nlh, extack); in genl_rcv_msg()
852 if (!family->parallel_ops) in genl_rcv_msg()
871 static int ctrl_fill_info(const struct genl_family *family, u32 portid, u32 seq, in ctrl_fill_info() argument
880 if (nla_put_string(skb, CTRL_ATTR_FAMILY_NAME, family->name) || in ctrl_fill_info()
881 nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, family->id) || in ctrl_fill_info()
882 nla_put_u32(skb, CTRL_ATTR_VERSION, family->version) || in ctrl_fill_info()
883 nla_put_u32(skb, CTRL_ATTR_HDRSIZE, family->hdrsize) || in ctrl_fill_info()
884 nla_put_u32(skb, CTRL_ATTR_MAXATTR, family->maxattr)) in ctrl_fill_info()
887 if (genl_get_cmd_cnt(family)) { in ctrl_fill_info()
895 for (i = 0; i < genl_get_cmd_cnt(family); i++) { in ctrl_fill_info()
900 genl_get_cmd_by_index(i, family, &op); in ctrl_fill_info()
923 if (family->n_mcgrps) { in ctrl_fill_info()
931 for (i = 0; i < family->n_mcgrps; i++) { in ctrl_fill_info()
935 grp = &family->mcgrps[i]; in ctrl_fill_info()
942 family->mcgrp_offset + i) || in ctrl_fill_info()
960 static int ctrl_fill_mcgrp_info(const struct genl_family *family, in ctrl_fill_mcgrp_info() argument
973 if (nla_put_string(skb, CTRL_ATTR_FAMILY_NAME, family->name) || in ctrl_fill_mcgrp_info()
974 nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, family->id)) in ctrl_fill_mcgrp_info()
1028 static struct sk_buff *ctrl_build_family_msg(const struct genl_family *family, in ctrl_build_family_msg() argument
1038 err = ctrl_fill_info(family, portid, seq, 0, skb, cmd); in ctrl_build_family_msg()
1048 ctrl_build_mcgrp_msg(const struct genl_family *family, in ctrl_build_mcgrp_msg() argument
1059 err = ctrl_fill_mcgrp_info(family, grp, grp_id, portid, in ctrl_build_mcgrp_msg()
1096 request_module("net-pf-%d-proto-%d-family-%s", in ctrl_getfamily()
1110 /* family doesn't exist here */ in ctrl_getfamily()
1122 static int genl_ctrl_event(int event, const struct genl_family *family, in genl_ctrl_event() argument
1136 msg = ctrl_build_family_msg(family, 0, 0, event); in genl_ctrl_event()
1141 msg = ctrl_build_mcgrp_msg(family, grp, grp_id, 0, 0, event); in genl_ctrl_event()
1150 if (!family->netnsok) { in genl_ctrl_event()
1420 const struct genl_family *family; in genl_bind() local
1426 idr_for_each_entry(&genl_fam_idr, family, id) { in genl_bind()
1430 if (family->n_mcgrps == 0) in genl_bind()
1433 i = group - family->mcgrp_offset; in genl_bind()
1434 if (i < 0 || i >= family->n_mcgrps) in genl_bind()
1437 grp = &family->mcgrps[i]; in genl_bind()
1537 int genlmsg_multicast_allns(const struct genl_family *family, in genlmsg_multicast_allns() argument
1541 if (WARN_ON_ONCE(group >= family->n_mcgrps)) in genlmsg_multicast_allns()
1544 group = family->mcgrp_offset + group; in genlmsg_multicast_allns()
1549 void genl_notify(const struct genl_family *family, struct sk_buff *skb, in genl_notify() argument
1555 if (WARN_ON_ONCE(group >= family->n_mcgrps)) in genl_notify()
1558 group = family->mcgrp_offset + group; in genl_notify()