In the previous two sections, we analyzed the IGMP snooping process based on the IGMP snooping code implemented in linux2.6.32.
This section analyzes the functionality required to implement IGMP snooping based on the first two sections
One, data structure
For the implementation of a sub-layer function, the most important is the establishment of data structures. For IGMP snooping, the relationship between the data structures we need to build is
1. A multicast group can be associated with multiple bridge ports
2. A bridge port can be associated with multiple multicast groups
3. A bridge port is associated with only one bridge
4, for the bridge port, there are LAN side bridge port and Wan side bridge port points
5, multicast group data items how to link (can be achieved through the linked list)
6. How to use a bridge port to quickly find all the multicast groups it joins
7, how to through a multicast group data items, quickly find to join to the multicast group of all bridge ports
According to the above conditions, we can construct the corresponding multicast group data structure to meet the above requirements. For a subsystem, the data structure can best reflect the quality of the function, so our data structure needs to consider as much as possible
various conditions.
2. Function realization
1, for the IGMP message processing, for IGMP to join the message, we need to create the corresponding multicast group data items, and then send the message to be added.
For a multicast group that has already been created, we need the appropriate expiration timer and the Send query timer to maintain the update operation of the multicast group database.
2, for the leave message, you need to delete the corresponding multicast group database entries and so on.
3. For LAN side Bridge port and Wan side bridge port, it receives or sends the type limit of IGMP message.
4, provide the external interface, for the two-layer received multicast streaming data, to determine whether the need to forward to the corresponding one or more ports
5, provides the multicast snooping function to turn on or closes the interface function to supply uses the layer to call
6. Create a subdocument in the/proc directory to view the bridge ports and multicast group information that is currently joined to the multicast group for debugging purposes.
7, the code implementation of the use of macros to strictly separate the IGMP snooping function, when the IGMP snooping function is not compiled, to ensure that the kernel can work correctly.
If we implement the IGMP snooping function ourselves, we should be able to implement the IGMP snooping function simply by considering the above general situation. In the actual implementation, for each
Functions we have detailed design, increase the judgment conditions, etc., so that the final implementation of our own IGMP snooping function should also be OK.
It is much easier to read the implementation code of the Linux IGMP snooping, depending on the overall requirements above. For reading the Linux kernel code, our main point is to understand the implementation principle.
If we read the function of a subsystem after the implementation of the process, take a moment to think about its implementation principles and requirements, should be our usual code design will be a great help.