Multicast Listener Discovery version 2

(Redirected from MLDv2)
Jump to: navigation, search

Table of Contents >> IPv6 Programmer's Reference


The Treck Multicast Listener Discovery version 2 (MLDv2) option is an enhancement to the Treck Multicast Listener Discovery (MLD) option. MLD allows an IPv6 socket to receive multicast data. MLDv2 allows the socket to filter the incoming multicast data based on who sent it. MLDv2 provides the same functionality for IPv6 that Internet Group Management Protocol version 3 (IGMPv3) provides for IPv4.

A socket that uses MLDv2 will have a list of zero or more unicast IPv6 addresses and a Filter Mode. The address list provides the list of source or host addresses to include or exclude, based on the filter mode. When the filter mode is include, multicast data will be received only from the hosts in the source address list. When the filter mode is exclude, multicast data will be received from any host except those in the source address list.

A socket may have different source list and filter modes for each multicast group to which it belongs, but it may have only one source list and filter mode per group. The user may change the source list and filter mode for a given multicast group without closing and reopening the socket.

Each interface will have it's own internal source filters based on the collective source filters of all sockets that receive multicast data on the interface. The user does not have direct access to the source filters in the interface.

Code Configuration

To enable MLDv2 for IPv6, uncomment the following macros in trsystem.h:

Source Address Selection for MLD (RFC 3590) is inherently supported in MLDv2 (see RFC 3810 section 5.2.13), so you do not have to define TM_USE_RFC_3590.

RFC 3493 describes the IPV6_MULTICAST_LOOP socket option, which allows local sockets to receive multicast datagrams that you send, if they have joined the group. To enable support for this socket option, uncomment the following macro in trsystem.h:

Interface Requirements

Refer to the same section in the Treck MLD Option.

Initialization

The following MLDv2 attributes control the maximum source list size for sockets and interfaces. Call tfInitTreckOptions() or tfSetTreckOptions() to change the default values. Refer to the pages for those functions for more details.

Option Name Default Value Description
TM_6_OPTION_MLD_SO_MAX_SRC_FILTER 64
(TM_SO_MAX_SOURCE_FILTER)
The maximum number of IPv6 addresses per source list per socket. There is one source list per multicast group and a socket may belong to more than one multicast group.
TM_6_OPTION_MLD_IP_MAX_SRC_FILTER 128
(TM_IP_MAX_SOURCE_FILTER)
The maximum number of IPv6 addresses per source list per interface. There is one source list per multicast group and an interface may belong to more than one multicast group.

In the table above, the internal Treck macro that represents the default value is shown in parentheses. These macros are not part of the public API. However, you may define either or both in trsystem.h and your defined values will become the system-wide defaults. Of course, you are still free to change the default values at runtime by calling tfInitTreckOptions() or tfSetTreckOptions(). Note that these internal macros are also shared with IGMPv3.

Sending Multicast Packets

Sending multicast packets is the same for MLDv2 as it is for MLD. Refer to section MLD - Sending Multicast Packets.

Receiving Multicast Packets with Source Filtering

When you configure an IPv6 socket to receive multicast data you can provide information about who you do or do not wish receive data from. This is called source filtering. If you have no need to source filter the multicast data that you receive, please refer to MLD regarding the multicast group join and leave operations. The following discussion deals specifically with the source filtering multicast API for MLDv2.

Treck provides several alternatives for socket layer support of MLDv2, in accordance with RFC 3678. The following sections discuss each alternative.

  1. Basic (Delta-based) API
    • setsockopt() allows you to manipulate a multicast group's source list one entry one at a time. Call setsockopt() to add or remove a source address for a multicast group. You cannot change the filter mode of an existing source list with this API and getsockopt() is not supported.
  2. Advanced (Full-state) API

All APIs act on a specific socket and a specific multicast group within that socket.

For all APIs, you must specify an interface index when identifying an IPv6 multicast group. You can use if_nametoindex() to retrieve the index for your device or, alternatively, you can specify an interface index of zero to use the default multicast interface if you have successfully set the default interface with tf6SetMcastInterface() or setsockopt() IPV6_MULTICAST_IF.

