Audit changes

This commit is contained in:
jdl
2026-06-14 05:42:44 +02:00
parent 992eabc0e9
commit c12ef3341f

View File

@@ -2,6 +2,7 @@ package peer
import ( import (
"log" "log"
"net/netip"
"time" "time"
"vppn/peer/control" "vppn/peer/control"
@@ -32,13 +33,13 @@ func (a *App) onPing(e PingEvent) {
return return
} }
// We can only learn our own endpoint from directly-connected peers — Dst // We can only learn our own endpoint from directly-connected peers — Dst is
// is the sender's observation of our WG handshake source. // the sender's observation of our WG handshake source.
// //
// We make sure we don't set a private address as our public address since we // We make sure we don't set a private address as our public address since we
// may be connected via LAN to some peers. // may be connected via LAN to some peers.
if peer.State == StateDirect { if peer.State == StateDirect {
if dst := e.ping.Dst; dst.IsValid() && !dst.Addr().IsPrivate() { if dst := e.ping.Dst; addrIsRoutable(e.ping.Dst) {
if dst.Addr().Is4() { if dst.Addr().Is4() {
if dst != a.selfV4 { if dst != a.selfV4 {
log.Printf("Local IPv4 updated: %s -> %s", a.selfV4, dst) log.Printf("Local IPv4 updated: %s -> %s", a.selfV4, dst)
@@ -56,3 +57,11 @@ func (a *App) onPing(e PingEvent) {
peer.UpdateEndpoints(e.ping.SrcV4, e.ping.SrcV6) peer.UpdateEndpoints(e.ping.SrcV4, e.ping.SrcV6)
} }
func addrIsRoutable(addrPort netip.AddrPort) bool {
if addrPort.Port() == 0 {
return false
}
addr := addrPort.Addr()
return addr.IsGlobalUnicast() && !addr.IsPrivate()
}