From c453770b85ea635ae16a609ff9b5e84336f02d80 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 16 Feb 2018 14:12:44 +0000 Subject: [PATCH 1/3] Add support for running Yggdrasil as a Windows service (using minwinsvc) --- README.md | 27 +++++++++++++++++++++++++-- build | 1 + yggdrasil.go | 13 +++++++++++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 51829307..a51efdc0 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ You're encouraged to play with it, but I strongly advise against using it for an 2. Clone this repository. 2. `./build` -Note that you can cross-compile for other platforms and architectures by specifying the `$GOOS` and `$GOARCH` environment variables, for example, `GOOS=windows ./build` or `GOOS=linux GOARCH=mipsle ./build`. +Note that you can cross-compile for other platforms and architectures by specifying the `$GOOS` and `$GOARCH` environment variables, for example, `GOOS=windows ./build` or `GOOS=linux GOARCH=mipsle ./build`. The build script sets its own `$GOPATH`, so the build environment is self-contained. @@ -52,6 +52,19 @@ In the interest of testing the TCP machinery, it's set to create TCP connections #### Linux - Should work out of the box on most Linux distributions with `iproute2` installed. +- systemd service scripts are included in the `contrib/systemd/` folder so that it runs automatically in the background (using `/etc/yggdrasil.conf` for configuration): + - Copy the service files into `/etc/systemd/system` + - Copy `yggdrasil` into your `$PATH`, i.e. `/usr/bin` + - Enable the service: +``` +systemctl enable yggdrasil +systemctl start yggdrasil +``` + - Read the `yggdrasil` output: +``` +systemctl status yggdrasil +journalctl -u yggdrasil +``` #### macOS @@ -63,6 +76,17 @@ In the interest of testing the TCP machinery, it's set to create TCP connections - Tested and working on Windows 7 and Windows 10, and should work on any recent versions of Windows, but it depends on the [OpenVPN TAP driver](https://openvpn.net/index.php/open-source/downloads.html) being installed first. - Has been proven to work with both the [NDIS 5](https://swupdate.openvpn.org/community/releases/tap-windows-9.9.2_3.exe) (`tap-windows-9.9.2_3`) driver and the [NDIS 6](https://swupdate.openvpn.org/community/releases/tap-windows-9.21.2.exe) (`tap-windows-9.21.2`) driver, however there are substantial performance issues with the NDIS 6 driver therefore it is recommended to use the NDIS 5 driver instead. - Be aware that connectivity issues can occur on Windows if multiple IPv6 addresses from the `fd00::/8` prefix are assigned to the TAP interface. If this happens, then you may need to manually remove the old/unused addresses from the interface (though the code has a workaround in place to do this automatically in some cases). +- Yggdrasil can be installed as a Windows service so that it runs automatically in the background. From an Administrator Command Prompt: +``` +sc create yggdrasil binpath= "\"C:\path\to\yggdrasil.exe\" -useconffile \"C:\path\to\yggdrasil.conf\"" +sc config yggdrasil displayname= "Yggdrasil Service" +sc config yggdrasil start= "auto" +sc start yggdrasil +``` +- Alternatively, if you want the service to autoconfigure instead of using an `yggdrasil.conf`, replace the `sc create` line from above with: +``` +sc create yggdrasil binpath= "\"C:\path\to\yggdrasil.exe\" -autoconf" +``` #### EdgeRouter @@ -114,4 +138,3 @@ Both of these optimizations are not present in the current implementation, as th This code is released under the terms of the LGPLv3, but with an added exception that was shamelessly taken from [godeb](https://github.com/niemeyer/godeb). Under certain circumstances, this exception permits distribution of binaries that are (statically or dynamically) linked with this code, without requiring the distribution of Minimal Corresponding Source or Minimal Application Code. For more details, see: [LICENSE](LICENSE). - diff --git a/build b/build index ddd386dd..39b6ae13 100755 --- a/build +++ b/build @@ -1,6 +1,7 @@ #!/bin/bash export GOPATH=$PWD echo "Downloading..." +go get -d -v go get -d -v yggdrasil for file in *.go ; do echo "Building: $file" diff --git a/yggdrasil.go b/yggdrasil.go index 37921f3f..6211ad78 100644 --- a/yggdrasil.go +++ b/yggdrasil.go @@ -21,6 +21,8 @@ import "golang.org/x/net/ipv6" import . "yggdrasil" +import _ "github.com/kardianos/minwinsvc" + /** * This is a very crude wrapper around src/yggdrasil * It can generate a new config (--genconf) @@ -228,6 +230,7 @@ func (n *node) announce() { var pprof = flag.Bool("pprof", false, "Run pprof, see http://localhost:6060/debug/pprof/") var genconf = flag.Bool("genconf", false, "print a new config to stdout") var useconf = flag.Bool("useconf", false, "read config from stdin") +var useconffile = flag.String("useconffile", "", "read config from specified file path") var autoconf = flag.Bool("autoconf", false, "automatic mode (dynamic IP, peer with IPv6 neighbors)") func main() { @@ -236,8 +239,14 @@ func main() { switch { case *autoconf: cfg = generateConfig() - case *useconf: - config, err := ioutil.ReadAll(os.Stdin) + case *useconffile != "" || *useconf: + var config []byte + var err error + if *useconffile != "" { + config, err = ioutil.ReadFile(*useconffile) + } else { + config, err = ioutil.ReadAll(os.Stdin) + } if err != nil { panic(err) } From d02250c94dcff9ad175b4d95f952e65ce659c160 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 16 Feb 2018 14:19:26 +0000 Subject: [PATCH 2/3] Update README.md for Linux/systemd too --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a51efdc0..45c39a2a 100644 --- a/README.md +++ b/README.md @@ -52,15 +52,12 @@ In the interest of testing the TCP machinery, it's set to create TCP connections #### Linux - Should work out of the box on most Linux distributions with `iproute2` installed. -- systemd service scripts are included in the `contrib/systemd/` folder so that it runs automatically in the background (using `/etc/yggdrasil.conf` for configuration): - - Copy the service files into `/etc/systemd/system` - - Copy `yggdrasil` into your `$PATH`, i.e. `/usr/bin` - - Enable the service: +- systemd service scripts are included in the `contrib/systemd/` folder so that it runs automatically in the background (using `/etc/yggdrasil.conf` for configuration), copy the service files into `/etc/systemd/system`, copy `yggdrasil` into your `$PATH`, i.e. `/usr/bin`, and then enable the service: ``` systemctl enable yggdrasil systemctl start yggdrasil ``` - - Read the `yggdrasil` output: +- Once installed as a systemd service, you can read the `yggdrasil` output: ``` systemctl status yggdrasil journalctl -u yggdrasil From b57491656b67b35e6ad72cc5bc0262ab01ea4d72 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 16 Feb 2018 14:21:57 +0000 Subject: [PATCH 3/3] Fix .travis.yml for these builds --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 093b2fe7..2b0331d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ os: install: - export GOPATH="$TRAVIS_BUILD_DIR:$GOPATH" + - go get -d -v - go get -d -v yggdrasil - for file in *.go ; do go build -v $file; done