Commit 0ec3ca44 authored by Johannes Berg's avatar Johannes Berg Committed by David S. Miller

[PATCH] mac80211: validate VLAN interfaces better

This patch changes mac80211 to verify that VLAN interfaces
are valid and not bother drivers about them any more.
VLAN interfaces are now only valid when an AP interface
is up with the same MAC address, and are automatically
turned off when the AP interface is set down.
Signed-off-by: default avatarJohannes Berg <johannes@sipsolutions.net>
Cc: Jouni Malinen <j@w1.fi>
Signed-off-by: default avatarMichael Wu <flamingice@sourmilk.net>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 4150c572
...@@ -442,16 +442,17 @@ struct ieee80211_conf { ...@@ -442,16 +442,17 @@ struct ieee80211_conf {
* @IEEE80211_IF_TYPE_IBSS: interface in IBSS (ad-hoc) mode. * @IEEE80211_IF_TYPE_IBSS: interface in IBSS (ad-hoc) mode.
* @IEEE80211_IF_TYPE_MNTR: interface in monitor (rfmon) mode. * @IEEE80211_IF_TYPE_MNTR: interface in monitor (rfmon) mode.
* @IEEE80211_IF_TYPE_WDS: interface in WDS mode. * @IEEE80211_IF_TYPE_WDS: interface in WDS mode.
* @IEEE80211_IF_TYPE_VLAN: not used. * @IEEE80211_IF_TYPE_VLAN: VLAN interface bound to an AP, drivers
* will never see this type.
*/ */
enum ieee80211_if_types { enum ieee80211_if_types {
IEEE80211_IF_TYPE_AP = 0x00000000, IEEE80211_IF_TYPE_AP,
IEEE80211_IF_TYPE_MGMT = 0x00000001, IEEE80211_IF_TYPE_MGMT,
IEEE80211_IF_TYPE_STA = 0x00000002, IEEE80211_IF_TYPE_STA,
IEEE80211_IF_TYPE_IBSS = 0x00000003, IEEE80211_IF_TYPE_IBSS,
IEEE80211_IF_TYPE_MNTR = 0x00000004, IEEE80211_IF_TYPE_MNTR,
IEEE80211_IF_TYPE_WDS = 0x5A580211, IEEE80211_IF_TYPE_WDS,
IEEE80211_IF_TYPE_VLAN = 0x00080211, IEEE80211_IF_TYPE_VLAN,
}; };
/** /**
......
...@@ -162,9 +162,6 @@ __IEEE80211_IF_FILE(beacon_tail_len); ...@@ -162,9 +162,6 @@ __IEEE80211_IF_FILE(beacon_tail_len);
/* WDS attributes */ /* WDS attributes */
IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC); IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
/* VLAN attributes */
IEEE80211_IF_FILE(vlan_id, u.vlan.id, DEC);
#define DEBUGFS_ADD(name, type)\ #define DEBUGFS_ADD(name, type)\
sdata->debugfs.type.name = debugfs_create_file(#name, 0444,\ sdata->debugfs.type.name = debugfs_create_file(#name, 0444,\
sdata->debugfsdir, sdata, &name##_ops); sdata->debugfsdir, sdata, &name##_ops);
...@@ -223,7 +220,6 @@ static void add_vlan_files(struct ieee80211_sub_if_data *sdata) ...@@ -223,7 +220,6 @@ static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
DEBUGFS_ADD(drop_unencrypted, vlan); DEBUGFS_ADD(drop_unencrypted, vlan);
DEBUGFS_ADD(eapol, vlan); DEBUGFS_ADD(eapol, vlan);
DEBUGFS_ADD(ieee8021_x, vlan); DEBUGFS_ADD(ieee8021_x, vlan);
DEBUGFS_ADD(vlan_id, vlan);
} }
static void add_monitor_files(struct ieee80211_sub_if_data *sdata) static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
...@@ -317,7 +313,6 @@ static void del_vlan_files(struct ieee80211_sub_if_data *sdata) ...@@ -317,7 +313,6 @@ static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
DEBUGFS_DEL(drop_unencrypted, vlan); DEBUGFS_DEL(drop_unencrypted, vlan);
DEBUGFS_DEL(eapol, vlan); DEBUGFS_DEL(eapol, vlan);
DEBUGFS_DEL(ieee8021_x, vlan); DEBUGFS_DEL(ieee8021_x, vlan);
DEBUGFS_DEL(vlan_id, vlan);
} }
static void del_monitor_files(struct ieee80211_sub_if_data *sdata) static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
......
...@@ -314,22 +314,43 @@ static int ieee80211_open(struct net_device *dev) ...@@ -314,22 +314,43 @@ static int ieee80211_open(struct net_device *dev)
int res; int res;
sdata = IEEE80211_DEV_TO_SUB_IF(dev); sdata = IEEE80211_DEV_TO_SUB_IF(dev);
read_lock(&local->sub_if_lock); read_lock(&local->sub_if_lock);
list_for_each_entry(nsdata, &local->sub_if_list, list) { list_for_each_entry(nsdata, &local->sub_if_list, list) {
struct net_device *ndev = nsdata->dev; struct net_device *ndev = nsdata->dev;
if (ndev != dev && ndev != local->mdev && netif_running(ndev) && if (ndev != dev && ndev != local->mdev && netif_running(ndev) &&
compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0 && compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0) {
!identical_mac_addr_allowed(sdata->type, nsdata->type)) { /*
read_unlock(&local->sub_if_lock); * check whether it may have the same address
return -ENOTUNIQ; */
if (!identical_mac_addr_allowed(sdata->type,
nsdata->type)) {
read_unlock(&local->sub_if_lock);
return -ENOTUNIQ;
}
/*
* can only add VLANs to enabled APs
*/
if (sdata->type == IEEE80211_IF_TYPE_VLAN &&
nsdata->type == IEEE80211_IF_TYPE_AP &&
netif_running(nsdata->dev))
sdata->u.vlan.ap = nsdata;
} }
} }
read_unlock(&local->sub_if_lock); read_unlock(&local->sub_if_lock);
if (sdata->type == IEEE80211_IF_TYPE_WDS && switch (sdata->type) {
is_zero_ether_addr(sdata->u.wds.remote_addr)) case IEEE80211_IF_TYPE_WDS:
return -ENOLINK; if (is_zero_ether_addr(sdata->u.wds.remote_addr))
return -ENOLINK;
break;
case IEEE80211_IF_TYPE_VLAN:
if (!sdata->u.vlan.ap)
return -ENOLINK;
break;
}
if (local->open_count == 0) { if (local->open_count == 0) {
res = 0; res = 0;
...@@ -340,6 +361,10 @@ static int ieee80211_open(struct net_device *dev) ...@@ -340,6 +361,10 @@ static int ieee80211_open(struct net_device *dev)
} }
switch (sdata->type) { switch (sdata->type) {
case IEEE80211_IF_TYPE_VLAN:
list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans);
/* no need to tell driver */
break;
case IEEE80211_IF_TYPE_MNTR: case IEEE80211_IF_TYPE_MNTR:
/* must be before the call to ieee80211_configure_filter */ /* must be before the call to ieee80211_configure_filter */
local->monitors++; local->monitors++;
...@@ -407,9 +432,24 @@ static int ieee80211_stop(struct net_device *dev) ...@@ -407,9 +432,24 @@ static int ieee80211_stop(struct net_device *dev)
dev_mc_unsync(local->mdev, dev); dev_mc_unsync(local->mdev, dev);
/* down all dependent devices, that is VLANs */
if (sdata->type == IEEE80211_IF_TYPE_AP) {
struct ieee80211_sub_if_data *vlan, *tmp;
list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
u.vlan.list)
dev_close(vlan->dev);
WARN_ON(!list_empty(&sdata->u.ap.vlans));
}
local->open_count--; local->open_count--;
switch (sdata->type) { switch (sdata->type) {
case IEEE80211_IF_TYPE_VLAN:
list_del(&sdata->u.vlan.list);
sdata->u.vlan.ap = NULL;
/* no need to tell driver */
break;
case IEEE80211_IF_TYPE_MNTR: case IEEE80211_IF_TYPE_MNTR:
local->monitors--; local->monitors--;
if (local->monitors == 0) { if (local->monitors == 0) {
......
...@@ -191,6 +191,8 @@ struct ieee80211_if_ap { ...@@ -191,6 +191,8 @@ struct ieee80211_if_ap {
u8 *beacon_head, *beacon_tail; u8 *beacon_head, *beacon_tail;
int beacon_head_len, beacon_tail_len; int beacon_head_len, beacon_tail_len;
struct list_head vlans;
u8 ssid[IEEE80211_MAX_SSID_LEN]; u8 ssid[IEEE80211_MAX_SSID_LEN];
size_t ssid_len; size_t ssid_len;
u8 *generic_elem; u8 *generic_elem;
...@@ -214,7 +216,8 @@ struct ieee80211_if_wds { ...@@ -214,7 +216,8 @@ struct ieee80211_if_wds {
}; };
struct ieee80211_if_vlan { struct ieee80211_if_vlan {
u8 id; struct ieee80211_sub_if_data *ap;
struct list_head list;
}; };
/* flags used in struct ieee80211_if_sta.flags */ /* flags used in struct ieee80211_if_sta.flags */
...@@ -377,7 +380,6 @@ struct ieee80211_sub_if_data { ...@@ -377,7 +380,6 @@ struct ieee80211_sub_if_data {
struct dentry *drop_unencrypted; struct dentry *drop_unencrypted;
struct dentry *eapol; struct dentry *eapol;
struct dentry *ieee8021_x; struct dentry *ieee8021_x;
struct dentry *vlan_id;
} vlan; } vlan;
struct { struct {
struct dentry *mode; struct dentry *mode;
......
...@@ -164,6 +164,7 @@ void ieee80211_if_set_type(struct net_device *dev, int type) ...@@ -164,6 +164,7 @@ void ieee80211_if_set_type(struct net_device *dev, int type)
sdata->bss = NULL; sdata->bss = NULL;
break; break;
case IEEE80211_IF_TYPE_VLAN: case IEEE80211_IF_TYPE_VLAN:
sdata->u.vlan.ap = NULL;
break; break;
case IEEE80211_IF_TYPE_AP: case IEEE80211_IF_TYPE_AP:
sdata->u.ap.dtim_period = 2; sdata->u.ap.dtim_period = 2;
...@@ -171,6 +172,7 @@ void ieee80211_if_set_type(struct net_device *dev, int type) ...@@ -171,6 +172,7 @@ void ieee80211_if_set_type(struct net_device *dev, int type)
sdata->u.ap.max_ratectrl_rateidx = -1; sdata->u.ap.max_ratectrl_rateidx = -1;
skb_queue_head_init(&sdata->u.ap.ps_bc_buf); skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
sdata->bss = &sdata->u.ap; sdata->bss = &sdata->u.ap;
INIT_LIST_HEAD(&sdata->u.ap.vlans);
break; break;
case IEEE80211_IF_TYPE_STA: case IEEE80211_IF_TYPE_STA:
case IEEE80211_IF_TYPE_IBSS: { case IEEE80211_IF_TYPE_IBSS: {
...@@ -284,6 +286,9 @@ void ieee80211_if_reinit(struct net_device *dev) ...@@ -284,6 +286,9 @@ void ieee80211_if_reinit(struct net_device *dev)
case IEEE80211_IF_TYPE_MNTR: case IEEE80211_IF_TYPE_MNTR:
dev->type = ARPHRD_ETHER; dev->type = ARPHRD_ETHER;
break; break;
case IEEE80211_IF_TYPE_VLAN:
sdata->u.vlan.ap = NULL;
break;
} }
/* remove all STAs that are bound to this virtual interface */ /* remove all STAs that are bound to this virtual interface */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment