X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fbsd%2Fdevice.c;h=d0d0b58cf733fe630fdac3672a6eaecfc20530b8;hb=c897f8c99e0b0827cff60f098bd3f9852a062233;hp=0e795dd06e31b22ba0a9bcca03f628f45aadc85b;hpb=053925efebf466b5866de12434010c1e8127c172;p=tinc diff --git a/src/bsd/device.c b/src/bsd/device.c index 0e795dd0..d0d0b58c 100644 --- a/src/bsd/device.c +++ b/src/bsd/device.c @@ -63,18 +63,9 @@ static device_type_t device_type = DEVICE_TYPE_TUN; #endif static bool setup_device(void) { - char *type; - - if(!get_config_string(lookup_config(config_tree, "Device"), &device)) { - if(routing_mode == RMODE_ROUTER) - device = xstrdup(DEFAULT_TUN_DEVICE); - else - device = xstrdup(DEFAULT_TAP_DEVICE); - } - - if(!get_config_string(lookup_config(config_tree, "Interface"), &iface)) - iface = xstrdup(strrchr(device, '/') ? strrchr(device, '/') + 1 : device); + get_config_string(lookup_config(config_tree, "Device"), &device); + char *type; if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) { if(!strcasecmp(type, "tun")) /* use default */; @@ -93,10 +84,29 @@ static bool setup_device(void) { return false; } } else { - if(strstr(device, "tap") || routing_mode != RMODE_ROUTER) + if((device && strstr(device, "tap")) || routing_mode != RMODE_ROUTER) device_type = DEVICE_TYPE_TAP; } + if(!device) { + if(device_type == DEVICE_TYPE_TAP) + device = xstrdup(DEFAULT_TAP_DEVICE); + else + device = xstrdup(DEFAULT_TUN_DEVICE); + } + + if(!get_config_string(lookup_config(config_tree, "Interface"), &iface)) + iface = NULL; +#ifndef TAPGIFNAME + if (iface) { + logger(DEBUG_ALWAYS, LOG_WARNING, "Ignoring specified interface name '%s' as device rename is not supported on this platform", iface); + free(iface); + iface = NULL; + } +#endif + if (!iface) + iface = xstrdup(strrchr(device, '/') ? strrchr(device, '/') + 1 : device); + switch(device_type) { #ifdef ENABLE_TUNEMU case DEVICE_TYPE_TUNEMU: {