Skip to main content

Real TCP window rewriting

Real TCP window (wssize) writes a small TCP window into the first packets of a connection and can lower or remove the Window Scale option of its SYN. b4 follows each connection it rewrites from the SYN to the point where the rewrite stops. Which set a connection gets at its SYN is described in How sets match traffic.

At the Trace log level, the Logs page shows WSSize: opened for ... when b4 starts to follow a connection, with the window and the Window Scale before and after, and WSSize: ended for ... with the reason when a packet or the 5-second limit stops the rewrite. No ended line follows when the connection goes idle or the configuration is saved.

What is rewritten​

Packet of the connectionWhat changes
The SYN and its retransmissionsThe window field, when Window is not 0. The Window Scale option: lowered with Lower to a value when it holds a larger value, removed with Remove the option
Packets without data before the stopThe window field
Packets with data up to the stop, the last one includedThe window field
Packets after the stopNothing
Packets with the RST flagNothing

A SYN without a Window Scale option stays without one. A packet in which nothing has to change is left as it is. b4 changes the packet before the set's other techniques split it or build fake packets from it. Packets from the server are not looked at.

Where the rewrite stops​

With After the ClientHello, b4 follows the bytes the device sends, counted from the SYN, however they are split into TCP segments and TLS records. Segments that arrive out of order or twice are handled. The packet that completes the ClientHello is rewritten too, even when it carries data after the ClientHello. A part of the ClientHello sent again is still rewritten until 5 seconds have passed since the connection's first data byte.

With After the first data packet, the rewrite stops after the first packet with data that is not a SYN.

Data that is not a TLS ClientHello, such as an HTTP request, stops the rewrite with its first packet in both modes. Data inside a Fast Open SYN is followed as the start of the ClientHello and starts the 5 seconds, but it is not the first data packet.

Limit with After the ClientHelloValueWhen it is reached
Time from the first data byte5 secondsA later packet passes unchanged, and the rewrite is over
Size of the ClientHello64 KBThe packet is still rewritten, then the rewrite stops
Packets with data128The same
Buffers of all followed connections together4 MBThe same, and b4 logs a warning

How long a connection is followed​

Connectionb4 stops following it
Only SYNs so far35 seconds after the last SYN
Handshake done, no data yetAfter 2 minutes without a packet. Until then every packet b4 sees is rewritten
The rewrite stoppedAt once. After a complete ClientHello, 5 seconds after the connection's first data byte
The device sends a FINAt once
The configuration is savedAt once, for every connection

b4 follows at most 20,000 connections at a time. A new connection beyond that passes unchanged, and b4 logs a warning at most once in 10 seconds. Neither a reset nor a packet from the server makes b4 stop following a connection.

Where it does not apply​

  • With TUN interface as the packet engine. The set keeps the option, and b4 logs a warning. A Discovery run then tests the set without the rewrite as well.
  • To packets that leave through a tunnel or by another service's route, see Packets that leave by another route.
  • To packets of a connection that a routing set hands to a proxy or to another interface.
  • To ports b4 does not capture and to interfaces outside Capture Interfaces.
  • To IPv4 fragments and to IPv6 packets with extension headers.
  • To a connection whose SYN b4 did not see, or for whose SYN no set matched.

b4 sees only the first packets of a connection, 19 by default (TCP Connection Packets Limit). The SYN and the packets up to the stop have to be among them, and a device that retransmits many times before it sends data can use them up.

A lowered Window Scale lasts​

TCP fixes the Window Scale in the SYN. The device keeps writing its windows for its own scale, the server reads them with the lowered one, and b4 does not rescale later packets. With a scale of 7 lowered to 1, the server sees every later window as 1/64 of what the device meant, until the connection closes. Window alone has no such effect: packets after the stop carry the device's own window.

Without the Window Scale option​

With Remove the option, b4 overwrites the option in the SYN with padding of the same length, in every copy of the SYN. A server that receives a SYN without the option offers no window scaling in its answer, and the device then turns scaling off as well. Both ends read every window as a plain number of bytes for the whole connection.

Lowered Window ScaleOption removed
The server reads Window asWindow times 2 to the power of the lowered scaleWindow bytes
The device's windows after the stopRead with the lowered scale, too smallRead as sent
Packets rewritten after the stopNoneNone

A connection without window scaling carries at most 65,535 bytes per round trip in each direction, uploads included, until it closes. A connection whose SYN b4 did not rewrite keeps its window scaling.