IGMP - Internet Group Management Protocol¶
pcapkit.protocols.internet.igmp.protocol contains
IGMP, the abstract base of the
Internet Group Management Protocol (IGMP) [*] versions 1, 2 and 3:
Version class |
|
Schema and data model |
|---|---|---|
|
this page’s, keyed |
|
|
this page’s, keyed |
|
|
its own, as its wire format differs by message (IGMPv3 - Internet Group Management Protocol Version 3) |
IGMPv1’s alias is the name
RFC 1112 gives it. Parsing octets through the base, or building it from
fields, gives the version class its version keyword names, which a
class checks as its own on both paths (#2840); without it, octets give the
class the message classifies as, and fields are refused.
from_data() gives the class
its data’s version 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).
_dispatch() gives octets a
version class, or Raw, as
_classify() decides:
flowchart TD
NEW["IGMP(octets) with no version=<br/>IGMP.\_\_new\_\_"] --> DISP
NET["an IP layer's IGMP payload<br/>Internet.\_next\_layer\_class"] --> DISP
DISP{"\_dispatch: at least 2 octets?"}
DISP -->|yes| TYPE{"\_classify: the Type"}
DISP -->|no| RAW
TYPE -->|"0x12, v1 Report"| V1
TYPE -->|"0x16, v2 Report<br/>0x17, Leave Group"| V2
TYPE -->|"0x22, v3 Report"| V3
TYPE -->|"0x11, Membership Query"| LEN{"the message length?"}
TYPE -->|"any other"| RAW
LEN -->|"8 octets"| MRT{"Max Resp Time zero?"}
LEN -->|"12 or more"| V3
LEN -->|"any other"| RAW
MRT -->|yes| V1
MRT -->|no| V2
V1["IGMPv1"]
V2["IGMPv2"]
V3["IGMPv3"]
RAW["Raw"]
RAW -->|"from IGMP.\_\_new\_\_"| ERR["ProtocolError: unknown version"]
RAW -->|"from Internet"| KEPT["parsed as Raw, the next layer"]
click NEW "igmp.html#pcapkit.protocols.internet.igmp.protocol.IGMP.__new__"
click NET "internet.html#pcapkit.protocols.internet.internet.Internet._next_layer_class"
click DISP "igmp.html#pcapkit.protocols.internet.igmp.protocol.IGMP._dispatch"
click TYPE "igmp.html#pcapkit.protocols.internet.igmp.protocol.IGMP._classify"
click V1 "igmpv1.html#pcapkit.protocols.internet.igmpv1.protocol.IGMPv1"
click V2 "igmpv2.html#pcapkit.protocols.internet.igmpv2.protocol.IGMPv2"
click V3 "igmpv3.html#pcapkit.protocols.internet.igmpv3.protocol.IGMPv3"
The IGMPv1 and IGMPv2 structure, keyed as for IGMPv1:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Type |
1 |
8 |
|
Max Response Time |
2 |
16 |
|
Checksum |
4 |
32 |
|
Group Address |
Added in version 1.6.0.
- class pcapkit.protocols.internet.igmp.protocol.IGMP[_PT: Data, _ST: Schema](file, length=None, /, *, version=None, layer=None, protocol=None, context=None)[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.Properties
- property alias: str¶
Acronym of corresponding protocol,
'IGMP','IGMPv2'or'IGMPv3'.IGMPv1 reports
'IGMP', the name RFC 1112 gives it.
Methods
- 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.
Data Models
- __init__(file=NO_VALUE, length=None, /, *, version=None, layer=None, protocol=None, context=None, **fields)[source]¶
Parse a protocol instance from its octets, or construct one from its fields.
- Overloads:
file (
IO[bytes] |bytes), length (int|None) =..., /, *, version (Literal[1,2,3] |None) =..., layer (str|None) =..., protocol (str|ProtocolBase|Type[ProtocolBase] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =...→None*, version (
Literal[1,2,3] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =..., **fields (Any) →None
- Parameters:
file (
IO[bytes] |bytes|NoValueType) – Source packet stream; omitted to construct.version (
Literal[1,2,3] |None) – Version of IGMP,1,2or3: the class__new__()picks, which must be this class’s own.layer (
str|None) – AsProtocol.__init__.protocol (
str|ProtocolBase|Type[ProtocolBase] |None) – AsProtocol.__init__.context (
ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) – AsProtocol.__init__.**fields (
Any) – AsProtocol.__init__.
- Raises:
ProtocolError – If
versionnames no version class, or is not this class’s ownversion, which every IGMP class states, a subclass outside the members included.
Changed in version 1.8.0:
versionis checked against the class, asfrom_fields()checks it, rather than handed on (#2840).
- static __new__(cls, file=NO_VALUE, length=None, /, **kwargs)[source]¶
Create the version class a parse or a construction of this class describes.
The
versionkeyword names the class. Without it, the octets give the class_dispatch()picks, and fields are refused. 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 – On this class, if
versionnames no version class; if, without it, the octets are no version’s message; or if fields come without it.
Utilities
- 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.
- classmethod _construction_member(fields)[source]¶
The version class
from_fields(),from_data()and a call given no file construct.On this class, the version class
versionnames; on another, the class itself, whoseversionversionmust be.versionis taken out offields, asmake()does not read it.- Parameters:
- Return type:
- Returns:
The version class, or the class itself.
- Raises:
ProtocolError – If, on this class,
versionis missing; if it names no version class; or if it is not the class’s ownversion.
Added in version 1.8.0.
Header Schemas¶
- class pcapkit.protocols.internet.igmp.schema.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.internet.igmp.data.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.internet.igmpv3.data.- 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