mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-22 21:22:37 +01:00
rtnlutil: Move rtnl_set_powered from netdev to rtnlutil
This function fits with the other utilities in rtnlutil and netdev.c can slim down.
This commit is contained in:
parent
3ffb645f22
commit
81be5fbae5
46
src/netdev.c
46
src/netdev.c
@ -340,31 +340,6 @@ static void netdev_set_powered_destroy(void *user_data)
|
|||||||
netdev->set_powered_user_data = NULL;
|
netdev->set_powered_user_data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t rtnl_set_powered(int ifindex, bool powered,
|
|
||||||
l_netlink_command_func_t cb, void *user_data,
|
|
||||||
l_netlink_destroy_func_t destroy)
|
|
||||||
{
|
|
||||||
struct ifinfomsg *rtmmsg;
|
|
||||||
size_t bufsize;
|
|
||||||
uint32_t id;
|
|
||||||
|
|
||||||
bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg));
|
|
||||||
|
|
||||||
rtmmsg = l_malloc(bufsize);
|
|
||||||
memset(rtmmsg, 0, bufsize);
|
|
||||||
|
|
||||||
rtmmsg->ifi_family = AF_UNSPEC;
|
|
||||||
rtmmsg->ifi_index = ifindex;
|
|
||||||
rtmmsg->ifi_change = IFF_UP;
|
|
||||||
rtmmsg->ifi_flags = powered ? IFF_UP : 0;
|
|
||||||
|
|
||||||
id = l_netlink_send(rtnl, RTM_SETLINK, 0, rtmmsg, bufsize,
|
|
||||||
cb, user_data, destroy);
|
|
||||||
|
|
||||||
l_free(rtmmsg);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
int netdev_set_powered(struct netdev *netdev, bool powered,
|
int netdev_set_powered(struct netdev *netdev, bool powered,
|
||||||
netdev_command_cb_t callback, void *user_data,
|
netdev_command_cb_t callback, void *user_data,
|
||||||
netdev_destroy_func_t destroy)
|
netdev_destroy_func_t destroy)
|
||||||
@ -374,7 +349,7 @@ int netdev_set_powered(struct netdev *netdev, bool powered,
|
|||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
netdev->set_powered_cmd_id =
|
netdev->set_powered_cmd_id =
|
||||||
rtnl_set_powered(netdev->index, powered,
|
rtnl_set_powered(rtnl, netdev->index, powered,
|
||||||
netdev_set_powered_result, netdev,
|
netdev_set_powered_result, netdev,
|
||||||
netdev_set_powered_destroy);
|
netdev_set_powered_destroy);
|
||||||
if (!netdev->set_powered_cmd_id)
|
if (!netdev->set_powered_cmd_id)
|
||||||
@ -664,7 +639,7 @@ static void netdev_shutdown_one(void *data, void *user_data)
|
|||||||
struct netdev *netdev = data;
|
struct netdev *netdev = data;
|
||||||
|
|
||||||
if (netdev_get_is_up(netdev))
|
if (netdev_get_is_up(netdev))
|
||||||
rtnl_set_powered(netdev->index, false, NULL, NULL, NULL);
|
rtnl_set_powered(rtnl, netdev->index, false, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool netdev_match(const void *a, const void *b)
|
static bool netdev_match(const void *a, const void *b)
|
||||||
@ -3917,7 +3892,7 @@ static void netdev_set_iftype_cb(struct l_genl_msg *msg, void *user_data)
|
|||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
netdev->set_powered_cmd_id =
|
netdev->set_powered_cmd_id =
|
||||||
rtnl_set_powered(netdev->index, true,
|
rtnl_set_powered(rtnl, netdev->index, true,
|
||||||
netdev_set_iftype_up_cb, req,
|
netdev_set_iftype_up_cb, req,
|
||||||
netdev_set_iftype_request_destroy);
|
netdev_set_iftype_request_destroy);
|
||||||
if (!netdev->set_powered_cmd_id) {
|
if (!netdev->set_powered_cmd_id) {
|
||||||
@ -4013,7 +3988,7 @@ int netdev_set_iftype(struct netdev *netdev, enum netdev_iftype type,
|
|||||||
l_genl_msg_unref(msg);
|
l_genl_msg_unref(msg);
|
||||||
} else {
|
} else {
|
||||||
netdev->set_powered_cmd_id =
|
netdev->set_powered_cmd_id =
|
||||||
rtnl_set_powered(netdev->index, false,
|
rtnl_set_powered(rtnl, netdev->index, false,
|
||||||
netdev_set_iftype_down_cb, req,
|
netdev_set_iftype_down_cb, req,
|
||||||
netdev_set_iftype_request_destroy);
|
netdev_set_iftype_request_destroy);
|
||||||
if (netdev->set_powered_cmd_id)
|
if (netdev->set_powered_cmd_id)
|
||||||
@ -4244,8 +4219,8 @@ static void netdev_set_mac_cb(int error, uint16_t type, const void *data,
|
|||||||
strerror(-error));
|
strerror(-error));
|
||||||
|
|
||||||
netdev->set_powered_cmd_id =
|
netdev->set_powered_cmd_id =
|
||||||
rtnl_set_powered(netdev->index, true, netdev_initial_up_cb,
|
rtnl_set_powered(rtnl, netdev->index, true,
|
||||||
netdev, NULL);
|
netdev_initial_up_cb, netdev, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void netdev_initial_down_cb(int error, uint16_t type, const void *data,
|
static void netdev_initial_down_cb(int error, uint16_t type, const void *data,
|
||||||
@ -4276,8 +4251,8 @@ static void netdev_initial_down_cb(int error, uint16_t type, const void *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
netdev->set_powered_cmd_id =
|
netdev->set_powered_cmd_id =
|
||||||
rtnl_set_powered(netdev->index, true, netdev_initial_up_cb,
|
rtnl_set_powered(rtnl, netdev->index, true,
|
||||||
netdev, NULL);
|
netdev_initial_up_cb, netdev, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void netdev_getlink_cb(int error, uint16_t type, const void *data,
|
static void netdev_getlink_cb(int error, uint16_t type, const void *data,
|
||||||
@ -4335,7 +4310,8 @@ static void netdev_getlink_cb(int error, uint16_t type, const void *data,
|
|||||||
cb = powered ? netdev_initial_down_cb : netdev_initial_up_cb;
|
cb = powered ? netdev_initial_down_cb : netdev_initial_up_cb;
|
||||||
|
|
||||||
netdev->set_powered_cmd_id =
|
netdev->set_powered_cmd_id =
|
||||||
rtnl_set_powered(ifi->ifi_index, !powered, cb, netdev, NULL);
|
rtnl_set_powered(rtnl, ifi->ifi_index, !powered, cb, netdev,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void netdev_frame_watch_free(struct watchlist_item *item)
|
static void netdev_frame_watch_free(struct watchlist_item *item)
|
||||||
@ -4653,6 +4629,8 @@ static void netdev_link_notify(uint16_t type, const void *data, uint32_t len,
|
|||||||
if (ifi->ifi_type != ARPHRD_ETHER)
|
if (ifi->ifi_type != ARPHRD_ETHER)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
l_debug("event %u on ifindex %u", type, ifi->ifi_index);
|
||||||
|
|
||||||
bytes = len - NLMSG_ALIGN(sizeof(struct ifinfomsg));
|
bytes = len - NLMSG_ALIGN(sizeof(struct ifinfomsg));
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <linux/if.h>
|
||||||
#include <linux/rtnetlink.h>
|
#include <linux/rtnetlink.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
@ -130,6 +131,31 @@ uint32_t rtnl_set_mac(struct l_netlink *rtnl, int ifindex,
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t rtnl_set_powered(struct l_netlink *rtnl, int ifindex, bool powered,
|
||||||
|
l_netlink_command_func_t cb, void *user_data,
|
||||||
|
l_netlink_destroy_func_t destroy)
|
||||||
|
{
|
||||||
|
struct ifinfomsg *rtmmsg;
|
||||||
|
size_t bufsize;
|
||||||
|
uint32_t id;
|
||||||
|
|
||||||
|
bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg));
|
||||||
|
|
||||||
|
rtmmsg = l_malloc(bufsize);
|
||||||
|
memset(rtmmsg, 0, bufsize);
|
||||||
|
|
||||||
|
rtmmsg->ifi_family = AF_UNSPEC;
|
||||||
|
rtmmsg->ifi_index = ifindex;
|
||||||
|
rtmmsg->ifi_change = IFF_UP;
|
||||||
|
rtmmsg->ifi_flags = powered ? IFF_UP : 0;
|
||||||
|
|
||||||
|
id = l_netlink_send(rtnl, RTM_SETLINK, 0, rtmmsg, bufsize,
|
||||||
|
cb, user_data, destroy);
|
||||||
|
l_free(rtmmsg);
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
void rtnl_ifaddr_extract(const struct ifaddrmsg *ifa, int bytes,
|
void rtnl_ifaddr_extract(const struct ifaddrmsg *ifa, int bytes,
|
||||||
char **label, char **ip, char **broadcast)
|
char **label, char **ip, char **broadcast)
|
||||||
{
|
{
|
||||||
|
@ -32,6 +32,10 @@ uint32_t rtnl_set_mac(struct l_netlink *rtnl, int ifindex,
|
|||||||
void *user_data,
|
void *user_data,
|
||||||
l_netlink_destroy_func_t destroy);
|
l_netlink_destroy_func_t destroy);
|
||||||
|
|
||||||
|
uint32_t rtnl_set_powered(struct l_netlink *rtnl, int ifindex, bool powered,
|
||||||
|
l_netlink_command_func_t cb, void *user_data,
|
||||||
|
l_netlink_destroy_func_t destroy);
|
||||||
|
|
||||||
void rtnl_ifaddr_extract(const struct ifaddrmsg *ifa, int bytes,
|
void rtnl_ifaddr_extract(const struct ifaddrmsg *ifa, int bytes,
|
||||||
char **label, char **ip, char **broadcast);
|
char **label, char **ip, char **broadcast);
|
||||||
uint32_t rtnl_ifaddr_get(struct l_netlink *rtnl, l_netlink_command_func_t cb,
|
uint32_t rtnl_ifaddr_get(struct l_netlink *rtnl, l_netlink_command_func_t cb,
|
||||||
|
Loading…
Reference in New Issue
Block a user