<div dir="ltr"><div dir="ltr">On Tue, Sep 14, 2021 at 4:08 AM Ryan McClue <<a href="mailto:re.mcclue@protonmail.com">re.mcclue@protonmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>I understand this is slightly off-topic, but I'm completely new to BPF. Analyzing libudev source and Internet I understand the general idea. However, I don't understand how information/what information is passed to the filter from the socket. For example, in my case the socket payload, i.e. buf_str = <i>add@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.4/1-2.4:1.0/input/input38/event14</i><br></div><div>1. How do I pass this string to the <b>sock_filter/sock_fprog</b> structures?<br></div></blockquote><div><br></div><div>As far as I know – you don't. Once you attach the filter to the socket, it automatically gets invoked with each packet's payload as the input (whatever counts as "input" for BPF, I'm not entirely sure), and you don't need to pass anything anywhere manually.</div><div><br></div><div>Note that this is not eBPF but the traditional cBPF that's used e.g. by tcpdump/libpcap.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div></div><div>2. Is a correct way of filtering these to implement string parsing to check for '/event' sub-string in EPF bytecode?<br></div></blockquote><div><br></div><div>See sd_device_monitor_filter_update() in src/libsystemd/sd-device/device-monitor.c (nowadays, sd-device has all the interesting code, while libudev is a thin wrapper around it).</div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Mantas Mikulėnas</div></div></div>