can_rx_register(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– can_rx_register(9) β€” or, how to subscribe to CAN frames like the main character πŸ’–

okay so bestie, welcome to the Kernel API Manual ✨ this one's a kernel function, it lives in the CAN subsystem, and it's literally the "hey, send me frames from this interface pls" function. no cap.


🌸 NAME 🌸

can_rx_register β€” subscribe CAN frames from a specific interface πŸŽ€


✨ SYNOPSIS ✨

int can_rx_register (struct net *net , struct net_device *dev , canid_t
can_id , canid_t mask , void (*func)(struct sk_buff *, void *) , void
*data , char *ident , struct sock *sk );

that's eight arguments, bestie. eight. we love a thorough signature πŸ’…


πŸ¦‹ ARGUMENTS πŸ¦‹

  • net β€” the applicable net namespace. yes, namespaces, we're being organized today 🫢
  • dev β€” pointer to the netdevice. pass NULL and you're subscribing from the 'all' CAN devices list, like a lil social butterfly 🌈
  • can_id β€” the CAN identifier (peep the description below, it's got lore πŸ‘€)
  • mask β€” the CAN mask (also described below, stay with me πŸ’œ)
  • func β€” the callback function that fires on a filter match. this is your moment, this is your main character energy ⭐
  • data β€” the returned parameter for the callback function πŸŽ€
  • ident β€” a string for calling module identification, so everyone knows who sent you πŸ”₯
  • sk β€” socket pointer, and it might be NULL πŸ™ˆ no pressure

πŸ’€ DESCRIPTION πŸ’€

so what actually happens: it invokes the callback function with the received sk_buff and the given parameter 'data' on a matching receive filter. a filter matches, when

<received_can_id> & mask == can_id & mask

that's it, that's the whole vibe check πŸ’…

the filter can be inverted (the CAN_INV_FILTER bit set in can_id) or it can filter for error message frames (the CAN_ERR_FLAG bit set in mask). two fun little plot twists, your choice ✨

⚠️ okay this part matters, listen: the provided pointer to the sk_buff is guaranteed to be valid as long as the callback function is running. the callback function must _not_ free the given sk_buff while processing it's task. and when the given sk_buff is needed after the end of the callback function, it must be cloned inside the callback function with skb_clone. no stealing the sk_buff, no yeeting it into the void, we do not do that here 😭

πŸ‘‘ RETURN πŸ‘‘

  • 0 on success β€” slay πŸŽ‰
  • -ENOMEM on missing cache mem to create subscription entry β€” the subscription entry didn't get its memory, sad πŸ“
  • -ENODEV unknown device β€” that device? never heard of her πŸ’€

🌟 SEE ALSO 🌟

kernel file ./net/can/af_can.c, plus the whole friend group: can_send(9), effhash(9), can_rcv_list_find(9), can_rx_unregister(9), can_proto_register(9), can_proto_unregister(9) πŸ§šβ€β™€οΈ


alright bestie, that's the whole page πŸ’– this little beauty is filed under ./net/can, dated October 2026, and it goes by can_rx_register(9) β€” go forth and subscribe responsibly, mwah 😘🌸

πŸ“¦ where this page comes from