mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-03 19:02:34 +01:00
netdev: Use nl80211_parse_attrs
This commit is contained in:
parent
9ee2b4ea4a
commit
83e535b643
107
src/netdev.c
107
src/netdev.c
@ -4437,14 +4437,12 @@ error:
|
||||
|
||||
struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac)
|
||||
{
|
||||
struct l_genl_attr attr;
|
||||
uint16_t type, len;
|
||||
const void *data;
|
||||
const char *ifname = NULL;
|
||||
uint16_t ifname_len = 0;
|
||||
const uint8_t *ifaddr = NULL;
|
||||
const uint32_t *ifindex = NULL, *iftype = NULL;
|
||||
const uint64_t *wdev = NULL;
|
||||
const char *ifname;
|
||||
const uint8_t *ifaddr;
|
||||
uint32_t ifindex;
|
||||
uint32_t iftype;
|
||||
uint64_t wdev;
|
||||
uint32_t wiphy_id;
|
||||
struct netdev *netdev;
|
||||
struct wiphy *wiphy = NULL;
|
||||
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 };
|
||||
struct l_io *pae_io = NULL;
|
||||
|
||||
if (!l_genl_attr_init(&attr, msg))
|
||||
return NULL;
|
||||
|
||||
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
||||
switch (type) {
|
||||
case NL80211_ATTR_IFINDEX:
|
||||
if (len != sizeof(uint32_t)) {
|
||||
l_warn("Invalid interface index attribute");
|
||||
if (nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
|
||||
NL80211_ATTR_WDEV, &wdev,
|
||||
NL80211_ATTR_IFNAME, &ifname,
|
||||
NL80211_ATTR_WIPHY, &wiphy_id,
|
||||
NL80211_ATTR_IFTYPE, &iftype,
|
||||
NL80211_ATTR_MAC, &ifaddr,
|
||||
NL80211_ATTR_UNSPEC) < 0) {
|
||||
l_warn("Required attributes missing");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ifindex = data;
|
||||
break;
|
||||
|
||||
case NL80211_ATTR_WDEV:
|
||||
if (len != sizeof(uint64_t)) {
|
||||
l_warn("Invalid wdev attribute");
|
||||
wiphy = wiphy_find(wiphy_id);
|
||||
if (!wiphy) {
|
||||
l_warn("No wiphy: %d", wiphy_id);
|
||||
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;
|
||||
}
|
||||
|
||||
if (!wiphy || !ifindex || !wdev || !ifaddr || !ifname) {
|
||||
l_warn("Unable to parse interface information");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (netdev_find(*ifindex)) {
|
||||
l_debug("Skipping duplicate netdev %s[%d]", ifname, *ifindex);
|
||||
if (netdev_find(ifindex)) {
|
||||
l_debug("Skipping duplicate netdev %s[%d]", ifname, ifindex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!wiphy_has_ext_feature(wiphy,
|
||||
NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211) ||
|
||||
!pae_over_nl80211) {
|
||||
pae_io = pae_open(*ifindex);
|
||||
pae_io = pae_open(ifindex);
|
||||
if (!pae_io) {
|
||||
l_error("Unable to open PAE interface");
|
||||
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->index = *ifindex;
|
||||
netdev->wdev_id = *wdev;
|
||||
netdev->type = *iftype;
|
||||
netdev->index = ifindex;
|
||||
netdev->wdev_id = wdev;
|
||||
netdev->type = iftype;
|
||||
netdev->rekey_offload_support = true;
|
||||
memcpy(netdev->addr, ifaddr, sizeof(netdev->addr));
|
||||
memcpy(netdev->name, ifname, ifname_len);
|
||||
l_strlcpy(netdev->name, ifname, IFNAMSIZ);
|
||||
netdev->wiphy = wiphy;
|
||||
netdev->pae_over_nl80211 = pae_io == NULL;
|
||||
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);
|
||||
|
||||
rtmmsg->ifi_family = AF_UNSPEC;
|
||||
rtmmsg->ifi_index = *ifindex;
|
||||
rtmmsg->ifi_index = ifindex;
|
||||
|
||||
l_netlink_send(rtnl, RTM_GETLINK, 0, rtmmsg, bufsize,
|
||||
netdev_getlink_cb, NULL, NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user