Using setsockopt() to Manage Multicast Source Filters

You can use setsockopt() with a protocol level of IPPROTO_IPV6 to add or remove IPv6 hosts to/from a source list for a given IPv6 multicast group. You can only specify one source address per call to setsockopt(), which is why this method is referred to as delta-based.

Within the Basic (Delta-based) API, there are typically two different kinds of applications:

  1. Any-Source Multicast - By default, all sources are accepted. Individual sources may be blocked or unblocked as needed. We use the exclude filter mode, in this case.
  2. Source-Specific Multicast - Only sources in a given list are allowed. Individual sources may be added or removed as needed. We use the include filter mode, in this case.

Separate from the application type, there are two sets of setsockopt() options available for multicast group management. API details on specific options can be found in setsockopt() - IPv6 Level Options.

  1. Protocol-independent socket options as discussed in RFC 3678, section 5.
    • Use MCAST_JOIN_GROUP to join an IPv6 or IPv4 multicast group.
    • Use MCAST_LEAVE_GROUP to leave an IPv6 or IPv4 multicast group.
    • Use MCAST_JOIN_SOURCE_GROUP to join (or add to) a source-specific IPv6 or IPv4 multicast group.
    • Use MCAST_LEAVE_SOURCE_GROUP to leave (or remove from) a source-specific IPv6 or IPv4 multicast group.
    • Use MCAST_BLOCK_SOURCE to mute a source in an any-cast IPv6 or IPv4 multicast group.
    • Use MCAST_UNBLOCK_SOURCE to unmute a source in an any-cast IPv6 or IPv4 multicast group.
  2. IPv6-specific socket options as discussed in RFC 3493, section 5.2.
    • Use IPV6_JOIN_GROUP to join an IPv6 multicast group.
    • Use IPV6_LEAVE_GROUP to leave an IPv6 multicast group.
    • Use IPV6_MULTICAST_IF to set the default interface to use for IPv6 multicast I/O. You can also use tf6SetMcastInterface().
    • Use IPV6_MULTICAST_HOPS to set the Hop Limit (IPv6 header field) to use for outbound multicast packets. By default, this value is 1, which is suitable for link-local traffic.
    • Use IPV6_MULTICAST_LOOP to enable loopback of multicast packets that you send. Refer to MLD - Multicast Loopback Option.

The following table shows the data structures used by different setsockopt() options for managing a multicast group. Each structure contains the IPv6 multicast group address and interface index. An IPv6 source address is contained in the structure used to manage the group source list. Click on the associated links to view more detailed information.

Structures Used by setsockopt() Options
Socket Option Structure name
MCAST_JOIN_GROUP,
MCAST_LEAVE_GROUP
group_req
MCAST_BLOCK_SOURCE,
MCAST_UNBLOCK_SOURCE,
MCAST_JOIN_SOURCE_GROUP,
MCAST_LEAVE_SOURCE_GROUP
group_source_req
IPV6_JOIN_GROUP,
IPV6_LEAVE_GROUP
ipv6_mreq

The join operation is implicit, when adding the first source address. If the socket is not yet a member of the multicast group, the membership will be created along with source filter appropriate for the requested operation. The following table shows the resulting filter mode for the given, first-time operation:

Results of First Call on a New Group Membership
Socket Option Used Filter Mode Filter Type Source List
MCAST_JOIN_GROUP,
IPV6_JOIN_GROUP
MCAST_EXCLUDE Any-source Empty
MCAST_BLOCK_SOURCE MCAST_EXCLUDE Any-source One source address, user-specified
MCAST_JOIN_SOURCE_GROUP MCAST_INCLUDE Source-specific One source address, user-specified
MCAST_LEAVE_GROUP,
IPV6_LEAVE_GROUP,
MCAST_LEAVE_SOURCE_GROUP,
MCAST_UNBLOCK_SOURCE
Invalid Operation

