tcp: Fix window size in initial SYN, ACK segment to guest

During handshake, the initial SYN, ACK segment to the guest, send as
a response to the SYN segment, needs to report the unscaled value for
the window, given that the handshake hasn't completed yet.

While at it, fix the endianness for the window value in case TCP
parameters can't be queried via TCP_INFO and we need to use the
default value.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2021-06-05 14:54:12 +02:00
parent 46b799c077
commit 8b39b0b47f

11
tcp.c
View file

@ -798,10 +798,13 @@ static int tcp_send_to_tap(struct ctx *c, int s, int flags, char *in, int len)
th->source = tc[s].sock_port; th->source = tc[s].sock_port;
th->dest = tc[s].tap_port; th->dest = tc[s].tap_port;
if (!err) if (!err) {
th->window = htons(info.tcpi_snd_wnd >> info.tcpi_snd_wscale); /* First value sent by receiver is not scaled */
else th->window = htons(info.tcpi_snd_wnd >>
th->window = WINDOW_DEFAULT; ((flags & SYN) ? 0 : info.tcpi_snd_wscale));
} else {
th->window = htons(WINDOW_DEFAULT);
}
th->urg_ptr = 0; th->urg_ptr = 0;
th->check = 0; th->check = 0;