Xray-core icon indicating copy to clipboard operation
Xray-core copied to clipboard

Wireguard outbound ignores sockopt:domainStrategy setting

Open paratroop3r opened this issue 1 year ago • 14 comments

Integrity requirements

  • [x] I have read all the comments in the issue template and ensured that this issue meet the requirements.
  • [x] I confirm that I have read the documentation, understand the meaning of all the configuration items I wrote, and did not pile up seemingly useful options or default values.
  • [x] I provided the complete config and logs, rather than just providing the truncated parts based on my own judgment.
  • [x] I searched issues and did not find any similar issues.
  • [x] The problem can be successfully reproduced in the latest Release

Description

I want to prioritize IPv6 connections with my wireguard server, which has IPv6 and IPv4 addresses. The client ignores any settings for specifying this priority in the server connection properties: domainStrategy, happyEyeballs settings are ignored.

Reproduction Method

Create a new WireGuard connection and try setting the IPv6 address priority using the settings I provided below. In log you will see that DNS in any case return A record, even if it is disabled. With happyEyeballs options you will see random ipv4 connections to the server.

Client config

Variant 1: priority with domainStrategy setting

{
  "log": {
    "loglevel": "debug",
    "dnsLog": true
  },
  "dns": {
    "hosts": {
      "common.dot.dns.yandex.net": [
        "77.88.8.8",
        "77.88.8.1",
        "2a02:6b8::feed:0ff",
        "2a02:6b8:0:1::feed:0ff"
      ]
    },
    "servers": [
      "https://one.one.one.one/dns-query",
      {
        "address": "https+local://common.dot.dns.yandex.net/dns-query",
        "domains": [
          "domain:engage.cloudflareclient.com"
        ],
        "tag": "domestic-dns"
      }
    ],
    "disableFallback": true,
    "tag": "dns-module"
  },
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "inboundTag": [
          "domestic-dns"
        ],
        "outboundTag": "direct"
      }
    ]
  },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 10808,
      "protocol": "socks",
      "settings": {
        "auth": "noauth",
        "udp": true,
        "userLevel": 8
      },
      "sniffing": {
        "destOverride": [
          "http",
          "tls",
          "quic"
        ],
        "enabled": true,
        "routeOnly": false
      },
      "tag": "socks"
    }
  ],
  "outbounds": [
    {
      "mux": {
        "concurrency": -1,
        "enabled": false
      },
      "protocol": "wireguard",
      "settings": {
        "address": [
          "172.16.0.2/32",
          "2606:4700:110:86c3:3476:1d78:57b7:638/128"
        ],
        "mtu": 1280,
        "peers": [
          {
            "endpoint": "engage.cloudflareclient.com:2408",
            "publicKey": "bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo="
          }
        ],
        "reserved": [
          210,
          107,
          225
        ],
        "secretKey": "J7H+ZOphnt1S2eQUBfnuoXSk/ycI7BMQmw+BEyOvCQw="
      },
      "streamSettings": {
        "network": "tcp",
          "domainStrategy": "ForceIPv6",
        }
      },
      "tag": "proxy"
    },
    {
      "protocol": "freedom",
      "streamSettings": {
        "sockopt": {
          "domainStrategy": "UseIP",
          "happyEyeballs": {
            "interleave": 2,
            "maxConcurrentTry": 4,
            "prioritizeIPv6": true,
            "tryDelayMs": 250
          }
        }
      },
      "tag": "direct"
    },
    {
      "protocol": "blackhole",
      "settings": {
        "response": {
          "type": "http"
        }
      },
      "tag": "block"
    }
  ]
}
Variant 2: priority with happyEyeballs

