1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-07 17:17:44 +03:00

netlink: introduce sd_netlink_message_has_flag()

This commit is contained in:
Yu Watanabe 2021-02-15 02:49:55 +09:00 committed by Lennart Poettering
parent 0a5393ad68
commit 3b4e3ebb51
2 changed files with 32 additions and 5 deletions

View File

@ -663,13 +663,17 @@ int sd_netlink_message_cancel_array(sd_netlink_message *m) {
return 0;
}
static int netlink_message_read_internal(sd_netlink_message *m, unsigned short type, void **data, bool *net_byteorder) {
static int netlink_message_read_internal(
sd_netlink_message *m,
unsigned short type,
void **ret_data,
bool *ret_net_byteorder) {
struct netlink_attribute *attribute;
struct rtattr *rta;
assert_return(m, -EINVAL);
assert_return(m->sealed, -EPERM);
assert_return(data, -EINVAL);
assert(m->n_containers < RTNL_CONTAINER_DEPTH);
@ -686,10 +690,11 @@ static int netlink_message_read_internal(sd_netlink_message *m, unsigned short t
rta = (struct rtattr*)((uint8_t *) m->hdr + attribute->offset);
*data = RTA_DATA(rta);
if (ret_data)
*ret_data = RTA_DATA(rta);
if (net_byteorder)
*net_byteorder = attribute->net_byteorder;
if (ret_net_byteorder)
*ret_net_byteorder = attribute->net_byteorder;
return RTA_PAYLOAD(rta);
}
@ -974,6 +979,27 @@ int sd_netlink_message_read_in6_addr(sd_netlink_message *m, unsigned short type,
return r;
}
int sd_netlink_message_has_flag(sd_netlink_message *m, unsigned short type) {
void *attr_data;
int r;
assert_return(m, -EINVAL);
/* This returns 1 when the flag is set, 0 when not set, negative errno on error. */
r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_FLAG);
if (r < 0)
return r;
r = netlink_message_read_internal(m, type, &attr_data, NULL);
if (r == -ENODATA)
return 0;
if (r < 0)
return r;
return 1;
}
int sd_netlink_message_read_strv(sd_netlink_message *m, unsigned short container_type, unsigned short type_id, char ***ret) {
_cleanup_strv_free_ char **s = NULL;
const NLTypeSystem *type_system;

View File

@ -116,6 +116,7 @@ int sd_netlink_message_read_ether_addr(sd_netlink_message *m, unsigned short typ
int sd_netlink_message_read_cache_info(sd_netlink_message *m, unsigned short type, struct ifa_cacheinfo *info);
int sd_netlink_message_read_in_addr(sd_netlink_message *m, unsigned short type, struct in_addr *data);
int sd_netlink_message_read_in6_addr(sd_netlink_message *m, unsigned short type, struct in6_addr *data);
int sd_netlink_message_has_flag(sd_netlink_message *m, unsigned short type);
int sd_netlink_message_enter_container(sd_netlink_message *m, unsigned short type);
int sd_netlink_message_enter_array(sd_netlink_message *m, unsigned short type);
int sd_netlink_message_exit_container(sd_netlink_message *m);