mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-09-03 01:28:04 +00:00
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: 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>
This commit is contained in:
parent
f9c7504d30
commit
a862771d1a
@ -180,13 +180,26 @@ static void xgetnameinfo(const struct sockaddr *addr, socklen_t addrlen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void xgetaddrinfo(const char *node, const char *service,
|
static void xgetaddrinfo(const char *node, const char *service,
|
||||||
const struct addrinfo *hints,
|
struct addrinfo *hints,
|
||||||
struct addrinfo **res)
|
struct addrinfo **res)
|
||||||
{
|
{
|
||||||
|
again:
|
||||||
int err = getaddrinfo(node, service, hints, res);
|
int err = getaddrinfo(node, service, hints, res);
|
||||||
|
|
||||||
if (err) {
|
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",
|
fprintf(stderr, "Fatal: getaddrinfo(%s:%s): %s\n",
|
||||||
node ? node : "", service ? service : "", errstr);
|
node ? node : "", service ? service : "", errstr);
|
||||||
@ -292,7 +305,7 @@ static int sock_listen_mptcp(const char * const listenaddr,
|
|||||||
{
|
{
|
||||||
int sock = -1;
|
int sock = -1;
|
||||||
struct addrinfo hints = {
|
struct addrinfo hints = {
|
||||||
.ai_protocol = IPPROTO_TCP,
|
.ai_protocol = IPPROTO_MPTCP,
|
||||||
.ai_socktype = SOCK_STREAM,
|
.ai_socktype = SOCK_STREAM,
|
||||||
.ai_flags = AI_PASSIVE | AI_NUMERICHOST
|
.ai_flags = AI_PASSIVE | AI_NUMERICHOST
|
||||||
};
|
};
|
||||||
@ -356,7 +369,7 @@ static int sock_connect_mptcp(const char * const remoteaddr,
|
|||||||
int infd, struct wstate *winfo)
|
int infd, struct wstate *winfo)
|
||||||
{
|
{
|
||||||
struct addrinfo hints = {
|
struct addrinfo hints = {
|
||||||
.ai_protocol = IPPROTO_TCP,
|
.ai_protocol = IPPROTO_MPTCP,
|
||||||
.ai_socktype = SOCK_STREAM,
|
.ai_socktype = SOCK_STREAM,
|
||||||
};
|
};
|
||||||
struct addrinfo *a, *addr;
|
struct addrinfo *a, *addr;
|
||||||
|
Loading…
Reference in New Issue
Block a user