I'm trying to filter CAN frames with certain IDs as described here: https://landlock.io/linux-doc/landlock-v8/networking/can.html#raw-protocol-sockets-with-can-filters-sock-raw
Part of my code:
struct can_filter rfilter[4];
if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
fprintf(stderr, "Error while opening socket.\n");
exit(EXIT_FAILURE);
}
rfilter[0].can_id = 0x0D6 | CAN_INV_FILTER;
rfilter[0].can_mask = CAN_SFF_MASK;
rfilter[1].can_id = 0x0D8 | CAN_INV_FILTER;
rfilter[1].can_mask = CAN_SFF_MASK;
rfilter[2].can_id = 0x0E4 | CAN_INV_FILTER;
rfilter[2].can_mask = CAN_SFF_MASK;
rfilter[3].can_id = 0x77F | CAN_INV_FILTER;
rfilter[3].can_mask = CAN_SFF_MASK;
setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));
If I use only one of my four filters and comment out the other three, it's working as expected. If I use all four filters, it's not working at all. In that case I'm still receiving everything on the CANbus interface.
So, my guess is that somehow my filters are neutralising each other?! What do I need to change to filter the CAN IDs 0x0D6, 0x0D8, 0x0E4, and 0x77F?