Run ip link up before adding addresses and routes
[tinc] / src / ifconfig.c
index f4ce313..9913b81 100644 (file)
@@ -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 <your vpn IP address> netmask <netmask of whole VPN>\n");
-               return false;
-       } else {
+               fprintf(out,
 #ifdef HAVE_LINUX
-               fprintf(out, "ip link set \"$INTERFACE\" up\n");
+                       "#ip addr add <your vpn IP address>/<prefix of whole VPN> dev $INTERFACE\n"
 #else
+                       "#ifconfig $INTERFACE <your vpn IP address>/<prefix of whole VPN>\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;
@@ -105,6 +113,7 @@ void ifconfig_address(FILE *out, const char *value) {
                ipv6 = address;
                break;
 
+       case SUBNET_MAC:
        default:
                return;
        }
@@ -208,6 +217,7 @@ void ifconfig_route(FILE *out, const char *value) {
                        fprintf(out, "ip route add %s via %s dev \"$INTERFACE\" onlink\n", subnet_str, gateway_str);
                        break;
 
+               case SUBNET_MAC:
                default:
                        return;
                }
@@ -221,6 +231,7 @@ void ifconfig_route(FILE *out, const char *value) {
                        fprintf(out, "ip route add %s dev \"$INTERFACE\"\n", subnet_str);
                        break;
 
+               case SUBNET_MAC:
                default:
                        return;
                }
@@ -238,6 +249,7 @@ void ifconfig_route(FILE *out, const char *value) {
                        fprintf(out, "netsh interface ipv6 add route %s \"%%INTERFACE%%\" %s\n", subnet_str, gateway_str);
                        break;
 
+               case SUBNET_MAC:
                default:
                        return;
                }
@@ -251,6 +263,7 @@ void ifconfig_route(FILE *out, const char *value) {
                        fprintf(out, "netsh interface ipv6 add route %s \"%%INTERFACE%%\"\n", subnet_str);
                        break;
 
+               case SUBNET_MAC:
                default:
                        return;
                }
@@ -278,6 +291,7 @@ void ifconfig_route(FILE *out, const char *value) {
                        net2str(gateway_str, sizeof(gateway_str), &ipv6);
                        break;
 
+               case SUBNET_MAC:
                default:
                        return;
                }
@@ -298,6 +312,7 @@ void ifconfig_route(FILE *out, const char *value) {
                fprintf(out, "route add -inet6 %s %s\n", subnet_str, gateway_str);
                break;
 
+       case SUBNET_MAC:
        default:
                return;
        }