Commit a043897a authored by Holger Schurig's avatar Holger Schurig Committed by John W. Linville
Browse files

cfg80211: introduce nl80211_get_ifidx()



... which get's rid of three indentical cut-n-paste sections.
Signed-off-by: default avatarHolger Schurig <holgerschurig@gmail.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent f273fe55
...@@ -152,6 +152,26 @@ nl80211_key_policy[NL80211_KEY_MAX + 1] __read_mostly = { ...@@ -152,6 +152,26 @@ nl80211_key_policy[NL80211_KEY_MAX + 1] __read_mostly = {
[NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
}; };
/* ifidx get helper */
static int nl80211_get_ifidx(struct netlink_callback *cb)
{
int res;
res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
nl80211_fam.attrbuf, nl80211_fam.maxattr,
nl80211_policy);
if (res)
return res;
if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
return -EINVAL;
res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
if (!res)
return -EINVAL;
return res;
}
/* IE validation */ /* IE validation */
static bool is_valid_ie_attr(const struct nlattr *attr) static bool is_valid_ie_attr(const struct nlattr *attr)
{ {
...@@ -1693,20 +1713,10 @@ static int nl80211_dump_station(struct sk_buff *skb, ...@@ -1693,20 +1713,10 @@ static int nl80211_dump_station(struct sk_buff *skb,
int sta_idx = cb->args[1]; int sta_idx = cb->args[1];
int err; int err;
if (!ifidx) { if (!ifidx)
err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, ifidx = nl80211_get_ifidx(cb);
nl80211_fam.attrbuf, nl80211_fam.maxattr, if (ifidx < 0)
nl80211_policy); return ifidx;
if (err)
return err;
if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
return -EINVAL;
ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
if (!ifidx)
return -EINVAL;
}
rtnl_lock(); rtnl_lock();
...@@ -2156,20 +2166,10 @@ static int nl80211_dump_mpath(struct sk_buff *skb, ...@@ -2156,20 +2166,10 @@ static int nl80211_dump_mpath(struct sk_buff *skb,
int path_idx = cb->args[1]; int path_idx = cb->args[1];
int err; int err;
if (!ifidx) { if (!ifidx)
err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, ifidx = nl80211_get_ifidx(cb);
nl80211_fam.attrbuf, nl80211_fam.maxattr, if (ifidx < 0)
nl80211_policy); return ifidx;
if (err)
return err;
if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
return -EINVAL;
ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
if (!ifidx)
return -EINVAL;
}
rtnl_lock(); rtnl_lock();
...@@ -3198,21 +3198,11 @@ static int nl80211_dump_scan(struct sk_buff *skb, ...@@ -3198,21 +3198,11 @@ static int nl80211_dump_scan(struct sk_buff *skb,
int start = cb->args[1], idx = 0; int start = cb->args[1], idx = 0;
int err; int err;
if (!ifidx) { if (!ifidx)
err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, ifidx = nl80211_get_ifidx(cb);
nl80211_fam.attrbuf, nl80211_fam.maxattr, if (ifidx < 0)
nl80211_policy); return ifidx;
if (err) cb->args[0] = ifidx;
return err;
if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
return -EINVAL;
ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
if (!ifidx)
return -EINVAL;
cb->args[0] = ifidx;
}
dev = dev_get_by_index(sock_net(skb->sk), ifidx); dev = dev_get_by_index(sock_net(skb->sk), ifidx);
if (!dev) if (!dev)
......
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