X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fifconfig.c;h=9913b81562703c24e9da5dae3c99e34d84590abd;hb=e1823fc941f16b4b769e4511c8acb274705cc989;hp=f4b8453748c50900ec2510c91cc441560ac504bb;hpb=f6e87ab476a0faf8b124ecaaa27f967d825e6457;p=tinc diff --git a/src/ifconfig.c b/src/ifconfig.c index f4b84537..9913b815 100644 --- a/src/ifconfig.c +++ b/src/ifconfig.c @@ -1,6 +1,6 @@ /* ifconfig.c -- Generate platform specific interface configuration commands - Copyright (C) 2016-2017 Guus Sliepen + Copyright (C) 2016-2018 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,9 +25,12 @@ static long start; -#ifndef HAVE_MINGW +#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; @@ -71,10 +79,12 @@ void ifconfig_dhcp(FILE *out) { } void ifconfig_dhcp6(FILE *out) { + (void)out; fprintf(stderr, "DHCPv6 requested, but not supported by tinc on this platform\n"); } void ifconfig_slaac(FILE *out) { + (void)out; // It's the default? } @@ -86,7 +96,7 @@ bool ifconfig_footer(FILE *out) { static subnet_t ipv4, ipv6; void ifconfig_address(FILE *out, const char *value) { - subnet_t address = {}; + subnet_t address = {0}; char address_str[MAXNETSTR]; if(!str2net(&address, value) || !net2str(address_str, sizeof(address_str), &address)) { @@ -103,6 +113,7 @@ void ifconfig_address(FILE *out, const char *value) { ipv6 = address; break; + case SUBNET_MAC: default: return; } @@ -126,7 +137,7 @@ void ifconfig_address(FILE *out, const char *value) { return; } -#elif defined(HAVE_MINGW) || defined(HAVE_CYGWIN) +#elif defined(HAVE_WINDOWS) switch(address.type) { case SUBNET_MAC: @@ -134,11 +145,11 @@ void ifconfig_address(FILE *out, const char *value) { break; case SUBNET_IPV4: - fprintf(out, "netsh inetface ipv4 set address \"$INTERFACE\" static %s\n", address_str); + fprintf(out, "netsh interface ipv4 set address \"%%INTERFACE%%\" static %s\n", address_str); break; case SUBNET_IPV6: - fprintf(out, "netsh inetface ipv6 set address \"$INTERFACE\" static %s\n", address_str); + fprintf(out, "netsh interface ipv6 set address \"%%INTERFACE%%\" %s\n", address_str); break; default: @@ -168,7 +179,7 @@ void ifconfig_address(FILE *out, const char *value) { } void ifconfig_route(FILE *out, const char *value) { - subnet_t subnet = {}, gateway = {}; + subnet_t subnet = {0}, gateway = {0}; char subnet_str[MAXNETSTR] = "", gateway_str[MAXNETSTR] = ""; char *sep = strchr(value, ' '); @@ -199,13 +210,14 @@ void ifconfig_route(FILE *out, const char *value) { if(*gateway_str) { switch(subnet.type) { case SUBNET_IPV4: - fprintf(out, "ip route add %s via %s dev \"$INTERFACE\"\n", subnet_str, gateway_str); + fprintf(out, "ip route add %s via %s dev \"$INTERFACE\" onlink\n", subnet_str, gateway_str); break; case SUBNET_IPV6: - fprintf(out, "ip route add %s via %s dev \"$INTERFACE\"\n", subnet_str, gateway_str); + fprintf(out, "ip route add %s via %s dev \"$INTERFACE\" onlink\n", subnet_str, gateway_str); break; + case SUBNET_MAC: default: return; } @@ -219,36 +231,39 @@ 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; } } -#elif defined(HAVE_MINGW) || defined(HAVE_CYGWIN) +#elif defined(HAVE_WINDOWS) if(*gateway_str) { switch(subnet.type) { case SUBNET_IPV4: - fprintf(out, "netsh inetface ipv4 add route %s \"%%INTERFACE%%\" %s\n", subnet_str, gateway_str); + fprintf(out, "netsh interface ipv4 add route %s \"%%INTERFACE%%\" %s\n", subnet_str, gateway_str); break; case SUBNET_IPV6: - fprintf(out, "netsh inetface ipv6 add route %s \"%%INTERFACE%%\" %s\n", subnet_str, gateway_str); + fprintf(out, "netsh interface ipv6 add route %s \"%%INTERFACE%%\" %s\n", subnet_str, gateway_str); break; + case SUBNET_MAC: default: return; } } else { switch(subnet.type) { case SUBNET_IPV4: - fprintf(out, "netsh inetface ipv4 add route %s \"%%INTERFACE%%\"\n", subnet_str); + fprintf(out, "netsh interface ipv4 add route %s \"%%INTERFACE%%\"\n", subnet_str); break; case SUBNET_IPV6: - fprintf(out, "netsh inetface ipv6 add route %s \"%%INTERFACE%%\"\n", subnet_str); + fprintf(out, "netsh interface ipv6 add route %s \"%%INTERFACE%%\"\n", subnet_str); break; + case SUBNET_MAC: default: return; } @@ -276,6 +291,7 @@ void ifconfig_route(FILE *out, const char *value) { net2str(gateway_str, sizeof(gateway_str), &ipv6); break; + case SUBNET_MAC: default: return; } @@ -296,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; }