Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * INET     An implementation of the TCP/IP protocol suite for the LINUX
0004  *      operating system.  INET is implemented using the  BSD Socket
0005  *      interface as the means of communication with the user level.
0006  *
0007  *      Ethernet-type device handling.
0008  *
0009  * Version: @(#)eth.c   1.0.7   05/25/93
0010  *
0011  * Authors: Ross Biro
0012  *      Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
0013  *      Mark Evans, <evansmp@uhura.aston.ac.uk>
0014  *      Florian  La Roche, <rzsfl@rz.uni-sb.de>
0015  *      Alan Cox, <gw4pts@gw4pts.ampr.org>
0016  *
0017  * Fixes:
0018  *      Mr Linux    : Arp problems
0019  *      Alan Cox    : Generic queue tidyup (very tiny here)
0020  *      Alan Cox    : eth_header ntohs should be htons
0021  *      Alan Cox    : eth_rebuild_header missing an htons and
0022  *                minor other things.
0023  *      Tegge       : Arp bug fixes.
0024  *      Florian     : Removed many unnecessary functions, code cleanup
0025  *                and changes for new arp and skbuff.
0026  *      Alan Cox    : Redid header building to reflect new format.
0027  *      Alan Cox    : ARP only when compiled with CONFIG_INET
0028  *      Greg Page   : 802.2 and SNAP stuff.
0029  *      Alan Cox    : MAC layer pointers/new format.
0030  *      Paul Gortmaker  : eth_copy_and_sum shouldn't csum padding.
0031  *      Alan Cox    : Protect against forwarding explosions with
0032  *                older network drivers and IFF_ALLMULTI.
0033  *  Christer Weinigel   : Better rebuild header message.
0034  *             Andrew Morton    : 26Feb01: kill ether_setup() - use netdev_boot_setup().
0035  */
0036 #include <linux/module.h>
0037 #include <linux/types.h>
0038 #include <linux/kernel.h>
0039 #include <linux/string.h>
0040 #include <linux/mm.h>
0041 #include <linux/socket.h>
0042 #include <linux/in.h>
0043 #include <linux/inet.h>
0044 #include <linux/ip.h>
0045 #include <linux/netdevice.h>
0046 #include <linux/nvmem-consumer.h>
0047 #include <linux/etherdevice.h>
0048 #include <linux/skbuff.h>
0049 #include <linux/errno.h>
0050 #include <linux/init.h>
0051 #include <linux/if_ether.h>
0052 #include <linux/of_net.h>
0053 #include <linux/pci.h>
0054 #include <linux/property.h>
0055 #include <net/dst.h>
0056 #include <net/arp.h>
0057 #include <net/sock.h>
0058 #include <net/ipv6.h>
0059 #include <net/ip.h>
0060 #include <net/dsa.h>
0061 #include <net/flow_dissector.h>
0062 #include <net/gro.h>
0063 #include <linux/uaccess.h>
0064 #include <net/pkt_sched.h>
0065 
0066 /**
0067  * eth_header - create the Ethernet header
0068  * @skb:    buffer to alter
0069  * @dev:    source device
0070  * @type:   Ethernet type field
0071  * @daddr: destination address (NULL leave destination address)
0072  * @saddr: source address (NULL use device source address)
0073  * @len:   packet length (<= skb->len)
0074  *
0075  *
0076  * Set the protocol type. For a packet of type ETH_P_802_3/2 we put the length
0077  * in here instead.
0078  */
0079 int eth_header(struct sk_buff *skb, struct net_device *dev,
0080            unsigned short type,
0081            const void *daddr, const void *saddr, unsigned int len)
0082 {
0083     struct ethhdr *eth = skb_push(skb, ETH_HLEN);
0084 
0085     if (type != ETH_P_802_3 && type != ETH_P_802_2)
0086         eth->h_proto = htons(type);
0087     else
0088         eth->h_proto = htons(len);
0089 
0090     /*
0091      *      Set the source hardware address.
0092      */
0093 
0094     if (!saddr)
0095         saddr = dev->dev_addr;
0096     memcpy(eth->h_source, saddr, ETH_ALEN);
0097 
0098     if (daddr) {
0099         memcpy(eth->h_dest, daddr, ETH_ALEN);
0100         return ETH_HLEN;
0101     }
0102 
0103     /*
0104      *      Anyway, the loopback-device should never use this function...
0105      */
0106 
0107     if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) {
0108         eth_zero_addr(eth->h_dest);
0109         return ETH_HLEN;
0110     }
0111 
0112     return -ETH_HLEN;
0113 }
0114 EXPORT_SYMBOL(eth_header);
0115 
0116 /**
0117  * eth_get_headlen - determine the length of header for an ethernet frame
0118  * @dev: pointer to network device
0119  * @data: pointer to start of frame
0120  * @len: total length of frame
0121  *
0122  * Make a best effort attempt to pull the length for all of the headers for
0123  * a given frame in a linear buffer.
0124  */
0125 u32 eth_get_headlen(const struct net_device *dev, const void *data, u32 len)
0126 {
0127     const unsigned int flags = FLOW_DISSECTOR_F_PARSE_1ST_FRAG;
0128     const struct ethhdr *eth = (const struct ethhdr *)data;
0129     struct flow_keys_basic keys;
0130 
0131     /* this should never happen, but better safe than sorry */
0132     if (unlikely(len < sizeof(*eth)))
0133         return len;
0134 
0135     /* parse any remaining L2/L3 headers, check for L4 */
0136     if (!skb_flow_dissect_flow_keys_basic(dev_net(dev), NULL, &keys, data,
0137                           eth->h_proto, sizeof(*eth),
0138                           len, flags))
0139         return max_t(u32, keys.control.thoff, sizeof(*eth));
0140 
0141     /* parse for any L4 headers */
0142     return min_t(u32, __skb_get_poff(NULL, data, &keys, len), len);
0143 }
0144 EXPORT_SYMBOL(eth_get_headlen);
0145 
0146 /**
0147  * eth_type_trans - determine the packet's protocol ID.
0148  * @skb: received socket data
0149  * @dev: receiving network device
0150  *
0151  * The rule here is that we
0152  * assume 802.3 if the type field is short enough to be a length.
0153  * This is normal practice and works for any 'now in use' protocol.
0154  */
0155 __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)
0156 {
0157     unsigned short _service_access_point;
0158     const unsigned short *sap;
0159     const struct ethhdr *eth;
0160 
0161     skb->dev = dev;
0162     skb_reset_mac_header(skb);
0163 
0164     eth = (struct ethhdr *)skb->data;
0165     skb_pull_inline(skb, ETH_HLEN);
0166 
0167     if (unlikely(!ether_addr_equal_64bits(eth->h_dest,
0168                           dev->dev_addr))) {
0169         if (unlikely(is_multicast_ether_addr_64bits(eth->h_dest))) {
0170             if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast))
0171                 skb->pkt_type = PACKET_BROADCAST;
0172             else
0173                 skb->pkt_type = PACKET_MULTICAST;
0174         } else {
0175             skb->pkt_type = PACKET_OTHERHOST;
0176         }
0177     }
0178 
0179     /*
0180      * Some variants of DSA tagging don't have an ethertype field
0181      * at all, so we check here whether one of those tagging
0182      * variants has been configured on the receiving interface,
0183      * and if so, set skb->protocol without looking at the packet.
0184      */
0185     if (unlikely(netdev_uses_dsa(dev)))
0186         return htons(ETH_P_XDSA);
0187 
0188     if (likely(eth_proto_is_802_3(eth->h_proto)))
0189         return eth->h_proto;
0190 
0191     /*
0192      *      This is a magic hack to spot IPX packets. Older Novell breaks
0193      *      the protocol design and runs IPX over 802.3 without an 802.2 LLC
0194      *      layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
0195      *      won't work for fault tolerant netware but does for the rest.
0196      */
0197     sap = skb_header_pointer(skb, 0, sizeof(*sap), &_service_access_point);
0198     if (sap && *sap == 0xFFFF)
0199         return htons(ETH_P_802_3);
0200 
0201     /*
0202      *      Real 802.2 LLC
0203      */
0204     return htons(ETH_P_802_2);
0205 }
0206 EXPORT_SYMBOL(eth_type_trans);
0207 
0208 /**
0209  * eth_header_parse - extract hardware address from packet
0210  * @skb: packet to extract header from
0211  * @haddr: destination buffer
0212  */
0213 int eth_header_parse(const struct sk_buff *skb, unsigned char *haddr)
0214 {
0215     const struct ethhdr *eth = eth_hdr(skb);
0216     memcpy(haddr, eth->h_source, ETH_ALEN);
0217     return ETH_ALEN;
0218 }
0219 EXPORT_SYMBOL(eth_header_parse);
0220 
0221 /**
0222  * eth_header_cache - fill cache entry from neighbour
0223  * @neigh: source neighbour
0224  * @hh: destination cache entry
0225  * @type: Ethernet type field
0226  *
0227  * Create an Ethernet header template from the neighbour.
0228  */
0229 int eth_header_cache(const struct neighbour *neigh, struct hh_cache *hh, __be16 type)
0230 {
0231     struct ethhdr *eth;
0232     const struct net_device *dev = neigh->dev;
0233 
0234     eth = (struct ethhdr *)
0235         (((u8 *) hh->hh_data) + (HH_DATA_OFF(sizeof(*eth))));
0236 
0237     if (type == htons(ETH_P_802_3))
0238         return -1;
0239 
0240     eth->h_proto = type;
0241     memcpy(eth->h_source, dev->dev_addr, ETH_ALEN);
0242     memcpy(eth->h_dest, neigh->ha, ETH_ALEN);
0243 
0244     /* Pairs with READ_ONCE() in neigh_resolve_output(),
0245      * neigh_hh_output() and neigh_update_hhs().
0246      */
0247     smp_store_release(&hh->hh_len, ETH_HLEN);
0248 
0249     return 0;
0250 }
0251 EXPORT_SYMBOL(eth_header_cache);
0252 
0253 /**
0254  * eth_header_cache_update - update cache entry
0255  * @hh: destination cache entry
0256  * @dev: network device
0257  * @haddr: new hardware address
0258  *
0259  * Called by Address Resolution module to notify changes in address.
0260  */
0261 void eth_header_cache_update(struct hh_cache *hh,
0262                  const struct net_device *dev,
0263                  const unsigned char *haddr)
0264 {
0265     memcpy(((u8 *) hh->hh_data) + HH_DATA_OFF(sizeof(struct ethhdr)),
0266            haddr, ETH_ALEN);
0267 }
0268 EXPORT_SYMBOL(eth_header_cache_update);
0269 
0270 /**
0271  * eth_header_parse_protocol - extract protocol from L2 header
0272  * @skb: packet to extract protocol from
0273  */
0274 __be16 eth_header_parse_protocol(const struct sk_buff *skb)
0275 {
0276     const struct ethhdr *eth = eth_hdr(skb);
0277 
0278     return eth->h_proto;
0279 }
0280 EXPORT_SYMBOL(eth_header_parse_protocol);
0281 
0282 /**
0283  * eth_prepare_mac_addr_change - prepare for mac change
0284  * @dev: network device
0285  * @p: socket address
0286  */
0287 int eth_prepare_mac_addr_change(struct net_device *dev, void *p)
0288 {
0289     struct sockaddr *addr = p;
0290 
0291     if (!(dev->priv_flags & IFF_LIVE_ADDR_CHANGE) && netif_running(dev))
0292         return -EBUSY;
0293     if (!is_valid_ether_addr(addr->sa_data))
0294         return -EADDRNOTAVAIL;
0295     return 0;
0296 }
0297 EXPORT_SYMBOL(eth_prepare_mac_addr_change);
0298 
0299 /**
0300  * eth_commit_mac_addr_change - commit mac change
0301  * @dev: network device
0302  * @p: socket address
0303  */
0304 void eth_commit_mac_addr_change(struct net_device *dev, void *p)
0305 {
0306     struct sockaddr *addr = p;
0307 
0308     eth_hw_addr_set(dev, addr->sa_data);
0309 }
0310 EXPORT_SYMBOL(eth_commit_mac_addr_change);
0311 
0312 /**
0313  * eth_mac_addr - set new Ethernet hardware address
0314  * @dev: network device
0315  * @p: socket address
0316  *
0317  * Change hardware address of device.
0318  *
0319  * This doesn't change hardware matching, so needs to be overridden
0320  * for most real devices.
0321  */
0322 int eth_mac_addr(struct net_device *dev, void *p)
0323 {
0324     int ret;
0325 
0326     ret = eth_prepare_mac_addr_change(dev, p);
0327     if (ret < 0)
0328         return ret;
0329     eth_commit_mac_addr_change(dev, p);
0330     return 0;
0331 }
0332 EXPORT_SYMBOL(eth_mac_addr);
0333 
0334 int eth_validate_addr(struct net_device *dev)
0335 {
0336     if (!is_valid_ether_addr(dev->dev_addr))
0337         return -EADDRNOTAVAIL;
0338 
0339     return 0;
0340 }
0341 EXPORT_SYMBOL(eth_validate_addr);
0342 
0343 const struct header_ops eth_header_ops ____cacheline_aligned = {
0344     .create     = eth_header,
0345     .parse      = eth_header_parse,
0346     .cache      = eth_header_cache,
0347     .cache_update   = eth_header_cache_update,
0348     .parse_protocol = eth_header_parse_protocol,
0349 };
0350 
0351 /**
0352  * ether_setup - setup Ethernet network device
0353  * @dev: network device
0354  *
0355  * Fill in the fields of the device structure with Ethernet-generic values.
0356  */
0357 void ether_setup(struct net_device *dev)
0358 {
0359     dev->header_ops     = &eth_header_ops;
0360     dev->type       = ARPHRD_ETHER;
0361     dev->hard_header_len    = ETH_HLEN;
0362     dev->min_header_len = ETH_HLEN;
0363     dev->mtu        = ETH_DATA_LEN;
0364     dev->min_mtu        = ETH_MIN_MTU;
0365     dev->max_mtu        = ETH_DATA_LEN;
0366     dev->addr_len       = ETH_ALEN;
0367     dev->tx_queue_len   = DEFAULT_TX_QUEUE_LEN;
0368     dev->flags      = IFF_BROADCAST|IFF_MULTICAST;
0369     dev->priv_flags     |= IFF_TX_SKB_SHARING;
0370 
0371     eth_broadcast_addr(dev->broadcast);
0372 
0373 }
0374 EXPORT_SYMBOL(ether_setup);
0375 
0376 /**
0377  * alloc_etherdev_mqs - Allocates and sets up an Ethernet device
0378  * @sizeof_priv: Size of additional driver-private structure to be allocated
0379  *  for this Ethernet device
0380  * @txqs: The number of TX queues this device has.
0381  * @rxqs: The number of RX queues this device has.
0382  *
0383  * Fill in the fields of the device structure with Ethernet-generic
0384  * values. Basically does everything except registering the device.
0385  *
0386  * Constructs a new net device, complete with a private data area of
0387  * size (sizeof_priv).  A 32-byte (not bit) alignment is enforced for
0388  * this private data area.
0389  */
0390 
0391 struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs,
0392                       unsigned int rxqs)
0393 {
0394     return alloc_netdev_mqs(sizeof_priv, "eth%d", NET_NAME_ENUM,
0395                 ether_setup, txqs, rxqs);
0396 }
0397 EXPORT_SYMBOL(alloc_etherdev_mqs);
0398 
0399 ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len)
0400 {
0401     return scnprintf(buf, PAGE_SIZE, "%*phC\n", len, addr);
0402 }
0403 EXPORT_SYMBOL(sysfs_format_mac);
0404 
0405 struct sk_buff *eth_gro_receive(struct list_head *head, struct sk_buff *skb)
0406 {
0407     const struct packet_offload *ptype;
0408     unsigned int hlen, off_eth;
0409     struct sk_buff *pp = NULL;
0410     struct ethhdr *eh, *eh2;
0411     struct sk_buff *p;
0412     __be16 type;
0413     int flush = 1;
0414 
0415     off_eth = skb_gro_offset(skb);
0416     hlen = off_eth + sizeof(*eh);
0417     eh = skb_gro_header_fast(skb, off_eth);
0418     if (skb_gro_header_hard(skb, hlen)) {
0419         eh = skb_gro_header_slow(skb, hlen, off_eth);
0420         if (unlikely(!eh))
0421             goto out;
0422     }
0423 
0424     flush = 0;
0425 
0426     list_for_each_entry(p, head, list) {
0427         if (!NAPI_GRO_CB(p)->same_flow)
0428             continue;
0429 
0430         eh2 = (struct ethhdr *)(p->data + off_eth);
0431         if (compare_ether_header(eh, eh2)) {
0432             NAPI_GRO_CB(p)->same_flow = 0;
0433             continue;
0434         }
0435     }
0436 
0437     type = eh->h_proto;
0438 
0439     ptype = gro_find_receive_by_type(type);
0440     if (ptype == NULL) {
0441         flush = 1;
0442         goto out;
0443     }
0444 
0445     skb_gro_pull(skb, sizeof(*eh));
0446     skb_gro_postpull_rcsum(skb, eh, sizeof(*eh));
0447 
0448     pp = indirect_call_gro_receive_inet(ptype->callbacks.gro_receive,
0449                         ipv6_gro_receive, inet_gro_receive,
0450                         head, skb);
0451 
0452 out:
0453     skb_gro_flush_final(skb, pp, flush);
0454 
0455     return pp;
0456 }
0457 EXPORT_SYMBOL(eth_gro_receive);
0458 
0459 int eth_gro_complete(struct sk_buff *skb, int nhoff)
0460 {
0461     struct ethhdr *eh = (struct ethhdr *)(skb->data + nhoff);
0462     __be16 type = eh->h_proto;
0463     struct packet_offload *ptype;
0464     int err = -ENOSYS;
0465 
0466     if (skb->encapsulation)
0467         skb_set_inner_mac_header(skb, nhoff);
0468 
0469     ptype = gro_find_complete_by_type(type);
0470     if (ptype != NULL)
0471         err = INDIRECT_CALL_INET(ptype->callbacks.gro_complete,
0472                      ipv6_gro_complete, inet_gro_complete,
0473                      skb, nhoff + sizeof(*eh));
0474 
0475     return err;
0476 }
0477 EXPORT_SYMBOL(eth_gro_complete);
0478 
0479 static struct packet_offload eth_packet_offload __read_mostly = {
0480     .type = cpu_to_be16(ETH_P_TEB),
0481     .priority = 10,
0482     .callbacks = {
0483         .gro_receive = eth_gro_receive,
0484         .gro_complete = eth_gro_complete,
0485     },
0486 };
0487 
0488 static int __init eth_offload_init(void)
0489 {
0490     dev_add_offload(&eth_packet_offload);
0491 
0492     return 0;
0493 }
0494 
0495 fs_initcall(eth_offload_init);
0496 
0497 unsigned char * __weak arch_get_platform_mac_address(void)
0498 {
0499     return NULL;
0500 }
0501 
0502 int eth_platform_get_mac_address(struct device *dev, u8 *mac_addr)
0503 {
0504     unsigned char *addr;
0505     int ret;
0506 
0507     ret = of_get_mac_address(dev->of_node, mac_addr);
0508     if (!ret)
0509         return 0;
0510 
0511     addr = arch_get_platform_mac_address();
0512     if (!addr)
0513         return -ENODEV;
0514 
0515     ether_addr_copy(mac_addr, addr);
0516 
0517     return 0;
0518 }
0519 EXPORT_SYMBOL(eth_platform_get_mac_address);
0520 
0521 /**
0522  * platform_get_ethdev_address - Set netdev's MAC address from a given device
0523  * @dev:    Pointer to the device
0524  * @netdev: Pointer to netdev to write the address to
0525  *
0526  * Wrapper around eth_platform_get_mac_address() which writes the address
0527  * directly to netdev->dev_addr.
0528  */
0529 int platform_get_ethdev_address(struct device *dev, struct net_device *netdev)
0530 {
0531     u8 addr[ETH_ALEN] __aligned(2);
0532     int ret;
0533 
0534     ret = eth_platform_get_mac_address(dev, addr);
0535     if (!ret)
0536         eth_hw_addr_set(netdev, addr);
0537     return ret;
0538 }
0539 EXPORT_SYMBOL(platform_get_ethdev_address);
0540 
0541 /**
0542  * nvmem_get_mac_address - Obtain the MAC address from an nvmem cell named
0543  * 'mac-address' associated with given device.
0544  *
0545  * @dev:    Device with which the mac-address cell is associated.
0546  * @addrbuf:    Buffer to which the MAC address will be copied on success.
0547  *
0548  * Returns 0 on success or a negative error number on failure.
0549  */
0550 int nvmem_get_mac_address(struct device *dev, void *addrbuf)
0551 {
0552     struct nvmem_cell *cell;
0553     const void *mac;
0554     size_t len;
0555 
0556     cell = nvmem_cell_get(dev, "mac-address");
0557     if (IS_ERR(cell))
0558         return PTR_ERR(cell);
0559 
0560     mac = nvmem_cell_read(cell, &len);
0561     nvmem_cell_put(cell);
0562 
0563     if (IS_ERR(mac))
0564         return PTR_ERR(mac);
0565 
0566     if (len != ETH_ALEN || !is_valid_ether_addr(mac)) {
0567         kfree(mac);
0568         return -EINVAL;
0569     }
0570 
0571     ether_addr_copy(addrbuf, mac);
0572     kfree(mac);
0573 
0574     return 0;
0575 }
0576 
0577 static int fwnode_get_mac_addr(struct fwnode_handle *fwnode,
0578                    const char *name, char *addr)
0579 {
0580     int ret;
0581 
0582     ret = fwnode_property_read_u8_array(fwnode, name, addr, ETH_ALEN);
0583     if (ret)
0584         return ret;
0585 
0586     if (!is_valid_ether_addr(addr))
0587         return -EINVAL;
0588     return 0;
0589 }
0590 
0591 /**
0592  * fwnode_get_mac_address - Get the MAC from the firmware node
0593  * @fwnode: Pointer to the firmware node
0594  * @addr:   Address of buffer to store the MAC in
0595  *
0596  * Search the firmware node for the best MAC address to use.  'mac-address' is
0597  * checked first, because that is supposed to contain to "most recent" MAC
0598  * address. If that isn't set, then 'local-mac-address' is checked next,
0599  * because that is the default address.  If that isn't set, then the obsolete
0600  * 'address' is checked, just in case we're using an old device tree.
0601  *
0602  * Note that the 'address' property is supposed to contain a virtual address of
0603  * the register set, but some DTS files have redefined that property to be the
0604  * MAC address.
0605  *
0606  * All-zero MAC addresses are rejected, because those could be properties that
0607  * exist in the firmware tables, but were not updated by the firmware.  For
0608  * example, the DTS could define 'mac-address' and 'local-mac-address', with
0609  * zero MAC addresses.  Some older U-Boots only initialized 'local-mac-address'.
0610  * In this case, the real MAC is in 'local-mac-address', and 'mac-address'
0611  * exists but is all zeros.
0612  */
0613 int fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr)
0614 {
0615     if (!fwnode_get_mac_addr(fwnode, "mac-address", addr) ||
0616         !fwnode_get_mac_addr(fwnode, "local-mac-address", addr) ||
0617         !fwnode_get_mac_addr(fwnode, "address", addr))
0618         return 0;
0619 
0620     return -ENOENT;
0621 }
0622 EXPORT_SYMBOL(fwnode_get_mac_address);
0623 
0624 /**
0625  * device_get_mac_address - Get the MAC for a given device
0626  * @dev:    Pointer to the device
0627  * @addr:   Address of buffer to store the MAC in
0628  */
0629 int device_get_mac_address(struct device *dev, char *addr)
0630 {
0631     return fwnode_get_mac_address(dev_fwnode(dev), addr);
0632 }
0633 EXPORT_SYMBOL(device_get_mac_address);
0634 
0635 /**
0636  * device_get_ethdev_address - Set netdev's MAC address from a given device
0637  * @dev:    Pointer to the device
0638  * @netdev: Pointer to netdev to write the address to
0639  *
0640  * Wrapper around device_get_mac_address() which writes the address
0641  * directly to netdev->dev_addr.
0642  */
0643 int device_get_ethdev_address(struct device *dev, struct net_device *netdev)
0644 {
0645     u8 addr[ETH_ALEN];
0646     int ret;
0647 
0648     ret = device_get_mac_address(dev, addr);
0649     if (!ret)
0650         eth_hw_addr_set(netdev, addr);
0651     return ret;
0652 }
0653 EXPORT_SYMBOL(device_get_ethdev_address);