Fix default device path selection on BSD.
Currently, if DeviceType = tap but Mode = router, the default device path is /dev/tun0, which is wrong. This commit fixes that.
This commit is contained in:
parent
a649aa51bf
commit
c897f8c99e
1 changed files with 22 additions and 21 deletions
|
@ -63,27 +63,9 @@ static device_type_t device_type = DEVICE_TYPE_TUN;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool setup_device(void) {
|
static bool setup_device(void) {
|
||||||
|
get_config_string(lookup_config(config_tree, "Device"), &device);
|
||||||
|
|
||||||
char *type;
|
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 = 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);
|
|
||||||
|
|
||||||
if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) {
|
if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) {
|
||||||
if(!strcasecmp(type, "tun"))
|
if(!strcasecmp(type, "tun"))
|
||||||
/* use default */;
|
/* use default */;
|
||||||
|
@ -102,10 +84,29 @@ static bool setup_device(void) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(strstr(device, "tap") || routing_mode != RMODE_ROUTER)
|
if((device && strstr(device, "tap")) || routing_mode != RMODE_ROUTER)
|
||||||
device_type = DEVICE_TYPE_TAP;
|
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) {
|
switch(device_type) {
|
||||||
#ifdef ENABLE_TUNEMU
|
#ifdef ENABLE_TUNEMU
|
||||||
case DEVICE_TYPE_TUNEMU: {
|
case DEVICE_TYPE_TUNEMU: {
|
||||||
|
|
Loading…
Reference in a new issue