{
  "log": {
    "loglevel": "debug",
    "dnsLog": true
  },
  "dns": {
    "hosts": {
      "common.dot.dns.yandex.net": [
        "77.88.8.8",
        "77.88.8.1",
        "2a02:6b8::feed:0ff",
        "2a02:6b8:0:1::feed:0ff"
      ]
    },
    "servers": [
      "https://one.one.one.one/dns-query",
      {
        "address": "https+local://common.dot.dns.yandex.net/dns-query",
        "domains": [
          "domain:engage.cloudflareclient.com"
        ],
        "tag": "domestic-dns"
      }
    ],
    "disableFallback": true,
    "tag": "dns-module"
  },
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "inboundTag": [
          "domestic-dns"
        ],
        "outboundTag": "direct"
      }
    ]
  },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 10808,
      "protocol": "socks",
      "settings": {
        "auth": "noauth",
        "udp": true,
        "userLevel": 8
      },
      "sniffing": {
        "destOverride": [
          "http",
          "tls",
          "quic"
        ],
        "enabled": true,
        "routeOnly": false
      },
      "tag": "socks"
    }
  ],
  "outbounds": [
    {
      "mux": {
        "concurrency": -1,
        "enabled": false
      },
      "protocol": "wireguard",
      "settings": {
        "address": [
          "172.16.0.2/32",
          "2606:4700:110:86c3:3476:1d78:57b7:638/128"
        ],
        "mtu": 1280,
        "peers": [
          {
            "endpoint": "engage.cloudflareclient.com:2408",
            "publicKey": "bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo="
          }
        ],
        "reserved": [
          210,
          107,
          225
        ],
        "secretKey": "J7H+ZOphnt1S2eQUBfnuoXSk/ycI7BMQmw+BEyOvCQw="
      },
      "streamSettings": {
        "network": "tcp",
          "domainStrategy": "UseIP",
          "happyEyeballs": {
            "interleave": 2,
            "maxConcurrentTry": 4,
            "prioritizeIPv6": true,
            "tryDelayMs": 250
          }
        }
      },
      "tag": "proxy"
    },
    {
      "protocol": "freedom",
      "streamSettings": {
        "sockopt": {
          "domainStrategy": "UseIP",
          "happyEyeballs": {
            "interleave": 2,
            "maxConcurrentTry": 4,
            "prioritizeIPv6": true,
            "tryDelayMs": 250
          }
        }
      },
      "tag": "direct"
    },
    {
      "protocol": "blackhole",
      "settings": {
        "response": {
          "type": "http"
        }
      },
      "tag": "block"
    }
  ]
}

Server config

.

Client log

Priority with domainStrategy setting

