For a 2.6 kernel, there is a struct pointer inside the Net_device,
struct dev_mc_list *dev->mc_list
By 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_addr
Provides 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