1818 DatagramID , Fragment , HoleDescriptor , Packet )
1919from pcapkit .foundation .reassembly .reassembly import ReassemblyBase
2020from pcapkit .protocols .transport .tcp import TCP as TCP_Protocol
21+ from pcapkit .utilities import config
2122
2223if TYPE_CHECKING :
2324 from typing import Type
@@ -99,6 +100,11 @@ class TCP(ReassemblyBase[Packet, Datagram, BufferID, Buffer]):
99100 <pcapkit.foundation.reassembly.data.tcp.Datagram.conflict>`; 1.4.x
100101 kept the later octets without a record (:issue:`443`).
101102
103+ .. versionremoved:: 1.6.0
104+
105+ ``__window__``, now :data:`~pcapkit.utilities.config.TCP_GAP_LIMIT`
106+ (:issue:`2546`).
107+
102108 """
103109 if TYPE_CHECKING :
104110 protocol : 'Type[TCP_Protocol]'
@@ -129,41 +135,33 @@ class TCP(ReassemblyBase[Packet, Datagram, BufferID, Buffer]):
129135 #: ask for one, e.g. ``2 * 120`` for 2·MSL if that is the policy wanted.
130136 __timeout__ = math .inf
131137
132- #: int: Widest gap, in octets, that merging a segment into the payload
133- #: buffer it is read against may zero-fill: 16 MiB. The gap is measured on
134- #: whichever side the segment lands, from the buffer's end to the
135- #: segment's start, or from the segment's end to the buffer's start.
136- #:
137- #: A segment can only legitimately open a gap as wide as the data in flight,
138- #: which the receive window bounds. :rfc:`7323` allows windows up to
139- #: ``2 ** 30``, but zero-filling a gap that wide costs 1 GiB, and real
140- #: windows are far smaller -- Linux's default ``net.ipv4.tcp_rmem`` ceiling
141- #: is 6 MiB -- so 16 MiB clears them with room to spare. A segment that
142- #: would open a wider gap is not padded to; the buffer held so far is
143- #: submitted and a fresh one opened for the segment instead. What that
144- #: means depends on whether the buffer's SYN was captured:
145- #:
146- #: * **No SYN** -- the segment is taken to start a new stream on a reused
147- #: 4-tuple, and the two buffers are reported independently.
148- #: * **SYN captured** -- the SYN proves both are the same stream with the
149- #: range in between lost, so that range is recorded in the
150- #: :attr:`~pcapkit.foundation.reassembly.data.tcp.Fragment.gap` of the
151- #: payload buffer the segment was read against and of the new one, and
152- #: both are reported
153- #: :attr:`~pcapkit.foundation.reassembly.data.data.Completion.PARTIAL`
154- #: (in strict mode, as a single run each). The new buffer keeps the
155- #: SYN's header and counts as having seen it.
156- #:
157- #: Override in a subclass to change the bound.
158- __window__ = 1 << 24
159-
160138 ##########################################################################
161139 # Methods.
162140 ##########################################################################
163141
164142 def reassembly (self , info : 'Packet' ) -> 'None' :
165143 """Reassembly procedure.
166144
145+ A segment is merged into the payload buffer it is read against by
146+ zero-filling the gap between them, measured on whichever side the
147+ segment lands: from the buffer's end to the segment's start, or from
148+ the segment's end to the buffer's start. A gap wider than
149+ :data:`~pcapkit.utilities.config.TCP_GAP_LIMIT` is not padded to; the
150+ buffer held so far is submitted and a fresh one opened for the segment
151+ instead. What that means depends on whether the buffer's SYN was
152+ captured:
153+
154+ * **No SYN** -- the segment is taken to start a new stream on a reused
155+ 4-tuple, and the two buffers are reported independently.
156+ * **SYN captured** -- the SYN proves both are the same stream with the
157+ range in between lost, so that range is recorded in the
158+ :attr:`~pcapkit.foundation.reassembly.data.tcp.Fragment.gap` of the
159+ payload buffer the segment was read against and of the new one, and
160+ both are reported
161+ :attr:`~pcapkit.foundation.reassembly.data.data.Completion.PARTIAL`
162+ (in strict mode, as a single run each). The new buffer keeps the
163+ SYN's header and counts as having seen it.
164+
167165 Arguments:
168166 info: :term:`info <reasm.tcp.packet>` dict of packets to be reassembled
169167
@@ -203,8 +201,8 @@ def reassembly(self, info: 'Packet') -> 'None':
203201 # it most plausibly continues -- this ACK's own payload buffer, or else
204202 # the most recently opened one -- per :rfc:`9293#section-3.4`. Plain
205203 # integer comparison reads a stream crossing 2**32 as a gap of about
206- # 4 GiB. A segment landing farther than ``__window__`` outside that
207- # buffer starts a new stream instead -- see ``__window__`` .
204+ # 4 GiB. A segment landing farther than ``config.TCP_GAP_LIMIT``
205+ # outside that buffer splits the stream instead -- see the docstring .
208206 SHIFT = 0
209207 HDR = info .header if SYN else b'' # header of the buffer opened below, if any
210208 ANCHORED = SYN # whether that buffer's stream start is known
@@ -217,7 +215,8 @@ def reassembly(self, info: 'Packet') -> 'None':
217215 END = fragment .isn + fragment .len
218216 UNWRAPPED = self ._unwrap (PSN , END )
219217 # the zero-filled gap merging this segment would open, either side
220- if max (UNWRAPPED - END , fragment .isn - (UNWRAPPED + info .len )) > self .__window__ :
218+ limit = config .TCP_GAP_LIMIT
219+ if limit != - 1 and max (UNWRAPPED - END , fragment .isn - (UNWRAPPED + info .len )) > limit :
221220 old = self ._buffer .pop (BUFID )
222221 if self ._anchored (old ):
223222 # The SYN proves this is still the same stream, with the
@@ -552,7 +551,7 @@ def _trim_gaps(gap: 'list[tuple[int, int]]', first: 'int', last: 'int') -> 'None
552551 """Remove a received range from a fragment's gap list, in place.
553552
554553 Only an entry lying outside :attr:`~pcapkit.foundation.reassembly.data.tcp.Fragment.raw`
555- -- the range a split stream left out, see :attr :`TCP.__window__ ` -- can
554+ -- the range a split stream left out, see :meth :`TCP.reassembly ` -- can
556555 still overlap a segment once it is merged; :meth:`_merge_overlap` has
557556 already closed every entry inside ``raw`` that the segment covers.
558557
@@ -806,7 +805,7 @@ def submit(self, buf: 'Buffer', *, bufid: 'BufferID', # type: ignore[override]
806805 # How completely this buffer came out, and why it stopped. Derived
807806 # once per buffer, so the two branches cannot disagree about it.
808807 # Any gap entry counts, including one lying wholly outside ``raw``:
809- # that is the range a split stream left out (see ``__window__ ``).
808+ # that is the range a split stream left out (see ``reassembly ``).
810809 completion = Completion .COMPLETE if not buffer .gap else (
811810 Completion .TIMEOUT if timeout else Completion .PARTIAL
812811 )
0 commit comments