Skip to content

Commit 68fd9a1

Browse files
authored
mptcpize: set GODEBUG=multipathtcp=1 env var (#316)
GO apps don't use the libC, so the LD_PRELOAD technique doesn't work with these apps. But since GO 1.21, MPTCP is natively supported, and can be forced by simply setting GODEBUG=multipathtcp=1. So mptcpize can easily support GO apps by also setting this env var. Similar to the LD_PRELOAD env var, the GODEBUG one is appended with a comma if it was already set. Link: https://go.dev/doc/godebug Link: https://pkg.go.dev/net#Dialer.SetMultipathTCP Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
1 parent d16f0c9 commit 68fd9a1

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/mptcpize.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#define SYSTEMCTL_SHOW "systemctl show -p FragmentPath "
3636
#define PRELOAD_VAR "LD_PRELOAD="
3737
#define MPTCPWRAP_ENV PKGLIBDIR"/libmptcpwrap.so.0.0."LIBREVISION
38+
#define GODEBUG_VAR "GODEBUG="
39+
#define MPTCPGO_ENV "multipathtcp=1"
3840

3941
/* Program documentation. */
4042
static char args_doc[] = "CMD";
@@ -62,7 +64,7 @@ static void help(void)
6264

6365
static int run(int argc, char *av[])
6466
{
65-
int i, nr = 0, ld, debug = 0;
67+
int i, nr = 0, ld, go, debug = 0;
6668
char **envp, **argv, *env;
6769
size_t len;
6870

@@ -81,18 +83,22 @@ static int run(int argc, char *av[])
8183
// build environment, copying the current one ...
8284
while (environ[nr])
8385
nr++;
84-
envp = calloc(nr + 3, sizeof(char *));
86+
envp = calloc(nr + 4, sizeof(char *));
8587
if (!envp)
8688
error(1, errno, "can't allocate env list");
8789

88-
// ... filtering out any 'LD_PRELOAD' ...
90+
// ... filtering out any 'LD_PRELOAD' and 'GODEBUG' ...
8991
nr = 0;
9092
i = 0;
9193
ld = -1;
94+
go = -1;
9295
while (environ[nr]) {
9396
if (strncmp(environ[nr], PRELOAD_VAR,
9497
strlen(PRELOAD_VAR)) == 0) {
9598
ld = nr;
99+
} else if (strncmp(environ[nr], GODEBUG_VAR,
100+
strlen(GODEBUG_VAR)) == 0) {
101+
go = nr;
96102
} else {
97103
envp[i] = environ[nr];
98104
i++;
@@ -110,6 +116,16 @@ static int run(int argc, char *av[])
110116
}
111117
envp[i++] = env;
112118

119+
// .. and GODEBUG=multipathtcp=1 ...
120+
if (go >= 0) {
121+
len = strlen(environ[go]) + strlen(MPTCPGO_ENV) + 2;
122+
env = alloca(len);
123+
snprintf(env, len, "%s,%s", environ[go], MPTCPGO_ENV);
124+
} else {
125+
env = GODEBUG_VAR MPTCPGO_ENV;
126+
}
127+
envp[i++] = env;
128+
113129
// ... and enable dbg if needed
114130
if (debug)
115131
envp[i++] = "MPTCPWRAP_DEBUG=1";

0 commit comments

Comments
 (0)