From 2a94fe48f32ccf7321450a2cc07f2b724a444e5b Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Tue, 19 Nov 2013 15:19:39 +0100 Subject: genetlink: make multicast groups const, prevent abuse Register generic netlink multicast groups as an array with the family and give them contiguous group IDs. Then instead of passing the global group ID to the various functions that send messages, pass the ID relative to the family - for most families that's just 0 because the only have one group. This avoids the list_head and ID in each group, adding a new field for the mcast group ID offset to the family. At the same time, this allows us to prevent abusing groups again like the quota and dropmon code did, since we can now check that a family only uses a group it owns. Signed-off-by: Johannes Berg Signed-off-by: David S. Miller --- net/core/drop_monitor.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'net/core/drop_monitor.c') diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c index 1eab1dc..9589718 100644 --- a/net/core/drop_monitor.c +++ b/net/core/drop_monitor.c @@ -106,8 +106,8 @@ static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data) return skb; } -static struct genl_multicast_group dm_mcgrp = { - .name = "events", +static struct genl_multicast_group dropmon_mcgrps[] = { + { .name = "events", }, }; static void send_dm_alert(struct work_struct *work) @@ -121,7 +121,7 @@ static void send_dm_alert(struct work_struct *work) if (skb) genlmsg_multicast(&net_drop_monitor_family, skb, 0, - dm_mcgrp.id, GFP_KERNEL); + 0, GFP_KERNEL); } /* @@ -369,19 +369,13 @@ static int __init init_net_drop_monitor(void) return -ENOSPC; } - rc = genl_register_family_with_ops(&net_drop_monitor_family, - dropmon_ops); + rc = genl_register_family_with_ops_groups(&net_drop_monitor_family, + dropmon_ops, dropmon_mcgrps); if (rc) { pr_err("Could not create drop monitor netlink family\n"); return rc; } - - rc = genl_register_mc_group(&net_drop_monitor_family, &dm_mcgrp); - if (rc) { - pr_err("Failed to register drop monitor mcast group\n"); - goto out_unreg; - } - WARN_ON(dm_mcgrp.id != NET_DM_GRP_ALERT); + WARN_ON(net_drop_monitor_family.mcgrp_offset != NET_DM_GRP_ALERT); rc = register_netdevice_notifier(&dropmon_net_notifier); if (rc < 0) { -- cgit v1.1