Skip to content

Commit

Permalink
mac80211: revamp virtual interface handling
Browse files Browse the repository at this point in the history
This patch revamps the virtual interface handling and makes the
code much easier to follow. Fewer functions, better names, less
spaghetti code.

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 Jul 14, 2008
1 parent 3e122be commit 7563652
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 265 deletions.
24 changes: 4 additions & 20 deletions net/mac80211/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
struct ieee80211_sub_if_data *sdata;
int err;

if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
return -ENODEV;

itype = nl80211_type_to_mac80211_type(type);
if (itype == IEEE80211_IF_TYPE_INVALID)
return -EINVAL;
Expand All @@ -68,35 +65,26 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name,

static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct net_device *dev;
char *name;

if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
return -ENODEV;

/* we're under RTNL */
dev = __dev_get_by_index(&init_net, ifindex);
if (!dev)
return 0;
return -ENODEV;

name = dev->name;
ieee80211_if_remove(dev);

return ieee80211_if_remove(local->mdev, name, -1);
return 0;
}

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;
enum ieee80211_if_types itype;
struct ieee80211_sub_if_data *sdata;

if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
return -ENODEV;

/* we're under RTNL */
dev = __dev_get_by_index(&init_net, ifindex);
if (!dev)
Expand All @@ -111,11 +99,7 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,

sdata = IEEE80211_DEV_TO_SUB_IF(dev);

if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
return -EOPNOTSUPP;

ieee80211_if_reinit(dev);
ieee80211_if_set_type(dev, itype);
ieee80211_if_change_type(sdata, itype);

if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
Expand Down
15 changes: 1 addition & 14 deletions net/mac80211/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",

/* statistics stuff */

static inline int rtnl_lock_local(struct ieee80211_local *local)
{
rtnl_lock();
if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) {
rtnl_unlock();
return -ENODEV;
}
return 0;
}

#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)

Expand All @@ -96,10 +86,7 @@ static ssize_t format_devstat_counter(struct ieee80211_local *local,
if (!local->ops->get_stats)
return -EOPNOTSUPP;

res = rtnl_lock_local(local);
if (res)
return res;

rtnl_lock();
res = local->ops->get_stats(local_to_hw(local), &stats);
rtnl_unlock();
if (!res)
Expand Down
14 changes: 4 additions & 10 deletions net/mac80211/debugfs_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,12 @@ static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
}
#endif

static void del_files(struct ieee80211_sub_if_data *sdata, int type)
static void del_files(struct ieee80211_sub_if_data *sdata)
{
if (!sdata->debugfsdir)
return;

switch (type) {
switch (sdata->vif.type) {
case IEEE80211_IF_TYPE_MESH_POINT:
#ifdef CONFIG_MAC80211_MESH
del_mesh_stats(sdata);
Expand Down Expand Up @@ -521,22 +521,16 @@ void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
sprintf(buf, "netdev:%s", sdata->dev->name);
sdata->debugfsdir = debugfs_create_dir(buf,
sdata->local->hw.wiphy->debugfsdir);
add_files(sdata);
}

void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
{
del_files(sdata, sdata->vif.type);
del_files(sdata);
debugfs_remove(sdata->debugfsdir);
sdata->debugfsdir = NULL;
}

void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
int oldtype)
{
del_files(sdata, oldtype);
add_files(sdata);
}

static int netdev_notify(struct notifier_block *nb,
unsigned long state,
void *ndev)
Expand Down
5 changes: 0 additions & 5 deletions net/mac80211/debugfs_netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#ifdef CONFIG_MAC80211_DEBUGFS
void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata);
void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata);
void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
int oldtype);
void ieee80211_debugfs_netdev_init(void);
void ieee80211_debugfs_netdev_exit(void);
#else
Expand All @@ -17,9 +15,6 @@ static inline void ieee80211_debugfs_add_netdev(
static inline void ieee80211_debugfs_remove_netdev(
struct ieee80211_sub_if_data *sdata)
{}
static inline void ieee80211_debugfs_change_if_type(
struct ieee80211_sub_if_data *sdata, int oldtype)
{}
static inline void ieee80211_debugfs_netdev_init(void)
{}

Expand Down
21 changes: 6 additions & 15 deletions net/mac80211/ieee80211_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,6 @@ struct ieee80211_local {
bool tim_in_locked_section; /* see ieee80211_beacon_get() */
int tx_headroom; /* required headroom for hardware/radiotap */

enum {
IEEE80211_DEV_UNINITIALIZED = 0,
IEEE80211_DEV_REGISTERED,
IEEE80211_DEV_UNREGISTERED,
} reg_state;

/* Tasklet and skb queue to process calls from IRQ mode. All frames
* added to skb_queue will be processed, but frames in
* skb_queue_unreliable may be dropped if the total length of these
Expand Down Expand Up @@ -863,7 +857,6 @@ int ieee80211_hw_config(struct ieee80211_local *local);
int ieee80211_if_config(struct net_device *dev);
int ieee80211_if_config_beacon(struct net_device *dev);
void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx);
void ieee80211_if_setup(struct net_device *dev);
u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht,
struct ieee80211_ht_info *req_ht_cap,
struct ieee80211_ht_bss_info *req_bss_cap);
Expand Down Expand Up @@ -933,16 +926,14 @@ static inline void ieee80211_start_mesh(struct net_device *dev)
#endif

/* interface handling */
void ieee80211_if_setup(struct net_device *dev);
int ieee80211_if_add(struct ieee80211_local *local, const char *name,
struct net_device **new_dev, int type,
struct net_device **new_dev, enum ieee80211_if_types type,
struct vif_params *params);
void ieee80211_if_set_type(struct net_device *dev, int type);
void ieee80211_if_reinit(struct net_device *dev);
void __ieee80211_if_del(struct ieee80211_local *local,
struct ieee80211_sub_if_data *sdata);
int ieee80211_if_remove(struct net_device *dev, const char *name, int id);
void ieee80211_if_free(struct net_device *dev);
void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata);
void ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
enum ieee80211_if_types type);
void ieee80211_if_remove(struct net_device *dev);
void ieee80211_remove_interfaces(struct ieee80211_local *local);

/* tx handling */
void ieee80211_clear_tx_pending(struct ieee80211_local *local);
Expand Down
Loading

0 comments on commit 7563652

Please sign in to comment.