Lines Matching full:family
3 * NETLINK Generic Netlink Family
57 static void genl_op_lock(const struct genl_family *family) in genl_op_lock() argument
59 if (!family->parallel_ops) in genl_op_lock()
63 static void genl_op_unlock(const struct genl_family *family) in genl_op_unlock() argument
65 if (!family->parallel_ops) in genl_op_unlock()
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.
101 static int genl_ctrl_event(int event, const struct genl_family *family,
106 genl_op_fill_in_reject_policy(const struct genl_family *family, in genl_op_fill_in_reject_policy() argument
111 if (op->policy || op->cmd < family->resv_start_op) in genl_op_fill_in_reject_policy()
119 genl_op_fill_in_reject_policy_split(const struct genl_family *family, in genl_op_fill_in_reject_policy_split() argument
136 const struct genl_family *family; in genl_family_find_byname() local
139 idr_for_each_entry(&genl_fam_idr, family, id) in genl_family_find_byname()
140 if (strcmp(family->name, name) == 0) in genl_family_find_byname()
141 return family; in genl_family_find_byname()
147 const struct genl_family *family; member
156 static void genl_op_from_full(const struct genl_family *family, in genl_op_from_full() argument
159 *op = family->ops[i]; in genl_op_from_full()
162 op->maxattr = family->maxattr; in genl_op_from_full()
164 op->policy = family->policy; in genl_op_from_full()
166 genl_op_fill_in_reject_policy(family, op); in genl_op_from_full()
169 static int genl_get_cmd_full(u32 cmd, const struct genl_family *family, in genl_get_cmd_full() argument
174 for (i = 0; i < family->n_ops; i++) in genl_get_cmd_full()
175 if (family->ops[i].cmd == cmd) { in genl_get_cmd_full()
176 genl_op_from_full(family, i, op); in genl_get_cmd_full()
183 static void genl_op_from_small(const struct genl_family *family, in genl_op_from_small() argument
187 op->doit = family->small_ops[i].doit; in genl_op_from_small()
188 op->dumpit = family->small_ops[i].dumpit; in genl_op_from_small()
189 op->cmd = family->small_ops[i].cmd; in genl_op_from_small()
190 op->internal_flags = family->small_ops[i].internal_flags; in genl_op_from_small()
191 op->flags = family->small_ops[i].flags; in genl_op_from_small()
192 op->validate = family->small_ops[i].validate; in genl_op_from_small()
194 op->maxattr = family->maxattr; in genl_op_from_small()
195 op->policy = family->policy; in genl_op_from_small()
197 genl_op_fill_in_reject_policy(family, op); in genl_op_from_small()
200 static int genl_get_cmd_small(u32 cmd, const struct genl_family *family, in genl_get_cmd_small() argument
205 for (i = 0; i < family->n_small_ops; i++) in genl_get_cmd_small()
206 if (family->small_ops[i].cmd == cmd) { in genl_get_cmd_small()
207 genl_op_from_small(family, i, op); in genl_get_cmd_small()
216 const struct genl_family *family = iter->family; in genl_op_from_split() local
219 i = iter->entry_idx - family->n_ops - family->n_small_ops; in genl_op_from_split()
221 if (family->split_ops[i + cnt].flags & GENL_CMD_CAP_DO) { in genl_op_from_split()
222 iter->doit = family->split_ops[i + cnt]; in genl_op_from_split()
223 genl_op_fill_in_reject_policy_split(family, &iter->doit); in genl_op_from_split()
229 if (i + cnt < family->n_split_ops && in genl_op_from_split()
230 family->split_ops[i + cnt].flags & GENL_CMD_CAP_DUMP && in genl_op_from_split()
231 (!cnt || family->split_ops[i + cnt].cmd == iter->doit.cmd)) { in genl_op_from_split()
232 iter->dumpit = family->split_ops[i + cnt]; in genl_op_from_split()
233 genl_op_fill_in_reject_policy_split(family, &iter->dumpit); in genl_op_from_split()
244 genl_get_cmd_split(u32 cmd, u8 flag, const struct genl_family *family, in genl_get_cmd_split() argument
249 for (i = 0; i < family->n_split_ops; i++) in genl_get_cmd_split()
250 if (family->split_ops[i].cmd == cmd && in genl_get_cmd_split()
251 family->split_ops[i].flags & flag) { in genl_get_cmd_split()
252 *op = family->split_ops[i]; in genl_get_cmd_split()
261 const struct genl_family *family, in genl_cmd_full_to_split() argument
275 op->pre_doit = family->pre_doit; in genl_cmd_full_to_split()
277 op->post_doit = family->post_doit; in genl_cmd_full_to_split()
302 genl_get_cmd(u32 cmd, u8 flags, const struct genl_family *family, in genl_get_cmd() argument
308 err = genl_get_cmd_full(cmd, family, &full); in genl_get_cmd()
310 err = genl_get_cmd_small(cmd, family, &full); in genl_get_cmd()
313 return genl_cmd_full_to_split(op, family, &full, flags); in genl_get_cmd()
315 err = genl_get_cmd_split(cmd, flags, family, op); in genl_get_cmd()
325 genl_get_cmd_both(u32 cmd, const struct genl_family *family, in genl_get_cmd_both() argument
330 err1 = genl_get_cmd(cmd, GENL_CMD_CAP_DO, family, doit); in genl_get_cmd_both()
331 err2 = genl_get_cmd(cmd, GENL_CMD_CAP_DUMP, family, dumpit); in genl_get_cmd_both()
337 genl_op_iter_init(const struct genl_family *family, struct genl_op_iter *iter) in genl_op_iter_init() argument
339 iter->family = family; in genl_op_iter_init()
345 return iter->family->n_ops + in genl_op_iter_init()
346 iter->family->n_small_ops + in genl_op_iter_init()
347 iter->family->n_split_ops; in genl_op_iter_init()
352 const struct genl_family *family = iter->family; in genl_op_iter_next() local
356 if (iter->entry_idx < family->n_ops) { in genl_op_iter_next()
357 genl_op_from_full(family, iter->entry_idx, &op); in genl_op_iter_next()
358 } else if (iter->entry_idx < family->n_ops + family->n_small_ops) { in genl_op_iter_next()
359 genl_op_from_small(family, iter->entry_idx - family->n_ops, in genl_op_iter_next()
362 family->n_ops + family->n_small_ops + family->n_split_ops) { in genl_op_iter_next()
375 genl_cmd_full_to_split(&iter->doit, family, in genl_op_iter_next()
377 genl_cmd_full_to_split(&iter->dumpit, family, in genl_op_iter_next()
460 static int genl_validate_assign_mc_groups(struct genl_family *family) in genl_validate_assign_mc_groups() argument
463 int n_groups = family->n_mcgrps; in genl_validate_assign_mc_groups()
471 const struct genl_multicast_group *grp = &family->mcgrps[i]; in genl_validate_assign_mc_groups()
480 if (family == &genl_ctrl) { in genl_validate_assign_mc_groups()
483 } else if (strcmp(family->name, "NET_DM") == 0) { in genl_validate_assign_mc_groups()
486 } else if (family->id == GENL_ID_VFS_DQUOT) { in genl_validate_assign_mc_groups()
489 } else if (family->id == GENL_ID_PMCRAID) { in genl_validate_assign_mc_groups()
499 family->mcgrp_offset = first_id; in genl_validate_assign_mc_groups()
505 if (family->netnsok) { in genl_validate_assign_mc_groups()
531 for (i = 0; i < family->n_mcgrps; i++) in genl_validate_assign_mc_groups()
532 clear_bit(family->mcgrp_offset + i, mc_groups); in genl_validate_assign_mc_groups()
538 static void genl_unregister_mc_groups(const struct genl_family *family) in genl_unregister_mc_groups() argument
546 for (i = 0; i < family->n_mcgrps; i++) in genl_unregister_mc_groups()
548 net->genl_sock, family->mcgrp_offset + i); in genl_unregister_mc_groups()
553 for (i = 0; i < family->n_mcgrps; i++) { in genl_unregister_mc_groups()
554 int grp_id = family->mcgrp_offset + i; in genl_unregister_mc_groups()
558 genl_ctrl_event(CTRL_CMD_DELMCAST_GRP, family, in genl_unregister_mc_groups()
559 &family->mcgrps[i], grp_id); in genl_unregister_mc_groups()
571 static int genl_validate_ops(const struct genl_family *family) in genl_validate_ops() argument
576 if (WARN_ON(family->n_ops && !family->ops) || in genl_validate_ops()
577 WARN_ON(family->n_small_ops && !family->small_ops) || in genl_validate_ops()
578 WARN_ON(family->n_split_ops && !family->split_ops)) in genl_validate_ops()
581 for (genl_op_iter_init(family, &i); genl_op_iter_next(&i); ) { in genl_validate_ops()
585 if (WARN_ON(i.cmd >= family->resv_start_op && in genl_validate_ops()
596 if (family->n_split_ops) { in genl_validate_ops()
597 if (genl_split_op_check(&family->split_ops[0])) in genl_validate_ops()
601 for (s = 1; s < family->n_split_ops; s++) { in genl_validate_ops()
604 a = &family->split_ops[s - 1]; in genl_validate_ops()
605 b = &family->split_ops[s]; in genl_validate_ops()
636 static void *genl_sk_priv_alloc(struct genl_family *family) in genl_sk_priv_alloc() argument
640 priv = kzalloc(family->sock_priv_size, GFP_KERNEL); in genl_sk_priv_alloc()
644 if (family->sock_priv_init) in genl_sk_priv_alloc()
645 family->sock_priv_init(priv); in genl_sk_priv_alloc()
650 static void genl_sk_priv_free(const struct genl_family *family, void *priv) in genl_sk_priv_free() argument
652 if (family->sock_priv_destroy) in genl_sk_priv_free()
653 family->sock_priv_destroy(priv); in genl_sk_priv_free()
657 static int genl_sk_privs_alloc(struct genl_family *family) in genl_sk_privs_alloc() argument
659 if (!family->sock_priv_size) in genl_sk_privs_alloc()
662 family->sock_privs = kzalloc(sizeof(*family->sock_privs), GFP_KERNEL); in genl_sk_privs_alloc()
663 if (!family->sock_privs) in genl_sk_privs_alloc()
665 xa_init(family->sock_privs); in genl_sk_privs_alloc()
669 static void genl_sk_privs_free(const struct genl_family *family) in genl_sk_privs_free() argument
674 if (!family->sock_priv_size) in genl_sk_privs_free()
677 xa_for_each(family->sock_privs, id, priv) in genl_sk_privs_free()
678 genl_sk_priv_free(family, priv); in genl_sk_privs_free()
680 xa_destroy(family->sock_privs); in genl_sk_privs_free()
681 kfree(family->sock_privs); in genl_sk_privs_free()
684 static void genl_sk_priv_free_by_sock(struct genl_family *family, in genl_sk_priv_free_by_sock() argument
689 if (!family->sock_priv_size) in genl_sk_priv_free_by_sock()
691 priv = xa_erase(family->sock_privs, (unsigned long) sk); in genl_sk_priv_free_by_sock()
694 genl_sk_priv_free(family, priv); in genl_sk_priv_free_by_sock()
699 struct genl_family *family; in genl_release() local
704 idr_for_each_entry(&genl_fam_idr, family, id) in genl_release()
705 genl_sk_priv_free_by_sock(family, sk); in genl_release()
711 * __genl_sk_priv_get - Get family private pointer for socket, if exists
713 * @family: family
716 * Lookup a private memory for a Generic netlink family and specified socket.
723 void *__genl_sk_priv_get(struct genl_family *family, struct sock *sk) in __genl_sk_priv_get() argument
725 if (WARN_ON_ONCE(!family->sock_privs)) in __genl_sk_priv_get()
727 return xa_load(family->sock_privs, (unsigned long) sk); in __genl_sk_priv_get()
731 * genl_sk_priv_get - Get family private pointer for socket
733 * @family: family
736 * Lookup a private memory for a Generic netlink family and specified socket.
742 void *genl_sk_priv_get(struct genl_family *family, struct sock *sk) in genl_sk_priv_get() argument
746 priv = __genl_sk_priv_get(family, sk); in genl_sk_priv_get()
750 /* priv for the family does not exist so far, create it. */ in genl_sk_priv_get()
752 priv = genl_sk_priv_alloc(family); in genl_sk_priv_get()
756 old_priv = xa_cmpxchg(family->sock_privs, (unsigned long) sk, NULL, in genl_sk_priv_get()
759 genl_sk_priv_free(family, priv); in genl_sk_priv_get()
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
780 int genl_register_family(struct genl_family *family) in genl_register_family() argument
785 err = genl_validate_ops(family); in genl_register_family()
791 if (genl_family_find_byname(family->name)) { in genl_register_family()
796 err = genl_sk_privs_alloc(family); in genl_register_family()
803 * and having used their family ID also as their in genl_register_family()
807 if (family == &genl_ctrl) { in genl_register_family()
808 /* and this needs to be special for initial family lookups */ in genl_register_family()
810 } else if (strcmp(family->name, "pmcraid") == 0) { in genl_register_family()
812 } else if (strcmp(family->name, "VFS_DQUOT") == 0) { in genl_register_family()
816 family->id = idr_alloc_cyclic(&genl_fam_idr, family, in genl_register_family()
818 if (family->id < 0) { in genl_register_family()
819 err = family->id; in genl_register_family()
823 err = genl_validate_assign_mc_groups(family); in genl_register_family()
830 genl_ctrl_event(CTRL_CMD_NEWFAMILY, family, NULL, 0); in genl_register_family()
831 for (i = 0; i < family->n_mcgrps; i++) in genl_register_family()
832 genl_ctrl_event(CTRL_CMD_NEWMCAST_GRP, family, in genl_register_family()
833 &family->mcgrps[i], family->mcgrp_offset + i); in genl_register_family()
838 idr_remove(&genl_fam_idr, family->id); in genl_register_family()
840 genl_sk_privs_free(family); in genl_register_family()
848 * genl_unregister_family - unregister generic netlink family
849 * @family: generic netlink family
851 * Unregisters the specified family.
855 int genl_unregister_family(const struct genl_family *family) in genl_unregister_family() argument
859 if (!genl_family_find_byid(family->id)) { in genl_unregister_family()
864 genl_unregister_mc_groups(family); in genl_unregister_family()
866 idr_remove(&genl_fam_idr, family->id); in genl_unregister_family()
872 genl_sk_privs_free(family); in genl_unregister_family()
876 genl_ctrl_event(CTRL_CMD_DELFAMILY, family, NULL, 0); in genl_unregister_family()
887 * @family: generic netlink family
894 const struct genl_family *family, int flags, u8 cmd) in genlmsg_put() argument
899 nlh = nlmsg_put(skb, portid, seq, family->id, GENL_HDRLEN + in genlmsg_put()
900 family->hdrsize, flags); in genlmsg_put()
906 hdr->version = family->version; in genlmsg_put()
924 genl_family_rcv_msg_attrs_parse(const struct genl_family *family, in genl_family_rcv_msg_attrs_parse() argument
960 const struct genl_family *family; member
980 attrs = genl_family_rcv_msg_attrs_parse(ctx->family, ctx->nlh, ctx->extack, in genl_start()
992 info->info.family = ctx->family; in genl_start()
1004 genl_op_lock(ctx->family); in genl_start()
1006 genl_op_unlock(ctx->family); in genl_start()
1026 genl_op_lock(info->family); in genl_dumpit()
1028 genl_op_unlock(info->family); in genl_dumpit()
1042 genl_op_lock(info->family); in genl_done()
1044 genl_op_unlock(info->family); in genl_done()
1051 static int genl_family_rcv_msg_dumpit(const struct genl_family *family, in genl_family_rcv_msg_dumpit() argument
1060 .module = family->module, in genl_family_rcv_msg_dumpit()
1069 ctx.family = family; in genl_family_rcv_msg_dumpit()
1075 genl_op_unlock(family); in genl_family_rcv_msg_dumpit()
1077 genl_op_lock(family); in genl_family_rcv_msg_dumpit()
1082 static int genl_family_rcv_msg_doit(const struct genl_family *family, in genl_family_rcv_msg_doit() argument
1093 attrbuf = genl_family_rcv_msg_attrs_parse(family, nlh, extack, in genl_family_rcv_msg_doit()
1101 info.family = family; in genl_family_rcv_msg_doit()
1126 static int genl_header_check(const struct genl_family *family, in genl_header_check() argument
1133 if (hdr->cmd < family->resv_start_op) in genl_header_check()
1156 static int genl_family_rcv_msg(const struct genl_family *family, in genl_family_rcv_msg() argument
1167 /* this family doesn't exist in this netns */ in genl_family_rcv_msg()
1168 if (!family->netnsok && !net_eq(net, &init_net)) in genl_family_rcv_msg()
1171 hdrlen = GENL_HDRLEN + family->hdrsize; in genl_family_rcv_msg()
1175 if (genl_header_check(family, nlh, hdr, extack)) in genl_family_rcv_msg()
1180 if (genl_get_cmd(hdr->cmd, flags, family, &op)) in genl_family_rcv_msg()
1192 return genl_family_rcv_msg_dumpit(family, skb, nlh, extack, in genl_family_rcv_msg()
1195 return genl_family_rcv_msg_doit(family, skb, nlh, extack, in genl_family_rcv_msg()
1202 const struct genl_family *family; in genl_rcv_msg() local
1205 family = genl_family_find_byid(nlh->nlmsg_type); in genl_rcv_msg()
1206 if (family == NULL) in genl_rcv_msg()
1209 genl_op_lock(family); in genl_rcv_msg()
1210 err = genl_family_rcv_msg(family, skb, nlh, extack); in genl_rcv_msg()
1211 genl_op_unlock(family); in genl_rcv_msg()
1229 static int ctrl_fill_info(const struct genl_family *family, u32 portid, u32 seq, in ctrl_fill_info() argument
1239 if (nla_put_string(skb, CTRL_ATTR_FAMILY_NAME, family->name) || in ctrl_fill_info()
1240 nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, family->id) || in ctrl_fill_info()
1241 nla_put_u32(skb, CTRL_ATTR_VERSION, family->version) || in ctrl_fill_info()
1242 nla_put_u32(skb, CTRL_ATTR_HDRSIZE, family->hdrsize) || in ctrl_fill_info()
1243 nla_put_u32(skb, CTRL_ATTR_MAXATTR, family->maxattr)) in ctrl_fill_info()
1246 if (genl_op_iter_init(family, &i)) { in ctrl_fill_info()
1275 if (family->n_mcgrps) { in ctrl_fill_info()
1283 for (i = 0; i < family->n_mcgrps; i++) { in ctrl_fill_info()
1287 grp = &family->mcgrps[i]; in ctrl_fill_info()
1294 family->mcgrp_offset + i) || in ctrl_fill_info()
1312 static int ctrl_fill_mcgrp_info(const struct genl_family *family, in ctrl_fill_mcgrp_info() argument
1325 if (nla_put_string(skb, CTRL_ATTR_FAMILY_NAME, family->name) || in ctrl_fill_mcgrp_info()
1326 nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, family->id)) in ctrl_fill_mcgrp_info()
1382 static struct sk_buff *ctrl_build_family_msg(const struct genl_family *family, in ctrl_build_family_msg() argument
1392 err = ctrl_fill_info(family, portid, seq, 0, skb, cmd); in ctrl_build_family_msg()
1402 ctrl_build_mcgrp_msg(const struct genl_family *family, in ctrl_build_mcgrp_msg() argument
1413 err = ctrl_fill_mcgrp_info(family, grp, grp_id, portid, in ctrl_build_mcgrp_msg()
1450 request_module("net-pf-%d-proto-%d-family-%s", in ctrl_getfamily()
1464 /* family doesn't exist here */ in ctrl_getfamily()
1476 static int genl_ctrl_event(int event, const struct genl_family *family, in genl_ctrl_event() argument
1490 msg = ctrl_build_family_msg(family, 0, 0, event); in genl_ctrl_event()
1495 msg = ctrl_build_mcgrp_msg(family, grp, grp_id, 0, 0, event); in genl_ctrl_event()
1504 if (!family->netnsok) in genl_ctrl_event()
1814 const struct genl_family *family; in genl_bind() local
1820 idr_for_each_entry(&genl_fam_idr, family, id) { in genl_bind()
1824 if (family->n_mcgrps == 0) in genl_bind()
1827 i = group - family->mcgrp_offset; in genl_bind()
1828 if (i < 0 || i >= family->n_mcgrps) in genl_bind()
1831 grp = &family->mcgrps[i]; in genl_bind()
1839 if (family->bind) in genl_bind()
1840 family->bind(i); in genl_bind()
1851 const struct genl_family *family; in genl_unbind() local
1856 idr_for_each_entry(&genl_fam_idr, family, id) { in genl_unbind()
1859 if (family->n_mcgrps == 0) in genl_unbind()
1862 i = group - family->mcgrp_offset; in genl_unbind()
1863 if (i < 0 || i >= family->n_mcgrps) in genl_unbind()
1866 if (family->unbind) in genl_unbind()
1867 family->unbind(i); in genl_unbind()
1969 int genlmsg_multicast_allns(const struct genl_family *family, in genlmsg_multicast_allns() argument
1973 if (WARN_ON_ONCE(group >= family->n_mcgrps)) in genlmsg_multicast_allns()
1976 group = family->mcgrp_offset + group; in genlmsg_multicast_allns()
1981 void genl_notify(const struct genl_family *family, struct sk_buff *skb, in genl_notify() argument
1987 if (WARN_ON_ONCE(group >= family->n_mcgrps)) in genl_notify()
1990 group = family->mcgrp_offset + group; in genl_notify()