This commit is contained in:
jdl
2026-06-11 17:03:57 +02:00
parent 82a6d47bc9
commit ab2837817d
6 changed files with 68 additions and 14 deletions

View File

@@ -14,10 +14,18 @@ import (
const (
hostsFile = "/etc/hosts"
hostsBegin = "# BEGIN vppn "
hostsEnd = "# END vppn "
hostsBegin = "# BEGIN vppn"
hostsEnd = "# END vppn"
)
// hostMarkers returns the begin/end marker lines that delimit the managed
// section for localDomain. The domain is wrapped in parentheses so one domain's
// marker can never be a prefix of another's (e.g. "net" vs "net2") when
// multiple vppn instances share /etc/hosts.
func hostMarkers(localDomain string) (begin, end string) {
return hostsBegin + "(" + localDomain + ")", hostsEnd + "(" + localDomain + ")"
}
// updateHosts rewrites the managed vppn section in /etc/hosts using the
// current peersByIP map. Peers without a Name are skipped.
func (a *App) updateHosts() {
@@ -36,8 +44,7 @@ func updateHosts(hostsPath, localDomain string, peers map[netip.Addr]*Peer) erro
}
defer lockFile.Close()
begin := hostsBegin + localDomain
end := hostsEnd + localDomain
begin, end := hostMarkers(localDomain)
info, err := os.Stat(hostsPath)
if err != nil {