From e1823fc941f16b4b769e4511c8acb274705cc989 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 7 Apr 2024 15:41:04 +0200 Subject: [PATCH] Run ip link up before adding addresses and routes On Linux, some iproute2 commands to set addresses and add routes don't work or have no effect if the link is not up, so make sure we set the link up first. --- src/ifconfig.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ifconfig.c b/src/ifconfig.c index d4f13865..9913b815 100644 --- a/src/ifconfig.c +++ b/src/ifconfig.c @@ -28,6 +28,9 @@ static long start; #ifndef HAVE_WINDOWS void ifconfig_header(FILE *out) { fprintf(out, "#!/bin/sh\n"); +#ifdef HAVE_LINUX + fprintf(out, "ip link set \"$INTERFACE\" up\n"); +#endif start = ftell(out); } @@ -50,12 +53,17 @@ void ifconfig_slaac(FILE *out) { bool ifconfig_footer(FILE *out) { if(ftell(out) == start) { - fprintf(out, "echo 'Unconfigured tinc-up script, please edit '$0'!'\n\n#ifconfig $INTERFACE netmask \n"); - return false; - } else { + fprintf(out, #ifdef HAVE_LINUX - fprintf(out, "ip link set \"$INTERFACE\" up\n"); + "#ip addr add / dev $INTERFACE\n" #else + "#ifconfig $INTERFACE /\n" +#endif + "\n" + "echo \"Unconfigured tinc-up script, please edit '$0'!\" >&2\n"); + return false; + } else { +#ifndef HAVE_LINUX fprintf(out, "ifconfig \"$INTERFACE\" up\n"); #endif return true; -- 2.20.1