From af3aa021050559e6bcd2f603af3c7a71b6fe7a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sat, 13 Jul 2024 01:56:02 +0900 Subject: [PATCH] feat(route): support `x` grammar --- README.md | 47 +++++++++++++++++++++++---------------------- gold/link/peer.go | 10 ++++++++++ gold/link/router.go | 2 +- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 395e6b5..eccb394 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@
- WireGold-Maria + WireGold-Maria

WireGold

Wire Golang Guard = WireGold

@@ -39,30 +39,31 @@ SubNet: 192.168.233.0/24 PrivateKey: 暲菉斂狧污爉窫擸紈卆帞蔩慈睠庮扝憚瞼縀 EndPoint: 0.0.0.0:56789 MTU: 1504 +SpeedLoop: 4096 Mask: 0x1234567890abcdef Peers: - - IP: "192.168.233.2" - SubNet: 192.168.233.0/24 - PublicKey: 徯萃嵾爻燸攗窍褃冔蒔犡緇袿屿組待族砇嘀 - PresharedKey: 瀸敀爅崾嘊嵜紼樴稍毯攣矐訷蟷扛嬋庩崛昀 - EndPoint: 1.2.3.4:56789 - AllowedIPs: ["192.168.233.2/32"] - KeepAliveSeconds: 0 - QueryList: ["192.168.233.3"] - MTU: 1400 - MTURandomRange: 128 - UseZstd: true - QuerySeconds: 10 - AllowTrans: false + IP: "192.168.233.2" + SubNet: 192.168.233.0/24 + PublicKey: 徯萃嵾爻燸攗窍褃冔蒔犡緇袿屿組待族砇嘀 + PresharedKey: 瀸敀爅崾嘊嵜紼樴稍毯攣矐訷蟷扛嬋庩崛昀 + EndPoint: 1.2.3.4:56789 + AllowedIPs: ["192.168.233.2/32", "x192.168.233.3/32"] # allow trans to 192.168.233.3, but don not create route + KeepAliveSeconds: 0 + QueryList: ["192.168.233.3"] + MTU: 1400 + MTURandomRange: 128 + UseZstd: true + QuerySeconds: 10 + AllowTrans: true - - IP: "192.168.233.3" - SubNet: 192.168.233.0/24 - PublicKey: 牢喨粷詸衭譛浾蘹櫠砙杹蟫瑳叩刋橋経挵蘀 - PresharedKey: 竅琚喫従痸告烈兇厕趭萨假蔛瀇譄施烸蝫瘀 - EndPoint: "" - AllowedIPs: ["192.168.233.3/32"] - MTU: 752 - KeepAliveSeconds: 0 - AllowTrans: false + IP: "192.168.233.3" + SubNet: 192.168.233.0/24 + PublicKey: 牢喨粷詸衭譛浾蘹櫠砙杹蟫瑳叩刋橋経挵蘀 + PresharedKey: 竅琚喫従痸告烈兇厕趭萨假蔛瀇譄施烸蝫瘀 + EndPoint: "" + AllowedIPs: ["192.168.233.3/32"] + MTU: 752 + KeepAliveSeconds: 0 + AllowTrans: false ``` diff --git a/gold/link/peer.go b/gold/link/peer.go index 98505cb..53cb190 100644 --- a/gold/link/peer.go +++ b/gold/link/peer.go @@ -81,6 +81,16 @@ func (m *Me) AddPeer(cfg *PeerConfig) (l *Link) { if cfg.AllowedIPs != nil { l.allowedips = make([]*net.IPNet, 0, len(cfg.AllowedIPs)) for _, ipnet := range cfg.AllowedIPs { + if len(ipnet) == 0 { + continue + } + noroute := ipnet[0] == 'x' + if noroute { + ipnet = ipnet[1:] + if len(ipnet) == 0 { + continue + } + } _, cidr, err := net.ParseCIDR(ipnet) if err == nil { l.allowedips = append(l.allowedips, cidr) diff --git a/gold/link/router.go b/gold/link/router.go index 452152d..eb2b730 100644 --- a/gold/link/router.go +++ b/gold/link/router.go @@ -81,7 +81,7 @@ func (r *Router) SetItem(ip *net.IPNet, l *Link) { if r.list[i].Contains(ip.IP) { // 是同一个网络 if ip.Mask.String() == r.list[i].Mask.String() { - logrus.Infoln("[router] change link of item", r.list[i], "from", r.table[r.list[i].String()], "to", l) + logrus.Warnln("[router] change link of item", r.list[i], "from", r.table[r.list[i].String()], "to", l) r.table[r.list[i].String()] = l break }