Skip to content

Commit

Permalink
mac80211: make master iface not wireless
Browse files Browse the repository at this point in the history
There's no need to register the master netdev with cfg80211,
in fact, this is quite dangerous and lead to having to add
checks for the master interface all over the config handlers.
This patch removes the "ieee80211_ptr" from the master iface
in favour of having a small netdev_priv() associated with
the master interface that stores the ieee80211_local pointer.
Because of this, a lot of code in the configuration handlers
can go away. To make this patch easier to verify I have also
removed a number of wiphy_priv() calls in favour of getting
the sdata first and then the local pointer from that.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Johannes Berg authored and John W. Linville committed Sep 24, 2008
1 parent 9e5e6c3 commit 133b822
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 99 deletions.
59 changes: 0 additions & 59 deletions net/mac80211/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
enum nl80211_iftype type, u32 *flags,
struct vif_params *params)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct net_device *dev;
struct ieee80211_sub_if_data *sdata;
int ret;
Expand All @@ -95,9 +94,6 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
if (!nl80211_type_check(type))
return -EINVAL;

if (dev == local->mdev)
return -EOPNOTSUPP;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

ret = ieee80211_if_change_type(sdata, type);
Expand All @@ -120,16 +116,12 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
u8 key_idx, u8 *mac_addr,
struct key_params *params)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct ieee80211_sub_if_data *sdata;
struct sta_info *sta = NULL;
enum ieee80211_key_alg alg;
struct ieee80211_key *key;
int err;

if (dev == local->mdev)
return -EOPNOTSUPP;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

switch (params->cipher) {
Expand Down Expand Up @@ -174,14 +166,10 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
u8 key_idx, u8 *mac_addr)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct ieee80211_sub_if_data *sdata;
struct sta_info *sta;
int ret;

if (dev == local->mdev)
return -EOPNOTSUPP;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

rcu_read_lock();
Expand Down Expand Up @@ -222,7 +210,6 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
void (*callback)(void *cookie,
struct key_params *params))
{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct ieee80211_sub_if_data *sdata;
struct sta_info *sta = NULL;
u8 seq[6] = {0};
Expand All @@ -232,9 +219,6 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
u16 iv16;
int err = -ENOENT;

if (dev == local->mdev)
return -EOPNOTSUPP;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

rcu_read_lock();
Expand Down Expand Up @@ -310,12 +294,8 @@ static int ieee80211_config_default_key(struct wiphy *wiphy,
struct net_device *dev,
u8 key_idx)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct ieee80211_sub_if_data *sdata;

if (dev == local->mdev)
return -EOPNOTSUPP;

rcu_read_lock();

sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Expand Down Expand Up @@ -496,13 +476,9 @@ static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
struct beacon_parameters *params)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct ieee80211_sub_if_data *sdata;
struct beacon_data *old;

if (dev == local->mdev)
return -EOPNOTSUPP;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

if (sdata->vif.type != NL80211_IFTYPE_AP)
Expand All @@ -519,13 +495,9 @@ static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
struct beacon_parameters *params)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct ieee80211_sub_if_data *sdata;
struct beacon_data *old;

if (dev == local->mdev)
return -EOPNOTSUPP;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

if (sdata->vif.type != NL80211_IFTYPE_AP)
Expand All @@ -541,13 +513,9 @@ static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,

static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct ieee80211_sub_if_data *sdata;
struct beacon_data *old;

if (dev == local->mdev)
return -EOPNOTSUPP;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

if (sdata->vif.type != NL80211_IFTYPE_AP)
Expand Down Expand Up @@ -695,9 +663,6 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
struct ieee80211_sub_if_data *sdata;
int err;

if (dev == local->mdev || params->vlan == local->mdev)
return -EOPNOTSUPP;

/* Prevent a race with changing the rate control algorithm */
if (!netif_running(dev))
return -ENETDOWN;
Expand Down Expand Up @@ -752,9 +717,6 @@ static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
struct ieee80211_sub_if_data *sdata;
struct sta_info *sta;

if (dev == local->mdev)
return -EOPNOTSUPP;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

