From a7c8be4d69b644dce77b7caa06d40c511a09bbb5 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Thu, 5 Jul 2018 23:07:01 -0500 Subject: [PATCH 01/17] base backpressure decisions on queue size in bytes, instead of packet counts --- src/yggdrasil/switch.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index 5b72620..e7b25a2 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -595,7 +595,7 @@ type switch_packetInfo struct { // Used to keep track of buffered packets type switch_buffer struct { packets []switch_packetInfo // Currently buffered packets, which may be dropped if it grows too large - count uint64 // Total queue size, including dropped packets + size uint64 // Total queue size in bytes } func (b *switch_buffer) dropTimedOut() { @@ -603,8 +603,10 @@ func (b *switch_buffer) dropTimedOut() { const timeout = 25 * time.Millisecond now := time.Now() for len(b.packets) > 0 && now.Sub(b.packets[0].time) > timeout { - util_putBytes(b.packets[0].bytes) - b.packets = b.packets[1:] + var packet switch_packetInfo + packet, b.packets = b.packets[0], b.packets[1:] + b.size -= uint64(len(packet.bytes)) + util_putBytes(packet.bytes) } } @@ -629,9 +631,9 @@ func (t *switchTable) handleIdle(port switchPort, buffs map[string]switch_buffer buffs[streamID] = buf packet := buf.packets[0] coords := switch_getPacketCoords(packet.bytes) - if (bestSize == 0 || buf.count < bestSize) && t.portIsCloser(coords, port) { + if (bestSize == 0 || buf.size < bestSize) && t.portIsCloser(coords, port) { best = streamID - bestSize = buf.count + bestSize = buf.size } } if bestSize != 0 { @@ -639,7 +641,7 @@ func (t *switchTable) handleIdle(port switchPort, buffs map[string]switch_buffer var packet switch_packetInfo // TODO decide if this should be LIFO or FIFO packet, buf.packets = buf.packets[0], buf.packets[1:] - buf.count-- + buf.size -= uint64(len(packet.bytes)) if len(buf.packets) == 0 { delete(buffs, best) } else { @@ -658,16 +660,16 @@ func (t *switchTable) doWorker() { idle := make(map[switchPort]struct{}) // this is to deduplicate things for { select { - case packet := <-t.packetIn: + case bytes := <-t.packetIn: // Try to send it somewhere (or drop it if it's corrupt or at a dead end) - if !t.handleIn(packet, idle) { + if !t.handleIn(bytes, idle) { // There's nobody free to take it right now, so queue it for later - streamID := switch_getPacketStreamID(packet) + packet := switch_packetInfo{bytes, time.Now()} + streamID := switch_getPacketStreamID(packet.bytes) buf := buffs[streamID] buf.dropTimedOut() - pinfo := switch_packetInfo{packet, time.Now()} - buf.packets = append(buf.packets, pinfo) - buf.count++ + buf.packets = append(buf.packets, packet) + buf.size += uint64(len(packet.bytes)) buffs[streamID] = buf } case port := <-t.idleIn: From 7da4967f5e67b3110be27dc8f49f9c9c7e915a75 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Thu, 5 Jul 2018 23:39:41 -0500 Subject: [PATCH 02/17] Limit maximum queue size to 4 MB --- src/yggdrasil/switch.go | 71 ++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index e7b25a2..20b5783 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -598,37 +598,53 @@ type switch_buffer struct { size uint64 // Total queue size in bytes } -func (b *switch_buffer) dropTimedOut() { - // TODO figure out what timeout makes sense - const timeout = 25 * time.Millisecond - now := time.Now() - for len(b.packets) > 0 && now.Sub(b.packets[0].time) > timeout { - var packet switch_packetInfo - packet, b.packets = b.packets[0], b.packets[1:] - b.size -= uint64(len(packet.bytes)) - util_putBytes(packet.bytes) +type switch_buffers struct { + bufs map[string]switch_buffer // Buffers indexed by StreamID + size uint64 // Total size of all buffers, in bytes +} + +func (b *switch_buffers) cleanup(t *switchTable) { + remove := func(streamID string) { + // Helper function to drop a queue + buf := b.bufs[streamID] + for _, packet := range buf.packets { + util_putBytes(packet.bytes) + } + b.size -= buf.size + delete(b.bufs, streamID) + } + for streamID, buf := range b.bufs { + // Remove queues for which we have no next hop + packet := buf.packets[0] + coords := switch_getPacketCoords(packet.bytes) + if t.selfIsClosest(coords) { + remove(streamID) + } + } + const maxSize = 4 * 1048576 // Maximum 4 MB + for b.size > maxSize { + // Drop a random queue + for streamID := range b.bufs { + remove(streamID) + break + } } } // Handles incoming idle notifications // Loops over packets and sends the newest one that's OK for this peer to send // Returns true if the peer is no longer idle, false if it should be added to the idle list -func (t *switchTable) handleIdle(port switchPort, buffs map[string]switch_buffer) bool { +func (t *switchTable) handleIdle(port switchPort, bufs *switch_buffers) bool { to := t.core.peers.getPorts()[port] if to == nil { return true } var best string var bestSize uint64 - for streamID, buf := range buffs { + bufs.cleanup(t) + for streamID, buf := range bufs.bufs { // Filter over the streams that this node is closer to // Keep the one with the smallest queue - buf.dropTimedOut() - if len(buf.packets) == 0 { - delete(buffs, streamID) - continue - } - buffs[streamID] = buf packet := buf.packets[0] coords := switch_getPacketCoords(packet.bytes) if (bestSize == 0 || buf.size < bestSize) && t.portIsCloser(coords, port) { @@ -637,15 +653,16 @@ func (t *switchTable) handleIdle(port switchPort, buffs map[string]switch_buffer } } if bestSize != 0 { - buf := buffs[best] + buf := bufs.bufs[best] var packet switch_packetInfo // TODO decide if this should be LIFO or FIFO packet, buf.packets = buf.packets[0], buf.packets[1:] buf.size -= uint64(len(packet.bytes)) + bufs.size -= uint64(len(packet.bytes)) if len(buf.packets) == 0 { - delete(buffs, best) + delete(bufs.bufs, best) } else { - buffs[best] = buf + bufs.bufs[best] = buf } to.sendPacket(packet.bytes) return true @@ -656,8 +673,9 @@ func (t *switchTable) handleIdle(port switchPort, buffs map[string]switch_buffer // The switch worker does routing lookups and sends packets to where they need to be func (t *switchTable) doWorker() { - buffs := make(map[string]switch_buffer) // Packets per PacketStreamID (string) - idle := make(map[switchPort]struct{}) // this is to deduplicate things + var bufs switch_buffers + bufs.bufs = make(map[string]switch_buffer) // Packets per PacketStreamID (string) + idle := make(map[switchPort]struct{}) // this is to deduplicate things for { select { case bytes := <-t.packetIn: @@ -666,15 +684,16 @@ func (t *switchTable) doWorker() { // There's nobody free to take it right now, so queue it for later packet := switch_packetInfo{bytes, time.Now()} streamID := switch_getPacketStreamID(packet.bytes) - buf := buffs[streamID] - buf.dropTimedOut() + buf := bufs.bufs[streamID] buf.packets = append(buf.packets, packet) buf.size += uint64(len(packet.bytes)) - buffs[streamID] = buf + bufs.size += uint64(len(packet.bytes)) + bufs.bufs[streamID] = buf + bufs.cleanup(t) } case port := <-t.idleIn: // Try to find something to send to this peer - if !t.handleIdle(port, buffs) { + if !t.handleIdle(port, &bufs) { // Didn't find anything ready to send yet, so stay idle idle[port] = struct{}{} } From 1a65c065d07f8034c9162740cc81ad9d4bbe9420 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Thu, 5 Jul 2018 23:56:37 -0500 Subject: [PATCH 03/17] prioritize sending from small queues that have been blocked for a long time --- src/yggdrasil/switch.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index 20b5783..1a0e781 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -640,19 +640,21 @@ func (t *switchTable) handleIdle(port switchPort, bufs *switch_buffers) bool { return true } var best string - var bestSize uint64 + var bestPriority float64 bufs.cleanup(t) + now := time.Now() for streamID, buf := range bufs.bufs { // Filter over the streams that this node is closer to // Keep the one with the smallest queue packet := buf.packets[0] coords := switch_getPacketCoords(packet.bytes) - if (bestSize == 0 || buf.size < bestSize) && t.portIsCloser(coords, port) { + priority := float64(now.Sub(packet.time)) / float64(buf.size) + if priority > bestPriority && t.portIsCloser(coords, port) { best = streamID - bestSize = buf.size + bestPriority = priority } } - if bestSize != 0 { + if bestPriority != 0 { buf := bufs.bufs[best] var packet switch_packetInfo // TODO decide if this should be LIFO or FIFO From e6a47f705da746372e53620132b37e0f43101525 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Fri, 6 Jul 2018 00:11:36 -0500 Subject: [PATCH 04/17] when dropping a queue, select one at random based on queue size in bytes --- src/yggdrasil/switch.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index 1a0e781..f47526f 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -12,6 +12,7 @@ package yggdrasil // A little annoying to do with constant changes from backpressure import ( + "math/rand" "sync" "sync/atomic" "time" @@ -624,7 +625,13 @@ func (b *switch_buffers) cleanup(t *switchTable) { const maxSize = 4 * 1048576 // Maximum 4 MB for b.size > maxSize { // Drop a random queue - for streamID := range b.bufs { + target := rand.Uint64() % b.size + var size uint64 // running total + for streamID, buf := range b.bufs { + size += buf.size + if size < target { + continue + } remove(streamID) break } From ad5dc9ea87afbde2aee36c9a7f377460105a8589 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Fri, 6 Jul 2018 00:55:00 -0500 Subject: [PATCH 05/17] Drop 1 packet instead of a whole queue when overflowing --- src/yggdrasil/switch.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index f47526f..ea52fdc 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -605,21 +605,16 @@ type switch_buffers struct { } func (b *switch_buffers) cleanup(t *switchTable) { - remove := func(streamID string) { - // Helper function to drop a queue - buf := b.bufs[streamID] - for _, packet := range buf.packets { - util_putBytes(packet.bytes) - } - b.size -= buf.size - delete(b.bufs, streamID) - } for streamID, buf := range b.bufs { // Remove queues for which we have no next hop packet := buf.packets[0] coords := switch_getPacketCoords(packet.bytes) if t.selfIsClosest(coords) { - remove(streamID) + for _, packet := range buf.packets { + util_putBytes(packet.bytes) + } + b.size -= buf.size + delete(b.bufs, streamID) } } const maxSize = 4 * 1048576 // Maximum 4 MB @@ -632,7 +627,13 @@ func (b *switch_buffers) cleanup(t *switchTable) { if size < target { continue } - remove(streamID) + var packet switch_packetInfo + packet, buf.packets = buf.packets[0], buf.packets[1:] + buf.size -= uint64(len(packet.bytes)) + b.size -= uint64(len(packet.bytes)) + if len(buf.packets) == 0 { + delete(b.bufs, streamID) + } break } } From ba4047b51a7db87a0e13df7221f39a6fc66e048b Mon Sep 17 00:00:00 2001 From: Arceliar Date: Fri, 6 Jul 2018 17:27:04 -0500 Subject: [PATCH 06/17] correctly update buffer sizs when buffers overflow, and returned freed packets to the byte store --- src/yggdrasil/switch.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index ea52fdc..6fe50bf 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -631,8 +631,12 @@ func (b *switch_buffers) cleanup(t *switchTable) { packet, buf.packets = buf.packets[0], buf.packets[1:] buf.size -= uint64(len(packet.bytes)) b.size -= uint64(len(packet.bytes)) + util_putBytes(packet.bytes) if len(buf.packets) == 0 { delete(b.bufs, streamID) + } else { + // Need to update the map, since buf was retrieved by value + b.bufs[streamID] = buf } break } @@ -672,6 +676,7 @@ func (t *switchTable) handleIdle(port switchPort, bufs *switch_buffers) bool { if len(buf.packets) == 0 { delete(bufs.bufs, best) } else { + // Need to update the map, since buf was retrieved by value bufs.bufs[best] = buf } to.sendPacket(packet.bytes) From cd6030ec8f9977fb5e151d719ddd8986f8b60584 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 7 Jul 2018 11:22:49 +0100 Subject: [PATCH 07/17] Add support for UNIX domain admin sockets and specifying URIs in AdminListen --- src/yggdrasil/admin.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index bd5eb0c..e02bf9e 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -229,13 +229,26 @@ func (a *admin) start() error { // listen is run by start and manages API connections. func (a *admin) listen() { - l, err := net.Listen("tcp", a.listenaddr) + var l net.Listener + u, err := url.Parse(a.listenaddr) + if err == nil { + switch strings.ToLower(u.Scheme) { + case "unix": + l, err = net.Listen("unix", a.listenaddr[7:]) + case "tcp": + l, err = net.Listen("tcp", u.Host) + default: + err = errors.New("protocol not supported") + } + } else { + l, err = net.Listen("tcp", a.listenaddr) + } if err != nil { a.core.log.Printf("Admin socket failed to listen: %v", err) os.Exit(1) } + a.core.log.Printf("%s admin socket listening on %s", strings.ToUpper(l.Addr().Network()), l.Addr().String()) defer l.Close() - a.core.log.Printf("Admin socket listening on %s", l.Addr().String()) for { conn, err := l.Accept() if err == nil { From 047b7d95a15db5726035617b2bdf2789635d09da Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 7 Jul 2018 11:25:01 +0100 Subject: [PATCH 08/17] Add support for UNIX domain admin sockets to yggdrasilctl --- yggdrasilctl.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/yggdrasilctl.go b/yggdrasilctl.go index 5cea774..25998e3 100644 --- a/yggdrasilctl.go +++ b/yggdrasilctl.go @@ -1,9 +1,11 @@ package main +import "errors" import "flag" import "fmt" import "strings" import "net" +import "net/url" import "sort" import "encoding/json" import "strconv" @@ -12,20 +14,34 @@ import "os" type admin_info map[string]interface{} func main() { - server := flag.String("endpoint", "localhost:9001", "Admin socket endpoint") + server := flag.String("endpoint", "tcp://localhost:9001", "Admin socket endpoint") injson := flag.Bool("json", false, "Output in JSON format") flag.Parse() args := flag.Args() if len(args) == 0 { - fmt.Println("usage:", os.Args[0], "[-endpoint=localhost:9001] [-json] command [key=value] [...]") + fmt.Println("usage:", os.Args[0], "[-endpoint=proto://server] [-json] command [key=value] [...]") fmt.Println("example:", os.Args[0], "getPeers") fmt.Println("example:", os.Args[0], "setTunTap name=auto mtu=1500 tap_mode=false") - fmt.Println("example:", os.Args[0], "-endpoint=localhost:9001 getDHT") + fmt.Println("example:", os.Args[0], "-endpoint=tcp://localhost:9001 getDHT") + fmt.Println("example:", os.Args[0], "-endpoint=unix:///var/run/ygg.sock getDHT") return } - conn, err := net.Dial("tcp", *server) + var conn net.Conn + u, err := url.Parse(*server) + if err == nil { + switch strings.ToLower(u.Scheme) { + case "unix": + conn, err = net.Dial("unix", (*server)[7:]) + case "tcp": + conn, err = net.Dial("tcp", u.Host) + default: + err = errors.New("protocol not supported") + } + } else { + conn, err = net.Dial("tcp", *server) + } if err != nil { panic(err) } From 171e1e7823a502db250e5e878f2251783fa8b15f Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 7 Jul 2018 11:28:50 +0100 Subject: [PATCH 09/17] Update default AdminListen to URI format --- yggdrasil.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yggdrasil.go b/yggdrasil.go index 20b4aa0..e4c63d7 100644 --- a/yggdrasil.go +++ b/yggdrasil.go @@ -53,7 +53,7 @@ func generateConfig(isAutoconf bool) *nodeConfig { r1 := rand.New(rand.NewSource(time.Now().UnixNano())) cfg.Listen = fmt.Sprintf("[::]:%d", r1.Intn(65534-32768)+32768) } - cfg.AdminListen = "localhost:9001" + cfg.AdminListen = "tcp://localhost:9001" cfg.EncryptionPublicKey = hex.EncodeToString(bpub[:]) cfg.EncryptionPrivateKey = hex.EncodeToString(bpriv[:]) cfg.SigningPublicKey = hex.EncodeToString(spub[:]) From 1692bd98fd78a452a37e6c12d71f4da37c536ef2 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 7 Jul 2018 12:08:52 +0100 Subject: [PATCH 10/17] Centralise platform defaults into the 'defaults' package --- src/yggdrasil/admin.go | 8 +++++--- src/yggdrasil/core.go | 14 ++++++++++---- src/yggdrasil/defaults/defaults.go | 15 +++++++++++++++ src/yggdrasil/defaults/defaults_darwin.go | 18 ++++++++++++++++++ src/yggdrasil/defaults/defaults_freebsd.go | 18 ++++++++++++++++++ src/yggdrasil/defaults/defaults_linux.go | 18 ++++++++++++++++++ src/yggdrasil/defaults/defaults_netbsd.go | 18 ++++++++++++++++++ src/yggdrasil/defaults/defaults_openbsd.go | 18 ++++++++++++++++++ src/yggdrasil/defaults/defaults_other.go | 18 ++++++++++++++++++ src/yggdrasil/defaults/defaults_windows.go | 18 ++++++++++++++++++ src/yggdrasil/tun.go | 18 +++++------------- src/yggdrasil/tun_darwin.go | 11 ----------- src/yggdrasil/tun_freebsd.go | 12 ------------ src/yggdrasil/tun_linux.go | 11 ----------- src/yggdrasil/tun_netbsd.go | 12 ------------ src/yggdrasil/tun_openbsd.go | 12 ------------ src/yggdrasil/tun_other.go | 11 ----------- src/yggdrasil/tun_windows.go | 11 ----------- yggdrasil.go | 9 +++++---- yggdrasilctl.go | 4 +++- 20 files changed, 169 insertions(+), 105 deletions(-) create mode 100644 src/yggdrasil/defaults/defaults.go create mode 100644 src/yggdrasil/defaults/defaults_darwin.go create mode 100644 src/yggdrasil/defaults/defaults_freebsd.go create mode 100644 src/yggdrasil/defaults/defaults_linux.go create mode 100644 src/yggdrasil/defaults/defaults_netbsd.go create mode 100644 src/yggdrasil/defaults/defaults_openbsd.go create mode 100644 src/yggdrasil/defaults/defaults_other.go create mode 100644 src/yggdrasil/defaults/defaults_windows.go delete mode 100644 src/yggdrasil/tun_freebsd.go delete mode 100644 src/yggdrasil/tun_netbsd.go delete mode 100644 src/yggdrasil/tun_openbsd.go diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index bd5eb0c..f486468 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -13,6 +13,8 @@ import ( "strings" "sync/atomic" "time" + + "yggdrasil/defaults" ) // TODO: Add authentication @@ -155,15 +157,15 @@ func (a *admin) init(c *Core, listenaddr string) { }) a.addHandler("setTunTap", []string{"name", "[tap_mode]", "[mtu]"}, func(in admin_info) (admin_info, error) { // Set sane defaults - iftapmode := getDefaults().defaultIfTAPMode - ifmtu := getDefaults().defaultIfMTU + iftapmode := defaults.GetDefaults().DefaultIfTAPMode + ifmtu := defaults.GetDefaults().DefaultIfMTU // Has TAP mode been specified? if tap, ok := in["tap_mode"]; ok { iftapmode = tap.(bool) } // Check we have enough params for MTU if mtu, ok := in["mtu"]; ok { - if mtu.(float64) >= 1280 && ifmtu <= getDefaults().maximumIfMTU { + if mtu.(float64) >= 1280 && ifmtu <= defaults.GetDefaults().MaximumIfMTU { ifmtu = int(in["mtu"].(float64)) } } diff --git a/src/yggdrasil/core.go b/src/yggdrasil/core.go index 6d130d8..28ca8f3 100644 --- a/src/yggdrasil/core.go +++ b/src/yggdrasil/core.go @@ -9,6 +9,7 @@ import ( "regexp" "yggdrasil/config" + "yggdrasil/defaults" ) // The Core object represents the Yggdrasil node. You should create a Core @@ -197,26 +198,31 @@ func (c *Core) AddAllowedEncryptionPublicKey(boxStr string) error { return c.admin.addAllowedEncryptionPublicKey(boxStr) } +// Gets the default admin listen address for your platform. +func (c *Core) GetAdminDefaultListen() string { + return defaults.GetDefaults().DefaultAdminListen +} + // Gets the default TUN/TAP interface name for your platform. func (c *Core) GetTUNDefaultIfName() string { - return getDefaults().defaultIfName + return defaults.GetDefaults().DefaultIfName } // Gets the default TUN/TAP interface MTU for your platform. This can be as high // as 65535, depending on platform, but is never lower than 1280. func (c *Core) GetTUNDefaultIfMTU() int { - return getDefaults().defaultIfMTU + return defaults.GetDefaults().DefaultIfMTU } // Gets the maximum supported TUN/TAP interface MTU for your platform. This // can be as high as 65535, depending on platform, but is never lower than 1280. func (c *Core) GetTUNMaximumIfMTU() int { - return getDefaults().maximumIfMTU + return defaults.GetDefaults().MaximumIfMTU } // Gets the default TUN/TAP interface mode for your platform. func (c *Core) GetTUNDefaultIfTAPMode() bool { - return getDefaults().defaultIfTAPMode + return defaults.GetDefaults().DefaultIfTAPMode } // Gets the current TUN/TAP interface name. diff --git a/src/yggdrasil/defaults/defaults.go b/src/yggdrasil/defaults/defaults.go new file mode 100644 index 0000000..6145539 --- /dev/null +++ b/src/yggdrasil/defaults/defaults.go @@ -0,0 +1,15 @@ +package defaults + +// Defines which parameters are expected by default for configuration on a +// specific platform. These values are populated in the relevant defaults_*.go +// for the platform being targeted. They must be set. +type platformDefaultParameters struct { + // Admin socket + DefaultAdminListen string + + // TUN/TAP + MaximumIfMTU int + DefaultIfMTU int + DefaultIfName string + DefaultIfTAPMode bool +} diff --git a/src/yggdrasil/defaults/defaults_darwin.go b/src/yggdrasil/defaults/defaults_darwin.go new file mode 100644 index 0000000..b82660f --- /dev/null +++ b/src/yggdrasil/defaults/defaults_darwin.go @@ -0,0 +1,18 @@ +// +build darwin + +package defaults + +// Sane defaults for the macOS/Darwin platform. The "default" options may be +// may be replaced by the running configuration. +func GetDefaults() platformDefaultParameters { + return platformDefaultParameters{ + // Admin + DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + + // TUN/TAP + MaximumIfMTU: 65535, + DefaultIfMTU: 65535, + DefaultIfName: "auto", + DefaultIfTAPMode: false, + } +} diff --git a/src/yggdrasil/defaults/defaults_freebsd.go b/src/yggdrasil/defaults/defaults_freebsd.go new file mode 100644 index 0000000..4ba7fac --- /dev/null +++ b/src/yggdrasil/defaults/defaults_freebsd.go @@ -0,0 +1,18 @@ +// +build freebsd + +package defaults + +// Sane defaults for the BSD platforms. The "default" options may be +// may be replaced by the running configuration. +func GetDefaults() platformDefaultParameters { + return platformDefaultParameters{ + // Admin + DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + + // TUN/TAP + MaximumIfMTU: 32767, + DefaultIfMTU: 32767, + DefaultIfName: "/dev/tap0", + DefaultIfTAPMode: true, + } +} diff --git a/src/yggdrasil/defaults/defaults_linux.go b/src/yggdrasil/defaults/defaults_linux.go new file mode 100644 index 0000000..4572f3c --- /dev/null +++ b/src/yggdrasil/defaults/defaults_linux.go @@ -0,0 +1,18 @@ +// +build linux + +package defaults + +// Sane defaults for the Linux platform. The "default" options may be +// may be replaced by the running configuration. +func GetDefaults() platformDefaultParameters { + return platformDefaultParameters{ + // Admin + DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + + // TUN/TAP + MaximumIfMTU: 65535, + DefaultIfMTU: 65535, + DefaultIfName: "auto", + DefaultIfTAPMode: false, + } +} diff --git a/src/yggdrasil/defaults/defaults_netbsd.go b/src/yggdrasil/defaults/defaults_netbsd.go new file mode 100644 index 0000000..d9f3b4d --- /dev/null +++ b/src/yggdrasil/defaults/defaults_netbsd.go @@ -0,0 +1,18 @@ +// +build freebsd + +package defaults + +// Sane defaults for the BSD platforms. The "default" options may be +// may be replaced by the running configuration. +func GetDefaults() platformDefaultParameters { + return platformDefaultParameters{ + // Admin + DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + + // TUN/TAP + MaximumIfMTU: 9000, + DefaultIfMTU: 9000, + DefaultIfName: "/dev/tap0", + DefaultIfTAPMode: true, + } +} diff --git a/src/yggdrasil/defaults/defaults_openbsd.go b/src/yggdrasil/defaults/defaults_openbsd.go new file mode 100644 index 0000000..1b3e0c0 --- /dev/null +++ b/src/yggdrasil/defaults/defaults_openbsd.go @@ -0,0 +1,18 @@ +// +build freebsd + +package defaults + +// Sane defaults for the BSD platforms. The "default" options may be +// may be replaced by the running configuration. +func GetDefaults() platformDefaultParameters { + return platformDefaultParameters{ + // Admin + DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + + // TUN/TAP + MaximumIfMTU: 16384, + DefaultIfMTU: 16384, + DefaultIfName: "/dev/tap0", + DefaultIfTAPMode: true, + } +} diff --git a/src/yggdrasil/defaults/defaults_other.go b/src/yggdrasil/defaults/defaults_other.go new file mode 100644 index 0000000..29e71e8 --- /dev/null +++ b/src/yggdrasil/defaults/defaults_other.go @@ -0,0 +1,18 @@ +// +build !linux,!darwin,!windows,!openbsd,!freebsd,!netbsd + +package defaults + +// Sane defaults for the other platforms. The "default" options may be +// may be replaced by the running configuration. +func GetDefaults() platformDefaultParameters { + return platformDefaultParameters{ + // Admin + DefaultAdminListen: "tcp://localhost:9001", + + // TUN/TAP + MaximumIfMTU: 65535, + DefaultIfMTU: 65535, + DefaultIfName: "none", + DefaultIfTAPMode: false, + } +} diff --git a/src/yggdrasil/defaults/defaults_windows.go b/src/yggdrasil/defaults/defaults_windows.go new file mode 100644 index 0000000..91e9e0e --- /dev/null +++ b/src/yggdrasil/defaults/defaults_windows.go @@ -0,0 +1,18 @@ +// +build windows + +package defaults + +// Sane defaults for the Windows platform. The "default" options may be +// may be replaced by the running configuration. +func GetDefaults() platformDefaultParameters { + return platformDefaultParameters{ + // Admin + DefaultAdminListen: "tcp://localhost:9001", + + // TUN/TAP + MaximumIfMTU: 65535, + DefaultIfMTU: 65535, + DefaultIfName: "auto", + DefaultIfTAPMode: true, + } +} diff --git a/src/yggdrasil/tun.go b/src/yggdrasil/tun.go index 94adbcb..cbbcdea 100644 --- a/src/yggdrasil/tun.go +++ b/src/yggdrasil/tun.go @@ -3,6 +3,8 @@ package yggdrasil // This manages the tun driver to send/recv packets to/from applications import ( + "yggdrasil/defaults" + "github.com/songgao/packets/ethernet" "github.com/yggdrasil-network/water" ) @@ -20,21 +22,11 @@ type tunDevice struct { iface *water.Interface } -// Defines which parameters are expected by default for a TUN/TAP adapter on a -// specific platform. These values are populated in the relevant tun_*.go for -// the platform being targeted. They must be set. -type tunDefaultParameters struct { - maximumIfMTU int - defaultIfMTU int - defaultIfName string - defaultIfTAPMode bool -} - // Gets the maximum supported MTU for the platform based on the defaults in -// getDefaults(). +// defaults.GetDefaults(). func getSupportedMTU(mtu int) int { - if mtu > getDefaults().maximumIfMTU { - return getDefaults().maximumIfMTU + if mtu > defaults.GetDefaults().MaximumIfMTU { + return defaults.GetDefaults().MaximumIfMTU } return mtu } diff --git a/src/yggdrasil/tun_darwin.go b/src/yggdrasil/tun_darwin.go index ff85aa4..e49ab52 100644 --- a/src/yggdrasil/tun_darwin.go +++ b/src/yggdrasil/tun_darwin.go @@ -13,17 +13,6 @@ import ( water "github.com/yggdrasil-network/water" ) -// Sane defaults for the Darwin/macOS platform. The "default" options may be -// may be replaced by the running configuration. -func getDefaults() tunDefaultParameters { - return tunDefaultParameters{ - maximumIfMTU: 65535, - defaultIfMTU: 65535, - defaultIfName: "auto", - defaultIfTAPMode: false, - } -} - // Configures the "utun" adapter with the correct IPv6 address and MTU. func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int) error { if iftapmode { diff --git a/src/yggdrasil/tun_freebsd.go b/src/yggdrasil/tun_freebsd.go deleted file mode 100644 index 4cfdcee..0000000 --- a/src/yggdrasil/tun_freebsd.go +++ /dev/null @@ -1,12 +0,0 @@ -package yggdrasil - -// Sane defaults for the FreeBSD platform. The "default" options may be -// may be replaced by the running configuration. -func getDefaults() tunDefaultParameters { - return tunDefaultParameters{ - maximumIfMTU: 32767, - defaultIfMTU: 32767, - defaultIfName: "/dev/tap0", - defaultIfTAPMode: true, - } -} diff --git a/src/yggdrasil/tun_linux.go b/src/yggdrasil/tun_linux.go index 977d73d..24c5aa9 100644 --- a/src/yggdrasil/tun_linux.go +++ b/src/yggdrasil/tun_linux.go @@ -12,17 +12,6 @@ import ( water "github.com/yggdrasil-network/water" ) -// Sane defaults for the Linux platform. The "default" options may be -// may be replaced by the running configuration. -func getDefaults() tunDefaultParameters { - return tunDefaultParameters{ - maximumIfMTU: 65535, - defaultIfMTU: 65535, - defaultIfName: "auto", - defaultIfTAPMode: false, - } -} - // Configures the TAP adapter with the correct IPv6 address and MTU. func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int) error { var config water.Config diff --git a/src/yggdrasil/tun_netbsd.go b/src/yggdrasil/tun_netbsd.go deleted file mode 100644 index d3e93c4..0000000 --- a/src/yggdrasil/tun_netbsd.go +++ /dev/null @@ -1,12 +0,0 @@ -package yggdrasil - -// Sane defaults for the NetBSD platform. The "default" options may be -// may be replaced by the running configuration. -func getDefaults() tunDefaultParameters { - return tunDefaultParameters{ - maximumIfMTU: 9000, - defaultIfMTU: 9000, - defaultIfName: "/dev/tap0", - defaultIfTAPMode: true, - } -} diff --git a/src/yggdrasil/tun_openbsd.go b/src/yggdrasil/tun_openbsd.go deleted file mode 100644 index c96c865..0000000 --- a/src/yggdrasil/tun_openbsd.go +++ /dev/null @@ -1,12 +0,0 @@ -package yggdrasil - -// Sane defaults for the OpenBSD platform. The "default" options may be -// may be replaced by the running configuration. -func getDefaults() tunDefaultParameters { - return tunDefaultParameters{ - maximumIfMTU: 16384, - defaultIfMTU: 16384, - defaultIfName: "/dev/tap0", - defaultIfTAPMode: true, - } -} diff --git a/src/yggdrasil/tun_other.go b/src/yggdrasil/tun_other.go index 7bc7100..1a3721a 100644 --- a/src/yggdrasil/tun_other.go +++ b/src/yggdrasil/tun_other.go @@ -7,17 +7,6 @@ import water "github.com/yggdrasil-network/water" // This is to catch unsupported platforms // If your platform supports tun devices, you could try configuring it manually -// These are sane defaults for any platform that has not been matched by one of -// the other tun_*.go files. -func getDefaults() tunDefaultParameters { - return tunDefaultParameters{ - maximumIfMTU: 65535, - defaultIfMTU: 65535, - defaultIfName: "none", - defaultIfTAPMode: false, - } -} - // Creates the TUN/TAP adapter, if supported by the Water library. Note that // no guarantees are made at this point on an unsupported platform. func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int) error { diff --git a/src/yggdrasil/tun_windows.go b/src/yggdrasil/tun_windows.go index 131bb34..c6e5770 100644 --- a/src/yggdrasil/tun_windows.go +++ b/src/yggdrasil/tun_windows.go @@ -10,17 +10,6 @@ import ( // This is to catch Windows platforms -// Sane defaults for the Windows platform. The "default" options may be -// may be replaced by the running configuration. -func getDefaults() tunDefaultParameters { - return tunDefaultParameters{ - maximumIfMTU: 65535, - defaultIfMTU: 65535, - defaultIfName: "auto", - defaultIfTAPMode: true, - } -} - // Configures the TAP adapter with the correct IPv6 address and MTU. On Windows // we don't make use of a direct operating system API to do this - we instead // delegate the hard work to "netsh". diff --git a/yggdrasil.go b/yggdrasil.go index 20b4aa0..ab237f4 100644 --- a/yggdrasil.go +++ b/yggdrasil.go @@ -23,6 +23,7 @@ import ( "yggdrasil" "yggdrasil/config" + "yggdrasil/defaults" ) type nodeConfig = config.NodeConfig @@ -53,7 +54,7 @@ func generateConfig(isAutoconf bool) *nodeConfig { r1 := rand.New(rand.NewSource(time.Now().UnixNano())) cfg.Listen = fmt.Sprintf("[::]:%d", r1.Intn(65534-32768)+32768) } - cfg.AdminListen = "localhost:9001" + cfg.AdminListen = defaults.GetDefaults().DefaultAdminListen cfg.EncryptionPublicKey = hex.EncodeToString(bpub[:]) cfg.EncryptionPrivateKey = hex.EncodeToString(bpriv[:]) cfg.SigningPublicKey = hex.EncodeToString(spub[:]) @@ -61,9 +62,9 @@ func generateConfig(isAutoconf bool) *nodeConfig { cfg.Peers = []string{} cfg.AllowedEncryptionPublicKeys = []string{} cfg.MulticastInterfaces = []string{".*"} - cfg.IfName = core.GetTUNDefaultIfName() - cfg.IfMTU = core.GetTUNDefaultIfMTU() - cfg.IfTAPMode = core.GetTUNDefaultIfTAPMode() + cfg.IfName = defaults.GetDefaults().DefaultIfName + cfg.IfMTU = defaults.GetDefaults().DefaultIfMTU + cfg.IfTAPMode = defaults.GetDefaults().DefaultIfTAPMode return &cfg } diff --git a/yggdrasilctl.go b/yggdrasilctl.go index 5cea774..c4efe77 100644 --- a/yggdrasilctl.go +++ b/yggdrasilctl.go @@ -9,10 +9,12 @@ import "encoding/json" import "strconv" import "os" +import "yggdrasil/defaults" + type admin_info map[string]interface{} func main() { - server := flag.String("endpoint", "localhost:9001", "Admin socket endpoint") + server := flag.String("endpoint", defaults.GetDefaults().DefaultAdminListen, "Admin socket endpoint") injson := flag.Bool("json", false, "Output in JSON format") flag.Parse() args := flag.Args() From 36c89da848adb164d01da5b7ca78c34972b8f590 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 7 Jul 2018 12:16:55 +0100 Subject: [PATCH 11/17] Stick with tcp://localhost:9001 as default for now --- src/yggdrasil/config/config.go | 2 +- src/yggdrasil/defaults/defaults_darwin.go | 2 +- src/yggdrasil/defaults/defaults_freebsd.go | 2 +- src/yggdrasil/defaults/defaults_linux.go | 2 +- src/yggdrasil/defaults/defaults_netbsd.go | 2 +- src/yggdrasil/defaults/defaults_openbsd.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/yggdrasil/config/config.go b/src/yggdrasil/config/config.go index 2b8fbe3..5b03e23 100644 --- a/src/yggdrasil/config/config.go +++ b/src/yggdrasil/config/config.go @@ -3,7 +3,7 @@ package config // NodeConfig defines all configuration values needed to run a signle yggdrasil node type NodeConfig struct { Listen string `comment:"Listen address for peer connections. Default is to listen for all\nTCP connections over IPv4 and IPv6 with a random port."` - AdminListen string `comment:"Listen address for admin connections Default is to listen for local\nconnections only on TCP port 9001."` + 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."` Peers []string `comment:"List of connection strings for static peers in URI format, i.e.\ntcp://a.b.c.d:e or socks://a.b.c.d:e/f.g.h.i:j"` AllowedEncryptionPublicKeys []string `comment:"List of peer encryption public keys to allow or incoming TCP\nconnections from. If left empty/undefined then all connections\nwill be allowed by default."` EncryptionPublicKey string `comment:"Your public encryption key. Your peers may ask you for this to put\ninto their AllowedEncryptionPublicKeys configuration."` diff --git a/src/yggdrasil/defaults/defaults_darwin.go b/src/yggdrasil/defaults/defaults_darwin.go index b82660f..3a88274 100644 --- a/src/yggdrasil/defaults/defaults_darwin.go +++ b/src/yggdrasil/defaults/defaults_darwin.go @@ -7,7 +7,7 @@ package defaults func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ // Admin - DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + DefaultAdminListen: "tcp://localhost:9001", // TUN/TAP MaximumIfMTU: 65535, diff --git a/src/yggdrasil/defaults/defaults_freebsd.go b/src/yggdrasil/defaults/defaults_freebsd.go index 4ba7fac..7c5c775 100644 --- a/src/yggdrasil/defaults/defaults_freebsd.go +++ b/src/yggdrasil/defaults/defaults_freebsd.go @@ -7,7 +7,7 @@ package defaults func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ // Admin - DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + DefaultAdminListen: "tcp://localhost:9001", // TUN/TAP MaximumIfMTU: 32767, diff --git a/src/yggdrasil/defaults/defaults_linux.go b/src/yggdrasil/defaults/defaults_linux.go index 4572f3c..2c54d0f 100644 --- a/src/yggdrasil/defaults/defaults_linux.go +++ b/src/yggdrasil/defaults/defaults_linux.go @@ -7,7 +7,7 @@ package defaults func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ // Admin - DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + DefaultAdminListen: "tcp://localhost:9001", // TUN/TAP MaximumIfMTU: 65535, diff --git a/src/yggdrasil/defaults/defaults_netbsd.go b/src/yggdrasil/defaults/defaults_netbsd.go index d9f3b4d..64dd5b0 100644 --- a/src/yggdrasil/defaults/defaults_netbsd.go +++ b/src/yggdrasil/defaults/defaults_netbsd.go @@ -7,7 +7,7 @@ package defaults func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ // Admin - DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + DefaultAdminListen: "tcp://localhost:9001", // TUN/TAP MaximumIfMTU: 9000, diff --git a/src/yggdrasil/defaults/defaults_openbsd.go b/src/yggdrasil/defaults/defaults_openbsd.go index 1b3e0c0..1e9e28c 100644 --- a/src/yggdrasil/defaults/defaults_openbsd.go +++ b/src/yggdrasil/defaults/defaults_openbsd.go @@ -7,7 +7,7 @@ package defaults func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ // Admin - DefaultAdminListen: "unix:///var/run/yggdrasil.sock", + DefaultAdminListen: "tcp://localhost:9001", // TUN/TAP MaximumIfMTU: 16384, From 14d48597da41bc73510140c34eeaba38750793b0 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 7 Jul 2018 12:18:03 +0100 Subject: [PATCH 12/17] Fix openbsd and netbsd --- src/yggdrasil/defaults/defaults_netbsd.go | 2 +- src/yggdrasil/defaults/defaults_openbsd.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/yggdrasil/defaults/defaults_netbsd.go b/src/yggdrasil/defaults/defaults_netbsd.go index 64dd5b0..8e8f7b5 100644 --- a/src/yggdrasil/defaults/defaults_netbsd.go +++ b/src/yggdrasil/defaults/defaults_netbsd.go @@ -1,4 +1,4 @@ -// +build freebsd +// +build netbsd package defaults diff --git a/src/yggdrasil/defaults/defaults_openbsd.go b/src/yggdrasil/defaults/defaults_openbsd.go index 1e9e28c..8b3e2bb 100644 --- a/src/yggdrasil/defaults/defaults_openbsd.go +++ b/src/yggdrasil/defaults/defaults_openbsd.go @@ -1,4 +1,4 @@ -// +build freebsd +// +build openbsd package defaults From 2a931df07af4bf889adf49cc896a61bf8e4484d4 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 7 Jul 2018 12:34:10 +0100 Subject: [PATCH 13/17] Try to clean up UNIX domain admin sockets if shutdown properly --- src/yggdrasil/admin.go | 10 ++++++++++ src/yggdrasil/core.go | 1 + 2 files changed, 11 insertions(+) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index e02bf9e..cd3ea5c 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -227,6 +227,16 @@ func (a *admin) start() error { return nil } +// cleans up when stopping +func (a *admin) stop() error { + if a.listenaddr[0:7] == "unix://" { + if err := os.Remove(a.listenaddr[7:]); err != nil { + return err + } + } + return nil +} + // listen is run by start and manages API connections. func (a *admin) listen() { var l net.Listener diff --git a/src/yggdrasil/core.go b/src/yggdrasil/core.go index 6d130d8..5263676 100644 --- a/src/yggdrasil/core.go +++ b/src/yggdrasil/core.go @@ -135,6 +135,7 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error { func (c *Core) Stop() { c.log.Println("Stopping...") c.tun.close() + c.admin.stop() } // Generates a new encryption keypair. The encryption keys are used to From a5af69df8a804cc9782570e98f3105e2a5b72643 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 7 Jul 2018 20:04:11 +0100 Subject: [PATCH 14/17] Use Close() for admin socket --- src/yggdrasil/admin.go | 25 +++++++++++-------------- src/yggdrasil/core.go | 2 +- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index cd3ea5c..caa4afc 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -20,6 +20,7 @@ import ( type admin struct { core *Core listenaddr string + listener net.Listener handlers []admin_handlerInfo } @@ -228,39 +229,35 @@ func (a *admin) start() error { } // cleans up when stopping -func (a *admin) stop() error { - if a.listenaddr[0:7] == "unix://" { - if err := os.Remove(a.listenaddr[7:]); err != nil { - return err - } - } - return nil +func (a *admin) close() error { + return a.listener.Close() } // listen is run by start and manages API connections. func (a *admin) listen() { - var l net.Listener u, err := url.Parse(a.listenaddr) if err == nil { switch strings.ToLower(u.Scheme) { case "unix": - l, err = net.Listen("unix", a.listenaddr[7:]) + a.listener, err = net.Listen("unix", a.listenaddr[7:]) case "tcp": - l, err = net.Listen("tcp", u.Host) + a.listener, err = net.Listen("tcp", u.Host) default: err = errors.New("protocol not supported") } } else { - l, err = net.Listen("tcp", a.listenaddr) + a.listener, err = net.Listen("tcp", a.listenaddr) } if err != nil { a.core.log.Printf("Admin socket failed to listen: %v", err) os.Exit(1) } - a.core.log.Printf("%s admin socket listening on %s", strings.ToUpper(l.Addr().Network()), l.Addr().String()) - defer l.Close() + a.core.log.Printf("%s admin socket listening on %s", + strings.ToUpper(a.listener.Addr().Network()), + a.listener.Addr().String()) + defer a.listener.Close() for { - conn, err := l.Accept() + conn, err := a.listener.Accept() if err == nil { a.handleRequest(conn) } diff --git a/src/yggdrasil/core.go b/src/yggdrasil/core.go index 5263676..13bb830 100644 --- a/src/yggdrasil/core.go +++ b/src/yggdrasil/core.go @@ -135,7 +135,7 @@ func (c *Core) Start(nc *config.NodeConfig, log *log.Logger) error { func (c *Core) Stop() { c.log.Println("Stopping...") c.tun.close() - c.admin.stop() + c.admin.close() } // Generates a new encryption keypair. The encryption keys are used to From bf90447cc425b6cf80992191665e46146dacbeeb Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 7 Jul 2018 19:37:36 -0500 Subject: [PATCH 15/17] update admin socket error message and run gofmt --- src/yggdrasil/admin.go | 2 +- src/yggdrasil/defaults/defaults.go | 2 +- src/yggdrasil/defaults/defaults_darwin.go | 12 ++++++------ src/yggdrasil/defaults/defaults_linux.go | 12 ++++++------ src/yggdrasil/defaults/defaults_other.go | 12 ++++++------ src/yggdrasil/defaults/defaults_windows.go | 12 ++++++------ 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index a8ac501..128b1d7 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -245,7 +245,7 @@ func (a *admin) listen() { case "tcp": a.listener, err = net.Listen("tcp", u.Host) default: - err = errors.New("protocol not supported") + err = errors.New(fmt.Sprint("protocol not supported: ", u.Scheme)) } } else { a.listener, err = net.Listen("tcp", a.listenaddr) diff --git a/src/yggdrasil/defaults/defaults.go b/src/yggdrasil/defaults/defaults.go index 6145539..753efc5 100644 --- a/src/yggdrasil/defaults/defaults.go +++ b/src/yggdrasil/defaults/defaults.go @@ -5,7 +5,7 @@ package defaults // for the platform being targeted. They must be set. type platformDefaultParameters struct { // Admin socket - DefaultAdminListen string + DefaultAdminListen string // TUN/TAP MaximumIfMTU int diff --git a/src/yggdrasil/defaults/defaults_darwin.go b/src/yggdrasil/defaults/defaults_darwin.go index 3a88274..778162c 100644 --- a/src/yggdrasil/defaults/defaults_darwin.go +++ b/src/yggdrasil/defaults/defaults_darwin.go @@ -6,13 +6,13 @@ package defaults // may be replaced by the running configuration. func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ - // Admin + // Admin DefaultAdminListen: "tcp://localhost:9001", - // TUN/TAP - MaximumIfMTU: 65535, - DefaultIfMTU: 65535, - DefaultIfName: "auto", - DefaultIfTAPMode: false, + // TUN/TAP + MaximumIfMTU: 65535, + DefaultIfMTU: 65535, + DefaultIfName: "auto", + DefaultIfTAPMode: false, } } diff --git a/src/yggdrasil/defaults/defaults_linux.go b/src/yggdrasil/defaults/defaults_linux.go index 2c54d0f..85287ee 100644 --- a/src/yggdrasil/defaults/defaults_linux.go +++ b/src/yggdrasil/defaults/defaults_linux.go @@ -6,13 +6,13 @@ package defaults // may be replaced by the running configuration. func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ - // Admin + // Admin DefaultAdminListen: "tcp://localhost:9001", - // TUN/TAP - MaximumIfMTU: 65535, - DefaultIfMTU: 65535, - DefaultIfName: "auto", - DefaultIfTAPMode: false, + // TUN/TAP + MaximumIfMTU: 65535, + DefaultIfMTU: 65535, + DefaultIfName: "auto", + DefaultIfTAPMode: false, } } diff --git a/src/yggdrasil/defaults/defaults_other.go b/src/yggdrasil/defaults/defaults_other.go index 29e71e8..d780872 100644 --- a/src/yggdrasil/defaults/defaults_other.go +++ b/src/yggdrasil/defaults/defaults_other.go @@ -6,13 +6,13 @@ package defaults // may be replaced by the running configuration. func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ - // Admin + // Admin DefaultAdminListen: "tcp://localhost:9001", - // TUN/TAP - MaximumIfMTU: 65535, - DefaultIfMTU: 65535, - DefaultIfName: "none", - DefaultIfTAPMode: false, + // TUN/TAP + MaximumIfMTU: 65535, + DefaultIfMTU: 65535, + DefaultIfName: "none", + DefaultIfTAPMode: false, } } diff --git a/src/yggdrasil/defaults/defaults_windows.go b/src/yggdrasil/defaults/defaults_windows.go index 91e9e0e..83877d6 100644 --- a/src/yggdrasil/defaults/defaults_windows.go +++ b/src/yggdrasil/defaults/defaults_windows.go @@ -6,13 +6,13 @@ package defaults // may be replaced by the running configuration. func GetDefaults() platformDefaultParameters { return platformDefaultParameters{ - // Admin + // Admin DefaultAdminListen: "tcp://localhost:9001", - // TUN/TAP - MaximumIfMTU: 65535, - DefaultIfMTU: 65535, - DefaultIfName: "auto", - DefaultIfTAPMode: true, + // TUN/TAP + MaximumIfMTU: 65535, + DefaultIfMTU: 65535, + DefaultIfName: "auto", + DefaultIfTAPMode: true, } } From d59bdfeb99d71e612ca1c4aedbd9d64545317564 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 8 Jul 2018 10:37:20 +0100 Subject: [PATCH 16/17] Fail to TCP when parsing AdminListen --- src/yggdrasil/admin.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index 128b1d7..cf56d41 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -245,7 +245,8 @@ func (a *admin) listen() { case "tcp": a.listener, err = net.Listen("tcp", u.Host) default: - err = errors.New(fmt.Sprint("protocol not supported: ", u.Scheme)) + // err = errors.New(fmt.Sprint("protocol not supported: ", u.Scheme)) + a.listener, err = net.Listen("tcp", a.listenaddr) } } else { a.listener, err = net.Listen("tcp", a.listenaddr) From 69cf64dce56f9ed001ba39a0eada71ec28c6ade6 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 8 Jul 2018 11:09:49 +0100 Subject: [PATCH 17/17] Update CHANGELOG.md --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d8b7d4..872c297 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - in case of vulnerabilities. --> +## [0.2.4] - 2018-07-08 +### Added +- Support for UNIX domain sockets for the admin socket using `unix:///path/to/file.sock` +- Centralised platform-specific defaults + +### Changed +- Backpressure tuning, including reducing resource consumption + +### Fixed +- macOS local ping bug, which previously prevented you from pinging your own `utun` adapter's IPv6 address + ## [0.2.3] - 2018-06-29 ### Added - Begin keeping changelog (incomplete and possibly inaccurate information before this point).