mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 00:11:36 +00:00
change multicast config format
This commit is contained in:
parent
2a7a53b6b6
commit
2874ce1327
@ -31,7 +31,7 @@ type NodeConfig struct {
|
|||||||
InterfacePeers map[string][]string `comment:"List of connection strings for outbound peer connections in URI format,\narranged by source interface, e.g. { \"eth0\": [ tls://a.b.c.d:e ] }.\nNote that SOCKS peerings will NOT be affected by this option and should\ngo in the \"Peers\" section instead."`
|
InterfacePeers map[string][]string `comment:"List of connection strings for outbound peer connections in URI format,\narranged by source interface, e.g. { \"eth0\": [ tls://a.b.c.d:e ] }.\nNote that SOCKS peerings will NOT be affected by this option and should\ngo in the \"Peers\" section instead."`
|
||||||
Listen []string `comment:"Listen addresses for incoming connections. You will need to add\nlisteners in order to accept incoming peerings from non-local nodes.\nMulticast peer discovery will work regardless of any listeners set\nhere. Each listener should be specified in URI format as above, e.g.\ntls://0.0.0.0:0 or tls://[::]:0 to listen on all interfaces."`
|
Listen []string `comment:"Listen addresses for incoming connections. You will need to add\nlisteners in order to accept incoming peerings from non-local nodes.\nMulticast peer discovery will work regardless of any listeners set\nhere. Each listener should be specified in URI format as above, e.g.\ntls://0.0.0.0:0 or tls://[::]:0 to listen on all interfaces."`
|
||||||
AdminListen string `comment:"Listen address for admin connections. Default is to listen for local\nconnections either on TCP/9001 or a UNIX socket depending on your\nplatform. Use this value for yggdrasilctl -endpoint=X. To disable\nthe admin socket, use the value \"none\" instead."`
|
AdminListen string `comment:"Listen address for admin connections. Default is to listen for local\nconnections either on TCP/9001 or a UNIX socket depending on your\nplatform. Use this value for yggdrasilctl -endpoint=X. To disable\nthe admin socket, use the value \"none\" instead."`
|
||||||
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."`
|
MulticastInterfaces []MulticastInterfaceConfig `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."`
|
||||||
AllowedPublicKeys []string `comment:"List of peer public keys to allow incoming peering connections\nfrom. If left empty/undefined then all connections will be allowed\nby default. This does not affect outgoing peerings, nor does it\naffect link-local peers discovered via multicast."`
|
AllowedPublicKeys []string `comment:"List of peer public keys to allow incoming peering connections\nfrom. If left empty/undefined then all connections will be allowed\nby default. This does not affect outgoing peerings, nor does it\naffect link-local peers discovered via multicast."`
|
||||||
PublicKey string `comment:"Your public key. Your peers may ask you for this to put\ninto their AllowedPublicKeys configuration."`
|
PublicKey string `comment:"Your public key. Your peers may ask you for this to put\ninto their AllowedPublicKeys configuration."`
|
||||||
PrivateKey string `comment:"Your private key. DO NOT share this with anyone!"`
|
PrivateKey string `comment:"Your private key. DO NOT share this with anyone!"`
|
||||||
@ -42,6 +42,12 @@ type NodeConfig struct {
|
|||||||
NodeInfo map[string]interface{} `comment:"Optional node info. This must be a { \"key\": \"value\", ... } map\nor set as null. This is entirely optional but, if set, is visible\nto the whole network on request."`
|
NodeInfo map[string]interface{} `comment:"Optional node info. This must be a { \"key\": \"value\", ... } map\nor set as null. This is entirely optional but, if set, is visible\nto the whole network on request."`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MulticastInterfaceConfig struct {
|
||||||
|
Regex string
|
||||||
|
Incoming bool
|
||||||
|
Outgoing bool
|
||||||
|
}
|
||||||
|
|
||||||
// NewSigningKeys replaces the signing keypair in the NodeConfig with a new
|
// NewSigningKeys replaces the signing keypair in the NodeConfig with a new
|
||||||
// signing keypair. The signing keys are used by the switch to derive the
|
// signing keypair. The signing keys are used by the switch to derive the
|
||||||
// structure of the spanning tree.
|
// structure of the spanning tree.
|
||||||
|
@ -2,6 +2,8 @@ package defaults
|
|||||||
|
|
||||||
import "github.com/yggdrasil-network/yggdrasil-go/src/config"
|
import "github.com/yggdrasil-network/yggdrasil-go/src/config"
|
||||||
|
|
||||||
|
type MulticastInterfaceConfig = config.MulticastInterfaceConfig
|
||||||
|
|
||||||
// Defines which parameters are expected by default for configuration on a
|
// Defines which parameters are expected by default for configuration on a
|
||||||
// specific platform. These values are populated in the relevant defaults_*.go
|
// specific platform. These values are populated in the relevant defaults_*.go
|
||||||
// for the platform being targeted. They must be set.
|
// for the platform being targeted. They must be set.
|
||||||
@ -13,7 +15,7 @@ type platformDefaultParameters struct {
|
|||||||
DefaultConfigFile string
|
DefaultConfigFile string
|
||||||
|
|
||||||
// Multicast interfaces
|
// Multicast interfaces
|
||||||
DefaultMulticastInterfaces []string
|
DefaultMulticastInterfaces []MulticastInterfaceConfig
|
||||||
|
|
||||||
// TUN/TAP
|
// TUN/TAP
|
||||||
MaximumIfMTU uint64
|
MaximumIfMTU uint64
|
||||||
|
@ -13,9 +13,9 @@ func GetDefaults() platformDefaultParameters {
|
|||||||
DefaultConfigFile: "/etc/yggdrasil.conf",
|
DefaultConfigFile: "/etc/yggdrasil.conf",
|
||||||
|
|
||||||
// Multicast interfaces
|
// Multicast interfaces
|
||||||
DefaultMulticastInterfaces: []string{
|
DefaultMulticastInterfaces: []MulticastInterfaceConfig{
|
||||||
"en.*",
|
{Regex: "en.*", Incoming: true, Outgoing: true},
|
||||||
"bridge.*",
|
{Regex: "bridge.*", Incoming: true, Outgoing: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
// TUN/TAP
|
// TUN/TAP
|
||||||
|
@ -13,8 +13,8 @@ func GetDefaults() platformDefaultParameters {
|
|||||||
DefaultConfigFile: "/usr/local/etc/yggdrasil.conf",
|
DefaultConfigFile: "/usr/local/etc/yggdrasil.conf",
|
||||||
|
|
||||||
// Multicast interfaces
|
// Multicast interfaces
|
||||||
DefaultMulticastInterfaces: []string{
|
DefaultMulticastInterfaces: []MulticastInterfaceConfig{
|
||||||
".*",
|
{Regex: ".*", Incoming: true, Outgoing: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
// TUN/TAP
|
// TUN/TAP
|
||||||
|
@ -13,8 +13,8 @@ func GetDefaults() platformDefaultParameters {
|
|||||||
DefaultConfigFile: "/etc/yggdrasil.conf",
|
DefaultConfigFile: "/etc/yggdrasil.conf",
|
||||||
|
|
||||||
// Multicast interfaces
|
// Multicast interfaces
|
||||||
DefaultMulticastInterfaces: []string{
|
DefaultMulticastInterfaces: []MulticastInterfaceConfig{
|
||||||
".*",
|
{Regex: ".*", Incoming: true, Outgoing: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
// TUN/TAP
|
// TUN/TAP
|
||||||
|
@ -13,8 +13,8 @@ func GetDefaults() platformDefaultParameters {
|
|||||||
DefaultConfigFile: "/etc/yggdrasil.conf",
|
DefaultConfigFile: "/etc/yggdrasil.conf",
|
||||||
|
|
||||||
// Multicast interfaces
|
// Multicast interfaces
|
||||||
DefaultMulticastInterfaces: []string{
|
DefaultMulticastInterfaces: []MulticastInterfaceConfig{
|
||||||
".*",
|
{Regex: ".*", Incoming: true, Outgoing: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
// TUN/TAP
|
// TUN/TAP
|
||||||
|
@ -13,8 +13,8 @@ func GetDefaults() platformDefaultParameters {
|
|||||||
DefaultConfigFile: "/etc/yggdrasil.conf",
|
DefaultConfigFile: "/etc/yggdrasil.conf",
|
||||||
|
|
||||||
// Multicast interfaces
|
// Multicast interfaces
|
||||||
DefaultMulticastInterfaces: []string{
|
DefaultMulticastInterfaces: []MulticastInterfaceConfig{
|
||||||
".*",
|
{Regex: ".*", Incoming: true, Outgoing: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
// TUN/TAP
|
// TUN/TAP
|
||||||
|
@ -13,8 +13,8 @@ func GetDefaults() platformDefaultParameters {
|
|||||||
DefaultConfigFile: "C:\\Program Files\\Yggdrasil\\yggdrasil.conf",
|
DefaultConfigFile: "C:\\Program Files\\Yggdrasil\\yggdrasil.conf",
|
||||||
|
|
||||||
// Multicast interfaces
|
// Multicast interfaces
|
||||||
DefaultMulticastInterfaces: []string{
|
DefaultMulticastInterfaces: []MulticastInterfaceConfig{
|
||||||
".*",
|
{Regex: ".*", Incoming: true, Outgoing: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
// TUN/TAP
|
// TUN/TAP
|
||||||
|
@ -40,6 +40,8 @@ type Multicast struct {
|
|||||||
type interfaceInfo struct {
|
type interfaceInfo struct {
|
||||||
iface net.Interface
|
iface net.Interface
|
||||||
addrs []net.Addr
|
addrs []net.Addr
|
||||||
|
incoming bool
|
||||||
|
outgoing bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type listenerInfo struct {
|
type listenerInfo struct {
|
||||||
@ -136,18 +138,16 @@ func (m *Multicast) _stop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Multicast) _updateInterfaces() {
|
func (m *Multicast) _updateInterfaces() {
|
||||||
interfaces := make(map[string]interfaceInfo)
|
interfaces := m.getAllowedInterfaces()
|
||||||
intfs := m.getAllowedInterfaces()
|
for name, info := range interfaces {
|
||||||
for _, intf := range intfs {
|
addrs, err := info.iface.Addrs()
|
||||||
addrs, err := intf.Addrs()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.log.Warnf("Failed up get addresses for interface %s: %s", intf.Name, err)
|
m.log.Warnf("Failed up get addresses for interface %s: %s", name, err)
|
||||||
|
delete(interfaces, name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
interfaces[intf.Name] = interfaceInfo{
|
info.addrs = addrs
|
||||||
iface: intf,
|
interfaces[name] = info
|
||||||
addrs: addrs,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
m._interfaces = interfaces
|
m._interfaces = interfaces
|
||||||
}
|
}
|
||||||
@ -163,10 +163,10 @@ func (m *Multicast) Interfaces() map[string]net.Interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getAllowedInterfaces returns the currently known/enabled multicast interfaces.
|
// getAllowedInterfaces returns the currently known/enabled multicast interfaces.
|
||||||
func (m *Multicast) getAllowedInterfaces() map[string]net.Interface {
|
func (m *Multicast) getAllowedInterfaces() map[string]interfaceInfo {
|
||||||
interfaces := make(map[string]net.Interface)
|
interfaces := make(map[string]interfaceInfo)
|
||||||
// Get interface expressions from config
|
// Get interface expressions from config
|
||||||
exprs := m.config.MulticastInterfaces
|
ifcfgs := m.config.MulticastInterfaces
|
||||||
// Ask the system for network interfaces
|
// Ask the system for network interfaces
|
||||||
allifaces, err := net.Interfaces()
|
allifaces, err := net.Interfaces()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -188,15 +188,23 @@ func (m *Multicast) getAllowedInterfaces() map[string]net.Interface {
|
|||||||
// Ignore point-to-point interfaces
|
// Ignore point-to-point interfaces
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, expr := range exprs {
|
for _, ifcfg := range ifcfgs {
|
||||||
// Compile each regular expression
|
// Compile each regular expression
|
||||||
e, err := regexp.Compile(expr)
|
e, err := regexp.Compile(ifcfg.Regex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
// Does the interface match the regular expression? Store it if so
|
// Does the interface match the regular expression? Store it if so
|
||||||
if e.MatchString(iface.Name) {
|
if e.MatchString(iface.Name) {
|
||||||
interfaces[iface.Name] = iface
|
if ifcfg.Incoming || ifcfg.Outgoing {
|
||||||
|
info := interfaceInfo{
|
||||||
|
iface: iface,
|
||||||
|
incoming: ifcfg.Incoming,
|
||||||
|
outgoing: ifcfg.Outgoing,
|
||||||
|
}
|
||||||
|
interfaces[iface.Name] = info
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -272,8 +280,13 @@ func (m *Multicast) _announce() {
|
|||||||
if !addrIP.IsLinkLocalUnicast() {
|
if !addrIP.IsLinkLocalUnicast() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Join the multicast group
|
if info.outgoing {
|
||||||
|
// Join the multicast group, so we can listen for advertisements to open outgoing connections
|
||||||
_ = m.sock.JoinGroup(&iface, groupAddr)
|
_ = m.sock.JoinGroup(&iface, groupAddr)
|
||||||
|
}
|
||||||
|
if !info.incoming {
|
||||||
|
break // Don't send multicast advertisements if we don't accept incoming connections
|
||||||
|
}
|
||||||
// Try and see if we already have a TCP listener for this interface
|
// Try and see if we already have a TCP listener for this interface
|
||||||
var info *listenerInfo
|
var info *listenerInfo
|
||||||
if nfo, ok := m.listeners[iface.Name]; !ok || nfo.listener.Listener == nil {
|
if nfo, ok := m.listeners[iface.Name]; !ok || nfo.listener.Listener == nil {
|
||||||
@ -378,7 +391,7 @@ func (m *Multicast) listen() {
|
|||||||
phony.Block(m, func() {
|
phony.Block(m, func() {
|
||||||
interfaces = m._interfaces
|
interfaces = m._interfaces
|
||||||
})
|
})
|
||||||
if _, ok := interfaces[from.Zone]; ok {
|
if info, ok := interfaces[from.Zone]; ok && info.outgoing {
|
||||||
addr.Zone = ""
|
addr.Zone = ""
|
||||||
pin := fmt.Sprintf("/?key=%s", hex.EncodeToString(key))
|
pin := fmt.Sprintf("/?key=%s", hex.EncodeToString(key))
|
||||||
u, err := url.Parse("tls://" + addr.String() + pin)
|
u, err := url.Parse("tls://" + addr.String() + pin)
|
||||||
|
Loading…
Reference in New Issue
Block a user