netdev: Make netdev_create_from_genl, netdev_destroy public

Make netdev_create_from_genl public and change signature to return the
created netdev or NULL.  Also add netdev_destroy that destroys and
unregisters the created netdevs.  Both will be used to move the
whole interface management to a new file.
This commit is contained in:
Andrew Zaborowski 2019-04-11 03:10:20 +02:00 committed by Denis Kenzior
parent 9aa2c8dae0
commit 8f910518c4
2 changed files with 27 additions and 13 deletions

View File

@ -4785,7 +4785,7 @@ error:
return NULL; return NULL;
} }
static void netdev_create_from_genl(struct l_genl_msg *msg) struct netdev *netdev_create_from_genl(struct l_genl_msg *msg)
{ {
struct l_genl_attr attr; struct l_genl_attr attr;
uint16_t type, len; uint16_t type, len;
@ -4806,14 +4806,14 @@ static void netdev_create_from_genl(struct l_genl_msg *msg)
bool pae_over_nl80211; bool pae_over_nl80211;
if (!l_genl_attr_init(&attr, msg)) if (!l_genl_attr_init(&attr, msg))
return; return NULL;
while (l_genl_attr_next(&attr, &type, &len, &data)) { while (l_genl_attr_next(&attr, &type, &len, &data)) {
switch (type) { switch (type) {
case NL80211_ATTR_IFINDEX: case NL80211_ATTR_IFINDEX:
if (len != sizeof(uint32_t)) { if (len != sizeof(uint32_t)) {
l_warn("Invalid interface index attribute"); l_warn("Invalid interface index attribute");
return; return NULL;
} }
ifindex = data; ifindex = data;
@ -4822,7 +4822,7 @@ static void netdev_create_from_genl(struct l_genl_msg *msg)
case NL80211_ATTR_IFNAME: case NL80211_ATTR_IFNAME:
if (len > IFNAMSIZ) { if (len > IFNAMSIZ) {
l_warn("Invalid interface name attribute"); l_warn("Invalid interface name attribute");
return; return NULL;
} }
ifname = data; ifname = data;
@ -4832,7 +4832,7 @@ static void netdev_create_from_genl(struct l_genl_msg *msg)
case NL80211_ATTR_WIPHY: case NL80211_ATTR_WIPHY:
if (len != sizeof(uint32_t)) { if (len != sizeof(uint32_t)) {
l_warn("Invalid wiphy attribute"); l_warn("Invalid wiphy attribute");
return; return NULL;
} }
wiphy = wiphy_find(*((uint32_t *) data)); wiphy = wiphy_find(*((uint32_t *) data));
@ -4841,7 +4841,7 @@ static void netdev_create_from_genl(struct l_genl_msg *msg)
case NL80211_ATTR_IFTYPE: case NL80211_ATTR_IFTYPE:
if (len != sizeof(uint32_t)) { if (len != sizeof(uint32_t)) {
l_warn("Invalid interface type attribute"); l_warn("Invalid interface type attribute");
return; return NULL;
} }
iftype = data; iftype = data;
@ -4850,7 +4850,7 @@ static void netdev_create_from_genl(struct l_genl_msg *msg)
case NL80211_ATTR_MAC: case NL80211_ATTR_MAC:
if (len != ETH_ALEN) { if (len != ETH_ALEN) {
l_warn("Invalid interface address attribute"); l_warn("Invalid interface address attribute");
return; return NULL;
} }
ifaddr = data; ifaddr = data;
@ -4859,26 +4859,26 @@ static void netdev_create_from_genl(struct l_genl_msg *msg)
} }
if (!wiphy) if (!wiphy)
return; return NULL;
if (!iftype) { if (!iftype) {
l_warn("Missing iftype attribute"); l_warn("Missing iftype attribute");
return; return NULL;
} }
if (!ifindex || !ifaddr | !ifname) { if (!ifindex || !ifaddr | !ifname) {
l_warn("Unable to parse interface information"); l_warn("Unable to parse interface information");
return; 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; return NULL;
} }
if (!netdev_is_managed(ifname)) { if (!netdev_is_managed(ifname)) {
l_debug("interface %s filtered out", ifname); l_debug("interface %s filtered out", ifname);
return; return NULL;
} }
if (!l_settings_get_bool(settings, "General", if (!l_settings_get_bool(settings, "General",
@ -4899,7 +4899,7 @@ static void netdev_create_from_genl(struct l_genl_msg *msg)
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; return NULL;
} }
} }
@ -4954,6 +4954,17 @@ static void netdev_create_from_genl(struct l_genl_msg *msg)
/* Set RSSI threshold for CQM notifications */ /* Set RSSI threshold for CQM notifications */
if (netdev->type == NL80211_IFTYPE_STATION) if (netdev->type == NL80211_IFTYPE_STATION)
netdev_cqm_rssi_update(netdev); netdev_cqm_rssi_update(netdev);
return netdev;
}
bool netdev_destroy(struct netdev *netdev)
{
if (!l_queue_remove(netdev_list, netdev))
return false;
netdev_free(netdev);
return true;
} }
static void netdev_get_interface_callback(struct l_genl_msg *msg, static void netdev_get_interface_callback(struct l_genl_msg *msg,

View File

@ -203,3 +203,6 @@ uint32_t netdev_station_watch_add(struct netdev *netdev,
netdev_station_watch_func_t func, void *user_data); netdev_station_watch_func_t func, void *user_data);
bool netdev_station_watch_remove(struct netdev *netdev, uint32_t id); bool netdev_station_watch_remove(struct netdev *netdev, uint32_t id);
struct netdev *netdev_create_from_genl(struct l_genl_msg *msg);
bool netdev_destroy(struct netdev *netdev);