STRUCT XFRM_MODE_CBS(9)
π struct xfrm_mode_cbs(9) β ok bestie, let's talk XFRM mode callbacks
So this is a page straight out of the Kernel API Manual (struct xfrm_mode_cbs(9)), and it's literally the cheat sheet for how an XFRM mode plugs itself into the rest of the kernel. Yes it's a struct full of function pointers. Yes it's giving "here's my whole personality in C". Let's go π
β¨ NAME β¨
struct xfrm_mode_cbs β XFRM mode callbacks. That's it, that's the whole name section. Short and iconic.
πΈ SYNOPSIS πΈ
struct xfrm_mode_cbs {
struct module *owner;
int (*init_state)(struct xfrm_state *x);
int (*clone_state)(struct xfrm_state *x, struct xfrm_state *orig);
void (*destroy_state)(struct xfrm_state *x);
int (*user_init)(struct net *net, struct xfrm_state *x, struct nlattr **attrs, struct netlink_ext_ack *extack);
int (*copy_to_user)(struct xfrm_state *x, struct sk_buff *skb);
unsigned int (*sa_len)(const struct xfrm_state *x);
u32 (*get_inner_mtu)(struct xfrm_state *x, int outer_mtu);
int (*input)(struct xfrm_state *x, struct sk_buff *skb);
int (*output)(struct net *net, struct sock *sk, struct sk_buff *skb);
int (*prepare_output)(struct xfrm_state *x, struct sk_buff *skb);
};
Nine-ish callbacks plus an owner pointer. It's a whole vibe check for a mode, ngl π
π¦ Members π¦
ownerβ the module owner, orNULL. Like, whose module is this even. π«Άinit_stateβ Add/init mode specific state inxfrm_state *x. Setup era β¨clone_stateβ Copy mode specific values fromorigto new statex. It's giving "copy my whole look".destroy_stateβ Cleanup mode specific state fromxfrm_state *x. Sad but necessary πuser_initβ Process mode specific netlink attributes from user. This is where the userspace gossip gets parsed.copy_to_userβ Add netlink attributes toattrsbased on state inx. Sending the info back out, periodt.sa_lenβ Return space required to store mode specific netlink attributes. How many bytes of attitude are we shipping.get_inner_mtuβ Return avail payload space after removing encap overhead. Math, but make it fashion π₯inputβ Process received packet from SA using mode. Incoming π¦outputβ Output given packet using mode. Outgoing πprepare_outputβ Add mode specific encapsulation to packet in skb. On return,transport_headershould point at ESP header,network_headershould point at outer IP header andmac_headershould opint at the protocol/nexthdr field of the outer IP.
no cap: that last one really does say opint in the original. It's a typo, but it's their typo and I'm not about to edit the kernel docs behind their back π
π Description π
One should examine and understand the specific uses of these callbacks in xfrm for further detail on how and when these functions are called. RTSL.
That's it. That's the description. No elaboration, no further lore, just "go read the source, lmao". Honestly? Respect. π
β SEE ALSO β
- Kernel file
./include/net/xfrm.h struct xfrm_policy(9)
and that's the whole page bestie, you ate that π This lil beauty lives at ./include/net in the kernel tree, and the page itself is dated October 2026 β yes, future vibes only. Go forth and encapsulate responsibly π§ββοΈπ
π¦ 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