mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-09-26 21:01:14 +08:00
config: make host sync domain configurable
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
This commit is contained in:
@@ -104,6 +104,9 @@ rtsync:
|
||||
hsync:
|
||||
enabled: true
|
||||
|
||||
# The domain name which is appended to each of the peer host names
|
||||
domain: wg-local
|
||||
|
||||
|
||||
## Peer discovery
|
||||
#
|
||||
|
@@ -72,6 +72,8 @@ type AutoConfigSettings struct {
|
||||
|
||||
type HostSyncSettings struct {
|
||||
Enabled bool `koanf:"enabled,omitempty"`
|
||||
|
||||
Domain string `koanf:"domain,omitempty"`
|
||||
}
|
||||
|
||||
type PeerDiscoverySettings struct {
|
||||
|
@@ -41,7 +41,7 @@ func NewFeatures(w *watcher.Watcher, cfg *config.Config, c *wgctrl.Client, b sig
|
||||
}
|
||||
|
||||
if cfg.DefaultInterfaceSettings.HostSync.Enabled {
|
||||
feats = append(feats, hsync.New(w))
|
||||
feats = append(feats, hsync.New(w, cfg.DefaultInterfaceSettings.HostSync.Domain))
|
||||
}
|
||||
|
||||
if cfg.DefaultInterfaceSettings.EndpointDisc.Enabled {
|
||||
|
@@ -20,12 +20,19 @@ const (
|
||||
)
|
||||
|
||||
type HostsSync struct {
|
||||
domain string
|
||||
|
||||
watcher *watcher.Watcher
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func New(w *watcher.Watcher) *HostsSync {
|
||||
func New(w *watcher.Watcher, d string) *HostsSync {
|
||||
if d != "" && !strings.HasPrefix(d, ".") {
|
||||
d = "." + d
|
||||
}
|
||||
|
||||
hs := &HostsSync{
|
||||
domain: d,
|
||||
watcher: w,
|
||||
logger: zap.L().Named("hsync"),
|
||||
}
|
||||
@@ -53,8 +60,10 @@ func (hs *HostsSync) Hosts() []Host {
|
||||
pkName := p.PublicKey().String()[:8]
|
||||
|
||||
h := Host{
|
||||
IP: p.PublicKey().IPv6Address().IP,
|
||||
Names: []string{pkName},
|
||||
IP: p.PublicKey().IPv6Address().IP,
|
||||
Names: []string{
|
||||
pkName + hs.domain,
|
||||
},
|
||||
Comment: fmt.Sprintf("%s: ifname=%s, ifindex=%d, pk=%s", hostsCommentPrefix,
|
||||
p.Interface.KernelDevice.Name(),
|
||||
p.Interface.KernelDevice.Index(),
|
||||
@@ -62,7 +71,7 @@ func (hs *HostsSync) Hosts() []Host {
|
||||
}
|
||||
|
||||
if p.Name != "" {
|
||||
h.Names = append(h.Names, p.Name)
|
||||
h.Names = append(h.Names, p.Name+hs.domain)
|
||||
}
|
||||
|
||||
hosts = append(hosts, h)
|
||||
|
Reference in New Issue
Block a user