Details of TCP/IP 2: Implementation -- IP Multicast

Source: Internet
Author: User
Tags switch case

Class d ip addresses (224.0.0.0 to 239.255.255.255) do not recognize a single interface on the Internet, but recognize an interface group, which is called multicast groups.

Members of a single network use the IGMP protocol to communicate with each other. Multicast Routing Protocol for multicast routers, such as dvmrp (Distance Vector Multicast

Routing Protocol, Distance Vector multicast routing selection protocol) transmits member information.

In net/3, if an interface supports multicasting, The if_flags mark iff_multicast bit in the IFNet structure of the interface is opened.

RFC 1112 describes the Host Requirements for multicast in three levels:

Level 0: the host cannot send or accept IP addresses.

Compromise the host should automatically discard the group with the D-type destination address it receives.

Level 1: The host can send but cannot accept IP multicast.

Before sending a datagram to an IP multicast group, the host is not required to join the group. Multicast datagram is sent in the same way as unicast, except for the destination address of multicast Datagram

Is outside of the IP multicast group. The network drive must be able to recognize this address.

Level 2: The host can send and receive IP Multicast

To receive IP multicast, the host must be able to join or leave Multicast Groups, and IGMP must be supported to exchange group member information on at least one interface. Multi-interface host

It must support multicast on a subnetwork of its interface. NET/3 meets the requirements of level 2 hosts. It can complete multicast router work.


The same as the UDP and TCP port numbers, the Internet authorization organization IANA (Internet Assigned Numbers Authority) maintains a registered IP multicast group table.

Only some well-known multicast groups are provided.


All 256 groups (224.0.0.0 to 224.0.0.255) are reserved for protocols that implement IP Unicast and multicast routing. No matter the IP address in the datagram sent to any group

How does the TTL value of the first vro change? The multicast router will not send it to the local network.

For a Level 2 system, it is required to add the 224.0.0.1 group to all multicast interfaces during system initialization, and keep the group members until the system is shut down.

Unicast and multicast routes may be added to the 224.0.0.2 group for mutual communication. ICMP router request messages and router announcements may be sent to 224.0.0.2 (all

Vro) and 224.0.0.1 (all hosts), instead of the restricted broadcast address (255.255.255.255 ).

The 224.0.0.4 group supports communication between dvmrp multicast routers.


1. Ethernet multicast address

The efficient implementation of IP multicast requires that IP addresses make full use of hardware-level multicast. Because there is no hardware-level multicast, each multicast IP datagram has to be broadcast on the network, and each host

You also have to check each datagram and discard what is not for it. The hardware filters out useless data before it reaches the IP layer.

To ensure that the hardware filter works properly, the network interface must convert the IP multicast Destination Address to the link-level multicast address recognized by the network hardware. In Ethernet

A function that explicitly maps addresses. The standard Ethernet ing applies to any network that uses 802.3 addressing.

Because Ethernet supports multiple protocols, You need to allocate multicast addresses to avoid conflicts. IEEE manages Ethernet multicast address allocation. IEEE multicast over Ethernet

The IP address is assigned to IANA to support IP multicast. The block address must start with 01: 00: 5E. Ethernet unicast instances starting with 00: 00: 5E will also be allocated to iana, but for the future

Use reservation. It shows that an Ethernet multicast address is constructed from a class d ip address.



2. ether_multi Structure

NET/3 maintains an Ethernet multicast address range table received by the hardware for each Ethernet interface. This table defines the multicast filtering implemented by the device. Because most

The IP address that can be selectively received by an Ethernet device is limited. Therefore, the IP layer must discard the data packets that have passed the hardware filter. The address range is stored in ether_multi.

Structure.


Enm_addrlo and enm_addrhi specify the range of Ethernet multicast addresses to be received. When enm_addrlo and enm_addrhi are the same, an Ethernet

Address. The complete list of ether_multi is attached to the arpcom structure of each Ethernet interface, indicating that there are three Lance interfaces in the ether_multi structure.


The interface has been added to three groups, which may be 224.0.0.1 (all hosts), 224.0.0.2 (all routers), and 224.0.1.2 (SGI-dogfight ). Because Ethernet

The ing to an IP address is one-to-multiple, so you cannot determine the IP address. The interface may also be added to groups 225.0.0.1, 225.0.0.2, and 225.0.1.2.


3. Ethernet Multicast Reception

In net/3, the system may also be configured to receive all Ethernet groups. Although the IP protocol family is not used, other kernel protocol families may be prepared to receive these multicast packets.

Group. You can run the ioctl command to explicitly configure multicast.


These two commands are directly passed to the device driver (IFP-> if_ioctl) of the interface)


4. in_multi Structure

The Ethernet multicast data structure is not dedicated to IP addresses. They must support multicast activities in any protocol family of all kernels. At the network level, an IP maintainer is related to an interface.

IP multicast group table.

For convenience, the IP multicast table is attached to the in_ifaddr structure related to this interface. This structure contains the unicast address of this interface. Except

In addition to the same interface, this Unicast address has no relationship with the attached multicast group table.

The in_multi structure of describes each IP multicast {interface, group} pair.


The interface instance le_softc [0] shows the interface, that is, the relationship between its Unicast address and its IP address before multicast table.


The ether_multi structure is omitted in the figure.


5. ip_moptions Structure

The Transport Layer controls multicast output processing through the multicast options contained in the ip_moptions structure. For each output datagram, you can send ip_moptions to ip_output.

Structure. Shows the structure of ip_moptions:


Imo_multicast_ifp selects the routes for the output multicast data packets. If imo_multicast_ifp is empty, the default Interface of the target station multicast group is used.

