can_rx_register(9)
π 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. passNULLand 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 beNULLπ 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 thesk_buffis guaranteed to be valid as long as the callback function is running. the callback function must _not_ free the givensk_buffwhile processing it's task. and when the givensk_buffis needed after the end of the callback function, it must be cloned inside the callback function withskb_clone. no stealing the sk_buff, no yeeting it into the void, we do not do that here π
π RETURN π
0on success β slay π-ENOMEMon missing cache mem to create subscription entry β the subscription entry didn't get its memory, sad π-ENODEVunknown 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
- 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