Skip to content

Commit

Permalink
mptcpize: set GODEBUG=multipathtcp=1 env var
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
matttbe committed Jan 27, 2025
1 parent d16f0c9 commit b0c286d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/mptcpize.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#define SYSTEMCTL_SHOW "systemctl show -p FragmentPath "
#define PRELOAD_VAR "LD_PRELOAD="
#define MPTCPWRAP_ENV PKGLIBDIR"/libmptcpwrap.so.0.0."LIBREVISION
#define GODEBUG_VAR "GODEBUG="
#define MPTCPGO_ENV "multipathtcp=1"

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

static int run(int argc, char *av[])
{
int i, nr = 0, ld, debug = 0;
int i, nr = 0, ld, go, debug = 0;
char **envp, **argv, *env;
size_t len;

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

// ... filtering out any 'LD_PRELOAD' ...
// ... filtering out any 'LD_PRELOAD' and 'GODEBUG' ...
nr = 0;
i = 0;
ld = -1;
go = -1;
while (environ[nr]) {
if (strncmp(environ[nr], PRELOAD_VAR,
strlen(PRELOAD_VAR)) == 0) {
ld = nr;
} else if (strncmp(environ[nr], GODEBUG_VAR,
strlen(GODEBUG_VAR)) == 0) {
go = nr;
} else {
envp[i] = environ[nr];
i++;
Expand All @@ -110,6 +116,16 @@ static int run(int argc, char *av[])
}
envp[i++] = env;

// .. and GODEBUG=multipathtcp=1 ...
if (go >= 0) {
len = strlen(environ[go]) + strlen(MPTCPGO_ENV) + 2;
env = alloca(len);
snprintf(env, len, "%s,%s", environ[go], MPTCPGO_ENV);
} else {
env = GODEBUG_VAR MPTCPGO_ENV;
}
envp[i++] = env;

// ... and enable dbg if needed
if (debug)
envp[i++] = "MPTCPWRAP_DEBUG=1";
Expand Down

0 comments on commit b0c286d

Please sign in to comment.