MLD Implementation (IPv6 Multicasting) Part 2

Leaving a Group: mld6_stop_listening() Function

The mld6_stop_listening() function is called when a node leaves a multicast group and performs the state transition to Non-Listener in Figure 2-19. It sends a Multicast Listener Done message if it sent the latest Report message for the group.

Listing 2-5

Listing 2-5

 

 

 

 

Listing 2-5

439-452 all_sa is set to the All-Nodes link-local address. Similarly, allrouter_sa is set to the All-Routers link-local address. Function in6_embedscope() embeds the corresponding link zone ID into the 128-bit IPv6 address, which is the general form of scoped addresses in the KAME IPv6 stack.

458-463 If the node is responsible for sending a Multicast Listener Done message, indicated by its status, the multicast address is not the All-Nodes link-local address, and the multicast scope is larger than the interface-local scope, then mld6_sendpkt() is called to send an actual MLD message. The destination is the All-Routers multicast address.


Input Processing: mld6_input() Function

The mld6_input() function is called by the icmp6_input() function.It processes incoming MLD messages and maintains the corresponding listener state accordingly.

Packet Validation

Listing 2-6

Listing 2-6

 

 

 

 

Listing 2-6

490-491 The IP6_EXTHDR_CHECK() macro ensures that the first mbuf (m) contains the packet portion from the IPv6 header to the end of the MLD header for later operations.

503-520 The source address of an MLD message must be a link-local address or the unspecified address, according to [RFC3590] (see Section 2.3.3). The code drops the packet if the source address is neither of them. Although it may look like the correct implementation of [RFC3590], it does not actually conform to the specification: the RFC clarifies that the special case of the unspecified source address is for MLD snooping switches and specifies that hosts and routers simply discard such MLD messages. That is, the implementation should drop the message with the unspecified source address. This inconsistency was fixed in later versions of KAME snapshots.

In addition, the kernel logging about an unexpected source address is explicitly disabled because a flood of such unexpected messages may consume an unacceptable portion of system log files.

522-532 mc_sa is a sockaddr_in6{} structure initialized with the 128-bit multicast address retrieved from the MLD message. The appropriate multicast scope zone ID is determined from the receiving interface and is embedded into the address as the general form in the kernel.

Process Query

Listing 2-7

Listing 2-7

 

 

 

 

Listing 2-7

558-559 The message was sent by the local node and is looped back if the receiving interface is a loopback interface. The message is discarded in this case.

561-564 The message is discarded if neither the unspecified address nor a multicast address is specified.

565 all_sa is set to the All-Nodes link-local address for later use.

Listing 2-8

Listing 2-8

 

 

 

 

Listing 2-8

621—623 The timer interval is calculated based on the received value specified by the Maximum Response Delay field. It is converted to the timer count for the granularity of 200ms, and is set in the variable timer. If the advertised delay is positive but less than 200, timer is set to 0, effectively disabling the timer. In such a case, the variable is adjusted to 1 to activate the timer.

629—650 Each IPv6 multicast group address that the node has joined on the receiving interface is examined. The All-Nodes link-local multicast group and group addresses whose scope is smaller than link-local are ignored.

652—655 A query of the unspecified address as the multicast group is a general Query (Section 2.3.1) that matches all group addresses. Otherwise, only the matching multicast group is considered.

657—672 A Multicast Listener Report is sent immediately if the query has a 0 Maximum Response Delay. The timer is reset and the flag is set to MLD_lREPORTEDLAST. Otherwise, if the multicast entry is in the Idle state or a shorter timer value is specified, the timer is restarted. It corresponds to the state transition from Idle to Delaying Listener or the loop within the Delaying Listener state in Figure 2-19. A random factor is added to the timer value to avoid Report message flooding. The global variable mld_group_timers_are_running indicates there are active timers and the MLD timer function needs to service these timers.

Next post:

Previous post: