Currently, the TCP_MAXSEG socket option doesn't seem to be supported
with MPTCP. This results in a warning when trying to set the MSS of
sockets in proto_tcp:tcp_bind_listener.

This can be resolved by adding two new variables:
sock_inet(6)_mptcp_maxseg_default that will hold the default
value of the TCP_MAXSEG option. Note that for the moment, this
will always be -1 as the option isn't supported. However, in the
future, when the support for this option will be added, it should
contain the correct value for the MSS, allowing to correctly
set the TCP_MAXSEG option.
---
 include/haproxy/sock_inet.h |  3 +++
 src/proto_tcp.c             | 17 +++++++++++++----
 src/sock_inet.c             | 28 ++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/include/haproxy/sock_inet.h b/include/haproxy/sock_inet.h
index 6f07e637a..7499ffb76 100644
--- a/include/haproxy/sock_inet.h
+++ b/include/haproxy/sock_inet.h
@@ -31,6 +31,9 @@ extern int sock_inet6_v6only_default;
 extern int sock_inet_tcp_maxseg_default;
 extern int sock_inet6_tcp_maxseg_default;
 
+extern int sock_inet_mptcp_maxseg_default;
+extern int sock_inet6_mptcp_maxseg_default;
+
 extern struct proto_fam proto_fam_inet4;
 extern struct proto_fam proto_fam_inet6;
 
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index 9cabae11b..6b2bb6665 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -690,12 +690,21 @@ int tcp_bind_listener(struct listener *listener, char 
*errmsg, int errlen)
                /* we may want to try to restore the default MSS if the socket 
was inherited */
                int tmpmaxseg = -1;
                int defaultmss;
+               int v4 = listener->rx.addr.ss_family == AF_INET;
+               int mptcp = listener->rx.proto->sock_prot == IPPROTO_MPTCP;
                socklen_t len = sizeof(tmpmaxseg);
 
-               if (listener->rx.addr.ss_family == AF_INET)
-                       defaultmss = sock_inet_tcp_maxseg_default;
-               else
-                       defaultmss = sock_inet6_tcp_maxseg_default;
+               if (mptcp) {
+                       if (v4)
+                               defaultmss = sock_inet_mptcp_maxseg_default;
+                       else
+                               defaultmss = sock_inet6_mptcp_maxseg_default;
+               } else {
+                       if (v4)
+                               defaultmss = sock_inet_tcp_maxseg_default;
+                       else
+                               defaultmss = sock_inet6_tcp_maxseg_default;
+               }
 
                getsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, &tmpmaxseg, &len);
                if (defaultmss > 0 &&
diff --git a/src/sock_inet.c b/src/sock_inet.c
index 028ffaa68..9f10c5654 100644
--- a/src/sock_inet.c
+++ b/src/sock_inet.c
@@ -77,6 +77,10 @@ int sock_inet6_v6only_default = 0;
 int sock_inet_tcp_maxseg_default = -1;
 int sock_inet6_tcp_maxseg_default = -1;
 
+/* Default MPTCPv4/MPTCPv6 MSS settings. -1=unknown. */
+int sock_inet_mptcp_maxseg_default = -1;
+int sock_inet6_mptcp_maxseg_default = -1;
+
 /* Compares two AF_INET sockaddr addresses. Returns 0 if they match or non-zero
  * if they do not match.
  */
@@ -494,6 +498,30 @@ static void sock_inet_prepare()
 #endif
                close(fd);
        }
+
+#ifdef __linux__
+       fd = socket(AF_INET, SOCK_STREAM, IPPROTO_MPTCP);
+       if (fd >= 0) {
+#ifdef TCP_MAXSEG
+               /* retrieve the OS' default mss for MPTCPv4 */
+               len = sizeof(val);
+               if (getsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, &val, &len) == 0)
+                       sock_inet_mptcp_maxseg_default = val;
+#endif
+               close(fd);
+       }
+
+       fd = socket(AF_INET6, SOCK_STREAM, IPPROTO_MPTCP);
+       if (fd >= 0) {
+#ifdef TCP_MAXSEG
+               /* retrieve the OS' default mss for MPTCPv6 */
+               len = sizeof(val);
+               if (getsockopt(fd, IPPROTO_TCP, TCP_MAXSEG, &val, &len) == 0)
+                       sock_inet6_mptcp_maxseg_default = val;
+#endif
+               close(fd);
+       }
+#endif
 }
 
 INITCALL0(STG_PREPARE, sock_inet_prepare);
-- 
2.46.0



Reply via email to