Imo_multicast_ttl specifies the initial ip ttl for outbound multicast data packets. The default value is 1.

If the imo_multicast_loop is 0, no datagram is returned or submitted to the interface being sent. Even if the interface is a member of a multicast group

If the interface being sent is a member of the multicast group, the multicast datagram is sent back to the interface.

Finally, the integer imo_num_memberships and the array imo_membership maintain the {interface, group} pairs related to the structure. All changes to this table are reported.

To the IP address, the IP address declares changes to the Members on the connected local network. Each entry of the imo_membership array points to an in_multi structure pointer,

The in_multi structure is attached to the in_ifaddr Structure of the appropriate interface.


6. multicast plug-in Options

Displays several IP-level plug-in options that provide processes and access to the ip_moptions structure.


All multicast options are processed by ip_setmoptions and ip_getmoptions functions. ip_setmoption is a switch case for each option.

Call functions for processing.


7. multicast TTL value

The TTL of multicast has two functions. The basic function is to restrict the lifetime of an IP group over the Internet, and avoid loop over the network. Second

The role is to restrict the group to the region of the Internet specified by the management boundary.

The multicast router also associates a TTL threshold value with each interface to restrict Multicast Transmission on this interface. A group to be transmitted on this interface must have a value greater than or

The TTL equal to the threshold value of this API. Therefore, multicast groups may be discarded before the TTL reaches 0.

The value assigned by the Administrator When configuring the multicast router at the threshold value determines the domain of the multicast group. Displays the recommended TTL values and recommendations for a variety of applications

.



8. Add an IP multicast group

Except for all hosts with IP addresses automatically added to the kernel, other group members are generated by explicitly sending requests from the process. Joining or leaving multicast groups has more options than other options.

. You must modify the in_multi table of the interface and other link layer multicast structures, such as ether_multi.

When optname is ip_addmembership, the data in the mbuf is shown in ip_mreq:


The ip_mreq structure specifies {interface, group} pairs to indicate Member changes.

Shows the function called when joining multicast groups related to the example of leaving our Ethernet interface.


For the ip_add_membership option, the general process of ip_setmoptions is as follows:

1. Verify. Checks input parameters.

Bytes

2. Find the interface. If the imr_interface in mreq is inaddr_any, you must find the default Interface of the specified group. The rtalloc function finds

Router; if the imr_interface is not inaddr_any, a clear interface is requested to search for the interface based on the provided address.

Bytes

3. Already a member? Check the imo_membership array to see if the selected interface is already a member of the Request group. If a match is found, or the member is full,

Terminate the processing of this option.

Bytes

4. Join multicast groups. Call the in_addrmulti function to join multicast groups.


8.1.in _ addrmulti Function

The in_addrmulti and in_delmulti Function Maintenance interfaces are added to multicast groups. Add a request or add a new in_multi structure to the interface table, or add

The number of times an existing structure is referenced. (This function is used to add multicast groups at the protocol layer)

The approximate process of the function is as follows:

1. If it is already a member, the in_multi structure corresponding to the member will be found, and the reference count will be updated and returned.

Bytes

2. If the interface is not a member, in_addrmulti will be allocated and a new in_multi structure will be initialized, and the structure will be inserted into the ia_multiaddrs structure of the in_ifaddr structure of the interface.

The front-end of the table.

Bytes

3. Update the API to notify you of changes. If the interface driver has defined an if_ioctl function, this function is called. Finally, in_addrmulti calls igmp_joingroup,

Spread the member change information to other hosts and routers.


8.2.leioctl functions: siocaddmulti and siocdelmulti

For the lance Ethernet interface, the if_ioctl function pointer points to the leioctl function. In the leioctl function, for the siocaddmulti and siocdelmulti options,

Call the ether_addmulti and ether_delmulti functions respectively.


8.3.ether _ addmulti Function

The ether_addmulti function is used to add multicast groups at the interface layer. This function maps IP Class D addresses to appropriate Ethernet addresses and updates ether_multi

Table. The approximate process of the function is as follows:

1. initialize the address range. Ether_addmulti initializes the multicast address ranges in addrlo and addrhi. If the requested address is from the af_unspec family,

Ether_addmulti assumes that the address is a clear Ethernet multicast address and copies it to addrlo and addrhi. If the address belongs to the af_inet family, and

Is inaddr_any, ether_addmulti initializes addrlo to e1__ipmulticast_min, and initializes addrhi to ether_ipmulticast_max.

The two ether address constants are defined:

Bytes

2. received. Ether_addmulti checks the multicast bits of high and low addresses to ensure they are real Ethernet multicast addresses. Then determine whether the hardware has been

Start listening to the specified address. If yes, the reference count (enm_refcount) that matches the ether_multi structure is increased ).

Bytes

3. Update the ether_multi table. If it is a new address range, allocate and initialize a new ether_multi structure and link it to the arpcom structure of the interface.

On the ac_multiaddrs table, the final function is returned. Based on the returned value, the device driver knows that the multicast table has been changed and must update the hardware receiving filter.

The relationship between the ip_moptions, in_multi, and ether_multi structures after the lance Ethernet interface is added to the Host group is displayed.



9. Leave an IP multicast group

Generally, when a multicast group is left, the steps for adding a multicast group are in reverse order. Update the member table and in_multi table of the IP interface in the ip_moptions structure.

And the device's ether_multi table.

We return to the ip_drop_membership statement in ip_setmoptions. Use the requested {interface, group} in the statement to find an in_multi

Structure. If yes, call in_delmulti to update the in_multi table, call igmp_leavegroup (without any operation), and call the if_ioctl function pointer

To delete the ether_multi structure.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.