1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 06:25:37 +03:00

sd-netlink: introduce sd_netlink_attach_filter()

This commit is contained in:
Yu Watanabe 2021-10-19 02:41:38 +09:00
parent 0522729e19
commit dc317a9aed
2 changed files with 17 additions and 0 deletions

View File

@ -1023,3 +1023,18 @@ int sd_netlink_add_match(
return netlink_add_match_internal(rtnl, ret_slot, groups, n_groups, type, 0, callback,
destroy_callback, userdata, description);
}
int sd_netlink_attach_filter(sd_netlink *nl, size_t len, struct sock_filter *filter) {
assert_return(nl, -EINVAL);
assert_return(len == 0 || filter, -EINVAL);
if (setsockopt(nl->fd, SOL_SOCKET,
len == 0 ? SO_DETACH_FILTER : SO_ATTACH_FILTER,
&(struct sock_fprog) {
.len = len,
.filter = filter,
}, sizeof(struct sock_fprog)) < 0)
return -errno;
return 0;
}

View File

@ -21,6 +21,7 @@
#include <inttypes.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <linux/filter.h>
#include <linux/neighbour.h>
#include <linux/rtnetlink.h>
@ -68,6 +69,7 @@ int sd_netlink_add_match(sd_netlink *nl, sd_netlink_slot **ret_slot, uint16_t ma
int sd_netlink_attach_event(sd_netlink *nl, sd_event *e, int64_t priority);
int sd_netlink_detach_event(sd_netlink *nl);
int sd_netlink_attach_filter(sd_netlink *nl, size_t len, struct sock_filter *filter);
/* message */
int sd_netlink_message_append_string(sd_netlink_message *m, unsigned short type, const char *data);