Skip to content

Commit bd90fdc

Browse files
jmberg-intellinvjw
authored andcommitted
nl80211: refactor mesh parameter parsing
I'm going to need this in a new place later. Tested-by: Javier Cardona <[email protected]> Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: John W. Linville <[email protected]>
1 parent f9e10ce commit bd90fdc

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

net/wireless/nl80211.c

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,14 +2613,6 @@ static int nl80211_get_mesh_params(struct sk_buff *skb,
26132613
return -ENOBUFS;
26142614
}
26152615

2616-
#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2617-
do {\
2618-
if (table[attr_num]) {\
2619-
cfg.param = nla_fn(table[attr_num]); \
2620-
mask |= (1 << (attr_num - 1)); \
2621-
} \
2622-
} while (0);\
2623-
26242616
static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
26252617
[NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
26262618
[NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
@@ -2639,31 +2631,34 @@ static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_A
26392631
[NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
26402632
};
26412633

2642-
static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2634+
static int nl80211_parse_mesh_params(struct genl_info *info,
2635+
struct mesh_config *cfg,
2636+
u32 *mask_out)
26432637
{
2644-
u32 mask;
2645-
struct cfg80211_registered_device *rdev = info->user_ptr[0];
2646-
struct net_device *dev = info->user_ptr[1];
2647-
struct mesh_config cfg;
26482638
struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
2649-
struct nlattr *parent_attr;
2639+
u32 mask = 0;
26502640

2651-
parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS];
2652-
if (!parent_attr)
2641+
#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2642+
do {\
2643+
if (table[attr_num]) {\
2644+
cfg->param = nla_fn(table[attr_num]); \
2645+
mask |= (1 << (attr_num - 1)); \
2646+
} \
2647+
} while (0);\
2648+
2649+
2650+
if (!info->attrs[NL80211_ATTR_MESH_PARAMS])
26532651
return -EINVAL;
26542652
if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
2655-
parent_attr, nl80211_meshconf_params_policy))
2653+
info->attrs[NL80211_ATTR_MESH_PARAMS],
2654+
nl80211_meshconf_params_policy))
26562655
return -EINVAL;
26572656

2658-
if (!rdev->ops->set_mesh_params)
2659-
return -EOPNOTSUPP;
2660-
26612657
/* This makes sure that there aren't more than 32 mesh config
26622658
* parameters (otherwise our bitfield scheme would not work.) */
26632659
BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
26642660

26652661
/* Fill in the params struct */
2666-
mask = 0;
26672662
FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
26682663
mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
26692664
FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
@@ -2703,12 +2698,32 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
27032698
NL80211_MESHCONF_HWMP_ROOTMODE,
27042699
nla_get_u8);
27052700

2701+
if (mask_out)
2702+
*mask_out = mask;
2703+
return 0;
2704+
2705+
#undef FILL_IN_MESH_PARAM_IF_SET
2706+
}
2707+
2708+
static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2709+
{
2710+
struct cfg80211_registered_device *rdev = info->user_ptr[0];
2711+
struct net_device *dev = info->user_ptr[1];
2712+
struct mesh_config cfg;
2713+
u32 mask;
2714+
int err;
2715+
2716+
if (!rdev->ops->set_mesh_params)
2717+
return -EOPNOTSUPP;
2718+
2719+
err = nl80211_parse_mesh_params(info, &cfg, &mask);
2720+
if (err)
2721+
return err;
2722+
27062723
/* Apply changes */
27072724
return rdev->ops->set_mesh_params(&rdev->wiphy, dev, &cfg, mask);
27082725
}
27092726

2710-
#undef FILL_IN_MESH_PARAM_IF_SET
2711-
27122727
static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
27132728
{
27142729
struct sk_buff *msg;

0 commit comments

Comments
 (0)