Short-Read Replay¶
pcapkit.corekit.schema.shortread carries a header cut short by the end of the
capture through to the protocol’s info, by which a protocol rebuilt from that info
is cut back to the octets its header had (#1458), for the layer base classes
and the PCAP global header alike, and tells a protocol’s checks of a header parsed on
its own where the cut fell (#2880). It names the protocol and schema classes
for type checking only, since those import it.
Added in version 1.6.0: Moved here from pcapkit.protocols.schema.schema (#2674).
- pcapkit.corekit.schema.shortread.keep_short_read(protocol, length=None)[source]¶
Carry a parsed header’s short read into the protocol’s info.
- Parameters:
protocol (
ProtocolBase) – Protocol instance, just parsed.length (
int|None) – Length of data the parse was given,Nonefor the octets it holds.
- Return type:
Called by the layer base classes, and by the PCAP global
Header, once a parse is done. When the data ended inside one of the header’s fields,infogains the__short_read__recordSchema.unpackmade, so thatProtocol.from_datahands it to the rebuild, whoseProtocol.packcuts the header back to what was captured before it is read (#1458, #2703). Beside it,__short_width__records the length the parse read the header at, which the rebuild is read at in turn, so that it holds the values its parse read (#2761). Both keys are listed inData.__included__, soInfo.to_dictcarries them andfrom_data(info.to_dict())cuts its rebuild back too; they are absent for a header that was captured whole.Where the capture cut the frame short, as
frame_lengthgives its lengths, a layer whose message runs to the end of the frame records the cut too, on the field it runs to the end in, throughSchema._note_short_read, so its rebuild reads as cut, as the layer did inside the frame (#2711). A layer whose own header declares where its message ends records none, whether the cut falls at that end or past it; seeSchema._frame_end_field.
- pcapkit.corekit.schema.shortread.replay_short_read(protocol, data)[source]¶
Hold a protocol rebuilt by
from_datato the octets its header had.- Parameters:
protocol (
_PB) – Protocol instance, just built byfrom_data.data (
Any) – The info it was built from.
- Return type:
_PB- Returns:
protocolitself.
The layer base classes and the PCAP global
Headercall it on whatProtocol.from_datareturns, which is cut back before it gets here:from_datahands the construction the__short_read__record thatkeep_short_read()left indata,Protocol.packcuts the header it makes back to the octets captured throughSchema._cut_short_read, andProtocol.__post_init__hasread()parse those octets at the width__short_width__records, the one its parse read them at, so the rebuild is read and verified as its capture was (#2703, #2761).The record names the field the capture ended inside and how much of it there was. Everything in the rebuild from that point on is dropped, which on a rebuild cut back as above is nothing, and the header and the info keep the record (#1458). A header cut short has no payload past it, so that point ends the rebuilt data, and what the protocol writes ahead of the header is kept: the HTTP/2 connection preface
HTTP.packwrites (#2665). This holds whilepackwrites nothing after the header schema, as no protocol rebuilt here does; a trailer would keep as many of the cut octets.
- pcapkit.corekit.schema.shortread.hoist_short_read(schema, name, parts)[source]¶
Record on
schemaa short read only the schemas in its fieldnamerecorded.- Parameters:
Each of
partsmust read to the end of the data, so a field there that reads short has reached it, and the record namesnamewith every octet of it read. Elsewhere a nested record need not mean that: hoisting one inkeep_short_read()marks a complete TCP segment with a malformed MPTCP DSS option as cut (#2660). IGMPv3 and ICMPv6 hoist the record of a message body counting records the data ends before.Added in version 1.7.0.
- pcapkit.corekit.schema.shortread.cut_on_its_own(header, name=None, end=None)[source]¶
Tell a check of a header parsed on its own whether the data ended before what it reads.
- Parameters:
- Return type:
- Returns:
Whether
headerwas parsed with no layer before it, asframe_depthtells, and the short read it records ends the data before those octets ofname, or anywhere in it without aname.
On its own the end of the data is a cut (#2880), so a value past it is a zero the cut left, not one read. A check that would refuse such a value leaves it to the short read, as a field callback does (#2727), and so does one refusing a header length the data ends inside, refused on #1404 because the rebuild filled the zeros in, which the short read now cuts back. Inside a frame its lengths say where the message ends, so such a check refuses as before.
Added in version 1.7.0.
- pcapkit.corekit.schema.shortread.fill_short_options(data, options, size, zero, padding=None)[source]¶
Fill out an options area a short read ended inside, so a rebuild writes its length.
- Parameters:
data (
Any) – The data model a protocol is rebuilt from.options (
Any) – Its options, keyed by code, as the protocol’sreadgives them, orNonefor none.size (
int) – Octets its header length gives the options area.zero (
tuple[Any,Any]) – The code and data model of the one-octet option a zero octet reads as.padding (
bytes|None) – Octets it records after an End of Option List, orNonewhere the protocol records none.
- Return type:
- Returns:
optionsandpaddingtosizeoctets wheredatarecords a short read: pastsize, trailingzerooptions dropped; short of it, filled out with zero octets, afterpaddingwhere the options end withzero, else as that manyzerooptions.
A header length the data ends before is read as parsed on its own (
cut_on_its_own()), butmakewrites the length of the options it is given, which past the cut are a cut option’s whole length and the end of the list its zeros read as. Whatever is filled or dropped lies past the cut, so the rebuild’s cut back leaves the octets and the header length its parse read (#2880).Added in version 1.7.0.
- pcapkit.corekit.schema.shortread.ends_inside_option(options, count)[source]¶
Tell whether the first
countoctets of an options area end inside one of its options.- Parameters:
- Return type:
- Returns:
Whether an option starts before
countoctets and declares more than them.
Such an option rebuilds by the values it holds rather than by the length it declares, so neither its own length nor the header length before it would rebuild as parsed: a header the data ends inside an option of stays refused on its own too (#1404, #2880).
Added in version 1.7.0.