Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 72fb2abc authored by Johannes Berg's avatar Johannes Berg
Browse files

nl80211: retrieve interface data by wdev



Since soon there will be virtual interfaces that
don't have a netdev, use the wdev identifier for
the API to retrieve interface data.

Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 1bf614ef
Loading
Loading
Loading
Loading
+15 −11
Original line number Original line Diff line number Diff line
@@ -1731,21 +1731,25 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)


static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
			      struct cfg80211_registered_device *rdev,
			      struct cfg80211_registered_device *rdev,
			      struct net_device *dev)
			      struct wireless_dev *wdev)
{
{
	struct net_device *dev = wdev->netdev;
	void *hdr;
	void *hdr;
	u64 wdev_id = (u64)dev->ieee80211_ptr->identifier |
	u64 wdev_id = (u64)wdev->identifier |
		      ((u64)rdev->wiphy_idx << 32);
		      ((u64)rdev->wiphy_idx << 32);


	hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
	hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
	if (!hdr)
	if (!hdr)
		return -1;
		return -1;


	if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
	if (dev &&
	    nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
	    (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
	     nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) ||
	     nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) ||
	    nla_put_u32(msg, NL80211_ATTR_IFTYPE,
	     nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dev->dev_addr)))
			dev->ieee80211_ptr->iftype) ||
		goto nla_put_failure;

	if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
	    nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
	    nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id) ||
	    nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id) ||
	    nla_put_u32(msg, NL80211_ATTR_GENERATION,
	    nla_put_u32(msg, NL80211_ATTR_GENERATION,
			rdev->devlist_generation ^
			rdev->devlist_generation ^
@@ -1794,7 +1798,7 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *
			}
			}
			if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
			if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
					       cb->nlh->nlmsg_seq, NLM_F_MULTI,
					       cb->nlh->nlmsg_seq, NLM_F_MULTI,
					       rdev, wdev->netdev) < 0) {
					       rdev, wdev) < 0) {
				mutex_unlock(&rdev->devlist_mtx);
				mutex_unlock(&rdev->devlist_mtx);
				goto out;
				goto out;
			}
			}
@@ -1817,14 +1821,14 @@ static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
{
{
	struct sk_buff *msg;
	struct sk_buff *msg;
	struct cfg80211_registered_device *dev = info->user_ptr[0];
	struct cfg80211_registered_device *dev = info->user_ptr[0];
	struct net_device *netdev = info->user_ptr[1];
	struct wireless_dev *wdev = info->user_ptr[1];


	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
	if (!msg)
	if (!msg)
		return -ENOMEM;
		return -ENOMEM;


	if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
	if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
			       dev, netdev) < 0) {
			       dev, wdev) < 0) {
		nlmsg_free(msg);
		nlmsg_free(msg);
		return -ENOBUFS;
		return -ENOBUFS;
	}
	}
@@ -6833,7 +6837,7 @@ static struct genl_ops nl80211_ops[] = {
		.dumpit = nl80211_dump_interface,
		.dumpit = nl80211_dump_interface,
		.policy = nl80211_policy,
		.policy = nl80211_policy,
		/* can be retrieved by unprivileged users */
		/* can be retrieved by unprivileged users */
		.internal_flags = NL80211_FLAG_NEED_NETDEV,
		.internal_flags = NL80211_FLAG_NEED_WDEV,
	},
	},
	{
	{
		.cmd = NL80211_CMD_SET_INTERFACE,
		.cmd = NL80211_CMD_SET_INTERFACE,