STRUCT CAN_FILTER(9)
π struct can_filter(9) π
okay so bestie, we're in the Kernel API Manual today and the star of the show is struct can_filter β like, the actual main character of CAN ID filtering. no cap, this little baby is what can_register() uses to decide which CAN frames get to slide into your socket. π¦
β¨ NAME β¨
struct can_filter β the CAN ID based filter you pass into can_register(). that's it, that's the vibe. π
πΈ SYNOPSIS πΈ
struct can_filter {
canid_t can_id;
canid_t can_mask;
};
literally two fields. two. and they run the whole show. iconic behavior honestly. π
π«Ά Members (the cast π)
can_idβ the relevant bits of the CAN ID, i.e. the bits that are not masked out. this is the "what am I even looking for" part of the whole situation.can_maskβ the CAN mask (peep the Description below for the tea β).
π₯ Description π₯
okay so here's when a filter actually matches. drumroll please π₯ β it matches when
<received_can_id> & mask == can_id & mask
that's the whole test, fr fr. mask out the bits you don't care about on both sides, and if they line up, congrats, you've got a match. β¨
and because the kernel likes to keep things spicy:
- the filter can be inverted by setting the
CAN_INV_FILTERbit incan_idπ - or it can filter for error message frames by setting the
CAN_ERR_FLAGbit inmaskπ
so yeah, one cute little struct, three whole moods. no cap. π
π SEE ALSO π
go touch some kernel grass and check out the file ./include/uapi/linux/can.h plus these besties:
struct can_frame(9)struct canfd_frame(9)struct canxl_frame(9)struct sockaddr_can(9)
and that's the page!! mwah π this one lives over in ./include/uapi/linux and the version stamp says October 2026, so go forth and filter those IDs, bestie β you're gonna slay it π§ββοΈπβ¨
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms