Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] 不能实现与 wg-quick 等价的 wireguard 配置 #522

Open
5 of 6 tasks
chaosong opened this issue Apr 25, 2023 · 2 comments
Open
5 of 6 tasks

[Bug] 不能实现与 wg-quick 等价的 wireguard 配置 #522

chaosong opened this issue Apr 25, 2023 · 2 comments

Comments

@chaosong
Copy link

chaosong commented Apr 25, 2023

Verify steps

  • 确保你使用的是本仓库最新的的 clash 或 clash Alpha 版本 Ensure you are using the latest version of Clash or Clash Premium from this repository.
  • 如果你可以自己 debug 并解决的话,提交 PR 吧 Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome.
  • 我已经在 Issue Tracker 中找过我要提出的问题 I have searched on the issue tracker for a related issue.
  • 我已经使用 Alpha 分支版本测试过,问题依旧存在 I have tested using the dev branch, and the issue still exists.
  • 我已经仔细看过 Documentation 并无法自行解决问题 I have read the documentation and was unable to solve the issue.
  • 这是 Clash 核心的问题,并非我所使用的 Clash 衍生版本(如 OpenClash、KoolClash 等)的特定问题 This is an issue of the Clash core per se, not to the derivatives of Clash, like OpenClash or KoolClash.

Clash version

alpha-efcb278f

What OS are you seeing the problem on?

macOS

Clash config

yaml
proxies:
  - name: "demo"
    type: wireguard
    private_key: xxxx
    udp: true

    peers:
      - server: 1.2.3.4
        port: 12345
        ip: 192.168.48.9/32
        public-key: aaaaaaa
        allowed_ips: ['192.168.48.1/24']
      - server: 5.6.7.8
        port: 12345
        ip: 192.168.48.9/32
        public-key: bbbbbbb
        allowed_ips: ['192.168.58.1/24']


### Clash log

```shell
Parse config error: proxy 4: create WireGuard device: parse local address 192.168.48.9/32: duplicate address

Description

应该是 outbound.tunDevice, err = wireguard.NewStackDevice(localPrefixes, uint32(mtu)) 这里报错,也即多个 peer 不允许用同一个 local ip。

虽然可以通过配置多个 proxy,而非使用一个 proxy 多个 peers 来回避掉,但是这种方式使得出口 nat 后的 endpoint 是多个,用来组网会引起诸多不便。

尝试了将 localPrefixes 去重,但结果仍然不对,会引起这几个 peer 都握手失败。(peer 只保留一个时,连接是没问题的)

是否考虑一下,将 WireguardPeerOption 中的 Ip、Ipv6 这两个字段上调到 WireGuardOption 中, 采用和 PrivateKey 一样的处理逻辑,亦即: 『如果peers不为空,该段落中的allowed_ips不可为空;前面段落的server,port,public-key,pre-shared-key均会被忽略,但ip,ipv6,private-key会被保留且只能在顶层指定』

type WireGuardOption struct {
	BasicOption
	WireGuardPeerOption
	Name                string `proxy:"name"`
	Ip           string   `proxy:"ip,omitempty"`
	Ipv6         string   `proxy:"ipv6,omitempty"`
	PrivateKey          string `proxy:"private-key"`
	Workers             int    `proxy:"workers,omitempty"`
	MTU                 int    `proxy:"mtu,omitempty"`
	UDP                 bool   `proxy:"udp,omitempty"`
	PersistentKeepalive int    `proxy:"persistent-keepalive,omitempty"`

	Peers []WireGuardPeerOption `proxy:"peers,omitempty"`

	RemoteDnsResolve bool     `proxy:"remote-dns-resolve,omitempty"`
	Dns              []string `proxy:"dns,omitempty"`
}

type WireGuardPeerOption struct {
	Server       string   `proxy:"server"`
	Port         int      `proxy:"port"`
	PublicKey    string   `proxy:"public-key,omitempty"`
	PreSharedKey string   `proxy:"pre-shared-key,omitempty"`
	Reserved     []uint8  `proxy:"reserved,omitempty"`
	AllowedIPs   []string `proxy:"allowed_ips,omitempty"`
}

这样,才是精确地和 wg-quick 等工具的配置方法和效果一一对应。

期盼大家的回复,谢谢!

@chaosong
Copy link
Author

试了一下,用 wireguard-go 官方 repo 中的例子(修改成个人 multi-peers 配置) go run wireguard-go/tun/netstack/examples/http_client.go 证明是可以实现的。

@daiaji
Copy link

daiaji commented Feb 26, 2024

配置很迷惑,普通的WG配置,根本不用为peers设置本地地址啊,这玩意是在对端配置的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants