From 70d5da1e2a58320626a7555c088bdce941bc176f Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Sun, 22 Sep 2019 19:25:40 -0700 Subject: [PATCH] . --- go/native/GoGlue.cpp | 3 ++ go/native/GoGlue.h | 1 + go/pkg/zerotier/localconfig.go | 73 ++++++++++++++++++++++++++++++++++ go/pkg/zerotier/node.go | 3 ++ osdep/OSUtils.cpp | 12 +++--- 5 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 go/pkg/zerotier/localconfig.go diff --git a/go/native/GoGlue.cpp b/go/native/GoGlue.cpp index f2fe1ed66..3a374c00b 100644 --- a/go/native/GoGlue.cpp +++ b/go/native/GoGlue.cpp @@ -100,6 +100,9 @@ struct ZT_GoNode_Impl std::thread backgroundTaskThread; }; +static const std::string defaultHomePath(OSUtils::platformDefaultHomePath()); +extern "C" const char *ZT_PLATFORM_DEFAULT_HOMEPATH = defaultHomePath.c_str(); + /****************************************************************************/ /* These functions are implemented in Go in pkg/ztnode/node-callbacks.go */ diff --git a/go/native/GoGlue.h b/go/native/GoGlue.h index 25ce1d7f9..2a16873b3 100644 --- a/go/native/GoGlue.h +++ b/go/native/GoGlue.h @@ -48,6 +48,7 @@ extern "C" { /****************************************************************************/ +const char *ZT_PLATFORM_DEFAULT_HOMEPATH; /****************************************************************************/ diff --git a/go/pkg/zerotier/localconfig.go b/go/pkg/zerotier/localconfig.go new file mode 100644 index 000000000..29d187e81 --- /dev/null +++ b/go/pkg/zerotier/localconfig.go @@ -0,0 +1,73 @@ +/* + * Copyright (c)2019 ZeroTier, Inc. + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file in the project's root directory. + * + * Change Date: 2023-01-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2.0 of the Apache License. + */ +/****/ + +package zerotier + +import ( + "net" + "runtime" +) + +// LocalConfigPhysicalPathConfiguration contains settings for physical paths +type LocalConfigPhysicalPathConfiguration struct { + Blacklist bool + TrustedPathID uint64 +} + +// LocalConfigVirtualAddressConfiguration contains settings for virtual addresses +type LocalConfigVirtualAddressConfiguration struct { + Try []net.Addr +} + +// LocalConfigSettings contains node settings +type LocalConfigSettings struct { + PrimaryPort int + SecondaryPort int + TertiaryPort int + PortMappingEnabled bool + MuiltipathMode int + InterfacePrefixBlacklist []string +} + +// LocalConfig is the local.conf file and stores local settings for the node. +type LocalConfig struct { + Physical map[string]LocalConfigPhysicalPathConfiguration + Virtual map[Address]LocalConfigVirtualAddressConfiguration + Settings LocalConfigSettings +} + +// NewLocalConfig creates a new local.conf file with defaults +func NewLocalConfig() *LocalConfig { + lc := &LocalConfig{ + Physical: make(map[string]LocalConfigPhysicalPathConfiguration), + Virtual: make(map[Address]LocalConfigVirtualAddressConfiguration), + Settings: LocalConfigSettings{ + PrimaryPort: 9993, + SecondaryPort: 0, + TertiaryPort: 0, + PortMappingEnabled: true, + MuiltipathMode: 0, + }, + } + switch runtime.GOOS { + case "darwin": + lc.Settings.InterfacePrefixBlacklist = []string{"utun", "tun", "tap", "feth", "lo", "zt"} + case "linux": + lc.Settings.InterfacePrefixBlacklist = []string{"tun", "tap", "lo", "zt"} + case "freebsd", "openbsd", "netbsd", "illumos", "solaris", "dragonfly": + lc.Settings.InterfacePrefixBlacklist = []string{"tun", "tap", "zt"} + case "android": + lc.Settings.InterfacePrefixBlacklist = []string{"tun", "tap"} + } + return lc +} diff --git a/go/pkg/zerotier/node.go b/go/pkg/zerotier/node.go index 473262f91..bd654d8a4 100644 --- a/go/pkg/zerotier/node.go +++ b/go/pkg/zerotier/node.go @@ -56,6 +56,9 @@ const ( // CoreVersionBuild is the build version of the ZeroTier core CoreVersionBuild int = C.ZEROTIER_ONE_VERSION_BUILD + // PlatformDefaultHomePath is the default location of ZeroTier's working path on this system + PlatformDefaultHomePath string = C.GoString(C.ZT_PLATFORM_DEFAULT_HOMEPATH) + afInet = C.AF_INET afInet6 = C.AF_INET6 ) diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp index 7cbf78ba7..142f7cc12 100644 --- a/osdep/OSUtils.cpp +++ b/osdep/OSUtils.cpp @@ -406,15 +406,15 @@ std::string OSUtils::platformDefaultHomePath() #ifdef __APPLE__ // /Library/... on Apple - return std::string("/Library/Application Support/ZeroTier/One"); + return std::string("/Library/Application Support/ZeroTier"); #else #ifdef __BSD__ // BSD likes /var/db instead of /var/lib - return std::string("/var/db/zerotier-one"); + return std::string("/var/db/zerotier"); #else // Use /var/lib for Linux and other *nix - return std::string("/var/lib/zerotier-one"); + return std::string("/var/lib/zerotier"); #endif #endif @@ -425,11 +425,11 @@ std::string OSUtils::platformDefaultHomePath() // Look up app data folder on Windows, e.g. C:\ProgramData\... char buf[16384]; if (SUCCEEDED(SHGetFolderPathA(NULL,CSIDL_COMMON_APPDATA,NULL,0,buf))) - return (std::string(buf) + "\\ZeroTier\\One"); - else return std::string("C:\\ZeroTier\\One"); + return (std::string(buf) + "\\ZeroTier"); + else return std::string("C:\\ZeroTier"); #else - return (std::string(ZT_PATH_SEPARATOR_S) + "ZeroTier" + ZT_PATH_SEPARATOR_S + "One"); // UNKNOWN PLATFORM + return (std::string(ZT_PATH_SEPARATOR_S) + "ZeroTier"); // UNKNOWN PLATFORM #endif