Packets Reassembly¶
pcapkit.foundation.reassembly bases on algorithms described
in RFC 791 and RFC 815, implements datagram reassembly
of IP and TCP packets.
See also
For more information on customisation and extension, please refer to Customisation & Extensions.
All reassembly classes are implemented as ReassemblyBase
subclasses, which are responsible for processing extracted packets and
reassemble the datagrams to a nonfragmented packet. Below is a brief
diagram of the class hierarchy of pcapkit.foundation.reassembly:
flowchart LR
A{{ReassemblyMeta}} -.->|metaclass| B(ReassemblyBase)
B --> IP & TCP
IP --> IPv4 & IPv6
B --> C(Reassembly)
C --> D([user customisation ...])
click A "/pcapkit/foundation/reassembly/reassembly.html#pcapkit.foundation.reassembly.reassembly.ReassemblyMeta"
click B "/pcapkit/foundation/reassembly/reassembly.html#pcapkit.foundation.reassembly.reassembly.ReassemblyBase"
click C "/pcapkit/foundation/reassembly/reassembly.html#pcapkit.foundation.reassembly.reassembly.Reassembly"
click D "/ext.html#reassembly-and-flow-tracing"
click IP "/pcapkit/foundation/reassembly/ip/ip.html#pcapkit.foundation.reassembly.ip.IP"
click IPv4 "/pcapkit/foundation/reassembly/ip/ipv4.html#pcapkit.foundation.reassembly.ipv4.IPv4"
click IPv6 "/pcapkit/foundation/reassembly/ip/ipv6.html#pcapkit.foundation.reassembly.ipv6.IPv6"
click TCP "/pcapkit/foundation/reassembly/tcp.html#pcapkit.foundation.reassembly.tcp.TCP"
Auxiliary Data¶
- class pcapkit.foundation.reassembly.ReassemblyManager(*args: VT, **kwargs: VT)[source]¶
Bases:
InfoReassembly Manager.
- class pcapkit.foundation.reassembly.data.data.ReassemblyData(*args: VT, **kwargs: VT)[source]¶
Bases:
InfoData storage for reassembly.
- class pcapkit.foundation.reassembly.data.data.Deferred(analyze, proto, payload)[source]¶
Bases:
objectA postponed analysis of a reassembled payload.
A reassembled datagram’s
packetis a second, full parse of the payload the datagram just reassembled. Nothing about postponing it is specific to any one reassembler, which is why this lives besideReassemblyDatarather than in either protocol’s data module.IP reassembly is the case that made it necessary. It submits a datagram for every frame – not only the fragmented ones, since a frame that is not fragmented in any sense still reaches
IP.reassemblyand is submitted there as a trivially complete datagram – so the eager parse re-parsed captures holding no fragments at all:http.pcaphas 1117 IPv4 frames, none of them fragmented, and the parse was 86% of the cost of IP reassembly over it.TCP reassembly builds its
packeteagerly too (TCP.submit). It is a far smaller cost there, being FIN/RST-driven rather than per-frame – 222 submits perhttp.pcappass against 1117 – so it is left for its own change, but it can use this unmodified when someone gets to it.Holding the call here defers it to the first read of
Datagram.packet, so a caller that wants the parsed payload still gets exactly the object the eager call produced, and one that does not never pays for it.- Parameters:
analyze (
Callable[[TransType,bytes],ProtocolBase]) – The analyser to call, i.e.Protocol.analyzebound to the reassembly object’s protocol.proto (
TransType) – Payload protocol type.payload (
bytes) – Reassembled payload to parse.
- class pcapkit.foundation.reassembly.data.data.DeferredPacket[source]¶
Bases:
objectResolves a
Deferredpacketfield on first read.A reassembled datagram’s
packetis the parsed form of the payload it just reassembled, and both reassemblers can hand aDeferredin its place. This carries the reading half of that arrangement, so the twoDatagrammodels share it rather than each declaring it.A subclass has to list
packetin its__additional__. That is what makes the field lazy at all:Infostores a field whose name is a builtin name under a mangled key and maps it back on the way out, sopacketnever lands in__dict__itself – which routes reading it through__getattr__(), where the deferred analysis can run, whiledict(datagram),to_dict()and iteration still report the field under its own name.