Skip to content

Commit fa555b1

Browse files
committed
refactor: rewrite routing rule and do not ping when no allowed ips
1 parent 7f1d523 commit fa555b1

File tree

3 files changed

+698
-463
lines changed

3 files changed

+698
-463
lines changed

services/wg/ping.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ func (w *wireGuard) scheduleVirtualAddrPings(log *logrus.Entry, ifceConfig *defs
142142
peers := ifceConfig.Peers
143143
for _, peer := range peers {
144144
p := peer
145+
// 没有 AllowedIPs 的 peer(例如仅用于保持连接/预连接的常驻 peer)不参与 virt addr 探测:
146+
// - 此时本机通常没有到对端 virtIP 的路由,探测必然失败
147+
// - 若失败写入不可达哨兵,会污染 master 的拓扑 cache,导致 SPF 误判为不可达,进而“完全不连通”
148+
if p == nil || len(p.GetAllowedIps()) == 0 {
149+
continue
150+
}
145151
addr := p.GetVirtualIp()
146152
if addr == "" {
147153
continue
@@ -157,7 +163,10 @@ func (w *wireGuard) scheduleVirtualAddrPings(log *logrus.Entry, ifceConfig *defs
157163
avg, err := tcpPingAvg(tcpAddr, endpointPingCount, endpointPingTimeout)
158164
if err != nil {
159165
log.WithError(err).Errorf("failed to tcp ping virt addr %s via %s", addr, tcpAddr)
160-
w.storeVirtAddrPing(addr, math.MaxUint32)
166+
// 失败时不写入不可达哨兵,避免污染拓扑;删除该条记录即可回退到 endpoint latency
167+
if w.virtAddrPingMap != nil {
168+
w.virtAddrPingMap.Delete(addr)
169+
}
161170
return
162171
}
163172

0 commit comments

Comments
 (0)