Skip to content

Commit

Permalink
genetlink: pass family to functions using groups
Browse files Browse the repository at this point in the history
This doesn't really change anything, but prepares for the
next patch that will change the APIs to pass the group ID
within the family, rather than the global group ID.

Signed-off-by: Johannes Berg <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jmberg-intel authored and davem330 committed Nov 19, 2013
1 parent 62b68e9 commit 68eb550
Show file tree
Hide file tree
Showing 18 changed files with 133 additions and 87 deletions.
3 changes: 2 additions & 1 deletion drivers/acpi/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ int acpi_bus_generate_netlink_event(const char *device_class,
return result;
}

genlmsg_multicast(skb, 0, acpi_event_mcgrp.id, GFP_ATOMIC);
genlmsg_multicast(&acpi_event_genl_family,
skb, 0, acpi_event_mcgrp.id, GFP_ATOMIC);
return 0;
}

Expand Down
5 changes: 3 additions & 2 deletions drivers/net/team/team.c
Original file line number Diff line number Diff line change
Expand Up @@ -2677,8 +2677,9 @@ static struct genl_multicast_group team_change_event_mcgrp = {
static int team_nl_send_multicast(struct sk_buff *skb,
struct team *team, u32 portid)
{
return genlmsg_multicast_netns(dev_net(team->dev), skb, 0,
team_change_event_mcgrp.id, GFP_KERNEL);
return genlmsg_multicast_netns(&team_nl_family, dev_net(team->dev),
skb, 0, team_change_event_mcgrp.id,
GFP_KERNEL);
}

static int team_nl_send_event_options_get(struct team *team,
Expand Down
3 changes: 2 additions & 1 deletion drivers/scsi/pmcraid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,8 @@ static int pmcraid_notify_aen(
}

result =
genlmsg_multicast(skb, 0, pmcraid_event_family.id, GFP_ATOMIC);
genlmsg_multicast(&pmcraid_event_family, skb, 0,
pmcraid_event_family.id, GFP_ATOMIC);

/* If there are no listeners, genlmsg_multicast may return non-zero
* value.
Expand Down
3 changes: 2 additions & 1 deletion drivers/thermal/thermal_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,8 @@ int thermal_generate_netlink_event(struct thermal_zone_device *tz,
return result;
}

result = genlmsg_multicast(skb, 0, thermal_event_mcgrp.id, GFP_ATOMIC);
result = genlmsg_multicast(&thermal_event_genl_family, skb, 0,
thermal_event_mcgrp.id, GFP_ATOMIC);
if (result)
dev_err(&tz->device, "Failed to send netlink event:%d", result);

Expand Down
2 changes: 1 addition & 1 deletion fs/quota/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
goto attr_err_out;
genlmsg_end(skb, msg_head);

genlmsg_multicast(skb, 0, quota_mcgrp.id, GFP_NOFS);
genlmsg_multicast(&quota_genl_family, skb, 0, quota_mcgrp.id, GFP_NOFS);
return;
attr_err_out:
printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
Expand Down
3 changes: 2 additions & 1 deletion include/linux/genl_magic_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ static int CONCAT_(GENL_MAGIC_FAMILY, _genl_multicast_ ## group)( \
CONCAT_(GENL_MAGIC_FAMILY, _mcg_ ## group).id; \
if (!group_id) \
return -EINVAL; \
return genlmsg_multicast(skb, 0, group_id, flags); \
return genlmsg_multicast(&ZZZ_genl_family, skb, 0, \
group_id, flags); \
}

#include GENL_MAGIC_INCLUDE_FILE
Expand Down
22 changes: 16 additions & 6 deletions include/net/genetlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ static inline int _genl_register_family_with_ops(struct genl_family *family,
int genl_unregister_family(struct genl_family *family);
int genl_register_mc_group(struct genl_family *family,
struct genl_multicast_group *grp);
void genl_notify(struct sk_buff *skb, struct net *net, u32 portid,
void genl_notify(struct genl_family *family,
struct sk_buff *skb, struct net *net, u32 portid,
u32 group, struct nlmsghdr *nlh, gfp_t flags);

void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
Expand Down Expand Up @@ -246,41 +247,48 @@ static inline void genlmsg_cancel(struct sk_buff *skb, void *hdr)

/**
* genlmsg_multicast_netns - multicast a netlink message to a specific netns
* @family: the generic netlink family
* @net: the net namespace
* @skb: netlink message as socket buffer
* @portid: own netlink portid to avoid sending to yourself
* @group: multicast group id
* @flags: allocation flags
*/
static inline int genlmsg_multicast_netns(struct net *net, struct sk_buff *skb,
static inline int genlmsg_multicast_netns(struct genl_family *family,
struct net *net, struct sk_buff *skb,
u32 portid, unsigned int group, gfp_t flags)
{
return nlmsg_multicast(net->genl_sock, skb, portid, group, flags);
}

/**
* genlmsg_multicast - multicast a netlink message to the default netns
* @family: the generic netlink family
* @skb: netlink message as socket buffer
* @portid: own netlink portid to avoid sending to yourself
* @group: multicast group id
* @flags: allocation flags
*/
static inline int genlmsg_multicast(struct sk_buff *skb, u32 portid,
static inline int genlmsg_multicast(struct genl_family *family,
struct sk_buff *skb, u32 portid,
unsigned int group, gfp_t flags)
{
return genlmsg_multicast_netns(&init_net, skb, portid, group, flags);
return genlmsg_multicast_netns(family, &init_net, skb,
portid, group, flags);
}

/**
* genlmsg_multicast_allns - multicast a netlink message to all net namespaces
* @family: the generic netlink family
* @skb: netlink message as socket buffer
* @portid: own netlink portid to avoid sending to yourself
* @group: multicast group id
* @flags: allocation flags
*
* This function must hold the RTNL or rcu_read_lock().
*/
int genlmsg_multicast_allns(struct sk_buff *skb, u32 portid,
int genlmsg_multicast_allns(struct genl_family *family,
struct sk_buff *skb, u32 portid,
unsigned int group, gfp_t flags);

/**
Expand Down Expand Up @@ -353,6 +361,7 @@ static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)

/**
* genl_set_err - report error to genetlink broadcast listeners
* @family: the generic netlink family
* @net: the network namespace to report the error to
* @portid: the PORTID of a process that we want to skip (if any)
* @group: the broadcast group that will notice the error
Expand All @@ -361,7 +370,8 @@ static inline struct sk_buff *genlmsg_new(size_t payload, gfp_t flags)
* This function returns the number of broadcast listeners that have set the
* NETLINK_RECV_NO_ENOBUFS socket option.
*/
static inline int genl_set_err(struct net *net, u32 portid, u32 group, int code)
static inline int genl_set_err(struct genl_family *family, struct net *net,
u32 portid, u32 group, int code)
{
return netlink_set_err(net->genl_sock, portid, group, code);
}
Expand Down
3 changes: 2 additions & 1 deletion net/core/drop_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ static void send_dm_alert(struct work_struct *work)
skb = reset_per_cpu_data(data);

if (skb)
genlmsg_multicast(skb, 0, dm_mcgrp.id, GFP_KERNEL);
genlmsg_multicast(&net_drop_monitor_family, skb, 0,
dm_mcgrp.id, GFP_KERNEL);
}

/*
Expand Down
6 changes: 4 additions & 2 deletions net/hsr/hsr_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ void hsr_nl_ringerror(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN],
goto nla_put_failure;

genlmsg_end(skb, msg_head);
genlmsg_multicast(skb, 0, hsr_network_genl_mcgrp.id, GFP_ATOMIC);
genlmsg_multicast(&hsr_genl_family, skb, 0,
hsr_network_genl_mcgrp.id, GFP_ATOMIC);

return;

Expand Down Expand Up @@ -163,7 +164,8 @@ void hsr_nl_nodedown(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN])
goto nla_put_failure;

genlmsg_end(skb, msg_head);
genlmsg_multicast(skb, 0, hsr_network_genl_mcgrp.id, GFP_ATOMIC);
genlmsg_multicast(&hsr_genl_family, skb, 0,
hsr_network_genl_mcgrp.id, GFP_ATOMIC);

return;

Expand Down
2 changes: 1 addition & 1 deletion net/ieee802154/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group)
if (genlmsg_end(msg, hdr) < 0)
goto out;

return genlmsg_multicast(msg, 0, group, GFP_ATOMIC);
return genlmsg_multicast(&nl802154_family, msg, 0, group, GFP_ATOMIC);
out:
nlmsg_free(msg);
return -ENOBUFS;
Expand Down
12 changes: 7 additions & 5 deletions net/netlink/genetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,11 +883,12 @@ static int genl_ctrl_event(int event, struct genl_family *family,
return PTR_ERR(msg);

if (!family->netnsok) {
genlmsg_multicast_netns(&init_net, msg, 0,
genlmsg_multicast_netns(&genl_ctrl, &init_net, msg, 0,
GENL_ID_CTRL, GFP_KERNEL);
} else {
rcu_read_lock();
genlmsg_multicast_allns(msg, 0, GENL_ID_CTRL, GFP_ATOMIC);
genlmsg_multicast_allns(&genl_ctrl, msg, 0,
GENL_ID_CTRL, GFP_ATOMIC);
rcu_read_unlock();
}

Expand Down Expand Up @@ -993,14 +994,15 @@ static int genlmsg_mcast(struct sk_buff *skb, u32 portid, unsigned long group,
return err;
}

int genlmsg_multicast_allns(struct sk_buff *skb, u32 portid, unsigned int group,
gfp_t flags)
int genlmsg_multicast_allns(struct genl_family *family, struct sk_buff *skb,
u32 portid, unsigned int group, gfp_t flags)
{
return genlmsg_mcast(skb, portid, group, flags);
}
EXPORT_SYMBOL(genlmsg_multicast_allns);

void genl_notify(struct sk_buff *skb, struct net *net, u32 portid, u32 group,
void genl_notify(struct genl_family *family,
struct sk_buff *skb, struct net *net, u32 portid, u32 group,
struct nlmsghdr *nlh, gfp_t flags)
{
struct sock *sk = net->genl_sock;
Expand Down
39 changes: 26 additions & 13 deletions net/nfc/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ int nfc_genl_targets_found(struct nfc_dev *dev)

genlmsg_end(msg, hdr);

return genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_ATOMIC);
return genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_ATOMIC);

nla_put_failure:
genlmsg_cancel(msg, hdr);
Expand Down Expand Up @@ -223,7 +224,8 @@ int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx)

genlmsg_end(msg, hdr);

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_KERNEL);

return 0;

Expand Down Expand Up @@ -255,7 +257,8 @@ int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol)

genlmsg_end(msg, hdr);

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_KERNEL);

return 0;

Expand Down Expand Up @@ -285,7 +288,8 @@ int nfc_genl_tm_deactivated(struct nfc_dev *dev)

genlmsg_end(msg, hdr);

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_KERNEL);

return 0;

Expand Down Expand Up @@ -318,7 +322,8 @@ int nfc_genl_device_added(struct nfc_dev *dev)

genlmsg_end(msg, hdr);

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_KERNEL);

return 0;

Expand Down Expand Up @@ -348,7 +353,8 @@ int nfc_genl_device_removed(struct nfc_dev *dev)

genlmsg_end(msg, hdr);

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_KERNEL);

return 0;

Expand Down Expand Up @@ -414,7 +420,8 @@ int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list)

genlmsg_end(msg, hdr);

return genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_ATOMIC);
return genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_ATOMIC);

nla_put_failure:
genlmsg_cancel(msg, hdr);
Expand Down Expand Up @@ -448,7 +455,8 @@ int nfc_genl_se_added(struct nfc_dev *dev, u32 se_idx, u16 type)

genlmsg_end(msg, hdr);

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_KERNEL);

return 0;

Expand Down Expand Up @@ -479,7 +487,8 @@ int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx)

genlmsg_end(msg, hdr);

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_KERNEL);

return 0;

Expand Down Expand Up @@ -600,7 +609,8 @@ int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,

dev->dep_link_up = true;

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_ATOMIC);
genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_ATOMIC);

return 0;

Expand Down Expand Up @@ -632,7 +642,8 @@ int nfc_genl_dep_link_down_event(struct nfc_dev *dev)

genlmsg_end(msg, hdr);

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_ATOMIC);
genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_ATOMIC);

return 0;

Expand Down Expand Up @@ -1137,7 +1148,8 @@ int nfc_genl_fw_download_done(struct nfc_dev *dev, const char *firmware_name,

genlmsg_end(msg, hdr);

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_KERNEL);

return 0;

Expand Down Expand Up @@ -1308,7 +1320,8 @@ static void se_io_cb(void *context, u8 *apdu, size_t apdu_len, int err)

genlmsg_end(msg, hdr);

genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
genlmsg_multicast(&nfc_genl_family, msg, 0,
nfc_genl_event_mcgrp.id, GFP_KERNEL);

kfree(ctx);

Expand Down
Loading

0 comments on commit 68eb550

Please sign in to comment.