SagerNet / sing-box

The universal proxy platform
https://sing-box.sagernet.org/
Other
18.69k stars 2.24k forks source link

Cannot bind IPv6 link-local address #315

Closed kabegoe closed 1 year ago

kabegoe commented 1 year ago

Welcome

Description of the problem

If assign "listen": "fe80::aaaa:bbbb:cccc:dddd", sing-box fails to bind to the address. However, "listen": "::" does the trick. Neither "listen": "fe80::aaaa:bbbb:cccc:dddd%wlo1" nor "listen": "fe80::aaaa:bbbb:cccc:dddd%3" works. No problem with global IPv6 address.

Version of sing-box

https://github.com/SagerNet/sing-box/commit/23a35b3c06304bd0d884f1b24260858afbbae2a5

$ sing-box version
sing-box version 1.1.2

Environment: go1.19.4 linux/amd64
CGO: enabled

Server and client configuration file

{
  "log": {
    "level": "trace"
  },
  "inbounds": [
    {
      "type": "direct",
      "tag": "v6-dns-in",
      "listen": "fe80::aaaa:bbbb:cccc:dddd",
      "listen_port": 53530,
      "sniff": true,
      "sniff_override_destination": false
    }
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct-out",
      "bind_interface": "wlo1"
    }
  ],
  "route": {
    "final": "direct-out",
    "default_interface": "wlo1"
  }
}

Server and client log file

FATAL[0000] start service: initialize inbound/direct[v6-dns-in]: listen tcp [fe80::aaaa:bbbb:cccc:dddd]:53530: bind: invalid argument
nekohasekai commented 1 year ago

Can you provide a working example of another program?

kabegoe commented 1 year ago

AdguardTeam/dnsproxy has same symptoms.

bind9 (not a go program) works.

$ uname -a
Linux raspberrypi 5.15.84-v8+ #1613 SMP PREEMPT Thu Jan 5 12:03:08 GMT 2023 aarch64 GNU/Linux

$ named -v
BIND 9.16.33-Debian (Extended Support Version) <id:35e9c6e>

$ cat /etc/bind/named.conf.options
options {
        directory "/var/cache/bind";
        listen-on-v6 port 53530 { fe80::aaaa:bbbb:cccc:dddd; };
        allow-query { any; };
        forwarders { 192.168.0.1; };
        forward only;
        recursion yes;
        send-cookie no;
        dnssec-validation no;
};

$ sudo lsof -i -P -n
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
named     1890     bind   49u  IPv6  26599      0t0  UDP [fe80::aaaa:bbbb:cccc:dddd]:53530
named     1890     bind   50u  IPv6  26600      0t0  UDP [fe80::aaaa:bbbb:cccc:dddd]:53530
named     1890     bind   51u  IPv6  26601      0t0  UDP [fe80::aaaa:bbbb:cccc:dddd]:53530
named     1890     bind   52u  IPv6  26602      0t0  UDP [fe80::aaaa:bbbb:cccc:dddd]:53530
named     1890     bind   53u  IPv6  26603      0t0  TCP [fe80::aaaa:bbbb:cccc:dddd]:53530 (LISTEN)
named     1890     bind   54u  IPv6  26604      0t0  TCP [fe80::aaaa:bbbb:cccc:dddd]:53530 (LISTEN)
named     1890     bind   55u  IPv6  26605      0t0  TCP [fe80::aaaa:bbbb:cccc:dddd]:53530 (LISTEN)
named     1890     bind   56u  IPv6  26606      0t0  TCP [fe80::aaaa:bbbb:cccc:dddd]:53530 (LISTEN)
kabegoe commented 1 year ago

Not a problem in most cases. Let's ignore it.

nekohasekai commented 1 year ago

Try 59e521c1db89072142f39e98bc440f2f9bf99401

(fe80::aaaa:bbbb:cccc:dddd%wlo1 should work)

kabegoe commented 1 year ago

Fixed. Thank you!