netdev: Act on NEW_INTERFACE & DEL_INTERFACE cmds

This commit is contained in:
Denis Kenzior 2016-07-19 16:02:37 -05:00
parent 37ea99d09e
commit 94f204b994
1 changed files with 46 additions and 41 deletions

View File

@ -1334,8 +1334,7 @@ check_blacklist:
return true;
}
static void netdev_get_interface_callback(struct l_genl_msg *msg,
void *user_data)
static void netdev_create_from_genl(struct l_genl_msg *msg)
{
struct l_genl_attr attr;
uint16_t type, len;
@ -1432,7 +1431,7 @@ static void netdev_get_interface_callback(struct l_genl_msg *msg,
l_queue_push_tail(netdev_list, netdev);
l_debug("Found interface %s[%d]", netdev->name, netdev->index);
l_debug("Created interface %s[%d]", netdev->name, netdev->index);
/* Query interface flags */
bufsize = NLMSG_LENGTH(sizeof(struct ifinfomsg));
@ -1448,60 +1447,66 @@ static void netdev_get_interface_callback(struct l_genl_msg *msg,
l_free(rtmmsg);
}
static void netdev_get_interface_callback(struct l_genl_msg *msg,
void *user_data)
{
netdev_create_from_genl(msg);
}
static void netdev_config_notify(struct l_genl_msg *msg, void *user_data)
{
struct l_genl_attr attr;
uint16_t type, len;
const void *data;
uint8_t cmd;
const uint32_t *wiphy_id = NULL;
const uint32_t *ifindex = NULL;
struct netdev *netdev;
cmd = l_genl_msg_get_command(msg);
l_debug("Notification of command %u", cmd);
if (cmd == NL80211_CMD_NEW_INTERFACE) {
netdev_create_from_genl(msg);
return;
}
if (cmd != NL80211_CMD_DEL_INTERFACE)
return;
if (!l_genl_attr_init(&attr, msg))
return;
switch (cmd) {
case NL80211_CMD_NEW_INTERFACE:
case NL80211_CMD_DEL_INTERFACE:
{
const uint32_t *wiphy_id = NULL;
const uint32_t *ifindex = NULL;
while (l_genl_attr_next(&attr, &type, &len, &data)) {
switch (type) {
case NL80211_ATTR_WIPHY:
if (len != sizeof(uint32_t)) {
l_warn("Invalid wiphy attribute");
return;
}
wiphy_id = data;
break;
case NL80211_ATTR_IFINDEX:
if (len != sizeof(uint32_t)) {
l_warn("Invalid ifindex attribute");
return;
}
ifindex = data;
break;
while (l_genl_attr_next(&attr, &type, &len, &data)) {
switch (type) {
case NL80211_ATTR_WIPHY:
if (len != sizeof(uint32_t)) {
l_warn("Invalid wiphy attribute");
return;
}
wiphy_id = data;
break;
case NL80211_ATTR_IFINDEX:
if (len != sizeof(uint32_t)) {
l_warn("Invalid ifindex attribute");
return;
}
ifindex = data;
break;
}
if (!wiphy_id || !ifindex)
return;
if (cmd == NL80211_CMD_NEW_INTERFACE)
l_info("New interface %d added", *ifindex);
else
l_info("Interface %d removed", *ifindex);
break;
}
}
if (!wiphy_id || !ifindex)
return;
netdev = l_queue_remove_if(netdev_list, netdev_match,
L_UINT_TO_PTR(*ifindex));
if (!netdev)
return;
netdev_free(netdev);
}
static void netdev_link_notify(uint16_t type, const void *data, uint32_t len,