Commit a862771d authored by zhenwei pi's avatar zhenwei pi Committed by Jakub Kicinski
Browse files

selftests: mptcp: use IPPROTO_MPTCP for getaddrinfo



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: default avatarGeliang Tang <geliang@kernel.org>
Signed-off-by: default avatarGeliang Tang <geliang@kernel.org>
Signed-off-by: default avatarzhenwei pi <pizhenwei@bytedance.com>
Reviewed-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarMatthieu 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: default avatarJakub Kicinski <kuba@kernel.org>
parent f9c7504d
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -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;