1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 #include <linux/filter.h>
5 #include <linux/netlink.h>
6 #include <linux/sockios.h>
10 #include "sd-device.h"
13 #include "MurmurHash2.h"
14 #include "alloc-util.h"
15 #include "device-monitor-private.h"
16 #include "device-private.h"
17 #include "device-util.h"
18 #include "errno-util.h"
20 #include "format-util.h"
23 #include "missing_socket.h"
24 #include "mountpoint-util.h"
26 #include "socket-util.h"
27 #include "string-util.h"
30 struct sd_device_monitor
{
34 union sockaddr_union snl
;
35 union sockaddr_union snl_trusted_sender
;
38 Hashmap
*subsystem_filter
;
43 sd_event_source
*event_source
;
44 sd_device_monitor_handler_t callback
;
48 #define UDEV_MONITOR_MAGIC 0xfeedcafe
50 typedef struct monitor_netlink_header
{
51 /* "libudev" prefix to distinguish libudev and kernel messages */
53 /* Magic to protect against daemon <-> Library message format mismatch
54 * Used in the kernel from socket filter rules; needs to be stored in network order */
56 /* Total length of header structure known to the sender */
58 /* Properties string buffer */
59 unsigned properties_off
;
60 unsigned properties_len
;
61 /* Hashes of primary device properties strings, to let libudev subscribers
62 * use in-kernel socket filters; values need to be stored in network order */
63 unsigned filter_subsystem_hash
;
64 unsigned filter_devtype_hash
;
65 unsigned filter_tag_bloom_hi
;
66 unsigned filter_tag_bloom_lo
;
67 } monitor_netlink_header
;
69 static int monitor_set_nl_address(sd_device_monitor
*m
) {
70 union sockaddr_union snl
;
75 /* Get the address the kernel has assigned us.
76 * It is usually, but not necessarily the pid. */
77 addrlen
= sizeof(struct sockaddr_nl
);
78 if (getsockname(m
->sock
, &snl
.sa
, &addrlen
) < 0)
81 m
->snl
.nl
.nl_pid
= snl
.nl
.nl_pid
;
85 int device_monitor_allow_unicast_sender(sd_device_monitor
*m
, sd_device_monitor
*sender
) {
86 assert_return(m
, -EINVAL
);
87 assert_return(sender
, -EINVAL
);
89 m
->snl_trusted_sender
.nl
.nl_pid
= sender
->snl
.nl
.nl_pid
;
93 _public_
int sd_device_monitor_set_receive_buffer_size(sd_device_monitor
*m
, size_t size
) {
94 int r
, n
= (int) size
;
96 assert_return(m
, -EINVAL
);
97 assert_return((size_t) n
== size
, -EINVAL
);
99 if (setsockopt_int(m
->sock
, SOL_SOCKET
, SO_RCVBUFFORCE
, n
) < 0) {
100 r
= setsockopt_int(m
->sock
, SOL_SOCKET
, SO_RCVBUF
, n
);
108 int device_monitor_disconnect(sd_device_monitor
*m
) {
111 m
->sock
= safe_close(m
->sock
);
115 int device_monitor_get_fd(sd_device_monitor
*m
) {
116 assert_return(m
, -EINVAL
);
121 int device_monitor_new_full(sd_device_monitor
**ret
, MonitorNetlinkGroup group
, int fd
) {
122 _cleanup_(sd_device_monitor_unrefp
) sd_device_monitor
*m
= NULL
;
123 _cleanup_close_
int sock
= -1;
126 assert_return(ret
, -EINVAL
);
127 assert_return(group
>= 0 && group
< _MONITOR_NETLINK_GROUP_MAX
, -EINVAL
);
129 if (group
== MONITOR_GROUP_UDEV
&&
130 access("/run/udev/control", F_OK
) < 0 &&
131 dev_is_devtmpfs() <= 0) {
134 * We do not support subscribing to uevents if no instance of
135 * udev is running. Uevents would otherwise broadcast the
136 * processing data of the host into containers, which is not
139 * Containers will currently not get any udev uevents, until
140 * a supporting infrastructure is available.
142 * We do not set a netlink multicast group here, so the socket
143 * will not receive any messages.
146 log_debug("sd-device-monitor: The udev service seems not to be active, disabling the monitor");
147 group
= MONITOR_GROUP_NONE
;
151 sock
= socket(PF_NETLINK
, SOCK_RAW
|SOCK_CLOEXEC
|SOCK_NONBLOCK
, NETLINK_KOBJECT_UEVENT
);
153 return log_debug_errno(errno
, "sd-device-monitor: Failed to create socket: %m");
156 m
= new(sd_device_monitor
, 1);
160 *m
= (sd_device_monitor
) {
162 .sock
= fd
>= 0 ? fd
: TAKE_FD(sock
),
164 .snl
.nl
.nl_family
= AF_NETLINK
,
165 .snl
.nl
.nl_groups
= group
,
169 r
= monitor_set_nl_address(m
);
171 log_debug_errno(r
, "sd-device-monitor: Failed to set netlink address: %m");
177 _cleanup_close_
int netns
= -1;
179 /* So here's the thing: only AF_NETLINK sockets from the main network namespace will get
180 * hardware events. Let's check if ours is from there, and if not generate a debug message,
181 * since we cannot possibly work correctly otherwise. This is just a safety check to make
182 * things easier to debug. */
184 netns
= ioctl(m
->sock
, SIOCGSKNS
);
186 log_debug_errno(errno
, "sd-device-monitor: Unable to get network namespace of udev netlink socket, unable to determine if we are in host netns: %m");
190 if (fstat(netns
, &a
) < 0) {
191 r
= log_debug_errno(errno
, "sd-device-monitor: Failed to stat netns of udev netlink socket: %m");
195 if (stat("/proc/1/ns/net", &b
) < 0) {
196 if (ERRNO_IS_PRIVILEGE(errno
))
197 /* If we can't access PID1's netns info due to permissions, it's fine, this is a
198 * safety check only after all. */
199 log_debug_errno(errno
, "sd-device-monitor: No permission to stat PID1's netns, unable to determine if we are in host netns: %m");
201 log_debug_errno(errno
, "sd-device-monitor: Failed to stat PID1's netns: %m");
203 } else if (a
.st_dev
!= b
.st_dev
|| a
.st_ino
!= b
.st_ino
)
204 log_debug("sd-device-monitor: Netlink socket we listen on is not from host netns, we won't see device events.");
212 /* Let's unset the socket fd in the monitor object before we destroy it so that the fd passed in is
213 * not closed on failure. */
220 _public_
int sd_device_monitor_new(sd_device_monitor
**ret
) {
221 return device_monitor_new_full(ret
, MONITOR_GROUP_UDEV
, -1);
224 _public_
int sd_device_monitor_stop(sd_device_monitor
*m
) {
225 assert_return(m
, -EINVAL
);
227 m
->event_source
= sd_event_source_unref(m
->event_source
);
228 (void) device_monitor_disconnect(m
);
233 static int device_monitor_event_handler(sd_event_source
*s
, int fd
, uint32_t revents
, void *userdata
) {
234 _cleanup_(sd_device_unrefp
) sd_device
*device
= NULL
;
235 sd_device_monitor
*m
= userdata
;
239 if (device_monitor_receive_device(m
, &device
) <= 0)
243 return m
->callback(m
, device
, m
->userdata
);
248 _public_
int sd_device_monitor_start(sd_device_monitor
*m
, sd_device_monitor_handler_t callback
, void *userdata
) {
251 assert_return(m
, -EINVAL
);
254 r
= sd_device_monitor_attach_event(m
, NULL
);
259 r
= device_monitor_enable_receiving(m
);
263 m
->callback
= callback
;
264 m
->userdata
= userdata
;
266 r
= sd_event_add_io(m
->event
, &m
->event_source
, m
->sock
, EPOLLIN
, device_monitor_event_handler
, m
);
270 (void) sd_event_source_set_description(m
->event_source
, "sd-device-monitor");
275 _public_
int sd_device_monitor_detach_event(sd_device_monitor
*m
) {
276 assert_return(m
, -EINVAL
);
278 (void) sd_device_monitor_stop(m
);
279 m
->event
= sd_event_unref(m
->event
);
284 _public_
int sd_device_monitor_attach_event(sd_device_monitor
*m
, sd_event
*event
) {
287 assert_return(m
, -EINVAL
);
288 assert_return(!m
->event
, -EBUSY
);
291 m
->event
= sd_event_ref(event
);
293 r
= sd_event_default(&m
->event
);
301 _public_ sd_event
*sd_device_monitor_get_event(sd_device_monitor
*m
) {
302 assert_return(m
, NULL
);
307 _public_ sd_event_source
*sd_device_monitor_get_event_source(sd_device_monitor
*m
) {
308 assert_return(m
, NULL
);
310 return m
->event_source
;
313 int device_monitor_enable_receiving(sd_device_monitor
*m
) {
316 assert_return(m
, -EINVAL
);
318 r
= sd_device_monitor_filter_update(m
);
320 return log_debug_errno(r
, "sd-device-monitor: Failed to update filter: %m");
323 /* enable receiving of sender credentials */
324 r
= setsockopt_int(m
->sock
, SOL_SOCKET
, SO_PASSCRED
, true);
326 return log_debug_errno(r
, "sd-device-monitor: Failed to set socket option SO_PASSCRED: %m");
328 if (bind(m
->sock
, &m
->snl
.sa
, sizeof(struct sockaddr_nl
)) < 0)
329 return log_debug_errno(errno
, "sd-device-monitor: Failed to bind monitoring socket: %m");
333 r
= monitor_set_nl_address(m
);
335 return log_debug_errno(r
, "sd-device-monitor: Failed to set address: %m");
341 static sd_device_monitor
*device_monitor_free(sd_device_monitor
*m
) {
344 (void) sd_device_monitor_detach_event(m
);
346 hashmap_free_free_free(m
->subsystem_filter
);
347 set_free_free(m
->tag_filter
);
352 DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_device_monitor
, sd_device_monitor
, device_monitor_free
);
354 static int passes_filter(sd_device_monitor
*m
, sd_device
*device
) {
355 const char *tag
, *subsystem
, *devtype
, *s
, *d
= NULL
;
359 assert_return(m
, -EINVAL
);
360 assert_return(device
, -EINVAL
);
362 if (hashmap_isempty(m
->subsystem_filter
))
365 r
= sd_device_get_subsystem(device
, &s
);
369 r
= sd_device_get_devtype(device
, &d
);
370 if (r
< 0 && r
!= -ENOENT
)
373 HASHMAP_FOREACH_KEY(devtype
, subsystem
, m
->subsystem_filter
, i
) {
374 if (!streq(s
, subsystem
))
383 if (streq(d
, devtype
))
390 if (set_isempty(m
->tag_filter
))
393 SET_FOREACH(tag
, m
->tag_filter
, i
)
394 if (sd_device_has_tag(device
, tag
) > 0)
400 int device_monitor_receive_device(sd_device_monitor
*m
, sd_device
**ret
) {
401 _cleanup_(sd_device_unrefp
) sd_device
*device
= NULL
;
403 monitor_netlink_header nlh
;
408 .iov_len
= sizeof(buf
)
410 CMSG_BUFFER_TYPE(CMSG_SPACE(sizeof(struct ucred
))) control
;
411 union sockaddr_union snl
;
412 struct msghdr smsg
= {
415 .msg_control
= &control
,
416 .msg_controllen
= sizeof(control
),
418 .msg_namelen
= sizeof(snl
),
420 struct cmsghdr
*cmsg
;
422 ssize_t buflen
, bufpos
;
423 bool is_initialized
= false;
428 buflen
= recvmsg(m
->sock
, &smsg
, 0);
431 log_debug_errno(errno
, "sd-device-monitor: Failed to receive message: %m");
435 if (buflen
< 32 || (smsg
.msg_flags
& MSG_TRUNC
))
436 return log_debug_errno(SYNTHETIC_ERRNO(EINVAL
),
437 "sd-device-monitor: Invalid message length.");
439 if (snl
.nl
.nl_groups
== MONITOR_GROUP_NONE
) {
440 /* unicast message, check if we trust the sender */
441 if (m
->snl_trusted_sender
.nl
.nl_pid
== 0 ||
442 snl
.nl
.nl_pid
!= m
->snl_trusted_sender
.nl
.nl_pid
)
443 return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN
),
444 "sd-device-monitor: Unicast netlink message ignored.");
446 } else if (snl
.nl
.nl_groups
== MONITOR_GROUP_KERNEL
) {
447 if (snl
.nl
.nl_pid
> 0)
448 return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN
),
449 "sd-device-monitor: Multicast kernel netlink message from PID %"PRIu32
" ignored.", snl
.nl
.nl_pid
);
452 cmsg
= CMSG_FIRSTHDR(&smsg
);
453 if (!cmsg
|| cmsg
->cmsg_type
!= SCM_CREDENTIALS
)
454 return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN
),
455 "sd-device-monitor: No sender credentials received, message ignored.");
457 cred
= (struct ucred
*) CMSG_DATA(cmsg
);
459 return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN
),
460 "sd-device-monitor: Sender uid="UID_FMT
", message ignored.", cred
->uid
);
462 if (streq(buf
.raw
, "libudev")) {
463 /* udev message needs proper version magic */
464 if (buf
.nlh
.magic
!= htobe32(UDEV_MONITOR_MAGIC
))
465 return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN
),
466 "sd-device-monitor: Invalid message signature (%x != %x)",
467 buf
.nlh
.magic
, htobe32(UDEV_MONITOR_MAGIC
));
469 if (buf
.nlh
.properties_off
+32 > (size_t) buflen
)
470 return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN
),
471 "sd-device-monitor: Invalid message length (%u > %zd)",
472 buf
.nlh
.properties_off
+32, buflen
);
474 bufpos
= buf
.nlh
.properties_off
;
476 /* devices received from udev are always initialized */
477 is_initialized
= true;
480 /* kernel message with header */
481 bufpos
= strlen(buf
.raw
) + 1;
482 if ((size_t) bufpos
< sizeof("a@/d") || bufpos
>= buflen
)
483 return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN
),
484 "sd-device-monitor: Invalid message length");
486 /* check message header */
487 if (!strstr(buf
.raw
, "@/"))
488 return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN
),
489 "sd-device-monitor: Invalid message header");
492 r
= device_new_from_nulstr(&device
, (uint8_t*) &buf
.raw
[bufpos
], buflen
- bufpos
);
494 return log_debug_errno(r
, "sd-device-monitor: Failed to create device from received message: %m");
497 device_set_is_initialized(device
);
499 /* Skip device, if it does not pass the current filter */
500 r
= passes_filter(m
, device
);
502 return log_device_debug_errno(device
, r
, "sd-device-monitor: Failed to check received device passing filter: %m");
504 log_device_debug(device
, "sd-device-monitor: Received device does not pass filter, ignoring");
506 *ret
= TAKE_PTR(device
);
511 static uint32_t string_hash32(const char *str
) {
512 return MurmurHash2(str
, strlen(str
), 0);
515 /* Get a bunch of bit numbers out of the hash, and set the bits in our bit field */
516 static uint64_t string_bloom64(const char *str
) {
518 uint32_t hash
= string_hash32(str
);
520 bits
|= 1LLU << (hash
& 63);
521 bits
|= 1LLU << ((hash
>> 6) & 63);
522 bits
|= 1LLU << ((hash
>> 12) & 63);
523 bits
|= 1LLU << ((hash
>> 18) & 63);
527 int device_monitor_send_device(
528 sd_device_monitor
*m
,
529 sd_device_monitor
*destination
,
532 monitor_netlink_header nlh
= {
534 .magic
= htobe32(UDEV_MONITOR_MAGIC
),
535 .header_size
= sizeof nlh
,
537 struct iovec iov
[2] = {
538 { .iov_base
= &nlh
, .iov_len
= sizeof nlh
},
540 struct msghdr smsg
= {
544 /* default destination for sending */
545 union sockaddr_union default_destination
= {
546 .nl
.nl_family
= AF_NETLINK
,
547 .nl
.nl_groups
= MONITOR_GROUP_UDEV
,
549 uint64_t tag_bloom_bits
;
550 const char *buf
, *val
;
558 r
= device_get_properties_nulstr(device
, (const uint8_t **) &buf
, &blen
);
560 return log_device_debug_errno(device
, r
, "sd-device-monitor: Failed to get device properties: %m");
562 log_device_debug(device
, "sd-device-monitor: Length of device property nulstr is too small to contain valid device information");
566 /* fill in versioned header */
567 r
= sd_device_get_subsystem(device
, &val
);
569 return log_device_debug_errno(device
, r
, "sd-device-monitor: Failed to get device subsystem: %m");
570 nlh
.filter_subsystem_hash
= htobe32(string_hash32(val
));
572 if (sd_device_get_devtype(device
, &val
) >= 0)
573 nlh
.filter_devtype_hash
= htobe32(string_hash32(val
));
575 /* add tag bloom filter */
577 FOREACH_DEVICE_TAG(device
, val
)
578 tag_bloom_bits
|= string_bloom64(val
);
580 if (tag_bloom_bits
> 0) {
581 nlh
.filter_tag_bloom_hi
= htobe32(tag_bloom_bits
>> 32);
582 nlh
.filter_tag_bloom_lo
= htobe32(tag_bloom_bits
& 0xffffffff);
585 /* add properties list */
586 nlh
.properties_off
= iov
[0].iov_len
;
587 nlh
.properties_len
= blen
;
588 iov
[1] = IOVEC_MAKE((char*) buf
, blen
);
591 * Use custom address for target, or the default one.
593 * If we send to a multicast group, we will get
594 * ECONNREFUSED, which is expected.
596 smsg
.msg_name
= destination
? &destination
->snl
: &default_destination
;
597 smsg
.msg_namelen
= sizeof(struct sockaddr_nl
);
598 count
= sendmsg(m
->sock
, &smsg
, 0);
600 if (!destination
&& errno
== ECONNREFUSED
) {
601 log_device_debug(device
, "sd-device-monitor: Passed to netlink monitor");
604 return log_device_debug_errno(device
, errno
, "sd-device-monitor: Failed to send device to netlink monitor: %m");
607 log_device_debug(device
, "sd-device-monitor: Passed %zi byte to netlink monitor", count
);
611 static void bpf_stmt(struct sock_filter
*ins
, unsigned *i
,
612 unsigned short code
, unsigned data
) {
613 ins
[(*i
)++] = (struct sock_filter
) {
619 static void bpf_jmp(struct sock_filter
*ins
, unsigned *i
,
620 unsigned short code
, unsigned data
,
621 unsigned short jt
, unsigned short jf
) {
622 ins
[(*i
)++] = (struct sock_filter
) {
630 _public_
int sd_device_monitor_filter_update(sd_device_monitor
*m
) {
631 struct sock_filter ins
[512] = {};
632 struct sock_fprog filter
;
633 const char *subsystem
, *devtype
, *tag
;
637 assert_return(m
, -EINVAL
);
639 if (m
->filter_uptodate
)
642 if (hashmap_isempty(m
->subsystem_filter
) &&
643 set_isempty(m
->tag_filter
)) {
644 m
->filter_uptodate
= true;
648 /* load magic in A */
649 bpf_stmt(ins
, &i
, BPF_LD
|BPF_W
|BPF_ABS
, offsetof(monitor_netlink_header
, magic
));
650 /* jump if magic matches */
651 bpf_jmp(ins
, &i
, BPF_JMP
|BPF_JEQ
|BPF_K
, UDEV_MONITOR_MAGIC
, 1, 0);
652 /* wrong magic, pass packet */
653 bpf_stmt(ins
, &i
, BPF_RET
|BPF_K
, 0xffffffff);
655 if (!set_isempty(m
->tag_filter
)) {
656 int tag_matches
= set_size(m
->tag_filter
);
658 /* add all tags matches */
659 SET_FOREACH(tag
, m
->tag_filter
, it
) {
660 uint64_t tag_bloom_bits
= string_bloom64(tag
);
661 uint32_t tag_bloom_hi
= tag_bloom_bits
>> 32;
662 uint32_t tag_bloom_lo
= tag_bloom_bits
& 0xffffffff;
664 /* load device bloom bits in A */
665 bpf_stmt(ins
, &i
, BPF_LD
|BPF_W
|BPF_ABS
, offsetof(monitor_netlink_header
, filter_tag_bloom_hi
));
666 /* clear bits (tag bits & bloom bits) */
667 bpf_stmt(ins
, &i
, BPF_ALU
|BPF_AND
|BPF_K
, tag_bloom_hi
);
668 /* jump to next tag if it does not match */
669 bpf_jmp(ins
, &i
, BPF_JMP
|BPF_JEQ
|BPF_K
, tag_bloom_hi
, 0, 3);
671 /* load device bloom bits in A */
672 bpf_stmt(ins
, &i
, BPF_LD
|BPF_W
|BPF_ABS
, offsetof(monitor_netlink_header
, filter_tag_bloom_lo
));
673 /* clear bits (tag bits & bloom bits) */
674 bpf_stmt(ins
, &i
, BPF_ALU
|BPF_AND
|BPF_K
, tag_bloom_lo
);
675 /* jump behind end of tag match block if tag matches */
677 bpf_jmp(ins
, &i
, BPF_JMP
|BPF_JEQ
|BPF_K
, tag_bloom_lo
, 1 + (tag_matches
* 6), 0);
680 /* nothing matched, drop packet */
681 bpf_stmt(ins
, &i
, BPF_RET
|BPF_K
, 0);
684 /* add all subsystem matches */
685 if (!hashmap_isempty(m
->subsystem_filter
)) {
686 HASHMAP_FOREACH_KEY(devtype
, subsystem
, m
->subsystem_filter
, it
) {
687 uint32_t hash
= string_hash32(subsystem
);
689 /* load device subsystem value in A */
690 bpf_stmt(ins
, &i
, BPF_LD
|BPF_W
|BPF_ABS
, offsetof(monitor_netlink_header
, filter_subsystem_hash
));
692 /* jump if subsystem does not match */
693 bpf_jmp(ins
, &i
, BPF_JMP
|BPF_JEQ
|BPF_K
, hash
, 0, 1);
695 /* jump if subsystem does not match */
696 bpf_jmp(ins
, &i
, BPF_JMP
|BPF_JEQ
|BPF_K
, hash
, 0, 3);
697 /* load device devtype value in A */
698 bpf_stmt(ins
, &i
, BPF_LD
|BPF_W
|BPF_ABS
, offsetof(monitor_netlink_header
, filter_devtype_hash
));
699 /* jump if value does not match */
700 hash
= string_hash32(devtype
);
701 bpf_jmp(ins
, &i
, BPF_JMP
|BPF_JEQ
|BPF_K
, hash
, 0, 1);
704 /* matched, pass packet */
705 bpf_stmt(ins
, &i
, BPF_RET
|BPF_K
, 0xffffffff);
707 if (i
+1 >= ELEMENTSOF(ins
))
711 /* nothing matched, drop packet */
712 bpf_stmt(ins
, &i
, BPF_RET
|BPF_K
, 0);
715 /* matched, pass packet */
716 bpf_stmt(ins
, &i
, BPF_RET
|BPF_K
, 0xffffffff);
719 filter
= (struct sock_fprog
) {
723 if (setsockopt(m
->sock
, SOL_SOCKET
, SO_ATTACH_FILTER
, &filter
, sizeof(filter
)) < 0)
726 m
->filter_uptodate
= true;
730 _public_
int sd_device_monitor_filter_add_match_subsystem_devtype(sd_device_monitor
*m
, const char *subsystem
, const char *devtype
) {
731 _cleanup_free_
char *s
= NULL
, *d
= NULL
;
734 assert_return(m
, -EINVAL
);
735 assert_return(subsystem
, -EINVAL
);
737 s
= strdup(subsystem
);
747 r
= hashmap_ensure_allocated(&m
->subsystem_filter
, NULL
);
751 r
= hashmap_put(m
->subsystem_filter
, s
, d
);
756 m
->filter_uptodate
= false;
761 _public_
int sd_device_monitor_filter_add_match_tag(sd_device_monitor
*m
, const char *tag
) {
762 _cleanup_free_
char *t
= NULL
;
765 assert_return(m
, -EINVAL
);
766 assert_return(tag
, -EINVAL
);
772 r
= set_ensure_allocated(&m
->tag_filter
, &string_hash_ops
);
776 r
= set_put(m
->tag_filter
, t
);
783 m
->filter_uptodate
= false;
788 _public_
int sd_device_monitor_filter_remove(sd_device_monitor
*m
) {
789 static const struct sock_fprog filter
= { 0, NULL
};
791 assert_return(m
, -EINVAL
);
793 m
->subsystem_filter
= hashmap_free_free_free(m
->subsystem_filter
);
794 m
->tag_filter
= set_free_free(m
->tag_filter
);
796 if (setsockopt(m
->sock
, SOL_SOCKET
, SO_DETACH_FILTER
, &filter
, sizeof(filter
)) < 0)
799 m
->filter_uptodate
= true;