3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-16 17:09:24 +01:00

monitor: Update to the new ell l_netlink_send API

This commit is contained in:
Denis Kenzior 2024-07-26 17:35:04 -05:00
parent e33fa63243
commit faa6a392e4

View File

@ -260,22 +260,6 @@ static struct l_genl *genl_lookup(const char *ifname)
return genl; return genl;
} }
static size_t rta_add(void *rta_buf, unsigned short type, uint16_t len,
const void *data)
{
unsigned short rta_len = RTA_LENGTH(len);
struct rtattr *rta = rta_buf;
memset(RTA_DATA(rta), 0, RTA_SPACE(len));
rta->rta_len = rta_len;
rta->rta_type = type;
if (len)
memcpy(RTA_DATA(rta), data, len);
return RTA_SPACE(len);
}
static bool rta_linkinfo_kind(struct rtattr *rta, unsigned short len, static bool rta_linkinfo_kind(struct rtattr *rta, unsigned short len,
const char* kind) const char* kind)
{ {
@ -304,10 +288,9 @@ static struct l_netlink *rtm_interface_send_message(struct l_netlink *rtnl,
{ {
size_t nlmon_type_len = strlen(NLMON_TYPE); size_t nlmon_type_len = strlen(NLMON_TYPE);
unsigned short ifname_len = 0; unsigned short ifname_len = 0;
size_t bufsize; struct l_netlink_message *nlm;
struct ifinfomsg *rtmmsg; struct ifinfomsg ifi;
void *rta_buf; uint16_t flags = 0;
struct rtattr *linkinfo_rta;
if (ifname) { if (ifname) {
ifname_len = strlen(ifname) + 1; ifname_len = strlen(ifname) + 1;
@ -316,64 +299,41 @@ static struct l_netlink *rtm_interface_send_message(struct l_netlink *rtnl,
return NULL; return NULL;
} }
if (!L_IN_SET(rtm_msg_type, RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK))
return NULL;
if (!rtnl) if (!rtnl)
rtnl = l_netlink_new(NETLINK_ROUTE); rtnl = l_netlink_new(NETLINK_ROUTE);
if (!rtnl) if (!rtnl)
return NULL; return NULL;
bufsize = NLMSG_LENGTH(sizeof(struct ifinfomsg)) + memset(&ifi, 0, sizeof(ifi));
RTA_SPACE(ifname_len) + RTA_SPACE(0) + ifi.ifi_family = AF_UNSPEC;
RTA_SPACE(nlmon_type_len); ifi.ifi_change = ~0;
rtmmsg = l_malloc(bufsize);
memset(rtmmsg, 0, bufsize);
rtmmsg->ifi_family = AF_UNSPEC;
rtmmsg->ifi_change = ~0;
rta_buf = rtmmsg + 1;
if (ifname)
rta_buf += rta_add(rta_buf, IFLA_IFNAME, ifname_len, ifname);
linkinfo_rta = rta_buf;
rta_buf += rta_add(rta_buf, IFLA_LINKINFO, 0, NULL);
rta_buf += rta_add(rta_buf, IFLA_INFO_KIND, nlmon_type_len, NLMON_TYPE);
linkinfo_rta->rta_len = rta_buf - (void *) linkinfo_rta;
switch (rtm_msg_type) { switch (rtm_msg_type) {
case RTM_NEWLINK: case RTM_NEWLINK:
rtmmsg->ifi_flags = IFF_UP | IFF_ALLMULTI | IFF_NOARP; ifi.ifi_flags = IFF_UP | IFF_ALLMULTI | IFF_NOARP;
flags = NLM_F_CREATE | NLM_F_EXCL;
l_netlink_send(rtnl, RTM_NEWLINK, NLM_F_CREATE|NLM_F_EXCL,
rtmmsg, rta_buf - (void *) rtmmsg, callback,
user_data, destroy);
break; break;
case RTM_DELLINK:
rta_buf += rta_add(rta_buf, IFLA_IFNAME, ifname_len, ifname);
l_netlink_send(rtnl, RTM_DELLINK, 0, rtmmsg,
rta_buf - (void *)rtmmsg, callback, user_data,
destroy);
break;
case RTM_GETLINK: case RTM_GETLINK:
l_netlink_send(rtnl, RTM_GETLINK, NLM_F_DUMP, rtmmsg, flags = NLM_F_DUMP;
rta_buf - (void *)rtmmsg, callback, user_data,
destroy);
break;
default:
l_netlink_destroy(rtnl);
rtnl = NULL;
break; break;
} }
l_free(rtmmsg); nlm = l_netlink_message_new(rtm_msg_type, flags);;
l_netlink_message_add_header(nlm, &ifi, sizeof(ifi));
if (ifname)
l_netlink_message_append(nlm, IFLA_IFNAME, ifname, ifname_len);
l_netlink_message_enter_nested(nlm, IFLA_LINKINFO);
l_netlink_message_append(nlm, IFLA_INFO_KIND,
NLMON_TYPE, nlmon_type_len);
l_netlink_message_leave_nested(nlm);
l_netlink_send(rtnl, nlm, callback, user_data, destroy);
return rtnl; return rtnl;
} }