Skip to content

Commit 3bb2055

Browse files
committed
cfg80211: send events when devices are added/removed
We're currently sending NEW_WIPHY events for renames (which is a bit odd, but now can't be changed), but also send them for really new devices that register. Also send DEL_WIPHY events when a device is removed, the event ID for this was already reserved. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 34171dc commit 3bb2055

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

‎net/wireless/core.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
130130
newname))
131131
pr_err("failed to rename debugfs dir to %s!\n", newname);
132132

133-
nl80211_notify_dev_rename(rdev);
133+
nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY);
134134

135135
return 0;
136136
}
@@ -660,6 +660,8 @@ int wiphy_register(struct wiphy *wiphy)
660660
return res;
661661
}
662662

663+
nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY);
664+
663665
return 0;
664666
}
665667
EXPORT_SYMBOL(wiphy_register);
@@ -698,6 +700,7 @@ void wiphy_unregister(struct wiphy *wiphy)
698700
rfkill_unregister(rdev->rfkill);
699701

700702
rtnl_lock();
703+
nl80211_notify_wiphy(rdev, NL80211_CMD_DEL_WIPHY);
701704
rdev->wiphy.registered = false;
702705

703706
WARN_ON(!list_empty(&rdev->wdev_list));

‎net/wireless/nl80211.c‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,7 @@ struct nl80211_dump_wiphy_state {
12261226
};
12271227

12281228
static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
1229+
enum nl80211_commands cmd,
12291230
struct sk_buff *msg, u32 portid, u32 seq,
12301231
int flags, struct nl80211_dump_wiphy_state *state)
12311232
{
@@ -1240,7 +1241,7 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
12401241
rdev->wiphy.mgmt_stypes;
12411242
u32 features;
12421243

1243-
hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_WIPHY);
1244+
hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
12441245
if (!hdr)
12451246
return -ENOBUFS;
12461247

@@ -1254,6 +1255,9 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
12541255
cfg80211_rdev_list_generation))
12551256
goto nla_put_failure;
12561257

1258+
if (cmd != NL80211_CMD_NEW_WIPHY)
1259+
goto finish;
1260+
12571261
switch (state->split_start) {
12581262
case 0:
12591263
if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
@@ -1682,6 +1686,7 @@ static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
16821686
state->split_start = 0;
16831687
break;
16841688
}
1689+
finish:
16851690
return genlmsg_end(msg, hdr);
16861691

16871692
nla_put_failure:
@@ -1756,7 +1761,8 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
17561761
continue;
17571762
/* attempt to fit multiple wiphy data chunks into the skb */
17581763
do {
1759-
ret = nl80211_send_wiphy(rdev, skb,
1764+
ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1765+
skb,
17601766
NETLINK_CB(cb->skb).portid,
17611767
cb->nlh->nlmsg_seq,
17621768
NLM_F_MULTI, state);
@@ -1811,7 +1817,8 @@ static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
18111817
if (!msg)
18121818
return -ENOMEM;
18131819

1814-
if (nl80211_send_wiphy(rdev, msg, info->snd_portid, info->snd_seq, 0,
1820+
if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1821+
info->snd_portid, info->snd_seq, 0,
18151822
&state) < 0) {
18161823
nlmsg_free(msg);
18171824
return -ENOBUFS;
@@ -10101,16 +10108,20 @@ static const struct genl_ops nl80211_ops[] = {
1010110108

1010210109
/* notification functions */
1010310110

10104-
void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
10111+
void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10112+
enum nl80211_commands cmd)
1010510113
{
1010610114
struct sk_buff *msg;
1010710115
struct nl80211_dump_wiphy_state state = {};
1010810116

10117+
WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10118+
cmd != NL80211_CMD_DEL_WIPHY);
10119+
1010910120
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1011010121
if (!msg)
1011110122
return;
1011210123

10113-
if (nl80211_send_wiphy(rdev, msg, 0, 0, 0, &state) < 0) {
10124+
if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
1011410125
nlmsg_free(msg);
1011510126
return;
1011610127
}

‎net/wireless/nl80211.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
int nl80211_init(void);
77
void nl80211_exit(void);
8-
void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev);
8+
void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
9+
enum nl80211_commands cmd);
910
void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
1011
struct wireless_dev *wdev);
1112
struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,

0 commit comments

Comments
 (0)