nl80211: Emit a SET_INTERFACE on iftype change
authorAndrew Zaborowski <andrew.zaborowski@intel.com>
Fri, 19 Oct 2018 21:19:06 +0000 (23:19 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Fri, 9 Nov 2018 10:22:10 +0000 (11:22 +0100)
Let userspace learn about iftype changes by sending a notification
when handling the NL80211_CMD_SET_INTERFACE command.  There seems
to be no other place where the iftype can change: nl80211_set_interface
is the only caller of cfg80211_change_iface which is the only caller of
ops->change_virtual_intf.

Signed-off-by: Andrew Zaborowski <andrew.zaborowski@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/wireless/nl80211.c

index 6fd93eb0df6d2794234d215dcdc20eab0d5f425f..5e7178954d615f0128b0270e1797902d525bbf27 100644 (file)
@@ -2977,14 +2977,15 @@ static int nl80211_send_chandef(struct sk_buff *msg,
 
 static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
                              struct cfg80211_registered_device *rdev,
-                             struct wireless_dev *wdev, bool removal)
+                             struct wireless_dev *wdev,
+                             enum nl80211_commands cmd)
 {
        struct net_device *dev = wdev->netdev;
-       u8 cmd = NL80211_CMD_NEW_INTERFACE;
        void *hdr;
 
-       if (removal)
-               cmd = NL80211_CMD_DEL_INTERFACE;
+       WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
+               cmd != NL80211_CMD_DEL_INTERFACE &&
+               cmd != NL80211_CMD_SET_INTERFACE);
 
        hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
        if (!hdr)
@@ -3132,7 +3133,8 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *
                        }
                        if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
                                               cb->nlh->nlmsg_seq, NLM_F_MULTI,
-                                              rdev, wdev, false) < 0) {
+                                              rdev, wdev,
+                                              NL80211_CMD_NEW_INTERFACE) < 0) {
                                goto out;
                        }
                        if_idx++;
@@ -3162,7 +3164,7 @@ static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
                return -ENOMEM;
 
        if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
-                              rdev, wdev, false) < 0) {
+                              rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
                nlmsg_free(msg);
                return -ENOBUFS;
        }
@@ -3352,6 +3354,12 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
        if (!err && params.use_4addr != -1)
                dev->ieee80211_ptr->use_4addr = params.use_4addr;
 
+       if (change && !err) {
+               struct wireless_dev *wdev = dev->ieee80211_ptr;
+
+               nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
+       }
+
        return err;
 }
 
@@ -3443,7 +3451,7 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
        }
 
        if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
-                              rdev, wdev, false) < 0) {
+                              rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
                nlmsg_free(msg);
                return -ENOBUFS;
        }
@@ -14097,15 +14105,11 @@ void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
 {
        struct sk_buff *msg;
 
-       WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
-               cmd != NL80211_CMD_DEL_INTERFACE);
-
        msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
        if (!msg)
                return;
 
-       if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev,
-                              cmd == NL80211_CMD_DEL_INTERFACE) < 0) {
+       if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
                nlmsg_free(msg);
                return;
        }