STRUCT CAN_FILTER(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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_FILTER bit in can_id πŸ™ˆ
  • or it can filter for error message frames by setting the CAN_ERR_FLAG bit in mask πŸ’€

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