if (mac) {
Expand Down Expand Up @@ -786,9 +748,6 @@ static int ieee80211_change_station(struct wiphy *wiphy,
struct sta_info *sta;
struct ieee80211_sub_if_data *vlansdata;

if (dev == local->mdev || params->vlan == local->mdev)
return -EOPNOTSUPP;

rcu_read_lock();

/* XXX: get sta belonging to dev */
Expand Down Expand Up @@ -828,9 +787,6 @@ static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
struct sta_info *sta;
int err;

if (dev == local->mdev)
return -EOPNOTSUPP;

if (!netif_running(dev))
return -ENETDOWN;

Expand Down Expand Up @@ -884,9 +840,6 @@ static int ieee80211_change_mpath(struct wiphy *wiphy,
struct mesh_path *mpath;
struct sta_info *sta;

if (dev == local->mdev)
return -EOPNOTSUPP;

if (!netif_running(dev))
return -ENETDOWN;

Expand Down Expand Up @@ -958,13 +911,9 @@ static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
u8 *dst, u8 *next_hop, struct mpath_info *pinfo)

{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct ieee80211_sub_if_data *sdata;
struct mesh_path *mpath;

if (dev == local->mdev)
return -EOPNOTSUPP;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Expand All @@ -986,13 +935,9 @@ static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
int idx, u8 *dst, u8 *next_hop,
struct mpath_info *pinfo)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct ieee80211_sub_if_data *sdata;
struct mesh_path *mpath;

if (dev == local->mdev)
return -EOPNOTSUPP;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Expand All @@ -1015,13 +960,9 @@ static int ieee80211_change_bss(struct wiphy *wiphy,
struct net_device *dev,
struct bss_parameters *params)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct ieee80211_sub_if_data *sdata;
u32 changed = 0;

if (dev == local->mdev)
return -EOPNOTSUPP;

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

if (sdata->vif.type != NL80211_IFTYPE_AP)
Expand Down
3 changes: 1 addition & 2 deletions net/mac80211/debugfs_sta.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ static ssize_t sta_agg_status_write(struct file *file,
const char __user *user_buf, size_t count, loff_t *ppos)
{
struct sta_info *sta = file->private_data;
struct net_device *dev = sta->sdata->dev;
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_local *local = sta->sdata->local;
struct ieee80211_hw *hw = &local->hw;
u8 *da = sta->sta.addr;
static int tid_static_tx[16] = {0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
4 changes: 4 additions & 0 deletions net/mac80211/ieee80211_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ enum {
/* maximum number of hardware queues we support. */
#define QD_MAX_QUEUES (IEEE80211_MAX_AMPDU_QUEUES + IEEE80211_MAX_QUEUES)

struct ieee80211_master_priv {
struct ieee80211_local *local;
};

struct ieee80211_local {
/* embed the driver visible part.
* don't cast (use the static inlines below), but we keep
Expand Down
19 changes: 10 additions & 9 deletions net/mac80211/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ static const struct header_ops ieee80211_header_ops = {

static int ieee80211_master_open(struct net_device *dev)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_master_priv *mpriv = netdev_priv(dev);
struct ieee80211_local *local = mpriv->local;
struct ieee80211_sub_if_data *sdata;
int res = -EOPNOTSUPP;

Expand All @@ -128,7 +129,8 @@ static int ieee80211_master_open(struct net_device *dev)

static int ieee80211_master_stop(struct net_device *dev)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_master_priv *mpriv = netdev_priv(dev);
struct ieee80211_local *local = mpriv->local;
struct ieee80211_sub_if_data *sdata;

/* we hold the RTNL here so can safely walk the list */
Expand All @@ -141,7 +143,8 @@ static int ieee80211_master_stop(struct net_device *dev)

static void ieee80211_master_set_multicast_list(struct net_device *dev)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_master_priv *mpriv = netdev_priv(dev);
struct ieee80211_local *local = mpriv->local;

ieee80211_configure_filter(local);
}
Expand Down Expand Up @@ -787,7 +790,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
int result;
enum ieee80211_band band;
struct net_device *mdev;
struct wireless_dev *mwdev;
struct ieee80211_master_priv *mpriv;

/*
* generic code guarantees at least one band,
Expand Down Expand Up @@ -829,16 +832,14 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
if (hw->queues < 4)
hw->ampdu_queues = 0;

mdev = alloc_netdev_mq(sizeof(struct wireless_dev),
mdev = alloc_netdev_mq(sizeof(struct ieee80211_master_priv),
"wmaster%d", ether_setup,
ieee80211_num_queues(hw));
if (!mdev)
goto fail_mdev_alloc;

mwdev = netdev_priv(mdev);
mdev->ieee80211_ptr = mwdev;
mwdev->wiphy = local->hw.wiphy;

mpriv = netdev_priv(mdev);
mpriv->local = local;
local->mdev = mdev;

ieee80211_rx_bss_list_init(local);
Expand Down
2 changes: 1 addition & 1 deletion net/mac80211/mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static void ieee80211_mesh_path_timer(unsigned long data)
struct ieee80211_sub_if_data *sdata =
(struct ieee80211_sub_if_data *) data;
struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
struct ieee80211_local *local = wdev_priv(&sdata->wdev);
struct ieee80211_local *local = sdata->local;

queue_work(local->hw.workqueue, &ifmsh->work);
}
Expand Down
25 changes: 10 additions & 15 deletions net/mac80211/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,32 +650,28 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
return result;
}

static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
static void ap_sta_ps_start(struct sta_info *sta)
{
struct ieee80211_sub_if_data *sdata;
struct ieee80211_sub_if_data *sdata = sta->sdata;
DECLARE_MAC_BUF(mac);

sdata = sta->sdata;

atomic_inc(&sdata->bss->num_sta_ps);
set_and_clear_sta_flags(sta, WLAN_STA_PS, WLAN_STA_PSPOLL);
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
dev->name, print_mac(mac, sta->sta.addr), sta->sta.aid);
sdata->dev->name, print_mac(mac, sta->sta.addr), sta->sta.aid);
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
}

static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
static int ap_sta_ps_end(struct sta_info *sta)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_sub_if_data *sdata = sta->sdata;
struct ieee80211_local *local = sdata->local;
struct sk_buff *skb;
int sent = 0;
struct ieee80211_sub_if_data *sdata;
struct ieee80211_tx_info *info;
DECLARE_MAC_BUF(mac);

sdata = sta->sdata;

atomic_dec(&sdata->bss->num_sta_ps);

clear_sta_flags(sta, WLAN_STA_PS | WLAN_STA_PSPOLL);
Expand All @@ -685,7 +681,7 @@ static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)

#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n",
dev->name, print_mac(mac, sta->sta.addr), sta->sta.aid);
sdata->dev->name, print_mac(mac, sta->sta.addr), sta->sta.aid);
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */

/* Send all buffered frames to the station */
Expand All @@ -701,7 +697,7 @@ static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
sent++;
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
printk(KERN_DEBUG "%s: STA %s aid %d send PS frame "
"since STA not sleeping anymore\n", dev->name,
"since STA not sleeping anymore\n", sdata->dev->name,
print_mac(mac, sta->sta.addr), sta->sta.aid);
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
info->flags |= IEEE80211_TX_CTL_REQUEUE;
Expand All @@ -715,7 +711,6 @@ static ieee80211_rx_result debug_noinline
ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
{
struct sta_info *sta = rx->sta;
struct net_device *dev = rx->dev;
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;

if (!sta)
Expand Down Expand Up @@ -757,10 +752,10 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
* exchange sequence */
if (test_sta_flags(sta, WLAN_STA_PS) &&
!ieee80211_has_pm(hdr->frame_control))
rx->sent_ps_buffered += ap_sta_ps_end(dev, sta);
rx->sent_ps_buffered += ap_sta_ps_end(sta);
else if (!test_sta_flags(sta, WLAN_STA_PS) &&
ieee80211_has_pm(hdr->frame_control))
ap_sta_ps_start(dev, sta);
ap_sta_ps_start(sta);
}

/* Drop data::nullfunc frames silently, since they are used only to
Expand Down
Loading

0 comments on commit 133b822

Please sign in to comment.