config.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package wireguard
  2. import (
  3. "context"
  4. "github.com/xtls/xray-core/common/errors"
  5. )
  6. func (c *DeviceConfig) preferIP4() bool {
  7. return c.DomainStrategy == DeviceConfig_FORCE_IP ||
  8. c.DomainStrategy == DeviceConfig_FORCE_IP4 ||
  9. c.DomainStrategy == DeviceConfig_FORCE_IP46
  10. }
  11. func (c *DeviceConfig) preferIP6() bool {
  12. return c.DomainStrategy == DeviceConfig_FORCE_IP ||
  13. c.DomainStrategy == DeviceConfig_FORCE_IP6 ||
  14. c.DomainStrategy == DeviceConfig_FORCE_IP64
  15. }
  16. func (c *DeviceConfig) hasFallback() bool {
  17. return c.DomainStrategy == DeviceConfig_FORCE_IP46 || c.DomainStrategy == DeviceConfig_FORCE_IP64
  18. }
  19. func (c *DeviceConfig) fallbackIP4() bool {
  20. return c.DomainStrategy == DeviceConfig_FORCE_IP64
  21. }
  22. func (c *DeviceConfig) fallbackIP6() bool {
  23. return c.DomainStrategy == DeviceConfig_FORCE_IP46
  24. }
  25. func (c *DeviceConfig) createTun() tunCreator {
  26. if c.NoKernelTun {
  27. errors.LogWarning(context.Background(), "Using gVisor TUN.")
  28. return createGVisorTun
  29. }
  30. kernelTunSupported, err := KernelTunSupported()
  31. if err != nil {
  32. errors.LogWarning(context.Background(), "Using gVisor TUN. Failed to check kernel TUN support:", err)
  33. return createGVisorTun
  34. }
  35. if !kernelTunSupported {
  36. errors.LogWarning(context.Background(), "Using gVisor TUN. Kernel TUN is not supported on your OS, or your permission is insufficient.")
  37. return createGVisorTun
  38. }
  39. errors.LogWarning(context.Background(), "Using kernel TUN.")
  40. return createKernelTun
  41. }