From 2f03a5d94c0bb6732fd65263217e3aa2b72f18ff Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 27 Feb 2016 14:46:01 +0100 Subject: [PATCH 1/1] Add warnings for bad combinations of Device and Interface. 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 | 2 ++ src/cygwin/device.c | 3 +++ src/mingw/device.c | 3 +++ 3 files changed, 8 insertions(+) diff --git a/src/bsd/device.c b/src/bsd/device.c index 3e9cfb27..377d4a7b 100644 --- a/src/bsd/device.c +++ b/src/bsd/device.c @@ -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); + 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")) diff --git a/src/cygwin/device.c b/src/cygwin/device.c index b582a6a9..47867a49 100644 --- a/src/cygwin/device.c +++ b/src/cygwin/device.c @@ -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); + 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)) { diff --git a/src/mingw/device.c b/src/mingw/device.c index 49b833ab..b77282ad 100644 --- a/src/mingw/device.c +++ b/src/mingw/device.c @@ -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); + 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)) { -- 2.20.1