Michal Kubecek | 2b4a899 | 2019-12-27 15:55:18 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 3 | #include <net/sock.h> |
Michal Kubecek | 2b4a899 | 2019-12-27 15:55:18 +0100 | [diff] [blame] | 4 | #include <linux/ethtool_netlink.h> |
| 5 | #include "netlink.h" |
| 6 | |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 7 | static struct genl_family ethtool_genl_family; |
| 8 | |
Michal Kubecek | 6b08d6c | 2019-12-27 15:55:33 +0100 | [diff] [blame] | 9 | static bool ethnl_ok __read_mostly; |
Michal Kubecek | 5cf2a54 | 2019-12-27 15:55:58 +0100 | [diff] [blame] | 10 | static u32 ethnl_bcast_seq; |
Michal Kubecek | 6b08d6c | 2019-12-27 15:55:33 +0100 | [diff] [blame] | 11 | |
Jakub Kicinski | a0de1cd | 2020-10-05 15:07:39 -0700 | [diff] [blame] | 12 | #define ETHTOOL_FLAGS_BASIC (ETHTOOL_FLAG_COMPACT_BITSETS | \ |
| 13 | ETHTOOL_FLAG_OMIT_REPLY) |
| 14 | #define ETHTOOL_FLAGS_STATS (ETHTOOL_FLAGS_BASIC | ETHTOOL_FLAG_STATS) |
| 15 | |
Jakub Kicinski | 329d9c3 | 2020-10-05 15:07:36 -0700 | [diff] [blame] | 16 | const struct nla_policy ethnl_header_policy[] = { |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 17 | [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 }, |
| 18 | [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING, |
| 19 | .len = ALTIFNAMSIZ - 1 }, |
Jakub Kicinski | a0de1cd | 2020-10-05 15:07:39 -0700 | [diff] [blame] | 20 | [ETHTOOL_A_HEADER_FLAGS] = NLA_POLICY_MASK(NLA_U32, |
| 21 | ETHTOOL_FLAGS_BASIC), |
| 22 | }; |
| 23 | |
| 24 | const struct nla_policy ethnl_header_policy_stats[] = { |
| 25 | [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 }, |
| 26 | [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING, |
| 27 | .len = ALTIFNAMSIZ - 1 }, |
| 28 | [ETHTOOL_A_HEADER_FLAGS] = NLA_POLICY_MASK(NLA_U32, |
| 29 | ETHTOOL_FLAGS_STATS), |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | /** |
Michal Kubecek | 9813054 | 2020-03-12 21:07:38 +0100 | [diff] [blame] | 33 | * ethnl_parse_header_dev_get() - parse request header |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 34 | * @req_info: structure to put results into |
| 35 | * @header: nest attribute with request header |
| 36 | * @net: request netns |
| 37 | * @extack: netlink extack for error reporting |
| 38 | * @require_dev: fail if no device identified in header |
| 39 | * |
| 40 | * Parse request header in nested attribute @nest and puts results into |
| 41 | * the structure pointed to by @req_info. Extack from @info is used for error |
| 42 | * reporting. If req_info->dev is not null on return, reference to it has |
| 43 | * been taken. If error is returned, *req_info is null initialized and no |
| 44 | * reference is held. |
| 45 | * |
| 46 | * Return: 0 on success or negative error code |
| 47 | */ |
Michal Kubecek | 9813054 | 2020-03-12 21:07:38 +0100 | [diff] [blame] | 48 | int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info, |
| 49 | const struct nlattr *header, struct net *net, |
| 50 | struct netlink_ext_ack *extack, bool require_dev) |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 51 | { |
Jakub Kicinski | ff419af | 2020-10-05 15:07:35 -0700 | [diff] [blame] | 52 | struct nlattr *tb[ARRAY_SIZE(ethnl_header_policy)]; |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 53 | const struct nlattr *devname_attr; |
| 54 | struct net_device *dev = NULL; |
Michal Kubecek | 2363d73 | 2020-03-15 18:17:53 +0100 | [diff] [blame] | 55 | u32 flags = 0; |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 56 | int ret; |
| 57 | |
| 58 | if (!header) { |
| 59 | NL_SET_ERR_MSG(extack, "request header missing"); |
| 60 | return -EINVAL; |
| 61 | } |
Jakub Kicinski | a0de1cd | 2020-10-05 15:07:39 -0700 | [diff] [blame] | 62 | /* No validation here, command policy should have a nested policy set |
| 63 | * for the header, therefore validation should have already been done. |
| 64 | */ |
Jakub Kicinski | ff419af | 2020-10-05 15:07:35 -0700 | [diff] [blame] | 65 | ret = nla_parse_nested(tb, ARRAY_SIZE(ethnl_header_policy) - 1, header, |
Jakub Kicinski | a0de1cd | 2020-10-05 15:07:39 -0700 | [diff] [blame] | 66 | NULL, extack); |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 67 | if (ret < 0) |
| 68 | return ret; |
Jakub Kicinski | a0de1cd | 2020-10-05 15:07:39 -0700 | [diff] [blame] | 69 | if (tb[ETHTOOL_A_HEADER_FLAGS]) |
Michal Kubecek | 2363d73 | 2020-03-15 18:17:53 +0100 | [diff] [blame] | 70 | flags = nla_get_u32(tb[ETHTOOL_A_HEADER_FLAGS]); |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 71 | |
Michal Kubecek | 2363d73 | 2020-03-15 18:17:53 +0100 | [diff] [blame] | 72 | devname_attr = tb[ETHTOOL_A_HEADER_DEV_NAME]; |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 73 | if (tb[ETHTOOL_A_HEADER_DEV_INDEX]) { |
| 74 | u32 ifindex = nla_get_u32(tb[ETHTOOL_A_HEADER_DEV_INDEX]); |
| 75 | |
| 76 | dev = dev_get_by_index(net, ifindex); |
| 77 | if (!dev) { |
| 78 | NL_SET_ERR_MSG_ATTR(extack, |
| 79 | tb[ETHTOOL_A_HEADER_DEV_INDEX], |
| 80 | "no device matches ifindex"); |
| 81 | return -ENODEV; |
| 82 | } |
| 83 | /* if both ifindex and ifname are passed, they must match */ |
| 84 | if (devname_attr && |
| 85 | strncmp(dev->name, nla_data(devname_attr), IFNAMSIZ)) { |
| 86 | dev_put(dev); |
| 87 | NL_SET_ERR_MSG_ATTR(extack, header, |
| 88 | "ifindex and name do not match"); |
| 89 | return -ENODEV; |
| 90 | } |
| 91 | } else if (devname_attr) { |
| 92 | dev = dev_get_by_name(net, nla_data(devname_attr)); |
| 93 | if (!dev) { |
| 94 | NL_SET_ERR_MSG_ATTR(extack, devname_attr, |
| 95 | "no device matches name"); |
| 96 | return -ENODEV; |
| 97 | } |
| 98 | } else if (require_dev) { |
| 99 | NL_SET_ERR_MSG_ATTR(extack, header, |
| 100 | "neither ifindex nor name specified"); |
| 101 | return -EINVAL; |
| 102 | } |
| 103 | |
| 104 | if (dev && !netif_device_present(dev)) { |
| 105 | dev_put(dev); |
| 106 | NL_SET_ERR_MSG(extack, "device not present"); |
| 107 | return -ENODEV; |
| 108 | } |
| 109 | |
| 110 | req_info->dev = dev; |
Michal Kubecek | 2363d73 | 2020-03-15 18:17:53 +0100 | [diff] [blame] | 111 | req_info->flags = flags; |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * ethnl_fill_reply_header() - Put common header into a reply message |
| 117 | * @skb: skb with the message |
| 118 | * @dev: network device to describe in header |
| 119 | * @attrtype: attribute type to use for the nest |
| 120 | * |
| 121 | * Create a nested attribute with attributes describing given network device. |
| 122 | * |
| 123 | * Return: 0 on success, error value (-EMSGSIZE only) on error |
| 124 | */ |
| 125 | int ethnl_fill_reply_header(struct sk_buff *skb, struct net_device *dev, |
| 126 | u16 attrtype) |
| 127 | { |
| 128 | struct nlattr *nest; |
| 129 | |
| 130 | if (!dev) |
| 131 | return 0; |
| 132 | nest = nla_nest_start(skb, attrtype); |
| 133 | if (!nest) |
| 134 | return -EMSGSIZE; |
| 135 | |
| 136 | if (nla_put_u32(skb, ETHTOOL_A_HEADER_DEV_INDEX, (u32)dev->ifindex) || |
| 137 | nla_put_string(skb, ETHTOOL_A_HEADER_DEV_NAME, dev->name)) |
| 138 | goto nla_put_failure; |
| 139 | /* If more attributes are put into reply header, ethnl_header_size() |
| 140 | * must be updated to account for them. |
| 141 | */ |
| 142 | |
| 143 | nla_nest_end(skb, nest); |
| 144 | return 0; |
| 145 | |
| 146 | nla_put_failure: |
| 147 | nla_nest_cancel(skb, nest); |
| 148 | return -EMSGSIZE; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * ethnl_reply_init() - Create skb for a reply and fill device identification |
Michal Kubecek | d2c4b44 | 2020-01-26 23:11:01 +0100 | [diff] [blame] | 153 | * @payload: payload length (without netlink and genetlink header) |
| 154 | * @dev: device the reply is about (may be null) |
| 155 | * @cmd: ETHTOOL_MSG_* message type for reply |
| 156 | * @hdr_attrtype: attribute type for common header |
| 157 | * @info: genetlink info of the received packet we respond to |
| 158 | * @ehdrp: place to store payload pointer returned by genlmsg_new() |
Michal Kubecek | 041b1c5 | 2019-12-27 15:55:23 +0100 | [diff] [blame] | 159 | * |
| 160 | * Return: pointer to allocated skb on success, NULL on error |
| 161 | */ |
| 162 | struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd, |
| 163 | u16 hdr_attrtype, struct genl_info *info, |
| 164 | void **ehdrp) |
| 165 | { |
| 166 | struct sk_buff *skb; |
| 167 | |
| 168 | skb = genlmsg_new(payload, GFP_KERNEL); |
| 169 | if (!skb) |
| 170 | goto err; |
| 171 | *ehdrp = genlmsg_put_reply(skb, info, ðtool_genl_family, 0, cmd); |
| 172 | if (!*ehdrp) |
| 173 | goto err_free; |
| 174 | |
| 175 | if (dev) { |
| 176 | int ret; |
| 177 | |
| 178 | ret = ethnl_fill_reply_header(skb, dev, hdr_attrtype); |
| 179 | if (ret < 0) |
| 180 | goto err_free; |
| 181 | } |
| 182 | return skb; |
| 183 | |
| 184 | err_free: |
| 185 | nlmsg_free(skb); |
| 186 | err: |
| 187 | if (info) |
| 188 | GENL_SET_ERR_MSG(info, "failed to setup reply message"); |
| 189 | return NULL; |
| 190 | } |
| 191 | |
Jakub Kicinski | c7d759e | 2020-07-09 17:42:47 -0700 | [diff] [blame] | 192 | void *ethnl_dump_put(struct sk_buff *skb, struct netlink_callback *cb, u8 cmd) |
| 193 | { |
| 194 | return genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, |
| 195 | ðtool_genl_family, 0, cmd); |
| 196 | } |
| 197 | |
Andrew Lunn | 0df960f | 2020-05-10 21:12:35 +0200 | [diff] [blame] | 198 | void *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd) |
Michal Kubecek | 5cf2a54 | 2019-12-27 15:55:58 +0100 | [diff] [blame] | 199 | { |
| 200 | return genlmsg_put(skb, 0, ++ethnl_bcast_seq, ðtool_genl_family, 0, |
| 201 | cmd); |
| 202 | } |
| 203 | |
Andrew Lunn | 0df960f | 2020-05-10 21:12:35 +0200 | [diff] [blame] | 204 | int ethnl_multicast(struct sk_buff *skb, struct net_device *dev) |
Michal Kubecek | 5cf2a54 | 2019-12-27 15:55:58 +0100 | [diff] [blame] | 205 | { |
| 206 | return genlmsg_multicast_netns(ðtool_genl_family, dev_net(dev), skb, |
| 207 | 0, ETHNL_MCGRP_MONITOR, GFP_KERNEL); |
| 208 | } |
| 209 | |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 210 | /* GET request helpers */ |
| 211 | |
| 212 | /** |
| 213 | * struct ethnl_dump_ctx - context structure for generic dumpit() callback |
Michal Kubecek | d2c4b44 | 2020-01-26 23:11:01 +0100 | [diff] [blame] | 214 | * @ops: request ops of currently processed message type |
| 215 | * @req_info: parsed request header of processed request |
| 216 | * @reply_data: data needed to compose the reply |
| 217 | * @pos_hash: saved iteration position - hashbucket |
| 218 | * @pos_idx: saved iteration position - index |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 219 | * |
| 220 | * These parameters are kept in struct netlink_callback as context preserved |
| 221 | * between iterations. They are initialized by ethnl_default_start() and used |
| 222 | * in ethnl_default_dumpit() and ethnl_default_done(). |
| 223 | */ |
| 224 | struct ethnl_dump_ctx { |
| 225 | const struct ethnl_request_ops *ops; |
| 226 | struct ethnl_req_info *req_info; |
| 227 | struct ethnl_reply_data *reply_data; |
| 228 | int pos_hash; |
| 229 | int pos_idx; |
| 230 | }; |
| 231 | |
| 232 | static const struct ethnl_request_ops * |
| 233 | ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { |
Michal Kubecek | 7192169 | 2019-12-27 15:55:43 +0100 | [diff] [blame] | 234 | [ETHTOOL_MSG_STRSET_GET] = ðnl_strset_request_ops, |
Michal Kubecek | 459e0b8 | 2019-12-27 15:55:48 +0100 | [diff] [blame] | 235 | [ETHTOOL_MSG_LINKINFO_GET] = ðnl_linkinfo_request_ops, |
Michal Kubecek | f625aa9 | 2019-12-27 15:56:08 +0100 | [diff] [blame] | 236 | [ETHTOOL_MSG_LINKMODES_GET] = ðnl_linkmodes_request_ops, |
Michal Kubecek | 3d2b847 | 2019-12-27 15:56:23 +0100 | [diff] [blame] | 237 | [ETHTOOL_MSG_LINKSTATE_GET] = ðnl_linkstate_request_ops, |
Michal Kubecek | 6a94b8c | 2020-01-26 23:11:04 +0100 | [diff] [blame] | 238 | [ETHTOOL_MSG_DEBUG_GET] = ðnl_debug_request_ops, |
Michal Kubecek | 51ea22b | 2020-01-26 23:11:13 +0100 | [diff] [blame] | 239 | [ETHTOOL_MSG_WOL_GET] = ðnl_wol_request_ops, |
Michal Kubecek | 0524399 | 2020-03-12 21:07:48 +0100 | [diff] [blame] | 240 | [ETHTOOL_MSG_FEATURES_GET] = ðnl_features_request_ops, |
Michal Kubecek | e16c338 | 2020-03-12 21:08:08 +0100 | [diff] [blame] | 241 | [ETHTOOL_MSG_PRIVFLAGS_GET] = ðnl_privflags_request_ops, |
Michal Kubecek | e4a1717 | 2020-03-12 21:08:23 +0100 | [diff] [blame] | 242 | [ETHTOOL_MSG_RINGS_GET] = ðnl_rings_request_ops, |
Michal Kubecek | 0c84979 | 2020-03-12 21:08:38 +0100 | [diff] [blame] | 243 | [ETHTOOL_MSG_CHANNELS_GET] = ðnl_channels_request_ops, |
Michal Kubecek | 2172754 | 2020-03-28 00:01:08 +0100 | [diff] [blame] | 244 | [ETHTOOL_MSG_COALESCE_GET] = ðnl_coalesce_request_ops, |
Michal Kubecek | 7f59fb3 | 2020-03-28 00:01:23 +0100 | [diff] [blame] | 245 | [ETHTOOL_MSG_PAUSE_GET] = ðnl_pause_request_ops, |
Michal Kubecek | b7eeefe | 2020-03-28 00:01:38 +0100 | [diff] [blame] | 246 | [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops, |
Jakub Kicinski | 1e5d1f6 | 2021-03-29 20:59:52 -0700 | [diff] [blame] | 247 | [ETHTOOL_MSG_FEC_GET] = ðnl_fec_request_ops, |
Michal Kubecek | 5b071c5 | 2020-03-28 00:01:58 +0100 | [diff] [blame] | 248 | [ETHTOOL_MSG_TSINFO_GET] = ðnl_tsinfo_request_ops, |
Vladyslav Tarasiuk | c781ff1 | 2021-04-09 11:06:34 +0300 | [diff] [blame] | 249 | [ETHTOOL_MSG_MODULE_EEPROM_GET] = ðnl_module_eeprom_request_ops, |
Jakub Kicinski | f09ea6f | 2021-04-16 12:27:39 -0700 | [diff] [blame] | 250 | [ETHTOOL_MSG_STATS_GET] = ðnl_stats_request_ops, |
Yangbo Lu | c156174a | 2021-06-30 16:11:56 +0800 | [diff] [blame^] | 251 | [ETHTOOL_MSG_PHC_VCLOCKS_GET] = ðnl_phc_vclocks_request_ops, |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 252 | }; |
| 253 | |
| 254 | static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) |
| 255 | { |
| 256 | return (struct ethnl_dump_ctx *)cb->ctx; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * ethnl_default_parse() - Parse request message |
| 261 | * @req_info: pointer to structure to put data into |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 262 | * @tb: parsed attributes |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 263 | * @net: request netns |
| 264 | * @request_ops: struct request_ops for request type |
| 265 | * @extack: netlink extack for error reporting |
| 266 | * @require_dev: fail if no device identified in header |
| 267 | * |
| 268 | * Parse universal request header and call request specific ->parse_request() |
| 269 | * callback (if defined) to parse the rest of the message. |
| 270 | * |
| 271 | * Return: 0 on success or negative error code |
| 272 | */ |
| 273 | static int ethnl_default_parse(struct ethnl_req_info *req_info, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 274 | struct nlattr **tb, struct net *net, |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 275 | const struct ethnl_request_ops *request_ops, |
| 276 | struct netlink_ext_ack *extack, bool require_dev) |
| 277 | { |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 278 | int ret; |
| 279 | |
Michal Kubecek | 9813054 | 2020-03-12 21:07:38 +0100 | [diff] [blame] | 280 | ret = ethnl_parse_header_dev_get(req_info, tb[request_ops->hdr_attr], |
| 281 | net, extack, require_dev); |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 282 | if (ret < 0) |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 283 | return ret; |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 284 | |
| 285 | if (request_ops->parse_request) { |
| 286 | ret = request_ops->parse_request(req_info, tb, extack); |
| 287 | if (ret < 0) |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 288 | return ret; |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 289 | } |
| 290 | |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 291 | return 0; |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /** |
| 295 | * ethnl_init_reply_data() - Initialize reply data for GET request |
Michal Kubecek | d2c4b44 | 2020-01-26 23:11:01 +0100 | [diff] [blame] | 296 | * @reply_data: pointer to embedded struct ethnl_reply_data |
| 297 | * @ops: instance of struct ethnl_request_ops describing the layout |
| 298 | * @dev: network device to initialize the reply for |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 299 | * |
| 300 | * Fills the reply data part with zeros and sets the dev member. Must be called |
| 301 | * before calling the ->fill_reply() callback (for each iteration when handling |
| 302 | * dump requests). |
| 303 | */ |
| 304 | static void ethnl_init_reply_data(struct ethnl_reply_data *reply_data, |
| 305 | const struct ethnl_request_ops *ops, |
| 306 | struct net_device *dev) |
| 307 | { |
| 308 | memset(reply_data, 0, ops->reply_data_size); |
| 309 | reply_data->dev = dev; |
| 310 | } |
| 311 | |
| 312 | /* default ->doit() handler for GET type requests */ |
| 313 | static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info) |
| 314 | { |
| 315 | struct ethnl_reply_data *reply_data = NULL; |
| 316 | struct ethnl_req_info *req_info = NULL; |
| 317 | const u8 cmd = info->genlhdr->cmd; |
| 318 | const struct ethnl_request_ops *ops; |
Jakub Kicinski | 4d1fb7c | 2021-06-15 20:33:38 -0700 | [diff] [blame] | 319 | int hdr_len, reply_len; |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 320 | struct sk_buff *rskb; |
| 321 | void *reply_payload; |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 322 | int ret; |
| 323 | |
| 324 | ops = ethnl_default_requests[cmd]; |
| 325 | if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", cmd)) |
| 326 | return -EOPNOTSUPP; |
| 327 | req_info = kzalloc(ops->req_info_size, GFP_KERNEL); |
| 328 | if (!req_info) |
| 329 | return -ENOMEM; |
| 330 | reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL); |
| 331 | if (!reply_data) { |
| 332 | kfree(req_info); |
| 333 | return -ENOMEM; |
| 334 | } |
| 335 | |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 336 | ret = ethnl_default_parse(req_info, info->attrs, genl_info_net(info), |
| 337 | ops, info->extack, !ops->allow_nodev_do); |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 338 | if (ret < 0) |
| 339 | goto err_dev; |
| 340 | ethnl_init_reply_data(reply_data, ops, req_info->dev); |
| 341 | |
| 342 | rtnl_lock(); |
| 343 | ret = ops->prepare_data(req_info, reply_data, info); |
| 344 | rtnl_unlock(); |
| 345 | if (ret < 0) |
| 346 | goto err_cleanup; |
Dan Carpenter | d97772d | 2020-01-08 08:41:25 +0300 | [diff] [blame] | 347 | ret = ops->reply_size(req_info, reply_data); |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 348 | if (ret < 0) |
| 349 | goto err_cleanup; |
Jakub Kicinski | 4d1fb7c | 2021-06-15 20:33:38 -0700 | [diff] [blame] | 350 | reply_len = ret; |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 351 | ret = -ENOMEM; |
Jakub Kicinski | 4d1fb7c | 2021-06-15 20:33:38 -0700 | [diff] [blame] | 352 | rskb = ethnl_reply_init(reply_len + ethnl_reply_header_size(), |
| 353 | req_info->dev, ops->reply_cmd, |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 354 | ops->hdr_attr, info, &reply_payload); |
| 355 | if (!rskb) |
| 356 | goto err_cleanup; |
Jakub Kicinski | 4d1fb7c | 2021-06-15 20:33:38 -0700 | [diff] [blame] | 357 | hdr_len = rskb->len; |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 358 | ret = ops->fill_reply(rskb, req_info, reply_data); |
| 359 | if (ret < 0) |
| 360 | goto err_msg; |
Jakub Kicinski | 4d1fb7c | 2021-06-15 20:33:38 -0700 | [diff] [blame] | 361 | WARN_ONCE(rskb->len - hdr_len > reply_len, |
| 362 | "ethnl cmd %d: calculated reply length %d, but consumed %d\n", |
| 363 | cmd, reply_len, rskb->len - hdr_len); |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 364 | if (ops->cleanup_data) |
| 365 | ops->cleanup_data(reply_data); |
| 366 | |
| 367 | genlmsg_end(rskb, reply_payload); |
| 368 | if (req_info->dev) |
| 369 | dev_put(req_info->dev); |
| 370 | kfree(reply_data); |
| 371 | kfree(req_info); |
| 372 | return genlmsg_reply(rskb, info); |
| 373 | |
| 374 | err_msg: |
| 375 | WARN_ONCE(ret == -EMSGSIZE, "calculated message payload length (%d) not sufficient\n", reply_len); |
| 376 | nlmsg_free(rskb); |
| 377 | err_cleanup: |
| 378 | if (ops->cleanup_data) |
| 379 | ops->cleanup_data(reply_data); |
| 380 | err_dev: |
| 381 | if (req_info->dev) |
| 382 | dev_put(req_info->dev); |
| 383 | kfree(reply_data); |
| 384 | kfree(req_info); |
| 385 | return ret; |
| 386 | } |
| 387 | |
| 388 | static int ethnl_default_dump_one(struct sk_buff *skb, struct net_device *dev, |
Michal Kubecek | 365f9ae | 2020-07-09 12:11:50 +0200 | [diff] [blame] | 389 | const struct ethnl_dump_ctx *ctx, |
| 390 | struct netlink_callback *cb) |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 391 | { |
Michal Kubecek | 365f9ae | 2020-07-09 12:11:50 +0200 | [diff] [blame] | 392 | void *ehdr; |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 393 | int ret; |
| 394 | |
Michal Kubecek | 365f9ae | 2020-07-09 12:11:50 +0200 | [diff] [blame] | 395 | ehdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, |
Fernando Fernandez Mancera | cf754ae | 2021-05-05 00:47:14 +0200 | [diff] [blame] | 396 | ðtool_genl_family, NLM_F_MULTI, |
| 397 | ctx->ops->reply_cmd); |
Michal Kubecek | 365f9ae | 2020-07-09 12:11:50 +0200 | [diff] [blame] | 398 | if (!ehdr) |
| 399 | return -EMSGSIZE; |
| 400 | |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 401 | ethnl_init_reply_data(ctx->reply_data, ctx->ops, dev); |
| 402 | rtnl_lock(); |
| 403 | ret = ctx->ops->prepare_data(ctx->req_info, ctx->reply_data, NULL); |
| 404 | rtnl_unlock(); |
| 405 | if (ret < 0) |
| 406 | goto out; |
| 407 | ret = ethnl_fill_reply_header(skb, dev, ctx->ops->hdr_attr); |
| 408 | if (ret < 0) |
| 409 | goto out; |
| 410 | ret = ctx->ops->fill_reply(skb, ctx->req_info, ctx->reply_data); |
| 411 | |
| 412 | out: |
| 413 | if (ctx->ops->cleanup_data) |
| 414 | ctx->ops->cleanup_data(ctx->reply_data); |
| 415 | ctx->reply_data->dev = NULL; |
Michal Kubecek | 365f9ae | 2020-07-09 12:11:50 +0200 | [diff] [blame] | 416 | if (ret < 0) |
| 417 | genlmsg_cancel(skb, ehdr); |
| 418 | else |
| 419 | genlmsg_end(skb, ehdr); |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 420 | return ret; |
| 421 | } |
| 422 | |
| 423 | /* Default ->dumpit() handler for GET requests. Device iteration copied from |
| 424 | * rtnl_dump_ifinfo(); we have to be more careful about device hashtable |
| 425 | * persistence as we cannot guarantee to hold RTNL lock through the whole |
| 426 | * function as rtnetnlink does. |
| 427 | */ |
| 428 | static int ethnl_default_dumpit(struct sk_buff *skb, |
| 429 | struct netlink_callback *cb) |
| 430 | { |
| 431 | struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb); |
| 432 | struct net *net = sock_net(skb->sk); |
| 433 | int s_idx = ctx->pos_idx; |
| 434 | int h, idx = 0; |
| 435 | int ret = 0; |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 436 | |
| 437 | rtnl_lock(); |
| 438 | for (h = ctx->pos_hash; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { |
| 439 | struct hlist_head *head; |
| 440 | struct net_device *dev; |
| 441 | unsigned int seq; |
| 442 | |
| 443 | head = &net->dev_index_head[h]; |
| 444 | |
| 445 | restart_chain: |
| 446 | seq = net->dev_base_seq; |
| 447 | cb->seq = seq; |
| 448 | idx = 0; |
| 449 | hlist_for_each_entry(dev, head, index_hlist) { |
| 450 | if (idx < s_idx) |
| 451 | goto cont; |
| 452 | dev_hold(dev); |
| 453 | rtnl_unlock(); |
| 454 | |
Michal Kubecek | 365f9ae | 2020-07-09 12:11:50 +0200 | [diff] [blame] | 455 | ret = ethnl_default_dump_one(skb, dev, ctx, cb); |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 456 | dev_put(dev); |
| 457 | if (ret < 0) { |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 458 | if (ret == -EOPNOTSUPP) |
| 459 | goto lock_and_cont; |
| 460 | if (likely(skb->len)) |
| 461 | ret = skb->len; |
| 462 | goto out; |
| 463 | } |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 464 | lock_and_cont: |
| 465 | rtnl_lock(); |
| 466 | if (net->dev_base_seq != seq) { |
| 467 | s_idx = idx + 1; |
| 468 | goto restart_chain; |
| 469 | } |
| 470 | cont: |
| 471 | idx++; |
| 472 | } |
| 473 | |
| 474 | } |
| 475 | rtnl_unlock(); |
| 476 | |
| 477 | out: |
| 478 | ctx->pos_hash = h; |
| 479 | ctx->pos_idx = idx; |
| 480 | nl_dump_check_consistent(cb, nlmsg_hdr(skb)); |
| 481 | |
| 482 | return ret; |
| 483 | } |
| 484 | |
| 485 | /* generic ->start() handler for GET requests */ |
| 486 | static int ethnl_default_start(struct netlink_callback *cb) |
| 487 | { |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 488 | const struct genl_dumpit_info *info = genl_dumpit_info(cb); |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 489 | struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb); |
| 490 | struct ethnl_reply_data *reply_data; |
| 491 | const struct ethnl_request_ops *ops; |
| 492 | struct ethnl_req_info *req_info; |
| 493 | struct genlmsghdr *ghdr; |
| 494 | int ret; |
| 495 | |
| 496 | BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx)); |
| 497 | |
| 498 | ghdr = nlmsg_data(cb->nlh); |
| 499 | ops = ethnl_default_requests[ghdr->cmd]; |
| 500 | if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", ghdr->cmd)) |
| 501 | return -EOPNOTSUPP; |
| 502 | req_info = kzalloc(ops->req_info_size, GFP_KERNEL); |
| 503 | if (!req_info) |
| 504 | return -ENOMEM; |
| 505 | reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL); |
| 506 | if (!reply_data) { |
Dan Carpenter | a6dd048 | 2020-01-08 08:39:48 +0300 | [diff] [blame] | 507 | ret = -ENOMEM; |
| 508 | goto free_req_info; |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 509 | } |
| 510 | |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 511 | ret = ethnl_default_parse(req_info, info->attrs, sock_net(cb->skb->sk), |
| 512 | ops, cb->extack, false); |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 513 | if (req_info->dev) { |
| 514 | /* We ignore device specification in dump requests but as the |
| 515 | * same parser as for non-dump (doit) requests is used, it |
| 516 | * would take reference to the device if it finds one |
| 517 | */ |
| 518 | dev_put(req_info->dev); |
| 519 | req_info->dev = NULL; |
| 520 | } |
| 521 | if (ret < 0) |
Dan Carpenter | a6dd048 | 2020-01-08 08:39:48 +0300 | [diff] [blame] | 522 | goto free_reply_data; |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 523 | |
| 524 | ctx->ops = ops; |
| 525 | ctx->req_info = req_info; |
| 526 | ctx->reply_data = reply_data; |
| 527 | ctx->pos_hash = 0; |
| 528 | ctx->pos_idx = 0; |
| 529 | |
| 530 | return 0; |
Dan Carpenter | a6dd048 | 2020-01-08 08:39:48 +0300 | [diff] [blame] | 531 | |
| 532 | free_reply_data: |
| 533 | kfree(reply_data); |
| 534 | free_req_info: |
| 535 | kfree(req_info); |
| 536 | |
| 537 | return ret; |
Michal Kubecek | 728480f | 2019-12-27 15:55:38 +0100 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | /* default ->done() handler for GET requests */ |
| 541 | static int ethnl_default_done(struct netlink_callback *cb) |
| 542 | { |
| 543 | struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb); |
| 544 | |
| 545 | kfree(ctx->reply_data); |
| 546 | kfree(ctx->req_info); |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
Michal Kubecek | 5cf2a54 | 2019-12-27 15:55:58 +0100 | [diff] [blame] | 551 | static const struct ethnl_request_ops * |
| 552 | ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = { |
Michal Kubecek | 7328673 | 2019-12-27 15:56:03 +0100 | [diff] [blame] | 553 | [ETHTOOL_MSG_LINKINFO_NTF] = ðnl_linkinfo_request_ops, |
Michal Kubecek | 1b1b184 | 2019-12-27 15:56:18 +0100 | [diff] [blame] | 554 | [ETHTOOL_MSG_LINKMODES_NTF] = ðnl_linkmodes_request_ops, |
Michal Kubecek | 0bda7af | 2020-01-26 23:11:10 +0100 | [diff] [blame] | 555 | [ETHTOOL_MSG_DEBUG_NTF] = ðnl_debug_request_ops, |
Michal Kubecek | 67bffa7 | 2020-01-26 23:11:19 +0100 | [diff] [blame] | 556 | [ETHTOOL_MSG_WOL_NTF] = ðnl_wol_request_ops, |
Michal Kubecek | 9c6451e | 2020-03-12 21:08:03 +0100 | [diff] [blame] | 557 | [ETHTOOL_MSG_FEATURES_NTF] = ðnl_features_request_ops, |
Michal Kubecek | 111dcba | 2020-03-12 21:08:18 +0100 | [diff] [blame] | 558 | [ETHTOOL_MSG_PRIVFLAGS_NTF] = ðnl_privflags_request_ops, |
Michal Kubecek | bc9d1c9 | 2020-03-12 21:08:33 +0100 | [diff] [blame] | 559 | [ETHTOOL_MSG_RINGS_NTF] = ðnl_rings_request_ops, |
Michal Kubecek | 546379b | 2020-03-12 21:08:48 +0100 | [diff] [blame] | 560 | [ETHTOOL_MSG_CHANNELS_NTF] = ðnl_channels_request_ops, |
Michal Kubecek | 0cf3eac | 2020-03-28 00:01:18 +0100 | [diff] [blame] | 561 | [ETHTOOL_MSG_COALESCE_NTF] = ðnl_coalesce_request_ops, |
Michal Kubecek | bf37faa | 2020-03-28 00:01:33 +0100 | [diff] [blame] | 562 | [ETHTOOL_MSG_PAUSE_NTF] = ðnl_pause_request_ops, |
Michal Kubecek | 6c5bc8f | 2020-03-28 00:01:48 +0100 | [diff] [blame] | 563 | [ETHTOOL_MSG_EEE_NTF] = ðnl_eee_request_ops, |
Jakub Kicinski | 1e5d1f6 | 2021-03-29 20:59:52 -0700 | [diff] [blame] | 564 | [ETHTOOL_MSG_FEC_NTF] = ðnl_fec_request_ops, |
Michal Kubecek | 5cf2a54 | 2019-12-27 15:55:58 +0100 | [diff] [blame] | 565 | }; |
| 566 | |
| 567 | /* default notification handler */ |
| 568 | static void ethnl_default_notify(struct net_device *dev, unsigned int cmd, |
| 569 | const void *data) |
| 570 | { |
| 571 | struct ethnl_reply_data *reply_data; |
| 572 | const struct ethnl_request_ops *ops; |
| 573 | struct ethnl_req_info *req_info; |
| 574 | struct sk_buff *skb; |
| 575 | void *reply_payload; |
| 576 | int reply_len; |
| 577 | int ret; |
| 578 | |
| 579 | if (WARN_ONCE(cmd > ETHTOOL_MSG_KERNEL_MAX || |
| 580 | !ethnl_default_notify_ops[cmd], |
| 581 | "unexpected notification type %u\n", cmd)) |
| 582 | return; |
| 583 | ops = ethnl_default_notify_ops[cmd]; |
| 584 | req_info = kzalloc(ops->req_info_size, GFP_KERNEL); |
| 585 | if (!req_info) |
| 586 | return; |
| 587 | reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL); |
| 588 | if (!reply_data) { |
| 589 | kfree(req_info); |
| 590 | return; |
| 591 | } |
| 592 | |
| 593 | req_info->dev = dev; |
| 594 | req_info->flags |= ETHTOOL_FLAG_COMPACT_BITSETS; |
| 595 | |
| 596 | ethnl_init_reply_data(reply_data, ops, dev); |
| 597 | ret = ops->prepare_data(req_info, reply_data, NULL); |
| 598 | if (ret < 0) |
| 599 | goto err_cleanup; |
Dan Carpenter | d97772d | 2020-01-08 08:41:25 +0300 | [diff] [blame] | 600 | ret = ops->reply_size(req_info, reply_data); |
Michal Kubecek | 5cf2a54 | 2019-12-27 15:55:58 +0100 | [diff] [blame] | 601 | if (ret < 0) |
| 602 | goto err_cleanup; |
Michal Kubecek | 7c87e32 | 2020-05-10 21:04:09 +0200 | [diff] [blame] | 603 | reply_len = ret + ethnl_reply_header_size(); |
Michal Kubecek | 5cf2a54 | 2019-12-27 15:55:58 +0100 | [diff] [blame] | 604 | ret = -ENOMEM; |
| 605 | skb = genlmsg_new(reply_len, GFP_KERNEL); |
| 606 | if (!skb) |
| 607 | goto err_cleanup; |
| 608 | reply_payload = ethnl_bcastmsg_put(skb, cmd); |
| 609 | if (!reply_payload) |
| 610 | goto err_skb; |
| 611 | ret = ethnl_fill_reply_header(skb, dev, ops->hdr_attr); |
| 612 | if (ret < 0) |
| 613 | goto err_msg; |
| 614 | ret = ops->fill_reply(skb, req_info, reply_data); |
| 615 | if (ret < 0) |
| 616 | goto err_msg; |
| 617 | if (ops->cleanup_data) |
| 618 | ops->cleanup_data(reply_data); |
| 619 | |
| 620 | genlmsg_end(skb, reply_payload); |
| 621 | kfree(reply_data); |
| 622 | kfree(req_info); |
| 623 | ethnl_multicast(skb, dev); |
| 624 | return; |
| 625 | |
| 626 | err_msg: |
| 627 | WARN_ONCE(ret == -EMSGSIZE, |
| 628 | "calculated message payload length (%d) not sufficient\n", |
| 629 | reply_len); |
| 630 | err_skb: |
| 631 | nlmsg_free(skb); |
| 632 | err_cleanup: |
| 633 | if (ops->cleanup_data) |
| 634 | ops->cleanup_data(reply_data); |
| 635 | kfree(reply_data); |
| 636 | kfree(req_info); |
| 637 | return; |
| 638 | } |
| 639 | |
Michal Kubecek | 6b08d6c | 2019-12-27 15:55:33 +0100 | [diff] [blame] | 640 | /* notifications */ |
| 641 | |
| 642 | typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd, |
| 643 | const void *data); |
| 644 | |
| 645 | static const ethnl_notify_handler_t ethnl_notify_handlers[] = { |
Michal Kubecek | 7328673 | 2019-12-27 15:56:03 +0100 | [diff] [blame] | 646 | [ETHTOOL_MSG_LINKINFO_NTF] = ethnl_default_notify, |
Michal Kubecek | 1b1b184 | 2019-12-27 15:56:18 +0100 | [diff] [blame] | 647 | [ETHTOOL_MSG_LINKMODES_NTF] = ethnl_default_notify, |
Michal Kubecek | 0bda7af | 2020-01-26 23:11:10 +0100 | [diff] [blame] | 648 | [ETHTOOL_MSG_DEBUG_NTF] = ethnl_default_notify, |
Michal Kubecek | 67bffa7 | 2020-01-26 23:11:19 +0100 | [diff] [blame] | 649 | [ETHTOOL_MSG_WOL_NTF] = ethnl_default_notify, |
Michal Kubecek | 9c6451e | 2020-03-12 21:08:03 +0100 | [diff] [blame] | 650 | [ETHTOOL_MSG_FEATURES_NTF] = ethnl_default_notify, |
Michal Kubecek | 111dcba | 2020-03-12 21:08:18 +0100 | [diff] [blame] | 651 | [ETHTOOL_MSG_PRIVFLAGS_NTF] = ethnl_default_notify, |
Michal Kubecek | bc9d1c9 | 2020-03-12 21:08:33 +0100 | [diff] [blame] | 652 | [ETHTOOL_MSG_RINGS_NTF] = ethnl_default_notify, |
Michal Kubecek | 546379b | 2020-03-12 21:08:48 +0100 | [diff] [blame] | 653 | [ETHTOOL_MSG_CHANNELS_NTF] = ethnl_default_notify, |
Michal Kubecek | 0cf3eac | 2020-03-28 00:01:18 +0100 | [diff] [blame] | 654 | [ETHTOOL_MSG_COALESCE_NTF] = ethnl_default_notify, |
Michal Kubecek | bf37faa | 2020-03-28 00:01:33 +0100 | [diff] [blame] | 655 | [ETHTOOL_MSG_PAUSE_NTF] = ethnl_default_notify, |
Michal Kubecek | 6c5bc8f | 2020-03-28 00:01:48 +0100 | [diff] [blame] | 656 | [ETHTOOL_MSG_EEE_NTF] = ethnl_default_notify, |
Jakub Kicinski | 1e5d1f6 | 2021-03-29 20:59:52 -0700 | [diff] [blame] | 657 | [ETHTOOL_MSG_FEC_NTF] = ethnl_default_notify, |
Michal Kubecek | 6b08d6c | 2019-12-27 15:55:33 +0100 | [diff] [blame] | 658 | }; |
| 659 | |
| 660 | void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data) |
| 661 | { |
| 662 | if (unlikely(!ethnl_ok)) |
| 663 | return; |
| 664 | ASSERT_RTNL(); |
| 665 | |
| 666 | if (likely(cmd < ARRAY_SIZE(ethnl_notify_handlers) && |
| 667 | ethnl_notify_handlers[cmd])) |
| 668 | ethnl_notify_handlers[cmd](dev, cmd, data); |
| 669 | else |
| 670 | WARN_ONCE(1, "notification %u not implemented (dev=%s)\n", |
| 671 | cmd, netdev_name(dev)); |
| 672 | } |
| 673 | EXPORT_SYMBOL(ethtool_notify); |
| 674 | |
Michal Kubecek | 9c6451e | 2020-03-12 21:08:03 +0100 | [diff] [blame] | 675 | static void ethnl_notify_features(struct netdev_notifier_info *info) |
| 676 | { |
| 677 | struct net_device *dev = netdev_notifier_info_to_dev(info); |
| 678 | |
| 679 | ethtool_notify(dev, ETHTOOL_MSG_FEATURES_NTF, NULL); |
| 680 | } |
| 681 | |
| 682 | static int ethnl_netdev_event(struct notifier_block *this, unsigned long event, |
| 683 | void *ptr) |
| 684 | { |
| 685 | switch (event) { |
| 686 | case NETDEV_FEAT_CHANGE: |
| 687 | ethnl_notify_features(ptr); |
| 688 | break; |
| 689 | } |
| 690 | |
| 691 | return NOTIFY_DONE; |
| 692 | } |
| 693 | |
| 694 | static struct notifier_block ethnl_netdev_notifier = { |
| 695 | .notifier_call = ethnl_netdev_event, |
| 696 | }; |
| 697 | |
Michal Kubecek | 2b4a899 | 2019-12-27 15:55:18 +0100 | [diff] [blame] | 698 | /* genetlink setup */ |
| 699 | |
| 700 | static const struct genl_ops ethtool_genl_ops[] = { |
Michal Kubecek | 7192169 | 2019-12-27 15:55:43 +0100 | [diff] [blame] | 701 | { |
| 702 | .cmd = ETHTOOL_MSG_STRSET_GET, |
| 703 | .doit = ethnl_default_doit, |
| 704 | .start = ethnl_default_start, |
| 705 | .dumpit = ethnl_default_dumpit, |
| 706 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 707 | .policy = ethnl_strset_get_policy, |
| 708 | .maxattr = ARRAY_SIZE(ethnl_strset_get_policy) - 1, |
Michal Kubecek | 7192169 | 2019-12-27 15:55:43 +0100 | [diff] [blame] | 709 | }, |
Michal Kubecek | 459e0b8 | 2019-12-27 15:55:48 +0100 | [diff] [blame] | 710 | { |
| 711 | .cmd = ETHTOOL_MSG_LINKINFO_GET, |
| 712 | .doit = ethnl_default_doit, |
| 713 | .start = ethnl_default_start, |
| 714 | .dumpit = ethnl_default_dumpit, |
| 715 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 716 | .policy = ethnl_linkinfo_get_policy, |
| 717 | .maxattr = ARRAY_SIZE(ethnl_linkinfo_get_policy) - 1, |
Michal Kubecek | 459e0b8 | 2019-12-27 15:55:48 +0100 | [diff] [blame] | 718 | }, |
Michal Kubecek | a53f3d4 | 2019-12-27 15:55:53 +0100 | [diff] [blame] | 719 | { |
| 720 | .cmd = ETHTOOL_MSG_LINKINFO_SET, |
| 721 | .flags = GENL_UNS_ADMIN_PERM, |
| 722 | .doit = ethnl_set_linkinfo, |
Jakub Kicinski | 5028588b | 2020-10-05 15:07:34 -0700 | [diff] [blame] | 723 | .policy = ethnl_linkinfo_set_policy, |
| 724 | .maxattr = ARRAY_SIZE(ethnl_linkinfo_set_policy) - 1, |
Michal Kubecek | a53f3d4 | 2019-12-27 15:55:53 +0100 | [diff] [blame] | 725 | }, |
Michal Kubecek | f625aa9 | 2019-12-27 15:56:08 +0100 | [diff] [blame] | 726 | { |
| 727 | .cmd = ETHTOOL_MSG_LINKMODES_GET, |
| 728 | .doit = ethnl_default_doit, |
| 729 | .start = ethnl_default_start, |
| 730 | .dumpit = ethnl_default_dumpit, |
| 731 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 732 | .policy = ethnl_linkmodes_get_policy, |
| 733 | .maxattr = ARRAY_SIZE(ethnl_linkmodes_get_policy) - 1, |
Michal Kubecek | f625aa9 | 2019-12-27 15:56:08 +0100 | [diff] [blame] | 734 | }, |
Michal Kubecek | bfbcfe2 | 2019-12-27 15:56:13 +0100 | [diff] [blame] | 735 | { |
| 736 | .cmd = ETHTOOL_MSG_LINKMODES_SET, |
| 737 | .flags = GENL_UNS_ADMIN_PERM, |
| 738 | .doit = ethnl_set_linkmodes, |
Jakub Kicinski | 5028588b | 2020-10-05 15:07:34 -0700 | [diff] [blame] | 739 | .policy = ethnl_linkmodes_set_policy, |
| 740 | .maxattr = ARRAY_SIZE(ethnl_linkmodes_set_policy) - 1, |
Michal Kubecek | bfbcfe2 | 2019-12-27 15:56:13 +0100 | [diff] [blame] | 741 | }, |
Michal Kubecek | 3d2b847 | 2019-12-27 15:56:23 +0100 | [diff] [blame] | 742 | { |
| 743 | .cmd = ETHTOOL_MSG_LINKSTATE_GET, |
| 744 | .doit = ethnl_default_doit, |
| 745 | .start = ethnl_default_start, |
| 746 | .dumpit = ethnl_default_dumpit, |
| 747 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 748 | .policy = ethnl_linkstate_get_policy, |
| 749 | .maxattr = ARRAY_SIZE(ethnl_linkstate_get_policy) - 1, |
Michal Kubecek | 3d2b847 | 2019-12-27 15:56:23 +0100 | [diff] [blame] | 750 | }, |
Michal Kubecek | 6a94b8c | 2020-01-26 23:11:04 +0100 | [diff] [blame] | 751 | { |
| 752 | .cmd = ETHTOOL_MSG_DEBUG_GET, |
| 753 | .doit = ethnl_default_doit, |
| 754 | .start = ethnl_default_start, |
| 755 | .dumpit = ethnl_default_dumpit, |
| 756 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 757 | .policy = ethnl_debug_get_policy, |
| 758 | .maxattr = ARRAY_SIZE(ethnl_debug_get_policy) - 1, |
Michal Kubecek | 6a94b8c | 2020-01-26 23:11:04 +0100 | [diff] [blame] | 759 | }, |
Michal Kubecek | e54d04e | 2020-01-26 23:11:07 +0100 | [diff] [blame] | 760 | { |
| 761 | .cmd = ETHTOOL_MSG_DEBUG_SET, |
| 762 | .flags = GENL_UNS_ADMIN_PERM, |
| 763 | .doit = ethnl_set_debug, |
Jakub Kicinski | 5028588b | 2020-10-05 15:07:34 -0700 | [diff] [blame] | 764 | .policy = ethnl_debug_set_policy, |
| 765 | .maxattr = ARRAY_SIZE(ethnl_debug_set_policy) - 1, |
Michal Kubecek | e54d04e | 2020-01-26 23:11:07 +0100 | [diff] [blame] | 766 | }, |
Michal Kubecek | 51ea22b | 2020-01-26 23:11:13 +0100 | [diff] [blame] | 767 | { |
| 768 | .cmd = ETHTOOL_MSG_WOL_GET, |
| 769 | .flags = GENL_UNS_ADMIN_PERM, |
| 770 | .doit = ethnl_default_doit, |
| 771 | .start = ethnl_default_start, |
| 772 | .dumpit = ethnl_default_dumpit, |
| 773 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 774 | .policy = ethnl_wol_get_policy, |
| 775 | .maxattr = ARRAY_SIZE(ethnl_wol_get_policy) - 1, |
Michal Kubecek | 51ea22b | 2020-01-26 23:11:13 +0100 | [diff] [blame] | 776 | }, |
Michal Kubecek | 8d425b1 | 2020-01-26 23:11:16 +0100 | [diff] [blame] | 777 | { |
| 778 | .cmd = ETHTOOL_MSG_WOL_SET, |
| 779 | .flags = GENL_UNS_ADMIN_PERM, |
| 780 | .doit = ethnl_set_wol, |
Jakub Kicinski | 5028588b | 2020-10-05 15:07:34 -0700 | [diff] [blame] | 781 | .policy = ethnl_wol_set_policy, |
| 782 | .maxattr = ARRAY_SIZE(ethnl_wol_set_policy) - 1, |
Michal Kubecek | 8d425b1 | 2020-01-26 23:11:16 +0100 | [diff] [blame] | 783 | }, |
Michal Kubecek | 0524399 | 2020-03-12 21:07:48 +0100 | [diff] [blame] | 784 | { |
| 785 | .cmd = ETHTOOL_MSG_FEATURES_GET, |
| 786 | .doit = ethnl_default_doit, |
| 787 | .start = ethnl_default_start, |
| 788 | .dumpit = ethnl_default_dumpit, |
| 789 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 790 | .policy = ethnl_features_get_policy, |
| 791 | .maxattr = ARRAY_SIZE(ethnl_features_get_policy) - 1, |
Michal Kubecek | 0524399 | 2020-03-12 21:07:48 +0100 | [diff] [blame] | 792 | }, |
Michal Kubecek | 0980bfc | 2020-03-12 21:07:58 +0100 | [diff] [blame] | 793 | { |
| 794 | .cmd = ETHTOOL_MSG_FEATURES_SET, |
| 795 | .flags = GENL_UNS_ADMIN_PERM, |
| 796 | .doit = ethnl_set_features, |
Jakub Kicinski | 5028588b | 2020-10-05 15:07:34 -0700 | [diff] [blame] | 797 | .policy = ethnl_features_set_policy, |
| 798 | .maxattr = ARRAY_SIZE(ethnl_features_set_policy) - 1, |
Michal Kubecek | 0980bfc | 2020-03-12 21:07:58 +0100 | [diff] [blame] | 799 | }, |
Michal Kubecek | e16c338 | 2020-03-12 21:08:08 +0100 | [diff] [blame] | 800 | { |
| 801 | .cmd = ETHTOOL_MSG_PRIVFLAGS_GET, |
| 802 | .doit = ethnl_default_doit, |
| 803 | .start = ethnl_default_start, |
| 804 | .dumpit = ethnl_default_dumpit, |
| 805 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 806 | .policy = ethnl_privflags_get_policy, |
| 807 | .maxattr = ARRAY_SIZE(ethnl_privflags_get_policy) - 1, |
Michal Kubecek | e16c338 | 2020-03-12 21:08:08 +0100 | [diff] [blame] | 808 | }, |
Michal Kubecek | f265d79 | 2020-03-12 21:08:13 +0100 | [diff] [blame] | 809 | { |
| 810 | .cmd = ETHTOOL_MSG_PRIVFLAGS_SET, |
| 811 | .flags = GENL_UNS_ADMIN_PERM, |
| 812 | .doit = ethnl_set_privflags, |
Jakub Kicinski | 5028588b | 2020-10-05 15:07:34 -0700 | [diff] [blame] | 813 | .policy = ethnl_privflags_set_policy, |
| 814 | .maxattr = ARRAY_SIZE(ethnl_privflags_set_policy) - 1, |
Michal Kubecek | f265d79 | 2020-03-12 21:08:13 +0100 | [diff] [blame] | 815 | }, |
Michal Kubecek | e4a1717 | 2020-03-12 21:08:23 +0100 | [diff] [blame] | 816 | { |
| 817 | .cmd = ETHTOOL_MSG_RINGS_GET, |
| 818 | .doit = ethnl_default_doit, |
| 819 | .start = ethnl_default_start, |
| 820 | .dumpit = ethnl_default_dumpit, |
| 821 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 822 | .policy = ethnl_rings_get_policy, |
| 823 | .maxattr = ARRAY_SIZE(ethnl_rings_get_policy) - 1, |
Michal Kubecek | e4a1717 | 2020-03-12 21:08:23 +0100 | [diff] [blame] | 824 | }, |
Michal Kubecek | 2fc2929 | 2020-03-12 21:08:28 +0100 | [diff] [blame] | 825 | { |
| 826 | .cmd = ETHTOOL_MSG_RINGS_SET, |
| 827 | .flags = GENL_UNS_ADMIN_PERM, |
| 828 | .doit = ethnl_set_rings, |
Jakub Kicinski | 5028588b | 2020-10-05 15:07:34 -0700 | [diff] [blame] | 829 | .policy = ethnl_rings_set_policy, |
| 830 | .maxattr = ARRAY_SIZE(ethnl_rings_set_policy) - 1, |
Michal Kubecek | 2fc2929 | 2020-03-12 21:08:28 +0100 | [diff] [blame] | 831 | }, |
Michal Kubecek | 0c84979 | 2020-03-12 21:08:38 +0100 | [diff] [blame] | 832 | { |
| 833 | .cmd = ETHTOOL_MSG_CHANNELS_GET, |
| 834 | .doit = ethnl_default_doit, |
| 835 | .start = ethnl_default_start, |
| 836 | .dumpit = ethnl_default_dumpit, |
| 837 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 838 | .policy = ethnl_channels_get_policy, |
| 839 | .maxattr = ARRAY_SIZE(ethnl_channels_get_policy) - 1, |
Michal Kubecek | 0c84979 | 2020-03-12 21:08:38 +0100 | [diff] [blame] | 840 | }, |
Michal Kubecek | e19c591 | 2020-03-12 21:08:43 +0100 | [diff] [blame] | 841 | { |
| 842 | .cmd = ETHTOOL_MSG_CHANNELS_SET, |
| 843 | .flags = GENL_UNS_ADMIN_PERM, |
| 844 | .doit = ethnl_set_channels, |
Johannes Berg | fd15dd0 | 2020-10-07 12:53:51 +0200 | [diff] [blame] | 845 | .policy = ethnl_channels_set_policy, |
| 846 | .maxattr = ARRAY_SIZE(ethnl_channels_set_policy) - 1, |
Michal Kubecek | e19c591 | 2020-03-12 21:08:43 +0100 | [diff] [blame] | 847 | }, |
Michal Kubecek | 2172754 | 2020-03-28 00:01:08 +0100 | [diff] [blame] | 848 | { |
| 849 | .cmd = ETHTOOL_MSG_COALESCE_GET, |
| 850 | .doit = ethnl_default_doit, |
| 851 | .start = ethnl_default_start, |
| 852 | .dumpit = ethnl_default_dumpit, |
| 853 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 854 | .policy = ethnl_coalesce_get_policy, |
| 855 | .maxattr = ARRAY_SIZE(ethnl_coalesce_get_policy) - 1, |
Michal Kubecek | 2172754 | 2020-03-28 00:01:08 +0100 | [diff] [blame] | 856 | }, |
Michal Kubecek | 9881418 | 2020-03-28 00:01:13 +0100 | [diff] [blame] | 857 | { |
| 858 | .cmd = ETHTOOL_MSG_COALESCE_SET, |
| 859 | .flags = GENL_UNS_ADMIN_PERM, |
| 860 | .doit = ethnl_set_coalesce, |
Jakub Kicinski | 5028588b | 2020-10-05 15:07:34 -0700 | [diff] [blame] | 861 | .policy = ethnl_coalesce_set_policy, |
| 862 | .maxattr = ARRAY_SIZE(ethnl_coalesce_set_policy) - 1, |
Michal Kubecek | 9881418 | 2020-03-28 00:01:13 +0100 | [diff] [blame] | 863 | }, |
Michal Kubecek | 7f59fb3 | 2020-03-28 00:01:23 +0100 | [diff] [blame] | 864 | { |
| 865 | .cmd = ETHTOOL_MSG_PAUSE_GET, |
| 866 | .doit = ethnl_default_doit, |
| 867 | .start = ethnl_default_start, |
| 868 | .dumpit = ethnl_default_dumpit, |
| 869 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 870 | .policy = ethnl_pause_get_policy, |
| 871 | .maxattr = ARRAY_SIZE(ethnl_pause_get_policy) - 1, |
Michal Kubecek | 7f59fb3 | 2020-03-28 00:01:23 +0100 | [diff] [blame] | 872 | }, |
Michal Kubecek | 3ab8799 | 2020-03-28 00:01:28 +0100 | [diff] [blame] | 873 | { |
| 874 | .cmd = ETHTOOL_MSG_PAUSE_SET, |
| 875 | .flags = GENL_UNS_ADMIN_PERM, |
| 876 | .doit = ethnl_set_pause, |
Jakub Kicinski | 5028588b | 2020-10-05 15:07:34 -0700 | [diff] [blame] | 877 | .policy = ethnl_pause_set_policy, |
| 878 | .maxattr = ARRAY_SIZE(ethnl_pause_set_policy) - 1, |
Michal Kubecek | 3ab8799 | 2020-03-28 00:01:28 +0100 | [diff] [blame] | 879 | }, |
Michal Kubecek | b7eeefe | 2020-03-28 00:01:38 +0100 | [diff] [blame] | 880 | { |
| 881 | .cmd = ETHTOOL_MSG_EEE_GET, |
| 882 | .doit = ethnl_default_doit, |
| 883 | .start = ethnl_default_start, |
| 884 | .dumpit = ethnl_default_dumpit, |
| 885 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 886 | .policy = ethnl_eee_get_policy, |
| 887 | .maxattr = ARRAY_SIZE(ethnl_eee_get_policy) - 1, |
Michal Kubecek | b7eeefe | 2020-03-28 00:01:38 +0100 | [diff] [blame] | 888 | }, |
Michal Kubecek | fd77be7 | 2020-03-28 00:01:43 +0100 | [diff] [blame] | 889 | { |
| 890 | .cmd = ETHTOOL_MSG_EEE_SET, |
| 891 | .flags = GENL_UNS_ADMIN_PERM, |
| 892 | .doit = ethnl_set_eee, |
Jakub Kicinski | 5028588b | 2020-10-05 15:07:34 -0700 | [diff] [blame] | 893 | .policy = ethnl_eee_set_policy, |
| 894 | .maxattr = ARRAY_SIZE(ethnl_eee_set_policy) - 1, |
Michal Kubecek | fd77be7 | 2020-03-28 00:01:43 +0100 | [diff] [blame] | 895 | }, |
Michal Kubecek | 5b071c5 | 2020-03-28 00:01:58 +0100 | [diff] [blame] | 896 | { |
| 897 | .cmd = ETHTOOL_MSG_TSINFO_GET, |
| 898 | .doit = ethnl_default_doit, |
| 899 | .start = ethnl_default_start, |
| 900 | .dumpit = ethnl_default_dumpit, |
| 901 | .done = ethnl_default_done, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 902 | .policy = ethnl_tsinfo_get_policy, |
| 903 | .maxattr = ARRAY_SIZE(ethnl_tsinfo_get_policy) - 1, |
Michal Kubecek | 5b071c5 | 2020-03-28 00:01:58 +0100 | [diff] [blame] | 904 | }, |
Andrew Lunn | 11ca3c42 | 2020-05-10 21:12:33 +0200 | [diff] [blame] | 905 | { |
| 906 | .cmd = ETHTOOL_MSG_CABLE_TEST_ACT, |
| 907 | .flags = GENL_UNS_ADMIN_PERM, |
| 908 | .doit = ethnl_act_cable_test, |
Jakub Kicinski | 5028588b | 2020-10-05 15:07:34 -0700 | [diff] [blame] | 909 | .policy = ethnl_cable_test_act_policy, |
| 910 | .maxattr = ARRAY_SIZE(ethnl_cable_test_act_policy) - 1, |
Andrew Lunn | 11ca3c42 | 2020-05-10 21:12:33 +0200 | [diff] [blame] | 911 | }, |
Andrew Lunn | 1a644de | 2020-05-27 00:21:38 +0200 | [diff] [blame] | 912 | { |
| 913 | .cmd = ETHTOOL_MSG_CABLE_TEST_TDR_ACT, |
| 914 | .flags = GENL_UNS_ADMIN_PERM, |
| 915 | .doit = ethnl_act_cable_test_tdr, |
Jakub Kicinski | 5028588b | 2020-10-05 15:07:34 -0700 | [diff] [blame] | 916 | .policy = ethnl_cable_test_tdr_act_policy, |
| 917 | .maxattr = ARRAY_SIZE(ethnl_cable_test_tdr_act_policy) - 1, |
Andrew Lunn | 1a644de | 2020-05-27 00:21:38 +0200 | [diff] [blame] | 918 | }, |
Jakub Kicinski | c7d759e | 2020-07-09 17:42:47 -0700 | [diff] [blame] | 919 | { |
| 920 | .cmd = ETHTOOL_MSG_TUNNEL_INFO_GET, |
| 921 | .doit = ethnl_tunnel_info_doit, |
| 922 | .start = ethnl_tunnel_info_start, |
| 923 | .dumpit = ethnl_tunnel_info_dumpit, |
Jakub Kicinski | 4f30974 | 2020-10-05 15:07:33 -0700 | [diff] [blame] | 924 | .policy = ethnl_tunnel_info_get_policy, |
| 925 | .maxattr = ARRAY_SIZE(ethnl_tunnel_info_get_policy) - 1, |
Jakub Kicinski | c7d759e | 2020-07-09 17:42:47 -0700 | [diff] [blame] | 926 | }, |
Jakub Kicinski | 1e5d1f6 | 2021-03-29 20:59:52 -0700 | [diff] [blame] | 927 | { |
| 928 | .cmd = ETHTOOL_MSG_FEC_GET, |
| 929 | .doit = ethnl_default_doit, |
| 930 | .start = ethnl_default_start, |
| 931 | .dumpit = ethnl_default_dumpit, |
| 932 | .done = ethnl_default_done, |
| 933 | .policy = ethnl_fec_get_policy, |
| 934 | .maxattr = ARRAY_SIZE(ethnl_fec_get_policy) - 1, |
| 935 | }, |
| 936 | { |
| 937 | .cmd = ETHTOOL_MSG_FEC_SET, |
| 938 | .flags = GENL_UNS_ADMIN_PERM, |
| 939 | .doit = ethnl_set_fec, |
| 940 | .policy = ethnl_fec_set_policy, |
| 941 | .maxattr = ARRAY_SIZE(ethnl_fec_set_policy) - 1, |
| 942 | }, |
Vladyslav Tarasiuk | c781ff1 | 2021-04-09 11:06:34 +0300 | [diff] [blame] | 943 | { |
| 944 | .cmd = ETHTOOL_MSG_MODULE_EEPROM_GET, |
| 945 | .flags = GENL_UNS_ADMIN_PERM, |
| 946 | .doit = ethnl_default_doit, |
| 947 | .start = ethnl_default_start, |
| 948 | .dumpit = ethnl_default_dumpit, |
| 949 | .done = ethnl_default_done, |
| 950 | .policy = ethnl_module_eeprom_get_policy, |
| 951 | .maxattr = ARRAY_SIZE(ethnl_module_eeprom_get_policy) - 1, |
| 952 | }, |
Jakub Kicinski | f09ea6f | 2021-04-16 12:27:39 -0700 | [diff] [blame] | 953 | { |
| 954 | .cmd = ETHTOOL_MSG_STATS_GET, |
| 955 | .doit = ethnl_default_doit, |
| 956 | .start = ethnl_default_start, |
| 957 | .dumpit = ethnl_default_dumpit, |
| 958 | .done = ethnl_default_done, |
| 959 | .policy = ethnl_stats_get_policy, |
| 960 | .maxattr = ARRAY_SIZE(ethnl_stats_get_policy) - 1, |
| 961 | }, |
Yangbo Lu | c156174a | 2021-06-30 16:11:56 +0800 | [diff] [blame^] | 962 | { |
| 963 | .cmd = ETHTOOL_MSG_PHC_VCLOCKS_GET, |
| 964 | .doit = ethnl_default_doit, |
| 965 | .start = ethnl_default_start, |
| 966 | .dumpit = ethnl_default_dumpit, |
| 967 | .done = ethnl_default_done, |
| 968 | .policy = ethnl_phc_vclocks_get_policy, |
| 969 | .maxattr = ARRAY_SIZE(ethnl_phc_vclocks_get_policy) - 1, |
| 970 | }, |
Michal Kubecek | 2b4a899 | 2019-12-27 15:55:18 +0100 | [diff] [blame] | 971 | }; |
| 972 | |
Michal Kubecek | 6b08d6c | 2019-12-27 15:55:33 +0100 | [diff] [blame] | 973 | static const struct genl_multicast_group ethtool_nl_mcgrps[] = { |
| 974 | [ETHNL_MCGRP_MONITOR] = { .name = ETHTOOL_MCGRP_MONITOR_NAME }, |
| 975 | }; |
| 976 | |
Jakub Kicinski | 78b7015 | 2020-09-28 17:58:41 -0700 | [diff] [blame] | 977 | static struct genl_family ethtool_genl_family __ro_after_init = { |
Michal Kubecek | 2b4a899 | 2019-12-27 15:55:18 +0100 | [diff] [blame] | 978 | .name = ETHTOOL_GENL_NAME, |
| 979 | .version = ETHTOOL_GENL_VERSION, |
| 980 | .netnsok = true, |
| 981 | .parallel_ops = true, |
| 982 | .ops = ethtool_genl_ops, |
| 983 | .n_ops = ARRAY_SIZE(ethtool_genl_ops), |
Michal Kubecek | 6b08d6c | 2019-12-27 15:55:33 +0100 | [diff] [blame] | 984 | .mcgrps = ethtool_nl_mcgrps, |
| 985 | .n_mcgrps = ARRAY_SIZE(ethtool_nl_mcgrps), |
Michal Kubecek | 2b4a899 | 2019-12-27 15:55:18 +0100 | [diff] [blame] | 986 | }; |
| 987 | |
| 988 | /* module setup */ |
| 989 | |
| 990 | static int __init ethnl_init(void) |
| 991 | { |
| 992 | int ret; |
| 993 | |
| 994 | ret = genl_register_family(ðtool_genl_family); |
| 995 | if (WARN(ret < 0, "ethtool: genetlink family registration failed")) |
| 996 | return ret; |
Michal Kubecek | 6b08d6c | 2019-12-27 15:55:33 +0100 | [diff] [blame] | 997 | ethnl_ok = true; |
Michal Kubecek | 2b4a899 | 2019-12-27 15:55:18 +0100 | [diff] [blame] | 998 | |
Michal Kubecek | 9c6451e | 2020-03-12 21:08:03 +0100 | [diff] [blame] | 999 | ret = register_netdevice_notifier(ðnl_netdev_notifier); |
| 1000 | WARN(ret < 0, "ethtool: net device notifier registration failed"); |
| 1001 | return ret; |
Michal Kubecek | 2b4a899 | 2019-12-27 15:55:18 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | subsys_initcall(ethnl_init); |