From 9d5ca85424ab25fb8244a6238c780a37e2847e1c Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 10 Mar 2019 19:08:56 +0000 Subject: [PATCH] Add LinkLocalTCPPort option --- CHANGELOG.md | 1 + src/config/config.go | 1 + src/yggdrasil/multicast.go | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae3b42c..b9ec85a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Yggdrasil will now attempt to clean up UNIX admin sockets on startup if left behind by a previous crash - Admin socket `getTunnelRouting` and `setTunnelRouting` calls for enabling and disabling crypto-key routing during runtime - On macOS, Yggdrasil will now try to wake up AWDL on start-up when `awdl0` is a configured multicast interface, to keep it awake after system sleep, and to stop waking it when no longer needed +- Added `LinkLocalTCPPort` option for controlling the port number that link-local TCP listeners will listen on by default when setting up `MulticastInterfaces` ### Changed - The `Listen` configuration statement is now an array instead of a string diff --git a/src/config/config.go b/src/config/config.go index 3c8bbcc..dbccc78 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -22,6 +22,7 @@ type NodeConfig struct { SigningPublicKey string `comment:"Your public signing key. You should not ordinarily need to share\nthis with anyone."` SigningPrivateKey string `comment:"Your private signing key. DO NOT share this with anyone!"` MulticastInterfaces []string `comment:"Regular expressions for which interfaces multicast peer discovery\nshould be enabled on. If none specified, multicast peer discovery is\ndisabled. The default value is .* which uses all interfaces."` + LinkLocalTCPPort uint16 `comment:"The port number to be used for the link-local TCP listeners for the\nconfigured MulticastInterfaces. This option does not affect listeners\nspecified in the Listen option. Unless you plan to firewall link-local\ntraffic, it is best to leave this as the default value of 0."` IfName string `comment:"Local network interface name for TUN/TAP adapter, or \"auto\" to select\nan interface automatically, or \"none\" to run without TUN/TAP."` IfTAPMode bool `comment:"Set local network interface to TAP mode rather than TUN mode if\nsupported by your platform - option will be ignored if not."` IfMTU int `comment:"Maximux Transmission Unit (MTU) size for your local TUN/TAP interface.\nDefault is the largest supported size for your platform. The lowest\npossible value is 1280."` diff --git a/src/yggdrasil/multicast.go b/src/yggdrasil/multicast.go index a29bbc7..dacad27 100644 --- a/src/yggdrasil/multicast.go +++ b/src/yggdrasil/multicast.go @@ -16,12 +16,16 @@ type multicast struct { sock *ipv6.PacketConn groupAddr string listeners map[string]*tcpListener + listenPort uint16 } func (m *multicast) init(core *Core) { m.core = core m.reconfigure = make(chan chan error, 1) m.listeners = make(map[string]*tcpListener) + m.core.configMutex.RLock() + m.listenPort = m.core.config.LinkLocalTCPPort + m.core.configMutex.RUnlock() go func() { for { e := <-m.reconfigure @@ -148,12 +152,14 @@ func (m *multicast) announce() { var listener *tcpListener if l, ok := m.listeners[iface.Name]; !ok || l.listener == nil { // No listener was found - let's create one - listenaddr := fmt.Sprintf("[%s%%%s]:0", addrIP, iface.Name) + listenaddr := fmt.Sprintf("[%s%%%s]:%d", addrIP, iface.Name, m.listenPort) if li, err := m.core.link.tcp.listen(listenaddr); err == nil { m.core.log.Debugln("Started multicasting on", iface.Name) // Store the listener so that we can stop it later if needed m.listeners[iface.Name] = li listener = li + } else { + m.core.log.Warnln("Not multicasting on", iface.Name, "due to error:", err) } } else { // An existing listener was found