mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-22 21:22:37 +01:00
netconfig: Obtain all currently assigned IPv4 addresses
This commit is contained in:
parent
9b0838d07c
commit
1368851611
@ -195,6 +195,22 @@ static void netconfig_ifaddr_notify(uint16_t type, const void *data,
|
||||
}
|
||||
}
|
||||
|
||||
static void netconfig_ifaddr_cmd_cb(int error, uint16_t type,
|
||||
const void *data, uint32_t len,
|
||||
void *user_data)
|
||||
{
|
||||
if (error) {
|
||||
l_error("netconfig: ifaddr command failure. "
|
||||
"Error %d: %s", error, strerror(-error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (type != RTM_NEWADDR)
|
||||
return;
|
||||
|
||||
netconfig_ifaddr_notify(type, data, len, user_data);
|
||||
}
|
||||
|
||||
bool netconfig_ifindex_add(uint32_t ifindex)
|
||||
{
|
||||
struct netconfig *netconfig;
|
||||
@ -272,6 +288,15 @@ static int netconfig_init(void)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = rtnl_ifaddr_get(rtnl, netconfig_ifaddr_cmd_cb, NULL, NULL);
|
||||
if (!r) {
|
||||
l_error("netconfig: Failed to get addresses from RTNL link.");
|
||||
l_netlink_destroy(rtnl);
|
||||
rtnl = NULL;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
netconfig_list = l_queue_new();
|
||||
|
||||
return 0;
|
||||
|
@ -110,3 +110,24 @@ void rtnl_ifaddr_extract(const struct ifaddrmsg *ifa, int bytes,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t rtnl_ifaddr_get(struct l_netlink *rtnl, l_netlink_command_func_t cb,
|
||||
void *user_data,
|
||||
l_netlink_destroy_func_t destroy)
|
||||
{
|
||||
struct ifaddrmsg *rtmmsg;
|
||||
uint32_t id;
|
||||
|
||||
rtmmsg = l_malloc(sizeof(struct ifaddrmsg));
|
||||
explicit_bzero(rtmmsg, sizeof(struct ifaddrmsg));
|
||||
|
||||
rtmmsg->ifa_family = AF_INET;
|
||||
|
||||
id = l_netlink_send(rtnl, RTM_GETADDR, NLM_F_DUMP, rtmmsg,
|
||||
sizeof(struct ifaddrmsg), cb, user_data,
|
||||
destroy);
|
||||
|
||||
l_free(rtmmsg);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
@ -28,3 +28,6 @@ uint32_t rtnl_set_linkmode_and_operstate(struct l_netlink *rtnl, int ifindex,
|
||||
|
||||
void rtnl_ifaddr_extract(const struct ifaddrmsg *ifa, int bytes,
|
||||
char **label, char **ip, char **broadcast);
|
||||
uint32_t rtnl_ifaddr_get(struct l_netlink *rtnl, l_netlink_command_func_t cb,
|
||||
void *user_data,
|
||||
l_netlink_destroy_func_t destroy);
|
||||
|
Loading…
Reference in New Issue
Block a user