IGMP - Internet Group Management Protocol¶
pcapkit.protocols.internet.igmp contains
IGMP, the abstract base of the
Internet Group Management Protocol (IGMP) [*] versions 1, 2 and 3. IGMPv1
and IGMPv2 share the 8-octet structure below.
IGMPv1 and
IGMPv2 set
version and reuse this schema and
data model as-is; IGMPv3’s wire format differs materially by message, so
IGMPv3 carries its own
instead – see IGMPv3 - Internet Group Management Protocol Version 3.
alias names the protocol each
message is read as: 'IGMP' for IGMPv1, the name RFC 1112 gives it, and
'IGMPv2' or 'IGMPv3' for the others. Constructing the base gives the
version class its version keyword names; without it, octets give the class
the message classifies as, and fields are refused. Its
from_data() gives the class the
version of its data names: every IGMP data model carries one, 1, 2 or
3, set by the class that read or built the message and on no octet, so an
IGMPv1 and an IGMPv2 message read alike apart from it (#2574).
The structure is keyed as for IGMPv1; an IGMPv2 message’s keys start igmpv2
instead:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Type |
1 |
8 |
|
Max Response Time |
2 |
16 |
|
Checksum |
4 |
32 |
|
Group Address |
- class pcapkit.protocols.internet.igmp.IGMP[_PT: Data, _ST: Schema](file=None, length=None, **kwargs)[source]¶
Bases:
Internet[_PT,_ST],Generic[_PT,_ST]This class implements Internet Group Management Protocol.
The class is abstract:
versionis set by the concrete IGMPv1, IGMPv2 and IGMPv3 classes.read()refuses a message that_classify()does not place inversion.It dispatches on both paths, never giving an instance of this class (#2574).
versionnames the version class; without it, octets give the one_dispatch()picks, and fields are refused, since no field picks a class.from_data()reads theversionof its data. See__new__().The checksum of every version is verified on read under
CHECKSUM_VERIFY, unless the enclosing IP layer is a fragment, see_verify_checksum();make()computes one it is not given.- property alias: str¶
Acronym of corresponding protocol,
'IGMP','IGMPv2'or'IGMPv3'.IGMPv1 reports
'IGMP', the name RFC 1112 gives it.
- classmethod id()[source]¶
Index ID of the protocol.
RFC 1112 names the protocol
IGMP, without a version, the same shapeICMPtakes for RFC 792 – so the family base’s own name doubles as IGMPv1’s canonical name. RFC 2236 and RFC 3376 name IGMPv2 and IGMPv3 with their own versions.
- read(length=None, **kwargs)[source]¶
Read Internet Group Management Protocol.
- Parameters:
- Raises:
ProtocolError – If
_classify()does not place the message inversion.- Return type:
_PT- Returns:
Parsed packet data.
- make(type=Type.IGMP_Membership_Query, max_resp_time=0, checksum=None, group='0.0.0.0', payload=b'', **kwargs)[source]¶
Make (construct) packet data.
The version of a constructed message is decided by its
type,max_resp_timeand length (see_classify()), not by the class that built it.- Parameters:
max_resp_time (
int) – Max response time, in tenths of a second; zero for an IGMPv1 message.checksum (
bytes|None) – Checksum over the message with this field zeroed, no pseudo-header (RFC 2236 Section 2.3); ifNone, computed over the message,payloadincluded, whenCHECKSUM_COMPUTEis on, zero when it is off.group (
IPv4Address|str|bytes|int) – Group address;0.0.0.0for a General Query.payload (
bytes|ProtocolBase|Schema) – Payload of current instance.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
_ST- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
typeis a name, abool, or a member or code outside 0 to 255,max_resp_timeis not a non-boolinteger from 0 to 255, orchecksumis not two octets.
- classmethod from_data(data, **kwargs)[source]¶
Create protocol instance from data.
- Parameters:
**kwargs (
Any) – AsProtocol.from_data.
- Return type:
- Returns:
Protocol instance; on this class, an instance of the version class the
versionofdatanames, which every IGMP data model carries (#2574).- Raises:
ProtocolError – If
datacarries noversion, or one that names no version class, on this class.
- __init__(file=None, length=None, *, version=None, **kwargs)[source]¶
Initialisation.
- Parameters:
version (
Literal[1,2,3] |None) – Version of IGMP,1,2or3: the class__new__()picks. Building from fields, it must be this class’sversion. Parsing, it is handed on unread, as the enclosing IP layer passes its own version under this name to the layer it carries.**kwargs (
Any) – AsProtocol.__init__.
- Raises:
ProtocolError – If, building from fields,
versionnames no version class, or is not this class’s ownversion, which every IGMP class states, a subclass outside the members included.
- static __new__(cls, file=None, length=None, **kwargs)[source]¶
Create the version class a construction of this class describes.
The
versionkeyword names the class, on either path. Without it, parsing octets gives the class_dispatch()picks, and building from fields is refused, since no field picks a class. That class’s__init__then runs with the same arguments. A subclass of this class is created as itself.- Parameters:
- Return type:
- Returns:
An uninitialised instance of the version class.
- Raises:
ProtocolError – If
versionnames no version class; or, without it, if building from fields, or if the octets are no version’s message.
- classmethod _classify(type, max_resp_time, length)[source]¶
Classify a parsed IGMP header as IGMPv1, IGMPv2 or IGMPv3.
A Membership Query is IGMPv1/v2 only at exactly 8 octets: IGMPv1 if
max_resp_timeis zero, IGMPv2 otherwise. A Membership Query of 12 or more octets is IGMPv3’s Query, carrying the source-list extension (RFC 3376 Section 7.1); one of 9 to 11 octets is neither and is ignored. The IGMPv3 Membership Report (0x22) is always IGMPv3, whatever its length.- Parameters:
- Return type:
Literal[0,1,2,3]- Returns:
1,2or3for that version,0for none of them.
- _verify_checksum(igmp, checksum, length)[source]¶
Record on
igmpthe outcome of verifying the message’s checksum.Only under
CHECKSUM_VERIFY, aschecksum_status. Every version’s checksum covers the whole message, the entire IP payload, with no pseudo-header (RFC 2236 Section 2.3, RFC 3376 Section 4.1.2, RFC 3376 Section 4.2.2). That holds for IGMPv1 as well: RFC 1112 defines an 8-octet message, and RFC 2236, which updates it, sums a longer one whole (RFC 2236 Section 2.5). Seeverify_message(). A message the data ends inside, as its header’s__short_read__records, isTRUNCATED(#2689).
- classmethod _dispatch(data, length)[source]¶
Pick the class that parses the IGMP message at the start of
data.The type and max response time are the first two octets, read here before any class is built, and
_classify()decides the version.
Header Schemas¶
- class pcapkit.protocols.schema.internet.igmp.IGMP(type=NO_VALUE, max_resp_time=NO_VALUE, checksum=NO_VALUE, group=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
SchemaHeader schema for IGMP packet.
The same 8-octet layout serves IGMPv1 (RFC 1112 Page 11) and IGMPv2 (RFC 2236 Section 2): v1 leaves
max_resp_timereserved at zero rather than omitting the octet (#2439).- max_resp_time: int = <UInt8Field max_resp_time>¶
Max response time, in units of 1/10 second (zero/reserved outside an IGMPv2 Membership Query).
- checksum: bytes = <BytesField checksum>¶
Checksum. The 16-bit one’s complement of the one’s complement sum of the message, with the checksum field itself taken as zero and no pseudo-header involved – the 8-octet message itself for IGMPv1 (RFC 1112 Page 11), or the whole IP payload for IGMPv2 (RFC 2236 Section 2.3).
- group: IPv4Address = <IPv4AddressField group>¶
Group address.
Data Models¶
- class pcapkit.protocols.data.internet.igmp.IGMP(version, type, max_resp_time, checksum, group)[source]¶
Bases:
ProtocolData model for Internet Group Management Protocol.
This single schema covers both IGMPv1 (RFC 1112 Page 11) and IGMPv2 (RFC 2236 Section 2) messages: v1’s 8-octet header is the same shape as v2’s, with
max_resp_timereserved at zero and fewertypevalues defined (#2439). IGMPv3 (RFC 3376) adds a group-record-list body of a materially different shape and is out of scope here – seepcapkit.protocols.data.internet.igmpv3.- version: Literal[1, 2]¶
Version of IGMP the message was read as,
1or2– theversionof the class that read or built it. It is on no octet, since the versions share this layout, andIGMP.from_datadispatches on it (#2574).
- max_resp_time: int¶
Max response time, in units of 1/10 second. Meaningful only for a Membership Query under IGMPv2 (RFC 2236 Section 2.2); reserved and zero on every other message, including every IGMPv1 one (RFC 1112 Page 11).
- group: IPv4Address¶
Group address – the IPv4 multicast group being queried, reported or left, or
0.0.0.0on a General Query.
- checksum_status: ChecksumStatus¶
Outcome of verifying
checksum, present only whenCHECKSUM_VERIFYis on.
Footnotes