]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: mptcp: use IPPROTO_MPTCP for getaddrinfo
authorzhenwei pi <pizhenwei@bytedance.com>
Sun, 13 Apr 2025 09:34:39 +0000 (11:34 +0200)
committerJakub Kicinski <kuba@kernel.org>
Tue, 15 Apr 2025 15:21:47 +0000 (08:21 -0700)
mptcp_connect.c is a startup tutorial of MPTCP programming, however
there is a lack of ai_protocol(IPPROTO_MPTCP) usage. Add comment for
getaddrinfo MPTCP support.

This patch first uses IPPROTO_MPTCP to get addrinfo, and if glibc
version is too old, it falls back to using IPPROTO_TCP.

Co-developed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20250413-net-next-mptcp-sched-mib-sft-misc-v2-8-0f83a4350150@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/mptcp/mptcp_connect.c

index c83a8b47bbdfa5fcf1462e2b2949b41fd32c9b14..ac1349c4b9e5404c95935eb38b08a15d774eb1d9 100644 (file)
@@ -180,13 +180,26 @@ static void xgetnameinfo(const struct sockaddr *addr, socklen_t addrlen,
 }
 
 static void xgetaddrinfo(const char *node, const char *service,
-                        const struct addrinfo *hints,
+                        struct addrinfo *hints,
                         struct addrinfo **res)
 {
+again:
        int err = getaddrinfo(node, service, hints, res);
 
        if (err) {
-               const char *errstr = getxinfo_strerr(err);
+               const char *errstr;
+
+               /* glibc starts to support MPTCP since v2.42.
+                * For older versions, use IPPROTO_TCP to resolve,
+                * and use TCP/MPTCP to create socket.
+                * Link: https://sourceware.org/git/?p=glibc.git;a=commit;h=a8e9022e0f82
+                */
+               if (err == EAI_SOCKTYPE) {
+                       hints->ai_protocol = IPPROTO_TCP;
+                       goto again;
+               }
+
+               errstr = getxinfo_strerr(err);
 
                fprintf(stderr, "Fatal: getaddrinfo(%s:%s): %s\n",
                        node ? node : "", service ? service : "", errstr);
@@ -292,7 +305,7 @@ static int sock_listen_mptcp(const char * const listenaddr,
 {
        int sock = -1;
        struct addrinfo hints = {
-               .ai_protocol = IPPROTO_TCP,
+               .ai_protocol = IPPROTO_MPTCP,
                .ai_socktype = SOCK_STREAM,
                .ai_flags = AI_PASSIVE | AI_NUMERICHOST
        };
@@ -356,7 +369,7 @@ static int sock_connect_mptcp(const char * const remoteaddr,
                              int infd, struct wstate *winfo)
 {
        struct addrinfo hints = {
-               .ai_protocol = IPPROTO_TCP,
+               .ai_protocol = IPPROTO_MPTCP,
                .ai_socktype = SOCK_STREAM,
        };
        struct addrinfo *a, *addr;