STRUCT ETHNL_REQUEST_OPS(9)
π struct ethnl_request_ops(9) β Kernel API Manual, but make it make sense
okay bestie, sit down, grab a strawberry π, because this one's a kernel netlink page and I promise it's actually iconic once you see it. this is struct ethnl_request_ops β the glow-up that gives you unified handling of GET and SET requests β¨
β¨ SYNOPSIS β¨
struct ethnl_request_ops {
u8 request_cmd;
u8 reply_cmd;
u16 hdr_attr;
unsigned int req_info_size;
unsigned int reply_data_size;
bool allow_nodev_do;
u8 set_ntf_cmd;
int (*parse_request)(struct ethnl_req_info *req_info, const struct
genl_info *info, struct nlattr **tb, struct netlink_ext_ack *extack);
int (*prepare_data)(const struct ethnl_req_info *req_info, struct
ethnl_reply_data *reply_data, const struct genl_info *info);
int (*reply_size)(const struct ethnl_req_info *req_info, const
struct ethnl_reply_data *reply_data);
int (*fill_reply)(struct sk_buff *skb, const struct ethnl_req_info
*req_info, const struct ethnl_reply_data *reply_data);
void (*cleanup_data)(struct ethnl_reply_data *reply_data);
int (*set_validate)(struct ethnl_req_info *req_info, struct
genl_info *info);
int (*set)(struct ethnl_req_info *req_info, struct genl_info *info);
};
π Members π
like, every field, no skips, no "you'll figure it out" energy π«Ά
request_cmdβ the command id for the request (GET) πreply_cmdβ the command id for the reply (GET_REPLY)hdr_attrβ the attribute type for the request headerreq_info_sizeβ the size of request inforeply_data_sizeβ the size of reply dataallow_nodev_doβ lets you do a non-dump request with no device identification. β οΈ and listen: locks (rtnl_locketc.) are only taken if the device is set. like, that's the whole catch, don't forget it πset_ntf_cmdβ the notification to generate on changes (SET) πparse_requestβ parses the request, except for the common header (struct ethnl_req_info). lowkey love this one: the common header is already filled on entry, and everything after it up torepdata_offsetis zero initialized. this callback should only modify the type-specific request info using attributes parsed from the request message. it's called for both GET and SET. and the info parsed for SET gets conveyed to thereq_infoused during NTF generation, iykyk π§prepare_dataβ retrieves and prepares the data you need to compose a reply message. calls toethtool_opshandlers are limited to this callback β that's the rule, periodt. the common reply data (struct ethnl_reply_data) is filled on entry, and the type-specific part after it is zero initialized. this callback should only modify the type-specific part of the reply data. device identification fromstruct ethnl_reply_datais to be used as for dump requests β it iterates through network devices while thedevmember ofstruct ethnl_req_infopoints to the device from the client request πΈreply_sizeβ estimates the reply message size. the returned value must be sufficient for the message payload without the common reply header. the callback may return an estimate higher than the actual message size if an exact calculation wouldn't be worth the saved memory space β and honestly? respect, sometimes close enough is slay β¨fill_replyβ fills the reply message payload (except for the common header) from the reply data. the callback must not generate more payload than the previously called->reply_sizeestimated. no overachieving here, bestie πcleanup_dataβ optional cleanup, called when the reply data is no longer needed. you can use it e.g. to free any additional data structures outside the main structure that were allocated by->prepare_data. when processing dump requests,->cleanupis called for each message π§Ήset_validateβ checks if a set operation is supported for a given device, and does extra input checks. expected return values:0if the operation is a noop for the device (rare π)1if the operation should proceed to callingset- a negative
errnoon errors
it's called without any locks β just a reference on the netdev. no cap.
setβ executes the set operation. the implementation should return:0if no configuration has changed1if configuration changed and a notification should be generated- a negative
errnoon errors
π Description π
this is the description of the variable parts of GET request handling when you're using the unified infrastructure. the way it works: when you use it, you add a pointer to an instance of this structure to the ethnl_default_requests array, and use the generic handlers ethnl_default_doit, ethnl_default_dumpit, ethnl_default_start and ethnl_default_done in ethtool_genl_ops. then ethnl_default_notify can be used in ethnl_notify_handlers to send notifications of the corresponding type π₯
π¦ SEE ALSO π¦
kernel file ./net/ethtool/netlink.h, ethnl_strz_size(9), ethnl_put_strz(9), ethnl_update_u32(9), ethnl_update_u8(9), ethnl_update_u8_u32(9), ethnl_update_bool32(9), ethnl_update_bool(9), ethnl_update_binary(9), ethnl_update_bitfield32(9), ethnl_reply_header_size(9), struct ethnl_req_info(9), ethnl_req_get_phydev(9), struct ethnl_reply_data(9)
and that's the whole vibe check π this page comes to you from ./net/ethtool, dated October 2026 β that's the source and the date, both accounted for, don't @ me π go forth and unify those GET and SET requests, bestie. 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