Skip to content

Commit dc317a9

Browse files
committed
sd-netlink: introduce sd_netlink_attach_filter()
1 parent 0522729 commit dc317a9

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/libsystemd/sd-netlink/sd-netlink.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,3 +1023,18 @@ int sd_netlink_add_match(
10231023
return netlink_add_match_internal(rtnl, ret_slot, groups, n_groups, type, 0, callback,
10241024
destroy_callback, userdata, description);
10251025
}
1026+
1027+
int sd_netlink_attach_filter(sd_netlink *nl, size_t len, struct sock_filter *filter) {
1028+
assert_return(nl, -EINVAL);
1029+
assert_return(len == 0 || filter, -EINVAL);
1030+
1031+
if (setsockopt(nl->fd, SOL_SOCKET,
1032+
len == 0 ? SO_DETACH_FILTER : SO_ATTACH_FILTER,
1033+
&(struct sock_fprog) {
1034+
.len = len,
1035+
.filter = filter,
1036+
}, sizeof(struct sock_fprog)) < 0)
1037+
return -errno;
1038+
1039+
return 0;
1040+
}

src/systemd/sd-netlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <inttypes.h>
2222
#include <net/ethernet.h>
2323
#include <netinet/in.h>
24+
#include <linux/filter.h>
2425
#include <linux/neighbour.h>
2526
#include <linux/rtnetlink.h>
2627

@@ -68,6 +69,7 @@ int sd_netlink_add_match(sd_netlink *nl, sd_netlink_slot **ret_slot, uint16_t ma
6869

6970
int sd_netlink_attach_event(sd_netlink *nl, sd_event *e, int64_t priority);
7071
int sd_netlink_detach_event(sd_netlink *nl);
72+
int sd_netlink_attach_filter(sd_netlink *nl, size_t len, struct sock_filter *filter);
7173

7274
/* message */
7375
int sd_netlink_message_append_string(sd_netlink_message *m, unsigned short type, const char *data);

0 commit comments

Comments
 (0)