Add warnings for bad combinations of Device and Interface.
authorGuus Sliepen <guus@tinc-vpn.org>
Sat, 27 Feb 2016 13:46:01 +0000 (14:46 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 27 Feb 2016 13:46:01 +0000 (14:46 +0100)
On Linux, the name of the tun/tap interface can be set freely. However,
on most other operating systems, tinc cannot change the name of the
interface. In those situations, it is possible to specify a Device and
an Interface that conflict with each other. On BSD, this can cause
$INTERFACE to be set incorrectly, on Windows, this results in a
potentially unreliable way in which a TAP-Win32 interface is selected.

src/bsd/device.c
src/cygwin/device.c
src/mingw/device.c

index 3e9cfb2..377d4a7 100644 (file)
@@ -75,6 +75,8 @@ static bool setup_device(void) {
 
        if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
                iface = xstrdup(strrchr(device, '/') ? strrchr(device, '/') + 1 : device);
 
        if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
                iface = xstrdup(strrchr(device, '/') ? strrchr(device, '/') + 1 : device);
+       else if(strcmp(iface, strrchr(device, '/') ? strrchr(device, '/') + 1 : device))
+               logger(LOG_WARNING, "Warning: Interface does not match Device. $INTERFACE might be set incorrectly.");
 
        if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) {
                if(!strcasecmp(type, "tun"))
 
        if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) {
                if(!strcasecmp(type, "tun"))
index b582a6a..47867a4 100644 (file)
@@ -61,6 +61,9 @@ static bool setup_device(void) {
        get_config_string(lookup_config(config_tree, "Device"), &device);
        get_config_string(lookup_config(config_tree, "Interface"), &iface);
 
        get_config_string(lookup_config(config_tree, "Device"), &device);
        get_config_string(lookup_config(config_tree, "Interface"), &iface);
 
+       if(device && interface)
+               logger(LOG_WARNING, "Warning: both Device and Interface specified, results may not be as expected");
+
        /* Open registry and look for network adapters */
 
        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, NETWORK_CONNECTIONS_KEY, 0, KEY_READ, &key)) {
        /* Open registry and look for network adapters */
 
        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, NETWORK_CONNECTIONS_KEY, 0, KEY_READ, &key)) {
index 49b833a..b77282a 100644 (file)
@@ -113,6 +113,9 @@ static bool setup_device(void) {
        get_config_string(lookup_config(config_tree, "Device"), &device);
        get_config_string(lookup_config(config_tree, "Interface"), &iface);
 
        get_config_string(lookup_config(config_tree, "Device"), &device);
        get_config_string(lookup_config(config_tree, "Interface"), &iface);
 
+       if(device && interface)
+               logger(LOG_WARNING, "Warning: both Device and Interface specified, results may not be as expected");
+
        /* Open registry and look for network adapters */
 
        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, NETWORK_CONNECTIONS_KEY, 0, KEY_READ, &key)) {
        /* Open registry and look for network adapters */
 
        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, NETWORK_CONNECTIONS_KEY, 0, KEY_READ, &key)) {