Multicast Listener Discovery
The Treck Multicast Listener Discovery (MLD) option allows an IPv6 socket to receive multicast data in the same way that the Internet Group Management Protocol (IGMP) option allows an IPv4 socket to receive multicast data. An IPv6 socket sends multicast data by directing datagrams to a destination address of the form FF00::/8 (see RFC 4291 - IPv6 Addressing Architecture). For example, you would send to destination address FF02:0:0:0:0:0:0:2 (FF02::2) if you wanted to get a message to all routers on the same link as your node. A socket uses MLD to join a multicast group so that it can receive datagrams that have been sent to specific multicast groups. The MLD code will communicate with the routers on the link to make sure that multicast datagrams of interest are forwarded on the link.
Currently, the MLD specification is at version 2 (MLDv2). The source-specific filtering enhancements added in RFC 3810 (MLDv2) are discussed in detail on the Treck MLDv2 page. The following discussion focuses on the basic MLD version 1 capabilities, as described in RFC 2710.
To enable MLD for IPv6, uncomment the following macros in trsystem.h:
To enable Source Address Selection for MLD (RFC 3590), uncomment the following macro in trsystem.h. During address configuration, multicast reports will be sent with the unspecified address (::) as the source address. Routers will probably discard these reports based on the source address. This option will cause the multicast reports to be resent when Duplicate Address Detection has successfully completed.
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:
For devices that support and filter link layer multicast addresses (most Ethernet drivers), you must provide a driverIoctl function with your device driver. As sockets join and leave multicast groups, Treck will call the device's driverIoctl function with the TM_DEV_SET_MCAST_LIST or TM_DEV_SET_ALL_MCAST flag to enable reception of the associated multicast Ethernet addresses. In response, you must configure your hardware to be able to receive packets for the specified multicast addresses. See Adding a Device Driver and drvIoctlFunc() for details.
You must designate an interface for outgoing multicast packets. The following methods are available:
- Use tf6SetMcastInterface() to set the default multicast interface for all sockets.
- Use the setsockopt() IPV6_MULTICAST_IF option with protocolLevel set to IPPROTO_IPV6 to set the multicast interface for the specified socket. This overrides any default multicast interface established by the first method.
Sending Multicast Packets
By default, the IPv6 layer will send a multicast packet with a Hop Limit of 1, which limits the packet's travel to the adjacent network. Use the setsockopt() IPV6_MULTICAST_HOPS option with protocolLevel set to IPPROTO_IPV6 to increase the Hop Limit and the distance that you can send a multicast packet. You should also choose a multicast destination address with scope higher than link-local (e.g. global scope), since routers may not forward node-local and link-local multicast packets (see RFC 4291 - IPv6 Addressing Architecture).
Receiving Multicast Packets
You configure a socket to receive datagrams sent to a particular multicast group by joining the multicast group. You stop receiving datagrams on a multicast group when you leave the group or close the socket. The multicast group is identified by its IPv6 multicast address.
You must specify an interface index when identifying an IPv6 multicast group. You can use if_nametoindex() to retrieve the index for your device. Alternatively, you can specify an interface index of zero to use the default multicast interface that you set when you called tf6SetMcastInterface().
To join or leave an IPv6 multicast group, call setsockopt() with a protocol level of IPPROTO_IPV6 and an appropriate option name for the desired operation. There are two sets of options for joining and leaving multicast groups. Refer to setsockopt() - IPv6 Level Options for the API details of each option.
- 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.
- 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.
Error results are listed on the setsockopt() page.
The following multicast addresses are pre-defined; you do not have to join the group to receive data on the group. See RFC 4291, section 2.7.1 for details.
- FF01::1 - all nodes address with interface-local scope. Interface-local scope spans only a single interface on a node and is useful only for loopback transmission of multicast data.
- FF02::1 - all nodes address with link-local scope. Link-local scope spans a single link.
Multicast Loopback Option
By default, Treck will send multicast datagrams without checking to see if any local sockets are members of the destination multicast group. In compliance with section 5.2 of RFC 3493, Treck has provided the capability for local sockets to receive a copy of the multicast datagram that you are sending. To enable this option, you must:
- Enable the necessary Treck code by defining TM_6_USE_MULTICAST_LOOP in trsystem.h and recompile the Treck code.
- Use the setsockopt() IPV6_MULTICAST_LOOP option to enable loopback multicast reception for each socket that needs to receive multicast data that you send.
Treck implements the following MLD-related specifications:
- RFC 2710 - MLD (for Multicast Address Listeners only; the Multicast Router part is not implemented).
- RFC 3493 - Basic Socket Interface Extensions for IPv6 (section 5.2).
- RFC 3590 - Source Address Selection for MLD.
- RFC 3678 - Socket Interface Extensions for Multicast Source Filters (MCAST_JOIN_GROUP and MCAST_LEAVE_GROUP).