0001
0002
0003 #ifndef _NET_ETHTOOL_NETLINK_H
0004 #define _NET_ETHTOOL_NETLINK_H
0005
0006 #include <linux/ethtool_netlink.h>
0007 #include <linux/netdevice.h>
0008 #include <net/genetlink.h>
0009 #include <net/sock.h>
0010
0011 struct ethnl_req_info;
0012
0013 int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
0014 const struct nlattr *nest, struct net *net,
0015 struct netlink_ext_ack *extack,
0016 bool require_dev);
0017 int ethnl_fill_reply_header(struct sk_buff *skb, struct net_device *dev,
0018 u16 attrtype);
0019 struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,
0020 u16 hdr_attrtype, struct genl_info *info,
0021 void **ehdrp);
0022 void *ethnl_dump_put(struct sk_buff *skb, struct netlink_callback *cb, u8 cmd);
0023 void *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd);
0024 int ethnl_multicast(struct sk_buff *skb, struct net_device *dev);
0025
0026
0027
0028
0029
0030
0031
0032 static inline int ethnl_strz_size(const char *s)
0033 {
0034 return nla_total_size(strnlen(s, ETH_GSTRING_LEN) + 1);
0035 }
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 static inline int ethnl_put_strz(struct sk_buff *skb, u16 attrtype,
0048 const char *s)
0049 {
0050 unsigned int len = strnlen(s, ETH_GSTRING_LEN);
0051 struct nlattr *attr;
0052
0053 attr = nla_reserve(skb, attrtype, len + 1);
0054 if (!attr)
0055 return -EMSGSIZE;
0056
0057 memcpy(nla_data(attr), s, len);
0058 ((char *)nla_data(attr))[len] = '\0';
0059 return 0;
0060 }
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 static inline void ethnl_update_u32(u32 *dst, const struct nlattr *attr,
0074 bool *mod)
0075 {
0076 u32 val;
0077
0078 if (!attr)
0079 return;
0080 val = nla_get_u32(attr);
0081 if (*dst == val)
0082 return;
0083
0084 *dst = val;
0085 *mod = true;
0086 }
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099 static inline void ethnl_update_u8(u8 *dst, const struct nlattr *attr,
0100 bool *mod)
0101 {
0102 u8 val;
0103
0104 if (!attr)
0105 return;
0106 val = nla_get_u8(attr);
0107 if (*dst == val)
0108 return;
0109
0110 *dst = val;
0111 *mod = true;
0112 }
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 static inline void ethnl_update_bool32(u32 *dst, const struct nlattr *attr,
0126 bool *mod)
0127 {
0128 u8 val;
0129
0130 if (!attr)
0131 return;
0132 val = !!nla_get_u8(attr);
0133 if (!!*dst == val)
0134 return;
0135
0136 *dst = val;
0137 *mod = true;
0138 }
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152 static inline void ethnl_update_binary(void *dst, unsigned int len,
0153 const struct nlattr *attr, bool *mod)
0154 {
0155 if (!attr)
0156 return;
0157 if (nla_len(attr) < len)
0158 len = nla_len(attr);
0159 if (!memcmp(dst, nla_data(attr), len))
0160 return;
0161
0162 memcpy(dst, nla_data(attr), len);
0163 *mod = true;
0164 }
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176 static inline void ethnl_update_bitfield32(u32 *dst, const struct nlattr *attr,
0177 bool *mod)
0178 {
0179 struct nla_bitfield32 change;
0180 u32 newval;
0181
0182 if (!attr)
0183 return;
0184 change = nla_get_bitfield32(attr);
0185 newval = (*dst & ~change.selector) | (change.value & change.selector);
0186 if (*dst == newval)
0187 return;
0188
0189 *dst = newval;
0190 *mod = true;
0191 }
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 static inline unsigned int ethnl_reply_header_size(void)
0202 {
0203 return nla_total_size(nla_total_size(sizeof(u32)) +
0204 nla_total_size(IFNAMSIZ));
0205 }
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232 struct ethnl_req_info {
0233 struct net_device *dev;
0234 netdevice_tracker dev_tracker;
0235 u32 flags;
0236 };
0237
0238 static inline void ethnl_parse_header_dev_put(struct ethnl_req_info *req_info)
0239 {
0240 netdev_put(req_info->dev, &req_info->dev_tracker);
0241 }
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253 struct ethnl_reply_data {
0254 struct net_device *dev;
0255 };
0256
0257 int ethnl_ops_begin(struct net_device *dev);
0258 void ethnl_ops_complete(struct net_device *dev);
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305 struct ethnl_request_ops {
0306 u8 request_cmd;
0307 u8 reply_cmd;
0308 u16 hdr_attr;
0309 unsigned int req_info_size;
0310 unsigned int reply_data_size;
0311 bool allow_nodev_do;
0312
0313 int (*parse_request)(struct ethnl_req_info *req_info,
0314 struct nlattr **tb,
0315 struct netlink_ext_ack *extack);
0316 int (*prepare_data)(const struct ethnl_req_info *req_info,
0317 struct ethnl_reply_data *reply_data,
0318 struct genl_info *info);
0319 int (*reply_size)(const struct ethnl_req_info *req_info,
0320 const struct ethnl_reply_data *reply_data);
0321 int (*fill_reply)(struct sk_buff *skb,
0322 const struct ethnl_req_info *req_info,
0323 const struct ethnl_reply_data *reply_data);
0324 void (*cleanup_data)(struct ethnl_reply_data *reply_data);
0325 };
0326
0327
0328
0329 extern const struct ethnl_request_ops ethnl_strset_request_ops;
0330 extern const struct ethnl_request_ops ethnl_linkinfo_request_ops;
0331 extern const struct ethnl_request_ops ethnl_linkmodes_request_ops;
0332 extern const struct ethnl_request_ops ethnl_linkstate_request_ops;
0333 extern const struct ethnl_request_ops ethnl_debug_request_ops;
0334 extern const struct ethnl_request_ops ethnl_wol_request_ops;
0335 extern const struct ethnl_request_ops ethnl_features_request_ops;
0336 extern const struct ethnl_request_ops ethnl_privflags_request_ops;
0337 extern const struct ethnl_request_ops ethnl_rings_request_ops;
0338 extern const struct ethnl_request_ops ethnl_channels_request_ops;
0339 extern const struct ethnl_request_ops ethnl_coalesce_request_ops;
0340 extern const struct ethnl_request_ops ethnl_pause_request_ops;
0341 extern const struct ethnl_request_ops ethnl_eee_request_ops;
0342 extern const struct ethnl_request_ops ethnl_tsinfo_request_ops;
0343 extern const struct ethnl_request_ops ethnl_fec_request_ops;
0344 extern const struct ethnl_request_ops ethnl_module_eeprom_request_ops;
0345 extern const struct ethnl_request_ops ethnl_stats_request_ops;
0346 extern const struct ethnl_request_ops ethnl_phc_vclocks_request_ops;
0347 extern const struct ethnl_request_ops ethnl_module_request_ops;
0348
0349 extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1];
0350 extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1];
0351 extern const struct nla_policy ethnl_strset_get_policy[ETHTOOL_A_STRSET_COUNTS_ONLY + 1];
0352 extern const struct nla_policy ethnl_linkinfo_get_policy[ETHTOOL_A_LINKINFO_HEADER + 1];
0353 extern const struct nla_policy ethnl_linkinfo_set_policy[ETHTOOL_A_LINKINFO_TP_MDIX_CTRL + 1];
0354 extern const struct nla_policy ethnl_linkmodes_get_policy[ETHTOOL_A_LINKMODES_HEADER + 1];
0355 extern const struct nla_policy ethnl_linkmodes_set_policy[ETHTOOL_A_LINKMODES_LANES + 1];
0356 extern const struct nla_policy ethnl_linkstate_get_policy[ETHTOOL_A_LINKSTATE_HEADER + 1];
0357 extern const struct nla_policy ethnl_debug_get_policy[ETHTOOL_A_DEBUG_HEADER + 1];
0358 extern const struct nla_policy ethnl_debug_set_policy[ETHTOOL_A_DEBUG_MSGMASK + 1];
0359 extern const struct nla_policy ethnl_wol_get_policy[ETHTOOL_A_WOL_HEADER + 1];
0360 extern const struct nla_policy ethnl_wol_set_policy[ETHTOOL_A_WOL_SOPASS + 1];
0361 extern const struct nla_policy ethnl_features_get_policy[ETHTOOL_A_FEATURES_HEADER + 1];
0362 extern const struct nla_policy ethnl_features_set_policy[ETHTOOL_A_FEATURES_WANTED + 1];
0363 extern const struct nla_policy ethnl_privflags_get_policy[ETHTOOL_A_PRIVFLAGS_HEADER + 1];
0364 extern const struct nla_policy ethnl_privflags_set_policy[ETHTOOL_A_PRIVFLAGS_FLAGS + 1];
0365 extern const struct nla_policy ethnl_rings_get_policy[ETHTOOL_A_RINGS_HEADER + 1];
0366 extern const struct nla_policy ethnl_rings_set_policy[ETHTOOL_A_RINGS_TX_PUSH + 1];
0367 extern const struct nla_policy ethnl_channels_get_policy[ETHTOOL_A_CHANNELS_HEADER + 1];
0368 extern const struct nla_policy ethnl_channels_set_policy[ETHTOOL_A_CHANNELS_COMBINED_COUNT + 1];
0369 extern const struct nla_policy ethnl_coalesce_get_policy[ETHTOOL_A_COALESCE_HEADER + 1];
0370 extern const struct nla_policy ethnl_coalesce_set_policy[ETHTOOL_A_COALESCE_MAX + 1];
0371 extern const struct nla_policy ethnl_pause_get_policy[ETHTOOL_A_PAUSE_HEADER + 1];
0372 extern const struct nla_policy ethnl_pause_set_policy[ETHTOOL_A_PAUSE_TX + 1];
0373 extern const struct nla_policy ethnl_eee_get_policy[ETHTOOL_A_EEE_HEADER + 1];
0374 extern const struct nla_policy ethnl_eee_set_policy[ETHTOOL_A_EEE_TX_LPI_TIMER + 1];
0375 extern const struct nla_policy ethnl_tsinfo_get_policy[ETHTOOL_A_TSINFO_HEADER + 1];
0376 extern const struct nla_policy ethnl_cable_test_act_policy[ETHTOOL_A_CABLE_TEST_HEADER + 1];
0377 extern const struct nla_policy ethnl_cable_test_tdr_act_policy[ETHTOOL_A_CABLE_TEST_TDR_CFG + 1];
0378 extern const struct nla_policy ethnl_tunnel_info_get_policy[ETHTOOL_A_TUNNEL_INFO_HEADER + 1];
0379 extern const struct nla_policy ethnl_fec_get_policy[ETHTOOL_A_FEC_HEADER + 1];
0380 extern const struct nla_policy ethnl_fec_set_policy[ETHTOOL_A_FEC_AUTO + 1];
0381 extern const struct nla_policy ethnl_module_eeprom_get_policy[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS + 1];
0382 extern const struct nla_policy ethnl_stats_get_policy[ETHTOOL_A_STATS_GROUPS + 1];
0383 extern const struct nla_policy ethnl_phc_vclocks_get_policy[ETHTOOL_A_PHC_VCLOCKS_HEADER + 1];
0384 extern const struct nla_policy ethnl_module_get_policy[ETHTOOL_A_MODULE_HEADER + 1];
0385 extern const struct nla_policy ethnl_module_set_policy[ETHTOOL_A_MODULE_POWER_MODE_POLICY + 1];
0386
0387 int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info);
0388 int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info);
0389 int ethnl_set_debug(struct sk_buff *skb, struct genl_info *info);
0390 int ethnl_set_wol(struct sk_buff *skb, struct genl_info *info);
0391 int ethnl_set_features(struct sk_buff *skb, struct genl_info *info);
0392 int ethnl_set_privflags(struct sk_buff *skb, struct genl_info *info);
0393 int ethnl_set_rings(struct sk_buff *skb, struct genl_info *info);
0394 int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info);
0395 int ethnl_set_coalesce(struct sk_buff *skb, struct genl_info *info);
0396 int ethnl_set_pause(struct sk_buff *skb, struct genl_info *info);
0397 int ethnl_set_eee(struct sk_buff *skb, struct genl_info *info);
0398 int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);
0399 int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info);
0400 int ethnl_tunnel_info_doit(struct sk_buff *skb, struct genl_info *info);
0401 int ethnl_tunnel_info_start(struct netlink_callback *cb);
0402 int ethnl_tunnel_info_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
0403 int ethnl_set_fec(struct sk_buff *skb, struct genl_info *info);
0404 int ethnl_set_module(struct sk_buff *skb, struct genl_info *info);
0405
0406 extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN];
0407 extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN];
0408 extern const char stats_eth_mac_names[__ETHTOOL_A_STATS_ETH_MAC_CNT][ETH_GSTRING_LEN];
0409 extern const char stats_eth_ctrl_names[__ETHTOOL_A_STATS_ETH_CTRL_CNT][ETH_GSTRING_LEN];
0410 extern const char stats_rmon_names[__ETHTOOL_A_STATS_RMON_CNT][ETH_GSTRING_LEN];
0411
0412 #endif