STRUCT RTNL_LINK_OPS(9)

๐Ÿ“ฆ version 7.3.1, in nixpkgs unstable

okay bestie, buckle up โ€” this one lives in the Kernel API Manual, and it's literally the blueprint for how rtnetlink link operations get defined โœจ it's the struct that tells the kernel "hey, here's a new kind of link and here's how to make it, change it, kill it, and brag about it in netlink attributes" ๐ŸŽ€


๐ŸŒธ NAME ๐ŸŒธ

struct rtnl_link_ops โ€” rtnetlink link operations, no cap ๐Ÿ’…


โœจ SYNOPSIS โœจ

struct rtnl_link_ops {
    struct list_head        list;
    struct srcu_struct      srcu;
    const char              *kind;
    size_t priv_size;
    struct net_device       *(*alloc)(struct nlattr *tb[], const char
*ifname, unsigned char name_assign_type, unsigned int num_tx_queues,
unsigned int num_rx_queues);
    void (*setup)(struct net_device *dev);
    bool netns_refund;
    const u16               peer_type;
    unsigned int            maxtype;
    const struct nla_policy *policy;
    int (*validate)(struct nlattr *tb[], struct nlattr *data[], struct
netlink_ext_ack *extack);
    int (*newlink)(struct net_device *dev, struct rtnl_newlink_params
*params, struct netlink_ext_ack *extack);
    int (*changelink)(struct net_device *dev, struct nlattr *tb[],
struct nlattr *data[], struct netlink_ext_ack *extack);
    void (*dellink)(struct net_device *dev, struct list_head *head);
    size_t (*get_size)(const struct net_device *dev);
    int (*fill_info)(struct sk_buff *skb, const struct net_device *dev);
    size_t (*get_xstats_size)(const struct net_device *dev);
    int (*fill_xstats)(struct sk_buff *skb, const struct net_device
*dev);
    unsigned int            (*get_num_tx_queues)(void);
    unsigned int            (*get_num_rx_queues)(void);
    unsigned int            slave_maxtype;
    const struct nla_policy *slave_policy;
    int (*slave_changelink)(struct net_device *dev, struct net_device
*slave_dev, struct nlattr *tb[], struct nlattr *data[], struct
netlink_ext_ack *extack);
    size_t (*get_slave_size)(const struct net_device *dev, const struct
net_device *slave_dev);
    int (*fill_slave_info)(struct sk_buff *skb, const struct net_device
*dev, const struct net_device *slave_dev);
    struct net              *(*get_link_net)(const struct net_device
*dev);
    size_t (*get_linkxstats_size)(const struct net_device *dev, int
attr);
    int (*fill_linkxstats)(struct sk_buff *skb, const struct net_device
*dev, int *prividx, int attr);
 };

๐Ÿฆ‹ Members ๐Ÿฆ‹

like, here's the whole cast of characters, one by one, main character energy only ๐Ÿ‘‘

  • list โ€” Used internally, protected by link_ops_mutex and SRCU ๐Ÿ”’ internal business, don't touch.
  • srcu โ€” Used internally. that's it, that's the description ๐Ÿ™ˆ
  • kind โ€” Identifier ๐Ÿท๏ธ
  • priv_size โ€” sizeof net_device private space ๐Ÿ“
  • alloc โ€” the netdev allocation function. it can be NULL, and when it is, it's then used in place of alloc_netdev_mqs โ€” and in that case priv_size and setup are unused. Returns a netdev or ERR_PTR ๐Ÿ˜ญ so yes, handle your error pointers, bestie.
  • setup โ€” net_device setup function ๐Ÿ› ๏ธ
  • netns_refund โ€” Physical device, move to init_net on netns exit ๐Ÿ 
  • peer_type โ€” Peer device specific netlink attribute number (e.g. VETH_INFO_PEER) ๐Ÿ‘ฏ
  • maxtype โ€” Highest device specific netlink attribute number ๐Ÿ”ข
  • policy โ€” Netlink policy for device specific attribute validation ๐Ÿ“œ
  • validate โ€” Optional validation function for netlink/changelink parameters โœ… optional is the key word here
  • newlink โ€” Function for configuring and registering a new device ๐ŸŽ€
  • changelink โ€” Function for changing parameters of an existing device ๐Ÿ”
  • dellink โ€” Function to remove a device ๐Ÿ’€
  • get_size โ€” Function to calculate required room for dumping device specific netlink attributes ๐Ÿ“ฆ
  • fill_info โ€” Function to dump device specific netlink attributes ๐Ÿ—‚๏ธ
  • get_xstats_size โ€” Function to calculate required room for dumping device specific statistics ๐Ÿ“Š
  • fill_xstats โ€” Function to dump device specific statistics โœจ
  • get_num_tx_queues โ€” Function to determine number of transmit queues to create when creating a new device. ๐Ÿ“ค
  • get_num_rx_queues โ€” Function to determine number of receive queues to create when creating a new device. ๐Ÿ“ฅ
  • get_link_net โ€” Function to get the i/o netns of the device ๐ŸŒ
  • get_linkxstats_size โ€” Function to calculate the required room for dumping device-specific extended link stats ๐Ÿงฎ
  • fill_linkxstats โ€” Function to dump device-specific extended link stats ๐ŸŒŸ
fyi bestie ๐Ÿ’• โ€” the struct up in the synopsis also shows slave_maxtype, slave_policy, slave_changelink, get_slave_size and fill_slave_info, and this page's Members list doesn't give them their own descriptions. don't come for me, i'm just matching what the page says ๐Ÿซถ

๐ŸŒˆ SEE ALSO ๐ŸŒˆ

  • Kernel file ./include/net/rtnetlink.h struct rtnl_msg_handler(9), struct rtnl_newlink_params(9), struct rtnl_af_ops(9) ๐Ÿ‘€ go read the whole cinematic universe

okay that's the whole page, you ate that ๐Ÿ’…๐Ÿ’– this gem came from ./include/net and it's dated October 2026 โ€” yes, future vibes only, periodt โญ๐ŸŽ€๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from