netlink.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. #include <net/netdev_lock.h>
  3. #include <net/netdev_queues.h>
  4. #include <net/sock.h>
  5. #include <linux/ethtool_netlink.h>
  6. #include <linux/phy_link_topology.h>
  7. #include <linux/pm_runtime.h>
  8. #include "netlink.h"
  9. #include "module_fw.h"
  10. static struct genl_family ethtool_genl_family;
  11. static bool ethnl_ok __read_mostly;
  12. static u32 ethnl_bcast_seq;
  13. #define ETHTOOL_FLAGS_BASIC (ETHTOOL_FLAG_COMPACT_BITSETS | \
  14. ETHTOOL_FLAG_OMIT_REPLY)
  15. #define ETHTOOL_FLAGS_STATS (ETHTOOL_FLAGS_BASIC | ETHTOOL_FLAG_STATS)
  16. const struct nla_policy ethnl_header_policy[] = {
  17. [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 },
  18. [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING,
  19. .len = ALTIFNAMSIZ - 1 },
  20. [ETHTOOL_A_HEADER_FLAGS] = NLA_POLICY_MASK(NLA_U32,
  21. ETHTOOL_FLAGS_BASIC),
  22. };
  23. const struct nla_policy ethnl_header_policy_stats[] = {
  24. [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 },
  25. [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING,
  26. .len = ALTIFNAMSIZ - 1 },
  27. [ETHTOOL_A_HEADER_FLAGS] = NLA_POLICY_MASK(NLA_U32,
  28. ETHTOOL_FLAGS_STATS),
  29. };
  30. const struct nla_policy ethnl_header_policy_phy[] = {
  31. [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 },
  32. [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING,
  33. .len = ALTIFNAMSIZ - 1 },
  34. [ETHTOOL_A_HEADER_FLAGS] = NLA_POLICY_MASK(NLA_U32,
  35. ETHTOOL_FLAGS_BASIC),
  36. [ETHTOOL_A_HEADER_PHY_INDEX] = NLA_POLICY_MIN(NLA_U32, 1),
  37. };
  38. const struct nla_policy ethnl_header_policy_phy_stats[] = {
  39. [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 },
  40. [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING,
  41. .len = ALTIFNAMSIZ - 1 },
  42. [ETHTOOL_A_HEADER_FLAGS] = NLA_POLICY_MASK(NLA_U32,
  43. ETHTOOL_FLAGS_STATS),
  44. [ETHTOOL_A_HEADER_PHY_INDEX] = NLA_POLICY_MIN(NLA_U32, 1),
  45. };
  46. int ethnl_sock_priv_set(struct sk_buff *skb, struct net_device *dev, u32 portid,
  47. enum ethnl_sock_type type)
  48. {
  49. struct ethnl_sock_priv *sk_priv;
  50. sk_priv = genl_sk_priv_get(&ethtool_genl_family, NETLINK_CB(skb).sk);
  51. if (IS_ERR(sk_priv))
  52. return PTR_ERR(sk_priv);
  53. sk_priv->dev = dev;
  54. sk_priv->portid = portid;
  55. sk_priv->type = type;
  56. return 0;
  57. }
  58. static void ethnl_sock_priv_destroy(void *priv)
  59. {
  60. struct ethnl_sock_priv *sk_priv = priv;
  61. switch (sk_priv->type) {
  62. case ETHTOOL_SOCK_TYPE_MODULE_FW_FLASH:
  63. ethnl_module_fw_flash_sock_destroy(sk_priv);
  64. break;
  65. default:
  66. break;
  67. }
  68. }
  69. u32 ethnl_bcast_seq_next(void)
  70. {
  71. ASSERT_RTNL();
  72. return ++ethnl_bcast_seq;
  73. }
  74. int ethnl_ops_begin(struct net_device *dev)
  75. {
  76. int ret;
  77. if (!dev)
  78. return -ENODEV;
  79. if (dev->dev.parent)
  80. pm_runtime_get_sync(dev->dev.parent);
  81. netdev_ops_assert_locked(dev);
  82. if (!netif_device_present(dev) ||
  83. dev->reg_state >= NETREG_UNREGISTERING) {
  84. ret = -ENODEV;
  85. goto err;
  86. }
  87. if (dev->ethtool_ops->begin) {
  88. ret = dev->ethtool_ops->begin(dev);
  89. if (ret)
  90. goto err;
  91. }
  92. return 0;
  93. err:
  94. if (dev->dev.parent)
  95. pm_runtime_put(dev->dev.parent);
  96. return ret;
  97. }
  98. void ethnl_ops_complete(struct net_device *dev)
  99. {
  100. if (dev->ethtool_ops->complete)
  101. dev->ethtool_ops->complete(dev);
  102. if (dev->dev.parent)
  103. pm_runtime_put(dev->dev.parent);
  104. }
  105. /**
  106. * ethnl_parse_header_dev_get() - parse request header
  107. * @req_info: structure to put results into
  108. * @header: nest attribute with request header
  109. * @net: request netns
  110. * @extack: netlink extack for error reporting
  111. * @require_dev: fail if no device identified in header
  112. *
  113. * Parse request header in nested attribute @nest and puts results into
  114. * the structure pointed to by @req_info. Extack from @info is used for error
  115. * reporting. If req_info->dev is not null on return, reference to it has
  116. * been taken. If error is returned, *req_info is null initialized and no
  117. * reference is held.
  118. *
  119. * Return: 0 on success or negative error code
  120. */
  121. int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
  122. const struct nlattr *header, struct net *net,
  123. struct netlink_ext_ack *extack, bool require_dev)
  124. {
  125. struct nlattr *tb[ARRAY_SIZE(ethnl_header_policy_phy)];
  126. const struct nlattr *devname_attr;
  127. struct net_device *dev = NULL;
  128. u32 flags = 0;
  129. int ret;
  130. if (!header) {
  131. if (!require_dev)
  132. return 0;
  133. NL_SET_ERR_MSG(extack, "request header missing");
  134. return -EINVAL;
  135. }
  136. /* No validation here, command policy should have a nested policy set
  137. * for the header, therefore validation should have already been done.
  138. */
  139. ret = nla_parse_nested(tb, ARRAY_SIZE(ethnl_header_policy_phy) - 1, header,
  140. NULL, extack);
  141. if (ret < 0)
  142. return ret;
  143. if (tb[ETHTOOL_A_HEADER_FLAGS])
  144. flags = nla_get_u32(tb[ETHTOOL_A_HEADER_FLAGS]);
  145. devname_attr = tb[ETHTOOL_A_HEADER_DEV_NAME];
  146. if (tb[ETHTOOL_A_HEADER_DEV_INDEX]) {
  147. u32 ifindex = nla_get_u32(tb[ETHTOOL_A_HEADER_DEV_INDEX]);
  148. dev = netdev_get_by_index(net, ifindex, &req_info->dev_tracker,
  149. GFP_KERNEL);
  150. if (!dev) {
  151. NL_SET_ERR_MSG_ATTR(extack,
  152. tb[ETHTOOL_A_HEADER_DEV_INDEX],
  153. "no device matches ifindex");
  154. return -ENODEV;
  155. }
  156. /* if both ifindex and ifname are passed, they must match */
  157. if (devname_attr &&
  158. strncmp(dev->name, nla_data(devname_attr), IFNAMSIZ)) {
  159. netdev_put(dev, &req_info->dev_tracker);
  160. NL_SET_ERR_MSG_ATTR(extack, header,
  161. "ifindex and name do not match");
  162. return -ENODEV;
  163. }
  164. } else if (devname_attr) {
  165. dev = netdev_get_by_name(net, nla_data(devname_attr),
  166. &req_info->dev_tracker, GFP_KERNEL);
  167. if (!dev) {
  168. NL_SET_ERR_MSG_ATTR(extack, devname_attr,
  169. "no device matches name");
  170. return -ENODEV;
  171. }
  172. } else if (require_dev) {
  173. NL_SET_ERR_MSG_ATTR(extack, header,
  174. "neither ifindex nor name specified");
  175. return -EINVAL;
  176. }
  177. if (tb[ETHTOOL_A_HEADER_PHY_INDEX]) {
  178. if (dev) {
  179. req_info->phy_index = nla_get_u32(tb[ETHTOOL_A_HEADER_PHY_INDEX]);
  180. } else {
  181. NL_SET_ERR_MSG_ATTR(extack, header,
  182. "phy_index set without a netdev");
  183. return -EINVAL;
  184. }
  185. }
  186. req_info->dev = dev;
  187. req_info->flags = flags;
  188. return 0;
  189. }
  190. struct phy_device *ethnl_req_get_phydev(const struct ethnl_req_info *req_info,
  191. struct nlattr **tb, unsigned int header,
  192. struct netlink_ext_ack *extack)
  193. {
  194. struct phy_device *phydev;
  195. ASSERT_RTNL();
  196. if (!req_info->dev)
  197. return NULL;
  198. if (!req_info->phy_index)
  199. return req_info->dev->phydev;
  200. phydev = phy_link_topo_get_phy(req_info->dev, req_info->phy_index);
  201. if (!phydev && tb) {
  202. NL_SET_ERR_MSG_ATTR(extack, tb[header],
  203. "no phy matching phyindex");
  204. return ERR_PTR(-ENODEV);
  205. }
  206. return phydev;
  207. }
  208. /**
  209. * ethnl_fill_reply_header() - Put common header into a reply message
  210. * @skb: skb with the message
  211. * @dev: network device to describe in header
  212. * @attrtype: attribute type to use for the nest
  213. *
  214. * Create a nested attribute with attributes describing given network device.
  215. *
  216. * Return: 0 on success, error value (-EMSGSIZE only) on error
  217. */
  218. int ethnl_fill_reply_header(struct sk_buff *skb, struct net_device *dev,
  219. u16 attrtype)
  220. {
  221. struct nlattr *nest;
  222. if (!dev)
  223. return 0;
  224. nest = nla_nest_start(skb, attrtype);
  225. if (!nest)
  226. return -EMSGSIZE;
  227. if (nla_put_u32(skb, ETHTOOL_A_HEADER_DEV_INDEX, (u32)dev->ifindex) ||
  228. nla_put_string(skb, ETHTOOL_A_HEADER_DEV_NAME, dev->name))
  229. goto nla_put_failure;
  230. /* If more attributes are put into reply header, ethnl_header_size()
  231. * must be updated to account for them.
  232. */
  233. nla_nest_end(skb, nest);
  234. return 0;
  235. nla_put_failure:
  236. nla_nest_cancel(skb, nest);
  237. return -EMSGSIZE;
  238. }
  239. /**
  240. * ethnl_reply_init() - Create skb for a reply and fill device identification
  241. * @payload: payload length (without netlink and genetlink header)
  242. * @dev: device the reply is about (may be null)
  243. * @cmd: ETHTOOL_MSG_* message type for reply
  244. * @hdr_attrtype: attribute type for common header
  245. * @info: genetlink info of the received packet we respond to
  246. * @ehdrp: place to store payload pointer returned by genlmsg_new()
  247. *
  248. * Return: pointer to allocated skb on success, NULL on error
  249. */
  250. struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,
  251. u16 hdr_attrtype, struct genl_info *info,
  252. void **ehdrp)
  253. {
  254. struct sk_buff *skb;
  255. skb = genlmsg_new(payload, GFP_KERNEL);
  256. if (!skb)
  257. goto err;
  258. *ehdrp = genlmsg_put_reply(skb, info, &ethtool_genl_family, 0, cmd);
  259. if (!*ehdrp)
  260. goto err_free;
  261. if (dev) {
  262. int ret;
  263. ret = ethnl_fill_reply_header(skb, dev, hdr_attrtype);
  264. if (ret < 0)
  265. goto err_free;
  266. }
  267. return skb;
  268. err_free:
  269. nlmsg_free(skb);
  270. err:
  271. if (info)
  272. GENL_SET_ERR_MSG(info, "failed to setup reply message");
  273. return NULL;
  274. }
  275. void *ethnl_dump_put(struct sk_buff *skb, struct netlink_callback *cb, u8 cmd)
  276. {
  277. return genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
  278. &ethtool_genl_family, 0, cmd);
  279. }
  280. void *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd)
  281. {
  282. return genlmsg_put(skb, 0, ++ethnl_bcast_seq, &ethtool_genl_family, 0,
  283. cmd);
  284. }
  285. void *ethnl_unicast_put(struct sk_buff *skb, u32 portid, u32 seq, u8 cmd)
  286. {
  287. return genlmsg_put(skb, portid, seq, &ethtool_genl_family, 0, cmd);
  288. }
  289. int ethnl_multicast(struct sk_buff *skb, struct net_device *dev)
  290. {
  291. return genlmsg_multicast_netns(&ethtool_genl_family, dev_net(dev), skb,
  292. 0, ETHNL_MCGRP_MONITOR, GFP_KERNEL);
  293. }
  294. /* GET request helpers */
  295. /**
  296. * struct ethnl_dump_ctx - context structure for generic dumpit() callback
  297. * @ops: request ops of currently processed message type
  298. * @req_info: parsed request header of processed request
  299. * @reply_data: data needed to compose the reply
  300. * @pos_ifindex: saved iteration position - ifindex
  301. *
  302. * These parameters are kept in struct netlink_callback as context preserved
  303. * between iterations. They are initialized by ethnl_default_start() and used
  304. * in ethnl_default_dumpit() and ethnl_default_done().
  305. */
  306. struct ethnl_dump_ctx {
  307. const struct ethnl_request_ops *ops;
  308. struct ethnl_req_info *req_info;
  309. struct ethnl_reply_data *reply_data;
  310. unsigned long pos_ifindex;
  311. };
  312. /**
  313. * struct ethnl_perphy_dump_ctx - context for dumpit() PHY-aware callbacks
  314. * @ethnl_ctx: generic ethnl context
  315. * @ifindex: For Filtered DUMP requests, the ifindex of the targeted netdev
  316. * @pos_phyindex: iterator position for multi-msg DUMP
  317. */
  318. struct ethnl_perphy_dump_ctx {
  319. struct ethnl_dump_ctx ethnl_ctx;
  320. unsigned int ifindex;
  321. unsigned long pos_phyindex;
  322. };
  323. static const struct ethnl_request_ops *
  324. ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
  325. [ETHTOOL_MSG_STRSET_GET] = &ethnl_strset_request_ops,
  326. [ETHTOOL_MSG_LINKINFO_GET] = &ethnl_linkinfo_request_ops,
  327. [ETHTOOL_MSG_LINKINFO_SET] = &ethnl_linkinfo_request_ops,
  328. [ETHTOOL_MSG_LINKMODES_GET] = &ethnl_linkmodes_request_ops,
  329. [ETHTOOL_MSG_LINKMODES_SET] = &ethnl_linkmodes_request_ops,
  330. [ETHTOOL_MSG_LINKSTATE_GET] = &ethnl_linkstate_request_ops,
  331. [ETHTOOL_MSG_DEBUG_GET] = &ethnl_debug_request_ops,
  332. [ETHTOOL_MSG_DEBUG_SET] = &ethnl_debug_request_ops,
  333. [ETHTOOL_MSG_WOL_GET] = &ethnl_wol_request_ops,
  334. [ETHTOOL_MSG_WOL_SET] = &ethnl_wol_request_ops,
  335. [ETHTOOL_MSG_FEATURES_GET] = &ethnl_features_request_ops,
  336. [ETHTOOL_MSG_PRIVFLAGS_GET] = &ethnl_privflags_request_ops,
  337. [ETHTOOL_MSG_PRIVFLAGS_SET] = &ethnl_privflags_request_ops,
  338. [ETHTOOL_MSG_RINGS_GET] = &ethnl_rings_request_ops,
  339. [ETHTOOL_MSG_RINGS_SET] = &ethnl_rings_request_ops,
  340. [ETHTOOL_MSG_CHANNELS_GET] = &ethnl_channels_request_ops,
  341. [ETHTOOL_MSG_CHANNELS_SET] = &ethnl_channels_request_ops,
  342. [ETHTOOL_MSG_COALESCE_GET] = &ethnl_coalesce_request_ops,
  343. [ETHTOOL_MSG_COALESCE_SET] = &ethnl_coalesce_request_ops,
  344. [ETHTOOL_MSG_PAUSE_GET] = &ethnl_pause_request_ops,
  345. [ETHTOOL_MSG_PAUSE_SET] = &ethnl_pause_request_ops,
  346. [ETHTOOL_MSG_EEE_GET] = &ethnl_eee_request_ops,
  347. [ETHTOOL_MSG_EEE_SET] = &ethnl_eee_request_ops,
  348. [ETHTOOL_MSG_FEC_GET] = &ethnl_fec_request_ops,
  349. [ETHTOOL_MSG_FEC_SET] = &ethnl_fec_request_ops,
  350. [ETHTOOL_MSG_TSINFO_GET] = &ethnl_tsinfo_request_ops,
  351. [ETHTOOL_MSG_MODULE_EEPROM_GET] = &ethnl_module_eeprom_request_ops,
  352. [ETHTOOL_MSG_STATS_GET] = &ethnl_stats_request_ops,
  353. [ETHTOOL_MSG_PHC_VCLOCKS_GET] = &ethnl_phc_vclocks_request_ops,
  354. [ETHTOOL_MSG_MODULE_GET] = &ethnl_module_request_ops,
  355. [ETHTOOL_MSG_MODULE_SET] = &ethnl_module_request_ops,
  356. [ETHTOOL_MSG_PSE_GET] = &ethnl_pse_request_ops,
  357. [ETHTOOL_MSG_PSE_SET] = &ethnl_pse_request_ops,
  358. [ETHTOOL_MSG_RSS_GET] = &ethnl_rss_request_ops,
  359. [ETHTOOL_MSG_RSS_SET] = &ethnl_rss_request_ops,
  360. [ETHTOOL_MSG_PLCA_GET_CFG] = &ethnl_plca_cfg_request_ops,
  361. [ETHTOOL_MSG_PLCA_SET_CFG] = &ethnl_plca_cfg_request_ops,
  362. [ETHTOOL_MSG_PLCA_GET_STATUS] = &ethnl_plca_status_request_ops,
  363. [ETHTOOL_MSG_MM_GET] = &ethnl_mm_request_ops,
  364. [ETHTOOL_MSG_MM_SET] = &ethnl_mm_request_ops,
  365. [ETHTOOL_MSG_TSCONFIG_GET] = &ethnl_tsconfig_request_ops,
  366. [ETHTOOL_MSG_TSCONFIG_SET] = &ethnl_tsconfig_request_ops,
  367. [ETHTOOL_MSG_PHY_GET] = &ethnl_phy_request_ops,
  368. [ETHTOOL_MSG_MSE_GET] = &ethnl_mse_request_ops,
  369. };
  370. static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
  371. {
  372. return (struct ethnl_dump_ctx *)cb->ctx;
  373. }
  374. static struct ethnl_perphy_dump_ctx *
  375. ethnl_perphy_dump_context(struct netlink_callback *cb)
  376. {
  377. return (struct ethnl_perphy_dump_ctx *)cb->ctx;
  378. }
  379. /**
  380. * ethnl_default_parse() - Parse request message
  381. * @req_info: pointer to structure to put data into
  382. * @info: genl_info from the request
  383. * @request_ops: struct request_ops for request type
  384. * @require_dev: fail if no device identified in header
  385. *
  386. * Parse universal request header and call request specific ->parse_request()
  387. * callback (if defined) to parse the rest of the message.
  388. *
  389. * Return: 0 on success or negative error code
  390. */
  391. static int ethnl_default_parse(struct ethnl_req_info *req_info,
  392. const struct genl_info *info,
  393. const struct ethnl_request_ops *request_ops,
  394. bool require_dev)
  395. {
  396. struct nlattr **tb = info->attrs;
  397. int ret;
  398. ret = ethnl_parse_header_dev_get(req_info, tb[request_ops->hdr_attr],
  399. genl_info_net(info), info->extack,
  400. require_dev);
  401. if (ret < 0)
  402. return ret;
  403. if (request_ops->parse_request) {
  404. ret = request_ops->parse_request(req_info, tb, info->extack);
  405. if (ret < 0)
  406. goto err_dev;
  407. }
  408. return 0;
  409. err_dev:
  410. netdev_put(req_info->dev, &req_info->dev_tracker);
  411. req_info->dev = NULL;
  412. return ret;
  413. }
  414. /**
  415. * ethnl_init_reply_data() - Initialize reply data for GET request
  416. * @reply_data: pointer to embedded struct ethnl_reply_data
  417. * @ops: instance of struct ethnl_request_ops describing the layout
  418. * @dev: network device to initialize the reply for
  419. *
  420. * Fills the reply data part with zeros and sets the dev member. Must be called
  421. * before calling the ->fill_reply() callback (for each iteration when handling
  422. * dump requests).
  423. */
  424. static void ethnl_init_reply_data(struct ethnl_reply_data *reply_data,
  425. const struct ethnl_request_ops *ops,
  426. struct net_device *dev)
  427. {
  428. memset(reply_data, 0, ops->reply_data_size);
  429. reply_data->dev = dev;
  430. }
  431. /* default ->doit() handler for GET type requests */
  432. static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)
  433. {
  434. struct ethnl_reply_data *reply_data = NULL;
  435. struct ethnl_req_info *req_info = NULL;
  436. const u8 cmd = info->genlhdr->cmd;
  437. const struct ethnl_request_ops *ops;
  438. int hdr_len, reply_len;
  439. struct sk_buff *rskb;
  440. void *reply_payload;
  441. int ret;
  442. ops = ethnl_default_requests[cmd];
  443. if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", cmd))
  444. return -EOPNOTSUPP;
  445. if (GENL_REQ_ATTR_CHECK(info, ops->hdr_attr))
  446. return -EINVAL;
  447. req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
  448. if (!req_info)
  449. return -ENOMEM;
  450. reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
  451. if (!reply_data) {
  452. kfree(req_info);
  453. return -ENOMEM;
  454. }
  455. ret = ethnl_default_parse(req_info, info, ops, !ops->allow_nodev_do);
  456. if (ret < 0)
  457. goto err_free;
  458. ethnl_init_reply_data(reply_data, ops, req_info->dev);
  459. rtnl_lock();
  460. if (req_info->dev)
  461. netdev_lock_ops(req_info->dev);
  462. ret = ops->prepare_data(req_info, reply_data, info);
  463. if (req_info->dev)
  464. netdev_unlock_ops(req_info->dev);
  465. rtnl_unlock();
  466. if (ret < 0)
  467. goto err_dev;
  468. ret = ops->reply_size(req_info, reply_data);
  469. if (ret < 0)
  470. goto err_cleanup;
  471. reply_len = ret;
  472. ret = -ENOMEM;
  473. rskb = ethnl_reply_init(reply_len + ethnl_reply_header_size(),
  474. req_info->dev, ops->reply_cmd,
  475. ops->hdr_attr, info, &reply_payload);
  476. if (!rskb)
  477. goto err_cleanup;
  478. hdr_len = rskb->len;
  479. ret = ops->fill_reply(rskb, req_info, reply_data);
  480. if (ret < 0)
  481. goto err_msg;
  482. WARN_ONCE(rskb->len - hdr_len > reply_len,
  483. "ethnl cmd %d: calculated reply length %d, but consumed %d\n",
  484. cmd, reply_len, rskb->len - hdr_len);
  485. if (ops->cleanup_data)
  486. ops->cleanup_data(reply_data);
  487. genlmsg_end(rskb, reply_payload);
  488. netdev_put(req_info->dev, &req_info->dev_tracker);
  489. kfree(reply_data);
  490. kfree(req_info);
  491. return genlmsg_reply(rskb, info);
  492. err_msg:
  493. WARN_ONCE(ret == -EMSGSIZE, "calculated message payload length (%d) not sufficient\n", reply_len);
  494. nlmsg_free(rskb);
  495. err_cleanup:
  496. if (ops->cleanup_data)
  497. ops->cleanup_data(reply_data);
  498. err_dev:
  499. netdev_put(req_info->dev, &req_info->dev_tracker);
  500. err_free:
  501. kfree(reply_data);
  502. kfree(req_info);
  503. return ret;
  504. }
  505. static int ethnl_default_dump_one(struct sk_buff *skb, struct net_device *dev,
  506. const struct ethnl_dump_ctx *ctx,
  507. const struct genl_info *info)
  508. {
  509. void *ehdr;
  510. int ret;
  511. ehdr = genlmsg_put(skb, info->snd_portid, info->snd_seq,
  512. &ethtool_genl_family, NLM_F_MULTI,
  513. ctx->ops->reply_cmd);
  514. if (!ehdr)
  515. return -EMSGSIZE;
  516. ethnl_init_reply_data(ctx->reply_data, ctx->ops, dev);
  517. rtnl_lock();
  518. netdev_lock_ops(dev);
  519. ret = ctx->ops->prepare_data(ctx->req_info, ctx->reply_data, info);
  520. netdev_unlock_ops(dev);
  521. rtnl_unlock();
  522. if (ret < 0)
  523. goto out_cancel;
  524. ret = ethnl_fill_reply_header(skb, dev, ctx->ops->hdr_attr);
  525. if (ret < 0)
  526. goto out;
  527. ret = ctx->ops->fill_reply(skb, ctx->req_info, ctx->reply_data);
  528. out:
  529. if (ctx->ops->cleanup_data)
  530. ctx->ops->cleanup_data(ctx->reply_data);
  531. out_cancel:
  532. ctx->reply_data->dev = NULL;
  533. if (ret < 0)
  534. genlmsg_cancel(skb, ehdr);
  535. else
  536. genlmsg_end(skb, ehdr);
  537. return ret;
  538. }
  539. /* Default ->dumpit() handler for GET requests. */
  540. static int ethnl_default_dumpit(struct sk_buff *skb,
  541. struct netlink_callback *cb)
  542. {
  543. struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
  544. struct net *net = sock_net(skb->sk);
  545. netdevice_tracker dev_tracker;
  546. struct net_device *dev;
  547. int ret = 0;
  548. rcu_read_lock();
  549. for_each_netdev_dump(net, dev, ctx->pos_ifindex) {
  550. netdev_hold(dev, &dev_tracker, GFP_ATOMIC);
  551. rcu_read_unlock();
  552. ret = ethnl_default_dump_one(skb, dev, ctx, genl_info_dump(cb));
  553. rcu_read_lock();
  554. netdev_put(dev, &dev_tracker);
  555. if (ret < 0 && ret != -EOPNOTSUPP) {
  556. if (likely(skb->len))
  557. ret = skb->len;
  558. break;
  559. }
  560. ret = 0;
  561. }
  562. rcu_read_unlock();
  563. return ret;
  564. }
  565. /* generic ->start() handler for GET requests */
  566. static int ethnl_default_start(struct netlink_callback *cb)
  567. {
  568. const struct genl_dumpit_info *info = genl_dumpit_info(cb);
  569. struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
  570. struct ethnl_reply_data *reply_data;
  571. const struct ethnl_request_ops *ops;
  572. struct ethnl_req_info *req_info;
  573. struct genlmsghdr *ghdr;
  574. int ret;
  575. BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx));
  576. ghdr = nlmsg_data(cb->nlh);
  577. ops = ethnl_default_requests[ghdr->cmd];
  578. if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", ghdr->cmd))
  579. return -EOPNOTSUPP;
  580. req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
  581. if (!req_info)
  582. return -ENOMEM;
  583. reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
  584. if (!reply_data) {
  585. ret = -ENOMEM;
  586. goto free_req_info;
  587. }
  588. ret = ethnl_default_parse(req_info, &info->info, ops, false);
  589. if (ret < 0)
  590. goto free_reply_data;
  591. if (req_info->dev) {
  592. /* We ignore device specification in dump requests but as the
  593. * same parser as for non-dump (doit) requests is used, it
  594. * would take reference to the device if it finds one
  595. */
  596. netdev_put(req_info->dev, &req_info->dev_tracker);
  597. req_info->dev = NULL;
  598. }
  599. ctx->ops = ops;
  600. ctx->req_info = req_info;
  601. ctx->reply_data = reply_data;
  602. ctx->pos_ifindex = 0;
  603. return 0;
  604. free_reply_data:
  605. kfree(reply_data);
  606. free_req_info:
  607. kfree(req_info);
  608. return ret;
  609. }
  610. /* per-PHY ->start() handler for GET requests */
  611. static int ethnl_perphy_start(struct netlink_callback *cb)
  612. {
  613. struct ethnl_perphy_dump_ctx *phy_ctx = ethnl_perphy_dump_context(cb);
  614. const struct genl_dumpit_info *info = genl_dumpit_info(cb);
  615. struct ethnl_dump_ctx *ctx = &phy_ctx->ethnl_ctx;
  616. struct ethnl_reply_data *reply_data;
  617. const struct ethnl_request_ops *ops;
  618. struct ethnl_req_info *req_info;
  619. struct genlmsghdr *ghdr;
  620. int ret;
  621. BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx));
  622. ghdr = nlmsg_data(cb->nlh);
  623. ops = ethnl_default_requests[ghdr->cmd];
  624. if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", ghdr->cmd))
  625. return -EOPNOTSUPP;
  626. req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
  627. if (!req_info)
  628. return -ENOMEM;
  629. reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
  630. if (!reply_data) {
  631. ret = -ENOMEM;
  632. goto free_req_info;
  633. }
  634. /* Unlike per-dev dump, don't ignore dev. The dump handler
  635. * will notice it and dump PHYs from given dev. We only keep track of
  636. * the dev's ifindex, .dumpit() will grab and release the netdev itself.
  637. */
  638. ret = ethnl_default_parse(req_info, &info->info, ops, false);
  639. if (ret < 0)
  640. goto free_reply_data;
  641. if (req_info->dev) {
  642. phy_ctx->ifindex = req_info->dev->ifindex;
  643. netdev_put(req_info->dev, &req_info->dev_tracker);
  644. req_info->dev = NULL;
  645. }
  646. ctx->ops = ops;
  647. ctx->req_info = req_info;
  648. ctx->reply_data = reply_data;
  649. ctx->pos_ifindex = 0;
  650. return 0;
  651. free_reply_data:
  652. kfree(reply_data);
  653. free_req_info:
  654. kfree(req_info);
  655. return ret;
  656. }
  657. static int ethnl_perphy_dump_one_dev(struct sk_buff *skb,
  658. struct ethnl_perphy_dump_ctx *ctx,
  659. const struct genl_info *info)
  660. {
  661. struct ethnl_dump_ctx *ethnl_ctx = &ctx->ethnl_ctx;
  662. struct net_device *dev = ethnl_ctx->req_info->dev;
  663. struct phy_device_node *pdn;
  664. int ret;
  665. if (!dev->link_topo)
  666. return 0;
  667. xa_for_each_start(&dev->link_topo->phys, ctx->pos_phyindex, pdn,
  668. ctx->pos_phyindex) {
  669. ethnl_ctx->req_info->phy_index = ctx->pos_phyindex;
  670. /* We can re-use the original dump_one as ->prepare_data in
  671. * commands use ethnl_req_get_phydev(), which gets the PHY from
  672. * the req_info->phy_index
  673. */
  674. ret = ethnl_default_dump_one(skb, dev, ethnl_ctx, info);
  675. if (ret)
  676. return ret;
  677. }
  678. ctx->pos_phyindex = 0;
  679. return 0;
  680. }
  681. static int ethnl_perphy_dump_all_dev(struct sk_buff *skb,
  682. struct ethnl_perphy_dump_ctx *ctx,
  683. const struct genl_info *info)
  684. {
  685. struct ethnl_dump_ctx *ethnl_ctx = &ctx->ethnl_ctx;
  686. struct net *net = sock_net(skb->sk);
  687. netdevice_tracker dev_tracker;
  688. struct net_device *dev;
  689. int ret = 0;
  690. rcu_read_lock();
  691. for_each_netdev_dump(net, dev, ethnl_ctx->pos_ifindex) {
  692. netdev_hold(dev, &dev_tracker, GFP_ATOMIC);
  693. rcu_read_unlock();
  694. /* per-PHY commands use ethnl_req_get_phydev(), which needs the
  695. * net_device in the req_info
  696. */
  697. ethnl_ctx->req_info->dev = dev;
  698. ret = ethnl_perphy_dump_one_dev(skb, ctx, info);
  699. rcu_read_lock();
  700. netdev_put(dev, &dev_tracker);
  701. ethnl_ctx->req_info->dev = NULL;
  702. if (ret < 0 && ret != -EOPNOTSUPP) {
  703. if (likely(skb->len))
  704. ret = skb->len;
  705. break;
  706. }
  707. ret = 0;
  708. }
  709. rcu_read_unlock();
  710. return ret;
  711. }
  712. /* per-PHY ->dumpit() handler for GET requests. */
  713. static int ethnl_perphy_dumpit(struct sk_buff *skb,
  714. struct netlink_callback *cb)
  715. {
  716. struct ethnl_perphy_dump_ctx *ctx = ethnl_perphy_dump_context(cb);
  717. const struct genl_dumpit_info *info = genl_dumpit_info(cb);
  718. struct ethnl_dump_ctx *ethnl_ctx = &ctx->ethnl_ctx;
  719. int ret = 0;
  720. if (ctx->ifindex) {
  721. netdevice_tracker dev_tracker;
  722. struct net_device *dev;
  723. dev = netdev_get_by_index(genl_info_net(&info->info),
  724. ctx->ifindex, &dev_tracker,
  725. GFP_KERNEL);
  726. if (!dev)
  727. return -ENODEV;
  728. ethnl_ctx->req_info->dev = dev;
  729. ret = ethnl_perphy_dump_one_dev(skb, ctx, genl_info_dump(cb));
  730. if (ret < 0 && ret != -EOPNOTSUPP && likely(skb->len))
  731. ret = skb->len;
  732. netdev_put(dev, &dev_tracker);
  733. } else {
  734. ret = ethnl_perphy_dump_all_dev(skb, ctx, genl_info_dump(cb));
  735. }
  736. return ret;
  737. }
  738. /* per-PHY ->done() handler for GET requests */
  739. static int ethnl_perphy_done(struct netlink_callback *cb)
  740. {
  741. struct ethnl_perphy_dump_ctx *ctx = ethnl_perphy_dump_context(cb);
  742. struct ethnl_dump_ctx *ethnl_ctx = &ctx->ethnl_ctx;
  743. kfree(ethnl_ctx->reply_data);
  744. kfree(ethnl_ctx->req_info);
  745. return 0;
  746. }
  747. /* default ->done() handler for GET requests */
  748. static int ethnl_default_done(struct netlink_callback *cb)
  749. {
  750. struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
  751. kfree(ctx->reply_data);
  752. kfree(ctx->req_info);
  753. return 0;
  754. }
  755. static int ethnl_default_set_doit(struct sk_buff *skb, struct genl_info *info)
  756. {
  757. const struct ethnl_request_ops *ops;
  758. const u8 cmd = info->genlhdr->cmd;
  759. struct ethnl_req_info *req_info;
  760. struct net_device *dev;
  761. int ret;
  762. ops = ethnl_default_requests[cmd];
  763. if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", cmd))
  764. return -EOPNOTSUPP;
  765. if (GENL_REQ_ATTR_CHECK(info, ops->hdr_attr))
  766. return -EINVAL;
  767. req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
  768. if (!req_info)
  769. return -ENOMEM;
  770. ret = ethnl_default_parse(req_info, info, ops, true);
  771. if (ret < 0)
  772. goto out_free_req;
  773. if (ops->set_validate) {
  774. ret = ops->set_validate(req_info, info);
  775. /* 0 means nothing to do */
  776. if (ret <= 0)
  777. goto out_dev;
  778. }
  779. dev = req_info->dev;
  780. rtnl_lock();
  781. netdev_lock_ops(dev);
  782. dev->cfg_pending = kmemdup(dev->cfg, sizeof(*dev->cfg),
  783. GFP_KERNEL_ACCOUNT);
  784. if (!dev->cfg_pending) {
  785. ret = -ENOMEM;
  786. goto out_tie_cfg;
  787. }
  788. ret = ethnl_ops_begin(dev);
  789. if (ret < 0)
  790. goto out_free_cfg;
  791. ret = ops->set(req_info, info);
  792. if (ret < 0)
  793. goto out_ops;
  794. swap(dev->cfg, dev->cfg_pending);
  795. if (!ret)
  796. goto out_ops;
  797. ethnl_notify(dev, ops->set_ntf_cmd, req_info);
  798. ret = 0;
  799. out_ops:
  800. ethnl_ops_complete(dev);
  801. out_free_cfg:
  802. kfree(dev->cfg_pending);
  803. out_tie_cfg:
  804. dev->cfg_pending = dev->cfg;
  805. netdev_unlock_ops(dev);
  806. rtnl_unlock();
  807. out_dev:
  808. ethnl_parse_header_dev_put(req_info);
  809. out_free_req:
  810. kfree(req_info);
  811. return ret;
  812. }
  813. static const struct ethnl_request_ops *
  814. ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = {
  815. [ETHTOOL_MSG_LINKINFO_NTF] = &ethnl_linkinfo_request_ops,
  816. [ETHTOOL_MSG_LINKMODES_NTF] = &ethnl_linkmodes_request_ops,
  817. [ETHTOOL_MSG_DEBUG_NTF] = &ethnl_debug_request_ops,
  818. [ETHTOOL_MSG_WOL_NTF] = &ethnl_wol_request_ops,
  819. [ETHTOOL_MSG_FEATURES_NTF] = &ethnl_features_request_ops,
  820. [ETHTOOL_MSG_PRIVFLAGS_NTF] = &ethnl_privflags_request_ops,
  821. [ETHTOOL_MSG_RINGS_NTF] = &ethnl_rings_request_ops,
  822. [ETHTOOL_MSG_CHANNELS_NTF] = &ethnl_channels_request_ops,
  823. [ETHTOOL_MSG_COALESCE_NTF] = &ethnl_coalesce_request_ops,
  824. [ETHTOOL_MSG_PAUSE_NTF] = &ethnl_pause_request_ops,
  825. [ETHTOOL_MSG_EEE_NTF] = &ethnl_eee_request_ops,
  826. [ETHTOOL_MSG_FEC_NTF] = &ethnl_fec_request_ops,
  827. [ETHTOOL_MSG_MODULE_NTF] = &ethnl_module_request_ops,
  828. [ETHTOOL_MSG_PLCA_NTF] = &ethnl_plca_cfg_request_ops,
  829. [ETHTOOL_MSG_MM_NTF] = &ethnl_mm_request_ops,
  830. [ETHTOOL_MSG_RSS_NTF] = &ethnl_rss_request_ops,
  831. [ETHTOOL_MSG_RSS_CREATE_NTF] = &ethnl_rss_request_ops,
  832. };
  833. /* default notification handler */
  834. static void ethnl_default_notify(struct net_device *dev, unsigned int cmd,
  835. const struct ethnl_req_info *orig_req_info)
  836. {
  837. struct ethnl_reply_data *reply_data;
  838. const struct ethnl_request_ops *ops;
  839. struct ethnl_req_info *req_info;
  840. struct genl_info info;
  841. struct sk_buff *skb;
  842. void *reply_payload;
  843. int reply_len;
  844. int ret;
  845. genl_info_init_ntf(&info, &ethtool_genl_family, cmd);
  846. if (WARN_ONCE(cmd > ETHTOOL_MSG_KERNEL_MAX ||
  847. !ethnl_default_notify_ops[cmd],
  848. "unexpected notification type %u\n", cmd))
  849. return;
  850. ops = ethnl_default_notify_ops[cmd];
  851. req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
  852. if (!req_info)
  853. return;
  854. reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
  855. if (!reply_data) {
  856. kfree(req_info);
  857. return;
  858. }
  859. req_info->dev = dev;
  860. req_info->flags |= ETHTOOL_FLAG_COMPACT_BITSETS;
  861. if (orig_req_info) {
  862. req_info->phy_index = orig_req_info->phy_index;
  863. memcpy(&req_info[1], &orig_req_info[1],
  864. ops->req_info_size - sizeof(*req_info));
  865. }
  866. netdev_ops_assert_locked(dev);
  867. ethnl_init_reply_data(reply_data, ops, dev);
  868. ret = ops->prepare_data(req_info, reply_data, &info);
  869. if (ret < 0)
  870. goto err_rep;
  871. ret = ops->reply_size(req_info, reply_data);
  872. if (ret < 0)
  873. goto err_cleanup;
  874. reply_len = ret + ethnl_reply_header_size();
  875. skb = genlmsg_new(reply_len, GFP_KERNEL);
  876. if (!skb)
  877. goto err_cleanup;
  878. reply_payload = ethnl_bcastmsg_put(skb, cmd);
  879. if (!reply_payload)
  880. goto err_skb;
  881. ret = ethnl_fill_reply_header(skb, dev, ops->hdr_attr);
  882. if (ret < 0)
  883. goto err_msg;
  884. ret = ops->fill_reply(skb, req_info, reply_data);
  885. if (ret < 0)
  886. goto err_msg;
  887. if (ops->cleanup_data)
  888. ops->cleanup_data(reply_data);
  889. genlmsg_end(skb, reply_payload);
  890. kfree(reply_data);
  891. kfree(req_info);
  892. ethnl_multicast(skb, dev);
  893. return;
  894. err_msg:
  895. WARN_ONCE(ret == -EMSGSIZE,
  896. "calculated message payload length (%d) not sufficient\n",
  897. reply_len);
  898. err_skb:
  899. nlmsg_free(skb);
  900. err_cleanup:
  901. if (ops->cleanup_data)
  902. ops->cleanup_data(reply_data);
  903. err_rep:
  904. kfree(reply_data);
  905. kfree(req_info);
  906. return;
  907. }
  908. /* notifications */
  909. typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd,
  910. const struct ethnl_req_info *req_info);
  911. static const ethnl_notify_handler_t ethnl_notify_handlers[] = {
  912. [ETHTOOL_MSG_LINKINFO_NTF] = ethnl_default_notify,
  913. [ETHTOOL_MSG_LINKMODES_NTF] = ethnl_default_notify,
  914. [ETHTOOL_MSG_DEBUG_NTF] = ethnl_default_notify,
  915. [ETHTOOL_MSG_WOL_NTF] = ethnl_default_notify,
  916. [ETHTOOL_MSG_FEATURES_NTF] = ethnl_default_notify,
  917. [ETHTOOL_MSG_PRIVFLAGS_NTF] = ethnl_default_notify,
  918. [ETHTOOL_MSG_RINGS_NTF] = ethnl_default_notify,
  919. [ETHTOOL_MSG_CHANNELS_NTF] = ethnl_default_notify,
  920. [ETHTOOL_MSG_COALESCE_NTF] = ethnl_default_notify,
  921. [ETHTOOL_MSG_PAUSE_NTF] = ethnl_default_notify,
  922. [ETHTOOL_MSG_EEE_NTF] = ethnl_default_notify,
  923. [ETHTOOL_MSG_FEC_NTF] = ethnl_default_notify,
  924. [ETHTOOL_MSG_MODULE_NTF] = ethnl_default_notify,
  925. [ETHTOOL_MSG_PLCA_NTF] = ethnl_default_notify,
  926. [ETHTOOL_MSG_MM_NTF] = ethnl_default_notify,
  927. [ETHTOOL_MSG_RSS_NTF] = ethnl_default_notify,
  928. [ETHTOOL_MSG_RSS_CREATE_NTF] = ethnl_default_notify,
  929. };
  930. void ethnl_notify(struct net_device *dev, unsigned int cmd,
  931. const struct ethnl_req_info *req_info)
  932. {
  933. if (unlikely(!ethnl_ok))
  934. return;
  935. ASSERT_RTNL();
  936. if (likely(cmd < ARRAY_SIZE(ethnl_notify_handlers) &&
  937. ethnl_notify_handlers[cmd]))
  938. ethnl_notify_handlers[cmd](dev, cmd, req_info);
  939. else
  940. WARN_ONCE(1, "notification %u not implemented (dev=%s)\n",
  941. cmd, netdev_name(dev));
  942. }
  943. void ethtool_notify(struct net_device *dev, unsigned int cmd)
  944. {
  945. ethnl_notify(dev, cmd, NULL);
  946. }
  947. EXPORT_SYMBOL(ethtool_notify);
  948. static void ethnl_notify_features(struct netdev_notifier_info *info)
  949. {
  950. struct net_device *dev = netdev_notifier_info_to_dev(info);
  951. ethtool_notify(dev, ETHTOOL_MSG_FEATURES_NTF);
  952. }
  953. static int ethnl_netdev_event(struct notifier_block *this, unsigned long event,
  954. void *ptr)
  955. {
  956. struct netdev_notifier_info *info = ptr;
  957. struct netlink_ext_ack *extack;
  958. struct net_device *dev;
  959. dev = netdev_notifier_info_to_dev(info);
  960. extack = netdev_notifier_info_to_extack(info);
  961. switch (event) {
  962. case NETDEV_FEAT_CHANGE:
  963. ethnl_notify_features(ptr);
  964. break;
  965. case NETDEV_PRE_UP:
  966. if (dev->ethtool->module_fw_flash_in_progress) {
  967. NL_SET_ERR_MSG(extack, "Can't set port up while flashing module firmware");
  968. return NOTIFY_BAD;
  969. }
  970. }
  971. return NOTIFY_DONE;
  972. }
  973. static struct notifier_block ethnl_netdev_notifier = {
  974. .notifier_call = ethnl_netdev_event,
  975. };
  976. /* genetlink setup */
  977. static const struct genl_ops ethtool_genl_ops[] = {
  978. {
  979. .cmd = ETHTOOL_MSG_STRSET_GET,
  980. .doit = ethnl_default_doit,
  981. .start = ethnl_default_start,
  982. .dumpit = ethnl_default_dumpit,
  983. .done = ethnl_default_done,
  984. .policy = ethnl_strset_get_policy,
  985. .maxattr = ARRAY_SIZE(ethnl_strset_get_policy) - 1,
  986. },
  987. {
  988. .cmd = ETHTOOL_MSG_LINKINFO_GET,
  989. .doit = ethnl_default_doit,
  990. .start = ethnl_default_start,
  991. .dumpit = ethnl_default_dumpit,
  992. .done = ethnl_default_done,
  993. .policy = ethnl_linkinfo_get_policy,
  994. .maxattr = ARRAY_SIZE(ethnl_linkinfo_get_policy) - 1,
  995. },
  996. {
  997. .cmd = ETHTOOL_MSG_LINKINFO_SET,
  998. .flags = GENL_UNS_ADMIN_PERM,
  999. .doit = ethnl_default_set_doit,
  1000. .policy = ethnl_linkinfo_set_policy,
  1001. .maxattr = ARRAY_SIZE(ethnl_linkinfo_set_policy) - 1,
  1002. },
  1003. {
  1004. .cmd = ETHTOOL_MSG_LINKMODES_GET,
  1005. .doit = ethnl_default_doit,
  1006. .start = ethnl_default_start,
  1007. .dumpit = ethnl_default_dumpit,
  1008. .done = ethnl_default_done,
  1009. .policy = ethnl_linkmodes_get_policy,
  1010. .maxattr = ARRAY_SIZE(ethnl_linkmodes_get_policy) - 1,
  1011. },
  1012. {
  1013. .cmd = ETHTOOL_MSG_LINKMODES_SET,
  1014. .flags = GENL_UNS_ADMIN_PERM,
  1015. .doit = ethnl_default_set_doit,
  1016. .policy = ethnl_linkmodes_set_policy,
  1017. .maxattr = ARRAY_SIZE(ethnl_linkmodes_set_policy) - 1,
  1018. },
  1019. {
  1020. .cmd = ETHTOOL_MSG_LINKSTATE_GET,
  1021. .doit = ethnl_default_doit,
  1022. .start = ethnl_default_start,
  1023. .dumpit = ethnl_default_dumpit,
  1024. .done = ethnl_default_done,
  1025. .policy = ethnl_linkstate_get_policy,
  1026. .maxattr = ARRAY_SIZE(ethnl_linkstate_get_policy) - 1,
  1027. },
  1028. {
  1029. .cmd = ETHTOOL_MSG_DEBUG_GET,
  1030. .doit = ethnl_default_doit,
  1031. .start = ethnl_default_start,
  1032. .dumpit = ethnl_default_dumpit,
  1033. .done = ethnl_default_done,
  1034. .policy = ethnl_debug_get_policy,
  1035. .maxattr = ARRAY_SIZE(ethnl_debug_get_policy) - 1,
  1036. },
  1037. {
  1038. .cmd = ETHTOOL_MSG_DEBUG_SET,
  1039. .flags = GENL_UNS_ADMIN_PERM,
  1040. .doit = ethnl_default_set_doit,
  1041. .policy = ethnl_debug_set_policy,
  1042. .maxattr = ARRAY_SIZE(ethnl_debug_set_policy) - 1,
  1043. },
  1044. {
  1045. .cmd = ETHTOOL_MSG_WOL_GET,
  1046. .flags = GENL_UNS_ADMIN_PERM,
  1047. .doit = ethnl_default_doit,
  1048. .start = ethnl_default_start,
  1049. .dumpit = ethnl_default_dumpit,
  1050. .done = ethnl_default_done,
  1051. .policy = ethnl_wol_get_policy,
  1052. .maxattr = ARRAY_SIZE(ethnl_wol_get_policy) - 1,
  1053. },
  1054. {
  1055. .cmd = ETHTOOL_MSG_WOL_SET,
  1056. .flags = GENL_UNS_ADMIN_PERM,
  1057. .doit = ethnl_default_set_doit,
  1058. .policy = ethnl_wol_set_policy,
  1059. .maxattr = ARRAY_SIZE(ethnl_wol_set_policy) - 1,
  1060. },
  1061. {
  1062. .cmd = ETHTOOL_MSG_FEATURES_GET,
  1063. .doit = ethnl_default_doit,
  1064. .start = ethnl_default_start,
  1065. .dumpit = ethnl_default_dumpit,
  1066. .done = ethnl_default_done,
  1067. .policy = ethnl_features_get_policy,
  1068. .maxattr = ARRAY_SIZE(ethnl_features_get_policy) - 1,
  1069. },
  1070. {
  1071. .cmd = ETHTOOL_MSG_FEATURES_SET,
  1072. .flags = GENL_UNS_ADMIN_PERM,
  1073. .doit = ethnl_set_features,
  1074. .policy = ethnl_features_set_policy,
  1075. .maxattr = ARRAY_SIZE(ethnl_features_set_policy) - 1,
  1076. },
  1077. {
  1078. .cmd = ETHTOOL_MSG_PRIVFLAGS_GET,
  1079. .doit = ethnl_default_doit,
  1080. .start = ethnl_default_start,
  1081. .dumpit = ethnl_default_dumpit,
  1082. .done = ethnl_default_done,
  1083. .policy = ethnl_privflags_get_policy,
  1084. .maxattr = ARRAY_SIZE(ethnl_privflags_get_policy) - 1,
  1085. },
  1086. {
  1087. .cmd = ETHTOOL_MSG_PRIVFLAGS_SET,
  1088. .flags = GENL_UNS_ADMIN_PERM,
  1089. .doit = ethnl_default_set_doit,
  1090. .policy = ethnl_privflags_set_policy,
  1091. .maxattr = ARRAY_SIZE(ethnl_privflags_set_policy) - 1,
  1092. },
  1093. {
  1094. .cmd = ETHTOOL_MSG_RINGS_GET,
  1095. .doit = ethnl_default_doit,
  1096. .start = ethnl_default_start,
  1097. .dumpit = ethnl_default_dumpit,
  1098. .done = ethnl_default_done,
  1099. .policy = ethnl_rings_get_policy,
  1100. .maxattr = ARRAY_SIZE(ethnl_rings_get_policy) - 1,
  1101. },
  1102. {
  1103. .cmd = ETHTOOL_MSG_RINGS_SET,
  1104. .flags = GENL_UNS_ADMIN_PERM,
  1105. .doit = ethnl_default_set_doit,
  1106. .policy = ethnl_rings_set_policy,
  1107. .maxattr = ARRAY_SIZE(ethnl_rings_set_policy) - 1,
  1108. },
  1109. {
  1110. .cmd = ETHTOOL_MSG_CHANNELS_GET,
  1111. .doit = ethnl_default_doit,
  1112. .start = ethnl_default_start,
  1113. .dumpit = ethnl_default_dumpit,
  1114. .done = ethnl_default_done,
  1115. .policy = ethnl_channels_get_policy,
  1116. .maxattr = ARRAY_SIZE(ethnl_channels_get_policy) - 1,
  1117. },
  1118. {
  1119. .cmd = ETHTOOL_MSG_CHANNELS_SET,
  1120. .flags = GENL_UNS_ADMIN_PERM,
  1121. .doit = ethnl_default_set_doit,
  1122. .policy = ethnl_channels_set_policy,
  1123. .maxattr = ARRAY_SIZE(ethnl_channels_set_policy) - 1,
  1124. },
  1125. {
  1126. .cmd = ETHTOOL_MSG_COALESCE_GET,
  1127. .doit = ethnl_default_doit,
  1128. .start = ethnl_default_start,
  1129. .dumpit = ethnl_default_dumpit,
  1130. .done = ethnl_default_done,
  1131. .policy = ethnl_coalesce_get_policy,
  1132. .maxattr = ARRAY_SIZE(ethnl_coalesce_get_policy) - 1,
  1133. },
  1134. {
  1135. .cmd = ETHTOOL_MSG_COALESCE_SET,
  1136. .flags = GENL_UNS_ADMIN_PERM,
  1137. .doit = ethnl_default_set_doit,
  1138. .policy = ethnl_coalesce_set_policy,
  1139. .maxattr = ARRAY_SIZE(ethnl_coalesce_set_policy) - 1,
  1140. },
  1141. {
  1142. .cmd = ETHTOOL_MSG_PAUSE_GET,
  1143. .doit = ethnl_default_doit,
  1144. .start = ethnl_default_start,
  1145. .dumpit = ethnl_default_dumpit,
  1146. .done = ethnl_default_done,
  1147. .policy = ethnl_pause_get_policy,
  1148. .maxattr = ARRAY_SIZE(ethnl_pause_get_policy) - 1,
  1149. },
  1150. {
  1151. .cmd = ETHTOOL_MSG_PAUSE_SET,
  1152. .flags = GENL_UNS_ADMIN_PERM,
  1153. .doit = ethnl_default_set_doit,
  1154. .policy = ethnl_pause_set_policy,
  1155. .maxattr = ARRAY_SIZE(ethnl_pause_set_policy) - 1,
  1156. },
  1157. {
  1158. .cmd = ETHTOOL_MSG_EEE_GET,
  1159. .doit = ethnl_default_doit,
  1160. .start = ethnl_default_start,
  1161. .dumpit = ethnl_default_dumpit,
  1162. .done = ethnl_default_done,
  1163. .policy = ethnl_eee_get_policy,
  1164. .maxattr = ARRAY_SIZE(ethnl_eee_get_policy) - 1,
  1165. },
  1166. {
  1167. .cmd = ETHTOOL_MSG_EEE_SET,
  1168. .flags = GENL_UNS_ADMIN_PERM,
  1169. .doit = ethnl_default_set_doit,
  1170. .policy = ethnl_eee_set_policy,
  1171. .maxattr = ARRAY_SIZE(ethnl_eee_set_policy) - 1,
  1172. },
  1173. {
  1174. .cmd = ETHTOOL_MSG_TSINFO_GET,
  1175. .doit = ethnl_default_doit,
  1176. .start = ethnl_tsinfo_start,
  1177. .dumpit = ethnl_tsinfo_dumpit,
  1178. .done = ethnl_tsinfo_done,
  1179. .policy = ethnl_tsinfo_get_policy,
  1180. .maxattr = ARRAY_SIZE(ethnl_tsinfo_get_policy) - 1,
  1181. },
  1182. {
  1183. .cmd = ETHTOOL_MSG_CABLE_TEST_ACT,
  1184. .flags = GENL_UNS_ADMIN_PERM,
  1185. .doit = ethnl_act_cable_test,
  1186. .policy = ethnl_cable_test_act_policy,
  1187. .maxattr = ARRAY_SIZE(ethnl_cable_test_act_policy) - 1,
  1188. },
  1189. {
  1190. .cmd = ETHTOOL_MSG_CABLE_TEST_TDR_ACT,
  1191. .flags = GENL_UNS_ADMIN_PERM,
  1192. .doit = ethnl_act_cable_test_tdr,
  1193. .policy = ethnl_cable_test_tdr_act_policy,
  1194. .maxattr = ARRAY_SIZE(ethnl_cable_test_tdr_act_policy) - 1,
  1195. },
  1196. {
  1197. .cmd = ETHTOOL_MSG_TUNNEL_INFO_GET,
  1198. .doit = ethnl_tunnel_info_doit,
  1199. .start = ethnl_tunnel_info_start,
  1200. .dumpit = ethnl_tunnel_info_dumpit,
  1201. .policy = ethnl_tunnel_info_get_policy,
  1202. .maxattr = ARRAY_SIZE(ethnl_tunnel_info_get_policy) - 1,
  1203. },
  1204. {
  1205. .cmd = ETHTOOL_MSG_FEC_GET,
  1206. .doit = ethnl_default_doit,
  1207. .start = ethnl_default_start,
  1208. .dumpit = ethnl_default_dumpit,
  1209. .done = ethnl_default_done,
  1210. .policy = ethnl_fec_get_policy,
  1211. .maxattr = ARRAY_SIZE(ethnl_fec_get_policy) - 1,
  1212. },
  1213. {
  1214. .cmd = ETHTOOL_MSG_FEC_SET,
  1215. .flags = GENL_UNS_ADMIN_PERM,
  1216. .doit = ethnl_default_set_doit,
  1217. .policy = ethnl_fec_set_policy,
  1218. .maxattr = ARRAY_SIZE(ethnl_fec_set_policy) - 1,
  1219. },
  1220. {
  1221. .cmd = ETHTOOL_MSG_MODULE_EEPROM_GET,
  1222. .flags = GENL_UNS_ADMIN_PERM,
  1223. .doit = ethnl_default_doit,
  1224. .start = ethnl_default_start,
  1225. .dumpit = ethnl_default_dumpit,
  1226. .done = ethnl_default_done,
  1227. .policy = ethnl_module_eeprom_get_policy,
  1228. .maxattr = ARRAY_SIZE(ethnl_module_eeprom_get_policy) - 1,
  1229. },
  1230. {
  1231. .cmd = ETHTOOL_MSG_STATS_GET,
  1232. .doit = ethnl_default_doit,
  1233. .start = ethnl_default_start,
  1234. .dumpit = ethnl_default_dumpit,
  1235. .done = ethnl_default_done,
  1236. .policy = ethnl_stats_get_policy,
  1237. .maxattr = ARRAY_SIZE(ethnl_stats_get_policy) - 1,
  1238. },
  1239. {
  1240. .cmd = ETHTOOL_MSG_PHC_VCLOCKS_GET,
  1241. .doit = ethnl_default_doit,
  1242. .start = ethnl_default_start,
  1243. .dumpit = ethnl_default_dumpit,
  1244. .done = ethnl_default_done,
  1245. .policy = ethnl_phc_vclocks_get_policy,
  1246. .maxattr = ARRAY_SIZE(ethnl_phc_vclocks_get_policy) - 1,
  1247. },
  1248. {
  1249. .cmd = ETHTOOL_MSG_MODULE_GET,
  1250. .doit = ethnl_default_doit,
  1251. .start = ethnl_default_start,
  1252. .dumpit = ethnl_default_dumpit,
  1253. .done = ethnl_default_done,
  1254. .policy = ethnl_module_get_policy,
  1255. .maxattr = ARRAY_SIZE(ethnl_module_get_policy) - 1,
  1256. },
  1257. {
  1258. .cmd = ETHTOOL_MSG_MODULE_SET,
  1259. .flags = GENL_UNS_ADMIN_PERM,
  1260. .doit = ethnl_default_set_doit,
  1261. .policy = ethnl_module_set_policy,
  1262. .maxattr = ARRAY_SIZE(ethnl_module_set_policy) - 1,
  1263. },
  1264. {
  1265. .cmd = ETHTOOL_MSG_PSE_GET,
  1266. .doit = ethnl_default_doit,
  1267. .start = ethnl_perphy_start,
  1268. .dumpit = ethnl_perphy_dumpit,
  1269. .done = ethnl_perphy_done,
  1270. .policy = ethnl_pse_get_policy,
  1271. .maxattr = ARRAY_SIZE(ethnl_pse_get_policy) - 1,
  1272. },
  1273. {
  1274. .cmd = ETHTOOL_MSG_PSE_SET,
  1275. .flags = GENL_UNS_ADMIN_PERM,
  1276. .doit = ethnl_default_set_doit,
  1277. .policy = ethnl_pse_set_policy,
  1278. .maxattr = ARRAY_SIZE(ethnl_pse_set_policy) - 1,
  1279. },
  1280. {
  1281. .cmd = ETHTOOL_MSG_RSS_GET,
  1282. .doit = ethnl_default_doit,
  1283. .start = ethnl_rss_dump_start,
  1284. .dumpit = ethnl_rss_dumpit,
  1285. .policy = ethnl_rss_get_policy,
  1286. .maxattr = ARRAY_SIZE(ethnl_rss_get_policy) - 1,
  1287. },
  1288. {
  1289. .cmd = ETHTOOL_MSG_PLCA_GET_CFG,
  1290. .doit = ethnl_default_doit,
  1291. .start = ethnl_perphy_start,
  1292. .dumpit = ethnl_perphy_dumpit,
  1293. .done = ethnl_perphy_done,
  1294. .policy = ethnl_plca_get_cfg_policy,
  1295. .maxattr = ARRAY_SIZE(ethnl_plca_get_cfg_policy) - 1,
  1296. },
  1297. {
  1298. .cmd = ETHTOOL_MSG_PLCA_SET_CFG,
  1299. .flags = GENL_UNS_ADMIN_PERM,
  1300. .doit = ethnl_default_set_doit,
  1301. .policy = ethnl_plca_set_cfg_policy,
  1302. .maxattr = ARRAY_SIZE(ethnl_plca_set_cfg_policy) - 1,
  1303. },
  1304. {
  1305. .cmd = ETHTOOL_MSG_PLCA_GET_STATUS,
  1306. .doit = ethnl_default_doit,
  1307. .start = ethnl_perphy_start,
  1308. .dumpit = ethnl_perphy_dumpit,
  1309. .done = ethnl_perphy_done,
  1310. .policy = ethnl_plca_get_status_policy,
  1311. .maxattr = ARRAY_SIZE(ethnl_plca_get_status_policy) - 1,
  1312. },
  1313. {
  1314. .cmd = ETHTOOL_MSG_MM_GET,
  1315. .doit = ethnl_default_doit,
  1316. .start = ethnl_default_start,
  1317. .dumpit = ethnl_default_dumpit,
  1318. .done = ethnl_default_done,
  1319. .policy = ethnl_mm_get_policy,
  1320. .maxattr = ARRAY_SIZE(ethnl_mm_get_policy) - 1,
  1321. },
  1322. {
  1323. .cmd = ETHTOOL_MSG_MM_SET,
  1324. .flags = GENL_UNS_ADMIN_PERM,
  1325. .doit = ethnl_default_set_doit,
  1326. .policy = ethnl_mm_set_policy,
  1327. .maxattr = ARRAY_SIZE(ethnl_mm_set_policy) - 1,
  1328. },
  1329. {
  1330. .cmd = ETHTOOL_MSG_MODULE_FW_FLASH_ACT,
  1331. .flags = GENL_UNS_ADMIN_PERM,
  1332. .doit = ethnl_act_module_fw_flash,
  1333. .policy = ethnl_module_fw_flash_act_policy,
  1334. .maxattr = ARRAY_SIZE(ethnl_module_fw_flash_act_policy) - 1,
  1335. },
  1336. {
  1337. .cmd = ETHTOOL_MSG_PHY_GET,
  1338. .doit = ethnl_default_doit,
  1339. .start = ethnl_perphy_start,
  1340. .dumpit = ethnl_perphy_dumpit,
  1341. .done = ethnl_perphy_done,
  1342. .policy = ethnl_phy_get_policy,
  1343. .maxattr = ARRAY_SIZE(ethnl_phy_get_policy) - 1,
  1344. },
  1345. {
  1346. .cmd = ETHTOOL_MSG_TSCONFIG_GET,
  1347. .doit = ethnl_default_doit,
  1348. .start = ethnl_default_start,
  1349. .dumpit = ethnl_default_dumpit,
  1350. .done = ethnl_default_done,
  1351. .policy = ethnl_tsconfig_get_policy,
  1352. .maxattr = ARRAY_SIZE(ethnl_tsconfig_get_policy) - 1,
  1353. },
  1354. {
  1355. .cmd = ETHTOOL_MSG_TSCONFIG_SET,
  1356. .flags = GENL_UNS_ADMIN_PERM,
  1357. .doit = ethnl_default_set_doit,
  1358. .policy = ethnl_tsconfig_set_policy,
  1359. .maxattr = ARRAY_SIZE(ethnl_tsconfig_set_policy) - 1,
  1360. },
  1361. {
  1362. .cmd = ETHTOOL_MSG_RSS_SET,
  1363. .flags = GENL_UNS_ADMIN_PERM,
  1364. .doit = ethnl_default_set_doit,
  1365. .policy = ethnl_rss_set_policy,
  1366. .maxattr = ARRAY_SIZE(ethnl_rss_set_policy) - 1,
  1367. },
  1368. {
  1369. .cmd = ETHTOOL_MSG_RSS_CREATE_ACT,
  1370. .flags = GENL_UNS_ADMIN_PERM,
  1371. .doit = ethnl_rss_create_doit,
  1372. .policy = ethnl_rss_create_policy,
  1373. .maxattr = ARRAY_SIZE(ethnl_rss_create_policy) - 1,
  1374. },
  1375. {
  1376. .cmd = ETHTOOL_MSG_RSS_DELETE_ACT,
  1377. .flags = GENL_UNS_ADMIN_PERM,
  1378. .doit = ethnl_rss_delete_doit,
  1379. .policy = ethnl_rss_delete_policy,
  1380. .maxattr = ARRAY_SIZE(ethnl_rss_delete_policy) - 1,
  1381. },
  1382. {
  1383. .cmd = ETHTOOL_MSG_MSE_GET,
  1384. .doit = ethnl_default_doit,
  1385. .start = ethnl_perphy_start,
  1386. .dumpit = ethnl_perphy_dumpit,
  1387. .done = ethnl_perphy_done,
  1388. .policy = ethnl_mse_get_policy,
  1389. .maxattr = ARRAY_SIZE(ethnl_mse_get_policy) - 1,
  1390. },
  1391. };
  1392. static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
  1393. [ETHNL_MCGRP_MONITOR] = { .name = ETHTOOL_MCGRP_MONITOR_NAME },
  1394. };
  1395. static struct genl_family ethtool_genl_family __ro_after_init = {
  1396. .name = ETHTOOL_GENL_NAME,
  1397. .version = ETHTOOL_GENL_VERSION,
  1398. .netnsok = true,
  1399. .parallel_ops = true,
  1400. .ops = ethtool_genl_ops,
  1401. .n_ops = ARRAY_SIZE(ethtool_genl_ops),
  1402. .resv_start_op = ETHTOOL_MSG_MODULE_GET + 1,
  1403. .mcgrps = ethtool_nl_mcgrps,
  1404. .n_mcgrps = ARRAY_SIZE(ethtool_nl_mcgrps),
  1405. .sock_priv_size = sizeof(struct ethnl_sock_priv),
  1406. .sock_priv_destroy = ethnl_sock_priv_destroy,
  1407. };
  1408. /* module setup */
  1409. static int __init ethnl_init(void)
  1410. {
  1411. int ret;
  1412. ret = genl_register_family(&ethtool_genl_family);
  1413. if (WARN(ret < 0, "ethtool: genetlink family registration failed"))
  1414. return ret;
  1415. ethnl_ok = true;
  1416. ret = register_netdevice_notifier(&ethnl_netdev_notifier);
  1417. WARN(ret < 0, "ethtool: net device notifier registration failed");
  1418. return ret;
  1419. }
  1420. subsys_initcall(ethnl_init);