IGMP Version 2 uses a message format 32 bits in size, with three fields.
The first 8 bits are the type, the next 8 bits are the max response time, and the final 16 bits are a checksum.
This message is encapsulated inside of an IP packet with a protocol number of 2.
The message is sent into the network with the IP router alert flag set, and a time to live of 1. This means that the packet will not be forwarded outside of it’s own broadcast area, as the TTL would reach 0 and the packet would be dropped.
The type field in the message content describes the type of IGMP message that is being sent by the host or the router. There are five different types.
0x16: Version 2 Membership Report
This is also referred as an IGMP Join. Hosts use this message type to join a multicast group or to respond to their local routers membership query message.
0x12: Version 1 Membership Report
This message type is used for backwards compatibility to IGMP v1.
0x17: Version 2 Leave Group
Hosts use this message type to indicate that they wish to stop receiving multicast traffic for the group they joined.
0x11: General Membership Query
This message type is periodically sent to 184.108.40.206 to query whether there any hosts in the attached subnet. The group address field is set to 0.0.0.0
0x11: Group Specific Query
This message type is sent in response to a leave group message to the group address that a host requested to leave. The group address is the destination IP address of the IP packet and group address field.
Field: Max Response Time
This field is set in general and group-specific membership query messages (0x11).
It specifies the maximum amount of time before sending a response in units one-tenth of a second.
In other messages, this field is set to 0x00
The checksum is a 16-bit field, it is the standard checksum algorithm used in TCP/.IP
Field: Group Address
The field is set to 0.0.0.0 for query messages and is set to the multicast group address for group-specific messages.
Membership reports carry the address of the group being reported in this field.
When hosts leave a group, they carry the group address that they are leaving in this field.
Joining a Multicast Group
When the host wishes to join a multicast stream, it will send a membership report, more commonly known as an IGMP join, towards the local router for the group that the host wishes to join.
The local router will send this request upstream towards the source using a Protocol Independent Multicast (PIM) join message.
When that local router starts receiving messages and packets for that multicast group, the local router will forward them downstream towards the host.
Leaving a Multicast Group
When a host requests to leave a group, if it was the last host to respond to a query, the host sends a message to the all-routers multicast group at 220.127.116.11.
If the host was not the last host to respond to a membership query, then it can quietly leave the group – there is another host in that subnet that is participating in that group, so no need to notify the router.
If the router receives a notification, it will follow up with a membership query specific to that group back into the subnet. This is a check to see whether there are any members left in the subnet that participate in that multicast group.
If there are no members left, the router removes the IGMP state for that group.
Periodically the router of the subnet will sent a general membership query into the subnet, to the all-hosts address of 18.104.22.168 to see if there are any group members in the subnet. There is a max response time set on the message which is 10 seconds by default.
Hosts in response set a random timer between 0 and 10 seconds. When that timer expires the host will send a report back to the router detailing which multicast groups they belong too.
If another host in the group receives a report from another host for a group it belongs too, that host stops the timer and discards the report. This is meant to save duplicate reports from being sent.
If there is more than one IGMP enabled router on a LAN segment, a querier election takes place to determine which router will be the querier.
IGMPv2 routers send general membership queries with their interface IP address as the source IP address. When another IGMPv2 router receives that message, it will compare the source IP address and compare it to its own interface address. If their interface address is lower, it will elect itself as the IGMP querier.
All non-querier routers at this point will start a timer that resets each time they receive a membership query report from the querier router. The default timer is 60 seconds. A querier election is triggered if the timer reaches zero.