TCP - Transmission Control Protocol¶
pcapkit.protocols.transport.tcp contains
TCP only,
which implements extractor for Transmission Control
Protocol (TCP) [*], whose structure is described as
below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Source Port |
2 |
16 |
|
Destination Port |
4 |
32 |
|
Sequence Number |
8 |
64 |
|
Acknowledgement Number (if ACK set) |
12 |
96 |
|
Data Offset |
12 |
100 |
Reserved (must be |
|
12 |
103 |
|
ECN Concealment Protection (NS) [†] |
13 |
104 |
|
Congestion Window Reduced (CWR) |
13 |
105 |
|
ECN-Echo (ECE) |
13 |
106 |
|
Urgent (URG) |
13 |
107 |
|
Acknowledgement (ACK) |
13 |
108 |
|
Push Function (PSH) |
13 |
109 |
|
Reset Connection (RST) |
13 |
110 |
|
Synchronize Sequence Numbers (SYN) |
13 |
111 |
|
Last Packet from Sender (FIN) |
14 |
112 |
|
Size of Receive Window |
16 |
128 |
|
Checksum |
18 |
144 |
|
Urgent Pointer (if URG set) |
20 |
160 |
|
TCP Options (if data offset > 5) |
- class pcapkit.protocols.transport.tcp.TCP(file=None, length=None, **kwargs)[source]¶
-
This class implements Transmission Control Protocol.
This class currently supports parsing of the following protocols, which are registered in the
self.__proto__attribute:Port Number
Protocol
20
21
80
8080
This class currently supports parsing of the following TCP options, which are directly mapped to the
pcapkit.const.tcp.option.Optionenumeration:Option Code
Option Parser
Option Constructor
This class currently supports parsing of the following Multipath TCP options, which are directly mapped to the
pcapkit.const.tcp.mp_tcp_option.MPTCPOptionenumeration:Option Code
Option Parser
Option Constructor
- classmethod register_mp_option(code, meth)[source]¶
Register an MPTCP option parser.
- Parameters:
code (
MPTCPOption) – MPTCP option code.meth (
str|tuple[Callable[[MPTCP,OrderedMultiDict[Option,Option]],MPTCP],Callable[[MPTCPOption,MPTCP|None,Any],MPTCP]]) – Method name or callable to parse and/or construct the option.
- read(length=None, **kwargs)[source]¶
Read Transmission Control Protocol (TCP).
Structure of TCP header [RFC 793]:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Port | Destination Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Sequence Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Acknowledgement Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Data | |U|A|P|R|S|F| | | Offset| Reserved |R|C|S|S|Y|I| Window | | | |G|K|H|T|N|N| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Checksum | Urgent Pointer | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | data | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- make(srcport=0, dstport=0, seq_no=0, ack_no=0, ns=False, cwr=False, ece=False, urg=False, ack=False, psh=False, rst=False, syn=False, fin=False, window=65535, checksum=b'\\x00\\x00', urgent=0, options=None, payload=b'', **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
seq_no (
int) – Sequence number.ack_no (
int) – Acknowledgement number.ns (
bool) – ECN-nonce concealment protection.cwr (
bool) – Congestion window reduced.ece (
bool) – ECN-Echo.urg (
bool) – Urgent.ack (
bool) – Acknowledgement.psh (
bool) – Push function.rst (
bool) – Reset connection.syn (
bool) – Synchronize sequence numbers.fin (
bool) – Last packet from sender.window (
int) – Window size.checksum (
bytes) – Checksum.urgent (
int) – Urgent pointer.options (
list[Option|tuple[Option,dict[str,Any]] |bytes] |OrderedMultiDict[Option,Option] |None) – TCP options.payload (
bytes|ProtocolBase|Schema) – Payload of the packet.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- _read_tcp_options(size)[source]¶
Read TCP option list.
- Parameters:
size (
int) – length of option list- Return type:
- Returns:
Extracted TCP options.
- Raises:
ProtocolError – If the threshold is NOT matching.
- _read_mode_donone(schema, *, options)[source]¶
Read options request no process.
- Parameters:
schema (
UnassignedOption) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- _read_mode_eool(schema, *, options)[source]¶
Read TCP End of Option List option.
Structure of TCP end of option list option [RFC 793]:
+--------+ |00000000| +--------+ Kind=0
- Parameters:
schema (
EndOfOptionList) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- _read_mode_nop(schema, *, options)[source]¶
Read TCP No Operation option.
Structure of TCP maximum segment size option [RFC 793]:
+--------+ |00000001| +--------+ Kind=1
- Parameters:
schema (
NoOperation) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- _read_mode_mss(schema, *, options)[source]¶
Read TCP max segment size option.
Structure of TCP maximum segment size option [RFC 793]:
+--------+--------+---------+--------+ |00000010|00000100| max seg size | +--------+--------+---------+--------+ Kind=2 Length=4
- Parameters:
schema (
MaximumSegmentSize) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
4.
- _read_mode_ws(schema, *, options)[source]¶
Read TCP windows scale option.
Structure of TCP window scale option [RFC 7323]:
+---------+---------+---------+ | Kind=3 |Length=3 |shift.cnt| +---------+---------+---------+ 1 1 1- Parameters:
schema (
WindowScale) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
3.
- _read_mode_sackpmt(schema, *, options)[source]¶
Read TCP SACK permitted option.
Structure of TCP SACK permitted option [RFC 2018]:
+---------+---------+ | Kind=4 | Length=2| +---------+---------+
- Parameters:
schema (
SACKPermitted) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
2.
- _read_mode_sack(schema, *, options)[source]¶
Read TCP SACK option.
Structure of TCP SACK option [RFC 2018]:
+--------+--------+ | Kind=5 | Length | +--------+--------+--------+--------+ | Left Edge of 1st Block | +--------+--------+--------+--------+ | Right Edge of 1st Block | +--------+--------+--------+--------+ | | / . . . / | | +--------+--------+--------+--------+ | Left Edge of nth Block | +--------+--------+--------+--------+ | Right Edge of nth Block | +--------+--------+--------+--------+- Parameters:
schema (
SACK) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT multiply of
8plus2.
- _read_mode_echo(schema, *, options)[source]¶
Read TCP echo option.
Structure of TCP echo option [RFC 1072]:
+--------+--------+--------+--------+--------+--------+ | Kind=6 | Length | 4 bytes of info to be echoed | +--------+--------+--------+--------+--------+--------+
- Parameters:
schema (
Echo) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
6.
- _read_mode_echore(schema, *, options)[source]¶
Read TCP echo reply option.
Structure of TCP echo reply option [RFC 1072]:
+--------+--------+--------+--------+--------+--------+ | Kind=7 | Length | 4 bytes of echoed info | +--------+--------+--------+--------+--------+--------+
- Parameters:
schema (
EchoReply) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
6.
- _read_mode_ts(schema, *, options)[source]¶
Read TCP timestamps option.
Structure of TCP timestamp option [RFC 7323]:
+-------+-------+---------------------+---------------------+ |Kind=8 | 10 | TS Value (TSval) |TS Echo Reply (TSecr)| +-------+-------+---------------------+---------------------+ 1 1 4 4- Parameters:
schema (
Timestamps) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
10.
- _read_mode_poc(schema, *, options)[source]¶
Read TCP partial order connection service profile option.
Structure of TCP
POC-Permittedoption [RFC 1693][RFC 6247]:+-----------+-------------+ | Kind=9 | Length=2 | +-----------+-------------+
- Parameters:
schema (
PartialOrderConnectionPermitted) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
2.
- _read_mode_pocsp(schema, *, options)[source]¶
Read TCP partial order connection service profile option.
Structure of TCP
POC-SPoption [RFC 1693][RFC 6247]:1 bit 1 bit 6 bits +----------+----------+------------+----------+--------+ | Kind=10 | Length=3 | Start_flag | End_flag | Filler | +----------+----------+------------+----------+--------+
- Parameters:
schema (
PartialOrderServiceProfile) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
3.
- _read_mode_cc(schema, *, options)[source]¶
Read TCP connection count option.
Structure of TCP
CCoption [RFC 1644]:+--------+--------+--------+--------+--------+--------+ |00001011|00000110| Connection Count: SEG.CC | +--------+--------+--------+--------+--------+--------+ Kind=11 Length=6
- Parameters:
schema (
CC) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
6.
- _read_mode_ccnew(schema, *, options)[source]¶
Read TCP connection count (new) option.
Structure of TCP
CC.NEWoption [RFC 1644]:+--------+--------+--------+--------+--------+--------+ |00001100|00000110| Connection Count: SEG.CC | +--------+--------+--------+--------+--------+--------+ Kind=12 Length=6
- Parameters:
schema (
CCNew) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
6.
- _read_mode_ccecho(schema, *, options)[source]¶
Read TCP connection count (echo) option.
Structure of TCP
CC.ECHOoption [RFC 1644]:+--------+--------+--------+--------+--------+--------+ |00001101|00000110| Connection Count: SEG.CC | +--------+--------+--------+--------+--------+--------+ Kind=13 Length=6
- Parameters:
schema (
CCEcho) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
6.
- _read_mode_chkreq(schema, *, options)[source]¶
Read TCP Alternate Checksum Request option.
Structure of TCP
CHKSUM-REQ[RFC 1146][RFC 6247]:+----------+----------+----------+ | Kind=14 | Length=3 | chksum | +----------+----------+----------+
- Parameters:
schema (
AlternateChecksumRequest) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
3.
- _read_mode_chksum(schema, *, options)[source]¶
Read Alternate Checksum Data option.
Structure of TCP
CHKSUM[RFC 1146][RFC 6247]:+---------+---------+---------+ +---------+ | Kind=15 |Length=N | data | ... | data | +---------+---------+---------+ +---------+
- Parameters:
schema (
AlternateChecksumData) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- _read_mode_sig(schema, *, options)[source]¶
Read MD5 Signature option.
Structure of TCP
SIGoption [RFC 2385]:+---------+---------+-------------------+ | Kind=19 |Length=18| MD5 digest... | +---------+---------+-------------------+ | | +---------------------------------------+ | | +---------------------------------------+ | | +-------------------+-------------------+ | | +-------------------+
- Parameters:
schema (
MD5Signature) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
18.
- _read_mode_qs(schema, *, options)[source]¶
Read Quick-Start Response option.
Structure of TCP
QSopt[RFC 4782]:0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Kind | Length=8 | Resv. | Rate | TTL Diff | | | | |Request| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | QS Nonce | R | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Parameters:
schema (
QuickStartResponse) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
8.
- _read_mode_timeout(schema, *, options)[source]¶
Read User Timeout option.
Structure of TCP
TIMEOUT[RFC 5482]:0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Kind = 28 | Length = 4 |G| User Timeout | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Parameters:
schema (
UserTimeout) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
4.
- _read_mode_ao(schema, *, options)[source]¶
Read Authentication option.
Structure of TCP
AOopt[RFC 5925]:+------------+------------+------------+------------+ | Kind=29 | Length | KeyID | RNextKeyID | +------------+------------+------------+------------+ | MAC ... +-----------------------------------... ...-----------------+ ... MAC (con't) | ...-----------------+
- Parameters:
schema (
Authentication) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT larger than or equal to
4.
- _read_mode_mp(schema, *, options)[source]¶
Read Multipath TCP option.
Structure of
MP-TCP[RFC 6824]:1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+---------------+-------+-----------------------+ | Kind | Length |Subtype| | +---------------+---------------+-------+ | | Subtype-specific data | | (variable length) | +---------------------------------------------------------------+
- Parameters:
schema (
MPTCP) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- _read_mode_fastopen(schema, *, options)[source]¶
Read Fast Open option.
Structure of TCP
FASTOPEN[RFC 7413]:+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Kind | Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | ~ Cookie ~ | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Parameters:
schema (
FastOpenCookie) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT valid.
- _read_mptcp_unknown(schema, *, options)[source]¶
Read unknown MPTCP subtype.
- Parameters:
schema (
MPTCPUnknown) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- _read_mptcp_capable(schema, *, options)[source]¶
Read Multipath Capable option.
Structure of
MP_CAPABLE[RFC 6824]:1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+---------------+-------+-------+---------------+ | Kind | Length |Subtype|Version|A|B|C|D|E|F|G|H| +---------------+---------------+-------+-------+---------------+ | Option Sender's Key (64 bits) | | | | | +---------------------------------------------------------------+ | Option Receiver's Key (64 bits) | | (if option Length == 20) | | | +---------------------------------------------------------------+
- Parameters:
schema (
MPTCPCapable) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
12or20.
- _read_mptcp_join(schema, *, options)[source]¶
Read Join Connection option.
- Parameters:
schema (
MPTCPJoin) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If the option is not given on a valid SYN/ACK packet.
- _read_mptcp_dss(schema, *, options)[source]¶
Read Data Sequence Signal (Data ACK and Data Sequence Mapping) option.
Structure of
DSS[RFC 8684, section 3.3, figure 9]:1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+---------------+-------+----------------------+ | Kind | Length |Subtype| (reserved) |F|m|M|a|A| +---------------+---------------+-------+----------------------+ | | | Data ACK (4 or 8 octets, depending on flags) | | | +--------------------------------------------------------------+ | | | Data sequence number (4 or 8 octets, depending on flags) | | | +--------------------------------------------------------------+ | Subflow Sequence Number (4 octets) | +-------------------------------+------------------------------+ | Data-Level Length (2 octets) | Checksum (2 octets) | +-------------------------------+------------------------------+
- Parameters:
schema (
MPTCPDSS) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- _read_mptcp_addaddr(schema, *, options)[source]¶
Read Add Address option.
Structure of
ADD_ADDR[RFC 6824]:1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+---------------+-------+-------+---------------+ | Kind | Length |Subtype| IPVer | Address ID | +---------------+---------------+-------+-------+---------------+ | Address (TCP - 4 octets / IPv6 - 16 octets) | +-------------------------------+-------------------------------+ | Port (2 octets, optional) | +-------------------------------+
- Parameters:
schema (
MPTCPAddAddress) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – Invalid IP version and/or addresses.
- _read_mptcp_remove(schema, *, options)[source]¶
Read Remove Address option.
Structure of
REMOVE_ADDR[RFC 8684, section 3.4.2, figure 13]:1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+---------------+-------+-------+---------------+ | Kind | Length = 3+n |Subtype|(resvd)| Address ID | ... +---------------+---------------+-------+-------+---------------+ (followed by n-1 Address IDs, if required)- Parameters:
schema (
MPTCPRemoveAddress) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If the length is smaller than 3.
Note
Length = 3 + n, per the figure above: the 3 isKind(1) +Length(1) + subtype-and-reserved (1), and each of the n Address IDs is one further octet.addr_idsizes its list aspkt['length'] - 3from exactly this, which is why_make_mptcp_remove’s constantlength=4(fixed in #576) also mis-sized the parse rather than only the pack.The guard permits
3, i.e.n = 0, which the figure does not describe – it shows one Address ID plus “n-1 Address IDs, if required”. Left as it stands: tightening it to reject an empty list is a behaviour change beyond #576’s scope, and a zero-ID REMOVE_ADDR now at least round-trips honestly instead of declaring an octet it never packed.
- _read_mptcp_prio(schema, *, options)[source]¶
Read Change Subflow Priority option.
Structure of
MP_PRIO[RFC 6824, section 3.3.8, figure 11]:1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+---------------+-------+-----+-+--------------+ | Kind | Length |Subtype| |B| AddrID (opt) | +---------------+---------------+-------+-----+-+--------------+
- Parameters:
schema (
MPTCPPriority) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If the length is neither 3 nor 4.
Note
The figure above is RFC 6824’s, deliberately, because it is the one with an Address ID in it and this method accepts both forms. RFC 8684 section 3.3.8 figure 11 draws MP_PRIO as 3 octets and nothing more –
Kind(1) +Length(1) + subtype/reserved/B(1) – since section 5 of that document “specifies the removal of the AddrID field [RFC6824] in the MP_PRIO option”, closing a theoretical attack in which a subflow could be forced into backup mode. The 4-octet RFC 6824 form is therefore legacy, and the guard stays permissive so that traffic carrying it still parses._make_mptcp_priodeclared a constantlength=4until #576, which meant the construction side could only ever emit the legacy form – and emitted it with an all-zero phantom Address ID when the caller supplied none, becauseMPTCPPriority’saddr_idis conditional on that very length being 4.
- _read_mptcp_fail(schema, *, options)[source]¶
Read Fallback option.
Structure of
MP_FAIL[RFC 6824]:1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+---------------+-------+----------------------+ | Kind | Length=12 |Subtype| (reserved) | +---------------+---------------+-------+----------------------+ | | | Data Sequence Number (8 octets) | | | +--------------------------------------------------------------+
- Parameters:
schema (
MPTCPFallback) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If the length is NOT 12.
- _read_mptcp_fastclose(schema, options)[source]¶
Read Fast Close option.
Structure of
MP_FASTCLOSE[RFC 8684, section 3.5, figure 14]:1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+---------------+-------+-----------------------+ | Kind | Length |Subtype| (reserved) | +---------------+---------------+-------+-----------------------+ | Option Receiver's Key | | (64 bits) | | | +---------------------------------------------------------------+
- Parameters:
schema (
MPTCPFastclose) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If the length is NOT 12.
Note
The figure above is RFC 8684 section 3.5 figure 14, and the option it draws is 12 octets:
Kind(1) +Length(1) + subtype-and-reserved (2, being 4 subtype bits and 12 reserved) + the option receiver’s key (64 bits, 8). Note that section 3.5 is Fast Close; section 3.7 is Fallback (MP_FAIL), which #576’s own text cited here by mistake.Three sites disagreed on this number before #576, all three now reading 12: this guard required
16, an octet count nothing in the RFC produces for MP_FASTCLOSE;_make_mptcp_fastclosedeclared the correct 12 but the schema packed only 11, missing the reserved octet entirely. The net effect was that constructing an MP_FASTCLOSE throughTCPraisedProtocolErrorfrom this very guard – the maker’s correct length failing the parser’s wrong check – which is whytcp-mptcp/MP_FASTCLOSEsat inEXPECTED_FAILURES.
- _read_join_syn(schema, *, options)[source]¶
Read Join Connection option for Initial SYN.
Structure of
MP_JOIN-SYN[RFC 8684, section 3.2, figure 5]:1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+---------------+-------+-----+-+---------------+ | Kind | Length = 12 |Subtype| |B| Address ID | +---------------+---------------+-------+-----+-+---------------+ | Receiver's Token (32 bits) | +---------------------------------------------------------------+ | Sender's Random Number (32 bits) | +---------------------------------------------------------------+
- Parameters:
schema (
MPTCPJoinSYN) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
12.
- _read_join_synack(schema, options)[source]¶
Read Join Connection option for Responding SYN/ACK.
Structure of
MP_JOIN-SYN/ACK[RFC 8684, section 3.2, figure 6]:1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+---------------+-------+-----+-+---------------+ | Kind | Length = 16 |Subtype| |B| Address ID | +---------------+---------------+-------+-----+-+---------------+ | | | Sender's Truncated HMAC (64 bits) | | | +---------------------------------------------------------------+ | Sender's Random Number (32 bits) | +---------------------------------------------------------------+
- Parameters:
schema (
MPTCPJoinSYNACK) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
16.
Note
The accepted length is
16, which is what the figure above – and RFC 8684 section 3.2 figure 6, which it reproduces – states, and whatMPTCPJoinSYNACKactually packs and unpacks:Kind(1) +Length(1) + subtype/flags (1) +Address ID(1) + the truncated HMAC (8) + the random number (4).This guard required
20until #576 – a value that appears in neither the figure nor the schema, and that contradicted this method’s own docstring. Together with_make_join_synack’slength=12it made the SYN/ACK form unusable in both directions at once: the maker could not produce a length this guard accepted, and a spec-correct 16-octet option off the wire was rejected as an invalid format.
- _read_join_ack(schema, *, options)[source]¶
Read Join Connection option for Third ACK.
Structure of
MP_JOIN-ACK[RFC 8684, section 3.2, figure 7]:1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +---------------+---------------+-------+-----------------------+ | Kind | Length = 24 |Subtype| (reserved) | +---------------+---------------+-------+-----------------------+ | | | | | Sender's HMAC (160 bits) | | | | | +---------------------------------------------------------------+
- Parameters:
schema (
MPTCPJoinACK) – parsed option schemaoptions (
OrderedMultiDict[Option,Option]) – extracted TCP options
- Return type:
- Returns:
Parsed option data.
- Raises:
ProtocolError – If length is NOT
24.
- _make_mode_donone(code, opt=None, *, data=b'', **kwargs)[source]¶
Make TCP unassigned option.
- Parameters:
- Return type:
- Returns:
Constructed option schema.
- _make_mode_eool(code, opt=None, **kwargs)[source]¶
Make TCP End of Option List option.
- Parameters:
code (
Option) – option codeopt (
EndOfOptionList|None) – option data**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mode_nop(code, opt=None, **kwargs)[source]¶
Make TCP NoOperation option.
- Parameters:
code (
Option) – option codeopt (
NoOperation|None) – option data**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mode_mss(code, opt=None, *, mss=65535, **kwargs)[source]¶
Make TCP maximum segment size option.
- Parameters:
code (
Option) – option codeopt (
MaximumSegmentSize|None) – option datamss (
int) – maximum segment size**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mode_ws(code, opt=None, *, shift=0, **kwargs)[source]¶
Make TCP window scale option.
- Parameters:
code (
Option) – option codeopt (
WindowScale|None) – option datashift (
int) – window scale shift count**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mode_sackpmt(code, opt=None, **kwargs)[source]¶
Make TCP SACK permitted option.
- Parameters:
code (
Option) – option codeopt (
SACKPermitted|None) – option data**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mode_echo(code, opt=None, *, data=b'\\x00\\x00\\x00\\x00', **kwargs)[source]¶
Make TCP echo option.
- _make_mode_echore(code, opt=None, *, data=b'\\x00\\x00\\x00\\x00', **kwargs)[source]¶
Make TCP echo reply option.
- _make_mode_ts(code, opt=None, *, tsval=0, tsecr=0, **kwargs)[source]¶
Make TCP timestamps option.
- Parameters:
- Return type:
- Returns:
Constructed option schema.
- _make_mode_poc(code, opt=None, **kwargs)[source]¶
Make TCP partial order connection option.
- Parameters:
code (
Option) – option codeopt (
PartialOrderConnectionPermitted|None) – option data**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mode_pocsp(code, opt=None, *, start=False, end=False, **kwargs)[source]¶
Make TCP partial order connection service profile option.
- Parameters:
- Return type:
- Returns:
Constructed option schema.
- _make_mode_ccnew(code, opt=None, *, count=0, **kwargs)[source]¶
Make TCP connection count new option.
- _make_mode_ccecho(code, opt=None, *, count=0, **kwargs)[source]¶
Make TCP connection count echo option.
- _make_mode_chkreq(code, opt=None, *, algorithm=<Checksum.TCP_checksum: 0>, algorithm_default=None, algorithm_namespace=None, algorithm_reversed=False, **kwargs)[source]¶
Make TCP alternate checksum request option.
- Parameters:
code (
Option) – option codeopt (
AlternateChecksumRequest|None) – option dataalgorithm (
Checksum|IntEnum|IntEnum|int|str) – checksum algorithmalgorithm_default (
int|None) – default value for checksum algorithmalgorithm_namespace (
dict[str,int] |dict[int,str] |Type[IntEnum] |Type[IntEnum] |None) – namespace for checksum algorithmalgorithm_reversed (
bool) – reversed flag for checksum algorithm**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mode_chksum(code, opt=None, *, data=b'', **kwargs)[source]¶
Make TCP alternate checksum data option.
- Parameters:
code (
Option) – option codeopt (
AlternateChecksumData|None) – option datadata (
bytes) – checksum data**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mode_sig(code, opt=None, *, digest=b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', **kwargs)[source]¶
Make TCP MD5 signature option.
- Parameters:
code (
Option) – option codeopt (
MD5Signature|None) – option datadigest (
bytes) – digest**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mode_qs(code, opt=None, *, rate=0, diff=0, nonce=0, **kwargs)[source]¶
Make TCP quick start response option.
- Parameters:
- Return type:
- Returns:
Constructed option schema.
- _make_mode_timeout(code, opt=None, *, timeout=0, **kwargs)[source]¶
Make TCP user timeout option.
- Parameters:
- Return type:
- Returns:
Constructed option schema.
- _make_mode_ao(code, opt=None, *, key_id=0, next_key_id=0, mac=b'', **kwargs)[source]¶
Make TCP authentication option.
- Parameters:
- Return type:
- Returns:
Constructed option schema.
- _make_mode_mp(code, opt=None, *, subtype=<MPTCPOption.MP_CAPABLE: 0>, subtype_default=None, subtype_namespace=None, subtype_reversed=False, **kwargs)[source]¶
Make multipath TCP option.
- Parameters:
code (
Option) – option codesubtype (
MPTCPOption|IntEnum|IntEnum|int|str) – MPTCP subtypesubtype_default (
int|None) – default value for MPTCP subtypesubtype_namespace (
dict[str,int] |dict[int,str] |Type[IntEnum] |Type[IntEnum] |None) – namespace for MPTCP subtypesubtype_reversed (
bool) – reversed flag for MPTCP subtype**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mode_fastopen(code, opt=None, *, cookie=None, **kwargs)[source]¶
Make TCP Fast Open option.
- Parameters:
- Return type:
- Returns:
Constructed option schema.
- _make_mptcp_unknown(subtype, opt=None, *, data=b'\\x00', **kwargs)[source]¶
Make unknown multipath TCP option.
- Parameters:
subtype (
MPTCPOption) – MPTCP subtypeopt (
MPTCPUnknown|None) – option datadata (
bytes) – option payload data**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mptcp_capable(subtype, opt=None, *, version=0, flag_req=False, flag_ext=False, flag_hsa=False, skey=0, rkey=0, **kwargs)[source]¶
Make multipath TCP capable option.
- Parameters:
subtype (
MPTCPOption) – MPTCP subtypeopt (
MPTCPCapable|None) – option dataversion (
int) – MPTCP versionflag_req (
bool) – checksum required flagflag_ext (
bool) – extensability flagflag_hsa (
bool) – use of HMAC-SHA1 flagskey (
int) – option sender’s key**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mptcp_join(subtype, opt=None, **kwargs)[source]¶
Make multipath TCP join option.
- Parameters:
subtype (
MPTCPOption) – MPTCP subtype**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mptcp_dss(subtype, opt=None, *, data_fin=False, ack=None, dsn=None, ssn=None, dl_len=None, checksum=None, **kwargs)[source]¶
Make multipath TCP DSS option.
- Parameters:
subtype (
MPTCPOption) – MPTCP subtypedata_fin (
bool) –DATA_FINflag**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mptcp_addaddr(subtype, opt=None, *, addr_id=0, addr='0.0.0.0', port=None, **kwargs)[source]¶
Make multipath TCP add address option.
- Parameters:
subtype (
MPTCPOption) – MPTCP subtypeopt (
MPTCPAddAddress|None) – option dataaddr_id (
int) – address IDaddr (
IPv4Address|IPv6Address|int|bytes|str) – address**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mptcp_remove(subtype, opt=None, *, addr_id=None, **kwargs)[source]¶
Make multipath TCP remove address option.
- Parameters:
subtype (
MPTCPOption) – MPTCP subtypeopt (
MPTCPRemoveAddress|None) – option data**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mptcp_prio(subtype, opt=None, *, backup=False, addr_id=None, **kwargs)[source]¶
Make multipath TCP priority option.
- Parameters:
subtype (
MPTCPOption) – MPTCP subtypeopt (
MPTCPPriority|None) – option databackup (
bool) – backup flag**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mptcp_fail(subtype, opt=None, *, dsn=0, **kwargs)[source]¶
Make multipath TCP fail option.
- Parameters:
subtype (
MPTCPOption) – MPTCP subtypeopt (
MPTCPFallback|None) – option datadsn (
int) – data sequence number**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_mptcp_fastclose(subtype, opt=None, *, key=0, **kwargs)[source]¶
Make multipath TCP fastclose option.
- Parameters:
subtype (
MPTCPOption) – MPTCP subtypeopt (
MPTCPFastclose|None) – option datakey (
int) – option receiver’s key**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_join_syn(subtype, opt=None, *, backup=False, addr_id=0, token=0, nonce=0, **kwargs)[source]¶
Make multipath TCP join SYN option.
- Parameters:
subtype (
MPTCPOption) – MPTCP subtypeopt (
MPTCPJoinSYN|None) – option databackup (
bool) – backup flagaddr_id (
int) – address IDtoken (
int) – receiver’s tokennonce (
int) – sender’s random number**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_join_synack(subtype, opt=None, *, backup=False, addr_id=0, hmac=b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', nonce=0, **kwargs)[source]¶
Make multipath TCP join SYN/ACK option.
- Parameters:
subtype (
MPTCPOption) – MPTCP subtypeopt (
MPTCPJoinSYNACK|None) – option databackup (
bool) – backup flagaddr_id (
int) – address IDhmac (
bytes) – sender’s truncated HMACnonce (
int) – sender’s random number**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- _make_join_ack(subtype, opt=None, *, hmac=b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', **kwargs)[source]¶
Make multipath TCP join ACK option.
- Parameters:
subtype (
MPTCPOption) – MPTCP subtypeopt (
MPTCPJoinACK|None) – option datahmac (
bytes) – sender’s HMAC**kwargs (
Any) – arbitrary keyword arguments
- Return type:
- Returns:
Constructed option schema.
- __proto__: DefaultDict[int, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]¶
Protocol index mapping for decoding next layer, c.f.
self._decode_next_layer&self._import_next_layer.- Type:
DefaultDict[int, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]
- __option__: DefaultDict[int, str | tuple[Callable[[Option, OrderedMultiDict[Option, Option]], Option], Callable[[Option, Option | None, Any], Option]]]¶
Option code to method mapping, c.f.
_read_tcp_options()and_make_tcp_options(). Method names are expected to be referred to the class by_read_mode_${name}and_make_mode_${name}, and if such name not found, the value should then be a method that can parse the option by itself.
- __mp_option__: DefaultDict[int, str | tuple[Callable[[MPTCP, OrderedMultiDict[Option, Option]], MPTCP], Callable[[MPTCPOption, MPTCP | None, Any], MPTCP]]]¶
Option code to method mapping, c.f.
_read_mode_mp()and_make_mode_mp(). Method names are expected to be referred to the class by_read_mptcp_${name}and_make_mptcp_${name}, and if such name not found, the value should then be a method that can parse the option by itself.
Header Schemas¶
- class pcapkit.protocols.schema.transport.tcp.TCP(*args: _VT, **kwargs: _VT)[source]¶
Bases:
SchemaHeader schema for TCP packet.
- offset: OffsetFlag = <BitField offset>¶
Data offset.
- class pcapkit.protocols.schema.transport.tcp.Option(dict_=None, **kwargs)[source]¶
Bases:
EnumSchema[Option]Header schema for TCP options.
- class pcapkit.protocols.schema.transport.tcp.UnassignedOption(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP unassigned options.
- class pcapkit.protocols.schema.transport.tcp.EndOfOptionList(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP end of option list.
- class pcapkit.protocols.schema.transport.tcp.NoOperation(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP no operation.
- class pcapkit.protocols.schema.transport.tcp.MaximumSegmentSize(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP max segment size option.
- class pcapkit.protocols.schema.transport.tcp.WindowScale(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP window scale option.
- class pcapkit.protocols.schema.transport.tcp.SACKPermitted(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP SACK permitted option.
- class pcapkit.protocols.schema.transport.tcp.SACK(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP SACK option.
- class pcapkit.protocols.schema.transport.tcp.Echo(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP echo option.
- class pcapkit.protocols.schema.transport.tcp.EchoReply(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP echo reply option.
- class pcapkit.protocols.schema.transport.tcp.Timestamps(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP timestamps option.
- class pcapkit.protocols.schema.transport.tcp.PartialOrderConnectionPermitted(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP partial order connection permitted option.
- class pcapkit.protocols.schema.transport.tcp.PartialOrderServiceProfile(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP partial order connection service profile option.
- profile: POCProfile = <BitField profile>¶
Profile data.
- class pcapkit.protocols.schema.transport.tcp.CC(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP CC option.
- class pcapkit.protocols.schema.transport.tcp.CCNew(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP connection count (new) option.
- class pcapkit.protocols.schema.transport.tcp.CCEcho(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP connection count (echo) option.
- class pcapkit.protocols.schema.transport.tcp.AlternateChecksumRequest(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP alternate checksum request option.
- class pcapkit.protocols.schema.transport.tcp.AlternateChecksumData(kind, length, data)[source]¶
Bases:
OptionHeader schema for TCP alternate checksum data option.
- class pcapkit.protocols.schema.transport.tcp.MD5Signature(kind, length, digest)[source]¶
Bases:
OptionHeader schema for TCP MD5 signature option.
- class pcapkit.protocols.schema.transport.tcp.QuickStartResponse(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP quick start response option.
- flags: QuickStartFlags = <BitField flags>¶
Flags.
- nonce: QuickStartNonce = <BitField nonce>¶
QS nonce.
- class pcapkit.protocols.schema.transport.tcp.UserTimeout(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP user timeout option.
- info: TimeoutInfo = <BitField info>¶
Granularity and user timeout.
- class pcapkit.protocols.schema.transport.tcp.Authentication(*args: _VT, **kwargs: _VT)[source]¶
Bases:
OptionHeader schema for TCP authentication option.
- class pcapkit.protocols.schema.transport.tcp.FastOpenCookie(*args: _VT, **kwargs: _VT)[source]¶
Bases:
Option“Header schema for TCP Fast Open option.
- class pcapkit.protocols.schema.transport.tcp.MPTCP(dict_=None, **kwargs)[source]¶
Bases:
EnumSchema[MPTCPOption]Header schema for Multipath TCP options.
- subtype: MPTCPOption¶
MPTCP subtype.
- class pcapkit.protocols.schema.transport.tcp.MPTCPUnknown(*args: _VT, **kwargs: _VT)[source]¶
Bases:
MPTCPHeader schema for unknown Multipath TCP option.
- test: MPTCPSubtypeUnknown = <BitField test>¶
Subtype and data.
- class pcapkit.protocols.schema.transport.tcp.MPTCPCapable(*args: _VT, **kwargs: _VT)[source]¶
Bases:
MPTCPHeader schema for Multipath TCP capable option.
- test: MPTCPSubtypeCapable = <BitField test>¶
Subtype and version.
- flags: MPTCPCapableFlags = <BitField flags>¶
Flags.
- rkey: int = <ConditionalField rkey>¶
Option receiver’s key.
RFC 8684 section 3.1 gives MP_CAPABLE as 12 octets without this key and 20 octets with it, so the field is present only for the latter – not, as it read until #567, for every length except 32, which is not an MP_CAPABLE length either RFC form uses.
- class pcapkit.protocols.schema.transport.tcp.MPTCPJoin(dict_=None, **kwargs)[source]¶
Bases:
MPTCPHeader schema for Multipath TCP join option.
- class pcapkit.protocols.schema.transport.tcp.MPTCPJoinSYN(*args: _VT, **kwargs: _VT)[source]¶
Bases:
MPTCPJoinHeader schema for Multipath TCP join option for
SYNconnection.- test: MPTCPSubtypeJoin = <BitField test>¶
Subtype and flags.
- class pcapkit.protocols.schema.transport.tcp.MPTCPJoinSYNACK(*args: _VT, **kwargs: _VT)[source]¶
Bases:
MPTCPJoinHeader schema for Multipath TCP join option for
SYN/ACKconnection.- test: MPTCPSubtypeJoin = <BitField test>¶
Subtype and flags.
- class pcapkit.protocols.schema.transport.tcp.MPTCPJoinACK(*args: _VT, **kwargs: _VT)[source]¶
Bases:
MPTCPJoinHeader schema for Multipath TCP join option for
ACKconnection.- test: MPTCPSubtype = <BitField test>¶
Subtype.
- class pcapkit.protocols.schema.transport.tcp.MPTCPDSS(*args: _VT, **kwargs: _VT)[source]¶
Bases:
MPTCPHeader schema for Multipath TCP DSS option.
- test: MPTCPSubtype = <BitField test>¶
Subtype and flags.
- flags: MPTCPDSSFlags = <BitField flags>¶
Flags.
- ack: int = <SwitchField ack>¶
Data ACK.
4 octets when
Ais set, 8 whenais set as well, absent otherwise – RFC 8684 section 3.3 figure 9. Both the presence test and the width live inmptcp_dss_ack_selector(), whose note records what this field declared until #576 and why the switch form is kept.
- dsn: int = <SwitchField dsn>¶
Data sequence number.
4 octets when
Mis set, 8 whenmis set as well, absent otherwise – RFC 8684 section 3.3 figure 9. C.f.mptcp_dss_dsn_selector().
- class pcapkit.protocols.schema.transport.tcp.MPTCPAddAddress(*args: _VT, **kwargs: _VT)[source]¶
Bases:
MPTCPHeader schema for Multipath TCP add address option.
- test: MPTCPSubtypeAddAddress = <BitField test>¶
Subtype and IP version.
- address: IPv4Address | IPv6Address = <SwitchField address>¶
Address.
- class pcapkit.protocols.schema.transport.tcp.MPTCPRemoveAddress(*args: _VT, **kwargs: _VT)[source]¶
Bases:
MPTCPHeader schema for Multipath TCP remove address option.
- test: MPTCPSubtype = <BitField test>¶
Subtype.
- class pcapkit.protocols.schema.transport.tcp.MPTCPPriority(*args: _VT, **kwargs: _VT)[source]¶
Bases:
MPTCPHeader schema for Multipath TCP priority option.
- test: MPTCPSubtypePriority = <BitField test>¶
Subtype.
- class pcapkit.protocols.schema.transport.tcp.MPTCPFallback(*args: _VT, **kwargs: _VT)[source]¶
Bases:
MPTCPHeader schema for Multipath TCP fallback option.
- test: MPTCPSubtype = <BitField test>¶
Subtype.
- class pcapkit.protocols.schema.transport.tcp.MPTCPFastclose(*args: _VT, **kwargs: _VT)[source]¶
Bases:
MPTCPHeader schema for Multipath TCP fastclose option.
- test: MPTCPSubtype = <BitField test>¶
Subtype.
- reserved: bytes = <PaddingField reserved>¶
Reserved.
RFC 8684 section 3.5 figure 14 spends a whole 32-bit row on
Kind/Length/Subtype/(reserved), i.e. the subtype’s 4 bits are followed by 12 reserved bits, not 4 – so the subtype-and-reserved part is 2 octets and the option is 12 octets in total. Until #576 this field did not exist andtestwas the only octet betweenlengthandkey, so the schema packed 11 octets against alengthof 12. Declared the same wayMPTCPJoinACKdeclares its own reserved octet, for the same reason: a widertestwould make the reserved bits look like part of the subtype namespace.
Type Stubs¶
- class pcapkit.protocols.schema.transport.tcp.OffsetFlag[source]¶
Bases:
TypedDictTCP offset field flag.
- class pcapkit.protocols.schema.transport.tcp.Flags[source]
Bases:
TypedDictTCP flags.
- cwr: int
Congestion window reduced.
- ece: int
ECN-Echo.
- urg: int
Urgent pointer.
- ack: int
Acknowledgment.
- psh: int
Push function.
- rst: int
Reset connection.
- syn: int
Synchronize sequence numbers.
- fin: int
Last packet from sender.
- class pcapkit.protocols.schema.transport.tcp.POCProfile[source]¶
Bases:
TypedDictTCP partial order connection service profile.
- class pcapkit.protocols.schema.transport.tcp.QuickStartFlags[source]¶
Bases:
TypedDictTCP quick start flags.
- class pcapkit.protocols.schema.transport.tcp.QuickStartNonce[source]¶
Bases:
TypedDictTCP quick start nonce.
- class pcapkit.protocols.schema.transport.tcp.TimeoutInfo[source]¶
Bases:
TypedDictUser timeout information.
- class pcapkit.protocols.schema.transport.tcp.MPTCPSubtypeTest[source]¶
Bases:
TypedDictTCP MPTCP subtype.
- class pcapkit.protocols.schema.transport.tcp.MPTCPSubtypeUnknown[source]¶
Bases:
TypedDictTCP unknown MPTCP subtype field.
- class pcapkit.protocols.schema.transport.tcp.MPTCPSubtypeCapable[source]¶
Bases:
TypedDictMPTCP Capable subtype field.
- class pcapkit.protocols.schema.transport.tcp.MPTCPCapableFlags[source]¶
Bases:
TypedDictMPTCP Capable flags.
- class pcapkit.protocols.schema.transport.tcp.MPTCPSubtypeJoin[source]¶
Bases:
TypedDictMPTCP Join subtype field.
- class pcapkit.protocols.schema.transport.tcp.MPTCPSubtype[source]¶
Bases:
TypedDictMPTCP subtype field.
- class pcapkit.protocols.schema.transport.tcp.MPTCPDSSFlags[source]¶
Bases:
TypedDictMPTCP-DSS flags.
Auxiliary Functions¶
- pcapkit.protocols.schema.transport.tcp.mptcp_data_selector(pkt)[source]¶
Selector function for
_MPTCP.datafield.
- pcapkit.protocols.schema.transport.tcp.mptcp_add_address_selector(pkt)[source]¶
Selector function for
MPTCPAddAddress.addressfield.- Parameters:
- Return type:
- Returns:
If IP version is 4, a
IPv4AddressFieldinstance.If IP version is 6, a
IPv6AddressFieldinstance.
- pcapkit.protocols.schema.transport.tcp.mptcp_dss_ack_selector(pkt)[source]¶
Selector function for
MPTCPDSS.ackfield.RFC 8684 section 3.3 figure 9 gives the Data ACK as “4 or 8 octets, depending on flags”: present only when
Ais set, and 8 octets wide only whenais also set – “a = Data ACK is 8 octets (if not set, Data ACK is 4 octets)”.- Parameters:
- Return type:
- Returns:
If
Ais clear, aNoValueFieldinstance – the field is absent from the wire.If
Ais set andais set, aUInt64Fieldinstance.If
Ais set andais clear, aUInt32Fieldinstance.
Note
This is a
SwitchFieldselector rather than aConditionalFieldwrappingNumberField(length=lambda pkt: ...), which is what it was until #576.The width lambda read
8 if pkt['flags']['a'] else 0– 0, not 4 – so an unextended Data ACK packed no octets at all while thelengthoctet still counted 4 for it. That is the defect #576 records: the option went onto the wire 4 (or 8, withdsntoo) octets shorter than it declared, and theackvalue the caller supplied was simply not present.Correcting the lambda to
8 if ... else 4would not have worked at the time, becauseNumberFieldcould not pack a callable length at all: it calledbuild_templateonce at__init__with the placeholder length-1, which latched_need_process = True, and nothing cleared that flag when__call__later resolved the real length and rebuilt the template as>I/>Q.pre_processthen handedstruct.pack()bytes for an integer template and it raisedstruct.error: required argument is not an integer. Measured on the 8-octet form, which the old lambda did reach:_make_mptcp_dss(DSS, ack=1 << 40)raised exactly that.That half is now history: #598 fixed it, in
pcapkit.corekit.fields.numberswhere this note used to say the fix belonged, by recomputing_need_processfrom the width actually in force instead of once from the placeholder. A callable-lengthNumberFieldpacks and unpacks both the 4- and the 8-octet form today, soConditionalField(NumberField(length=...), lambda pkt: pkt['flags']['A'])would express this field correctly. Nor was wire absence ever the obstacle:MPTCPDSS.ssn,MPTCPDSS.dl_lenandMPTCPDSS.checksumare each aConditionalFieldon the siblingMflag, so this very class already leans on that wrapper to keep a field off the wire.The
SwitchFieldform is kept anyway, for a narrower reason about composition rather than about absence. AConditionalField’slengthforwards to the wrapped field unconditionally, never consulting the condition, so reading it while the condition is false – the wrapped field then still unresolved, at its-1placeholder – raisesstruct.error: bad char in struct format. Nothing here meets that only becauseSchema’spackandunpackspecial-caseConditionalFieldby name and skip the wrapped field outright before anylengthis read. ASwitchFieldneeds no such special case: its selector always hands back an already-concrete field,NoValueFieldincluded, so itslengthis safe wherever it is read. Swapping the two would be a behaviour change, not a tidy-up, and #603 does not make it.
- pcapkit.protocols.schema.transport.tcp.mptcp_dss_dsn_selector(pkt)[source]¶
Selector function for
MPTCPDSS.dsnfield.RFC 8684 section 3.3 figure 9 gives the Data Sequence Number as “4 or 8 octets, depending on flags”: present only when
Mis set, and 8 octets wide only whenmis also set – “m = Data Sequence Number is 8 octets (if not set, DSN is 4 octets)”.- Parameters:
- Return type:
- Returns:
If
Mis clear, aNoValueFieldinstance – the field is absent from the wire.If
Mis set andmis set, aUInt64Fieldinstance.If
Mis set andmis clear, aUInt32Fieldinstance.
Note
Identical in shape to
mptcp_dss_ack_selector(), and it replaces the identical defect:NumberField(length=lambda pkt: 8 if pkt['flags']['m'] else 0, ...). See that function’s note for why the0was wrong, why a corrected lambda would not have packed either at the time, and why theSwitchFieldform is kept now that #598 has made a callable length work. C.f. #576, #598.
Data Models¶
- class pcapkit.protocols.data.transport.tcp.TCP(*args: VT, **kwargs: VT)[source]¶
Bases:
ProtocolData model for TCP packet.
- options: OrderedMultiDict[Option, Option]¶
TCP options.
- class pcapkit.protocols.data.transport.tcp.Flags(*args: VT, **kwargs: VT)[source]¶
Bases:
DataData model for TCP flags.
- class pcapkit.protocols.data.transport.tcp.Option(dict_=None, **kwargs)[source]¶
Bases:
DataData model for TCP options.
- class pcapkit.protocols.data.transport.tcp.UnassignedOption(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for unassigned TCP option.
- class pcapkit.protocols.data.transport.tcp.EndOfOptionList(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP end of option list option.
- class pcapkit.protocols.data.transport.tcp.NoOperation(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP no operation option.
- class pcapkit.protocols.data.transport.tcp.MaximumSegmentSize(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP maximum segment size option.
- class pcapkit.protocols.data.transport.tcp.WindowScale(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP window scale option.
- class pcapkit.protocols.data.transport.tcp.SACKPermitted(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP SACK permitted option.
- class pcapkit.protocols.data.transport.tcp.SACK(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP SACK option.
- class pcapkit.protocols.data.transport.tcp.Echo(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP echo option.
- class pcapkit.protocols.data.transport.tcp.EchoReply(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP echo reply option.
- class pcapkit.protocols.data.transport.tcp.Timestamps(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP timestamp option.
- class pcapkit.protocols.data.transport.tcp.PartialOrderConnectionPermitted(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP partial order connection permitted option.
- class pcapkit.protocols.data.transport.tcp.PartialOrderServiceProfile(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP partial order connection profile option.
- class pcapkit.protocols.data.transport.tcp.CC(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP CC option.
- class pcapkit.protocols.data.transport.tcp.CCNew(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP CC.NEW option.
- class pcapkit.protocols.data.transport.tcp.CCEcho(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP CC.ECHO option.
- class pcapkit.protocols.data.transport.tcp.AlternateChecksumRequest(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP alternate checksum request option.
- class pcapkit.protocols.data.transport.tcp.AlternateChecksumData(kind, length, data)[source]¶
Bases:
OptionData model for TCP alternate checksum data option.
- class pcapkit.protocols.data.transport.tcp.MD5Signature(kind, length, digest)[source]¶
Bases:
OptionData model for TCP MD5 signature option.
- class pcapkit.protocols.data.transport.tcp.QuickStartResponse(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP quick start response option.
- class pcapkit.protocols.data.transport.tcp.UserTimeout(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP user timeout option.
- class pcapkit.protocols.data.transport.tcp.Authentication(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP authentication option.
- class pcapkit.protocols.data.transport.tcp.FastOpenCookie(*args: VT, **kwargs: VT)[source]¶
Bases:
OptionData model for TCP fast open cookie option.
- class pcapkit.protocols.data.transport.tcp.MPTCP(dict_=None, **kwargs)[source]¶
Bases:
OptionData model for TCP MPTCP option.
- subtype: MPTCPOption¶
Subtype.
- class pcapkit.protocols.data.transport.tcp.MPTCPUnknown(*args: VT, **kwargs: VT)[source]¶
Bases:
MPTCPData model for TCP unknown MPTCP option.
- class pcapkit.protocols.data.transport.tcp.MPTCPCapable(*args: VT, **kwargs: VT)[source]¶
Bases:
MPTCPData model for TCP
MP_CAPABLEoption.- flags: MPTCPCapableFlag¶
Flags.
- class pcapkit.protocols.data.transport.tcp.MPTCPJoin(dict_=None, **kwargs)[source]¶
Bases:
MPTCPData model for TCP
MP_JOINoption.
- class pcapkit.protocols.data.transport.tcp.MPTCPJoinSYN(*args: VT, **kwargs: VT)[source]¶
Bases:
MPTCPJoinData model for TCP
MP_JOIN-SYNoption.
- class pcapkit.protocols.data.transport.tcp.MPTCPJoinSYNACK(*args: VT, **kwargs: VT)[source]¶
Bases:
MPTCPJoinData model for TCP
MP_JOIN-SYNACKoption.
- class pcapkit.protocols.data.transport.tcp.MPTCPJoinACK(*args: VT, **kwargs: VT)[source]¶
Bases:
MPTCPJoinData model for TCP
MP_JOIN-ACKoption.
- class pcapkit.protocols.data.transport.tcp.MPTCPDSS(*args: VT, **kwargs: VT)[source]¶
Bases:
MPTCPData model for TCP
DSSoption.
- class pcapkit.protocols.data.transport.tcp.MPTCPAddAddress(*args: VT, **kwargs: VT)[source]¶
Bases:
MPTCPData model for TCP
ADD_ADDRoption.- addr: IPv4Address | IPv6Address¶
Address.
- class pcapkit.protocols.data.transport.tcp.MPTCPRemoveAddress(*args: VT, **kwargs: VT)[source]¶
Bases:
MPTCPData model for TCP
REMOVE_ADDRoption.
- class pcapkit.protocols.data.transport.tcp.MPTCPPriority(*args: VT, **kwargs: VT)[source]¶
Bases:
MPTCPData model for TCP
MP_PRIOoption.
- class pcapkit.protocols.data.transport.tcp.MPTCPFallback(*args: VT, **kwargs: VT)[source]¶
Bases:
MPTCPData model for TCP
MP_FAILoption.
- class pcapkit.protocols.data.transport.tcp.MPTCPFastclose(*args: VT, **kwargs: VT)[source]¶
Bases:
MPTCPData model for TCP
MP_FASTCLOSEoption.
Footnotes