eth.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * INET An implementation of the TCP/IP protocol suite for the LINUX
  4. * operating system. INET is implemented using the BSD Socket
  5. * interface as the means of communication with the user level.
  6. *
  7. * Ethernet-type device handling.
  8. *
  9. * Version: @(#)eth.c 1.0.7 05/25/93
  10. *
  11. * Authors: Ross Biro
  12. * Fred N. van Kempen, <[email protected]>
  13. * Mark Evans, <[email protected]>
  14. * Florian La Roche, <[email protected]>
  15. * Alan Cox, <[email protected]>
  16. *
  17. * Fixes:
  18. * Mr Linux : Arp problems
  19. * Alan Cox : Generic queue tidyup (very tiny here)
  20. * Alan Cox : eth_header ntohs should be htons
  21. * Alan Cox : eth_rebuild_header missing an htons and
  22. * minor other things.
  23. * Tegge : Arp bug fixes.
  24. * Florian : Removed many unnecessary functions, code cleanup
  25. * and changes for new arp and skbuff.
  26. * Alan Cox : Redid header building to reflect new format.
  27. * Alan Cox : ARP only when compiled with CONFIG_INET
  28. * Greg Page : 802.2 and SNAP stuff.
  29. * Alan Cox : MAC layer pointers/new format.
  30. * Paul Gortmaker : eth_copy_and_sum shouldn't csum padding.
  31. * Alan Cox : Protect against forwarding explosions with
  32. * older network drivers and IFF_ALLMULTI.
  33. * Christer Weinigel : Better rebuild header message.
  34. * Andrew Morton : 26Feb01: kill ether_setup() - use netdev_boot_setup().
  35. */
  36. #include <linux/module.h>
  37. #include <linux/types.h>
  38. #include <linux/kernel.h>
  39. #include <linux/string.h>
  40. #include <linux/mm.h>
  41. #include <linux/socket.h>
  42. #include <linux/in.h>
  43. #include <linux/inet.h>
  44. #include <linux/ip.h>
  45. #include <linux/netdevice.h>
  46. #include <linux/nvmem-consumer.h>
  47. #include <linux/etherdevice.h>
  48. #include <linux/skbuff.h>
  49. #include <linux/errno.h>
  50. #include <linux/init.h>
  51. #include <linux/if_ether.h>
  52. #include <linux/of_net.h>
  53. #include <linux/pci.h>
  54. #include <linux/property.h>
  55. #include <net/dst.h>
  56. #include <net/arp.h>
  57. #include <net/sock.h>
  58. #include <net/ipv6.h>
  59. #include <net/ip.h>
  60. #include <net/dsa.h>
  61. #include <net/flow_dissector.h>
  62. #include <net/gro.h>
  63. #include <linux/uaccess.h>
  64. #include <net/pkt_sched.h>
  65. /**
  66. * eth_header - create the Ethernet header
  67. * @skb: buffer to alter
  68. * @dev: source device
  69. * @type: Ethernet type field
  70. * @daddr: destination address (NULL leave destination address)
  71. * @saddr: source address (NULL use device source address)
  72. * @len: packet length (<= skb->len)
  73. *
  74. *
  75. * Set the protocol type. For a packet of type ETH_P_802_3/2 we put the length
  76. * in here instead.
  77. */
  78. int eth_header(struct sk_buff *skb, struct net_device *dev,
  79. unsigned short type,
  80. const void *daddr, const void *saddr, unsigned int len)
  81. {
  82. struct ethhdr *eth = skb_push(skb, ETH_HLEN);
  83. if (type != ETH_P_802_3 && type != ETH_P_802_2)
  84. eth->h_proto = htons(type);
  85. else
  86. eth->h_proto = htons(len);
  87. /*
  88. * Set the source hardware address.
  89. */
  90. if (!saddr)
  91. saddr = dev->dev_addr;
  92. memcpy(eth->h_source, saddr, ETH_ALEN);
  93. if (daddr) {
  94. memcpy(eth->h_dest, daddr, ETH_ALEN);
  95. return ETH_HLEN;
  96. }
  97. /*
  98. * Anyway, the loopback-device should never use this function...
  99. */
  100. if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
  101. eth_zero_addr(eth->h_dest);
  102. return ETH_HLEN;
  103. }
  104. return -ETH_HLEN;
  105. }
  106. EXPORT_SYMBOL(eth_header);
  107. /**
  108. * eth_get_headlen - determine the length of header for an ethernet frame
  109. * @dev: pointer to network device
  110. * @data: pointer to start of frame
  111. * @len: total length of frame
  112. *
  113. * Make a best effort attempt to pull the length for all of the headers for
  114. * a given frame in a linear buffer.
  115. */
  116. u32 eth_get_headlen(const struct net_device *dev, const void *data, u32 len)
  117. {
  118. const unsigned int flags = FLOW_DISSECTOR_F_PARSE_1ST_FRAG;
  119. const struct ethhdr *eth = (const struct ethhdr *)data;
  120. struct flow_keys_basic keys;
  121. /* this should never happen, but better safe than sorry */
  122. if (unlikely(len < sizeof(*eth)))
  123. return len;
  124. /* parse any remaining L2/L3 headers, check for L4 */
  125. if (!skb_flow_dissect_flow_keys_basic(dev_net(dev), NULL, &keys, data,
  126. eth->h_proto, sizeof(*eth),
  127. len, flags))
  128. return max_t(u32, keys.control.thoff, sizeof(*eth));
  129. /* parse for any L4 headers */
  130. return min_t(u32, __skb_get_poff(NULL, data, &keys, len), len);
  131. }
  132. EXPORT_SYMBOL(eth_get_headlen);
  133. /**
  134. * eth_type_trans - determine the packet's protocol ID.
  135. * @skb: received socket data
  136. * @dev: receiving network device
  137. *
  138. * The rule here is that we
  139. * assume 802.3 if the type field is short enough to be a length.
  140. * This is normal practice and works for any 'now in use' protocol.
  141. */
  142. __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
  143. {
  144. unsigned short _service_access_point;
  145. const unsigned short *sap;
  146. const struct ethhdr *eth;
  147. skb->dev = dev;
  148. skb_reset_mac_header(skb);
  149. eth = (struct ethhdr *)skb->data;
  150. skb_pull_inline(skb, ETH_HLEN);
  151. if (unlikely(!ether_addr_equal_64bits(eth->h_dest,
  152. dev->dev_addr))) {
  153. if (unlikely(is_multicast_ether_addr_64bits(eth->h_dest))) {
  154. if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast))
  155. skb->pkt_type = PACKET_BROADCAST;
  156. else
  157. skb->pkt_type = PACKET_MULTICAST;
  158. } else {
  159. skb->pkt_type = PACKET_OTHERHOST;
  160. }
  161. }
  162. /*
  163. * Some variants of DSA tagging don't have an ethertype field
  164. * at all, so we check here whether one of those tagging
  165. * variants has been configured on the receiving interface,
  166. * and if so, set skb->protocol without looking at the packet.
  167. */
  168. if (unlikely(netdev_uses_dsa(dev)))
  169. return htons(ETH_P_XDSA);
  170. if (likely(eth_proto_is_802_3(eth->h_proto)))
  171. return eth->h_proto;
  172. /*
  173. * This is a magic hack to spot IPX packets. Older Novell breaks
  174. * the protocol design and runs IPX over 802.3 without an 802.2 LLC
  175. * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
  176. * won't work for fault tolerant netware but does for the rest.
  177. */
  178. sap = skb_header_pointer(skb, 0, sizeof(*sap), &_service_access_point);
  179. if (sap && *sap == 0xFFFF)
  180. return htons(ETH_P_802_3);
  181. /*
  182. * Real 802.2 LLC
  183. */
  184. return htons(ETH_P_802_2);
  185. }
  186. EXPORT_SYMBOL(eth_type_trans);
  187. /**
  188. * eth_header_parse - extract hardware address from packet
  189. * @skb: packet to extract header from
  190. * @haddr: destination buffer
  191. */
  192. int eth_header_parse(const struct sk_buff *skb, unsigned char *haddr)
  193. {
  194. const struct ethhdr *eth = eth_hdr(skb);
  195. memcpy(haddr, eth->h_source, ETH_ALEN);
  196. return ETH_ALEN;
  197. }
  198. EXPORT_SYMBOL(eth_header_parse);
  199. /**
  200. * eth_header_cache - fill cache entry from neighbour
  201. * @neigh: source neighbour
  202. * @hh: destination cache entry
  203. * @type: Ethernet type field
  204. *
  205. * Create an Ethernet header template from the neighbour.
  206. */
  207. int eth_header_cache(const struct neighbour *neigh, struct hh_cache *hh, __be16 type)
  208. {
  209. struct ethhdr *eth;
  210. const struct net_device *dev = neigh->dev;
  211. eth = (struct ethhdr *)
  212. (((u8 *) hh->hh_data) + (HH_DATA_OFF(sizeof(*eth))));
  213. if (type == htons(ETH_P_802_3))
  214. return -1;
  215. eth->h_proto = type;
  216. memcpy(eth->h_source, dev->dev_addr, ETH_ALEN);
  217. memcpy(eth->h_dest, neigh->ha, ETH_ALEN);
  218. /* Pairs with READ_ONCE() in neigh_resolve_output(),
  219. * neigh_hh_output() and neigh_update_hhs().
  220. */
  221. smp_store_release(&hh->hh_len, ETH_HLEN);
  222. return 0;
  223. }
  224. EXPORT_SYMBOL(eth_header_cache);
  225. /**
  226. * eth_header_cache_update - update cache entry
  227. * @hh: destination cache entry
  228. * @dev: network device
  229. * @haddr: new hardware address
  230. *
  231. * Called by Address Resolution module to notify changes in address.
  232. */
  233. void eth_header_cache_update(struct hh_cache *hh,
  234. const struct net_device *dev,
  235. const unsigned char *haddr)
  236. {
  237. memcpy(((u8 *) hh->hh_data) + HH_DATA_OFF(sizeof(struct ethhdr)),
  238. haddr, ETH_ALEN);
  239. }
  240. EXPORT_SYMBOL(eth_header_cache_update);
  241. /**
  242. * eth_header_parse_protocol - extract protocol from L2 header
  243. * @skb: packet to extract protocol from
  244. */
  245. __be16 eth_header_parse_protocol(const struct sk_buff *skb)
  246. {
  247. const struct ethhdr *eth = eth_hdr(skb);
  248. return eth->h_proto;
  249. }
  250. EXPORT_SYMBOL(eth_header_parse_protocol);
  251. /**
  252. * eth_prepare_mac_addr_change - prepare for mac change
  253. * @dev: network device
  254. * @p: socket address
  255. */
  256. int eth_prepare_mac_addr_change(struct net_device *dev, void *p)
  257. {
  258. struct sockaddr *addr = p;
  259. if (!(dev->priv_flags & IFF_LIVE_ADDR_CHANGE) && netif_running(dev))
  260. return -EBUSY;
  261. if (!is_valid_ether_addr(addr->sa_data))
  262. return -EADDRNOTAVAIL;
  263. return 0;
  264. }
  265. EXPORT_SYMBOL(eth_prepare_mac_addr_change);
  266. /**
  267. * eth_commit_mac_addr_change - commit mac change
  268. * @dev: network device
  269. * @p: socket address
  270. */
  271. void eth_commit_mac_addr_change(struct net_device *dev, void *p)
  272. {
  273. struct sockaddr *addr = p;
  274. eth_hw_addr_set(dev, addr->sa_data);
  275. }
  276. EXPORT_SYMBOL(eth_commit_mac_addr_change);
  277. /**
  278. * eth_mac_addr - set new Ethernet hardware address
  279. * @dev: network device
  280. * @p: socket address
  281. *
  282. * Change hardware address of device.
  283. *
  284. * This doesn't change hardware matching, so needs to be overridden
  285. * for most real devices.
  286. */
  287. int eth_mac_addr(struct net_device *dev, void *p)
  288. {
  289. int ret;
  290. ret = eth_prepare_mac_addr_change(dev, p);
  291. if (ret < 0)
  292. return ret;
  293. eth_commit_mac_addr_change(dev, p);
  294. return 0;
  295. }
  296. EXPORT_SYMBOL(eth_mac_addr);
  297. int eth_validate_addr(struct net_device *dev)
  298. {
  299. if (!is_valid_ether_addr(dev->dev_addr))
  300. return -EADDRNOTAVAIL;
  301. return 0;
  302. }
  303. EXPORT_SYMBOL(eth_validate_addr);
  304. const struct header_ops eth_header_ops ____cacheline_aligned = {
  305. .create = eth_header,
  306. .parse = eth_header_parse,
  307. .cache = eth_header_cache,
  308. .cache_update = eth_header_cache_update,
  309. .parse_protocol = eth_header_parse_protocol,
  310. };
  311. /**
  312. * ether_setup - setup Ethernet network device
  313. * @dev: network device
  314. *
  315. * Fill in the fields of the device structure with Ethernet-generic values.
  316. */
  317. void ether_setup(struct net_device *dev)
  318. {
  319. dev->header_ops = &eth_header_ops;
  320. dev->type = ARPHRD_ETHER;
  321. dev->hard_header_len = ETH_HLEN;
  322. dev->min_header_len = ETH_HLEN;
  323. dev->mtu = ETH_DATA_LEN;
  324. dev->min_mtu = ETH_MIN_MTU;
  325. dev->max_mtu = ETH_DATA_LEN;
  326. dev->addr_len = ETH_ALEN;
  327. dev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
  328. dev->flags = IFF_BROADCAST|IFF_MULTICAST;
  329. dev->priv_flags |= IFF_TX_SKB_SHARING;
  330. eth_broadcast_addr(dev->broadcast);
  331. }
  332. EXPORT_SYMBOL(ether_setup);
  333. /**
  334. * alloc_etherdev_mqs - Allocates and sets up an Ethernet device
  335. * @sizeof_priv: Size of additional driver-private structure to be allocated
  336. * for this Ethernet device
  337. * @txqs: The number of TX queues this device has.
  338. * @rxqs: The number of RX queues this device has.
  339. *
  340. * Fill in the fields of the device structure with Ethernet-generic
  341. * values. Basically does everything except registering the device.
  342. *
  343. * Constructs a new net device, complete with a private data area of
  344. * size (sizeof_priv). A 32-byte (not bit) alignment is enforced for
  345. * this private data area.
  346. */
  347. struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs,
  348. unsigned int rxqs)
  349. {
  350. return alloc_netdev_mqs(sizeof_priv, "eth%d", NET_NAME_ENUM,
  351. ether_setup, txqs, rxqs);
  352. }
  353. EXPORT_SYMBOL(alloc_etherdev_mqs);
  354. ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
  355. {
  356. return scnprintf(buf, PAGE_SIZE, "%*phC\n", len, addr);
  357. }
  358. EXPORT_SYMBOL(sysfs_format_mac);
  359. struct sk_buff *eth_gro_receive(struct list_head *head, struct sk_buff *skb)
  360. {
  361. const struct packet_offload *ptype;
  362. unsigned int hlen, off_eth;
  363. struct sk_buff *pp = NULL;
  364. struct ethhdr *eh, *eh2;
  365. struct sk_buff *p;
  366. __be16 type;
  367. int flush = 1;
  368. off_eth = skb_gro_offset(skb);
  369. hlen = off_eth + sizeof(*eh);
  370. eh = skb_gro_header(skb, hlen, off_eth);
  371. if (unlikely(!eh))
  372. goto out;
  373. flush = 0;
  374. list_for_each_entry(p, head, list) {
  375. if (!NAPI_GRO_CB(p)->same_flow)
  376. continue;
  377. eh2 = (struct ethhdr *)(p->data + off_eth);
  378. if (compare_ether_header(eh, eh2)) {
  379. NAPI_GRO_CB(p)->same_flow = 0;
  380. continue;
  381. }
  382. }
  383. type = eh->h_proto;
  384. ptype = gro_find_receive_by_type(type);
  385. if (ptype == NULL) {
  386. flush = 1;
  387. goto out;
  388. }
  389. skb_gro_pull(skb, sizeof(*eh));
  390. skb_gro_postpull_rcsum(skb, eh, sizeof(*eh));
  391. pp = indirect_call_gro_receive_inet(ptype->callbacks.gro_receive,
  392. ipv6_gro_receive, inet_gro_receive,
  393. head, skb);
  394. out:
  395. skb_gro_flush_final(skb, pp, flush);
  396. return pp;
  397. }
  398. EXPORT_SYMBOL(eth_gro_receive);
  399. int eth_gro_complete(struct sk_buff *skb, int nhoff)
  400. {
  401. struct ethhdr *eh = (struct ethhdr *)(skb->data + nhoff);
  402. __be16 type = eh->h_proto;
  403. struct packet_offload *ptype;
  404. int err = -ENOSYS;
  405. if (skb->encapsulation)
  406. skb_set_inner_mac_header(skb, nhoff);
  407. ptype = gro_find_complete_by_type(type);
  408. if (ptype != NULL)
  409. err = INDIRECT_CALL_INET(ptype->callbacks.gro_complete,
  410. ipv6_gro_complete, inet_gro_complete,
  411. skb, nhoff + sizeof(*eh));
  412. return err;
  413. }
  414. EXPORT_SYMBOL(eth_gro_complete);
  415. static struct packet_offload eth_packet_offload __read_mostly = {
  416. .type = cpu_to_be16(ETH_P_TEB),
  417. .priority = 10,
  418. .callbacks = {
  419. .gro_receive = eth_gro_receive,
  420. .gro_complete = eth_gro_complete,
  421. },
  422. };
  423. static int __init eth_offload_init(void)
  424. {
  425. dev_add_offload(&eth_packet_offload);
  426. return 0;
  427. }
  428. fs_initcall(eth_offload_init);
  429. unsigned char * __weak arch_get_platform_mac_address(void)
  430. {
  431. return NULL;
  432. }
  433. int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr)
  434. {
  435. unsigned char *addr;
  436. int ret;
  437. ret = of_get_mac_address(dev->of_node, mac_addr);
  438. if (!ret)
  439. return 0;
  440. addr = arch_get_platform_mac_address();
  441. if (!addr)
  442. return -ENODEV;
  443. ether_addr_copy(mac_addr, addr);
  444. return 0;
  445. }
  446. EXPORT_SYMBOL(eth_platform_get_mac_address);
  447. /**
  448. * platform_get_ethdev_address - Set netdev's MAC address from a given device
  449. * @dev: Pointer to the device
  450. * @netdev: Pointer to netdev to write the address to
  451. *
  452. * Wrapper around eth_platform_get_mac_address() which writes the address
  453. * directly to netdev->dev_addr.
  454. */
  455. int platform_get_ethdev_address(struct device *dev, struct net_device *netdev)
  456. {
  457. u8 addr[ETH_ALEN] __aligned(2);
  458. int ret;
  459. ret = eth_platform_get_mac_address(dev, addr);
  460. if (!ret)
  461. eth_hw_addr_set(netdev, addr);
  462. return ret;
  463. }
  464. EXPORT_SYMBOL(platform_get_ethdev_address);
  465. /**
  466. * nvmem_get_mac_address - Obtain the MAC address from an nvmem cell named
  467. * 'mac-address' associated with given device.
  468. *
  469. * @dev: Device with which the mac-address cell is associated.
  470. * @addrbuf: Buffer to which the MAC address will be copied on success.
  471. *
  472. * Returns 0 on success or a negative error number on failure.
  473. */
  474. int nvmem_get_mac_address(struct device *dev, void *addrbuf)
  475. {
  476. struct nvmem_cell *cell;
  477. const void *mac;
  478. size_t len;
  479. cell = nvmem_cell_get(dev, "mac-address");
  480. if (IS_ERR(cell))
  481. return PTR_ERR(cell);
  482. mac = nvmem_cell_read(cell, &len);
  483. nvmem_cell_put(cell);
  484. if (IS_ERR(mac))
  485. return PTR_ERR(mac);
  486. if (len != ETH_ALEN || !is_valid_ether_addr(mac)) {
  487. kfree(mac);
  488. return -EINVAL;
  489. }
  490. ether_addr_copy(addrbuf, mac);
  491. kfree(mac);
  492. return 0;
  493. }
  494. static int fwnode_get_mac_addr(struct fwnode_handle *fwnode,
  495. const char *name, char *addr)
  496. {
  497. int ret;
  498. ret = fwnode_property_read_u8_array(fwnode, name, addr, ETH_ALEN);
  499. if (ret)
  500. return ret;
  501. if (!is_valid_ether_addr(addr))
  502. return -EINVAL;
  503. return 0;
  504. }
  505. /**
  506. * fwnode_get_mac_address - Get the MAC from the firmware node
  507. * @fwnode: Pointer to the firmware node
  508. * @addr: Address of buffer to store the MAC in
  509. *
  510. * Search the firmware node for the best MAC address to use. 'mac-address' is
  511. * checked first, because that is supposed to contain to "most recent" MAC
  512. * address. If that isn't set, then 'local-mac-address' is checked next,
  513. * because that is the default address. If that isn't set, then the obsolete
  514. * 'address' is checked, just in case we're using an old device tree.
  515. *
  516. * Note that the 'address' property is supposed to contain a virtual address of
  517. * the register set, but some DTS files have redefined that property to be the
  518. * MAC address.
  519. *
  520. * All-zero MAC addresses are rejected, because those could be properties that
  521. * exist in the firmware tables, but were not updated by the firmware. For
  522. * example, the DTS could define 'mac-address' and 'local-mac-address', with
  523. * zero MAC addresses. Some older U-Boots only initialized 'local-mac-address'.
  524. * In this case, the real MAC is in 'local-mac-address', and 'mac-address'
  525. * exists but is all zeros.
  526. */
  527. int fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr)
  528. {
  529. if (!fwnode_get_mac_addr(fwnode, "mac-address", addr) ||
  530. !fwnode_get_mac_addr(fwnode, "local-mac-address", addr) ||
  531. !fwnode_get_mac_addr(fwnode, "address", addr))
  532. return 0;
  533. return -ENOENT;
  534. }
  535. EXPORT_SYMBOL(fwnode_get_mac_address);
  536. /**
  537. * device_get_mac_address - Get the MAC for a given device
  538. * @dev: Pointer to the device
  539. * @addr: Address of buffer to store the MAC in
  540. */
  541. int device_get_mac_address(struct device *dev, char *addr)
  542. {
  543. return fwnode_get_mac_address(dev_fwnode(dev), addr);
  544. }
  545. EXPORT_SYMBOL(device_get_mac_address);
  546. /**
  547. * device_get_ethdev_address - Set netdev's MAC address from a given device
  548. * @dev: Pointer to the device
  549. * @netdev: Pointer to netdev to write the address to
  550. *
  551. * Wrapper around device_get_mac_address() which writes the address
  552. * directly to netdev->dev_addr.
  553. */
  554. int device_get_ethdev_address(struct device *dev, struct net_device *netdev)
  555. {
  556. u8 addr[ETH_ALEN];
  557. int ret;
  558. ret = device_get_mac_address(dev, addr);
  559. if (!ret)
  560. eth_hw_addr_set(netdev, addr);
  561. return ret;
  562. }
  563. EXPORT_SYMBOL(device_get_ethdev_address);