3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-10-04 10:29:03 +02:00

netdev: Use nl80211_parse_attrs

This commit is contained in:
Denis Kenzior 2019-12-17 16:57:21 -06:00
parent 9ee2b4ea4a
commit 83e535b643

View File

@ -4437,14 +4437,12 @@ error:
struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac) struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac)
{ {
struct l_genl_attr attr; const char *ifname;
uint16_t type, len; const uint8_t *ifaddr;
const void *data; uint32_t ifindex;
const char *ifname = NULL; uint32_t iftype;
uint16_t ifname_len = 0; uint64_t wdev;
const uint8_t *ifaddr = NULL; uint32_t wiphy_id;
const uint32_t *ifindex = NULL, *iftype = NULL;
const uint64_t *wdev = NULL;
struct netdev *netdev; struct netdev *netdev;
struct wiphy *wiphy = NULL; struct wiphy *wiphy = NULL;
struct ifinfomsg *rtmmsg; struct ifinfomsg *rtmmsg;
@ -4456,87 +4454,32 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac)
const uint8_t action_qos_map_prefix[] = { 0x01, 0x04 }; const uint8_t action_qos_map_prefix[] = { 0x01, 0x04 };
struct l_io *pae_io = NULL; struct l_io *pae_io = NULL;
if (!l_genl_attr_init(&attr, msg)) if (nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
return NULL; NL80211_ATTR_WDEV, &wdev,
NL80211_ATTR_IFNAME, &ifname,
while (l_genl_attr_next(&attr, &type, &len, &data)) { NL80211_ATTR_WIPHY, &wiphy_id,
switch (type) { NL80211_ATTR_IFTYPE, &iftype,
case NL80211_ATTR_IFINDEX: NL80211_ATTR_MAC, &ifaddr,
if (len != sizeof(uint32_t)) { NL80211_ATTR_UNSPEC) < 0) {
l_warn("Invalid interface index attribute"); l_warn("Required attributes missing");
return NULL;
}
ifindex = data;
break;
case NL80211_ATTR_WDEV:
if (len != sizeof(uint64_t)) {
l_warn("Invalid wdev attribute");
return NULL;
}
wdev = data;
break;
case NL80211_ATTR_IFNAME:
if (len > IFNAMSIZ) {
l_warn("Invalid interface name attribute");
return NULL;
}
ifname = data;
ifname_len = len;
break;
case NL80211_ATTR_WIPHY:
if (len != sizeof(uint32_t)) {
l_warn("Invalid wiphy attribute");
return NULL;
}
wiphy = wiphy_find(*((uint32_t *) data));
break;
case NL80211_ATTR_IFTYPE:
if (len != sizeof(uint32_t)) {
l_warn("Invalid interface type attribute");
return NULL;
}
iftype = data;
break;
case NL80211_ATTR_MAC:
if (len != ETH_ALEN) {
l_warn("Invalid interface address attribute");
return NULL;
}
ifaddr = data;
break;
}
}
if (!iftype) {
l_warn("Missing iftype attribute");
return NULL; return NULL;
} }
if (!wiphy || !ifindex || !wdev || !ifaddr || !ifname) { wiphy = wiphy_find(wiphy_id);
l_warn("Unable to parse interface information"); if (!wiphy) {
l_warn("No wiphy: %d", wiphy_id);
return NULL; return NULL;
} }
if (netdev_find(*ifindex)) { if (netdev_find(ifindex)) {
l_debug("Skipping duplicate netdev %s[%d]", ifname, *ifindex); l_debug("Skipping duplicate netdev %s[%d]", ifname, ifindex);
return NULL; return NULL;
} }
if (!wiphy_has_ext_feature(wiphy, if (!wiphy_has_ext_feature(wiphy,
NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211) || NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211) ||
!pae_over_nl80211) { !pae_over_nl80211) {
pae_io = pae_open(*ifindex); pae_io = pae_open(ifindex);
if (!pae_io) { if (!pae_io) {
l_error("Unable to open PAE interface"); l_error("Unable to open PAE interface");
return NULL; return NULL;
@ -4544,12 +4487,12 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac)
} }
netdev = l_new(struct netdev, 1); netdev = l_new(struct netdev, 1);
netdev->index = *ifindex; netdev->index = ifindex;
netdev->wdev_id = *wdev; netdev->wdev_id = wdev;
netdev->type = *iftype; netdev->type = iftype;
netdev->rekey_offload_support = true; netdev->rekey_offload_support = true;
memcpy(netdev->addr, ifaddr, sizeof(netdev->addr)); memcpy(netdev->addr, ifaddr, sizeof(netdev->addr));
memcpy(netdev->name, ifname, ifname_len); l_strlcpy(netdev->name, ifname, IFNAMSIZ);
netdev->wiphy = wiphy; netdev->wiphy = wiphy;
netdev->pae_over_nl80211 = pae_io == NULL; netdev->pae_over_nl80211 = pae_io == NULL;
netdev->mac_randomize_once = random_mac; netdev->mac_randomize_once = random_mac;
@ -4574,7 +4517,7 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac)
memset(rtmmsg, 0, bufsize); memset(rtmmsg, 0, bufsize);
rtmmsg->ifi_family = AF_UNSPEC; rtmmsg->ifi_family = AF_UNSPEC;
rtmmsg->ifi_index = *ifindex; rtmmsg->ifi_index = ifindex;
l_netlink_send(rtnl, RTM_GETLINK, 0, rtmmsg, bufsize, l_netlink_send(rtnl, RTM_GETLINK, 0, rtmmsg, bufsize,
netdev_getlink_cb, NULL, NULL); netdev_getlink_cb, NULL, NULL);