aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-09-29 16:46:58 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-09-29 16:46:58 +0200
commit2408ddffa32a34ff1555946629ae81b9f33fe59e (patch)
tree3930101f4cc790753d0d30d77a62accfefa06fb2
parent4e5129719d77ad6950989fc8b5c2a36ae4c2ec2f (diff)
downloadpasst-2408ddffa32a34ff1555946629ae81b9f33fe59e.tar
passt-2408ddffa32a34ff1555946629ae81b9f33fe59e.tar.gz
passt-2408ddffa32a34ff1555946629ae81b9f33fe59e.tar.bz2
passt-2408ddffa32a34ff1555946629ae81b9f33fe59e.tar.lz
passt-2408ddffa32a34ff1555946629ae81b9f33fe59e.tar.xz
passt-2408ddffa32a34ff1555946629ae81b9f33fe59e.tar.zst
passt-2408ddffa32a34ff1555946629ae81b9f33fe59e.zip
tcp: Derive MSS announced to guest/namespace from configured MTU if present
...and from the sending socket only if the MTU is not configured. Otherwise, a connection to a host from a local guest, with a non-loopback destination address, will get its MSS from the MTU of the outbound interface with that address, which is unnecessary as we know the guest can send us larger segments. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--tcp.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/tcp.c b/tcp.c
index 7de8fa9..d5e47c9 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1187,10 +1187,23 @@ static int tcp_send_to_tap(struct ctx *c, struct tcp_tap_conn *conn, int flags,
th->doff = sizeof(*th) / 4;
if (flags & SYN) {
+ uint16_t mss;
+
/* Options: MSS, NOP and window scale if allowed (4-8 bytes) */
*data++ = OPT_MSS;
*data++ = OPT_MSS_LEN;
- *(uint16_t *)data = htons(info.tcpi_snd_mss);
+
+ if (c->mtu == -1) {
+ mss = info.tcpi_snd_mss;
+ } else {
+ mss = c->mtu - sizeof(sizeof *th);
+ if (IN6_IS_ADDR_V4MAPPED(&conn->a.a6))
+ mss -= sizeof(struct iphdr);
+ else
+ mss -= sizeof(struct ipv6hdr);
+ }
+ *(uint16_t *)data = htons(mss);
+
data += OPT_MSS_LEN - 2;
th->doff += OPT_MSS_LEN / 4;