Xray 25.12.2 (Xray, Penetrates Everything.) e403abe (go1.25.4 android/arm64)
A unified platform for anti-censorship.
2025/12/03 05:09:55.543600 Using config from STDIN
2025/12/03 05:09:55.543745 [Info] infra/conf/serial: Reading config: &{Name:stdin: Format:json}
2025/12/03 05:09:55.546254 [Debug] app/log: Logger started
2025/12/03 05:09:55.546277 [Info] app/dns: DNS: created DOH client for https://one.one.one.one/dns-query, with h2c false
2025/12/03 05:09:55.546286 [Info] app/dns: DNS: created DOHL client for https://common.dot.dns.yandex.net/dns-query, with h2c false
2025/12/03 05:09:55.546426 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:10808
2025/12/03 05:09:55.546432 [Debug] app/stats: create new counter outbound>>>proxy>>>traffic>>>uplink
2025/12/03 05:09:55.546434 [Debug] app/stats: create new counter outbound>>>proxy>>>traffic>>>downlink
2025/12/03 05:09:55.546435 [Debug] app/stats: create new counter outbound>>>direct>>>traffic>>>uplink
2025/12/03 05:09:55.546437 [Debug] app/stats: create new counter outbound>>>direct>>>traffic>>>downlink
2025/12/03 05:09:55.546439 [Debug] app/stats: create new counter outbound>>>block>>>traffic>>>uplink
2025/12/03 05:09:55.546440 [Debug] app/stats: create new counter outbound>>>block>>>traffic>>>downlink
2025/12/03 05:09:55.546634 [Info] transport/internet/tcp: listening TCP on 127.0.0.1:10808
2025/12/03 05:09:55.546804 [Info] transport/internet/udp: listening UDP on 127.0.0.1:10808
2025/12/03 05:09:55.546855 [Info] app/commander: API server listening on 127.0.0.1:15861
2025/12/03 05:09:55.546859 [Warning] core: Xray 25.12.2 started
2025/12/03 05:10:04.720187 [Debug] [1869883453] proxy/socks: Not Socks request, try to parse as HTTP request
2025/12/03 05:10:04.720424 [Info] [1869883453] proxy/http: request to Method [CONNECT] Host [ads.mozilla.org:443] with URL [//ads.mozilla.org:443]
2025/12/03 05:10:04.721542 [Info] [1869883453] app/dispatcher: sniffed domain: ads.mozilla.org
2025/12/03 05:10:04.721556 [Info] [1869883453] app/dispatcher: default route for tcp:ads.mozilla.org:443
2025/12/03 05:10:04.721558 [Info] switching dialer
2025/12/03 05:10:04.721560 [Warning] proxy/wireguard: Using gVisor TUN. Kernel TUN is not supported on your OS, or your permission is insufficient.
2025/12/03 05:10:04.721659 from 127.0.0.1:52420 accepted //ads.mozilla.org:443 [socks >> proxy]
2025/12/03 05:10:04.721828 [Debug] app/dns: domain engage.cloudflareclient.com matches following rules: [domain:engage.cloudflareclient.com(DNS idx:1)]
2025/12/03 05:10:04.721831 [Debug] app/dns: domain engage.cloudflareclient.com will use DNS in order: [DOHL//common.dot.dns.yandex.net]
2025/12/03 05:10:04.721833 [Info] app/dns: DOHL//common.dot.dns.yandex.net querying: engage.cloudflareclient.com.
2025/12/03 05:10:04.722638 from DNS accepted https://common.dot.dns.yandex.net/dns-query [local]
2025/12/03 05:10:04.722661 [Debug] transport/internet: dialing to tcp:common.dot.dns.yandex.net:443
2025/12/03 05:10:04.727078 from 127.0.0.1:52422 accepted http://detectportal.firefox.com/success.txt?ipv4 [socks >> proxy]
2025/12/03 05:10:04.727349 [Debug] [1409662596] proxy/socks: Not Socks request, try to parse as HTTP request
2025/12/03 05:10:04.727363 [Info] [1409662596] proxy/http: request to Method [GET] Host [detectportal.firefox.com] with URL [http://detectportal.firefox.com/success.txt?ipv4]
2025/12/03 05:10:04.727370 [Info] [1409662596] app/dispatcher: default route for tcp:detectportal.firefox.com:80
2025/12/03 05:10:04.728865 [Debug] [3694486531] proxy/socks: Not Socks request, try to parse as HTTP request
2025/12/03 05:10:04.728887 [Info] [3694486531] proxy/http: request to Method [GET] Host [detectportal.firefox.com] with URL [http://detectportal.firefox.com/success.txt?ipv6]
2025/12/03 05:10:04.728923 from 127.0.0.1:52430 accepted http://detectportal.firefox.com/success.txt?ipv6 [socks >> proxy]
2025/12/03 05:10:04.728949 [Info] [3694486531] app/dispatcher: default route for tcp:detectportal.firefox.com:80
2025/12/03 05:10:04.730735 [Debug] [1259029611] proxy/socks: Not Socks request, try to parse as HTTP request
2025/12/03 05:10:04.730763 [Info] [1259029611] proxy/http: request to Method [CONNECT] Host [ads.mozilla.org:443] with URL [//ads.mozilla.org:443]
2025/12/03 05:10:04.730765 [Debug] [4291056118] proxy/socks: Not Socks request, try to parse as HTTP request
2025/12/03 05:10:04.730770 [Info] [4291056118] proxy/http: request to Method [CONNECT] Host [incoming.telemetry.mozilla.org:443] with URL [//incoming.telemetry.mozilla.org:443]
2025/12/03 05:10:04.732900 from 127.0.0.1:52440 accepted //incoming.telemetry.mozilla.org:443 [socks >> proxy]
2025/12/03 05:10:04.732935 [Info] [4291056118] app/dispatcher: sniffed domain: incoming.telemetry.mozilla.org
2025/12/03 05:10:04.732943 [Info] [4291056118] app/dispatcher: default route for tcp:incoming.telemetry.mozilla.org:443
2025/12/03 05:10:04.733241 from 127.0.0.1:52438 accepted //ads.mozilla.org:443 [socks >> proxy]
2025/12/03 05:10:04.733251 [Info] [1259029611] app/dispatcher: sniffed domain: ads.mozilla.org
2025/12/03 05:10:04.733254 [Info] [1259029611] app/dispatcher: default route for tcp:ads.mozilla.org:443
2025/12/03 05:10:04.957151 [Info] app/dns: DOHL//common.dot.dns.yandex.net got answer: engage.cloudflareclient.com. TypeAAAA -> [2606:4700:d0::a29f:c001], rtt: 235.303646ms, lock: 3.698µs
2025/12/03 05:10:04.957188 [Info] app/dns: DOHL//common.dot.dns.yandex.net got answer: engage.cloudflareclient.com. TypeA -> [162.159.192.1], rtt: 235.317396ms, lock: 3.125µs
2025/12/03 05:10:04.957202 DOHL//common.dot.dns.yandex.net got answer: engage.cloudflareclient.com. -> [162.159.192.1, 2606:4700:d0::a29f:c001] 235.355ms
2025/12/03 05:10:04.957215 [Debug] Routine: encryption worker 1 - started
2025/12/03 05:10:04.957227 [Debug] Routine: encryption worker 2 - started
2025/12/03 05:10:04.957230 [Debug] Routine: decryption worker 1 - started
2025/12/03 05:10:04.957236 [Debug] Routine: decryption worker 3 - started
2025/12/03 05:10:04.957239 [Debug] Routine: handshake worker 1 - started
2025/12/03 05:10:04.957242 [Debug] Routine: handshake worker 2 - started
2025/12/03 05:10:04.957244 [Debug] Routine: encryption worker 3 - started
2025/12/03 05:10:04.957246 [Debug] Routine: encryption worker 5 - started
2025/12/03 05:10:04.957252 [Debug] Routine: encryption worker 4 - started
2025/12/03 05:10:04.957261 [Debug] Routine: decryption worker 4 - started
2025/12/03 05:10:04.957263 [Debug] Routine: handshake worker 4 - started
2025/12/03 05:10:04.957265 [Debug] Routine: encryption worker 6 - started
2025/12/03 05:10:04.957267 [Debug] Routine: handshake worker 3 - started
2025/12/03 05:10:04.957269 [Debug] Routine: decryption worker 5 - started
2025/12/03 05:10:04.957271 [Debug] Routine: handshake worker 5 - started
2025/12/03 05:10:04.957273 [Debug] Routine: handshake worker 6 - started
2025/12/03 05:10:04.957275 [Debug] Routine: handshake worker 7 - started
2025/12/03 05:10:04.957277 [Debug] UAPI: Updating private key
2025/12/03 05:10:04.957282 [Debug] Routine: encryption worker 7 - started
2025/12/03 05:10:04.957284 [Debug] Routine: decryption worker 6 - started
2025/12/03 05:10:04.957300 [Debug] Routine: handshake worker 8 - started
2025/12/03 05:10:04.957302 [Debug] Routine: decryption worker 7 - started
2025/12/03 05:10:04.957304 [Debug] Routine: decryption worker 8 - started
2025/12/03 05:10:04.957306 [Debug] Routine: encryption worker 8 - started
2025/12/03 05:10:04.957308 [Debug] Routine: TUN reader - started
2025/12/03 05:10:04.957373 [Debug] Routine: decryption worker 2 - started
2025/12/03 05:10:04.957383 [Debug] Routine: event worker - started
2025/12/03 05:10:04.957386 [Debug] Interface up requested
2025/12/03 05:10:04.957415 [Debug] UDP bind has been updated
2025/12/03 05:10:04.957455 [Debug] Routine: receive incoming Open - started
2025/12/03 05:10:04.957755 [Debug] peer(bmXO…fgyo) - UAPI: Created
2025/12/03 05:10:04.957758 [Debug] peer(bmXO…fgyo) - UAPI: Updating endpoint
2025/12/03 05:10:04.957759 [Debug] peer(bmXO…fgyo) - UAPI: Adding allowedip
2025/12/03 05:10:04.957761 [Debug] peer(bmXO…fgyo) - UAPI: Adding allowedip
2025/12/03 05:10:04.957763 [Debug] peer(bmXO…fgyo) - Starting
2025/12/03 05:10:04.957765 [Debug] Interface state was Down, requested Up, now Up
2025/12/03 05:10:04.958107 [Warning] app/dns: domain ads.mozilla.org will use the first DNS: [DOH//one.one.one.one]
2025/12/03 05:10:04.958118 [Info] app/dns: DOH//one.one.one.one querying: ads.mozilla.org.
2025/12/03 05:10:04.958325 [Debug] peer(bmXO…fgyo) - Routine: sequential sender - started
2025/12/03 05:10:04.958335 [Debug] peer(bmXO…fgyo) - Routine: sequential receiver - started
2025/12/03 05:10:04.958367 [Warning] app/dns: domain detectportal.firefox.com will use the first DNS: [DOH//one.one.one.one]
2025/12/03 05:10:04.958370 [Info] app/dns: DOH//one.one.one.one querying: detectportal.firefox.com.
2025/12/03 05:10:04.958375 [Warning] app/dns: domain incoming.telemetry.mozilla.org will use the first DNS: [DOH//one.one.one.one]
2025/12/03 05:10:04.958503 [Info] app/dns: DOH//one.one.one.one querying: incoming.telemetry.mozilla.org.

Server log

.

paratroop3r avatar Dec 02 '25 05:12 paratroop3r

未遵照模板

Fangliding avatar Dec 02 '25 05:12 Fangliding

未遵照模板

I dont understand, what else you need to check my report? Server logs and config is not relevant in that case. We talk about domain resolution.

paratroop3r avatar Dec 02 '25 06:12 paratroop3r

无论如何都需要按要求填写模板 否则会关闭 写的很清楚 因为我们要稳定复现 不是花时间去猜你别的地方是怎么写的和你的意思是什么

Fangliding avatar Dec 02 '25 06:12 Fangliding

无论如何都需要按要求填写模板 否则会关闭 写的很清楚 因为我们要稳定复现 不是花时间去猜你别的地方是怎么写的和你的意思是什么

ok, what should I write for server side? I don't have access to server. In that case bug will be ignored? I can extend client side configs and logs. Is it enough for issue reopening?

paratroop3r avatar Dec 02 '25 06:12 paratroop3r

至少客户端要可以运行起来 而且要可以直接运行

Fangliding avatar Dec 02 '25 06:12 Fangliding

至少客户端要可以运行起来 而且要可以直接运行

I've made changes. Reopen, please.

paratroop3r avatar Dec 03 '25 05:12 paratroop3r

sockopt.domainstrategy 控制的是连接服务端的行为 而不是被代理连接的行为

Fangliding avatar Dec 03 '25 08:12 Fangliding

sockopt.domainstrategy 控制的是连接服务端的行为 而不是被代理连接的行为

Exactly! I need to connect to server through ipv6. It is what I've said in "Description" section of topic.

paratroop3r avatar Dec 03 '25 08:12 paratroop3r

由于 ~~糟糕~~非常辣眼睛 的wireguard实现它被预解析了 甚至逻辑都是个错的 这个出站已经被半放弃维护了( 这里建议直接写IP 因为就算让它遵守sockopt happyeyeball也对它不生效(它只支持TCP) 没法达到你的目的

Fangliding avatar Dec 03 '25 08:12 Fangliding

Forget about happy eyeballs. Lets discuss variant 1 of config. It doesn't have happy eyeballs. I think that if I set sockopt.domainstrategy = ForceIPv6, then when querying the DNS server for the IP address of the WireGuard server, only an AAAA record should be returned. No A record. This is exactly how it's described in the official X-Ray documentation.

Image

I've tested this with a vless server. If you set sockopt.domainstrategy = ForceIPv6 in its configuration, then ONLY an AAAA record is obtained for its domain name. This is visible in the log files. For some reason, this doesn't work for the WireGuard server's domain name. It always returns both A and AAAA records, and the connection is established randomly: sometimes to IPv4, sometimes to IPv6.

paratroop3r avatar Dec 03 '25 09:12 paratroop3r

是的 wireguard 出站有问题 因为它不遵守ray架构内部的一些约定 不太打算修

Fangliding avatar Dec 03 '25 09:12 Fangliding

我在 review targetStrategy 的时候无意间发现了这个

@paratroop3r 试试 wireguard.settings.domainStrategy 是否有效

      "protocol": "wireguard",
      "settings": {
        "domainStrategy": "ForceIPv6", // here!
        "address": [
          "172.16.0.2/32",
          "2606:4700:110:86c3:3476:1d78:57b7:638/128"
        ],
        "mtu": 1280,
        "peers": [

Meo597 avatar Dec 12 '25 07:12 Meo597

@Meo597 It is the target strategy (which IP type for sites need to request through dns). In your solution warp will be able to open only sites, which has ipv6 address.

I've bypassed the bug with dns.hosts part (I left only the IPv6 address for domain). But anyway bug is present...

paratroop3r avatar Dec 12 '25 07:12 paratroop3r

Image

wireguard.settings.domainStrategy 同时控制着 peer 和 被代理流量 所以它是有效的

Meo597 avatar Dec 12 '25 08:12 Meo597