Once you have established a filter mode for a multicast group, you must continue to use the socket options that correspond to that type of filter. For example, you cannot use MCAST_JOIN_SOURCE_GROUP to create a source-specific membership with a single source, then use MCAST_BLOCK_SOURCE to remove that source from the list. You must use MCAST_LEAVE_SOURCE_GROUP.

Similarly, but not as obvious, you cannot use MCAST_JOIN_GROUP to create an any-source membership with an empty source list, then use MCAST_JOIN_SOURCE_GROUP to install the first source in the list.

Note Note: The only way to create a source-specific multicast group with setsockopt() is by using the MCAST_JOIN_SOURCE_GROUP option on a multicast group that does not exist in the socket.


Using setsourcefilter() and getsourcefilter() to Manage Multicast Source Filters

Use setsourcefilter() to set the source list and filter mode for a multicast group in a socket. If the socket is not a member of the group, the membership will be created. If the socket is already a member of the group, the previous filter mode and source list will be replaced. Refer to the setsourcefilter() page for API details.

Use getsourcefilter() to extract the current source list and filter mode for a multicast group in a socket. Refer to the getsourcefilter() page for API details.

Using tfIoctl() to Manage Multicast Source Filters

Use tfIoctl() option SIOCSMSFILTER to set the source list and filter mode for a multicast group in a socket. If the socket is not a member of the group, the membership will be created. If the socket is already a member of the group, the previous filter mode and source list will be replaced.

Use tfIoctl() option SIOCGMSFILTER to extract the current source list and filter mode for a multicast group in a socket.

Structure group_filter is used to transfer multicast group information to and from tfIoctl().

Refer to tfIoctl() - SIOCSMSFILTER and SIOCGMSFILTER Notes() for complete API details.

Note Note: Use of tfIoctl() SIOCSMSFILTER / SIOCGMSFILTER() is deprecated. setsourcefilter() and getsourcefilter() provide the same functionality and are the preferred alternative.


Changing the Robustness Variable for an Interface

RFC 3810 section 9.14.1 describes the Robustness Variable as a way of tuning the MLD retransmission count to expect packet loss on the link. When you join or leave a multicast group or change the source address filter for a group, MLD will report the change twice, by default. You should never set the Robustness Variable to less than 2.

Define macro TM_6_MLD_DEF_ROBUSTNESS in trsystem.h to change the default Robustness Variable inherited by all interfaces. For example, add the following definition to trsystem.h to transmit MLD state change reports 3 times:

#define TM_6_MLD_DEF_ROBUSTNESS 3

Call tfInterfaceSetOptions() with option TM_6_DEV_OPTIONS_MLD_ROBUSTNESS to change the default Robustness Variable for a given interface. This change does not affect MLD report transmissions currently in progress. For maximum benefit, you should change the Robustness Variable prior to opening the interface. As an example, the following code causes subsequent MLD state change reports to be sent 5 times for interface interfaceHandle:

        unsigned char   temp8;
        int             errorCode;
 
            .
            .
            .
 
        temp8 = 5;
        errorCode = tfInterfaceSetOptions(interfaceHandle,
                                          TM_6_DEV_OPTIONS_MLD_ROBUSTNESS,
                                          &temp8,
                                          sizeof(temp8));
        if (errorCode != TM_ENOERROR)
        {
            /* Error */
        }
Note Note: The Robustness Variable may change if an interface receives a Multicast Listener Query Message with a new QRV (Querier's Robustness Variable).


Multicast Loopback Option

Refer to the same section in the Treck MLD Option.

Implementation Notes

Treck implements the following MLDv2-related specifications:

  • RFC 3810 - MLDv2 (for Multicast Address Listeners only; the Multicast Router part is not implemented).
  • RFC 3678 - Socket Interface Extensions for Multicast Source Filters.
  • RFC 4604 - Using IGMPv3 and MLDv2 for Source-Specific Multicast.

Function Calls


Table of Contents >> IPv6 Programmer's Reference