Acquisition of multicast MAC address in Linux NIC driver

Source: Internet
Author: User

For a 2.6 kernel, there is a struct pointer inside the Net_device,
struct dev_mc_list *dev->mc_listBy accessing it, you can loop through all of the multicast MAC addresses.

However, the new kernel (at least 3.10) has changed, instead
struct netdev_hw_addr_list mc;

We can obtain the corresponding data by directly accessing the MC, or we can take advantage of the macros provided by the Linux kernel.

netdev_mc_count(dev)This macro can get the current total number of multicast MAC addresses, the specific macro definition is as follows:

#define netdev_mc_count(dev) netdev_hw_addr_list_count(&(dev)->mc)

netdev_for_each_mc_addrProvides a looping way to get all the multicast Mac
The specific macro definition is as follows:

#define netdev_for_each_mc_addr(ha, dev)netdev_hw_addr_list_for_each(ha, &(dev)->mc)

Ha is a netdev_hw_addr struct with an array inside to unsigned char addr[MAX_ADDR_LEN]; store the MAC address
Here are some of the code

struct netdev_hw_addr {       struct list_head        list;       char           addr[MAX_ADDR_LEN];      char           type;}

List_head is a doubly linked list of Linux implementations in the kernel, and netdev_hw_addr_list_for_each it is access to such a list.

We can look at it in detail.netdev_hw_addr_list_for_each

#define&(l)->listlist)

and list_for_each_entry

#define list_for_each_entry(pos, list, member) \
for (pos = list_head(list, typeof(*pos), member); \
&pos->member != (list); \
pos = list_next(pos, member))

So netdev_for_each_mc_addr the essence of that is a for loop.

Acquisition of multicast MAC address in Linux NIC driver

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.