mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
.
This commit is contained in:
parent
9c37fc1a5f
commit
570032484f
9 changed files with 93 additions and 103 deletions
131
.gitignore
vendored
131
.gitignore
vendored
|
@ -1,19 +1,56 @@
|
||||||
# Main binaries created in *nix builds
|
build/
|
||||||
/zerotier-one
|
/version.h
|
||||||
/zerotier-idtool
|
|
||||||
/zerotier-cli
|
|
||||||
/zerotier-selftest
|
|
||||||
/zerotier
|
|
||||||
/nltest
|
|
||||||
|
|
||||||
# OS-created garbage files from various platforms
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.Trashes
|
||||||
|
*.swp
|
||||||
|
._*
|
||||||
|
*~
|
||||||
|
*~.nib
|
||||||
.Apple*
|
.Apple*
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
@eaDir
|
@eaDir
|
||||||
._*
|
DerivedData/
|
||||||
|
*.pbxuser
|
||||||
|
*.mode1v3
|
||||||
|
*.mode2v3
|
||||||
|
*.perspectivev3
|
||||||
|
!default.pbxuser
|
||||||
|
!default.mode1v3
|
||||||
|
!default.mode2v3
|
||||||
|
!default.perspectivev3
|
||||||
|
*.xccheckout
|
||||||
|
xcuserdata/
|
||||||
|
.vscode
|
||||||
|
__pycache__
|
||||||
|
attic/world/*.c25519
|
||||||
|
attic/world/mkworld
|
||||||
|
*.log
|
||||||
|
*.opensdf
|
||||||
|
*.user
|
||||||
|
*.cache
|
||||||
|
*.obj
|
||||||
|
*.tlog
|
||||||
|
*.pid
|
||||||
|
*.pkg
|
||||||
|
*.o
|
||||||
|
*.o-*
|
||||||
|
*.core
|
||||||
|
*.deb
|
||||||
|
*.rpm
|
||||||
|
*.autosave
|
||||||
|
*.tmp
|
||||||
|
.depend
|
||||||
|
node_modules
|
||||||
|
debian/files
|
||||||
|
debian/zerotier-one
|
||||||
|
debian/zerotier-one*.debhelper
|
||||||
|
debian/*.log
|
||||||
|
debian/zerotier-one.substvars
|
||||||
|
root/identity.*
|
||||||
|
root/config.*
|
||||||
|
/ext/installfiles/windows/chocolatey/zerotier-one/*.nupkg
|
||||||
|
/go/zerotier
|
||||||
|
|
||||||
# Windows build droppings
|
|
||||||
/windows/ZeroTierOne.sdf
|
/windows/ZeroTierOne.sdf
|
||||||
/windows/ZeroTierOne.v11.suo
|
/windows/ZeroTierOne.v11.suo
|
||||||
/windows/x64
|
/windows/x64
|
||||||
|
@ -32,7 +69,7 @@ Thumbs.db
|
||||||
/ext/installfiles/windows/ZeroTier One-SetupFiles
|
/ext/installfiles/windows/ZeroTier One-SetupFiles
|
||||||
/ext/installfiles/windows/Prerequisites
|
/ext/installfiles/windows/Prerequisites
|
||||||
/ext/installfiles/windows/*-cache
|
/ext/installfiles/windows/*-cache
|
||||||
/ZeroTier One.msi
|
/*.msi
|
||||||
/windows/.vs
|
/windows/.vs
|
||||||
*.vcxproj.backup
|
*.vcxproj.backup
|
||||||
/windows/TapDriver6/Win7Debug
|
/windows/TapDriver6/Win7Debug
|
||||||
|
@ -43,50 +80,6 @@ enc_temp_folder
|
||||||
/windows/copyutil/bin
|
/windows/copyutil/bin
|
||||||
/windows/copyutil/obj
|
/windows/copyutil/obj
|
||||||
|
|
||||||
# *nix/Mac build droppings
|
|
||||||
/build-*
|
|
||||||
/ZeroTierOneInstaller-*
|
|
||||||
/examples/docker/zerotier-one
|
|
||||||
/examples/docker/test-*.env
|
|
||||||
/world/mkworld
|
|
||||||
/world/*.c25519
|
|
||||||
zt1-src.tar.gz
|
|
||||||
/MacEthernetTapAgent
|
|
||||||
|
|
||||||
# Miscellaneous temporaries, build files, etc.
|
|
||||||
*.log
|
|
||||||
*.opensdf
|
|
||||||
*.user
|
|
||||||
*.cache
|
|
||||||
*.obj
|
|
||||||
*.tlog
|
|
||||||
*.pid
|
|
||||||
*.pkg
|
|
||||||
*.o
|
|
||||||
/*.a
|
|
||||||
*.dylib
|
|
||||||
*.so
|
|
||||||
*.so.*
|
|
||||||
*.o-*
|
|
||||||
*.core
|
|
||||||
*.deb
|
|
||||||
*.rpm
|
|
||||||
*.autosave
|
|
||||||
*.tmp
|
|
||||||
.depend
|
|
||||||
node_modules
|
|
||||||
zt1_update_*
|
|
||||||
debian/files
|
|
||||||
debian/zerotier-one
|
|
||||||
debian/zerotier-one*.debhelper
|
|
||||||
debian/*.log
|
|
||||||
debian/zerotier-one.substvars
|
|
||||||
root-watcher/config.json
|
|
||||||
root/identity.*
|
|
||||||
root/zerotier-root
|
|
||||||
root/config.*
|
|
||||||
|
|
||||||
# Java/Android/JNI build droppings
|
|
||||||
java/obj/
|
java/obj/
|
||||||
java/libs/
|
java/libs/
|
||||||
java/bin/
|
java/bin/
|
||||||
|
@ -98,29 +91,3 @@ java/build_win32/
|
||||||
windows/WinUI/obj/
|
windows/WinUI/obj/
|
||||||
windows/WinUI/bin/
|
windows/WinUI/bin/
|
||||||
windows/ZeroTierOne/Debug/
|
windows/ZeroTierOne/Debug/
|
||||||
/ext/installfiles/windows/chocolatey/zerotier-one/*.nupkg
|
|
||||||
|
|
||||||
# Miscellaneous mac/Xcode droppings
|
|
||||||
.DS_Store
|
|
||||||
.Trashes
|
|
||||||
*.swp
|
|
||||||
*~.nib
|
|
||||||
DerivedData/
|
|
||||||
build/
|
|
||||||
*.pbxuser
|
|
||||||
*.mode1v3
|
|
||||||
*.mode2v3
|
|
||||||
*.perspectivev3
|
|
||||||
!default.pbxuser
|
|
||||||
!default.mode1v3
|
|
||||||
!default.mode2v3
|
|
||||||
!default.perspectivev3
|
|
||||||
*.xccheckout
|
|
||||||
xcuserdata/
|
|
||||||
ext/librethinkdbxx/build
|
|
||||||
.vscode
|
|
||||||
__pycache__
|
|
||||||
*~
|
|
||||||
attic/world/*.c25519
|
|
||||||
attic/world/mkworld
|
|
||||||
/version.h
|
|
||||||
|
|
2
go/Makefile
Normal file
2
go/Makefile
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
all:
|
||||||
|
go build -o zerotier cmd/zerotier/zerotier.go
|
|
@ -37,9 +37,7 @@ func Service(basePath, authToken string, args []string) {
|
||||||
osSignalChannel := make(chan os.Signal, 2)
|
osSignalChannel := make(chan os.Signal, 2)
|
||||||
signal.Notify(osSignalChannel, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGINT, syscall.SIGBUS)
|
signal.Notify(osSignalChannel, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGINT, syscall.SIGBUS)
|
||||||
signal.Ignore(syscall.SIGUSR1, syscall.SIGUSR2)
|
signal.Ignore(syscall.SIGUSR1, syscall.SIGUSR2)
|
||||||
go func() {
|
|
||||||
<-osSignalChannel
|
<-osSignalChannel
|
||||||
node.Close()
|
node.Close()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,13 @@ func readAuthToken(basePath string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func authTokenRequired(authToken string) {
|
||||||
|
if len(authToken) == 0 {
|
||||||
|
fmt.Println("FATAL: unable to read API authorization token from service path or user home ('sudo' may be needed)")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
globalOpts := flag.NewFlagSet("global", flag.ContinueOnError)
|
globalOpts := flag.NewFlagSet("global", flag.ContinueOnError)
|
||||||
hflag := globalOpts.Bool("h", false, "") // support -h to be canonical with other Unix utilities
|
hflag := globalOpts.Bool("h", false, "") // support -h to be canonical with other Unix utilities
|
||||||
|
@ -81,16 +88,13 @@ func main() {
|
||||||
if len(*pflag) > 0 {
|
if len(*pflag) > 0 {
|
||||||
basePath = *pflag
|
basePath = *pflag
|
||||||
}
|
}
|
||||||
|
|
||||||
var authToken string
|
var authToken string
|
||||||
if len(*tflag) > 0 {
|
if len(*tflag) > 0 {
|
||||||
authToken = *tflag
|
authToken = *tflag
|
||||||
} else {
|
} else {
|
||||||
authToken = readAuthToken(basePath)
|
authToken = readAuthToken(basePath)
|
||||||
}
|
}
|
||||||
if len(authToken) == 0 {
|
|
||||||
fmt.Println("FATAL: unable to read API authorization token from service path or user home ('sudo' may be needed)")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
authToken = strings.TrimSpace(authToken)
|
authToken = strings.TrimSpace(authToken)
|
||||||
|
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
|
@ -103,24 +107,34 @@ func main() {
|
||||||
case "service":
|
case "service":
|
||||||
cli.Service(basePath, authToken, cmdArgs)
|
cli.Service(basePath, authToken, cmdArgs)
|
||||||
case "status":
|
case "status":
|
||||||
|
authTokenRequired(authToken)
|
||||||
cli.Status(basePath, authToken, cmdArgs, *jflag)
|
cli.Status(basePath, authToken, cmdArgs, *jflag)
|
||||||
case "peers":
|
case "peers":
|
||||||
|
authTokenRequired(authToken)
|
||||||
cli.Peers(basePath, authToken, cmdArgs)
|
cli.Peers(basePath, authToken, cmdArgs)
|
||||||
case "roots":
|
case "roots":
|
||||||
|
authTokenRequired(authToken)
|
||||||
cli.Roots(basePath, authToken, cmdArgs)
|
cli.Roots(basePath, authToken, cmdArgs)
|
||||||
case "addroot":
|
case "addroot":
|
||||||
|
authTokenRequired(authToken)
|
||||||
cli.AddRoot(basePath, authToken, cmdArgs)
|
cli.AddRoot(basePath, authToken, cmdArgs)
|
||||||
case "removeroot":
|
case "removeroot":
|
||||||
|
authTokenRequired(authToken)
|
||||||
cli.RemoveRoot(basePath, authToken, cmdArgs)
|
cli.RemoveRoot(basePath, authToken, cmdArgs)
|
||||||
case "networks":
|
case "networks":
|
||||||
|
authTokenRequired(authToken)
|
||||||
cli.Networks(basePath, authToken, cmdArgs)
|
cli.Networks(basePath, authToken, cmdArgs)
|
||||||
case "join":
|
case "join":
|
||||||
|
authTokenRequired(authToken)
|
||||||
cli.Join(basePath, authToken, cmdArgs)
|
cli.Join(basePath, authToken, cmdArgs)
|
||||||
case "leave":
|
case "leave":
|
||||||
|
authTokenRequired(authToken)
|
||||||
cli.Leave(basePath, authToken, cmdArgs)
|
cli.Leave(basePath, authToken, cmdArgs)
|
||||||
case "show":
|
case "show":
|
||||||
|
authTokenRequired(authToken)
|
||||||
cli.Show(basePath, authToken, cmdArgs)
|
cli.Show(basePath, authToken, cmdArgs)
|
||||||
case "set":
|
case "set":
|
||||||
|
authTokenRequired(authToken)
|
||||||
cli.Set(basePath, authToken, cmdArgs)
|
cli.Set(basePath, authToken, cmdArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "../../node/Address.hpp"
|
#include "../../node/Address.hpp"
|
||||||
#include "../../osdep/OSUtils.hpp"
|
#include "../../osdep/OSUtils.hpp"
|
||||||
#include "../../osdep/EthernetTap.hpp"
|
#include "../../osdep/EthernetTap.hpp"
|
||||||
|
#include "../../osdep/ManagedRoute.hpp"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -102,7 +103,7 @@ struct ZT_GoNode_Impl
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::string defaultHomePath(OSUtils::platformDefaultHomePath());
|
static const std::string defaultHomePath(OSUtils::platformDefaultHomePath());
|
||||||
extern "C" const char *ZT_PLATFORM_DEFAULT_HOMEPATH = defaultHomePath.c_str();
|
const char *ZT_PLATFORM_DEFAULT_HOMEPATH = defaultHomePath.c_str();
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ func (lc *LocalConfig) Read(p string, saveDefaultsIfNotExist bool) error {
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(p)
|
data, err := ioutil.ReadFile(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != os.ErrNotExist {
|
if !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if saveDefaultsIfNotExist {
|
if saveDefaultsIfNotExist {
|
||||||
|
|
|
@ -328,7 +328,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) {
|
||||||
k := r.key()
|
k := r.key()
|
||||||
wantManagedRoutes[k] = true
|
wantManagedRoutes[k] = true
|
||||||
if _, have := haveManagedRoutes[k]; !have {
|
if _, have := haveManagedRoutes[k]; !have {
|
||||||
n.node.log.Printf("%.16x adding managed route %s", n.ID, r.Target.String())
|
n.node.log.Printf("%.16x adding managed route %s", n.ID, r.String())
|
||||||
n.tap.AddRoute(&r)
|
n.tap.AddRoute(&r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,7 +336,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) {
|
||||||
}
|
}
|
||||||
for k, r := range haveManagedRoutes {
|
for k, r := range haveManagedRoutes {
|
||||||
if _, want := wantManagedRoutes[k]; !want {
|
if _, want := wantManagedRoutes[k]; !want {
|
||||||
n.node.log.Printf("%.16x removing managed route %s", n.ID, r.Target.String())
|
n.node.log.Printf("%.16x removing managed route %s", n.ID, r.String())
|
||||||
n.tap.RemoveRoute(r)
|
n.tap.RemoveRoute(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ package zerotier
|
||||||
// and generally contains all the other CGO stuff.
|
// and generally contains all the other CGO stuff.
|
||||||
|
|
||||||
//#cgo CFLAGS: -O3
|
//#cgo CFLAGS: -O3
|
||||||
//#cgo LDFLAGS: ${SRCDIR}/../../../build/node/libzt_core.a ${SRCDIR}/../../../build/osdep/libzt_osdep.a ${SRCDIR}/../../../build/go/native/libzt_go_native.a -lc++ -lpthread
|
//#cgo darwin LDFLAGS: ${SRCDIR}/../../../build/go/native/libzt_go_native.a ${SRCDIR}/../../../build/node/libzt_core.a ${SRCDIR}/../../../build/osdep/libzt_osdep.a -lc++ -lpthread
|
||||||
//#define ZT_CGO 1
|
//#cgo linux android LDFLAGS: ${SRCDIR}/../../../build/go/native/libzt_go_native.a ${SRCDIR}/../../../build/node/libzt_core.a ${SRCDIR}/../../../build/osdep/libzt_osdep.a -lstdc++ -lpthread -lm
|
||||||
//#include "../../native/GoGlue.h"
|
//#include "../../native/GoGlue.h"
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
@ -68,9 +68,6 @@ const (
|
||||||
// CoreVersionBuild is the build version of the ZeroTier core
|
// CoreVersionBuild is the build version of the ZeroTier core
|
||||||
CoreVersionBuild int = C.ZEROTIER_ONE_VERSION_BUILD
|
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 is the address family for IPv4
|
// AFInet is the address family for IPv4
|
||||||
AFInet = C.AF_INET
|
AFInet = C.AF_INET
|
||||||
|
|
||||||
|
@ -81,7 +78,10 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
nodesByUserPtr map[uintptr]*Node
|
// PlatformDefaultHomePath is the default location of ZeroTier's working path on this system
|
||||||
|
PlatformDefaultHomePath string = C.GoString(C.ZT_PLATFORM_DEFAULT_HOMEPATH)
|
||||||
|
|
||||||
|
nodesByUserPtr = make(map[uintptr]*Node)
|
||||||
nodesByUserPtrLock sync.RWMutex
|
nodesByUserPtrLock sync.RWMutex
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -862,7 +862,7 @@ func goVirtualNetworkConfigFunc(gn, tapP unsafe.Pointer, nwid C.uint64_t, op C.i
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
node.networksLock.RLock()
|
node.networksLock.RLock()
|
||||||
network := node.networks[uint64(nwid)]
|
network := node.networks[NetworkID(nwid)]
|
||||||
node.networksLock.RUnlock()
|
node.networksLock.RUnlock()
|
||||||
if network != nil {
|
if network != nil {
|
||||||
ncc := (*C.ZT_VirtualNetworkConfig)(conf)
|
ncc := (*C.ZT_VirtualNetworkConfig)(conf)
|
||||||
|
@ -1124,7 +1124,7 @@ func handleTapMulticastGroupChange(gn unsafe.Pointer, nwid, mac C.uint64_t, adi
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
node.networksLock.RLock()
|
node.networksLock.RLock()
|
||||||
network := node.networks[uint64(nwid)]
|
network := node.networks[NetworkID(nwid)]
|
||||||
node.networksLock.RUnlock()
|
node.networksLock.RUnlock()
|
||||||
if network != nil {
|
if network != nil {
|
||||||
tap, _ := network.tap.(*nativeTap)
|
tap, _ := network.tap.(*nativeTap)
|
||||||
|
|
|
@ -33,6 +33,14 @@ type Route struct {
|
||||||
Metric uint16
|
Metric uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns a string representation of this route
|
||||||
|
func (r *Route) String() string {
|
||||||
|
if len(r.Via) == 0 {
|
||||||
|
return r.Target.String() + "->LAN"
|
||||||
|
}
|
||||||
|
return r.Target.String() + "->" + r.Via.String()
|
||||||
|
}
|
||||||
|
|
||||||
// key generates a key suitable for a map[] from this route
|
// key generates a key suitable for a map[] from this route
|
||||||
func (r *Route) key() (k [6]uint64) {
|
func (r *Route) key() (k [6]uint64) {
|
||||||
copy(((*[16]byte)(unsafe.Pointer(&k[0])))[:], r.Target.IP)
|
copy(((*[16]byte)(unsafe.Pointer(&k[0])))[:], r.Target.IP)
|
||||||
|
|
Loading…
Add table
Reference in a new issue