2023-11-12 22:52:09 +02:00
|
|
|
package wireguard
|
|
|
|
|
2024-10-18 03:10:09 +03:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/xtls/xray-core/common/errors"
|
|
|
|
)
|
|
|
|
|
2023-11-12 22:52:09 +02:00
|
|
|
func (c *DeviceConfig) preferIP4() bool {
|
|
|
|
return c.DomainStrategy == DeviceConfig_FORCE_IP ||
|
|
|
|
c.DomainStrategy == DeviceConfig_FORCE_IP4 ||
|
|
|
|
c.DomainStrategy == DeviceConfig_FORCE_IP46
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *DeviceConfig) preferIP6() bool {
|
|
|
|
return c.DomainStrategy == DeviceConfig_FORCE_IP ||
|
|
|
|
c.DomainStrategy == DeviceConfig_FORCE_IP6 ||
|
|
|
|
c.DomainStrategy == DeviceConfig_FORCE_IP64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *DeviceConfig) hasFallback() bool {
|
|
|
|
return c.DomainStrategy == DeviceConfig_FORCE_IP46 || c.DomainStrategy == DeviceConfig_FORCE_IP64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *DeviceConfig) fallbackIP4() bool {
|
|
|
|
return c.DomainStrategy == DeviceConfig_FORCE_IP64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *DeviceConfig) fallbackIP6() bool {
|
|
|
|
return c.DomainStrategy == DeviceConfig_FORCE_IP46
|
|
|
|
}
|
2023-11-18 05:27:17 +02:00
|
|
|
|
|
|
|
func (c *DeviceConfig) createTun() tunCreator {
|
2024-10-18 03:10:09 +03:00
|
|
|
if c.NoKernelTun {
|
2024-10-30 04:20:55 +02:00
|
|
|
errors.LogWarning(context.Background(), "Using gVisor TUN.")
|
2024-10-18 03:10:09 +03:00
|
|
|
return createGVisorTun
|
|
|
|
}
|
|
|
|
kernelTunSupported, err := KernelTunSupported()
|
|
|
|
if err != nil {
|
|
|
|
errors.LogWarning(context.Background(), "Using gVisor TUN. Failed to check kernel TUN support:", err)
|
|
|
|
return createGVisorTun
|
|
|
|
}
|
|
|
|
if !kernelTunSupported {
|
2024-10-30 04:20:55 +02:00
|
|
|
errors.LogWarning(context.Background(), "Using gVisor TUN. Kernel TUN is not supported on your OS, or your permission is insufficient.")
|
2024-10-18 03:10:09 +03:00
|
|
|
return createGVisorTun
|
2023-11-18 05:27:17 +02:00
|
|
|
}
|
2024-10-30 04:20:55 +02:00
|
|
|
errors.LogWarning(context.Background(), "Using kernel TUN.")
|
2024-10-18 03:10:09 +03:00
|
|
|
return createKernelTun
|
2023-11-18 05:27:17 +02:00
|
|
|
}
|