Protocol Family¶
pcapkit.protocols holds the protocol families.
- Root Protocol
- Link Layer
- Link Layer Base Protocol
- Ethernet Protocol
- ARP - Address Resolution Protocol
- InARP - Inverse Address Resolution Protocol
- FRAD - Frame Relay Access Device
- GRE - Generic Routing Encapsulation
- IEEE 802.11 - Wireless LAN MAC Header
- L2TP - Layer Two Tunnelling Protocol
- L2TPv2 - Layer Two Tunnelling Protocol Version 2
- LinuxSLL - Linux “Cooked” Capture Encapsulation Family
- Linux “Cooked” Capture Encapsulation
- Linux “Cooked” Capture Encapsulation v2
- BSD Loopback Encapsulation
- Netlink - Linux Netlink Socket Framing
- Radiotap - IEEE 802.11 Radiotap Header
- VLAN - 802.1Q/802.1ad VLAN Tag Types
- C_Tag - 802.1Q Customer VLAN Tag Type
- S_Tag - 802.1ad Service VLAN Tag Type
- Protocol Registry
- Internet Layer
- Internet Layer Base Protocol
- IP - Internet Protocol
- IPv4 - Internet Protocol Version 4
- IPv6 - Internet Protocol Version 6
- IPv6-Ext - IPv6 Extension Header
- IPv6-Frag - Fragment Header for IPv6
- IPv6-Opts - Destination Options for IPv6
- IPv6-Route - Routing Header for IPv6
- HOPOPT - IPv6 Hop-by-Hop Options
- IPv6 Options - Shared Option Helpers
- MH - Mobility Header
- IPsec - Internet Protocol Security
- AH - Authentication Header
- ESP - Encapsulating Security Payload
- ICMP - Internet Control Message Protocol
- ICMPv4 - Internet Control Message Protocol
- ICMPv6 - Internet Control Message Protocol for IPv6
- HIP - Host Identity Protocol
- IGMP - Internet Group Management Protocol
- IGMPv1 - Internet Group Management Protocol Version 1
- IGMPv2 - Internet Group Management Protocol Version 2
- IGMPv3 - Internet Group Management Protocol Version 3
- IPX - Internetwork Packet Exchange
- Protocol Registry
- Transport Layer
- Application Layer
- Application Layer Base Protocol
- HTTP - Hypertext Transfer Protocol
- HTTP/1.* - Hypertext Transfer Protocol
- HTTP/2 - Hypertext Transfer Protocol
- FTP - File Transfer Protocol
- FTP_DATA - FTP Data Channel
- NGAP - NG Application Protocol
- OSPF - Open Shortest Path First
- RARP - Reverse Address Resolution Protocol
- DRARP - Dynamic Reverse Address Resolution Protocol
- SSL - Secure Sockets Layer
- SSLv2 - Secure Sockets Layer Version 2
- TLS/SSL - Transport Layer Security
- SSLv3 - Secure Sockets Layer Version 3
- DTLS - Datagram Transport Layer Security
- Protocol Registry
- Auxiliary Protocols
Every protocol class subclasses ProtocolBase,
parsing a packet from its octets or building one from field values:
flowchart LR
A{{ProtocolMeta}} -.->|metaclass| B(ProtocolBase)
%% The layers are declared in this order so that ARP --> RARP and
%% Raw --> FTP_DATA stay short instead of crossing the other layers.
subgraph misc [Miscellaneous]
subgraph pcap [PCAP Format]
Header & Frame
end
subgraph pcapng [PCAP-NG Format]
PCAPNG
end
subgraph checksum [Checksum Pseudo-Headers]
IP_Pseudo
end
Raw & NoPayload
end
subgraph application [Application Layer]
Application --> HTTP & FTP & FTP_DATA & NGAP & OSPF & RARP & SSL
subgraph http [HTTP Family]
HTTP --> h1["HTTP/1.*"] & h2["HTTP/2"]
end
subgraph ftp [FTP Family]
FTP & FTP_DATA
end
subgraph rarp [RARP Family]
RARP --> DRARP
end
subgraph ssl [SSL Family]
SSL --> TLS & DTLS & SSLv2
TLS --> SSLv3
end
end
subgraph link [Link Layer]
Link --> Ethernet & L2TP & LinuxSLL & Loopback & VLAN & ARP
subgraph arp [ARP Family]
ARP --> InARP
end
subgraph vlan [VLAN Family]
VLAN --> C_Tag & S_Tag
end
subgraph l2tp [L2TP Family]
L2TP --> L2TPv2
end
subgraph sll [LinuxSLL Family]
LinuxSLL --> LinuxSLL1 & LinuxSLL2
end
end
subgraph internet [Internet Layer]
Internet --> IPX & IP & ICMP & IPsec & IPv6_Ext & IGMP
subgraph ip [IP Family]
IP --> IPv4 & IPv6
end
subgraph icmp [ICMP Family]
ICMP --> ICMPv4 & ICMPv6
end
subgraph ipsec [IPsec Family]
IPsec --> AH & ESP
end
subgraph ipv6ext [IPv6 Extension Header]
IPv6_Ext --> IPv6-Frag & IPv6-Opts & IPv6-Route & HOPOPT & MH & HIP
end
subgraph igmp [IGMP Family]
IGMP --> IGMPv1 & IGMPv2 & IGMPv3
end
end
subgraph transport [Transport Layer]
Transport --> TCP & UDP & SCTP & DCCP
end
B --> Link & Internet & Transport & Application
B --> Header & Frame & PCAPNG & Raw & NoPayload & IP_Pseudo
Raw --> FTP_DATA
ARP --> RARP
IPv6_Ext --> AH & ESP
B --> C(Protocol)
C --> D([user customisation ...])
click A "protocol.html#pcapkit.protocols.protocol.ProtocolMeta"
click B "protocol.html#pcapkit.protocols.protocol.ProtocolBase"
click C "protocol.html#pcapkit.protocols.protocol.Protocol"
click D "../../ext.html#customising-protocols"
click Link "link/link.html#pcapkit.protocols.link.link.Link"
click Ethernet "link/ethernet.html#pcapkit.protocols.link.ethernet.protocol.Ethernet"
click L2TP "link/l2tp.html#pcapkit.protocols.link.l2tp.protocol.L2TP"
click L2TPv2 "link/l2tpv2.html#pcapkit.protocols.link.l2tpv2.protocol.L2TPv2"
click LinuxSLL "link/linux_sll.html#pcapkit.protocols.link.linux_sll.protocol.LinuxSLL"
click LinuxSLL1 "link/linux_sll1.html#pcapkit.protocols.link.linux_sll1.protocol.LinuxSLL1"
click LinuxSLL2 "link/linux_sll2.html#pcapkit.protocols.link.linux_sll2.protocol.LinuxSLL2"
click Loopback "link/loopback.html#pcapkit.protocols.link.loopback.protocol.Loopback"
click VLAN "link/vlan.html#pcapkit.protocols.link.vlan.protocol.VLAN"
click C_Tag "link/c_tag.html#pcapkit.protocols.link.c_tag.protocol.C_Tag"
click S_Tag "link/s_tag.html#pcapkit.protocols.link.s_tag.protocol.S_Tag"
click ARP "link/arp.html#pcapkit.protocols.link.arp.protocol.ARP"
click InARP "link/inarp.html#pcapkit.protocols.link.inarp.protocol.InARP"
click Internet "internet/internet.html#pcapkit.protocols.internet.internet.Internet"
click AH "internet/ah.html#pcapkit.protocols.internet.ah.protocol.AH"
click ESP "internet/esp.html#pcapkit.protocols.internet.esp.protocol.ESP"
click HIP "internet/hip.html#pcapkit.protocols.internet.hip.protocol.HIP"
click IGMP "internet/igmp.html#pcapkit.protocols.internet.igmp.protocol.IGMP"
click IGMPv1 "internet/igmpv1.html#pcapkit.protocols.internet.igmpv1.protocol.IGMPv1"
click IGMPv2 "internet/igmpv2.html#pcapkit.protocols.internet.igmpv2.protocol.IGMPv2"
click IGMPv3 "internet/igmpv3.html#pcapkit.protocols.internet.igmpv3.protocol.IGMPv3"
click HOPOPT "internet/hopopt.html#pcapkit.protocols.internet.hopopt.protocol.HOPOPT"
click ICMP "internet/icmp.html#pcapkit.protocols.internet.icmp.protocol.ICMP"
click ICMPv4 "internet/icmpv4.html#pcapkit.protocols.internet.icmpv4.protocol.ICMPv4"
click ICMPv6 "internet/icmpv6.html#pcapkit.protocols.internet.icmpv6.protocol.ICMPv6"
click IP "internet/ip.html#pcapkit.protocols.internet.ip.protocol.IP"
click IPsec "internet/ipsec.html#pcapkit.protocols.internet.ipsec.protocol.IPsec"
click IPv4 "internet/ipv4.html#pcapkit.protocols.internet.ipv4.protocol.IPv4"
click IPv6 "internet/ipv6.html#pcapkit.protocols.internet.ipv6.protocol.IPv6"
click IPv6_Ext "internet/ipv6_ext.html#pcapkit.protocols.internet.ipv6_ext.protocol.IPv6_Ext"
click IPv6-Frag "internet/ipv6_frag.html#pcapkit.protocols.internet.ipv6_frag.protocol.IPv6_Frag"
click IPv6-Opts "internet/ipv6_opts.html#pcapkit.protocols.internet.ipv6_opts.protocol.IPv6_Opts"
click IPv6-Route "internet/ipv6_route.html#pcapkit.protocols.internet.ipv6_route.protocol.IPv6_Route"
click IP_Pseudo "misc/checksum.html#pcapkit.protocols.misc.checksum.ip_pseudo.protocol.IP_Pseudo"
click IPX "internet/ipx.html#pcapkit.protocols.internet.ipx.protocol.IPX"
click MH "internet/mh.html#pcapkit.protocols.internet.mh.protocol.MH"
click Transport "transport/transport.html#pcapkit.protocols.transport.transport.Transport"
click TCP "transport/tcp.html#pcapkit.protocols.transport.tcp.protocol.TCP"
click UDP "transport/udp.html#pcapkit.protocols.transport.udp.protocol.UDP"
click SCTP "transport/sctp.html#pcapkit.protocols.transport.sctp.protocol.SCTP"
click DCCP "transport/dccp.html#pcapkit.protocols.transport.dccp.protocol.DCCP"
click Application "application/application.html#pcapkit.protocols.application.application.Application"
click HTTP "application/http.html#pcapkit.protocols.application.http.protocol.HTTP"
click h1 "application/httpv1.html#pcapkit.protocols.application.httpv1.protocol.HTTPv1"
click h2 "application/httpv2.html#pcapkit.protocols.application.httpv2.protocol.HTTPv2"
click FTP "application/ftp.html#pcapkit.protocols.application.ftp.protocol.FTP"
click FTP_DATA "application/ftp_data.html#pcapkit.protocols.application.ftp_data.protocol.FTP_DATA"
click NGAP "application/ngap.html#pcapkit.protocols.application.ngap.protocol.NGAP"
click OSPF "application/ospf.html#pcapkit.protocols.application.ospf.protocol.OSPF"
click RARP "application/rarp.html#pcapkit.protocols.application.rarp.protocol.RARP"
click DRARP "application/drarp.html#pcapkit.protocols.application.drarp.protocol.DRARP"
click SSL "application/ssl.html#pcapkit.protocols.application.ssl.protocol.SSL"
click SSLv2 "application/sslv2.html#pcapkit.protocols.application.sslv2.protocol.SSLv2"
click TLS "application/tls.html#pcapkit.protocols.application.tls.protocol.TLS"
click SSLv3 "application/sslv3.html#pcapkit.protocols.application.sslv3.protocol.SSLv3"
click DTLS "application/dtls.html#pcapkit.protocols.application.dtls.protocol.DTLS"
click Raw "misc/raw.html#pcapkit.protocols.misc.raw.protocol.Raw"
click NoPayload "misc/no_payload.html#pcapkit.protocols.misc.no_payload.protocol.NoPayload"
click PCAPNG "misc/pcapng.html#pcapkit.protocols.misc.pcapng.protocol.PCAPNG"
click Header "misc/pcap.html#pcapkit.protocols.misc.pcap.header.protocol.Header"
click Frame "misc/pcap.html#pcapkit.protocols.misc.pcap.frame.protocol.Frame"
Protocol Registry¶
ProtocolBase.__registry__
maps names to protocol classes.
ProtocolMeta.registry reads it
as AnyProtocol.registry, a read-only view importing nothing, and
ProtocolBase.get_protocol
returns the class a name maps to.
Removed in version 1.6.0: pcapkit.protocols.__proto__, with no alias: read
ProtocolBase.__registry__
through ProtocolBase.get_protocol instead (#2763).
See also
pcapkit.foundation.registry.protocols.protocol.register_protocol(), which
registers a protocol.
Header Schema¶
Removed in version 1.6.0: pcapkit.protocols.schema.schema, with no alias: the module moved here. The
pcapkit.protocols.schema.application, pcapkit.protocols.schema.internet,
pcapkit.protocols.schema.link, pcapkit.protocols.schema.misc,
pcapkit.protocols.schema.misc.checksum, pcapkit.protocols.schema.misc.pcap
and pcapkit.protocols.schema.transport subpackages, and the header schemas they
and pcapkit.protocols.schema collected, with no alias: each protocol’s are in the
schema module of its own package, such as
pcapkit.protocols.link.vlan.schema (#2534).
Removed in version 1.6.0: pcapkit.protocols.schema.schema.keep_short_read and
pcapkit.protocols.schema.schema.replay_short_read, now
pcapkit.corekit.schema.shortread.keep_short_read() and
pcapkit.corekit.schema.shortread.replay_short_read() (#2674).
- class pcapkit.protocols.schema.Schema[_VT](dict_=None, **kwargs)[source]¶
Bases:
ReduceAsProtocol2,Mapping[str,_VT],Generic[_VT]Schema for protocol headers.
Note
Building a schema directly does not range-check its field values. A
NumberFieldmasks an out-of-range integer to its width on packing, so e.g.70000in a two-octet field packs as0x1170. The range checks live in each protocol’smake(), and in a field whose values have a range of their own, such asPortEnumField(#2314).- __fields__: OrderedDict[str, FieldBase]¶
Mapping of fields.
- classmethod from_dict(dict_=None, **kwargs)[source]¶
Create a new instance.
If
dict_is a mapping, then does:for k in dict_: self[k] = dict_[k].If
dict_is present and not a mapping, then does:for k, v in dict_: self[k] = v.In either case, and if
dict_is not present, this is followed by:for k, v in kwargs.items(): self[k] = v.
- to_dict()[source]¶
-
Important
Only a nested
Schemathat is an attribute’s direct value is converted intodict; one held within another type, such aslist,tupleorset, is left intact.Note
A schema unpacked as the value of a
SchemaFieldthat left part of the field’s span unread carries those octets under a__remainder__key, and the number of octets it did read under__remainder_offset__.from_dict()accepts both back, so that the rebuilt field still packs them (#1380). The keys are absent otherwise.A schema whose data ended inside one of its fields carries the
__short_read__thatunpack()recorded, andfrom_dict()accepts it back, likewise.
- pack(packet=None)[source]¶
-
- Parameters:
- Return type:
- Returns:
Notes
The packet’s length being unknown,
__length__defaults to-1, whichFieldtakes as a placeholder; give__length__to pack the correct length.
- pre_pack(packet)[source]¶
Prepare
packetdata for packing process.Note
This method is expected to directly modify any data stored in the
packetand thus no return is required.
- classmethod unpack(data, length=None, packet=None)[source]¶
-
- Parameters:
- Return type:
- Returns:
Unpacked data as
Schema.
Notes
packetcarries the bookkeeping keys below. For a nested schema, unpacked through aSchemaField, it is the contextnested_packet_context()builds: a name this schema does not declare falls through to the enclosing schema, which__packet__also holds.__length__– the length of the remaining data, which sizes the payload field.__option_padding__– how much of anOptionField’s declared area it left after its end-of-option-list marker.datais rewound by as much of that unparsed remainder as was read, so the fields sized from this key read the remainder itself and record a cut inside it (#2685). What follows decides what it is: usually padding, but the PCAP-NG name resolution block reads further options from it.__short_read__– for the fields after the one the data ends inside, the(name, octets read)pair recorded, or that of aForwardMatchFieldthe data ends inside first, which the record leaves out as it consumes nothing. A field callback can so tell a value the end of the data left as zero from one read, and leave it to the short read.__data_end__– thatlengthends where the data does, as aListFieldsays of an item it counts. Fields running pastlengthare then the cut the short read records, and do not warn that__length__fell below zero (#2749).__data_present__– thatdataholds the data that many octets in, and past them the zeros aListFieldof schema items filled it out with. The field a read crosses them in is given how many of its octets the data holds, under the same key, so a list there ends with the data (#2760).
The last three are cleared as unpacking starts, so a nested schema finds only its own.
A payload field of a declared length the data ends inside records a cut like any other field, so its layer’s rebuild reads as cut (#2711); one declaring no length takes what the message leaves, as a trailer does, and records nothing. A
ListFieldwhose octets hold fewer items than it counts records the cut too, the missing items being itsshortfall.Changed in version 1.6.0: The field the data ends inside is given to the fields after it, as
__short_read__inpacket(#2727), a schema whoselengthends with the data reads its fields past it as cut, not as a negative length (#2749), and the field a read crosses the end of the data in, inside zeros filled out past it, is told where it ends (#2760).
- classmethod pre_unpack(packet)[source]¶
Prepare
packetdata for unpacking process.Note
This method is expected to directly modify any data stored in the
packetand thus no return is required.
- classmethod __init_subclass__(*args, **kwargs)[source]¶
Refuse to derive from a finalised schema.
final()only informs the type checker: it records__final__and leaves the class subclassable. A schemaschema_final()finalises carries an__init__generated from its__fields__at that moment, which cannot set a field a subclass adds, so the subclass is refused.- Parameters:
- Raises:
SchemaError – If any class in
cls’s ancestry carries the__final__marker in its own__dict__.
- static __new__(cls, *args, **kwargs)[source]¶
Create a new instance.
The class will try to automatically generate
__init__method with one keyword parameter per field in__fields__, which is inspired by PEP 557 (dataclasses).Note
Whether
clsstill needs finalising is read from its own__dict__, never inherited (#1498). Each class is finalised on its first construction, whatever its ancestors’ state, so a subclass of aBASEancestor still gets its own__builtin__,__excluded__and generated__init__, and a@finalclass under aBASEancestor is refused like any other.- Parameters:
*args (
_VT) – Arbitrary positional arguments.**kwargs (
_VT) – Arbitrary keyword arguments.
- Raises:
SchemaError – If
clswas marked withfinal()but never finalised byschema_final(), i.e. it carries__final__in its own__dict__withoutFINAL.- Return type:
- _cut_short_read()[source]¶
Cut the packed buffers back to the octets a short read consumed.
A schema whose data ended inside one of its fields records, as
__short_read__, that field’s name and how many of its octets were there (seeunpack()). Its value is read as though the missing octets were zeros, so packing it writes the field at full width and every field after it besides, none of which was captured. Only the octets read are kept here, so a truncated header packs back to exactly what was captured (#1458).
- class pcapkit.protocols.schema.EnumSchema[_ET: Enum](*args, **kwargs)[source]¶
-
Schemawith enumeration mapping support.Examples
Subclass it with the enumeration:
class MySchema(EnumSchema[MyEnum]): # optional, set the default schema for enumeration mapping # if the enumeration number is not found in the mapping __default__ = lambda: UnknownSchema # by default, None
then subclass that per code, or list of codes:
class OneSchema(MySchema, code=MyEnum.ONE): ... class MultipleSchema(MySchema, code=[MyEnum.TWO, MyEnum.THREE]): ...
or optionally, using the
register()method to register a schema to the enumeration mapping:MySchema.register(MyEnum.ZERO, ZeroSchema)
And now you can access the enumeration mapping via the
registryproperty (more specifically, class attribute):>>> MySchema.registry[MyEnum.ONE] # OneSchema
- __default__: Callable[[], Type[Self]]¶
Callback to return the default schema for enumeration mapping, by default is a
lambda: Nonestatement.
- __enum__: DefaultDict[_ET, Type[Self]]¶
Mapping of enumeration numbers to schemas.
- property registry: DefaultDict[_ET, Type[Self]]¶
Mapping of enumeration numbers to schemas.
Note
This property answers on an instance; on the class, the same mapping is served by
EnumMeta.registry.Important
See
EnumMeta.registry: the returned mapping is a_EnumRegistry, so looking up an unregisteredcodereturns the default schema without recordingcodeas if it had been registered.
- classmethod register(code, schema)[source]¶
Register enumeration to
__enum__mapping.- Parameters:
- Warns:
pcapkit.utilities.warnings.RegistryWarning– Ifcodeis already registered, naming the displaced schema and its replacement.
Note
Each registrar in
pcapkit.foundation.registry.protocolsthat takes aschemaregisters both halves of one binding, a parser through e.g.IPv4.register_optionand a schema through this method, and both warn on an overwrite.Registering the same schema object again is a silent no-op. Presence is a faithful test only because
_EnumRegistrydoes not record a miss.pcapkit.protocols.misc.pcapng.schema.Optionoverrides this method with a namespaced registry of its own, guarded separately.
- classmethod __init_subclass__(code=None, *args, **kwargs)[source]¶
Register enumeration to
registrymapping.- Parameters:
- Return type:
A subclass given
codeis registered under it inregistry; one without is not.- Warns:
pcapkit.utilities.warnings.RegistryWarning– If any ofcodeis already registered, naming the displaced schema and its replacement, asregister()does: a class declaration such asclass MyOption(Option, code=...)writes the registry without calling it.
Notes
An undefined
__enum__becomes an_EnumRegistrydefaulting to__default__.To customise the mapping, override this method and define
__enum__manually. A plaincollections.defaultdictdefined so, as for the namespaced mapping ofpcapkit.protocols.misc.pcapng.schema.Option, is swapped for an_EnumRegistrybefore anything else can hold it.
- @pcapkit.protocols.schema.schema_final(cls, *, _finalised=True)[source]¶
Finalise schema class.
This decorator generates the attributes and methods of the decorated
Schemaclass once, rather than at runtime.Notes
Use it on the final class only. With
_finalised=Trueit seals the class against subclassing, whichSchema.__init_subclass__()enforces, and marks it withfinal(), so@schema_finalimplies@final; writing both is harmless.Schema.__new__()refuses@finalwithout this decorator, where@finalisfinal(), ortyping.final()on Python 3.11 and up. Below 3.11,typing.final()sets no__final__(gh-90500), so a class marked with it is not refused.Applying it to the same class a second time only warns, and the class comes back finalised and usable.
- Parameters:
- Return type:
- Returns:
Finalised schema class.
- Warns:
pcapkit.utilities.warnings.SchemaWarning– Ifclshas already been finalised by this function, i.e. it carriesFINALin its own__dict__. The class is returned untouched.
Changed in version 1.5.0: A class finalised with
_finalised=Truerefuses to be subclassed, and a schema marked@finalwithout this decorator cannot be instantiated (#778).
Internal Definitions¶
- class pcapkit.protocols.schema.SchemaMeta(name, bases, attrs, /, **kwargs)[source]¶
Bases:
ABCMetaMeta class to add dynamic support to
Schema.It generates the attributes of the
Schemaclass:Schema.__fields__maps each field name, the attribute name, to itsFieldobject, which defines and parses the header. It is populated from the class attributes.See also
The
__prepare__()method sets up the initial field dictionary from those of the base classes; during class creation,Field.__set_name__names each field object and adds it to the dictionary.Schema.__additional__andSchema.__excluded__list names to include in or exclude from the field dictionary, populated from the class attributes of the class and its bases.Note
This metaclass’s
__new__inherits both lists from the base classes and extends them with the subclass’s own.class A(Schema): __additional__ = ['a', 'b'] class B(A): __additional__ = ['c', 'd'] class C(B): __additional__ = ['e', 'f'] print(A.__additional__) # ['a', 'b'] print(B.__additional__) # ['a', 'b', 'c', 'd'] print(C.__additional__) # ['a', 'b', 'c', 'd', 'e', 'f']
- classmethod __prepare__(name, bases, /, **kwds)[source]¶
Prepare the namespace for the schema class.
- Parameters:
- Return type:
This method is used to create the initial field dictionary
__fields__for the schema class.
- class pcapkit.protocols.schema.EnumMeta[_ET: Enum](name, bases, attrs, /, **kwargs)[source]¶
Bases:
SchemaMeta,Generic[_ET]Meta class to add dynamic support for
EnumSchema.It adds
registryto subclasses: a read-only class property returning theEnumSchema.__enum__mapping.- property registry: DefaultDict[_ET, Type[EnumSchema]]¶
Mapping of enumeration numbers to schemas.
Important
The returned mapping is a
_EnumRegistry, not a plaincollections.defaultdict: indexing it with an unregisteredcodestill returnsEnumSchema.__default__’s schema, but does not insert that code. See_EnumRegistryfor why that distinction matters.
- class pcapkit.protocols.schema._EnumRegistry[source]¶
Bases:
defaultdictA registry
collections.defaultdictthat never inserts a miss.EnumSchema.registry(and its class-level twin,EnumMeta.registry) is read with a bareregistry[code]across the schema layer, e.g.Option.registry[type]. A plaincollections.defaultdictwould insert whatdefault_factoryreturns on the first miss, and the registry lives on the class, so one packet with an unrecognised code would grow it for the rest of the process, and make a later, legitimateEnumSchema.register()report an overwrite that never happened.The fallback is how an unknown option, chunk or block gets its
Unknown*/Unassigned*schema, so this subclass still returns it, without recording it, asProtocol._lookup_registrydoes for the__proto__family.- __missing__(key)[source]¶
Return the fallback for an unregistered
key, without storing it.- Parameters:
key (
Any) – Registry key that is not registered.- Return type:
- Returns:
What
default_factoryreturns. The registry is left as it was, sokeystays unregistered.- Raises:
KeyError – If
default_factoryisNone.
Type Variables¶
- pcapkit.protocols.schema._ST: Type[pcapkit.protocols.schema.Schema]¶
Data Model¶
Removed in version 1.6.0: pcapkit.protocols.data.data and pcapkit.protocols.data.protocol, with no
alias: the modules merged here. The pcapkit.protocols.data.application,
pcapkit.protocols.data.internet, pcapkit.protocols.data.link,
pcapkit.protocols.data.misc, pcapkit.protocols.data.misc.checksum,
pcapkit.protocols.data.misc.pcap and pcapkit.protocols.data.transport
subpackages, and the data models they and pcapkit.protocols.data collected, with
no alias: each protocol’s are in the data module of its own package, such as
pcapkit.protocols.link.vlan.data (#2534).
- class pcapkit.protocols.data.Data(*args, **kwargs)[source]¶
Bases:
InfoBase class for data models.
The
__next_name__,__next_type__,__short_read__and__short_width__keys are metadata, listed in__included__and__excluded__.Protocol.from_datadispatches the payload on the first two alone, cuts a short read back on the third, and reads it at the width the fourth records.to_dict()carries them, sofrom_data(info.to_dict())rebuilds asfrom_data(info)does; the dumpers andreprleave them out. A hand-writtendictneeds them too, and for IPv6 the extension header chain under__exthdr__: without the first two no payload layer is dispatched, and without__exthdr__no IPv6 extension header is rebuilt (#2003).- __excluded__: list[str]¶
Metadata keys that
repr,strand the dumps leave out.See also
Protocol._decode_next_layer, which inserts__next_name__and__next_type__.