Compare commits
No commits in common. "master" and "pristine-tar" have entirely different histories.
master
...
pristine-t
113
.gitignore
vendored
|
@ -1,113 +0,0 @@
|
||||||
<<<<<<< HEAD
|
|
||||||
# Main binaries created in *nix builds
|
|
||||||
/zerotier-one
|
|
||||||
/zerotier-idtool
|
|
||||||
/zerotier-cli
|
|
||||||
/zerotier-selftest
|
|
||||||
/zerotier
|
|
||||||
|
|
||||||
# OS-created garbage files from various platforms
|
|
||||||
.DS_Store
|
|
||||||
.Apple*
|
|
||||||
Thumbs.db
|
|
||||||
@eaDir
|
|
||||||
|
|
||||||
# Windows build droppings
|
|
||||||
/windows/ZeroTierOne.sdf
|
|
||||||
/windows/ZeroTierOne.v11.suo
|
|
||||||
/windows/x64
|
|
||||||
/windows/Win32
|
|
||||||
/windows/*/x64
|
|
||||||
/windows/*/Win32
|
|
||||||
/windows/ZeroTierOne/Release
|
|
||||||
/windows/ZeroTierOneService/obj
|
|
||||||
/windows/ZeroTierOneService/bin
|
|
||||||
/windows/Build
|
|
||||||
/windows/Debug
|
|
||||||
/windows/Release
|
|
||||||
/windows/WebUIWrapper/bin
|
|
||||||
/windows/WebUIWrapper/obj
|
|
||||||
/ext/installfiles/windows/ZeroTier One-SetupFiles
|
|
||||||
/ext/installfiles/windows/Prerequisites
|
|
||||||
/ext/installfiles/windows/*-cache
|
|
||||||
/ZeroTier One.msi
|
|
||||||
/windows/.vs
|
|
||||||
*.vcxproj.backup
|
|
||||||
/windows/TapDriver6/Win7Debug
|
|
||||||
/windows/TapDriver6/win7Release
|
|
||||||
/windows/*.db
|
|
||||||
/windows/*.opendb
|
|
||||||
enc_temp_folder
|
|
||||||
/windows/copyutil/bin
|
|
||||||
/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
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
# Java/Android/JNI build droppings
|
|
||||||
java/obj/
|
|
||||||
java/libs/
|
|
||||||
java/bin/
|
|
||||||
java/classes/
|
|
||||||
java/doc/
|
|
||||||
java/build_win64/
|
|
||||||
java/build_win32/
|
|
||||||
/java/mac32_64/
|
|
||||||
windows/WinUI/obj/
|
|
||||||
windows/WinUI/bin/
|
|
||||||
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/
|
|
73
AUTHORS.md
|
@ -1,73 +0,0 @@
|
||||||
## Primary Authors
|
|
||||||
|
|
||||||
* ZeroTier Core and ZeroTier One virtual networking service<br>
|
|
||||||
Adam Ierymenko / adam.ierymenko@zerotier.com
|
|
||||||
|
|
||||||
* Java JNI Interface to enable Android application development, and Android app itself (code for that is elsewhere)<br>
|
|
||||||
Grant Limberg / glimberg@gmail.com
|
|
||||||
|
|
||||||
* ZeroTier SDK (formerly known as Network Containers)<br>
|
|
||||||
Joseph Henry / joseph.henry@zerotier.com
|
|
||||||
|
|
||||||
## Third Party Contributors
|
|
||||||
|
|
||||||
* A number of fixes and improvements to the new controller, other stuff.<br>
|
|
||||||
Kees Bos / https://github.com/keesbos/
|
|
||||||
|
|
||||||
* Debugging and testing, OpenWRT support fixes.<br>
|
|
||||||
Moritz Warning / moritzwarning@web.de
|
|
||||||
|
|
||||||
* Debian GNU/Linux packaging, manual pages, and license compliance edits.<br>
|
|
||||||
Ben Finney <ben+zerotier@benfinney.id.au>
|
|
||||||
|
|
||||||
* Several others made smaller contributions, which GitHub tracks here:<br>
|
|
||||||
https://github.com/zerotier/ZeroTierOne/graphs/contributors/
|
|
||||||
|
|
||||||
## Third-Party Code
|
|
||||||
|
|
||||||
ZeroTier includes the following third party code, either in ext/ or incorporated into the ZeroTier core.
|
|
||||||
|
|
||||||
* LZ4 compression algorithm by Yann Collet
|
|
||||||
|
|
||||||
* Files: node/Packet.cpp (bundled within anonymous namespace)
|
|
||||||
* Home page: http://code.google.com/p/lz4/
|
|
||||||
* License grant: BSD 2-clause
|
|
||||||
|
|
||||||
* http-parser by Joyent, Inc. (many authors)
|
|
||||||
|
|
||||||
* Files: ext/http-parser/*
|
|
||||||
* Home page: https://github.com/joyent/http-parser/
|
|
||||||
* License grant: MIT/Expat
|
|
||||||
|
|
||||||
* C++11 json (nlohmann/json) by Niels Lohmann
|
|
||||||
|
|
||||||
* Files: ext/json/*
|
|
||||||
* Home page: https://github.com/nlohmann/json
|
|
||||||
* License grant: MIT
|
|
||||||
|
|
||||||
* TunTapOSX by Mattias Nissler
|
|
||||||
|
|
||||||
* Files: ext/tap-mac/tuntap/*
|
|
||||||
* Home page: http://tuntaposx.sourceforge.net/
|
|
||||||
* License grant: BSD attribution no-endorsement
|
|
||||||
* ZeroTier Modifications: change interface name to zt#, increase max MTU, increase max devices
|
|
||||||
|
|
||||||
* tap-windows6 by the OpenVPN project
|
|
||||||
|
|
||||||
* Files: windows/TapDriver6/*
|
|
||||||
* Home page: https://github.com/OpenVPN/tap-windows6/
|
|
||||||
* License grant: GNU GPL v2
|
|
||||||
* ZeroTier Modifications: change name of driver to ZeroTier, add ioctl() to get L2 multicast memberships (source is in ext/ and modifications inherit GPL)
|
|
||||||
|
|
||||||
* Salsa20 stream cipher, Curve25519 elliptic curve cipher, Ed25519 digital signature algorithm, and Poly1305 MAC algorithm, all by Daniel J. Bernstein
|
|
||||||
|
|
||||||
* Files: node/Salsa20.* node/C25519.* node/Poly1305.*
|
|
||||||
* Home page: http://cr.yp.to/
|
|
||||||
* License grant: public domain
|
|
||||||
* ZeroTier Modifications: slight cryptographically-irrelevant modifications for inclusion into ZeroTier core
|
|
||||||
|
|
||||||
* MiniUPNPC and libnatpmp by Thomas Bernard
|
|
||||||
|
|
||||||
* Files: ext/libnatpmp/* ext/miniupnpc/*
|
|
||||||
* Home page: http://miniupnp.free.fr/
|
|
||||||
* License grant: BSD attribution no-endorsement
|
|
17
COPYING
|
@ -1,17 +0,0 @@
|
||||||
ZeroTier One, an endpoint server for the ZeroTier virtual network layer.
|
|
||||||
Copyright © 2011–2016 ZeroTier, Inc.
|
|
||||||
|
|
||||||
ZeroTier One is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 3 of the License, or (at
|
|
||||||
your option) any later version.
|
|
||||||
|
|
||||||
See the file ‘LICENSE.GPL-3’ for the text of the GNU GPL version 3.
|
|
||||||
If that file is not present, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
..
|
|
||||||
Local variables:
|
|
||||||
coding: utf-8
|
|
||||||
mode: text
|
|
||||||
End:
|
|
||||||
vim: fileencoding=utf-8 filetype=text :
|
|
82
Jenkinsfile
vendored
|
@ -1,82 +0,0 @@
|
||||||
#!/usr/bin/env groovy
|
|
||||||
|
|
||||||
node('master') {
|
|
||||||
def changelog = getChangeLog currentBuild
|
|
||||||
|
|
||||||
slackSend "Building ${env.JOB_NAME} #${env.BUILD_NUMBER} \n Change Log: \n ${changelog}"
|
|
||||||
}
|
|
||||||
|
|
||||||
parallel 'centos7': {
|
|
||||||
node('centos7') {
|
|
||||||
try {
|
|
||||||
checkout scm
|
|
||||||
|
|
||||||
stage('Build Centos 7') {
|
|
||||||
sh 'make -f make-linux.mk'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
currentBuild.result = "FAILURE"
|
|
||||||
slackSend color: '#ff0000', message: "${env.JOB_NAME} broken on Centos 7 (<${env.BUILD_URL}|Open>)"
|
|
||||||
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 'android-ndk': {
|
|
||||||
node('android-ndk') {
|
|
||||||
try {
|
|
||||||
checkout scm
|
|
||||||
|
|
||||||
stage('Build Android NDK') {
|
|
||||||
sh "/android/android-ndk-r13b/ndk-build -C $WORKSPACE/java ZT1=${WORKSPACE}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
currentBuild.result = "FAILURE"
|
|
||||||
slackSend color: '#ff0000', message: "${env.JOB_NAME} broken on Android NDK (<${env.BUILD_URL}|Open>)"
|
|
||||||
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 'macOS': {
|
|
||||||
node('macOS') {
|
|
||||||
try {
|
|
||||||
checkout scm
|
|
||||||
|
|
||||||
stage('Build macOS') {
|
|
||||||
sh 'make -f make-mac.mk'
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Build macOS UI') {
|
|
||||||
sh 'cd macui && xcodebuild -target "ZeroTier One" -configuration Debug'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
currentBuild.result = "FAILURE"
|
|
||||||
slackSend color: '#ff0000', message: "${env.JOB_NAME} broken on macOS (<${env.BUILD_URL}|Open>)"
|
|
||||||
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 'windows': {
|
|
||||||
node('windows') {
|
|
||||||
try {
|
|
||||||
checkout scm
|
|
||||||
|
|
||||||
stage('Build Windows') {
|
|
||||||
bat '''CALL "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat" amd64
|
|
||||||
git clean -dfx
|
|
||||||
msbuild windows\\ZeroTierOne.sln
|
|
||||||
'''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
currentBuild.result = "FAILURE"
|
|
||||||
slackSend color: '#ff0000', message: "${env.JOB_NAME} broken on Windows (<${env.BUILD_URL}|Open>)"
|
|
||||||
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
slackSend color: "#00ff00", message: "${env.JOB_NAME} #${env.BUILD_NUMBER} Complete (<${env.BUILD_URL}|Show More...>)"
|
|
339
LICENSE.GPL-2
|
@ -1,339 +0,0 @@
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 2, June 1991
|
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
|
||||||
License is intended to guarantee your freedom to share and change free
|
|
||||||
software--to make sure the software is free for all its users. This
|
|
||||||
General Public License applies to most of the Free Software
|
|
||||||
Foundation's software and to any other program whose authors commit to
|
|
||||||
using it. (Some other Free Software Foundation software is covered by
|
|
||||||
the GNU Lesser General Public License instead.) You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
this service if you wish), that you receive source code or can get it
|
|
||||||
if you want it, that you can change the software or use pieces of it
|
|
||||||
in new free programs; and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
|
||||||
anyone to deny you these rights or to ask you to surrender the rights.
|
|
||||||
These restrictions translate to certain responsibilities for you if you
|
|
||||||
distribute copies of the software, or if you modify it.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must give the recipients all the rights that
|
|
||||||
you have. You must make sure that they, too, receive or can get the
|
|
||||||
source code. And you must show them these terms so they know their
|
|
||||||
rights.
|
|
||||||
|
|
||||||
We protect your rights with two steps: (1) copyright the software, and
|
|
||||||
(2) offer you this license which gives you legal permission to copy,
|
|
||||||
distribute and/or modify the software.
|
|
||||||
|
|
||||||
Also, for each author's protection and ours, we want to make certain
|
|
||||||
that everyone understands that there is no warranty for this free
|
|
||||||
software. If the software is modified by someone else and passed on, we
|
|
||||||
want its recipients to know that what they have is not the original, so
|
|
||||||
that any problems introduced by others will not reflect on the original
|
|
||||||
authors' reputations.
|
|
||||||
|
|
||||||
Finally, any free program is threatened constantly by software
|
|
||||||
patents. We wish to avoid the danger that redistributors of a free
|
|
||||||
program will individually obtain patent licenses, in effect making the
|
|
||||||
program proprietary. To prevent this, we have made it clear that any
|
|
||||||
patent must be licensed for everyone's free use or not licensed at all.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License applies to any program or other work which contains
|
|
||||||
a notice placed by the copyright holder saying it may be distributed
|
|
||||||
under the terms of this General Public License. The "Program", below,
|
|
||||||
refers to any such program or work, and a "work based on the Program"
|
|
||||||
means either the Program or any derivative work under copyright law:
|
|
||||||
that is to say, a work containing the Program or a portion of it,
|
|
||||||
either verbatim or with modifications and/or translated into another
|
|
||||||
language. (Hereinafter, translation is included without limitation in
|
|
||||||
the term "modification".) Each licensee is addressed as "you".
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
|
||||||
covered by this License; they are outside its scope. The act of
|
|
||||||
running the Program is not restricted, and the output from the Program
|
|
||||||
is covered only if its contents constitute a work based on the
|
|
||||||
Program (independent of having been made by running the Program).
|
|
||||||
Whether that is true depends on what the Program does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Program's
|
|
||||||
source code as you receive it, in any medium, provided that you
|
|
||||||
conspicuously and appropriately publish on each copy an appropriate
|
|
||||||
copyright notice and disclaimer of warranty; keep intact all the
|
|
||||||
notices that refer to this License and to the absence of any warranty;
|
|
||||||
and give any other recipients of the Program a copy of this License
|
|
||||||
along with the Program.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy, and
|
|
||||||
you may at your option offer warranty protection in exchange for a fee.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Program or any portion
|
|
||||||
of it, thus forming a work based on the Program, and copy and
|
|
||||||
distribute such modifications or work under the terms of Section 1
|
|
||||||
above, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) You must cause the modified files to carry prominent notices
|
|
||||||
stating that you changed the files and the date of any change.
|
|
||||||
|
|
||||||
b) You must cause any work that you distribute or publish, that in
|
|
||||||
whole or in part contains or is derived from the Program or any
|
|
||||||
part thereof, to be licensed as a whole at no charge to all third
|
|
||||||
parties under the terms of this License.
|
|
||||||
|
|
||||||
c) If the modified program normally reads commands interactively
|
|
||||||
when run, you must cause it, when started running for such
|
|
||||||
interactive use in the most ordinary way, to print or display an
|
|
||||||
announcement including an appropriate copyright notice and a
|
|
||||||
notice that there is no warranty (or else, saying that you provide
|
|
||||||
a warranty) and that users may redistribute the program under
|
|
||||||
these conditions, and telling the user how to view a copy of this
|
|
||||||
License. (Exception: if the Program itself is interactive but
|
|
||||||
does not normally print such an announcement, your work based on
|
|
||||||
the Program is not required to print an announcement.)
|
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
|
||||||
identifiable sections of that work are not derived from the Program,
|
|
||||||
and can be reasonably considered independent and separate works in
|
|
||||||
themselves, then this License, and its terms, do not apply to those
|
|
||||||
sections when you distribute them as separate works. But when you
|
|
||||||
distribute the same sections as part of a whole which is a work based
|
|
||||||
on the Program, the distribution of the whole must be on the terms of
|
|
||||||
this License, whose permissions for other licensees extend to the
|
|
||||||
entire whole, and thus to each and every part regardless of who wrote it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
|
||||||
exercise the right to control the distribution of derivative or
|
|
||||||
collective works based on the Program.
|
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Program
|
|
||||||
with the Program (or with a work based on the Program) on a volume of
|
|
||||||
a storage or distribution medium does not bring the other work under
|
|
||||||
the scope of this License.
|
|
||||||
|
|
||||||
3. You may copy and distribute the Program (or a work based on it,
|
|
||||||
under Section 2) in object code or executable form under the terms of
|
|
||||||
Sections 1 and 2 above provided that you also do one of the following:
|
|
||||||
|
|
||||||
a) Accompany it with the complete corresponding machine-readable
|
|
||||||
source code, which must be distributed under the terms of Sections
|
|
||||||
1 and 2 above on a medium customarily used for software interchange; or,
|
|
||||||
|
|
||||||
b) Accompany it with a written offer, valid for at least three
|
|
||||||
years, to give any third party, for a charge no more than your
|
|
||||||
cost of physically performing source distribution, a complete
|
|
||||||
machine-readable copy of the corresponding source code, to be
|
|
||||||
distributed under the terms of Sections 1 and 2 above on a medium
|
|
||||||
customarily used for software interchange; or,
|
|
||||||
|
|
||||||
c) Accompany it with the information you received as to the offer
|
|
||||||
to distribute corresponding source code. (This alternative is
|
|
||||||
allowed only for noncommercial distribution and only if you
|
|
||||||
received the program in object code or executable form with such
|
|
||||||
an offer, in accord with Subsection b above.)
|
|
||||||
|
|
||||||
The source code for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For an executable work, complete source
|
|
||||||
code means all the source code for all modules it contains, plus any
|
|
||||||
associated interface definition files, plus the scripts used to
|
|
||||||
control compilation and installation of the executable. However, as a
|
|
||||||
special exception, the source code distributed need not include
|
|
||||||
anything that is normally distributed (in either source or binary
|
|
||||||
form) with the major components (compiler, kernel, and so on) of the
|
|
||||||
operating system on which the executable runs, unless that component
|
|
||||||
itself accompanies the executable.
|
|
||||||
|
|
||||||
If distribution of executable or object code is made by offering
|
|
||||||
access to copy from a designated place, then offering equivalent
|
|
||||||
access to copy the source code from the same place counts as
|
|
||||||
distribution of the source code, even though third parties are not
|
|
||||||
compelled to copy the source along with the object code.
|
|
||||||
|
|
||||||
4. You may not copy, modify, sublicense, or distribute the Program
|
|
||||||
except as expressly provided under this License. Any attempt
|
|
||||||
otherwise to copy, modify, sublicense or distribute the Program is
|
|
||||||
void, and will automatically terminate your rights under this License.
|
|
||||||
However, parties who have received copies, or rights, from you under
|
|
||||||
this License will not have their licenses terminated so long as such
|
|
||||||
parties remain in full compliance.
|
|
||||||
|
|
||||||
5. You are not required to accept this License, since you have not
|
|
||||||
signed it. However, nothing else grants you permission to modify or
|
|
||||||
distribute the Program or its derivative works. These actions are
|
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
|
||||||
modifying or distributing the Program (or any work based on the
|
|
||||||
Program), you indicate your acceptance of this License to do so, and
|
|
||||||
all its terms and conditions for copying, distributing or modifying
|
|
||||||
the Program or works based on it.
|
|
||||||
|
|
||||||
6. Each time you redistribute the Program (or any work based on the
|
|
||||||
Program), the recipient automatically receives a license from the
|
|
||||||
original licensor to copy, distribute or modify the Program subject to
|
|
||||||
these terms and conditions. You may not impose any further
|
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
|
||||||
You are not responsible for enforcing compliance by third parties to
|
|
||||||
this License.
|
|
||||||
|
|
||||||
7. If, as a consequence of a court judgment or allegation of patent
|
|
||||||
infringement or for any other reason (not limited to patent issues),
|
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot
|
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you
|
|
||||||
may not distribute the Program at all. For example, if a patent
|
|
||||||
license would not permit royalty-free redistribution of the Program by
|
|
||||||
all those who receive copies directly or indirectly through you, then
|
|
||||||
the only way you could satisfy both it and this License would be to
|
|
||||||
refrain entirely from distribution of the Program.
|
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under
|
|
||||||
any particular circumstance, the balance of the section is intended to
|
|
||||||
apply and the section as a whole is intended to apply in other
|
|
||||||
circumstances.
|
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
|
||||||
patents or other property right claims or to contest validity of any
|
|
||||||
such claims; this section has the sole purpose of protecting the
|
|
||||||
integrity of the free software distribution system, which is
|
|
||||||
implemented by public license practices. Many people have made
|
|
||||||
generous contributions to the wide range of software distributed
|
|
||||||
through that system in reliance on consistent application of that
|
|
||||||
system; it is up to the author/donor to decide if he or she is willing
|
|
||||||
to distribute software through any other system and a licensee cannot
|
|
||||||
impose that choice.
|
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
|
||||||
be a consequence of the rest of this License.
|
|
||||||
|
|
||||||
8. If the distribution and/or use of the Program is restricted in
|
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
|
||||||
original copyright holder who places the Program under this License
|
|
||||||
may add an explicit geographical distribution limitation excluding
|
|
||||||
those countries, so that distribution is permitted only in or among
|
|
||||||
countries not thus excluded. In such case, this License incorporates
|
|
||||||
the limitation as if written in the body of this License.
|
|
||||||
|
|
||||||
9. The Free Software Foundation may publish revised and/or new versions
|
|
||||||
of the General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Program
|
|
||||||
specifies a version number of this License which applies to it and "any
|
|
||||||
later version", you have the option of following the terms and conditions
|
|
||||||
either of that version or of any later version published by the Free
|
|
||||||
Software Foundation. If the Program does not specify a version number of
|
|
||||||
this License, you may choose any version ever published by the Free Software
|
|
||||||
Foundation.
|
|
||||||
|
|
||||||
10. If you wish to incorporate parts of the Program into other free
|
|
||||||
programs whose distribution conditions are different, write to the author
|
|
||||||
to ask for permission. For software which is copyrighted by the Free
|
|
||||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
|
||||||
make exceptions for this. Our decision will be guided by the two goals
|
|
||||||
of preserving the free status of all derivatives of our free software and
|
|
||||||
of promoting the sharing and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
|
||||||
|
|
||||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
|
||||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
|
||||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
|
||||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
|
||||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
|
||||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
|
||||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
|
||||||
REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
|
||||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
|
||||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
|
||||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
|
||||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
|
||||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|
||||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
convey the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program is interactive, make it output a short notice like this
|
|
||||||
when it starts in an interactive mode:
|
|
||||||
|
|
||||||
Gnomovision version 69, Copyright (C) year name of author
|
|
||||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, the commands you use may
|
|
||||||
be called something other than `show w' and `show c'; they could even be
|
|
||||||
mouse-clicks or menu items--whatever suits your program.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or your
|
|
||||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
|
||||||
necessary. Here is a sample; alter the names:
|
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
|
||||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1989
|
|
||||||
Ty Coon, President of Vice
|
|
||||||
|
|
||||||
This General Public License does not permit incorporating your program into
|
|
||||||
proprietary programs. If your program is a subroutine library, you may
|
|
||||||
consider it more useful to permit linking proprietary applications with the
|
|
||||||
library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License.
|
|
674
LICENSE.GPL-3
|
@ -1,674 +0,0 @@
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
24
Makefile
|
@ -1,24 +0,0 @@
|
||||||
# Common makefile -- loads make rules for each platform
|
|
||||||
|
|
||||||
OSTYPE=$(shell uname -s)
|
|
||||||
|
|
||||||
ifeq ($(OSTYPE),Darwin)
|
|
||||||
include make-mac.mk
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(OSTYPE),Linux)
|
|
||||||
include make-linux.mk
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(OSTYPE),FreeBSD)
|
|
||||||
CC=clang
|
|
||||||
CXX=clang++
|
|
||||||
ZT_BUILD_PLATFORM=7
|
|
||||||
include make-bsd.mk
|
|
||||||
endif
|
|
||||||
ifeq ($(OSTYPE),OpenBSD)
|
|
||||||
CC=egcc
|
|
||||||
CXX=eg++
|
|
||||||
ZT_BUILD_PLATFORM=9
|
|
||||||
include make-bsd.mk
|
|
||||||
endif
|
|
|
@ -1,64 +0,0 @@
|
||||||
ZeroTier Official Release Steps
|
|
||||||
======
|
|
||||||
|
|
||||||
This is mostly for ZeroTier internal use, but others who want to do builds might find it helpful.
|
|
||||||
|
|
||||||
Note: Many of these steps will require GPG and other signing keys that are kept in cold storage and must be mounted.
|
|
||||||
|
|
||||||
# Bumping the Version and Preparing Installers
|
|
||||||
|
|
||||||
The version must be incremented in all of the following files:
|
|
||||||
|
|
||||||
/version.h
|
|
||||||
/zerotier-one.spec
|
|
||||||
/debian/changelog
|
|
||||||
/ext/installfiles/mac/ZeroTier One.pkgproj
|
|
||||||
/ext/installfiles/windows/chocolatey/zerotier-one.nuspec
|
|
||||||
/ext/installfiles/windows/ZeroTier One.aip
|
|
||||||
/windows/WinUI/AboutView.xaml
|
|
||||||
|
|
||||||
The final .AIP file can only be edited on Windows with [Advanced Installer Enterprise](http://www.advancedinstaller.com/). In addition to incrementing the version be sure that a new product code is generated. (The "upgrade code" GUID on the other hand must never change.)
|
|
||||||
|
|
||||||
# Building for Supported Platforms
|
|
||||||
|
|
||||||
## Macintosh
|
|
||||||
|
|
||||||
Mac's easy. Just type:
|
|
||||||
|
|
||||||
make official
|
|
||||||
|
|
||||||
You will need [Packages](http://s.sudre.free.fr/Software/Packages/about.html) and our release signing key in the keychain.
|
|
||||||
|
|
||||||
## Linux
|
|
||||||
|
|
||||||
Mount the GPG key for *contact@zerotier.com* and then on an x86_64 box with a recent version of Docker and an Internet connection run:
|
|
||||||
|
|
||||||
make distclean
|
|
||||||
cd linux-build-farm
|
|
||||||
./build.sh
|
|
||||||
|
|
||||||
This will build i386 and x86_64 packages. Now ssh into our build Raspberry Pi and type `make debian` there to build the Raspbian armhf package. Copy it to `debian-jessie/` inside `linux-build-farm` so that it will be included in the repositories we generate. Now generate the YUM and APT repos:
|
|
||||||
|
|
||||||
rm -rf ~/.aptly*
|
|
||||||
rm -rf /tmp/zt-rpm-repo
|
|
||||||
./make-apt-repos.sh
|
|
||||||
./make-rpm-repos.sh
|
|
||||||
|
|
||||||
This will require the passphrase for *contact@zerotier.com*.
|
|
||||||
|
|
||||||
The contents of ~/.aptly/public must be published as `debian/` on `download.zerotier.com`. The contents of /tmp/zt-rpm-repo are published as `redhat/` on same.
|
|
||||||
|
|
||||||
## Windows
|
|
||||||
|
|
||||||
First load the Visual Studio solution and rebuild the UI and ZeroTier One in both x64 and i386 `Release` mode. Then load [Advanced Installer Enterprise](http://www.advancedinstaller.com/), check that the version is correct, and build. The build will fail if any build artifacts are missing, and Windows must have our product singing key (from DigiCert) available to sign the resulting MSI file. The MSI must then be tested on at least a few different CLEAN Windows VMs to ensure that the installer is valid and properly signed.
|
|
||||||
|
|
||||||
*After the MSI is published to download.zerotier.com in the proper RELEASE/#.#.#/dist subfolder for its version* the Chocolatey package must be rebuilt and published. Open a command prompt, change to `ext/installfiles/windows/chocolatey`, and type `choco pack`. Then use `choco push` to push it to Chocolatey (API key required).
|
|
||||||
|
|
||||||
choco pack
|
|
||||||
choco push zerotier-one.#.#.#.nupkg -s https://chocolatey.org/
|
|
||||||
|
|
||||||
Note that this does not cover rebuilding the drivers or their containing MSI projects, as this is typically not necessary and they are shipped in binary form in the repository for convenience.
|
|
||||||
|
|
||||||
## iOS, Android
|
|
||||||
|
|
||||||
... no docs here yet since this is done entirely out of band with regular installs.
|
|
125
README.md
|
@ -1,125 +0,0 @@
|
||||||
ZeroTier - A Planetary Ethernet Switch
|
|
||||||
======
|
|
||||||
|
|
||||||
ZeroTier is an enterprise Ethernet switch for planet Earth.
|
|
||||||
|
|
||||||
It erases the LAN/WAN distinction and makes VPNs, tunnels, proxies, and other kludges arising from the inflexible nature of physical networks obsolete. Everything is encrypted end-to-end and traffic takes the most direct (peer to peer) path available.
|
|
||||||
|
|
||||||
Visit [ZeroTier's site](https://www.zerotier.com/) for more information and [pre-built binary packages](https://www.zerotier.com/download.shtml). Apps for Android and iOS are available for free in the Google Play and Apple app stores.
|
|
||||||
|
|
||||||
### Getting Started
|
|
||||||
|
|
||||||
ZeroTier's basic operation is easy to understand. Devices have 10-digit *ZeroTier addresses* like `89e92ceee5` and networks have 16-digit network IDs like `8056c2e21c000001`. All it takes for a device to join a network is its 16-digit ID, and all it takes for a network to authorize a device is its 10-digit address. Everything else is automatic.
|
|
||||||
|
|
||||||
A "device" in our terminology is any "unit of compute" capable of talking to a network: desktops, laptops, phones, servers, VMs/VPSes, containers, and even user-space applications via our [SDK](https://github.com/zerotier/ZeroTierSDK).
|
|
||||||
|
|
||||||
For testing purposes we provide a public virtual network called *Earth* with network ID `8056c2e21c000001`. You can join it with:
|
|
||||||
|
|
||||||
sudo zerotier-cli join 8056c2e21c000001
|
|
||||||
|
|
||||||
Now wait about 30 seconds and check your system with `ip addr list` or `ifconfig`. You'll see a new interface whose name starts with *zt* and it should quickly get an IPv4 and an IPv6 address. Once you see it get an IP, try pinging `earth.zerotier.net` at `29.209.112.93`. If you've joined Earth from more than one system, try pinging your other machine. If you don't want to belong to a giant Ethernet party line anymore, just type:
|
|
||||||
|
|
||||||
sudo zerotier-cli leave 8056c2e21c000001
|
|
||||||
|
|
||||||
The *zt* interface will disappear. You're no longer on the network.
|
|
||||||
|
|
||||||
To create networks of your own, you'll need a network controller. ZeroTier One (for desktops and servers) includes controller functionality in its default build that can be configured via its JSON API (see [README.md in controller/](controller/)). ZeroTier provides a hosted solution with a nice web UI and SaaS add-ons at [my.zerotier.com](https://my.zerotier.com/). Basic controller functionality is free for up to 100 devices.
|
|
||||||
|
|
||||||
### Project Layout
|
|
||||||
|
|
||||||
- `artwork/`: icons, logos, etc.
|
|
||||||
- `attic/`: old stuff and experimental code that we want to keep around for reference.
|
|
||||||
- `controller/`: the reference network controller implementation, which is built and included by default on desktop and server build targets.
|
|
||||||
- `debian/`: files for building Debian packages on Linux.
|
|
||||||
- `doc/`: manual pages and other documentation.
|
|
||||||
- `ext/`: third party libraries, binaries that we ship for convenience on some platforms (Mac and Windows), and installation support files.
|
|
||||||
- `include/`: include files for the ZeroTier core.
|
|
||||||
- `java/`: a JNI wrapper used with our Android mobile app. (The whole Android app is not open source but may be made so in the future.)
|
|
||||||
- `macui/`: a Macintosh menu-bar app for controlling ZeroTier One, written in Objective C.
|
|
||||||
- `node/`: the ZeroTier virtual Ethernet switch core, which is designed to be entirely separate from the rest of the code and able to be built as a stand-alone OS-independent library. Note to developers: do not use C++11 features in here, since we want this to build on old embedded platforms that lack C++11 support. C++11 can be used elsewhere.
|
|
||||||
- `osdep/`: code to support and integrate with OSes, including platform-specific stuff only built for certain targets.
|
|
||||||
- `service/`: the ZeroTier One service, which wraps the ZeroTier core and provides VPN-like connectivity to virtual networks for desktops, laptops, servers, VMs, and containers.
|
|
||||||
- `tcp-proxy/`: TCP proxy code run by ZeroTier, Inc. to provide TCP fallback (this will die soon!).
|
|
||||||
- `windows/`: Visual Studio solution files, Windows service code for ZeroTier One, and the Windows task bar app UI.
|
|
||||||
|
|
||||||
The base path contains the ZeroTier One service main entry point (`one.cpp`), self test code, makefiles, etc.
|
|
||||||
|
|
||||||
### Build and Platform Notes
|
|
||||||
|
|
||||||
To build on Mac and Linux just type `make`. On FreeBSD and OpenBSD `gmake` (GNU make) is required and can be installed from packages or ports. For Windows there is a Visual Studio solution in `windows/'.
|
|
||||||
|
|
||||||
- **Mac**
|
|
||||||
- Xcode command line tools for OSX 10.7 or newer are required.
|
|
||||||
- Tap device driver kext source is in `ext/tap-mac` and a signed pre-built binary can be found in `ext/bin/tap-mac`. You should not need to build it yourself. It's a fork of [tuntaposx](http://tuntaposx.sourceforge.net) with device names changed to `zt#`, support for a larger MTU, and tun functionality removed.
|
|
||||||
- **Linux**
|
|
||||||
- The minimum compiler versions required are GCC/G++ 4.9.3 or CLANG/CLANG++ 3.4.2.
|
|
||||||
- Linux makefiles automatically detect and prefer clang/clang++ if present as it produces smaller and slightly faster binaries in most cases. You can override by supplying CC and CXX variables on the make command line.
|
|
||||||
- CentOS 7 ships with a version of GCC/G++ that is too old, but a new enough version of CLANG can be found in the *epel* repositories. Type `yum install epel-release` and then `yum install clang` to build there.
|
|
||||||
- **Windows**
|
|
||||||
- Windows 7 or newer (and equivalent server versions) are supported. This *may* work on Vista but you're on your own there. Windows XP is not supported since it lacks many important network API functions.
|
|
||||||
- We build with Visual Studio 2015. Older versions may not work with the solution file and project files we ship and may not have new enough C++11 support.
|
|
||||||
- Pre-built signed Windows drivers are included in `ext/bin/tap-windows-ndis6`. The MSI files found there will install them on 32-bit and 64-bit systems. (These are included in our multi-architecture installer as chained MSIs.)
|
|
||||||
- Windows builds are more painful in general than other platforms and are for the adventurous.
|
|
||||||
- **FreeBSD**
|
|
||||||
- Tested most recently on FreeBSD-11. Older versions may work but we're not sure.
|
|
||||||
- GCC/G++ 4.9 and gmake are required. These can be installed from packages or ports. Type `gmake` to build.
|
|
||||||
- **OpenBSD**
|
|
||||||
- There is a limit of four network memberships on OpenBSD as there are only four tap devices (`/dev/tap0` through `/dev/tap3`). We're not sure if this can be increased.
|
|
||||||
- OpenBSD lacks `getifmaddrs` (or any equivalent method) to get interface multicast memberships. As a result multicast will only work on OpenBSD for ARP and NDP (IP/MAC lookup) and not for other purposes.
|
|
||||||
- Only tested on OpenBSD 6.0. Older versions may not work.
|
|
||||||
- GCC/G++ 4.9 and gmake are required and can be installed using `pkg_add` or from ports. They get installed in `/usr/local/bin` as `egcc` and `eg++` and our makefile is pre-configured to use them on OpenBSD.
|
|
||||||
|
|
||||||
Typing `make selftest` will build a *zerotier-selftest* binary which unit tests various internals and reports on a few aspects of the build environment. It's a good idea to try this on novel platforms or architectures.
|
|
||||||
|
|
||||||
### Running
|
|
||||||
|
|
||||||
Running *zerotier-one* with -h will show help.
|
|
||||||
|
|
||||||
On Linux and BSD you can start the service with:
|
|
||||||
|
|
||||||
sudo ./zerotier-one -d
|
|
||||||
|
|
||||||
A home folder for your system will automatically be created.
|
|
||||||
|
|
||||||
The service is controlled via the JSON API, which by default is available at 127.0.0.1 port 9993. We include a *zerotier-cli* command line utility to make API calls for standard things like joining and leaving networks. The *authtoken.secret* file in the home folder contains the secret token for accessing this API. See README.md in [service/](service/) for API documentation.
|
|
||||||
|
|
||||||
Here's where home folders live (by default) on each OS:
|
|
||||||
|
|
||||||
* **Linux**: `/var/lib/zerotier-one`
|
|
||||||
* **FreeBSD** / **OpenBSD**: `/var/db/zerotier-one`
|
|
||||||
* **Mac**: `/Library/Application Support/ZeroTier/One`
|
|
||||||
* **Windows**: `\ProgramData\ZeroTier\One` (That's for Windows 7. The base 'shared app data' folder might be different on different Windows versions.)
|
|
||||||
|
|
||||||
Running ZeroTier One on a Mac is the same, but OSX requires a kernel extension. We ship a signed binary build of the ZeroTier tap device driver, which can be installed on Mac with:
|
|
||||||
|
|
||||||
sudo make install-mac-tap
|
|
||||||
|
|
||||||
This will create the home folder for Mac, place *tap.kext* there, and set its modes correctly to enable ZeroTier One to manage it with *kextload* and *kextunload*.
|
|
||||||
|
|
||||||
### Troubleshooting
|
|
||||||
|
|
||||||
For most users, it just works.
|
|
||||||
|
|
||||||
If you are running a local system firewall, we recommend adding a rule permitting UDP port 9993 inbound and outbound. If you installed binaries for Windows this should be done automatically. Other platforms might require manual editing of local firewall rules depending on your configuration.
|
|
||||||
|
|
||||||
The Mac firewall can be found under "Security" in System Preferences. Linux has a variety of firewall configuration systems and tools. If you're using Ubuntu's *ufw*, you can do this:
|
|
||||||
|
|
||||||
sudo ufw allow 9993/udp
|
|
||||||
|
|
||||||
On CentOS check `/etc/sysconfig/iptables` for IPTables rules. For other distributions consult your distribution's documentation. You'll also have to check the UIs or documentation for commercial third party firewall applications like Little Snitch (Mac), McAfee Firewall Enterprise (Windows), etc. if you are running any of those. Some corporate environments might have centrally managed firewall software, so you might also have to contact IT.
|
|
||||||
|
|
||||||
ZeroTier One peers will automatically locate each other and communicate directly over a local wired LAN *if UDP port 9993 inbound is open*. If that port is filtered, they won't be able to see each others' LAN announcement packets. If you're experiencing poor performance between devices on the same physical network, check their firewall settings. Without LAN auto-location peers must attempt "loopback" NAT traversal, which sometimes fails and in any case requires that every packet traverse your external router twice.
|
|
||||||
|
|
||||||
Users behind certain types of firewalls and "symmetric" NAT devices may not able able to connect to external peers directly at all. ZeroTier has limited support for port prediction and will *attempt* to traverse symmetric NATs, but this doesn't always work. If P2P connectivity fails you'll be bouncing UDP packets off our relay servers resulting in slower performance. Some NAT router(s) have a configurable NAT mode, and setting this to "full cone" will eliminate this problem. If you do this you may also see a magical improvement for things like VoIP phones, Skype, BitTorrent, WebRTC, certain games, etc., since all of these use NAT traversal techniques similar to ours.
|
|
||||||
|
|
||||||
If you're interested, there's a [technical deep dive about NAT traversal on our blog](https://www.zerotier.com/blog/?p=226). A troubleshooting tool to help you diagnose NAT issues is planned for the future as are uPnP/IGD/NAT-PMP and IPv6 transport.
|
|
||||||
|
|
||||||
If a firewall between you and the Internet blocks ZeroTier's UDP traffic, you will fall back to last-resort TCP tunneling to rootservers over port 443 (https impersonation). This will work almost anywhere but is *very slow* compared to UDP or direct peer to peer connectivity.
|
|
||||||
|
|
||||||
### Contributing
|
|
||||||
|
|
||||||
Please make pull requests against the `dev` branch. The `master` branch is release, and `edge` is for unstable and work in progress changes and is not likely to work.
|
|
||||||
|
|
||||||
### License
|
|
||||||
|
|
||||||
The ZeroTier source code is open source and is licensed under the GNU GPL v3 (not LGPL). If you'd like to embed it in a closed-source commercial product or appliance, please e-mail [contact@zerotier.com](mailto:contact@zerotier.com) to discuss commercial licensing. Otherwise it can be used for free.
|
|
138
RELEASE-NOTES.md
|
@ -1,138 +0,0 @@
|
||||||
ZeroTier Release Notes
|
|
||||||
======
|
|
||||||
|
|
||||||
# 2017-04-20 -- Version 1.2.4
|
|
||||||
|
|
||||||
* Managed routes are now only bifurcated for the default route. This is a change in behavior, though few people will probably notice. Bifurcating all managed routes was causing more trouble than it was worth for most users.
|
|
||||||
* Up to 2X crypto speedup on x86-64 (except Windows, which will take some porting) and 32-bit ARM platforms due to integration of fast assembly language implementations of Salsa20/12 from the [supercop](http://bench.cr.yp.to/supercop.html) code base. These were written by Daniel J. Bernstein and are in the public domain. My Macbook Pro (Core i5 2.8ghz) now does almost 1.5GiB/sec Salsa20/12 per core and a Raspberry Pi got a 2X boost. 64-bit ARM support and Windows support will take some work but should not be too hard.
|
|
||||||
* Refactored code that manages credentials to greatly reduce memory use in most cases. This may also result in a small performance improvement.
|
|
||||||
* Reworked and simplified path selection and priority logic to fix path instability and dead path persistence edge cases. There have been some sporadic reports of persistent path instabilities and dead paths hanging around that take minutes to resolve. These have proven difficult to reproduce in house, but hopefully this will fix them. In any case it seems to speed up path establishment in our tests and it makes the code simpler and more readable.
|
|
||||||
* Eliminated some unused cruft from the code around path management and in the peer class.
|
|
||||||
* Fixed an issue causing build problems on some MIPS architecture systems.
|
|
||||||
* Fixed Windows forgetting routes on sleep/wake or in some other circumstances. (GitHub issue #465)
|
|
||||||
|
|
||||||
# 2017-03-17 -- Version 1.2.2
|
|
||||||
|
|
||||||
* A bug causing unreliable multicast propagation (GitHub issue #461).
|
|
||||||
* A crash in ARM binaries due to a build chain and flags problem.
|
|
||||||
* A bug in the network controller preventing members from being listed (GitHub issue #460).
|
|
||||||
|
|
||||||
# 2017-03-14 -- Version 1.2.0
|
|
||||||
|
|
||||||
Version 1.2.0 is a major milestone release representing almost nine months of work. It includes our rules engine for distributed network packet filtering and security monitoring, federated roots, and many other architectural and UI improvements and bug fixes.
|
|
||||||
|
|
||||||
## New Features in 1.2.0
|
|
||||||
|
|
||||||
### The ZeroTier Rules Engine
|
|
||||||
|
|
||||||
The largest new feature in 1.2.0, and the product of many months of work, is our advanced network rules engine. With this release we achieve traffic control, security monitoring, and micro-segmentation capability on par with many enterprise SDN solutions designed for use in advanced data centers and corporate networks.
|
|
||||||
|
|
||||||
Rules allow you to filter packets on your network and vector traffic to security observers. Security observation can be performed in-band using REDIRECT or out of band using TEE.
|
|
||||||
|
|
||||||
Tags and capabilites provide advanced methods for implementing fine grained permission structures and micro-segmentation schemes without bloating the size and complexity of your rules table.
|
|
||||||
|
|
||||||
See the [rules engine announcement blog post](https://www.zerotier.com/blog/?p=927) for an in-depth discussion of theory and implementation. The [manual](https://www.zerotier.com/manual.shtml) contains detailed information on rule, tag, and capability use, and the `rule-compiler/` subfolder of the ZeroTier source tree contains a JavaScript function to compile rules in our human-readable rule definition language into rules suitable for import into a network controller. (ZeroTier Central uses this same script to compile rules on [my.zerotier.com](https://my.zerotier.com/).)
|
|
||||||
|
|
||||||
### Root Server Federation
|
|
||||||
|
|
||||||
It's now possible to create your own root servers and add them to the root server pool on your nodes. This is done by creating what's called a "moon," which is a signed enumeration of root servers and their stable points on the network. Refer to the [manual](https://www.zerotier.com/manual.shtml) for instructions.
|
|
||||||
|
|
||||||
Federated roots achieve a number of things:
|
|
||||||
|
|
||||||
* You can deploy your own infrastructure to reduce dependency on ours.
|
|
||||||
* You can deploy roots *inside your LAN* to ensure that network connectivity inside your facility still works if the Internet goes down. This is the first step toward making ZeroTier viable as an in-house SDN solution.
|
|
||||||
* Roots can be deployed inside national boundaries for countries with data residency laws or "great firewalls." (As of 1.2.0 there is still no way to force all traffic to use these roots, but that will be easy to do in a later version.)
|
|
||||||
* Last but not least this makes ZeroTier somewhat less centralized by eliminating any hard dependency on ZeroTier, Inc.'s infrastructure.
|
|
||||||
|
|
||||||
Our roots will of course remain and continue to provide zero-configuration instant-on deployment, a secure global authority for identities, and free traffic relaying for those who can't establish peer to peer connections.
|
|
||||||
|
|
||||||
### Local Configuration
|
|
||||||
|
|
||||||
An element of our design philosophy is "features are bugs." This isn't an absolute dogma but more of a guiding principle. We try as hard as we can to avoid adding features, especially "knobs" that must be tweaked by a user.
|
|
||||||
|
|
||||||
As of 1.2.0 we've decided that certain knobs are unavoidable, and so there is now a `local.conf` file that can be used to configure them. See the ZeroTier One documentation for these. They include:
|
|
||||||
|
|
||||||
* Blacklisting interfaces you want to make sure ZeroTier doesn't use for network traffic, such as VPNs, slow links, or backplanes designated for only certain kinds of traffic.
|
|
||||||
* Turning uPnP/NAT-PMP on or off.
|
|
||||||
* Configuring software updates on Windows and Mac platforms.
|
|
||||||
* Defining trusted paths (the old trusted paths file is now deprecated)
|
|
||||||
* Setting the ZeroTier main port so it doesn't have to be changed on the command line, which is very inconvenient in many cases.
|
|
||||||
|
|
||||||
### Improved In-Band Software Updates
|
|
||||||
|
|
||||||
A good software update system for Windows and Mac clients has been a missing feature in previous versions. It does exist but we've been shy about using it so far due to its fragility in some environments.
|
|
||||||
|
|
||||||
We've greatly improved this mechanism in 1.2.0. Not only does it now do a better job of actually invoking the update, but it also transfers updates in-band using the ZeroTier protocol. This means it can work in environments that do not allows http/https traffic or that force it through proxies. There's also now an update channel setting: `beta` or `release` (the default).
|
|
||||||
|
|
||||||
Software updates are authenticated three ways:
|
|
||||||
|
|
||||||
1. ZeroTier's own signing key is used to sign all updates and this signature is checked prior to installation. ZeroTier, Inc.'s signatures are performed on an air-gapped machine.
|
|
||||||
|
|
||||||
2. Updates for Mac and Windows are signed using Apple and Microsoft (DigiCert EV) keys and will not install unless these signatures are also valid.
|
|
||||||
|
|
||||||
3. The new in-band update mechanism also authenticates the source of the update via ZeroTier's built-in security features. This provides transport security, while 1 and 2 provide security of the update at rest.
|
|
||||||
|
|
||||||
Updates are now configurable via `local.conf`. There are three options: `disable`, `download`, and `apply`. The third (apply) is the default for official builds on Windows and Mac, making updates happen silently and automatically as they do for popular browsers like Chrome and Firefox. Updates are disabled by default on Linux and other Unix-type systems as these are typically updated through package managers.
|
|
||||||
|
|
||||||
### Path Link Quality Awareness
|
|
||||||
|
|
||||||
Version 1.2.0 is now aware of the link quality of direct paths with other 1.2.0 nodes. This information isn't used yet but is visible through the JSON API. (Quality always shows as 100% with pre-1.2.0 nodes.) Quality is measured passively with no additional overhead using a counter based packet loss detection algorithm.
|
|
||||||
|
|
||||||
This information is visible from the command line via `listpeers`:
|
|
||||||
|
|
||||||
200 listpeers XXXXXXXXXX 199.XXX.XXX.XXX/9993;10574;15250;1.00 48 1.2.0 LEAF
|
|
||||||
200 listpeers XXXXXXXXXX 195.XXX.XXX.XXX/45584;467;7608;0.44 290 1.2.0 LEAF
|
|
||||||
|
|
||||||
The first peer's path is at 100% (1.00), while the second peer's path is suffering quite a bit of packet loss (0.44).
|
|
||||||
|
|
||||||
Link quality awareness is a precursor to intelligent multi-path and QoS support, which will in future versions bring us to feature parity with SD-WAN products like Cisco iWAN.
|
|
||||||
|
|
||||||
### Security Improvements
|
|
||||||
|
|
||||||
Version 1.2.0 adds anti-DOS (denial of service) rate limits and other hardening for improved resiliency against a number of denial of service attack scenarios.
|
|
||||||
|
|
||||||
It also adds a mechanism for instantaneous credential revocation. This can be used to revoke certificates of membership instantly to kick a node off a network (for private networks) and also to revoke capabilities and tags. The new controller sends revocations by default when a peer is de-authorized.
|
|
||||||
|
|
||||||
Revocations propagate using a "rumor mill" peer to peer algorithm. This means that a controller need only successfully send a revocation to at least one member of a network with connections to other active members. At this point the revocation will flood through the network peer to peer very quickly. This helps make revocations more robust in the face of poor connectivity with the controller or attempts to incapacitate the controller with denial of service attacks, as well as making revocations faster on huge networks.
|
|
||||||
|
|
||||||
### Windows and Macintosh UI Improvements (ZeroTier One)
|
|
||||||
|
|
||||||
The Mac has a whole new UI built natively in Objective-C. It provides a pulldown similar in appearance and operation to the Mac WiFi task bar menu.
|
|
||||||
|
|
||||||
The Windows UI has also been improved and now provides a task bar icon that can be right-clicked to manage networks. Both now expose managed route and IP permissions, allowing nodes to easily opt in to full tunnel operation if you have a router configured on your network.
|
|
||||||
|
|
||||||
### Ad-Hoc Networks
|
|
||||||
|
|
||||||
A special kind of public network called an ad-hoc network may be accessed by joining a network ID with the format:
|
|
||||||
|
|
||||||
ffSSSSEEEE000000
|
|
||||||
| | | |
|
|
||||||
| | | Reserved for future use, must be 0
|
|
||||||
| | End of port range (hex)
|
|
||||||
| Start of port range (hex)
|
|
||||||
Reserved ZeroTier address prefix indicating a controller-less network
|
|
||||||
|
|
||||||
Ad-hoc networks are public (no access control) networks that have no network controller. Instead their configuration and other credentials are generated locally. Ad-hoc networks permit only IPv6 UDP and TCP unicast traffic (no multicast or broadcast) using 6plane format NDP-emulated IPv6 addresses. In addition an ad-hoc network ID encodes an IP port range. UDP packets and TCP SYN (connection open) packets are only allowed to desintation ports within the encoded range.
|
|
||||||
|
|
||||||
For example `ff00160016000000` is an ad-hoc network allowing only SSH, while `ff0000ffff000000` is an ad-hoc network allowing any UDP or TCP port.
|
|
||||||
|
|
||||||
Keep in mind that these networks are public and anyone in the entire world can join them. Care must be taken to avoid exposing vulnerable services or sharing unwanted files or other resources.
|
|
||||||
|
|
||||||
### Network Controller (Partial) Rewrite
|
|
||||||
|
|
||||||
The network controller has been largely rewritten to use a simple in-filesystem JSON data store in place of SQLite, and it is now included by default in all Windows, Mac, Linux, and BSD builds. This means any desktop or server node running ZeroTier One can now be a controller with no recompilation needed.
|
|
||||||
|
|
||||||
If you have data in an old SQLite3 controller we've included a NodeJS script in `controller/migrate-sqlite` to migrate data to the new format. If you don't migrate, members will start getting `NOT_FOUND` when they attempt to query for updates.
|
|
||||||
|
|
||||||
## Major Bug Fixes in 1.2.0
|
|
||||||
|
|
||||||
* **The Windows HyperV 100% CPU bug is FINALLY DEAD**: This long-running problem turns out to have been an issue with Windows itself, but one we were triggering by placing invalid data into the Windows registry. Microsoft is aware of the issue but we've also fixed the triggering problem on our side. ZeroTier should now co-exist quite well with HyperV and should now be able to be bridged with a HyperV virtual switch.
|
|
||||||
* **Segmenation faults on musl-libc based Linux systems**: Alpine Linux and some embedded Linux systems that use musl libc (a minimal libc) experienced segmentation faults. These were due to a smaller default stack size. A work-around that sets the stack size for new threads has been added.
|
|
||||||
* **Windows firewall blocks local JSON API**: On some Windows systems the firewall likes to block 127.0.0.1:9993 for mysterious reasons. This is now fixed in the installer via the addition of another firewall exemption rule.
|
|
||||||
* **UI crash on embedded Windows due to missing fonts**: The MSI installer now ships fonts and will install them if they are not present, so this should be fixed.
|
|
||||||
|
|
||||||
## Other Improvements in 1.2.0
|
|
||||||
|
|
||||||
* **Improved dead path detection**: ZeroTier is now more aggressive about expiring paths that do not seem to be active. If a path seems marginal it is re-confirmed before re-use.
|
|
||||||
* **Minor performance improvements**: We've reduced unnecessary memcpy's and made a few other performance improvements in the core.
|
|
||||||
* **Linux static binaries**: For our official packages (the ones in the download.zerotier.com apt and yum repositories) we now build Linux binaries with static linking. Hopefully this will stop all the bug reports relating to library inconsistencies, as well as allowing our deb packages to run on a wider variety of Debian-based distributions. (There are far too many of these to support officially!) The overhead for this is very small, especially since we built our static versions against musl-libc. Distribution maintainers are of course free to build dynamically linked versions for inclusion into distributions; this only affects our official binaries.
|
|
Before Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 74 KiB |
Before Width: | Height: | Size: 144 KiB |
Before Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 108 KiB |
Before Width: | Height: | Size: 126 KiB |
Before Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 361 KiB |
Before Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 50 KiB |
|
@ -1,37 +0,0 @@
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<style type="text/css">
|
|
||||||
html,body {
|
|
||||||
background: #aaaaaa;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
font-family: "Helvetica";
|
|
||||||
font-weight: bold;
|
|
||||||
font-size: 12pt;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
div.icon {
|
|
||||||
background: #ffb354;
|
|
||||||
color: #000000;
|
|
||||||
font-size: 150pt;
|
|
||||||
border-radius: 2.5rem;
|
|
||||||
display: inline-block;
|
|
||||||
width: 1.3em;
|
|
||||||
height: 1.3em;
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
line-height: 1.4em;
|
|
||||||
vertical-align: middle;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<br><br><br><br><br><br>
|
|
||||||
<!-- Yes, our logo is a Unicode character. It sort of just turned out that way. -->
|
|
||||||
<center>
|
|
||||||
<div class="icon">⏁</div>
|
|
||||||
</center>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
|
@ -1,650 +0,0 @@
|
||||||
/*
|
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
|
||||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* --
|
|
||||||
*
|
|
||||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
|
||||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
|
||||||
*
|
|
||||||
* If you would like to embed ZeroTier into a commercial application or
|
|
||||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
|
||||||
* LLC. Start here: http://www.zerotier.com/
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <sys/select.h>
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
#include <sys/uio.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <net/route.h>
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <net/if_arp.h>
|
|
||||||
#include <net/if_dl.h>
|
|
||||||
#include <net/if_media.h>
|
|
||||||
#include <netinet6/in6_var.h>
|
|
||||||
#include <netinet/in_var.h>
|
|
||||||
#include <netinet/icmp6.h>
|
|
||||||
|
|
||||||
#include <pcap/pcap.h>
|
|
||||||
|
|
||||||
// OSX compile fix... in6_var defines this in a struct which namespaces it for C++ ... why?!?
|
|
||||||
struct prf_ra {
|
|
||||||
u_char onlink : 1;
|
|
||||||
u_char autonomous : 1;
|
|
||||||
u_char reserved : 6;
|
|
||||||
} prf_ra;
|
|
||||||
|
|
||||||
#include <netinet6/nd6.h>
|
|
||||||
#include <ifaddrs.h>
|
|
||||||
|
|
||||||
// These are KERNEL_PRIVATE... why?
|
|
||||||
#ifndef SIOCAUTOCONF_START
|
|
||||||
#define SIOCAUTOCONF_START _IOWR('i', 132, struct in6_ifreq) /* accept rtadvd on this interface */
|
|
||||||
#endif
|
|
||||||
#ifndef SIOCAUTOCONF_STOP
|
|
||||||
#define SIOCAUTOCONF_STOP _IOWR('i', 133, struct in6_ifreq) /* stop accepting rtadv for this interface */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef ETH_ALEN
|
|
||||||
#define ETH_ALEN 6
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// This source is from:
|
|
||||||
// http://www.opensource.apple.com/source/Libinfo/Libinfo-406.17/gen.subproj/getifmaddrs.c?txt
|
|
||||||
// It's here because OSX 10.6 does not have this convenience function.
|
|
||||||
|
|
||||||
#define SALIGN (sizeof(uint32_t) - 1)
|
|
||||||
#define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : \
|
|
||||||
(SALIGN + 1))
|
|
||||||
#define MAX_SYSCTL_TRY 5
|
|
||||||
#define RTA_MASKS (RTA_GATEWAY | RTA_IFP | RTA_IFA)
|
|
||||||
|
|
||||||
/* FreeBSD uses NET_RT_IFMALIST and RTM_NEWMADDR from <sys/socket.h> */
|
|
||||||
/* We can use NET_RT_IFLIST2 and RTM_NEWMADDR2 on Darwin */
|
|
||||||
//#define DARWIN_COMPAT
|
|
||||||
|
|
||||||
//#ifdef DARWIN_COMPAT
|
|
||||||
#define GIM_SYSCTL_MIB NET_RT_IFLIST2
|
|
||||||
#define GIM_RTM_ADDR RTM_NEWMADDR2
|
|
||||||
//#else
|
|
||||||
//#define GIM_SYSCTL_MIB NET_RT_IFMALIST
|
|
||||||
//#define GIM_RTM_ADDR RTM_NEWMADDR
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
// Not in 10.6 includes so use our own
|
|
||||||
struct _intl_ifmaddrs {
|
|
||||||
struct _intl_ifmaddrs *ifma_next;
|
|
||||||
struct sockaddr *ifma_name;
|
|
||||||
struct sockaddr *ifma_addr;
|
|
||||||
struct sockaddr *ifma_lladdr;
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline int _intl_getifmaddrs(struct _intl_ifmaddrs **pif)
|
|
||||||
{
|
|
||||||
int icnt = 1;
|
|
||||||
int dcnt = 0;
|
|
||||||
int ntry = 0;
|
|
||||||
size_t len;
|
|
||||||
size_t needed;
|
|
||||||
int mib[6];
|
|
||||||
int i;
|
|
||||||
char *buf;
|
|
||||||
char *data;
|
|
||||||
char *next;
|
|
||||||
char *p;
|
|
||||||
struct ifma_msghdr2 *ifmam;
|
|
||||||
struct _intl_ifmaddrs *ifa, *ift;
|
|
||||||
struct rt_msghdr *rtm;
|
|
||||||
struct sockaddr *sa;
|
|
||||||
|
|
||||||
mib[0] = CTL_NET;
|
|
||||||
mib[1] = PF_ROUTE;
|
|
||||||
mib[2] = 0; /* protocol */
|
|
||||||
mib[3] = 0; /* wildcard address family */
|
|
||||||
mib[4] = GIM_SYSCTL_MIB;
|
|
||||||
mib[5] = 0; /* no flags */
|
|
||||||
do {
|
|
||||||
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
|
|
||||||
return (-1);
|
|
||||||
if ((buf = (char *)malloc(needed)) == NULL)
|
|
||||||
return (-1);
|
|
||||||
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
|
|
||||||
if (errno != ENOMEM || ++ntry >= MAX_SYSCTL_TRY) {
|
|
||||||
free(buf);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
free(buf);
|
|
||||||
buf = NULL;
|
|
||||||
}
|
|
||||||
} while (buf == NULL);
|
|
||||||
|
|
||||||
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
|
|
||||||
rtm = (struct rt_msghdr *)(void *)next;
|
|
||||||
if (rtm->rtm_version != RTM_VERSION)
|
|
||||||
continue;
|
|
||||||
switch (rtm->rtm_type) {
|
|
||||||
case GIM_RTM_ADDR:
|
|
||||||
ifmam = (struct ifma_msghdr2 *)(void *)rtm;
|
|
||||||
if ((ifmam->ifmam_addrs & RTA_IFA) == 0)
|
|
||||||
break;
|
|
||||||
icnt++;
|
|
||||||
p = (char *)(ifmam + 1);
|
|
||||||
for (i = 0; i < RTAX_MAX; i++) {
|
|
||||||
if ((RTA_MASKS & ifmam->ifmam_addrs &
|
|
||||||
(1 << i)) == 0)
|
|
||||||
continue;
|
|
||||||
sa = (struct sockaddr *)(void *)p;
|
|
||||||
len = SA_RLEN(sa);
|
|
||||||
dcnt += len;
|
|
||||||
p += len;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data = (char *)malloc(sizeof(struct _intl_ifmaddrs) * icnt + dcnt);
|
|
||||||
if (data == NULL) {
|
|
||||||
free(buf);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ifa = (struct _intl_ifmaddrs *)(void *)data;
|
|
||||||
data += sizeof(struct _intl_ifmaddrs) * icnt;
|
|
||||||
|
|
||||||
memset(ifa, 0, sizeof(struct _intl_ifmaddrs) * icnt);
|
|
||||||
ift = ifa;
|
|
||||||
|
|
||||||
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
|
|
||||||
rtm = (struct rt_msghdr *)(void *)next;
|
|
||||||
if (rtm->rtm_version != RTM_VERSION)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
switch (rtm->rtm_type) {
|
|
||||||
case GIM_RTM_ADDR:
|
|
||||||
ifmam = (struct ifma_msghdr2 *)(void *)rtm;
|
|
||||||
if ((ifmam->ifmam_addrs & RTA_IFA) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
p = (char *)(ifmam + 1);
|
|
||||||
for (i = 0; i < RTAX_MAX; i++) {
|
|
||||||
if ((RTA_MASKS & ifmam->ifmam_addrs &
|
|
||||||
(1 << i)) == 0)
|
|
||||||
continue;
|
|
||||||
sa = (struct sockaddr *)(void *)p;
|
|
||||||
len = SA_RLEN(sa);
|
|
||||||
switch (i) {
|
|
||||||
case RTAX_GATEWAY:
|
|
||||||
ift->ifma_lladdr =
|
|
||||||
(struct sockaddr *)(void *)data;
|
|
||||||
memcpy(data, p, len);
|
|
||||||
data += len;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RTAX_IFP:
|
|
||||||
ift->ifma_name =
|
|
||||||
(struct sockaddr *)(void *)data;
|
|
||||||
memcpy(data, p, len);
|
|
||||||
data += len;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RTAX_IFA:
|
|
||||||
ift->ifma_addr =
|
|
||||||
(struct sockaddr *)(void *)data;
|
|
||||||
memcpy(data, p, len);
|
|
||||||
data += len;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
data += len;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
p += len;
|
|
||||||
}
|
|
||||||
ift->ifma_next = ift + 1;
|
|
||||||
ift = ift->ifma_next;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(buf);
|
|
||||||
|
|
||||||
if (ift > ifa) {
|
|
||||||
ift--;
|
|
||||||
ift->ifma_next = NULL;
|
|
||||||
*pif = ifa;
|
|
||||||
} else {
|
|
||||||
*pif = NULL;
|
|
||||||
free(ifa);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void _intl_freeifmaddrs(struct _intl_ifmaddrs *ifmp)
|
|
||||||
{
|
|
||||||
free(ifmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <set>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "../node/Constants.hpp"
|
|
||||||
#include "../node/Utils.hpp"
|
|
||||||
#include "../node/Mutex.hpp"
|
|
||||||
#include "../node/Dictionary.hpp"
|
|
||||||
#include "OSUtils.hpp"
|
|
||||||
#include "OSXEthernetTap.hpp"
|
|
||||||
|
|
||||||
// ff:ff:ff:ff:ff:ff with no ADI
|
|
||||||
static const ZeroTier::MulticastGroup _blindWildcardMulticastGroup(ZeroTier::MAC(0xff),0);
|
|
||||||
|
|
||||||
static inline bool _setIpv6Stuff(const char *ifname,bool performNUD,bool acceptRouterAdverts)
|
|
||||||
{
|
|
||||||
struct in6_ndireq nd;
|
|
||||||
struct in6_ifreq ifr;
|
|
||||||
|
|
||||||
int s = socket(AF_INET6,SOCK_DGRAM,0);
|
|
||||||
if (s <= 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
memset(&nd,0,sizeof(nd));
|
|
||||||
strncpy(nd.ifname,ifname,sizeof(nd.ifname));
|
|
||||||
|
|
||||||
if (ioctl(s,SIOCGIFINFO_IN6,&nd)) {
|
|
||||||
close(s);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long oldFlags = (unsigned long)nd.ndi.flags;
|
|
||||||
|
|
||||||
if (performNUD)
|
|
||||||
nd.ndi.flags |= ND6_IFF_PERFORMNUD;
|
|
||||||
else nd.ndi.flags &= ~ND6_IFF_PERFORMNUD;
|
|
||||||
|
|
||||||
if (oldFlags != (unsigned long)nd.ndi.flags) {
|
|
||||||
if (ioctl(s,SIOCSIFINFO_FLAGS,&nd)) {
|
|
||||||
close(s);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&ifr,0,sizeof(ifr));
|
|
||||||
strncpy(ifr.ifr_name,ifname,sizeof(ifr.ifr_name));
|
|
||||||
if (ioctl(s,acceptRouterAdverts ? SIOCAUTOCONF_START : SIOCAUTOCONF_STOP,&ifr)) {
|
|
||||||
close(s);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
close(s);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
|
||||||
|
|
||||||
static std::set<std::string> globalDeviceNames;
|
|
||||||
static Mutex globalTapCreateLock;
|
|
||||||
|
|
||||||
OSXEthernetTap::OSXEthernetTap(
|
|
||||||
const char *homePath,
|
|
||||||
const MAC &mac,
|
|
||||||
unsigned int mtu,
|
|
||||||
unsigned int metric,
|
|
||||||
uint64_t nwid,
|
|
||||||
const char *friendlyName,
|
|
||||||
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *data,unsigned int len),
|
|
||||||
void *arg) :
|
|
||||||
_handler(handler),
|
|
||||||
_arg(arg),
|
|
||||||
_pcap((void *)0),
|
|
||||||
_nwid(nwid),
|
|
||||||
_mac(mac),
|
|
||||||
_homePath(homePath),
|
|
||||||
_mtu(mtu),
|
|
||||||
_metric(metric),
|
|
||||||
_enabled(true)
|
|
||||||
{
|
|
||||||
char errbuf[PCAP_ERRBUF_SIZE];
|
|
||||||
char devname[64],ethaddr[64],mtustr[32],metstr[32],nwids[32];
|
|
||||||
|
|
||||||
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
|
||||||
|
|
||||||
if (mtu > 2800)
|
|
||||||
throw std::runtime_error("max tap MTU is 2800");
|
|
||||||
|
|
||||||
Mutex::Lock _gl(globalTapCreateLock);
|
|
||||||
|
|
||||||
std::string desiredDevice;
|
|
||||||
Dictionary devmap;
|
|
||||||
{
|
|
||||||
std::string devmapbuf;
|
|
||||||
if (OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmapbuf)) {
|
|
||||||
devmap.fromString(devmapbuf);
|
|
||||||
desiredDevice = devmap.get(nwids,"");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((desiredDevice.length() >= 9)&&(desiredDevice.substr(0,6) == "bridge")) {
|
|
||||||
// length() >= 9 matches bridge### or bridge####
|
|
||||||
_dev = desiredDevice;
|
|
||||||
} else {
|
|
||||||
if (globalDeviceNames.size() >= (10000 - 128)) // sanity check... this would be nuts
|
|
||||||
throw std::runtime_error("too many devices!");
|
|
||||||
unsigned int pseudoBridgeNo = (unsigned int)((nwid ^ (nwid >> 32)) % (10000 - 128)) + 128; // range: bridge128 to bridge9999
|
|
||||||
sprintf(devname,"bridge%u",pseudoBridgeNo);
|
|
||||||
while (globalDeviceNames.count(std::string(devname)) > 0) {
|
|
||||||
++pseudoBridgeNo;
|
|
||||||
if (pseudoBridgeNo > 9999)
|
|
||||||
pseudoBridgeNo = 64;
|
|
||||||
sprintf(devname,"bridge%u",pseudoBridgeNo);
|
|
||||||
}
|
|
||||||
_dev = devname;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure MAC address and MTU, bring interface up
|
|
||||||
long cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"create",(const char *)0);
|
|
||||||
::_exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(cpid,&exitcode,0);
|
|
||||||
if (exitcode != 0)
|
|
||||||
throw std::runtime_error("ifconfig failure setting link-layer address and activating tap interface");
|
|
||||||
} else throw std::runtime_error("unable to fork()");
|
|
||||||
Utils::snprintf(ethaddr,sizeof(ethaddr),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)mac[0],(int)mac[1],(int)mac[2],(int)mac[3],(int)mac[4],(int)mac[5]);
|
|
||||||
Utils::snprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
|
||||||
Utils::snprintf(metstr,sizeof(metstr),"%u",_metric);
|
|
||||||
cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"lladdr",ethaddr,"mtu",mtustr,"metric",metstr,"up",(const char *)0);
|
|
||||||
::_exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(cpid,&exitcode,0);
|
|
||||||
if (exitcode != 0)
|
|
||||||
throw std::runtime_error("ifconfig failure setting link-layer address and activating tap interface");
|
|
||||||
} else throw std::runtime_error("unable to fork()");
|
|
||||||
|
|
||||||
_setIpv6Stuff(_dev.c_str(),true,false);
|
|
||||||
|
|
||||||
_pcap = (void *)pcap_create(_dev.c_str(),errbuf);
|
|
||||||
if (!_pcap) {
|
|
||||||
cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"destroy",(const char *)0);
|
|
||||||
::_exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(cpid,&exitcode,0);
|
|
||||||
}
|
|
||||||
throw std::runtime_error((std::string("pcap_create() on new bridge device failed: ") + errbuf).c_str());
|
|
||||||
}
|
|
||||||
pcap_set_promisc(reinterpret_cast<pcap_t *>(_pcap),1);
|
|
||||||
pcap_set_timeout(reinterpret_cast<pcap_t *>(_pcap),120000);
|
|
||||||
pcap_set_immediate_mode(reinterpret_cast<pcap_t *>(_pcap),1);
|
|
||||||
if (pcap_set_buffer_size(reinterpret_cast<pcap_t *>(_pcap),1024 * 1024 * 16) != 0) // 16MB
|
|
||||||
fprintf(stderr,"WARNING: pcap_set_buffer_size() failed!\n");
|
|
||||||
if (pcap_set_snaplen(reinterpret_cast<pcap_t *>(_pcap),4096) != 0)
|
|
||||||
fprintf(stderr,"WARNING: pcap_set_snaplen() failed!\n");
|
|
||||||
if (pcap_activate(reinterpret_cast<pcap_t *>(_pcap)) != 0) {
|
|
||||||
pcap_close(reinterpret_cast<pcap_t *>(_pcap));
|
|
||||||
cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"destroy",(const char *)0);
|
|
||||||
::_exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(cpid,&exitcode,0);
|
|
||||||
}
|
|
||||||
throw std::runtime_error("pcap_activate() on new bridge device failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
globalDeviceNames.insert(_dev);
|
|
||||||
|
|
||||||
devmap[nwids] = _dev;
|
|
||||||
OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmap.toString());
|
|
||||||
|
|
||||||
_thread = Thread::start(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
OSXEthernetTap::~OSXEthernetTap()
|
|
||||||
{
|
|
||||||
_enabled = false;
|
|
||||||
|
|
||||||
Mutex::Lock _gl(globalTapCreateLock);
|
|
||||||
globalDeviceNames.erase(_dev);
|
|
||||||
|
|
||||||
long cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"destroy",(const char *)0);
|
|
||||||
::_exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(cpid,&exitcode,0);
|
|
||||||
if (exitcode == 0) {
|
|
||||||
// Destroying the interface nukes pcap and terminates the thread.
|
|
||||||
Thread::join(_thread);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pcap_close(reinterpret_cast<pcap_t *>(_pcap));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ___removeIp(const std::string &_dev,const InetAddress &ip)
|
|
||||||
{
|
|
||||||
long cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"inet",ip.toIpString().c_str(),"-alias",(const char *)0);
|
|
||||||
_exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
waitpid(cpid,&exitcode,0);
|
|
||||||
return (exitcode == 0);
|
|
||||||
}
|
|
||||||
return false; // never reached, make compiler shut up about return value
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OSXEthernetTap::addIp(const InetAddress &ip)
|
|
||||||
{
|
|
||||||
if (!ip)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
std::vector<InetAddress> allIps(ips());
|
|
||||||
if (std::binary_search(allIps.begin(),allIps.end(),ip))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Remove and reconfigure if address is the same but netmask is different
|
|
||||||
for(std::vector<InetAddress>::iterator i(allIps.begin());i!=allIps.end();++i) {
|
|
||||||
if ((i->ipsEqual(ip))&&(i->netmaskBits() != ip.netmaskBits())) {
|
|
||||||
if (___removeIp(_dev,*i))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),ip.isV4() ? "inet" : "inet6",ip.toString().c_str(),"alias",(const char *)0);
|
|
||||||
::_exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(cpid,&exitcode,0);
|
|
||||||
return (exitcode == 0);
|
|
||||||
} // else return false...
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OSXEthernetTap::removeIp(const InetAddress &ip)
|
|
||||||
{
|
|
||||||
if (!ip)
|
|
||||||
return true;
|
|
||||||
std::vector<InetAddress> allIps(ips());
|
|
||||||
if (!std::binary_search(allIps.begin(),allIps.end(),ip)) {
|
|
||||||
if (___removeIp(_dev,ip))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<InetAddress> OSXEthernetTap::ips() const
|
|
||||||
{
|
|
||||||
struct ifaddrs *ifa = (struct ifaddrs *)0;
|
|
||||||
if (getifaddrs(&ifa))
|
|
||||||
return std::vector<InetAddress>();
|
|
||||||
|
|
||||||
std::vector<InetAddress> r;
|
|
||||||
|
|
||||||
struct ifaddrs *p = ifa;
|
|
||||||
while (p) {
|
|
||||||
if ((!strcmp(p->ifa_name,_dev.c_str()))&&(p->ifa_addr)&&(p->ifa_netmask)&&(p->ifa_addr->sa_family == p->ifa_netmask->sa_family)) {
|
|
||||||
switch(p->ifa_addr->sa_family) {
|
|
||||||
case AF_INET: {
|
|
||||||
struct sockaddr_in *sin = (struct sockaddr_in *)p->ifa_addr;
|
|
||||||
struct sockaddr_in *nm = (struct sockaddr_in *)p->ifa_netmask;
|
|
||||||
r.push_back(InetAddress(&(sin->sin_addr.s_addr),4,Utils::countBits((uint32_t)nm->sin_addr.s_addr)));
|
|
||||||
} break;
|
|
||||||
case AF_INET6: {
|
|
||||||
struct sockaddr_in6 *sin = (struct sockaddr_in6 *)p->ifa_addr;
|
|
||||||
struct sockaddr_in6 *nm = (struct sockaddr_in6 *)p->ifa_netmask;
|
|
||||||
uint32_t b[4];
|
|
||||||
memcpy(b,nm->sin6_addr.s6_addr,sizeof(b));
|
|
||||||
r.push_back(InetAddress(sin->sin6_addr.s6_addr,16,Utils::countBits(b[0]) + Utils::countBits(b[1]) + Utils::countBits(b[2]) + Utils::countBits(b[3])));
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p = p->ifa_next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ifa)
|
|
||||||
freeifaddrs(ifa);
|
|
||||||
|
|
||||||
std::sort(r.begin(),r.end());
|
|
||||||
std::unique(r.begin(),r.end());
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OSXEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
|
||||||
{
|
|
||||||
char putBuf[4096];
|
|
||||||
if ((len <= _mtu)&&(_enabled)) {
|
|
||||||
to.copyTo(putBuf,6);
|
|
||||||
from.copyTo(putBuf + 6,6);
|
|
||||||
*((uint16_t *)(putBuf + 12)) = htons((uint16_t)etherType);
|
|
||||||
memcpy(putBuf + 14,data,len);
|
|
||||||
len += 14;
|
|
||||||
int r = pcap_inject(reinterpret_cast<pcap_t *>(_pcap),putBuf,len);
|
|
||||||
if (r <= 0) {
|
|
||||||
printf("%s: pcap_inject() failed\n",_dev.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
printf("%s: inject %s -> %s etherType==%u len=%u r==%d\n",_dev.c_str(),from.toString().c_str(),to.toString().c_str(),etherType,len,r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string OSXEthernetTap::deviceName() const
|
|
||||||
{
|
|
||||||
return _dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OSXEthernetTap::setFriendlyName(const char *friendlyName)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void OSXEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed)
|
|
||||||
{
|
|
||||||
std::vector<MulticastGroup> newGroups;
|
|
||||||
|
|
||||||
struct _intl_ifmaddrs *ifmap = (struct _intl_ifmaddrs *)0;
|
|
||||||
if (!_intl_getifmaddrs(&ifmap)) {
|
|
||||||
struct _intl_ifmaddrs *p = ifmap;
|
|
||||||
while (p) {
|
|
||||||
if (p->ifma_addr->sa_family == AF_LINK) {
|
|
||||||
struct sockaddr_dl *in = (struct sockaddr_dl *)p->ifma_name;
|
|
||||||
struct sockaddr_dl *la = (struct sockaddr_dl *)p->ifma_addr;
|
|
||||||
if ((la->sdl_alen == 6)&&(in->sdl_nlen <= _dev.length())&&(!memcmp(_dev.data(),in->sdl_data,in->sdl_nlen)))
|
|
||||||
newGroups.push_back(MulticastGroup(MAC(la->sdl_data + la->sdl_nlen,6),0));
|
|
||||||
}
|
|
||||||
p = p->ifma_next;
|
|
||||||
}
|
|
||||||
_intl_freeifmaddrs(ifmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<InetAddress> allIps(ips());
|
|
||||||
for(std::vector<InetAddress>::iterator ip(allIps.begin());ip!=allIps.end();++ip)
|
|
||||||
newGroups.push_back(MulticastGroup::deriveMulticastGroupForAddressResolution(*ip));
|
|
||||||
|
|
||||||
std::sort(newGroups.begin(),newGroups.end());
|
|
||||||
std::unique(newGroups.begin(),newGroups.end());
|
|
||||||
|
|
||||||
for(std::vector<MulticastGroup>::iterator m(newGroups.begin());m!=newGroups.end();++m) {
|
|
||||||
if (!std::binary_search(_multicastGroups.begin(),_multicastGroups.end(),*m))
|
|
||||||
added.push_back(*m);
|
|
||||||
}
|
|
||||||
for(std::vector<MulticastGroup>::iterator m(_multicastGroups.begin());m!=_multicastGroups.end();++m) {
|
|
||||||
if (!std::binary_search(newGroups.begin(),newGroups.end(),*m))
|
|
||||||
removed.push_back(*m);
|
|
||||||
}
|
|
||||||
|
|
||||||
_multicastGroups.swap(newGroups);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _pcapHandler(u_char *ptr,const struct pcap_pkthdr *hdr,const u_char *data)
|
|
||||||
{
|
|
||||||
OSXEthernetTap *tap = reinterpret_cast<OSXEthernetTap *>(ptr);
|
|
||||||
if (hdr->caplen > 14) {
|
|
||||||
MAC to(data,6);
|
|
||||||
MAC from(data + 6,6);
|
|
||||||
if (from == tap->_mac) {
|
|
||||||
unsigned int etherType = ntohs(((const uint16_t *)data)[6]);
|
|
||||||
printf("%s: %s -> %s etherType==%u len==%u\n",tap->_dev.c_str(),from.toString().c_str(),to.toString().c_str(),etherType,(unsigned int)hdr->caplen);
|
|
||||||
// TODO: VLAN support
|
|
||||||
tap->_handler(tap->_arg,tap->_nwid,from,to,etherType,0,(const void *)(data + 14),hdr->len - 14);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OSXEthernetTap::threadMain()
|
|
||||||
throw()
|
|
||||||
{
|
|
||||||
pcap_loop(reinterpret_cast<pcap_t *>(_pcap),-1,&_pcapHandler,reinterpret_cast<u_char *>(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ZeroTier
|
|
|
@ -1,831 +0,0 @@
|
||||||
/*
|
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
|
||||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* --
|
|
||||||
*
|
|
||||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
|
||||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
|
||||||
*
|
|
||||||
* If you would like to embed ZeroTier into a commercial application or
|
|
||||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
|
||||||
* LLC. Start here: http://www.zerotier.com/
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <sys/select.h>
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
#include <sys/uio.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/sys_domain.h>
|
|
||||||
#include <sys/kern_control.h>
|
|
||||||
#include <net/if_utun.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <net/route.h>
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <net/if_arp.h>
|
|
||||||
#include <net/if_dl.h>
|
|
||||||
#include <net/if_media.h>
|
|
||||||
#include <netinet6/in6_var.h>
|
|
||||||
#include <netinet/in_var.h>
|
|
||||||
#include <netinet/icmp6.h>
|
|
||||||
|
|
||||||
// OSX compile fix... in6_var defines this in a struct which namespaces it for C++ ... why?!?
|
|
||||||
struct prf_ra {
|
|
||||||
u_char onlink : 1;
|
|
||||||
u_char autonomous : 1;
|
|
||||||
u_char reserved : 6;
|
|
||||||
} prf_ra;
|
|
||||||
|
|
||||||
#include <netinet6/nd6.h>
|
|
||||||
#include <ifaddrs.h>
|
|
||||||
|
|
||||||
// These are KERNEL_PRIVATE... why?
|
|
||||||
#ifndef SIOCAUTOCONF_START
|
|
||||||
#define SIOCAUTOCONF_START _IOWR('i', 132, struct in6_ifreq) /* accept rtadvd on this interface */
|
|
||||||
#endif
|
|
||||||
#ifndef SIOCAUTOCONF_STOP
|
|
||||||
#define SIOCAUTOCONF_STOP _IOWR('i', 133, struct in6_ifreq) /* stop accepting rtadv for this interface */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// This source is from:
|
|
||||||
// http://www.opensource.apple.com/source/Libinfo/Libinfo-406.17/gen.subproj/getifmaddrs.c?txt
|
|
||||||
// It's here because OSX 10.6 does not have this convenience function.
|
|
||||||
|
|
||||||
#define SALIGN (sizeof(uint32_t) - 1)
|
|
||||||
#define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : \
|
|
||||||
(SALIGN + 1))
|
|
||||||
#define MAX_SYSCTL_TRY 5
|
|
||||||
#define RTA_MASKS (RTA_GATEWAY | RTA_IFP | RTA_IFA)
|
|
||||||
|
|
||||||
/* FreeBSD uses NET_RT_IFMALIST and RTM_NEWMADDR from <sys/socket.h> */
|
|
||||||
/* We can use NET_RT_IFLIST2 and RTM_NEWMADDR2 on Darwin */
|
|
||||||
//#define DARWIN_COMPAT
|
|
||||||
|
|
||||||
//#ifdef DARWIN_COMPAT
|
|
||||||
#define GIM_SYSCTL_MIB NET_RT_IFLIST2
|
|
||||||
#define GIM_RTM_ADDR RTM_NEWMADDR2
|
|
||||||
//#else
|
|
||||||
//#define GIM_SYSCTL_MIB NET_RT_IFMALIST
|
|
||||||
//#define GIM_RTM_ADDR RTM_NEWMADDR
|
|
||||||
//#endif
|
|
||||||
|
|
||||||
// Not in 10.6 includes so use our own
|
|
||||||
struct _intl_ifmaddrs {
|
|
||||||
struct _intl_ifmaddrs *ifma_next;
|
|
||||||
struct sockaddr *ifma_name;
|
|
||||||
struct sockaddr *ifma_addr;
|
|
||||||
struct sockaddr *ifma_lladdr;
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline int _intl_getifmaddrs(struct _intl_ifmaddrs **pif)
|
|
||||||
{
|
|
||||||
int icnt = 1;
|
|
||||||
int dcnt = 0;
|
|
||||||
int ntry = 0;
|
|
||||||
size_t len;
|
|
||||||
size_t needed;
|
|
||||||
int mib[6];
|
|
||||||
int i;
|
|
||||||
char *buf;
|
|
||||||
char *data;
|
|
||||||
char *next;
|
|
||||||
char *p;
|
|
||||||
struct ifma_msghdr2 *ifmam;
|
|
||||||
struct _intl_ifmaddrs *ifa, *ift;
|
|
||||||
struct rt_msghdr *rtm;
|
|
||||||
struct sockaddr *sa;
|
|
||||||
|
|
||||||
mib[0] = CTL_NET;
|
|
||||||
mib[1] = PF_ROUTE;
|
|
||||||
mib[2] = 0; /* protocol */
|
|
||||||
mib[3] = 0; /* wildcard address family */
|
|
||||||
mib[4] = GIM_SYSCTL_MIB;
|
|
||||||
mib[5] = 0; /* no flags */
|
|
||||||
do {
|
|
||||||
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
|
|
||||||
return (-1);
|
|
||||||
if ((buf = (char *)malloc(needed)) == NULL)
|
|
||||||
return (-1);
|
|
||||||
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
|
|
||||||
if (errno != ENOMEM || ++ntry >= MAX_SYSCTL_TRY) {
|
|
||||||
free(buf);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
free(buf);
|
|
||||||
buf = NULL;
|
|
||||||
}
|
|
||||||
} while (buf == NULL);
|
|
||||||
|
|
||||||
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
|
|
||||||
rtm = (struct rt_msghdr *)(void *)next;
|
|
||||||
if (rtm->rtm_version != RTM_VERSION)
|
|
||||||
continue;
|
|
||||||
switch (rtm->rtm_type) {
|
|
||||||
case GIM_RTM_ADDR:
|
|
||||||
ifmam = (struct ifma_msghdr2 *)(void *)rtm;
|
|
||||||
if ((ifmam->ifmam_addrs & RTA_IFA) == 0)
|
|
||||||
break;
|
|
||||||
icnt++;
|
|
||||||
p = (char *)(ifmam + 1);
|
|
||||||
for (i = 0; i < RTAX_MAX; i++) {
|
|
||||||
if ((RTA_MASKS & ifmam->ifmam_addrs &
|
|
||||||
(1 << i)) == 0)
|
|
||||||
continue;
|
|
||||||
sa = (struct sockaddr *)(void *)p;
|
|
||||||
len = SA_RLEN(sa);
|
|
||||||
dcnt += len;
|
|
||||||
p += len;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data = (char *)malloc(sizeof(struct _intl_ifmaddrs) * icnt + dcnt);
|
|
||||||
if (data == NULL) {
|
|
||||||
free(buf);
|
|
||||||
return (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ifa = (struct _intl_ifmaddrs *)(void *)data;
|
|
||||||
data += sizeof(struct _intl_ifmaddrs) * icnt;
|
|
||||||
|
|
||||||
memset(ifa, 0, sizeof(struct _intl_ifmaddrs) * icnt);
|
|
||||||
ift = ifa;
|
|
||||||
|
|
||||||
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
|
|
||||||
rtm = (struct rt_msghdr *)(void *)next;
|
|
||||||
if (rtm->rtm_version != RTM_VERSION)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
switch (rtm->rtm_type) {
|
|
||||||
case GIM_RTM_ADDR:
|
|
||||||
ifmam = (struct ifma_msghdr2 *)(void *)rtm;
|
|
||||||
if ((ifmam->ifmam_addrs & RTA_IFA) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
p = (char *)(ifmam + 1);
|
|
||||||
for (i = 0; i < RTAX_MAX; i++) {
|
|
||||||
if ((RTA_MASKS & ifmam->ifmam_addrs &
|
|
||||||
(1 << i)) == 0)
|
|
||||||
continue;
|
|
||||||
sa = (struct sockaddr *)(void *)p;
|
|
||||||
len = SA_RLEN(sa);
|
|
||||||
switch (i) {
|
|
||||||
case RTAX_GATEWAY:
|
|
||||||
ift->ifma_lladdr =
|
|
||||||
(struct sockaddr *)(void *)data;
|
|
||||||
memcpy(data, p, len);
|
|
||||||
data += len;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RTAX_IFP:
|
|
||||||
ift->ifma_name =
|
|
||||||
(struct sockaddr *)(void *)data;
|
|
||||||
memcpy(data, p, len);
|
|
||||||
data += len;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RTAX_IFA:
|
|
||||||
ift->ifma_addr =
|
|
||||||
(struct sockaddr *)(void *)data;
|
|
||||||
memcpy(data, p, len);
|
|
||||||
data += len;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
data += len;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
p += len;
|
|
||||||
}
|
|
||||||
ift->ifma_next = ift + 1;
|
|
||||||
ift = ift->ifma_next;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(buf);
|
|
||||||
|
|
||||||
if (ift > ifa) {
|
|
||||||
ift--;
|
|
||||||
ift->ifma_next = NULL;
|
|
||||||
*pif = ifa;
|
|
||||||
} else {
|
|
||||||
*pif = NULL;
|
|
||||||
free(ifa);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void _intl_freeifmaddrs(struct _intl_ifmaddrs *ifmp)
|
|
||||||
{
|
|
||||||
free(ifmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <set>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "../node/Constants.hpp"
|
|
||||||
#include "../node/Utils.hpp"
|
|
||||||
#include "../node/Mutex.hpp"
|
|
||||||
#include "../node/Dictionary.hpp"
|
|
||||||
#include "Arp.hpp"
|
|
||||||
#include "OSUtils.hpp"
|
|
||||||
#include "OSXEthernetTap.hpp"
|
|
||||||
|
|
||||||
// ff:ff:ff:ff:ff:ff with no ADI
|
|
||||||
static const ZeroTier::MulticastGroup _blindWildcardMulticastGroup(ZeroTier::MAC(0xff),0);
|
|
||||||
|
|
||||||
static inline bool _setIpv6Stuff(const char *ifname,bool performNUD,bool acceptRouterAdverts)
|
|
||||||
{
|
|
||||||
struct in6_ndireq nd;
|
|
||||||
struct in6_ifreq ifr;
|
|
||||||
|
|
||||||
int s = socket(AF_INET6,SOCK_DGRAM,0);
|
|
||||||
if (s <= 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
memset(&nd,0,sizeof(nd));
|
|
||||||
strncpy(nd.ifname,ifname,sizeof(nd.ifname));
|
|
||||||
|
|
||||||
if (ioctl(s,SIOCGIFINFO_IN6,&nd)) {
|
|
||||||
close(s);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long oldFlags = (unsigned long)nd.ndi.flags;
|
|
||||||
|
|
||||||
if (performNUD)
|
|
||||||
nd.ndi.flags |= ND6_IFF_PERFORMNUD;
|
|
||||||
else nd.ndi.flags &= ~ND6_IFF_PERFORMNUD;
|
|
||||||
|
|
||||||
if (oldFlags != (unsigned long)nd.ndi.flags) {
|
|
||||||
if (ioctl(s,SIOCSIFINFO_FLAGS,&nd)) {
|
|
||||||
close(s);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&ifr,0,sizeof(ifr));
|
|
||||||
strncpy(ifr.ifr_name,ifname,sizeof(ifr.ifr_name));
|
|
||||||
if (ioctl(s,acceptRouterAdverts ? SIOCAUTOCONF_START : SIOCAUTOCONF_STOP,&ifr)) {
|
|
||||||
close(s);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
close(s);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create an OSX-native utun device (utun# where # is desiredNumber)
|
|
||||||
// Adapted from public domain utun example code by Jonathan Levin
|
|
||||||
static int _make_utun(int desiredNumber)
|
|
||||||
{
|
|
||||||
struct sockaddr_ctl sc;
|
|
||||||
struct ctl_info ctlInfo;
|
|
||||||
struct ifreq ifr;
|
|
||||||
|
|
||||||
memset(&ctlInfo, 0, sizeof(ctlInfo));
|
|
||||||
if (strlcpy(ctlInfo.ctl_name, UTUN_CONTROL_NAME, sizeof(ctlInfo.ctl_name)) >= sizeof(ctlInfo.ctl_name)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL);
|
|
||||||
if (fd == -1)
|
|
||||||
return -1;
|
|
||||||
if (ioctl(fd, CTLIOCGINFO, &ctlInfo) == -1) {
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sc.sc_id = ctlInfo.ctl_id;
|
|
||||||
sc.sc_len = sizeof(sc);
|
|
||||||
sc.sc_family = AF_SYSTEM;
|
|
||||||
sc.ss_sysaddr = AF_SYS_CONTROL;
|
|
||||||
sc.sc_unit = desiredNumber + 1;
|
|
||||||
|
|
||||||
if (connect(fd, (struct sockaddr *)&sc, sizeof(sc)) == -1) {
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&ifr,0,sizeof(ifr));
|
|
||||||
sprintf(ifr.ifr_name,"utun%d",desiredNumber);
|
|
||||||
if (ioctl(fd,SIOCGIFFLAGS,(void *)&ifr) < 0) {
|
|
||||||
printf("SIOCGIFFLAGS failed\n");
|
|
||||||
}
|
|
||||||
ifr.ifr_flags &= ~IFF_POINTOPOINT;
|
|
||||||
if (ioctl(fd,SIOCSIFFLAGS,(void *)&ifr) < 0) {
|
|
||||||
printf("clear IFF_POINTOPOINT failed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
|
||||||
|
|
||||||
static long globalTapsRunning = 0;
|
|
||||||
static Mutex globalTapCreateLock;
|
|
||||||
|
|
||||||
OSXEthernetTap::OSXEthernetTap(
|
|
||||||
const char *homePath,
|
|
||||||
const MAC &mac,
|
|
||||||
unsigned int mtu,
|
|
||||||
unsigned int metric,
|
|
||||||
uint64_t nwid,
|
|
||||||
const char *friendlyName,
|
|
||||||
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *data,unsigned int len),
|
|
||||||
void *arg) :
|
|
||||||
_handler(handler),
|
|
||||||
_arg(arg),
|
|
||||||
_arp((Arp *)0),
|
|
||||||
_nwid(nwid),
|
|
||||||
_homePath(homePath),
|
|
||||||
_mtu(mtu),
|
|
||||||
_metric(metric),
|
|
||||||
_fd(0),
|
|
||||||
_utun(false),
|
|
||||||
_enabled(true)
|
|
||||||
{
|
|
||||||
char devpath[64],ethaddr[64],mtustr[32],metstr[32],nwids[32];
|
|
||||||
struct stat stattmp;
|
|
||||||
|
|
||||||
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
|
||||||
|
|
||||||
if (mtu > 2800)
|
|
||||||
throw std::runtime_error("max tap MTU is 2800");
|
|
||||||
|
|
||||||
Mutex::Lock _gl(globalTapCreateLock);
|
|
||||||
|
|
||||||
// Read remembered previous device name, if any -- we'll try to reuse
|
|
||||||
Dictionary devmap;
|
|
||||||
std::string desiredDevice;
|
|
||||||
{
|
|
||||||
std::string devmapbuf;
|
|
||||||
if (OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmapbuf)) {
|
|
||||||
devmap.fromString(devmapbuf);
|
|
||||||
desiredDevice = devmap.get(nwids,"");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (::stat((_homePath + ZT_PATH_SEPARATOR_S + "tap.kext").c_str(),&stattmp) == 0) {
|
|
||||||
// Try to init kext if it's there, otherwise revert to utun mode
|
|
||||||
|
|
||||||
if (::stat("/dev/zt0",&stattmp)) {
|
|
||||||
long kextpid = (long)vfork();
|
|
||||||
if (kextpid == 0) {
|
|
||||||
::chdir(homePath);
|
|
||||||
OSUtils::redirectUnixOutputs("/dev/null",(const char *)0);
|
|
||||||
::execl("/sbin/kextload","/sbin/kextload","-q","-repository",homePath,"tap.kext",(const char *)0);
|
|
||||||
::_exit(-1);
|
|
||||||
} else if (kextpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(kextpid,&exitcode,0);
|
|
||||||
}
|
|
||||||
::usleep(500); // give tap device driver time to start up and try again
|
|
||||||
if (::stat("/dev/zt0",&stattmp))
|
|
||||||
_utun = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_utun) {
|
|
||||||
// See if we can re-use the last device we had.
|
|
||||||
bool recalledDevice = false;
|
|
||||||
if (desiredDevice.length() > 2) {
|
|
||||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",desiredDevice.c_str());
|
|
||||||
if (stat(devpath,&stattmp) == 0) {
|
|
||||||
_fd = ::open(devpath,O_RDWR);
|
|
||||||
if (_fd > 0) {
|
|
||||||
_dev = desiredDevice;
|
|
||||||
recalledDevice = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open the first unused tap device if we didn't recall a previous one.
|
|
||||||
if (!recalledDevice) {
|
|
||||||
for(int i=0;i<64;++i) {
|
|
||||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/zt%d",i);
|
|
||||||
if (stat(devpath,&stattmp)) {
|
|
||||||
_utun = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_fd = ::open(devpath,O_RDWR);
|
|
||||||
if (_fd > 0) {
|
|
||||||
char foo[16];
|
|
||||||
Utils::snprintf(foo,sizeof(foo),"zt%d",i);
|
|
||||||
_dev = foo;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (_fd <= 0)
|
|
||||||
_utun = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_utun = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_utun) {
|
|
||||||
// Use OSX built-in utun device if kext is not available or doesn't work
|
|
||||||
|
|
||||||
int utunNo = 0;
|
|
||||||
|
|
||||||
if ((desiredDevice.length() > 4)&&(desiredDevice.substr(0,4) == "utun")) {
|
|
||||||
utunNo = Utils::strToInt(desiredDevice.substr(4).c_str());
|
|
||||||
if (utunNo >= 0)
|
|
||||||
_fd = _make_utun(utunNo);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_fd <= 0) {
|
|
||||||
// Start at utun8 to leave lower utuns unused since other stuff might
|
|
||||||
// want them -- OpenVPN, cjdns, etc. I'm not sure if those are smart
|
|
||||||
// enough to scan upward like this.
|
|
||||||
for(utunNo=8;utunNo<=256;++utunNo) {
|
|
||||||
if ((_fd = _make_utun(utunNo)) > 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_fd <= 0)
|
|
||||||
throw std::runtime_error("unable to find/load ZeroTier tap driver OR use built-in utun driver in OSX; permission or system problem or too many open devices?");
|
|
||||||
|
|
||||||
Utils::snprintf(devpath,sizeof(devpath),"utun%d",utunNo);
|
|
||||||
_dev = devpath;
|
|
||||||
|
|
||||||
// Configure address and bring it up
|
|
||||||
Utils::snprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
|
||||||
Utils::snprintf(metstr,sizeof(metstr),"%u",_metric);
|
|
||||||
long cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"mtu",mtustr,"metric",metstr,"up",(const char *)0);
|
|
||||||
::_exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(cpid,&exitcode,0);
|
|
||||||
if (exitcode) {
|
|
||||||
::close(_fd);
|
|
||||||
throw std::runtime_error("ifconfig failure activating utun interface");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Use our ZeroTier OSX tun/tap driver for zt# Ethernet tap device
|
|
||||||
|
|
||||||
if (fcntl(_fd,F_SETFL,fcntl(_fd,F_GETFL) & ~O_NONBLOCK) == -1) {
|
|
||||||
::close(_fd);
|
|
||||||
throw std::runtime_error("unable to set flags on file descriptor for TAP device");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure MAC address and MTU, bring interface up
|
|
||||||
Utils::snprintf(ethaddr,sizeof(ethaddr),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)mac[0],(int)mac[1],(int)mac[2],(int)mac[3],(int)mac[4],(int)mac[5]);
|
|
||||||
Utils::snprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
|
||||||
Utils::snprintf(metstr,sizeof(metstr),"%u",_metric);
|
|
||||||
long cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"lladdr",ethaddr,"mtu",mtustr,"metric",metstr,"up",(const char *)0);
|
|
||||||
::_exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(cpid,&exitcode,0);
|
|
||||||
if (exitcode) {
|
|
||||||
::close(_fd);
|
|
||||||
throw std::runtime_error("ifconfig failure setting link-layer address and activating tap interface");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_setIpv6Stuff(_dev.c_str(),true,false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set close-on-exec so that devices cannot persist if we fork/exec for update
|
|
||||||
fcntl(_fd,F_SETFD,fcntl(_fd,F_GETFD) | FD_CLOEXEC);
|
|
||||||
|
|
||||||
::pipe(_shutdownSignalPipe);
|
|
||||||
|
|
||||||
++globalTapsRunning;
|
|
||||||
|
|
||||||
devmap[nwids] = _dev;
|
|
||||||
OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmap.toString());
|
|
||||||
|
|
||||||
_thread = Thread::start(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
OSXEthernetTap::~OSXEthernetTap()
|
|
||||||
{
|
|
||||||
Mutex::Lock _gl(globalTapCreateLock);
|
|
||||||
|
|
||||||
::write(_shutdownSignalPipe[1],(const void *)this,1); // writing a byte causes thread to exit
|
|
||||||
Thread::join(_thread);
|
|
||||||
|
|
||||||
::close(_fd);
|
|
||||||
::close(_shutdownSignalPipe[0]);
|
|
||||||
::close(_shutdownSignalPipe[1]);
|
|
||||||
|
|
||||||
if (_utun) {
|
|
||||||
delete _arp;
|
|
||||||
} else {
|
|
||||||
if (--globalTapsRunning <= 0) {
|
|
||||||
globalTapsRunning = 0; // sanity check -- should not be possible
|
|
||||||
|
|
||||||
char tmp[16384];
|
|
||||||
sprintf(tmp,"%s/%s",_homePath.c_str(),"tap.kext");
|
|
||||||
long kextpid = (long)vfork();
|
|
||||||
if (kextpid == 0) {
|
|
||||||
OSUtils::redirectUnixOutputs("/dev/null",(const char *)0);
|
|
||||||
::execl("/sbin/kextunload","/sbin/kextunload",tmp,(const char *)0);
|
|
||||||
::_exit(-1);
|
|
||||||
} else if (kextpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(kextpid,&exitcode,0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OSXEthernetTap::setEnabled(bool en)
|
|
||||||
{
|
|
||||||
_enabled = en;
|
|
||||||
// TODO: interface status change
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OSXEthernetTap::enabled() const
|
|
||||||
{
|
|
||||||
return _enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ___removeIp(const std::string &_dev,const InetAddress &ip)
|
|
||||||
{
|
|
||||||
long cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"inet",ip.toIpString().c_str(),"-alias",(const char *)0);
|
|
||||||
_exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
waitpid(cpid,&exitcode,0);
|
|
||||||
return (exitcode == 0);
|
|
||||||
}
|
|
||||||
return false; // never reached, make compiler shut up about return value
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OSXEthernetTap::addIp(const InetAddress &ip)
|
|
||||||
{
|
|
||||||
if (!ip)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
std::vector<InetAddress> allIps(ips());
|
|
||||||
if (std::binary_search(allIps.begin(),allIps.end(),ip))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Remove and reconfigure if address is the same but netmask is different
|
|
||||||
for(std::vector<InetAddress>::iterator i(allIps.begin());i!=allIps.end();++i) {
|
|
||||||
if ((i->ipsEqual(ip))&&(i->netmaskBits() != ip.netmaskBits())) {
|
|
||||||
if (___removeIp(_dev,*i))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_utun) {
|
|
||||||
long cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
if (ip.ss_family == AF_INET6) {
|
|
||||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"inet6",ip.toString().c_str(),"alias",(const char *)0);
|
|
||||||
} else {
|
|
||||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),ip.toString().c_str(),ip.toIpString().c_str(),"alias",(const char *)0);
|
|
||||||
}
|
|
||||||
::_exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(cpid,&exitcode,0);
|
|
||||||
|
|
||||||
if (exitcode == 0) {
|
|
||||||
if (ip.ss_family == AF_INET) {
|
|
||||||
// Add route to network over tun for IPv4 -- otherwise it behaves
|
|
||||||
// as a simple point to point tunnel instead of a true route.
|
|
||||||
cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
::close(STDERR_FILENO);
|
|
||||||
::close(STDOUT_FILENO);
|
|
||||||
::execl("/sbin/route","/sbin/route","add",ip.network().toString().c_str(),ip.toIpString().c_str(),(const char *)0);
|
|
||||||
::exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(cpid,&exitcode,0);
|
|
||||||
return (exitcode == 0);
|
|
||||||
}
|
|
||||||
} else return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
long cpid = (long)vfork();
|
|
||||||
if (cpid == 0) {
|
|
||||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),ip.isV4() ? "inet" : "inet6",ip.toString().c_str(),"alias",(const char *)0);
|
|
||||||
::_exit(-1);
|
|
||||||
} else if (cpid > 0) {
|
|
||||||
int exitcode = -1;
|
|
||||||
::waitpid(cpid,&exitcode,0);
|
|
||||||
return (exitcode == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OSXEthernetTap::removeIp(const InetAddress &ip)
|
|
||||||
{
|
|
||||||
if (!ip)
|
|
||||||
return true;
|
|
||||||
std::vector<InetAddress> allIps(ips());
|
|
||||||
if (!std::binary_search(allIps.begin(),allIps.end(),ip)) {
|
|
||||||
if (___removeIp(_dev,ip))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<InetAddress> OSXEthernetTap::ips() const
|
|
||||||
{
|
|
||||||
struct ifaddrs *ifa = (struct ifaddrs *)0;
|
|
||||||
if (getifaddrs(&ifa))
|
|
||||||
return std::vector<InetAddress>();
|
|
||||||
|
|
||||||
std::vector<InetAddress> r;
|
|
||||||
|
|
||||||
struct ifaddrs *p = ifa;
|
|
||||||
while (p) {
|
|
||||||
if ((!strcmp(p->ifa_name,_dev.c_str()))&&(p->ifa_addr)&&(p->ifa_netmask)&&(p->ifa_addr->sa_family == p->ifa_netmask->sa_family)) {
|
|
||||||
switch(p->ifa_addr->sa_family) {
|
|
||||||
case AF_INET: {
|
|
||||||
struct sockaddr_in *sin = (struct sockaddr_in *)p->ifa_addr;
|
|
||||||
struct sockaddr_in *nm = (struct sockaddr_in *)p->ifa_netmask;
|
|
||||||
r.push_back(InetAddress(&(sin->sin_addr.s_addr),4,Utils::countBits((uint32_t)nm->sin_addr.s_addr)));
|
|
||||||
} break;
|
|
||||||
case AF_INET6: {
|
|
||||||
struct sockaddr_in6 *sin = (struct sockaddr_in6 *)p->ifa_addr;
|
|
||||||
struct sockaddr_in6 *nm = (struct sockaddr_in6 *)p->ifa_netmask;
|
|
||||||
uint32_t b[4];
|
|
||||||
memcpy(b,nm->sin6_addr.s6_addr,sizeof(b));
|
|
||||||
r.push_back(InetAddress(sin->sin6_addr.s6_addr,16,Utils::countBits(b[0]) + Utils::countBits(b[1]) + Utils::countBits(b[2]) + Utils::countBits(b[3])));
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p = p->ifa_next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ifa)
|
|
||||||
freeifaddrs(ifa);
|
|
||||||
|
|
||||||
std::sort(r.begin(),r.end());
|
|
||||||
std::unique(r.begin(),r.end());
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OSXEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
|
||||||
{
|
|
||||||
char putBuf[4096];
|
|
||||||
if ((_fd > 0)&&(len <= _mtu)&&(_enabled)) {
|
|
||||||
to.copyTo(putBuf,6);
|
|
||||||
from.copyTo(putBuf + 6,6);
|
|
||||||
*((uint16_t *)(putBuf + 12)) = htons((uint16_t)etherType);
|
|
||||||
memcpy(putBuf + 14,data,len);
|
|
||||||
len += 14;
|
|
||||||
::write(_fd,putBuf,len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string OSXEthernetTap::deviceName() const
|
|
||||||
{
|
|
||||||
return _dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OSXEthernetTap::setFriendlyName(const char *friendlyName)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void OSXEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed)
|
|
||||||
{
|
|
||||||
std::vector<MulticastGroup> newGroups;
|
|
||||||
|
|
||||||
struct _intl_ifmaddrs *ifmap = (struct _intl_ifmaddrs *)0;
|
|
||||||
if (!_intl_getifmaddrs(&ifmap)) {
|
|
||||||
struct _intl_ifmaddrs *p = ifmap;
|
|
||||||
while (p) {
|
|
||||||
if (p->ifma_addr->sa_family == AF_LINK) {
|
|
||||||
struct sockaddr_dl *in = (struct sockaddr_dl *)p->ifma_name;
|
|
||||||
struct sockaddr_dl *la = (struct sockaddr_dl *)p->ifma_addr;
|
|
||||||
if ((la->sdl_alen == 6)&&(in->sdl_nlen <= _dev.length())&&(!memcmp(_dev.data(),in->sdl_data,in->sdl_nlen)))
|
|
||||||
newGroups.push_back(MulticastGroup(MAC(la->sdl_data + la->sdl_nlen,6),0));
|
|
||||||
}
|
|
||||||
p = p->ifma_next;
|
|
||||||
}
|
|
||||||
_intl_freeifmaddrs(ifmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<InetAddress> allIps(ips());
|
|
||||||
for(std::vector<InetAddress>::iterator ip(allIps.begin());ip!=allIps.end();++ip)
|
|
||||||
newGroups.push_back(MulticastGroup::deriveMulticastGroupForAddressResolution(*ip));
|
|
||||||
|
|
||||||
std::sort(newGroups.begin(),newGroups.end());
|
|
||||||
std::unique(newGroups.begin(),newGroups.end());
|
|
||||||
|
|
||||||
for(std::vector<MulticastGroup>::iterator m(newGroups.begin());m!=newGroups.end();++m) {
|
|
||||||
if (!std::binary_search(_multicastGroups.begin(),_multicastGroups.end(),*m))
|
|
||||||
added.push_back(*m);
|
|
||||||
}
|
|
||||||
for(std::vector<MulticastGroup>::iterator m(_multicastGroups.begin());m!=_multicastGroups.end();++m) {
|
|
||||||
if (!std::binary_search(newGroups.begin(),newGroups.end(),*m))
|
|
||||||
removed.push_back(*m);
|
|
||||||
}
|
|
||||||
|
|
||||||
_multicastGroups.swap(newGroups);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OSXEthernetTap::threadMain()
|
|
||||||
throw()
|
|
||||||
{
|
|
||||||
fd_set readfds,nullfds;
|
|
||||||
MAC to,from;
|
|
||||||
int n,nfds,r;
|
|
||||||
char getBuf[8194];
|
|
||||||
|
|
||||||
Thread::sleep(500);
|
|
||||||
|
|
||||||
FD_ZERO(&readfds);
|
|
||||||
FD_ZERO(&nullfds);
|
|
||||||
nfds = (int)std::max(_shutdownSignalPipe[0],_fd) + 1;
|
|
||||||
|
|
||||||
r = 0;
|
|
||||||
for(;;) {
|
|
||||||
FD_SET(_shutdownSignalPipe[0],&readfds);
|
|
||||||
FD_SET(_fd,&readfds);
|
|
||||||
select(nfds,&readfds,&nullfds,&nullfds,(struct timeval *)0);
|
|
||||||
|
|
||||||
if (FD_ISSET(_shutdownSignalPipe[0],&readfds)) // writes to shutdown pipe terminate thread
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (FD_ISSET(_fd,&readfds)) {
|
|
||||||
n = (int)::read(_fd,getBuf + r,sizeof(getBuf) - r);
|
|
||||||
if (n < 0) {
|
|
||||||
if ((errno != EINTR)&&(errno != ETIMEDOUT))
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
// Some tap drivers like to send the ethernet frame and the
|
|
||||||
// payload in two chunks, so handle that by accumulating
|
|
||||||
// data until we have at least a frame.
|
|
||||||
r += n;
|
|
||||||
if (r > 14) {
|
|
||||||
if (r > ((int)_mtu + 14)) // sanity check for weird TAP behavior on some platforms
|
|
||||||
r = _mtu + 14;
|
|
||||||
|
|
||||||
if (_enabled) {
|
|
||||||
to.setTo(getBuf,6);
|
|
||||||
from.setTo(getBuf + 6,6);
|
|
||||||
unsigned int etherType = ntohs(((const uint16_t *)getBuf)[6]);
|
|
||||||
// TODO: VLAN support
|
|
||||||
_handler(_arg,_nwid,from,to,etherType,0,(const void *)(getBuf + 14),r - 14);
|
|
||||||
}
|
|
||||||
|
|
||||||
r = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ZeroTier
|
|
|
@ -1,96 +0,0 @@
|
||||||
/*
|
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
|
||||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* --
|
|
||||||
*
|
|
||||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
|
||||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
|
||||||
*
|
|
||||||
* If you would like to embed ZeroTier into a commercial application or
|
|
||||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
|
||||||
* LLC. Start here: http://www.zerotier.com/
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZT_OSXETHERNETTAP_HPP
|
|
||||||
#define ZT_OSXETHERNETTAP_HPP
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "../node/Constants.hpp"
|
|
||||||
#include "../node/MAC.hpp"
|
|
||||||
#include "../node/InetAddress.hpp"
|
|
||||||
#include "../node/MulticastGroup.hpp"
|
|
||||||
|
|
||||||
#include "Thread.hpp"
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OSX Ethernet tap using ZeroTier kernel extension zt# devices
|
|
||||||
*/
|
|
||||||
class OSXEthernetTap
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
OSXEthernetTap(
|
|
||||||
const char *homePath,
|
|
||||||
const MAC &mac,
|
|
||||||
unsigned int mtu,
|
|
||||||
unsigned int metric,
|
|
||||||
uint64_t nwid,
|
|
||||||
const char *friendlyName,
|
|
||||||
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
|
|
||||||
void *arg);
|
|
||||||
|
|
||||||
~OSXEthernetTap();
|
|
||||||
|
|
||||||
inline void setEnabled(bool en) { _enabled = en; }
|
|
||||||
inline bool enabled() const { return _enabled; }
|
|
||||||
bool addIp(const InetAddress &ip);
|
|
||||||
bool removeIp(const InetAddress &ip);
|
|
||||||
std::vector<InetAddress> ips() const;
|
|
||||||
void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
|
||||||
std::string deviceName() const;
|
|
||||||
void setFriendlyName(const char *friendlyName);
|
|
||||||
void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
|
|
||||||
|
|
||||||
void threadMain()
|
|
||||||
throw();
|
|
||||||
|
|
||||||
// Private members of OSXEthernetTap have public visibility to be accessable
|
|
||||||
// from an internal bounce function; don't modify directly.
|
|
||||||
void (*_handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
|
|
||||||
void *_arg;
|
|
||||||
void *_pcap; // pcap_t *
|
|
||||||
uint64_t _nwid;
|
|
||||||
MAC _mac;
|
|
||||||
Thread _thread;
|
|
||||||
std::string _homePath;
|
|
||||||
std::string _dev;
|
|
||||||
std::vector<MulticastGroup> _multicastGroups;
|
|
||||||
unsigned int _mtu;
|
|
||||||
unsigned int _metric;
|
|
||||||
volatile bool _enabled;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ZeroTier
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,101 +0,0 @@
|
||||||
/*
|
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
|
||||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* --
|
|
||||||
*
|
|
||||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
|
||||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
|
||||||
*
|
|
||||||
* If you would like to embed ZeroTier into a commercial application or
|
|
||||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
|
||||||
* LLC. Start here: http://www.zerotier.com/
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZT_OSXETHERNETTAP_HPP
|
|
||||||
#define ZT_OSXETHERNETTAP_HPP
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "../node/Constants.hpp"
|
|
||||||
#include "../node/MAC.hpp"
|
|
||||||
#include "../node/InetAddress.hpp"
|
|
||||||
#include "../node/MulticastGroup.hpp"
|
|
||||||
|
|
||||||
#include "Thread.hpp"
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
|
||||||
|
|
||||||
class Arp;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OSX Ethernet tap supporting either ZeroTier tun/tap kext or OSX-native utun
|
|
||||||
*/
|
|
||||||
class OSXEthernetTap
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
OSXEthernetTap(
|
|
||||||
const char *homePath,
|
|
||||||
const MAC &mac,
|
|
||||||
unsigned int mtu,
|
|
||||||
unsigned int metric,
|
|
||||||
uint64_t nwid,
|
|
||||||
const char *friendlyName,
|
|
||||||
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
|
|
||||||
void *arg);
|
|
||||||
|
|
||||||
~OSXEthernetTap();
|
|
||||||
|
|
||||||
void setEnabled(bool en);
|
|
||||||
bool enabled() const;
|
|
||||||
bool addIp(const InetAddress &ip);
|
|
||||||
bool removeIp(const InetAddress &ip);
|
|
||||||
std::vector<InetAddress> ips() const;
|
|
||||||
void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
|
||||||
std::string deviceName() const;
|
|
||||||
void setFriendlyName(const char *friendlyName);
|
|
||||||
void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
|
|
||||||
|
|
||||||
inline bool isNativeUtun() const { return _utun; }
|
|
||||||
|
|
||||||
void threadMain()
|
|
||||||
throw();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void (*_handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
|
|
||||||
void *_arg;
|
|
||||||
Arp *_arp; // created and used if utun is enabled
|
|
||||||
uint64_t _nwid;
|
|
||||||
Thread _thread;
|
|
||||||
std::string _homePath;
|
|
||||||
std::string _dev;
|
|
||||||
std::vector<MulticastGroup> _multicastGroups;
|
|
||||||
unsigned int _mtu;
|
|
||||||
unsigned int _metric;
|
|
||||||
int _fd;
|
|
||||||
int _shutdownSignalPipe[2];
|
|
||||||
bool _utun;
|
|
||||||
volatile bool _enabled;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ZeroTier
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,4 +0,0 @@
|
||||||
Retired Code and Miscellaneous Junk
|
|
||||||
======
|
|
||||||
|
|
||||||
This directory is for old code that isn't used but we don't want to lose track of, and for anything else random like debug scripts.
|
|
|
@ -1,24 +0,0 @@
|
||||||
FROM centos:latest
|
|
||||||
|
|
||||||
MAINTAINER https://www.zerotier.com/
|
|
||||||
|
|
||||||
EXPOSE 9993/udp
|
|
||||||
|
|
||||||
ADD nodesource-el.repo /etc/yum.repos.d/nodesource-el.repo
|
|
||||||
RUN yum -y update && yum install -y nodejs && yum clean all
|
|
||||||
|
|
||||||
RUN mkdir -p /var/lib/zerotier-one
|
|
||||||
RUN mkdir -p /var/lib/zerotier-one/networks.d
|
|
||||||
RUN touch /var/lib/zerotier-one/networks.d/ffffffffffffffff.conf
|
|
||||||
|
|
||||||
ADD package.json /
|
|
||||||
RUN npm install
|
|
||||||
|
|
||||||
ADD zerotier-one /
|
|
||||||
RUN chmod a+x /zerotier-one
|
|
||||||
|
|
||||||
ADD agent.js /
|
|
||||||
ADD docker-main.sh /
|
|
||||||
RUN chmod a+x /docker-main.sh
|
|
||||||
|
|
||||||
CMD ["./docker-main.sh"]
|
|
|
@ -1,12 +0,0 @@
|
||||||
HTTP one-to-all test
|
|
||||||
======
|
|
||||||
|
|
||||||
*This is really internal use code. You're free to test it out but expect to do some editing/tweaking to make it work. We used this to run some massive scale tests of our new geo-cluster-based root server infrastructure prior to taking it live.*
|
|
||||||
|
|
||||||
Before using this code you will want to edit agent.js to change SERVER_HOST to the IP address of where you will run server.js. This should typically be an open Internet IP, since this makes reporting not dependent upon the thing being tested. Also note that this thing does no security of any kind. It's designed for one-off tests run over a short period of time, not to be anything that runs permanently. You will also want to edit the Dockerfile if you want to build containers and change the network ID to the network you want to run tests over.
|
|
||||||
|
|
||||||
This code can be deployed across a large number of VMs or containers to test and benchmark HTTP traffic within a virtual network at scale. The agent acts as a server and can query other agents, while the server collects agent data and tells agents about each other. It's designed to use RFC4193-based ZeroTier IPv6 addresses within the cluster, which allows the easy provisioning of a large cluster without IP conflicts.
|
|
||||||
|
|
||||||
The Dockerfile builds an image that launches the agent. The image must be "docker run" with "--device=/dev/net/tun --privileged" to permit it to open a tun/tap device within the container. (Unfortunately CAP_NET_ADMIN may not work due to a bug in Docker and/or Linux.) You can run a bunch with a command like:
|
|
||||||
|
|
||||||
for ((n=0;n<10;n++)); do docker run --device=/dev/net/tun --privileged -d zerotier/http-test; done
|
|
|
@ -1,196 +0,0 @@
|
||||||
// ZeroTier distributed HTTP test agent
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Customizable parameters:
|
|
||||||
|
|
||||||
// Time between startup and first test attempt
|
|
||||||
var TEST_STARTUP_LAG = 10000;
|
|
||||||
|
|
||||||
// Maximum interval between test attempts (actual timing is random % this)
|
|
||||||
var TEST_INTERVAL_MAX = (60000 * 10);
|
|
||||||
|
|
||||||
// Test timeout in ms
|
|
||||||
var TEST_TIMEOUT = 30000;
|
|
||||||
|
|
||||||
// Where should I get other agents' IDs and POST results?
|
|
||||||
var SERVER_HOST = '52.26.196.147';
|
|
||||||
var SERVER_PORT = 18080;
|
|
||||||
|
|
||||||
// Which port do agents use to serve up test data to each other?
|
|
||||||
var AGENT_PORT = 18888;
|
|
||||||
|
|
||||||
// Payload size in bytes
|
|
||||||
var PAYLOAD_SIZE = 5000;
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
var ipaddr = require('ipaddr.js');
|
|
||||||
var os = require('os');
|
|
||||||
var http = require('http');
|
|
||||||
var async = require('async');
|
|
||||||
|
|
||||||
var express = require('express');
|
|
||||||
var app = express();
|
|
||||||
|
|
||||||
// Find our ZeroTier-assigned RFC4193 IPv6 address
|
|
||||||
var thisAgentId = null;
|
|
||||||
var interfaces = os.networkInterfaces();
|
|
||||||
if (!interfaces) {
|
|
||||||
console.error('FATAL: os.networkInterfaces() failed.');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
for(var ifname in interfaces) {
|
|
||||||
var ifaddrs = interfaces[ifname];
|
|
||||||
if (Array.isArray(ifaddrs)) {
|
|
||||||
for(var i=0;i<ifaddrs.length;++i) {
|
|
||||||
if (ifaddrs[i].family == 'IPv6') {
|
|
||||||
try {
|
|
||||||
var ipbytes = ipaddr.parse(ifaddrs[i].address).toByteArray();
|
|
||||||
if ((ipbytes.length === 16)&&(ipbytes[0] == 0xfd)&&(ipbytes[9] == 0x99)&&(ipbytes[10] == 0x93)) {
|
|
||||||
thisAgentId = '';
|
|
||||||
for(var j=0;j<16;++j) {
|
|
||||||
var tmp = ipbytes[j].toString(16);
|
|
||||||
if (tmp.length === 1)
|
|
||||||
thisAgentId += '0';
|
|
||||||
thisAgentId += tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (thisAgentId === null) {
|
|
||||||
console.error('FATAL: no ZeroTier-assigned RFC4193 IPv6 addresses found on any local interface!');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//console.log(thisAgentId);
|
|
||||||
|
|
||||||
// Create a random (and therefore not very compressable) payload
|
|
||||||
var payload = new Buffer(PAYLOAD_SIZE);
|
|
||||||
for(var xx=0;xx<PAYLOAD_SIZE;++xx) {
|
|
||||||
payload.writeUInt8(Math.round(Math.random() * 255.0),xx);
|
|
||||||
}
|
|
||||||
|
|
||||||
function agentIdToIp(agentId)
|
|
||||||
{
|
|
||||||
var ip = '';
|
|
||||||
ip += agentId.substr(0,4);
|
|
||||||
ip += ':';
|
|
||||||
ip += agentId.substr(4,4);
|
|
||||||
ip += ':';
|
|
||||||
ip += agentId.substr(8,4);
|
|
||||||
ip += ':';
|
|
||||||
ip += agentId.substr(12,4);
|
|
||||||
ip += ':';
|
|
||||||
ip += agentId.substr(16,4);
|
|
||||||
ip += ':';
|
|
||||||
ip += agentId.substr(20,4);
|
|
||||||
ip += ':';
|
|
||||||
ip += agentId.substr(24,4);
|
|
||||||
ip += ':';
|
|
||||||
ip += agentId.substr(28,4);
|
|
||||||
return ip;
|
|
||||||
};
|
|
||||||
|
|
||||||
var lastTestResult = null;
|
|
||||||
var allOtherAgents = {};
|
|
||||||
|
|
||||||
function doTest()
|
|
||||||
{
|
|
||||||
var submit = http.request({
|
|
||||||
host: SERVER_HOST,
|
|
||||||
port: SERVER_PORT,
|
|
||||||
path: '/'+thisAgentId,
|
|
||||||
method: 'POST'
|
|
||||||
},function(res) {
|
|
||||||
var body = '';
|
|
||||||
res.on('data',function(chunk) { body += chunk.toString(); });
|
|
||||||
res.on('end',function() {
|
|
||||||
|
|
||||||
if (body) {
|
|
||||||
try {
|
|
||||||
var peers = JSON.parse(body);
|
|
||||||
if (Array.isArray(peers)) {
|
|
||||||
for(var xx=0;xx<peers.length;++xx)
|
|
||||||
allOtherAgents[peers[xx]] = true;
|
|
||||||
}
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
var agents = Object.keys(allOtherAgents);
|
|
||||||
if (agents.length > 1) {
|
|
||||||
|
|
||||||
var target = agents[Math.floor(Math.random() * agents.length)];
|
|
||||||
while (target === thisAgentId)
|
|
||||||
target = agents[Math.floor(Math.random() * agents.length)];
|
|
||||||
|
|
||||||
var testRequest = null;
|
|
||||||
var timeoutId = null;
|
|
||||||
timeoutId = setTimeout(function() {
|
|
||||||
if (testRequest !== null)
|
|
||||||
testRequest.abort();
|
|
||||||
timeoutId = null;
|
|
||||||
},TEST_TIMEOUT);
|
|
||||||
var startTime = Date.now();
|
|
||||||
|
|
||||||
testRequest = http.get({
|
|
||||||
host: agentIdToIp(target),
|
|
||||||
port: AGENT_PORT,
|
|
||||||
path: '/'
|
|
||||||
},function(res) {
|
|
||||||
var bytes = 0;
|
|
||||||
res.on('data',function(chunk) { bytes += chunk.length; });
|
|
||||||
res.on('end',function() {
|
|
||||||
lastTestResult = {
|
|
||||||
source: thisAgentId,
|
|
||||||
target: target,
|
|
||||||
time: (Date.now() - startTime),
|
|
||||||
bytes: bytes,
|
|
||||||
timedOut: (timeoutId === null),
|
|
||||||
error: null
|
|
||||||
};
|
|
||||||
if (timeoutId !== null)
|
|
||||||
clearTimeout(timeoutId);
|
|
||||||
return setTimeout(doTest,Math.round(Math.random() * TEST_INTERVAL_MAX) + 1);
|
|
||||||
});
|
|
||||||
}).on('error',function(e) {
|
|
||||||
lastTestResult = {
|
|
||||||
source: thisAgentId,
|
|
||||||
target: target,
|
|
||||||
time: (Date.now() - startTime),
|
|
||||||
bytes: 0,
|
|
||||||
timedOut: (timeoutId === null),
|
|
||||||
error: e.toString()
|
|
||||||
};
|
|
||||||
if (timeoutId !== null)
|
|
||||||
clearTimeout(timeoutId);
|
|
||||||
return setTimeout(doTest,Math.round(Math.random() * TEST_INTERVAL_MAX) + 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return setTimeout(doTest,1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}).on('error',function(e) {
|
|
||||||
console.log('POST failed: '+e.toString());
|
|
||||||
return setTimeout(doTest,1000);
|
|
||||||
});
|
|
||||||
if (lastTestResult !== null) {
|
|
||||||
submit.write(JSON.stringify(lastTestResult));
|
|
||||||
lastTestResult = null;
|
|
||||||
}
|
|
||||||
submit.end();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Agents just serve up a test payload
|
|
||||||
app.get('/',function(req,res) { return res.status(200).send(payload); });
|
|
||||||
|
|
||||||
var expressServer = app.listen(AGENT_PORT,function () {
|
|
||||||
// Start timeout-based loop
|
|
||||||
setTimeout(doTest(),TEST_STARTUP_LAG);
|
|
||||||
});
|
|
|
@ -1,9 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Kills all running Docker containers on all big-test-hosts
|
|
||||||
|
|
||||||
export PATH=/bin:/usr/bin:/usr/local/bin:/usr/sbin:/sbin
|
|
||||||
|
|
||||||
pssh -h big-test-hosts -x '-t -t' -i -OUserKnownHostsFile=/dev/null -OStrictHostKeyChecking=no -t 0 -p 256 "sudo docker ps -aq | xargs -r sudo docker rm -f"
|
|
||||||
|
|
||||||
exit 0
|
|
|
@ -1,13 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# More than 500 container seems to result in a lot of sporadic failures, probably due to Linux kernel scaling issues with virtual network ports
|
|
||||||
# 250 with a 16GB RAM VM like Amazon m4.xlarge seems good
|
|
||||||
NUM_CONTAINERS=250
|
|
||||||
CONTAINER_IMAGE=zerotier/http-test
|
|
||||||
SCALE_UP_DELAY=10
|
|
||||||
|
|
||||||
export PATH=/bin:/usr/bin:/usr/local/bin:/usr/sbin:/sbin
|
|
||||||
|
|
||||||
pssh -h big-test-hosts -x '-t -t' -i -OUserKnownHostsFile=/dev/null -OStrictHostKeyChecking=no -t 0 -p 256 "sudo sysctl -w net.netfilter.nf_conntrack_max=262144 ; for ((n=0;n<$NUM_CONTAINERS;n++)); do sudo docker run --device=/dev/net/tun --privileged -d $CONTAINER_IMAGE; sleep $SCALE_UP_DELAY; done"
|
|
||||||
|
|
||||||
exit 0
|
|
|
@ -1,65 +0,0 @@
|
||||||
//
|
|
||||||
// Pipe the output of server.js into this to convert raw test results into bracketed statistics
|
|
||||||
// suitable for graphing.
|
|
||||||
//
|
|
||||||
|
|
||||||
// Time duration per statistical bracket
|
|
||||||
var BRACKET_SIZE = 10000;
|
|
||||||
|
|
||||||
// Number of bytes expected from each test
|
|
||||||
var EXPECTED_BYTES = 5000;
|
|
||||||
|
|
||||||
var readline = require('readline');
|
|
||||||
var rl = readline.createInterface({
|
|
||||||
input: process.stdin,
|
|
||||||
output: process.stdout,
|
|
||||||
terminal: false
|
|
||||||
});
|
|
||||||
|
|
||||||
var count = 0.0;
|
|
||||||
var overallCount = 0.0;
|
|
||||||
var totalFailures = 0.0;
|
|
||||||
var totalOverallFailures = 0.0;
|
|
||||||
var totalMs = 0;
|
|
||||||
var totalData = 0;
|
|
||||||
var devices = {};
|
|
||||||
var lastBracketTs = 0;
|
|
||||||
|
|
||||||
rl.on('line',function(line) {
|
|
||||||
line = line.trim();
|
|
||||||
var ls = line.split(',');
|
|
||||||
if (ls.length == 7) {
|
|
||||||
var ts = parseInt(ls[0]);
|
|
||||||
var fromId = ls[1];
|
|
||||||
var toId = ls[2];
|
|
||||||
var ms = parseFloat(ls[3]);
|
|
||||||
var bytes = parseInt(ls[4]);
|
|
||||||
var timedOut = (ls[5] == 'true') ? true : false;
|
|
||||||
var errMsg = ls[6];
|
|
||||||
|
|
||||||
count += 1.0;
|
|
||||||
overallCount += 1.0;
|
|
||||||
if ((bytes !== EXPECTED_BYTES)||(timedOut)) {
|
|
||||||
totalFailures += 1.0;
|
|
||||||
totalOverallFailures += 1.0;
|
|
||||||
}
|
|
||||||
totalMs += ms;
|
|
||||||
totalData += bytes;
|
|
||||||
|
|
||||||
devices[fromId] = true;
|
|
||||||
devices[toId] = true;
|
|
||||||
|
|
||||||
if (lastBracketTs === 0)
|
|
||||||
lastBracketTs = ts;
|
|
||||||
|
|
||||||
if (((ts - lastBracketTs) >= BRACKET_SIZE)&&(count > 0.0)) {
|
|
||||||
console.log(count.toString()+','+overallCount.toString()+','+(totalMs / count)+','+(totalFailures / count)+','+(totalOverallFailures / overallCount)+','+totalData+','+Object.keys(devices).length);
|
|
||||||
|
|
||||||
count = 0.0;
|
|
||||||
totalFailures = 0.0;
|
|
||||||
totalMs = 0;
|
|
||||||
totalData = 0;
|
|
||||||
lastBracketTs = ts;
|
|
||||||
}
|
|
||||||
} // else ignore junk
|
|
||||||
});
|
|
|
@ -1,16 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
|
|
||||||
|
|
||||||
/zerotier-one -d >>zerotier-one.out 2>&1
|
|
||||||
|
|
||||||
# Wait for ZeroTier to start and join the network
|
|
||||||
while [ ! -d "/proc/sys/net/ipv6/conf/zt0" ]; do
|
|
||||||
sleep 0.25
|
|
||||||
done
|
|
||||||
|
|
||||||
# Wait just a bit longer for stuff to settle
|
|
||||||
sleep 5
|
|
||||||
|
|
||||||
exec node --harmony /agent.js >>agent.out 2>&1
|
|
||||||
#exec node --harmony /agent.js
|
|
|
@ -1,6 +0,0 @@
|
||||||
[nodesource]
|
|
||||||
name=Node.js Packages for Enterprise Linux 7 - $basearch
|
|
||||||
baseurl=https://rpm.nodesource.com/pub_4.x/el/7/$basearch
|
|
||||||
failovermethod=priority
|
|
||||||
enabled=1
|
|
||||||
gpgcheck=0
|
|
|
@ -1,16 +0,0 @@
|
||||||
{
|
|
||||||
"name": "zerotier-test-http",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "ZeroTier in-network HTTP test",
|
|
||||||
"main": "agent.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"author": "ZeroTier, Inc.",
|
|
||||||
"license": "GPL-3.0",
|
|
||||||
"dependencies": {
|
|
||||||
"async": "^1.5.0",
|
|
||||||
"express": "^4.13.3",
|
|
||||||
"ipaddr.js": "^1.0.3"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
// ZeroTier distributed HTTP test coordinator and result-reporting server
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Customizable parameters:
|
|
||||||
|
|
||||||
var SERVER_PORT = 18080;
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
var fs = require('fs');
|
|
||||||
|
|
||||||
var express = require('express');
|
|
||||||
var app = express();
|
|
||||||
|
|
||||||
app.use(function(req,res,next) {
|
|
||||||
req.rawBody = '';
|
|
||||||
req.on('data', function(chunk) { req.rawBody += chunk.toString(); });
|
|
||||||
req.on('end', function() { return next(); });
|
|
||||||
});
|
|
||||||
|
|
||||||
var knownAgents = {};
|
|
||||||
|
|
||||||
app.post('/:agentId',function(req,res) {
|
|
||||||
var agentId = req.params.agentId;
|
|
||||||
if ((!agentId)||(agentId.length !== 32))
|
|
||||||
return res.status(404).send('');
|
|
||||||
|
|
||||||
if (req.rawBody) {
|
|
||||||
var receiveTime = Date.now();
|
|
||||||
var resultData = null;
|
|
||||||
try {
|
|
||||||
resultData = JSON.parse(req.rawBody);
|
|
||||||
console.log(Date.now().toString()+','+resultData.source+','+resultData.target+','+resultData.time+','+resultData.bytes+','+resultData.timedOut+',"'+((resultData.error) ? resultData.error : '')+'"');
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
knownAgents[agentId] = true;
|
|
||||||
var thisUpdate = [];
|
|
||||||
var agents = Object.keys(knownAgents);
|
|
||||||
if (agents.length < 100)
|
|
||||||
thisUpdate = agents;
|
|
||||||
else {
|
|
||||||
for(var xx=0;xx<100;++xx)
|
|
||||||
thisUpdate.push(agents[Math.floor(Math.random() * agents.length)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.status(200).send(JSON.stringify(thisUpdate));
|
|
||||||
});
|
|
||||||
|
|
||||||
var expressServer = app.listen(SERVER_PORT,function () {
|
|
||||||
console.log('LISTENING ON '+SERVER_PORT);
|
|
||||||
console.log('');
|
|
||||||
});
|
|
|
@ -1,57 +0,0 @@
|
||||||
The new ZeroTier CLI!
|
|
||||||
====
|
|
||||||
|
|
||||||
With this update we've expanded upon the previous CLI's functionality, so things should seem pretty familiar. Here are some of the new features we've introduced:
|
|
||||||
|
|
||||||
- Create and administer networks on ZeroTier Central directly from the console.
|
|
||||||
- Service configurations, allows you to control local/remote instances of ZeroTier One
|
|
||||||
- Identity generation and management is now part of the same CLI tool
|
|
||||||
|
|
||||||
***
|
|
||||||
## Configurations
|
|
||||||
|
|
||||||
Configurations are a way for you to nickname and logically organize the control of ZeroTier services running locally or remotely (this includes ZeroTier Central!). They're merely groupings of service API url's and auth tokens. The CLI's settings data is contained within `.zerotierCliSettings`.
|
|
||||||
|
|
||||||
For instance, you can control your local instance of ZeroTier One via the `@local` config. By default it is represented as follows:
|
|
||||||
|
|
||||||
```
|
|
||||||
"local": {
|
|
||||||
"auth": "7tyqRoFytajf21j2l2t9QPm5",
|
|
||||||
"type": "one",
|
|
||||||
"url": "http://127.0.0.1:9993/"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
As an example, if you issue the command `zerotier ls` is it implicitly stating `zerotier @local ls`.
|
|
||||||
|
|
||||||
With the same line of thinking, you could create a `@my.zerotier.com` which would allow for something like `zerotier @my.zerotier.com net-create` which talks to our hosted ZeroTier Central to create a new network.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Command families
|
|
||||||
|
|
||||||
- `cli-` is for configuring the settings data for the CLI itself, such as adding/removing `@thing` configurations, variables, etc.
|
|
||||||
- `net-` is for operating on a *ZeroTier Central* service such as `https://my.zerotier.com`
|
|
||||||
- `id-` is for handling ZeroTier identities.
|
|
||||||
|
|
||||||
And those commands with no prefix are there to allow you to operate ZeroTier One instances either local or remote.
|
|
||||||
|
|
||||||
***
|
|
||||||
## Useful command examples
|
|
||||||
|
|
||||||
*Add a ZeroTier One configuration:*
|
|
||||||
|
|
||||||
- `zerotier cli-add-zt MyLocalConfigName https://127.0.0.1:9993/ <authtoken>`
|
|
||||||
|
|
||||||
*Add a ZeroTier Central configuration:*
|
|
||||||
|
|
||||||
- `zerotier cli-add-central MyZTCentralConfigName https://my.zerotier.com/ <centralAPIAuthtoken>`
|
|
||||||
|
|
||||||
*Set a default ZeroTier One instance:*
|
|
||||||
|
|
||||||
- `zerotier cli-set defaultOne MyLocalConfigName`
|
|
||||||
|
|
||||||
*Set a default ZeroTier Central:*
|
|
||||||
|
|
||||||
- `zerotier cli-set defaultCentral MyZTCentralConfigName`
|
|
||||||
|
|
|
@ -1,957 +0,0 @@
|
||||||
/*
|
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
|
||||||
* Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Note: unlike the rest of ZT's code base, this requires C++11 due to
|
|
||||||
// the JSON library it uses and other things.
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "../node/Constants.hpp"
|
|
||||||
#include "../node/Identity.hpp"
|
|
||||||
#include "../version.h"
|
|
||||||
#include "../osdep/OSUtils.hpp"
|
|
||||||
#include "../ext/offbase/json/json.hpp"
|
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
#include <WinSock2.h>
|
|
||||||
#include <windows.h>
|
|
||||||
#include <tchar.h>
|
|
||||||
#include <wchar.h>
|
|
||||||
#else
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
#include <tuple>
|
|
||||||
#include <regex>
|
|
||||||
|
|
||||||
#include <curl/curl.h>
|
|
||||||
|
|
||||||
using json = nlohmann::json;
|
|
||||||
using namespace ZeroTier;
|
|
||||||
|
|
||||||
#define ZT_CLI_FLAG_VERBOSE 'v'
|
|
||||||
#define ZT_CLI_FLAG_UNSAFE_SSL 'X'
|
|
||||||
|
|
||||||
#define REQ_GET 0
|
|
||||||
#define REQ_POST 1
|
|
||||||
#define REQ_DEL 2
|
|
||||||
|
|
||||||
#define OK_STR "[OK ]: "
|
|
||||||
#define FAIL_STR "[FAIL]: "
|
|
||||||
#define WARN_STR "[WARN]: "
|
|
||||||
#define INVALID_ARGS_STR "Invalid args. Usage: "
|
|
||||||
|
|
||||||
struct CLIState
|
|
||||||
{
|
|
||||||
std::string atname;
|
|
||||||
std::string command;
|
|
||||||
std::string url;
|
|
||||||
std::map<std::string,std::string> reqHeaders;
|
|
||||||
std::vector<std::string> args;
|
|
||||||
std::map<char,std::string> opts;
|
|
||||||
json settings;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
static Identity getIdFromArg(char *arg)
|
|
||||||
{
|
|
||||||
Identity id;
|
|
||||||
if ((strlen(arg) > 32)&&(arg[10] == ':')) { // identity is a literal on the command line
|
|
||||||
if (id.fromString(arg))
|
|
||||||
return id;
|
|
||||||
} else { // identity is to be read from a file
|
|
||||||
std::string idser;
|
|
||||||
if (OSUtils::readFile(arg,idser)) {
|
|
||||||
if (id.fromString(idser))
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Identity();
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string trimString(const std::string &s)
|
|
||||||
{
|
|
||||||
unsigned long end = (unsigned long)s.length();
|
|
||||||
while (end) {
|
|
||||||
char c = s[end - 1];
|
|
||||||
if ((c == ' ')||(c == '\r')||(c == '\n')||(!c)||(c == '\t'))
|
|
||||||
--end;
|
|
||||||
else break;
|
|
||||||
}
|
|
||||||
unsigned long start = 0;
|
|
||||||
while (start < end) {
|
|
||||||
char c = s[start];
|
|
||||||
if ((c == ' ')||(c == '\r')||(c == '\n')||(!c)||(c == '\t'))
|
|
||||||
++start;
|
|
||||||
else break;
|
|
||||||
}
|
|
||||||
return s.substr(start,end - start);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline std::string getSettingsFilePath()
|
|
||||||
{
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
#else
|
|
||||||
const char *home = getenv("HOME");
|
|
||||||
if (!home)
|
|
||||||
home = "/";
|
|
||||||
return (std::string(home) + "/.zerotierCliSettings");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool saveSettingsBackup(CLIState &state)
|
|
||||||
{
|
|
||||||
std::string sfp(getSettingsFilePath().c_str());
|
|
||||||
if(state.settings.find("generateBackupConfig") != state.settings.end()
|
|
||||||
&& state.settings["generateBackupConfig"].get<std::string>() == "true") {
|
|
||||||
std::string backup_file = getSettingsFilePath() + ".bak";
|
|
||||||
if(!OSUtils::writeFile(sfp.c_str(), state.settings.dump(2))) {
|
|
||||||
OSUtils::lockDownFile(sfp.c_str(),false);
|
|
||||||
std::cout << WARN_STR << "unable to write backup config file" << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool saveSettings(CLIState &state)
|
|
||||||
{
|
|
||||||
std::string sfp(getSettingsFilePath().c_str());
|
|
||||||
if(OSUtils::writeFile(sfp.c_str(), state.settings.dump(2))) {
|
|
||||||
OSUtils::lockDownFile(sfp.c_str(),false);
|
|
||||||
std::cout << OK_STR << "changes saved." << std::endl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
std::cout << FAIL_STR << "unable to write to " << sfp << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dumpHelp()
|
|
||||||
{
|
|
||||||
std::cout << "ZeroTier Newer-Spiffier CLI " << ZEROTIER_ONE_VERSION_MAJOR << "." << ZEROTIER_ONE_VERSION_MINOR << "." << ZEROTIER_ONE_VERSION_REVISION << std::endl;
|
|
||||||
std::cout << "(c)2016 ZeroTier, Inc. / Licensed under the GNU GPL v3" << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "Configuration path: " << getSettingsFilePath() << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "Usage: zerotier [-option] [@name] <command> [<command options>]" << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "Options:" << std::endl;
|
|
||||||
std::cout << " -verbose - Verbose JSON output" << std::endl;
|
|
||||||
std::cout << " -X - Do not check SSL certs (CAUTION!)" << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "CLI Configuration Commands:" << std::endl;
|
|
||||||
std::cout << " cli-set <setting> <value> - Set a CLI option ('cli-set help')" << std::endl;
|
|
||||||
std::cout << " cli-unset <setting> <value> - Un-sets a CLI option ('cli-unset help')" << std::endl;
|
|
||||||
std::cout << " cli-ls - List configured @things" << std::endl;
|
|
||||||
std::cout << " cli-rm @name - Remove a configured @thing" << std::endl;
|
|
||||||
std::cout << " cli-add-zt @name <url> <auth> - Add a ZeroTier service" << std::endl;
|
|
||||||
std::cout << " cli-add-central @name <url> <auth> - Add ZeroTier Central instance" << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "ZeroTier One Service Commands:" << std::endl;
|
|
||||||
std::cout << " -v / -version - Displays default local instance's version'" << std::endl;
|
|
||||||
std::cout << " ls - List currently joined networks" << std::endl;
|
|
||||||
std::cout << " join <network> [opt=value ...] - Join a network" << std::endl;
|
|
||||||
std::cout << " leave <network> - Leave a network" << std::endl;
|
|
||||||
std::cout << " peers - List ZeroTier VL1 peers" << std::endl;
|
|
||||||
std::cout << " show [<network/peer address>] - Get info about self or object" << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "Network Controller Commands:" << std::endl;
|
|
||||||
std::cout << " net-create - Create a new network" << std::endl;
|
|
||||||
std::cout << " net-rm <network> - Delete a network (CAUTION!)" << std::endl;
|
|
||||||
std::cout << " net-ls - List administered networks" << std::endl;
|
|
||||||
std::cout << " net-members <network> - List members of a network" << std::endl;
|
|
||||||
std::cout << " net-show <network> [<address>] - Get network or member info" << std::endl;
|
|
||||||
std::cout << " net-auth <network> <address> - Authorize a member" << std::endl;
|
|
||||||
std::cout << " net-unauth <network> <address> - De-authorize a member" << std::endl;
|
|
||||||
std::cout << " net-set <path> <value> - See 'net-set help'" << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "Identity Commands:" << std::endl;
|
|
||||||
std::cout << " id-generate [<vanity prefix>] - Generate a ZeroTier identity" << std::endl;
|
|
||||||
std::cout << " id-validate <identity> - Locally validate an identity" << std::endl;
|
|
||||||
std::cout << " id-sign <identity> <file> - Sign a file" << std::endl;
|
|
||||||
std::cout << " id-verify <secret> <file> <sig> - Verify a file's signature" << std::endl;
|
|
||||||
std::cout << " id-getpublic <secret> - Get full identity's public portion" << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t _curlStringAppendCallback(void *contents,size_t size,size_t nmemb,void *stdstring)
|
|
||||||
{
|
|
||||||
size_t totalSize = size * nmemb;
|
|
||||||
reinterpret_cast<std::string *>(stdstring)->append((const char *)contents,totalSize);
|
|
||||||
return totalSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::tuple<int,std::string> REQUEST(int requestType, CLIState &state, const std::map<std::string,std::string> &headers, const std::string &postfield, const std::string &url)
|
|
||||||
{
|
|
||||||
std::string body;
|
|
||||||
char errbuf[CURL_ERROR_SIZE];
|
|
||||||
char urlbuf[4096];
|
|
||||||
|
|
||||||
CURL *curl;
|
|
||||||
curl = curl_easy_init();
|
|
||||||
if (!curl) {
|
|
||||||
std::cerr << "FATAL: curl_easy_init() failed" << std::endl;
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Utils::scopy(urlbuf,sizeof(urlbuf),url.c_str());
|
|
||||||
curl_easy_setopt(curl,CURLOPT_URL,urlbuf);
|
|
||||||
|
|
||||||
struct curl_slist *hdrs = (struct curl_slist *)0;
|
|
||||||
for(std::map<std::string,std::string>::const_iterator i(headers.begin());i!=headers.end();++i) {
|
|
||||||
std::string htmp(i->first);
|
|
||||||
htmp.append(": ");
|
|
||||||
htmp.append(i->second);
|
|
||||||
hdrs = curl_slist_append(hdrs,htmp.c_str());
|
|
||||||
}
|
|
||||||
if (hdrs)
|
|
||||||
curl_easy_setopt(curl,CURLOPT_HTTPHEADER,hdrs);
|
|
||||||
|
|
||||||
//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
|
||||||
curl_easy_setopt(curl,CURLOPT_WRITEDATA,(void *)&body);
|
|
||||||
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,_curlStringAppendCallback);
|
|
||||||
|
|
||||||
if(std::find(state.args.begin(), state.args.end(), "-X") == state.args.end())
|
|
||||||
curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,(state.opts.count(ZT_CLI_FLAG_UNSAFE_SSL) > 0) ? 0L : 1L);
|
|
||||||
|
|
||||||
if(requestType == REQ_POST) {
|
|
||||||
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postfield.c_str());
|
|
||||||
}
|
|
||||||
if(requestType == REQ_DEL)
|
|
||||||
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
|
||||||
if(requestType == REQ_GET) {
|
|
||||||
curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,errbuf);
|
|
||||||
curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,0L);
|
|
||||||
}
|
|
||||||
|
|
||||||
curl_easy_setopt(curl,CURLOPT_USERAGENT,"ZeroTier-CLI");
|
|
||||||
CURLcode res = curl_easy_perform(curl);
|
|
||||||
|
|
||||||
errbuf[CURL_ERROR_SIZE-1] = (char)0; // sanity check
|
|
||||||
|
|
||||||
if (res != CURLE_OK)
|
|
||||||
return std::make_tuple(-1,std::string(errbuf));
|
|
||||||
|
|
||||||
long response_code;
|
|
||||||
int rc = (int)curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE, &response_code);
|
|
||||||
|
|
||||||
if(response_code == 401) { std::cout << FAIL_STR << response_code << "Unauthorized." << std::endl; exit(0); }
|
|
||||||
else if(response_code == 403) { std::cout << FAIL_STR << response_code << "Forbidden." << std::endl; exit(0); }
|
|
||||||
else if(response_code == 404) { std::cout << FAIL_STR << response_code << "Not found." << std::endl; exit(0); }
|
|
||||||
else if(response_code == 408) { std::cout << FAIL_STR << response_code << "Request timed out." << std::endl; exit(0); }
|
|
||||||
else if(response_code != 200) { std::cout << FAIL_STR << response_code << "Unable to process request." << std::endl; exit(0); }
|
|
||||||
|
|
||||||
curl_easy_cleanup(curl);
|
|
||||||
if (hdrs)
|
|
||||||
curl_slist_free_all(hdrs);
|
|
||||||
return std::make_tuple(response_code,body);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // anonymous namespace
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// Check for user-specified @thing config
|
|
||||||
// Make sure it @thing makes sense
|
|
||||||
// Apply appropriate request headers
|
|
||||||
static void checkForThing(CLIState &state, std::string thingType, bool warnNoThingProvided)
|
|
||||||
{
|
|
||||||
std::string configName;
|
|
||||||
if(state.atname.length()) {
|
|
||||||
configName = state.atname.erase(0,1);
|
|
||||||
// make sure specified @thing makes sense in the context of the command
|
|
||||||
if(thingType == "one" && state.settings["things"][configName]["type"].get<std::string>() != "one") {
|
|
||||||
std::cout << FAIL_STR << "A ZeroTier Central config was specified for a ZeroTier One command." << std::endl;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
if(thingType == "central" && state.settings["things"][configName]["type"].get<std::string>() != "central") {
|
|
||||||
std::cout << FAIL_STR << "A ZeroTier One config was specified for a ZeroTier Central command." << std::endl;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else { // no @thing specified, check for defaults depending on type
|
|
||||||
if(thingType == "one") {
|
|
||||||
if(state.settings.find("defaultOne") != state.settings.end()) {
|
|
||||||
if(warnNoThingProvided)
|
|
||||||
std::cout << WARN_STR << "No @thing specified, assuming default for ZeroTier One command: " << state.settings["defaultOne"].get<std::string>().c_str() << std::endl;
|
|
||||||
configName = state.settings["defaultOne"].get<std::string>().erase(0,1); // get default
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cout << WARN_STR << "No @thing specified, and no default is known." << std::endl;
|
|
||||||
std::cout << "HELP: To set a default: zerotier cli-set defaultOne @my_default_thing" << std::endl;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(thingType == "central") {
|
|
||||||
if(state.settings.find("defaultCentral") != state.settings.end()) {
|
|
||||||
if(warnNoThingProvided)
|
|
||||||
std::cout << WARN_STR << "No @thing specified, assuming default for ZeroTier Central command: " << state.settings["defaultCentral"].get<std::string>().c_str() << std::endl;
|
|
||||||
configName = state.settings["defaultCentral"].get<std::string>().erase(0,1); // get default
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cout << WARN_STR << "No @thing specified, and no default is known." << std::endl;
|
|
||||||
std::cout << "HELP: To set a default: zerotier cli-set defaultCentral @my_default_thing" << std::endl;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Apply headers
|
|
||||||
if(thingType == "one") {
|
|
||||||
state.reqHeaders["X-ZT1-Auth"] = state.settings["things"][configName]["auth"];
|
|
||||||
}
|
|
||||||
if(thingType == "central"){
|
|
||||||
state.reqHeaders["Content-Type"] = "application/json";
|
|
||||||
state.reqHeaders["Authorization"] = "Bearer " + state.settings["things"][configName]["auth"].get<std::string>();
|
|
||||||
state.reqHeaders["Accept"] = "application/json";
|
|
||||||
}
|
|
||||||
state.url = state.settings["things"][configName]["url"];
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool checkURL(std::string url)
|
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string getLocalVersion(CLIState &state)
|
|
||||||
{
|
|
||||||
json result;
|
|
||||||
std::tuple<int,std::string> res;
|
|
||||||
checkForThing(state,"one",false);
|
|
||||||
res = REQUEST(REQ_GET,state,state.reqHeaders,"",state.url + "/status");
|
|
||||||
if(std::get<0>(res) == 200) {
|
|
||||||
result = json::parse(std::get<1>(res));
|
|
||||||
return result["version"].get<std::string>();
|
|
||||||
}
|
|
||||||
return "---";
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
int _tmain(int argc, _TCHAR* argv[])
|
|
||||||
#else
|
|
||||||
int main(int argc,char **argv)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
{
|
|
||||||
WSADATA wsaData;
|
|
||||||
WSAStartup(MAKEWORD(2,2),&wsaData);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
|
||||||
CLIState state;
|
|
||||||
std::string arg1, arg2, authToken;
|
|
||||||
|
|
||||||
for(int i=1;i<argc;++i) {
|
|
||||||
if (argv[i][0] == '@') {
|
|
||||||
state.atname = argv[i];
|
|
||||||
}
|
|
||||||
else if (state.command.length() == 0) {
|
|
||||||
if (argv[i][0] == '-') {
|
|
||||||
if (!argv[i][1]) {
|
|
||||||
dumpHelp();
|
|
||||||
return -1;
|
|
||||||
} else if (argv[i][2]) {
|
|
||||||
state.opts[argv[i][1]] = argv[i] + 2;
|
|
||||||
} else {
|
|
||||||
state.opts[argv[i][1]] = "";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
state.command = argv[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
state.args.push_back(std::string(argv[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
std::string buf;
|
|
||||||
if (OSUtils::readFile(getSettingsFilePath().c_str(),buf))
|
|
||||||
state.settings = json::parse(buf);
|
|
||||||
|
|
||||||
if (state.settings.empty()) {
|
|
||||||
// Default settings
|
|
||||||
state.settings = {
|
|
||||||
{ "configVersion", 1 },
|
|
||||||
{ "things", {
|
|
||||||
{ "my.zerotier.com", {
|
|
||||||
{ "type", "central" },
|
|
||||||
{ "url", "https://my.zerotier.com/" },
|
|
||||||
{ "auth", "" }
|
|
||||||
}},
|
|
||||||
{ "local", {
|
|
||||||
{ "type", "one" },
|
|
||||||
{ "url", "" },
|
|
||||||
{ "auth", "" }
|
|
||||||
}}
|
|
||||||
}},
|
|
||||||
{ "defaultController", "@my.zerotier.com" },
|
|
||||||
{ "defaultOne", "@local" }
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string oneHome(OSUtils::platformDefaultHomePath());
|
|
||||||
std::string portStr;
|
|
||||||
bool initSuccess = false;
|
|
||||||
std::string path = oneHome + ZT_PATH_SEPARATOR_S ;
|
|
||||||
if (OSUtils::readFile((oneHome + ZT_PATH_SEPARATOR_S + "authtoken.secret").c_str(),authToken)&&OSUtils::readFile((oneHome + ZT_PATH_SEPARATOR_S + "zerotier-one.port").c_str(),portStr)) {
|
|
||||||
portStr = trimString(portStr);
|
|
||||||
authToken = trimString(authToken);
|
|
||||||
int port = Utils::strToInt(portStr.c_str());
|
|
||||||
if (((port > 0)&&(port < 65536))&&(authToken.length() > 0)) {
|
|
||||||
state.settings["things"]["local"]["url"] = (std::string("http://127.0.0.1:") + portStr + "/");
|
|
||||||
state.settings["things"]["local"]["auth"] = authToken;
|
|
||||||
initSuccess = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!saveSettings(state)) {
|
|
||||||
std::cerr << "FATAL: unable to write " << getSettingsFilePath() << std::endl;
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (initSuccess) {
|
|
||||||
std::cerr << "INFO: initialized new config at " << getSettingsFilePath() << std::endl;
|
|
||||||
} else {
|
|
||||||
std::cerr << "INFO: initialized new config at " << getSettingsFilePath() << " but could not auto-init local ZeroTier One service config from " << oneHome << " -- you will need to set local service URL and port manually if you want to control a local instance of ZeroTier One. (This happens if you are not root/administrator.)" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PRE-REQUEST SETUP
|
|
||||||
|
|
||||||
json result;
|
|
||||||
std::tuple<int,std::string> res;
|
|
||||||
std::string url = "";
|
|
||||||
|
|
||||||
// META
|
|
||||||
|
|
||||||
if ((state.command.length() == 0)||(state.command == "help")) {
|
|
||||||
dumpHelp();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier version
|
|
||||||
else if (state.command == "v" || state.command == "version") {
|
|
||||||
std::cout << getLocalVersion(state) << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier cli-set <setting> <value>
|
|
||||||
else if (state.command == "cli-set") {
|
|
||||||
if(argc != 4) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier cli-set <setting> <value>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::string settingName, settingValue;
|
|
||||||
if(state.atname.length()) { // User provided @thing erroneously, we will ignore it and adjust argument indices
|
|
||||||
settingName = argv[3];
|
|
||||||
settingValue = argv[4];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
settingName = argv[2];
|
|
||||||
settingValue = argv[3];
|
|
||||||
}
|
|
||||||
saveSettingsBackup(state);
|
|
||||||
state.settings[settingName] = settingValue; // changes
|
|
||||||
saveSettings(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier cli-unset <setting>
|
|
||||||
else if (state.command == "cli-unset") {
|
|
||||||
if(argc != 3) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier cli-unset <setting>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::string settingName;
|
|
||||||
if(state.atname.length()) // User provided @thing erroneously, we will ignore it and adjust argument indices
|
|
||||||
settingName = argv[3];
|
|
||||||
else
|
|
||||||
settingName = argv[2];
|
|
||||||
saveSettingsBackup(state);
|
|
||||||
state.settings.erase(settingName); // changes
|
|
||||||
saveSettings(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier @thing_to_remove cli-rm --- removes the configuration
|
|
||||||
else if (state.command == "cli-rm") {
|
|
||||||
if(argc != 3) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier cli-rm <@thing>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if(state.settings["things"].find(state.atname) != state.settings["things"].end()) {
|
|
||||||
if(state.settings["defaultOne"] == state.atname) {
|
|
||||||
std::cout << "WARNING: The config you're trying to remove is currently set as your default. Set a new default first!" << std::endl;
|
|
||||||
std::cout << " | Usage: zerotier set defaultOne @your_other_thing" << std::endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
state.settings["things"].erase(state.atname.c_str());
|
|
||||||
saveSettings(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier cli-add-zt <shortname> <url> <auth>
|
|
||||||
// TODO: Check for malformed urls/auth
|
|
||||||
else if (state.command == "cli-add-zt") {
|
|
||||||
if(argc != 5) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier cli-add-zt <shortname> <url> <authToken>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::string thing_name = argv[2], url = argv[3], auth = argv[4];
|
|
||||||
if(!checkURL(url)) {
|
|
||||||
std::cout << FAIL_STR << "Malformed URL" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if(state.settings.find(thing_name) != state.settings.end()) {
|
|
||||||
std::cout << "WARNING: A @thing with the shortname " << thing_name.c_str()
|
|
||||||
<< " already exists. Choose another name or rename the old @thing" << std::endl;
|
|
||||||
std::cout << " | Usage: To rename a @thing: zerotier cli-rename @old_thing_name @new_thing_name" << std::endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result = json::parse("{ \"auth\": \"" + auth + "\", \"type\": \"" + "one" + "\", \"url\": \"" + url + "\" }");
|
|
||||||
saveSettingsBackup(state);
|
|
||||||
// TODO: Handle cases where user may or may not prepend an @
|
|
||||||
state.settings["things"][thing_name] = result; // changes
|
|
||||||
saveSettings(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier cli-add-central <shortname> <url> <auth>
|
|
||||||
// TODO: Check for malformed urls/auth
|
|
||||||
else if (state.command == "cli-add-central") {
|
|
||||||
if(argc != 5) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier cli-add-central <shortname> <url> <authToken>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::string thing_name = argv[2], url = argv[3], auth = argv[4];
|
|
||||||
if(!checkURL(url)) {
|
|
||||||
std::cout << FAIL_STR << "Malformed URL" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if(state.settings.find(thing_name) != state.settings.end()) {
|
|
||||||
std::cout << "WARNING: A @thing with the shortname " << thing_name.c_str()
|
|
||||||
<< " already exists. Choose another name or rename the old @thing" << std::endl;
|
|
||||||
std::cout << " | Usage: To rename a @thing: zerotier cli-rename @old_thing_name @new_thing_name" << std::endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result = json::parse("{ \"auth\": \"" + auth + "\", \"type\": \"" + "central" + "\", \"url\": \"" + url + "\" }");
|
|
||||||
saveSettingsBackup(state);
|
|
||||||
// TODO: Handle cases where user may or may not prepend an @
|
|
||||||
state.settings["things"]["@" + thing_name] = result; // changes
|
|
||||||
saveSettings(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ONE SERVICE
|
|
||||||
|
|
||||||
// zerotier ls --- display all networks currently joined
|
|
||||||
else if (state.command == "ls" || state.command == "listnetworks") {
|
|
||||||
if(argc != 2) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier ls" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
checkForThing(state,"one",true);
|
|
||||||
url = state.url + "network";
|
|
||||||
res = REQUEST(REQ_GET,state,state.reqHeaders,"",(const std::string)url);
|
|
||||||
if(std::get<0>(res) == 200) {
|
|
||||||
std::cout << "listnetworks <nwid> <name> <mac> <status> <type> <dev> <ZT assigned ips>" << std::endl;
|
|
||||||
auto j = json::parse(std::get<1>(res).c_str());
|
|
||||||
if (j.type() == json::value_t::array) {
|
|
||||||
for(int i=0;i<j.size();i++){
|
|
||||||
std::string nwid = j[i]["nwid"].get<std::string>();
|
|
||||||
std::string name = j[i]["name"].get<std::string>();
|
|
||||||
std::string mac = j[i]["mac"].get<std::string>();
|
|
||||||
std::string status = j[i]["status"].get<std::string>();
|
|
||||||
std::string type = j[i]["type"].get<std::string>();
|
|
||||||
std::string addrs;
|
|
||||||
for(int m=0; m<j[i]["assignedAddresses"].size(); m++) {
|
|
||||||
addrs += j[i]["assignedAddresses"][m].get<std::string>() + " ";
|
|
||||||
}
|
|
||||||
std::string dev = j[i]["portDeviceName"].get<std::string>();
|
|
||||||
std::cout << "listnetworks " << nwid << " " << name << " " << mac << " " << status << " " << type << " " << dev << " " << addrs << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier join <nwid> --- joins a network
|
|
||||||
else if (state.command == "join") {
|
|
||||||
if(argc != 3) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier join <nwid>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
checkForThing(state,"one",true);
|
|
||||||
res = REQUEST(REQ_POST,state,state.reqHeaders,"{}",state.url + "/network/" + state.args[0]);
|
|
||||||
if(std::get<0>(res) == 200) {
|
|
||||||
std::cout << OK_STR << "connected to " << state.args[0] << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier leave <nwid> --- leaves a network
|
|
||||||
else if (state.command == "leave") {
|
|
||||||
if(argc != 3) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier leave <nwid>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
checkForThing(state,"one",true);
|
|
||||||
res = REQUEST(REQ_DEL,state,state.reqHeaders,"{}",state.url + "/network/" + state.args[0]);
|
|
||||||
if(std::get<0>(res) == 200) {
|
|
||||||
std::cout << OK_STR << "disconnected from " << state.args[0] << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier peers --- display address and role of all peers
|
|
||||||
else if (state.command == "peers") {
|
|
||||||
if(argc != 2) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier peers" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
checkForThing(state,"one",true);
|
|
||||||
res = REQUEST(REQ_GET,state,state.reqHeaders,"",state.url + "/peer");
|
|
||||||
if(std::get<0>(res) == 200) {
|
|
||||||
json result = json::parse(std::get<1>(res));
|
|
||||||
for(int i=0; i<result.size(); i++) {
|
|
||||||
std::cout << result[i]["address"] << " " << result[i]["role"] << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier show --- display status of local instance
|
|
||||||
else if (state.command == "show" || state.command == "status") {
|
|
||||||
if(argc != 2) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier show" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
checkForThing(state,"one",true);
|
|
||||||
res = REQUEST(REQ_GET,state,state.reqHeaders,"",state.url + "/status");
|
|
||||||
if(std::get<0>(res) == 200) {
|
|
||||||
result = json::parse(std::get<1>(res));
|
|
||||||
std::string status_str = result["online"].get<bool>() ? "ONLINE" : "OFFLINE";
|
|
||||||
std::cout << "info " << result["address"].get<std::string>()
|
|
||||||
<< " " << status_str << " " << result["version"].get<std::string>() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// REMOTE
|
|
||||||
|
|
||||||
// zerotier @thing net-create --- creates a new network
|
|
||||||
else if (state.command == "net-create") {
|
|
||||||
if(argc > 3 || (argc == 3 && !state.atname.length())) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier <@thing> net-create" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
checkForThing(state,"central",true);
|
|
||||||
res = REQUEST(REQ_POST,state,state.reqHeaders,"",state.url + "api/network");
|
|
||||||
if(std::get<0>(res) == 200) {
|
|
||||||
json result = json::parse(std::get<1>(res));
|
|
||||||
std::cout << OK_STR << "created network " << result["config"]["nwid"].get<std::string>() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier @thing net-rm <nwid> --- deletes a network
|
|
||||||
else if (state.command == "net-rm") {
|
|
||||||
if(argc > 4 || (argc == 4 && !state.atname.length())) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier <@thing> net-rm <nwid>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
checkForThing(state,"central",true);
|
|
||||||
if(!state.args.size()) {
|
|
||||||
std::cout << "Argument error: No network specified." << std::endl;
|
|
||||||
std::cout << " | Usage: zerotier net-rm <nwid>" << std::endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::string nwid = state.args[0];
|
|
||||||
res = REQUEST(REQ_DEL,state,state.reqHeaders,"",state.url + "api/network/" + nwid);
|
|
||||||
if(std::get<0>(res) == 200) {
|
|
||||||
std::cout << "deleted network " << nwid << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier @thing net-ls --- lists all networks
|
|
||||||
else if (state.command == "net-ls") {
|
|
||||||
if(argc > 3 || (argc == 3 && !state.atname.length())) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier <@thing> net-ls" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
checkForThing(state,"central",true);
|
|
||||||
res = REQUEST(REQ_GET,state,state.reqHeaders,"",state.url + "api/network");
|
|
||||||
if(std::get<0>(res) == 200) {
|
|
||||||
json result = json::parse(std::get<1>(res));
|
|
||||||
for(int m=0;m<result.size(); m++) {
|
|
||||||
std::cout << "network " << result[m]["id"].get<std::string>() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier @thing net-members <nwid> --- show all members of a network
|
|
||||||
else if (state.command == "net-members") {
|
|
||||||
if(argc > 4 || (argc == 4 && !state.atname.length())) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier <@thing> net-members <nwid>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
checkForThing(state,"central",true);
|
|
||||||
if(!state.args.size()) {
|
|
||||||
std::cout << FAIL_STR << "Argument error: No network specified." << std::endl;
|
|
||||||
std::cout << " | Usage: zerotier net-members <nwid>" << std::endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::string nwid = state.args[0];
|
|
||||||
res = REQUEST(REQ_GET,state,state.reqHeaders,"",state.url + "api/network/" + nwid + "/member");
|
|
||||||
json result = json::parse(std::get<1>(res));
|
|
||||||
std::cout << "Members of " << nwid << ":" << std::endl;
|
|
||||||
for (json::iterator it = result.begin(); it != result.end(); ++it) {
|
|
||||||
std::cout << it.key() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier @thing net-show <nwid> <devID> --- show info about a device on a specific network
|
|
||||||
else if (state.command == "net-show") {
|
|
||||||
if(argc > 5 || (argc == 5 && !state.atname.length())) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier <@thing> net-show <nwid> <devID>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
checkForThing(state,"central",true);
|
|
||||||
if(state.args.size() < 2) {
|
|
||||||
std::cout << FAIL_STR << "Argument error: Too few arguments." << std::endl;
|
|
||||||
std::cout << " | Usage: zerotier net-show <nwid> <devID>" << std::endl;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::string nwid = state.args[0];
|
|
||||||
std::string devid = state.args[1];
|
|
||||||
res = REQUEST(REQ_GET,state,state.reqHeaders,"",state.url + "api/network/" + nwid + "/member/" + devid);
|
|
||||||
// TODO: More info, what would we like to show exactly?
|
|
||||||
if(std::get<0>(res) == 200) {
|
|
||||||
json result = json::parse(std::get<1>(res));
|
|
||||||
std::cout << "Assigned IP: " << std::endl;
|
|
||||||
for(int m=0; m<result["config"]["ipAssignments"].size();m++) {
|
|
||||||
std::cout << "\t" << result["config"]["ipAssignments"][m].get<std::string>() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier @thing net-auth <nwid> <devID> --- authorize a device on a network
|
|
||||||
else if (state.command == "net-auth") {
|
|
||||||
if(argc > 5 || (argc == 5 && !state.atname.length())) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier <@thing> net-auth <nwid> <devID>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
checkForThing(state,"central",true);
|
|
||||||
if(state.args.size() != 2) {
|
|
||||||
std::cout << FAIL_STR << "Argument error: Network and/or device ID not specified." << std::endl;
|
|
||||||
std::cout << " | Usage: zerotier net-auth <nwid> <devID>" << std::endl;
|
|
||||||
}
|
|
||||||
std::string nwid = state.args[0];
|
|
||||||
std::string devid = state.args[1];
|
|
||||||
url = state.url + "api/network/" + nwid + "/member/" + devid;
|
|
||||||
// Add device to network
|
|
||||||
res = REQUEST(REQ_POST,state,state.reqHeaders,"",(const std::string)url);
|
|
||||||
if(std::get<0>(res) == 200) {
|
|
||||||
result = json::parse(std::get<1>(res));
|
|
||||||
res = REQUEST(REQ_GET,state,state.reqHeaders,"",(const std::string)url);
|
|
||||||
result = json::parse(std::get<1>(res));
|
|
||||||
result["config"]["authorized"] = "true";
|
|
||||||
std::string newconfig = result.dump();
|
|
||||||
res = REQUEST(REQ_POST,state,state.reqHeaders,newconfig,(const std::string)url);
|
|
||||||
if(std::get<0>(res) == 200)
|
|
||||||
std::cout << OK_STR << devid << " authorized on " << nwid << std::endl;
|
|
||||||
else
|
|
||||||
std::cout << FAIL_STR << "There was a problem authorizing that device." << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier @thing net-unauth <nwid> <devID>
|
|
||||||
else if (state.command == "net-unauth") {
|
|
||||||
if(argc > 5 || (argc == 5 && !state.atname.length())) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier <@thing> net-unauth <nwid> <devID>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
checkForThing(state,"central",true);
|
|
||||||
if(state.args.size() != 2) {
|
|
||||||
std::cout << FAIL_STR << "Bad argument. No network and/or device ID specified." << std::endl;
|
|
||||||
std::cout << " | Usage: zerotier net-unauth <nwid> <devID>" << std::endl;
|
|
||||||
}
|
|
||||||
std::string nwid = state.args[0];
|
|
||||||
std::string devid = state.args[1];
|
|
||||||
// If successful, get member config
|
|
||||||
res = REQUEST(REQ_GET,state,state.reqHeaders,"",state.url + "api/network/" + nwid + "/member/" + devid);
|
|
||||||
result = json::parse(std::get<1>(res));
|
|
||||||
// modify auth field and re-POST
|
|
||||||
result["config"]["authorized"] = "false";
|
|
||||||
std::string newconfig = result.dump();
|
|
||||||
res = REQUEST(REQ_POST,state,state.reqHeaders,newconfig,state.url + "api/network/" + nwid + "/member/" + devid);
|
|
||||||
if(std::get<0>(res) == 200)
|
|
||||||
std::cout << OK_STR << devid << " de-authorized from " << nwid << std::endl;
|
|
||||||
else
|
|
||||||
std::cout << FAIL_STR << "There was a problem de-authorizing that device." << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier @thing net-set
|
|
||||||
else if (state.command == "net-set") {
|
|
||||||
}
|
|
||||||
|
|
||||||
// ID
|
|
||||||
|
|
||||||
// zerotier id-generate [<vanity prefix>]
|
|
||||||
else if (state.command == "id-generate") {
|
|
||||||
if(argc != 3) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier id-generate [<vanity prefix>]" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
uint64_t vanity = 0;
|
|
||||||
int vanityBits = 0;
|
|
||||||
if (argc >= 5) {
|
|
||||||
vanity = Utils::hexStrToU64(argv[4]) & 0xffffffffffULL;
|
|
||||||
vanityBits = 4 * strlen(argv[4]);
|
|
||||||
if (vanityBits > 40)
|
|
||||||
vanityBits = 40;
|
|
||||||
}
|
|
||||||
|
|
||||||
ZeroTier::Identity id;
|
|
||||||
for(;;) {
|
|
||||||
id.generate();
|
|
||||||
if ((id.address().toInt() >> (40 - vanityBits)) == vanity) {
|
|
||||||
if (vanityBits > 0) {
|
|
||||||
fprintf(stderr,"vanity address: found %.10llx !\n",(unsigned long long)id.address().toInt());
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
fprintf(stderr,"vanity address: tried %.10llx looking for first %d bits of %.10llx\n",(unsigned long long)id.address().toInt(),vanityBits,(unsigned long long)(vanity << (40 - vanityBits)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string idser = id.toString(true);
|
|
||||||
if (argc >= 3) {
|
|
||||||
if (!OSUtils::writeFile(argv[2],idser)) {
|
|
||||||
std::cerr << "Error writing to " << argv[2] << std::endl;
|
|
||||||
return 1;
|
|
||||||
} else std::cout << argv[2] << " written" << std::endl;
|
|
||||||
if (argc >= 4) {
|
|
||||||
idser = id.toString(false);
|
|
||||||
if (!OSUtils::writeFile(argv[3],idser)) {
|
|
||||||
std::cerr << "Error writing to " << argv[3] << std::endl;
|
|
||||||
return 1;
|
|
||||||
} else std::cout << argv[3] << " written" << std::endl;
|
|
||||||
}
|
|
||||||
} else std::cout << idser << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier id-validate <identity>
|
|
||||||
else if (state.command == "id-validate") {
|
|
||||||
if(argc != 3) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier id-validate <identity>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Identity id = getIdFromArg(argv[2]);
|
|
||||||
if (!id) {
|
|
||||||
std::cerr << "Identity argument invalid or file unreadable: " << argv[2] << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (!id.locallyValidate()) {
|
|
||||||
std::cerr << argv[2] << " FAILED validation." << std::endl;
|
|
||||||
return 1;
|
|
||||||
} else std::cout << argv[2] << "is a valid identity" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier id-sign <identity> <file>
|
|
||||||
else if (state.command == "id-sign") {
|
|
||||||
if(argc != 4) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier id-sign <identity> <file>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Identity id = getIdFromArg(argv[2]);
|
|
||||||
if (!id) {
|
|
||||||
std::cerr << "Identity argument invalid or file unreadable: " << argv[2] << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (!id.hasPrivate()) {
|
|
||||||
std::cerr << argv[2] << " does not contain a private key (must use private to sign)" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::string inf;
|
|
||||||
if (!OSUtils::readFile(argv[3],inf)) {
|
|
||||||
std::cerr << argv[3] << " is not readable" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
C25519::Signature signature = id.sign(inf.data(),(unsigned int)inf.length());
|
|
||||||
std::cout << Utils::hex(signature.data,(unsigned int)signature.size()) << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier id-verify <secret> <file> <sig>
|
|
||||||
else if (state.command == "id-verify") {
|
|
||||||
if(argc != 4) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier id-verify <secret> <file> <sig>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Identity id = getIdFromArg(argv[2]);
|
|
||||||
if (!id) {
|
|
||||||
std::cerr << "Identity argument invalid or file unreadable: " << argv[2] << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::string inf;
|
|
||||||
if (!OSUtils::readFile(argv[3],inf)) {
|
|
||||||
std::cerr << argv[3] << " is not readable" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::string signature(Utils::unhex(argv[4]));
|
|
||||||
if ((signature.length() > ZT_ADDRESS_LENGTH)&&(id.verify(inf.data(),(unsigned int)inf.length(),signature.data(),(unsigned int)signature.length()))) {
|
|
||||||
std::cout << argv[3] << " signature valid" << std::endl;
|
|
||||||
} else {
|
|
||||||
std::cerr << argv[3] << " signature check FAILED" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// zerotier id-getpublic <secret>
|
|
||||||
else if (state.command == "id-getpublic") {
|
|
||||||
if(argc != 3) {
|
|
||||||
std::cerr << INVALID_ARGS_STR << "zerotier id-getpublic <secret>" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
Identity id = getIdFromArg(argv[2]);
|
|
||||||
if (!id) {
|
|
||||||
std::cerr << "Identity argument invalid or file unreadable: " << argv[2] << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
std::cerr << id.toString(false) << std::endl;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
else {
|
|
||||||
dumpHelp();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if(std::find(state.args.begin(), state.args.end(), "-verbose") != state.args.end())
|
|
||||||
std::cout << "\n\nAPI response = " << std::get<1>(res) << std::endl;
|
|
||||||
curl_global_cleanup();
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,764 +0,0 @@
|
||||||
*****************************************************************************
|
|
||||||
Anode Protocol Specification Draft
|
|
||||||
Version 0.8
|
|
||||||
|
|
||||||
(c)2009-2010 Adam Ierymenko
|
|
||||||
*****************************************************************************
|
|
||||||
|
|
||||||
Table of Contents
|
|
||||||
|
|
||||||
*****************************************************************************
|
|
||||||
|
|
||||||
1. Introduction
|
|
||||||
|
|
||||||
Anode provides three components that work together to provide a global,
|
|
||||||
secure, and mobile addressing system for computer networks:
|
|
||||||
|
|
||||||
1) An addressing system based on public key cryptography enabling network
|
|
||||||
devices or applications to assign themselves secure, unique, and globally
|
|
||||||
reachable network addresses in a flat address space.
|
|
||||||
|
|
||||||
2) A system enabling network participants holding global addresses to locate
|
|
||||||
one another on local or global networks with "zero configuration."
|
|
||||||
|
|
||||||
3) A communications protocol for communication between addressed network
|
|
||||||
participants that requires no special operating system support and no
|
|
||||||
changes to existing network infrastructure.
|
|
||||||
|
|
||||||
Using Anode, both fixed and mobile applications and devices can communicate
|
|
||||||
directly as if they were all connected to the same VPN. Anode restores the
|
|
||||||
original vision of the Internet as a "flat" network where anything can talk
|
|
||||||
to anything, and adds the added benefits of address mobility and strong
|
|
||||||
protection against address spoofing and other protocol level attacks.
|
|
||||||
|
|
||||||
1.1. Design Philosophy
|
|
||||||
|
|
||||||
Anode's design philosophy is the classical "KISS" principle: "Keep It Simple
|
|
||||||
Stupid." Anode's design principles are:
|
|
||||||
|
|
||||||
#1: Do not try to solve too many problems at once, and stay in scope.
|
|
||||||
|
|
||||||
Anode does not attempt to solve too many problems at once. It attempts to
|
|
||||||
solve the problems of mobile addressing, address portability, and "flat"
|
|
||||||
addressing in the presence of NAT or other barriers.
|
|
||||||
|
|
||||||
It does not attempt to duplicate the full functionality of SSL, X.509, SSH,
|
|
||||||
XMPP, an enterprise service bus, a pub/sub architecture, BitTorrent, etc. All
|
|
||||||
of those protocols and services can be used over Anode if their functionality
|
|
||||||
is desired.
|
|
||||||
|
|
||||||
#2: Avoid state management.
|
|
||||||
|
|
||||||
State multiplies the complexity and failure modes of network protocols. State
|
|
||||||
also tends to get in the way of the achievement of new features implicitly
|
|
||||||
(see principle #4). Avoid state whenever possible.
|
|
||||||
|
|
||||||
#3: Avoid algorithm and dependency bloat.
|
|
||||||
|
|
||||||
Anode uses only elliptic curve Diffie-Hellman (EC-DH) and AES-256. No other
|
|
||||||
cryptographic algorithms or hash functions are presently necessary. This
|
|
||||||
yields implementations compact enough for embedded devices.
|
|
||||||
|
|
||||||
Anode also requires few or no dependencies, depending on whether the two
|
|
||||||
needed cryptographic algorithms are obtained through a library or included.
|
|
||||||
No other protocols or libraries are required in an implementation.
|
|
||||||
|
|
||||||
#4: Achieve features implicitly.
|
|
||||||
|
|
||||||
Use a simple stateless design that allows features to be achieved implicitly
|
|
||||||
rather than specified explicitly. For example, Anode can do multi-homing and
|
|
||||||
could be used to build a mesh network, but neither of these features is
|
|
||||||
explicitly specified.
|
|
||||||
|
|
||||||
*****************************************************************************
|
|
||||||
|
|
||||||
2. Core Concepts and Algorithms
|
|
||||||
|
|
||||||
This section describes addresses, zones, common algorithms, and other core
|
|
||||||
concepts.
|
|
||||||
|
|
||||||
2.1. Zones
|
|
||||||
|
|
||||||
A zone is a 32-bit integer encoded into every Anode address. Zones serve to
|
|
||||||
assist in the location of peers by address on global IP networks. They are
|
|
||||||
not presently significant for local communications, though they could be
|
|
||||||
used to partition addresses into groups or link them with configuration
|
|
||||||
options.
|
|
||||||
|
|
||||||
Each zone has a corresponding zone file which can be fetched in a number of
|
|
||||||
ways (see below). A zone file is a flat text format dictionary of the format
|
|
||||||
"key=value" separated by carriage returns. Line feeds are ignored, and any
|
|
||||||
character may be escaped with a backslash (\) character. Blank lines are
|
|
||||||
ignored.
|
|
||||||
|
|
||||||
The following entries must appear in a zone file:
|
|
||||||
|
|
||||||
n=<zone name>
|
|
||||||
d=<zone description>
|
|
||||||
c=<zone contact, e-mail address of zone administrator>
|
|
||||||
r=<zone revision, monotonically increasing integer with each edit>
|
|
||||||
ttl=<seconds before zone file should be re-checked for changes>
|
|
||||||
|
|
||||||
Additional fields may appear as well, including fields specific to special
|
|
||||||
applications or protocols supported within the zone. Some of these are
|
|
||||||
defined in this document.
|
|
||||||
|
|
||||||
Zone file fetching mechanisms are described below. Multiple mechanisms are
|
|
||||||
specified to enable fallback in the event that one mechanism is not available.
|
|
||||||
|
|
||||||
2.1.1. Zone File Retrieval
|
|
||||||
|
|
||||||
Zone files are retrieved via HTTP, with the HTTP address being formed in one
|
|
||||||
of two ways.
|
|
||||||
|
|
||||||
The preferred DNS method:
|
|
||||||
|
|
||||||
To fetch a zone file via DNS, use the zone ID to generate a host name and URI
|
|
||||||
of the form:
|
|
||||||
|
|
||||||
http://a--XXXXXXXX.net/z
|
|
||||||
|
|
||||||
The XXXXXXXX field is the zone ID in hexadecimal.
|
|
||||||
|
|
||||||
The fallback IP method:
|
|
||||||
|
|
||||||
For fallback in the absence of DNS, the zone ID can be used directly as an
|
|
||||||
IPv4 or IPv4-mapped-to-IPv6 IP address. A URI is generated of the form:
|
|
||||||
|
|
||||||
http://ip_address/z
|
|
||||||
|
|
||||||
Support for this method requires that a zone ID be chosen to correspond to a
|
|
||||||
permanent IPv4 (preferably mappable to IPv6 space as well) IP address.
|
|
||||||
|
|
||||||
2.1.2. Zone ID Reservation
|
|
||||||
|
|
||||||
By convention, a zone ID is considered reserved when a domain of the form
|
|
||||||
"a--XXXXXXXX.net" (where XXXXXXXX is the ID in hex) is registered.
|
|
||||||
|
|
||||||
It is recommended that this be done even for zone IDs not used for global
|
|
||||||
address location in order to globally reserve them.
|
|
||||||
|
|
||||||
2.2. Addresses
|
|
||||||
|
|
||||||
Anode addresses are binary strings containing a 32-bit zone ID, a public key,
|
|
||||||
and possibly other fields. Only one address type is presently defined:
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Name | Type ID | Elliptic Curve Parameters | Total Length |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| ANODE-256-40 | 1 | NIST-P-256 | 40 |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Name | Binary Layout |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| ANODE-256-40 | <type[1]><zone[4]><unused[2]><public key[33]> |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
The public key is a "compressed" form elliptic curve public key as described
|
|
||||||
in RFC5480.
|
|
||||||
|
|
||||||
The unused section of the address must be zero. These bytes are reserved for
|
|
||||||
future use.
|
|
||||||
|
|
||||||
2.2.1. ASCII Format For Addresses
|
|
||||||
|
|
||||||
Addresses are encoded in ASCII using base-32, which provides a quotable and
|
|
||||||
printable encoding that is of manageable length and is case-insensitive. For
|
|
||||||
example, an ANODE-256-40 address is 64 characters long in base-32 encoding.
|
|
||||||
|
|
||||||
2.3. Relaying
|
|
||||||
|
|
||||||
An Anode peer may optionally relay packets to any other reachable peer.
|
|
||||||
Relaying is accomplished by sending a packet to a peer with the recipient set
|
|
||||||
to the final recipient. The receiving peer will, if relaying is allowed and if
|
|
||||||
it knows of or can reach the recipient, forward the packet.
|
|
||||||
|
|
||||||
No error is returned if relaying fails, so relay paths are treated as possible
|
|
||||||
paths for communication until a return is received in the same way as direct
|
|
||||||
paths.
|
|
||||||
|
|
||||||
Relaying can be used by peers to send messages indirectly, locate one
|
|
||||||
another, and determine network location information to facilitate the
|
|
||||||
establishment of direct communications.
|
|
||||||
|
|
||||||
Peers may refuse to relay or may limit the transmission rate at which packets
|
|
||||||
can be relayed.
|
|
||||||
|
|
||||||
2.3.1. Zone Relays
|
|
||||||
|
|
||||||
If a zone's addresses are globally reachable on global IP networks, it must
|
|
||||||
have one or more zone relays. These must have globally reachable public
|
|
||||||
static IP addresses.
|
|
||||||
|
|
||||||
Zone relays are specified in the zone file in the following format:
|
|
||||||
|
|
||||||
zr.<address checksum>=<ip>[,<ip>]:<udp port>:<tcp port>:<anode addresses>
|
|
||||||
|
|
||||||
The address checksum is the sum of the bytes in the Anode address modulus
|
|
||||||
the number of "zr" entries, in hexadecimal. For example, if a zone had four
|
|
||||||
global relays its zone file could contain the lines:
|
|
||||||
|
|
||||||
zr.0=1.2.3.4:4343:4344:klj4j3...
|
|
||||||
zr.1=2.3.4.5:4343:4344:00194j...
|
|
||||||
zr.2=3.4.5.6:4343:4344:1j42zz...
|
|
||||||
zr.3=4.5.6.7:4343:4344:z94j1q...
|
|
||||||
|
|
||||||
The relay would be chosen by taking the sum of the bytes in the address
|
|
||||||
modulo 4. For example, if the bytes of an address sum to 5081 then relay
|
|
||||||
zr.1 would be used to communicate with that address.
|
|
||||||
|
|
||||||
If more than one IP address is listed for a given relay, the peer must choose
|
|
||||||
at random from among the addresses of the desired type (IPv4 or IPv6).
|
|
||||||
|
|
||||||
Each relay must have one Anode address for every address type supported within
|
|
||||||
the zone. (At present there is only one address type defined.)
|
|
||||||
|
|
||||||
Peers should prefer UDP and fall back to TCP only if UDP is not available.
|
|
||||||
|
|
||||||
To make itself available, a peer must make itself known to its designated zone
|
|
||||||
relay. This is accomplished by sending a PING message.
|
|
||||||
|
|
||||||
2.4. Key Agreement and Derivation
|
|
||||||
|
|
||||||
Key agreement is performed using elliptic curve Diffie-Hellman. This yields
|
|
||||||
a raw key whose size depends on the elliptic curve parameters in use.
|
|
||||||
|
|
||||||
The following algorithm is used to derive a key of any length from a raw
|
|
||||||
key generated through key agreement:
|
|
||||||
|
|
||||||
1) Zero the derived key buffer.
|
|
||||||
2) Determine the largest of the original raw key or the derived key.
|
|
||||||
3) Loop from 0 to the largest length determined in step 2, XOR each byte of
|
|
||||||
the derived key buffer with the corresponding byte of the original key
|
|
||||||
buffer with each index being modulus the length of the respective buffer.
|
|
||||||
|
|
||||||
2.5. Message Authentication
|
|
||||||
|
|
||||||
For message authentication, CMAC-AES (with AES-256) is used. This is also
|
|
||||||
known in some literature as OMAC1-AES. The key is derived from key agreement
|
|
||||||
between the key pair of the sending peer and the address of the recipient.
|
|
||||||
|
|
||||||
2.6. AES-DIGEST
|
|
||||||
|
|
||||||
To maintain cryptographic algorithm frugality, a cryptographic hash function
|
|
||||||
is constructed from the AES-256 cipher. This hash function uses the common
|
|
||||||
Davis-Meyer construction with Merkle-Damgård length padding.
|
|
||||||
|
|
||||||
It is described by the following pseudocode:
|
|
||||||
|
|
||||||
byte previous_digest[16]
|
|
||||||
byte digest[16] = { 0,0,... }
|
|
||||||
byte block[32] = { 0,0,... }
|
|
||||||
integer block_counter = 0
|
|
||||||
|
|
||||||
; digest message
|
|
||||||
for each byte b of message
|
|
||||||
block[block_counter] = b
|
|
||||||
block_counter = block_counter + 1
|
|
||||||
if block_counter == 32 then
|
|
||||||
block_counter = 0
|
|
||||||
save digest[] in previous_digest[]
|
|
||||||
encrypt digest[] with aes-256 using block[] as 256-bit aes-256 key
|
|
||||||
xor digest[] with previous_digest[]
|
|
||||||
end if
|
|
||||||
next
|
|
||||||
|
|
||||||
; append end marker, do final block
|
|
||||||
block[block_counter] = 0x80
|
|
||||||
block_counter = block_counter + 1
|
|
||||||
zero rest of block[] from block_counter to 15
|
|
||||||
save digest[] in previous_digest[]
|
|
||||||
encrypt digest[] with aes-256 using block[] as 256-bit aes-256 key
|
|
||||||
xor digest[] with previous_digest[]
|
|
||||||
|
|
||||||
; Merkle-Damgård length padding
|
|
||||||
zero first 8 bytes of block[]
|
|
||||||
fill last 8 bytes of block[] w/64-bit length in big-endian order
|
|
||||||
save digest[] in previous_digest[]
|
|
||||||
encrypt digest[] with aes-256 using block[] as 256-bit aes-128 key
|
|
||||||
xor digest[] with previous_digest[]
|
|
||||||
|
|
||||||
; digest[] now contains 128-bit message digest
|
|
||||||
|
|
||||||
2.7. Short Address Identifiers (Address IDs)
|
|
||||||
|
|
||||||
A short 8-byte version of the Anode address is used in the protocol to reduce
|
|
||||||
transmission overhead when both sides are already aware of the other's full
|
|
||||||
address.
|
|
||||||
|
|
||||||
The short address identifier is formed by computing the AES-DIGEST of the
|
|
||||||
full address and then XORing the first 8 bytes of the digest with the last
|
|
||||||
8 bytes to yield an 8-byte shortened digest.
|
|
||||||
|
|
||||||
2.8. DNS Resolution of Anode Addresses
|
|
||||||
|
|
||||||
Anode addresses can be saved in DNS TXT records in the following format:
|
|
||||||
|
|
||||||
anode:<address in base32 ASCII encoding>
|
|
||||||
|
|
||||||
This permits Anode addresses to be resolved from normal DNS host name.
|
|
||||||
|
|
||||||
2.9. Packet Transmission Mechanisms
|
|
||||||
|
|
||||||
2.9.1. UDP Transmission
|
|
||||||
|
|
||||||
The recommended method of sending Anode packets is UDP. Each packet is simply
|
|
||||||
sent as a UDP packet.
|
|
||||||
|
|
||||||
2.9.2. TCP Transmission
|
|
||||||
|
|
||||||
To send packets over TCP, each packet is prefixed by its size as a 16-bit
|
|
||||||
integer.
|
|
||||||
|
|
||||||
2.9.3. HTTP Transmission
|
|
||||||
|
|
||||||
Anode packets may be submitted in HTTP POST transactions for transport over
|
|
||||||
networks where HTTP is the only available protocol.
|
|
||||||
|
|
||||||
Anode packets are simply prefixed with a 16-byte packet size and concatenated
|
|
||||||
together just as they are in a TCP stream. One or more packets may be sent
|
|
||||||
with each HTTP POST transaction for improved performance.
|
|
||||||
|
|
||||||
Since this method is intended for use in "hostile" or highly restricted
|
|
||||||
circumstances, no additional details such as special headers or MIME types
|
|
||||||
are specified to allow maximum flexibility. Peers should ignore anything
|
|
||||||
other than the payload.
|
|
||||||
|
|
||||||
2.10. Endpoints
|
|
||||||
|
|
||||||
An endpoint indicates a place where Anode packets may be sent. The following
|
|
||||||
endpoint types are specified:
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Endpoint Type | Description | Address Format |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| 0x00 | Unspecified | (none) |
|
|
||||||
| 0x01 | Ethernet | <mac[6]> |
|
|
||||||
| 0x02 | UDP/IPv4 | <ip[4]><port[2]> |
|
|
||||||
| 0x03 | TCP/IPv4 | <ip[4]><port[2]> |
|
|
||||||
| 0x04 | UDP/IPv6 | <ip[16]><port[2]> |
|
|
||||||
| 0x05 | TCP/IPv6 | <ip[16]><port[2]> |
|
|
||||||
| 0x06 | HTTP | <null-terminated full URI> |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
Endpoints are encoded by beginning with a single byte indicating the endpoint
|
|
||||||
type followed by the address information required for the given type.
|
|
||||||
|
|
||||||
Note that IP ports bear no relationship to Anode protocol ports.
|
|
||||||
|
|
||||||
2.11. Notes
|
|
||||||
|
|
||||||
All integers in the protocol are transmitted in network (big endian) byte
|
|
||||||
order.
|
|
||||||
|
|
||||||
*****************************************************************************
|
|
||||||
|
|
||||||
3. Common Packet Format
|
|
||||||
|
|
||||||
A common header is used for all Anode packets:
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Hop Count | 1 | 8-bit hop count (not included in MAC) |
|
|
||||||
| Flags | 1 | 8-bit flags |
|
|
||||||
| MAC | 8 | 8 byte shortened CMAC-AES of packet |
|
|
||||||
| Sender Address | ? | Full address or short ID of sender |
|
|
||||||
| Recipient Address | ? | Full address or short ID of recipient |
|
|
||||||
| Peer IDs | 1 | Two 4-bit peer IDs: sender, recipient |
|
|
||||||
| Message Type | 1 | 8-bit message type |
|
|
||||||
| Message | ? | Message payload |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
3.1. Hop Count
|
|
||||||
|
|
||||||
The hop count begins at zero and must be incremented by each peer that relays
|
|
||||||
the packet to another peer. The hop count must not wrap to zero at 255.
|
|
||||||
|
|
||||||
Because the hop count is modified in transit, it is not included in MAC
|
|
||||||
calculation or authentication.
|
|
||||||
|
|
||||||
The hop count is used to prioritize endpoints that are direct over endpoints
|
|
||||||
that involve relaying, or to prioritize closer routes over more distant
|
|
||||||
ones.
|
|
||||||
|
|
||||||
3.2. Flags and Flag Behavior
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Flag | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| 0x01 | Sender address fully specified |
|
|
||||||
| 0x02 | Recipient address fully specified |
|
|
||||||
| 0x04 | Authentication error response |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
If flag 0x01 is set, then the sender address will be the full address rather
|
|
||||||
than a short address identifier. The length of the address can be determined
|
|
||||||
from the first byte of the address, which always specifies the address type.
|
|
||||||
Flag 0x02 has the same meaning for the recipient address.
|
|
||||||
|
|
||||||
A peer must send fully specified sender addresses until it receives a response
|
|
||||||
from the recipient. At this point the sender may assume that the recipient
|
|
||||||
knows its address and use short a short sender address instead. This
|
|
||||||
assumption should time out, with a recommended timeout of 60 seconds.
|
|
||||||
|
|
||||||
There is presently no need to send fully specified recipient addresses, but
|
|
||||||
the flag is present in case it is needed and must be honored.
|
|
||||||
|
|
||||||
Flag 0x04 indicates that this is an error response containing a failed
|
|
||||||
authentication error. Since authentication failed, this packet may not have
|
|
||||||
a valid MAC. Packets with this flag must never have any effect other than
|
|
||||||
to inform of an error. This error, since it is unauthenticated, must never
|
|
||||||
have any side effects such as terminating a connection.
|
|
||||||
|
|
||||||
3.3. MAC
|
|
||||||
|
|
||||||
The MAC is calculated as follows:
|
|
||||||
|
|
||||||
1) Temporarily set the 64-bit/8-byte MAC field in the packet to the packet's
|
|
||||||
size as a 64-bit big-endian integer.
|
|
||||||
2) Calculate the MAC for the entire packet (excluding the first byte) using
|
|
||||||
the key agreed upon between the sender and the recipient, resulting in a
|
|
||||||
16 byte full CMAC-AES MAC.
|
|
||||||
3) Derive the 8 byte packet MAC by XORing the first 8 bytes of the full 16
|
|
||||||
byte CMAC-AES MAC with the last 8 bytes. Place this into the packet's MAC
|
|
||||||
field.
|
|
||||||
|
|
||||||
3.4. Peer IDs
|
|
||||||
|
|
||||||
Peer IDs provide a method for up to 15 different peers to share an address,
|
|
||||||
each with a unique ID allowing packets to be routed to them individually.
|
|
||||||
|
|
||||||
A peer ID of zero indicates "any" or "unspecified." Real peers must have a
|
|
||||||
nonzero peer ID. In the normal single peer per address case, any peer ID may
|
|
||||||
be used. If multiple peers are to share an address, some implementation-
|
|
||||||
dependent method must be used to ensure that each peer has a unique peer ID.
|
|
||||||
|
|
||||||
Relaying peers must follow these rules based on the recipient peer ID when
|
|
||||||
relaying messages:
|
|
||||||
|
|
||||||
- IF the peer ID is zero or if the peer ID is not known, the message must
|
|
||||||
be forwarded to a random endpoint for the given recipient address.
|
|
||||||
- IF the peer ID is nonzero and matches one or more known endpoints for the
|
|
||||||
given recipient address and peer ID, the message must only be sent to
|
|
||||||
a matching endpoint.
|
|
||||||
|
|
||||||
A receiving peer should process any message that it receives regardless of
|
|
||||||
whether its recipient peer ID is correct. The peer ID is primarily for relays.
|
|
||||||
|
|
||||||
Peers should typically send messages with a nonzero recipient peer ID when
|
|
||||||
responding to or involved in a conversation with a specific peer (e.g. a
|
|
||||||
streaming connection), and send zero recipient peer IDs otherwise.
|
|
||||||
|
|
||||||
3.5. Short Address Conflict Disambiguation
|
|
||||||
|
|
||||||
In the unlikely event of two Anode addresses with the same short identifier,
|
|
||||||
the recipient should use MAC validation to disambiguate. The peer ID must not
|
|
||||||
be relied upon for this purpose.
|
|
||||||
|
|
||||||
*****************************************************************************
|
|
||||||
|
|
||||||
4. Basic Signaling and Transport Protocol
|
|
||||||
|
|
||||||
4.1. Message Types
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Type | ID | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| ERROR | 0x00 | Error response |
|
|
||||||
| PING | 0x01 | Echo request |
|
|
||||||
| PONG | 0x02 | Echo response |
|
|
||||||
| EPC_REQ | 0x03 | Endpoint check request |
|
|
||||||
| EPC | 0x04 | Endpoint check response |
|
|
||||||
| EPI | 0x05 | Endpoint information |
|
|
||||||
| NAT_T | 0x06 | NAT traversal message |
|
|
||||||
| NETID_REQ | 0x07 | Request network address identification and/or test |
|
|
||||||
| NETID | 0x08 | Response to network address identification request |
|
|
||||||
| DGRAM | 0x09 | Simple UDP-like datagram |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
4.2. Message Details
|
|
||||||
|
|
||||||
4.2.1. ERROR
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Error Code | 2 | 16-bit error code |
|
|
||||||
| Error Arguments | ? | Error arguments, depending on error type |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
Error arguments are empty unless otherwise stated below.
|
|
||||||
|
|
||||||
Error codes:
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Error Code | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| 0x01 | Message not valid |
|
|
||||||
| 0x02 | Message authentication or decryption failed |
|
|
||||||
| 0x03 | Relaying and related features not authorized |
|
|
||||||
| 0x04 | Relay recipient not reachable |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
Generation of errors is optional. A peer may choose to ignore invalid
|
|
||||||
messages or to throttle the sending of errors.
|
|
||||||
|
|
||||||
4.2.2. PING
|
|
||||||
|
|
||||||
(Payload unspecified.)
|
|
||||||
|
|
||||||
Request echo of payload as PONG message.
|
|
||||||
|
|
||||||
4.2.3. PONG
|
|
||||||
|
|
||||||
(Payload unspecified.)
|
|
||||||
|
|
||||||
Echoed payload of received PING message.
|
|
||||||
|
|
||||||
4.2.4. EPC_REQ
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Request ID | 4 | 32-bit request ID |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
Request echo of request ID in EPC message, used to check and learn endpoints.
|
|
||||||
|
|
||||||
To learn a network endpoint for a peer, CHECK_REQ is sent. If CHECK is
|
|
||||||
returned with a valid request ID, the endpoint is considered valid.
|
|
||||||
|
|
||||||
4.2.5. EPC
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Request ID | 4 | 32-bit request ID echoed back |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
Response to EPC_REQ containing request ID.
|
|
||||||
|
|
||||||
4.2.6. EPI
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Flags | 1 | 8-bit flags |
|
|
||||||
| Endpoint | ? | Endpoint type and address |
|
|
||||||
| NAT-T mode | 1 | 8-bit NAT traversal mode |
|
|
||||||
| NAT-T options | ? | Options related to specified NAT-T mode |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
EPI stands for EndPoint Identification, and is sent to notify another peer of
|
|
||||||
a network endpoint where the sending peer is reachable.
|
|
||||||
|
|
||||||
If the receiving peer is interested in communicating with the sending peer,
|
|
||||||
the receiving peer must send EPC_REQ to the sending peer at the specified
|
|
||||||
endpoint to check the validity of that endpoint. The endpoint is learned if a
|
|
||||||
valid EPC is returned.
|
|
||||||
|
|
||||||
If the endpoint in EPI is unspecified, the actual source of the EPI message
|
|
||||||
is the endpoint. This allows EPI messages to be broadcast on a local LAN
|
|
||||||
segment to advertise the presence of an address on a local network. EPI
|
|
||||||
broadcasts on local IP networks must be made to UDP port 8737.
|
|
||||||
|
|
||||||
Usually EPI is sent via relays (usually zone relays) to inform a peer of an
|
|
||||||
endpoint for direct communication.
|
|
||||||
|
|
||||||
There are presently no flags, so flags must be zero.
|
|
||||||
|
|
||||||
4.2.7. NAT_T
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| NAT-T mode | 1 | 8-bit NAT traversal mode |
|
|
||||||
| NAT-T options | ? | Options related to specified NAT-T mode |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
NAT_T is used to send messages specific to certain NAT traversal modes.
|
|
||||||
|
|
||||||
4.2.8. NETID_REQ
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Request ID | 4 | 32-bit request ID |
|
|
||||||
| Endpoint | ? | Endpoint type and address information |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
When a NETID_REQ message is received, the recipient attempts to echo it back
|
|
||||||
as a NETID message to the specified endpoint address. If the endpoint is
|
|
||||||
unspecified, the recipient must fill it in with the actual origin of the
|
|
||||||
NETID_REQ message. This allows a peer to cooperate with another peer (usually
|
|
||||||
a zone relay) to empirically determine its externally visible network
|
|
||||||
address information.
|
|
||||||
|
|
||||||
A peer may ignore NETID_REQ or respond with an error if it does not allow
|
|
||||||
relaying.
|
|
||||||
|
|
||||||
4.2.9. NETID
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Request ID | 4 | 32-bit request ID echoed back |
|
|
||||||
| Endpoint Type | 1 | 8-bit endpoint type |
|
|
||||||
| Endpoint Address | ? | Endpoint Address (size depends on type) |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
NETID is sent in response to NETID_REQ to the specified endpoint address. It
|
|
||||||
always contains the endpoint address to which it was sent.
|
|
||||||
|
|
||||||
4.2.10. DGRAM
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Source Port | 2 | 16-bit source port |
|
|
||||||
| Destination Port | 2 | 16-bit destination port |
|
|
||||||
| Payload | ? | Datagram packet payload |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
A datagram is a UDP-like message without flow control or delivery assurance.
|
|
||||||
|
|
||||||
*****************************************************************************
|
|
||||||
|
|
||||||
5. Stream Protocol
|
|
||||||
|
|
||||||
The stream protocol is very similar to TCP, though it omits some features
|
|
||||||
that are not required since they are taken care of by the encapsulating
|
|
||||||
protocol. SCTP was also an inspiration in the design.
|
|
||||||
|
|
||||||
5.1. Message Types
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Type | ID | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| S_OPEN | 20 | Initiate a streaming connection (like TCP SYN) |
|
|
||||||
| S_CLOSE | 21 | Terminate a streaming connection (like TCP RST/FIN) |
|
|
||||||
| S_DATA | 22 | Data packet |
|
|
||||||
| S_ACK | 23 | Acknowedge receipt of one or more data packets |
|
|
||||||
| S_DACK | 24 | Combination of DATA and ACK |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
5.2. Message Details
|
|
||||||
|
|
||||||
5.2.1. S_OPEN
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Sender Link ID | 2 | 16-bit sender link ID |
|
|
||||||
| Destination Port | 2 | 16-bit destination port |
|
|
||||||
| Window Size | 2 | 16-bit window size in 1024-byte increments |
|
|
||||||
| Init. Seq. Number | 4 | 32-bit initial sequence number |
|
|
||||||
| Flags | 1 | 8-bit flags |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
The OPEN message corresponds to TCP SYN, and initiates a connection. It
|
|
||||||
specifies the initial window size for the sender and the sender's initial
|
|
||||||
sequence number, which should be randomly chosen to prevent replay attacks.
|
|
||||||
|
|
||||||
If OPEN is successful, the recipient sends its own OPEN to establish the
|
|
||||||
connetion. If OPEN is unsuccessful, CLOSE is sent with its initial and current
|
|
||||||
sequence numbers equal and an appropriate reason such as "connection refused."
|
|
||||||
|
|
||||||
The sender link ID must be unique for a given recipient.
|
|
||||||
|
|
||||||
If flag 01 is set, the sender link ID is actually a source port where the
|
|
||||||
sender might be listening for connections as well. This exactly duplicates
|
|
||||||
the behavior of standard TCP. Otherwise, the sender link ID is simply an
|
|
||||||
arbitrary number that the sender uses to identify the connection with this
|
|
||||||
recipient and there is no port of origin. Ports of origin are optional for
|
|
||||||
Anode streaming connections to permit greater scalability.
|
|
||||||
|
|
||||||
5.2.2. S_CLOSE
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Sender Link ID | 2 | 16-bit sender link ID |
|
|
||||||
| Destination Port | 2 | 16-bit destination port |
|
|
||||||
| Flags | 1 | 8-bit flags |
|
|
||||||
| Reason | 1 | 8-bit close reason |
|
|
||||||
| Init. Seq. Number | 4 | 32-bit initial sequence number |
|
|
||||||
| Sequence Number | 4 | 32-bit current sequence number |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
The CLOSE message serves a function similar to TCP FIN. The initial sequence
|
|
||||||
number is the original starting sequence number sent with S_OPEN, while the
|
|
||||||
current sequence number is the sequence number corresponding to the close
|
|
||||||
and must be ACKed to complete the close operation. The use of the initial
|
|
||||||
sequence number helps to serve as a key to prevent replay attacks.
|
|
||||||
|
|
||||||
CLOSE is also used to indicate a failed OPEN attempt. In this case the current
|
|
||||||
sequence number will be equal to the initial sequence number and no ACK will
|
|
||||||
be expected.
|
|
||||||
|
|
||||||
There are currently no flags, so flags must be zero.
|
|
||||||
|
|
||||||
The reason field describes the reason for the close:
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Reason Code | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| 00 | Application closed connection |
|
|
||||||
| 01 | Connection refused |
|
|
||||||
| 02 | Protocol error |
|
|
||||||
| 03 | Timed out |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
Established connections will usually be closed with reason 00, while reason
|
|
||||||
01 is usually provided if an OPEN is received but the port is not bound.
|
|
||||||
|
|
||||||
5.2.3. S_DATA
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Sender Link ID | 2 | 16-bit sender link ID |
|
|
||||||
| Destination Port | 2 | 16-bit destination port |
|
|
||||||
| Sequence Number | 4 | 32-bit sequence number |
|
|
||||||
| Payload | ? | Data payload |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
The DATA message carries a packet of data, with the sequence number
|
|
||||||
determining order. The sequence number is monotonically incremented with
|
|
||||||
each data packet, and wraps at the maximum value of an unsigned 32-bit
|
|
||||||
integer.
|
|
||||||
|
|
||||||
5.2.4. S_ACK
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Sender Link ID | 2 | 16-bit sender link ID |
|
|
||||||
| Destination Port | 2 | 16-bit destination port |
|
|
||||||
| Window Size | 2 | 16-bit window size in 1024-byte increments |
|
|
||||||
| Acknowledgements | ? | One or more acknowledgements (see below) |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
Each acknowledgement is a 32-bit integer followed by an 8-bit integer (5 bytes
|
|
||||||
total). The 32-bit integer is the first sequence number to acknowledge, and
|
|
||||||
the 8-bit integer is the number of sequential following sequence numbers to
|
|
||||||
acknowledge. For example "1, 4" would acknowledge sequence numbers 1, 2, 3,
|
|
||||||
and 4.
|
|
||||||
|
|
||||||
5.2.5. S_DACK
|
|
||||||
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Field | Length | Description |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
| Sender Link ID | 2 | 16-bit sender link ID |
|
|
||||||
| Destination Port | 2 | 16-bit destination port |
|
|
||||||
| Window Size | 2 | 16-bit window size in 1024-byte increments |
|
|
||||||
| Num. Acks | 1 | 8-bit number of acknowledgements |
|
|
||||||
| Acknowledgements | ? | One or more acknowledgements |
|
|
||||||
| Payload | ? | Data payload |
|
|
||||||
|---------------------------------------------------------------------------|
|
|
||||||
|
|
||||||
The DACK message combines ACK and DATA, allowing two peers that are both
|
|
||||||
transmitting data to efficiently ACK without a separate packet.
|
|
|
@ -1,8 +0,0 @@
|
||||||
Dockerized Linux Build Farm
|
|
||||||
======
|
|
||||||
|
|
||||||
This subfolder contains Dockerfiles and a script to build Linux packages for a variety of Linux distributions. It's also an excellent way to test your CPU fans and stress test your disk.
|
|
||||||
|
|
||||||
Running `build.sh` with no arguments builds everything. You can run `build.sh` with the name of a distro (e.g. centos-7) to only build that. Both 32 and 64 bit packages are built except where no 32-bit version of the distribution exists.
|
|
||||||
|
|
||||||
The `make-apt-repos.sh` and `make-rpm-repos.sh` scripts build repositories. They may require some editing for outside-of-ZeroTier use, and be careful with the apt one if you have an existing *aptly* configuration.
|
|
|
@ -1,13 +0,0 @@
|
||||||
#FROM ambakshi/amazon-linux:2016.03
|
|
||||||
#MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
#RUN yum update -y
|
|
||||||
#RUN yum install -y epel-release
|
|
||||||
#RUN yum install -y make development-tools rpmdevtools clang gcc-c++ ruby ruby-devel
|
|
||||||
|
|
||||||
#RUN gem install ronn
|
|
||||||
|
|
||||||
FROM zerotier/zt1-build-amazon-2016.03-x64-base
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,69 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
export PATH=/bin:/usr/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin
|
|
||||||
|
|
||||||
subdirs=$*
|
|
||||||
if [ ! -n "$subdirs" ]; then
|
|
||||||
subdirs=`find . -type d -name '*-*' -printf '%f '`
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -d ./ubuntu-trusty ]; then
|
|
||||||
echo 'Must run from linux-build-farm subfolder.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -f zt1-src.tar.gz
|
|
||||||
cd ..
|
|
||||||
git archive --format=tar.gz --prefix=ZeroTierOne/ -o linux-build-farm/zt1-src.tar.gz HEAD
|
|
||||||
cd linux-build-farm
|
|
||||||
|
|
||||||
# Note that --privileged is used so we can bind mount VM shares when building in a VM.
|
|
||||||
# It has no other impact or purpose, but probably doesn't matter here in any case.
|
|
||||||
|
|
||||||
for distro in $subdirs; do
|
|
||||||
echo
|
|
||||||
echo "--- BUILDING FOR $distro ---"
|
|
||||||
echo
|
|
||||||
|
|
||||||
cd $distro
|
|
||||||
|
|
||||||
if [ -d x64 ]; then
|
|
||||||
cd x64
|
|
||||||
mv ../../zt1-src.tar.gz .
|
|
||||||
docker build -t zt1-build-${distro}-x64 .
|
|
||||||
mv zt1-src.tar.gz ../..
|
|
||||||
cd ..
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -d x86 ]; then
|
|
||||||
cd x86
|
|
||||||
mv ../../zt1-src.tar.gz .
|
|
||||||
docker build -t zt1-build-${distro}-x86 .
|
|
||||||
mv zt1-src.tar.gz ../..
|
|
||||||
cd ..
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -f *.deb *.rpm
|
|
||||||
|
|
||||||
# exit 0
|
|
||||||
|
|
||||||
if [ ! -n "`echo $distro | grep -F debian`" -a ! -n "`echo $distro | grep -F ubuntu`" ]; then
|
|
||||||
if [ -d x64 ]; then
|
|
||||||
docker run --rm -v `pwd`:/artifacts --privileged -it zt1-build-${distro}-x64 /bin/bash -c 'cd /ZeroTierOne ; make redhat ; cd .. ; cp `find /root/rpmbuild -type f -name *.rpm` /artifacts ; ls -l /artifacts'
|
|
||||||
fi
|
|
||||||
if [ -d x86 ]; then
|
|
||||||
docker run --rm -v `pwd`:/artifacts --privileged -it zt1-build-${distro}-x86 /bin/bash -c 'cd /ZeroTierOne ; make redhat ; cd .. ; cp `find /root/rpmbuild -type f -name *.rpm` /artifacts ; ls -l /artifacts'
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if [ -d x64 ]; then
|
|
||||||
docker run --rm -v `pwd`:/artifacts --privileged -it zt1-build-${distro}-x64 /bin/bash -c 'cd /ZeroTierOne ; make debian ; cd .. ; cp *.deb /artifacts ; ls -l /artifacts'
|
|
||||||
fi
|
|
||||||
if [ -d x86 ]; then
|
|
||||||
docker run --rm -v `pwd`:/artifacts --privileged -it zt1-build-${distro}-x86 /bin/bash -c 'cd /ZeroTierOne ; make debian ; cd .. ; cp *.deb /artifacts ; ls -l /artifacts'
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
cd ..
|
|
||||||
done
|
|
||||||
|
|
||||||
rm -f zt1-src.tar.gz
|
|
|
@ -1,13 +0,0 @@
|
||||||
FROM centos:6
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN yum update -y
|
|
||||||
RUN yum install -y epel-release
|
|
||||||
RUN yum install -y make development-tools rpmdevtools clang gcc-c++ tar
|
|
||||||
|
|
||||||
RUN yum install -y nodejs npm
|
|
||||||
|
|
||||||
# Stop use of http-parser-devel which is installed by nodejs/npm
|
|
||||||
RUN rm -f /usr/include/http_parser.h
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,13 +0,0 @@
|
||||||
FROM toopher/centos-i386:centos6
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN yum update -y
|
|
||||||
RUN yum install -y epel-release
|
|
||||||
RUN yum install -y make development-tools rpmdevtools clang gcc-c++ tar
|
|
||||||
|
|
||||||
RUN yum install -y nodejs npm
|
|
||||||
|
|
||||||
# Stop use of http-parser-devel which is installed by nodejs/npm
|
|
||||||
RUN rm -f /usr/include/http_parser.h
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,10 +0,0 @@
|
||||||
FROM centos:7
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN yum update -y
|
|
||||||
RUN yum install -y epel-release
|
|
||||||
RUN yum install -y make development-tools rpmdevtools clang gcc-c++ ruby ruby-devel
|
|
||||||
|
|
||||||
RUN gem install ronn
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,22 +0,0 @@
|
||||||
#FROM zerotier/centos7-32bit
|
|
||||||
#MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
#RUN echo 'i686-redhat-linux' >/etc/rpm/platform
|
|
||||||
|
|
||||||
#RUN yum update -y
|
|
||||||
#RUN yum install -y make development-tools rpmdevtools http-parser-devel lz4-devel libnatpmp-devel
|
|
||||||
|
|
||||||
#RUN yum install -y gcc-c++
|
|
||||||
#RUN rpm --install --force https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
|
|
||||||
#RUN rpm --install --force ftp://rpmfind.net/linux/centos/6.8/os/i386/Packages/libffi-3.0.5-3.2.el6.i686.rpm
|
|
||||||
#RUN yum install -y clang
|
|
||||||
|
|
||||||
FROM zerotier/zt1-build-centos-7-x86-base
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN yum install -y ruby ruby-devel
|
|
||||||
RUN gem install ronn
|
|
||||||
|
|
||||||
#RUN rpm --erase http-parser-devel lz4-devel libnatpmp-devel
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,12 +0,0 @@
|
||||||
FROM debian:jessie
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y build-essential debhelper libhttp-parser-dev liblz4-dev libnatpmp-dev dh-systemd ruby-ronn g++ make devscripts clang-3.5
|
|
||||||
|
|
||||||
RUN ln -sf /usr/bin/clang++-3.5 /usr/bin/clang++
|
|
||||||
RUN ln -sf /usr/bin/clang-3.5 /usr/bin/clang
|
|
||||||
|
|
||||||
RUN dpkg --purge libhttp-parser-dev
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,12 +0,0 @@
|
||||||
FROM 32bit/debian:jessie
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y build-essential debhelper libhttp-parser-dev liblz4-dev libnatpmp-dev dh-systemd ruby-ronn g++ make devscripts clang-3.5
|
|
||||||
|
|
||||||
RUN ln -sf /usr/bin/clang++-3.5 /usr/bin/clang++
|
|
||||||
RUN ln -sf /usr/bin/clang-3.5 /usr/bin/clang
|
|
||||||
|
|
||||||
RUN dpkg --purge libhttp-parser-dev
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,12 +0,0 @@
|
||||||
FROM debian:stretch
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y build-essential debhelper libhttp-parser-dev liblz4-dev libnatpmp-dev dh-systemd ruby-ronn g++ make devscripts clang
|
|
||||||
|
|
||||||
#RUN ln -sf /usr/bin/clang++-3.5 /usr/bin/clang++
|
|
||||||
#RUN ln -sf /usr/bin/clang-3.5 /usr/bin/clang
|
|
||||||
|
|
||||||
RUN dpkg --purge libhttp-parser-dev
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,12 +0,0 @@
|
||||||
FROM mcandre/docker-debian-32bit:stretch
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y build-essential debhelper libhttp-parser-dev liblz4-dev libnatpmp-dev dh-systemd ruby-ronn g++ make devscripts clang
|
|
||||||
|
|
||||||
#RUN ln -sf /usr/bin/clang++-3.5 /usr/bin/clang++
|
|
||||||
#RUN ln -sf /usr/bin/clang-3.5 /usr/bin/clang
|
|
||||||
|
|
||||||
RUN dpkg --purge libhttp-parser-dev
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,12 +0,0 @@
|
||||||
FROM debian:wheezy
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y build-essential debhelper ruby-ronn g++ make devscripts
|
|
||||||
|
|
||||||
RUN dpkg --purge libhttp-parser-dev
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
||||||
|
|
||||||
RUN mv -f /ZeroTierOne/debian/control.wheezy /ZeroTierOne/debian/control
|
|
||||||
RUN mv -f /ZeroTierOne/debian/rules.wheezy /ZeroTierOne/debian/rules
|
|
|
@ -1,15 +0,0 @@
|
||||||
#FROM tubia/debian:wheezy
|
|
||||||
#MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
#RUN apt-get update
|
|
||||||
#RUN apt-get install -y build-essential debhelper ruby-ronn g++ make devscripts
|
|
||||||
|
|
||||||
FROM zerotier/zt1-build-debian-wheezy-x86-base
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN dpkg --purge libhttp-parser-dev
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
||||||
|
|
||||||
RUN mv -f /ZeroTierOne/debian/control.wheezy /ZeroTierOne/debian/control
|
|
||||||
RUN mv -f /ZeroTierOne/debian/rules.wheezy /ZeroTierOne/debian/rules
|
|
|
@ -1,10 +0,0 @@
|
||||||
FROM fedora:22
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN yum update -y
|
|
||||||
RUN yum install -y make rpmdevtools gcc-c++ rubygem-ronn json-parser-devel lz4-devel http-parser-devel libnatpmp-devel
|
|
||||||
|
|
||||||
RUN rpm --erase http-parser-devel
|
|
||||||
RUN yum install -y rubygem-ronn ruby
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,19 +0,0 @@
|
||||||
#FROM nickcis/fedora-32:22
|
|
||||||
#MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
#RUN mkdir -p /etc/dnf/vars
|
|
||||||
#RUN echo 'i386' >/etc/dnf/vars/basearch
|
|
||||||
#RUN echo 'i386' >/etc/dnf/vars/arch
|
|
||||||
|
|
||||||
#RUN yum update -y
|
|
||||||
#RUN yum install -y make rpmdevtools gcc-c++ rubygem-ronn json-parser-devel lz4-devel http-parser-devel libnatpmp-devel
|
|
||||||
|
|
||||||
FROM zerotier/zt1-build-fedora-22-x86-base
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN echo 'i686-redhat-linux' >/etc/rpm/platform
|
|
||||||
|
|
||||||
RUN rpm --erase http-parser-devel
|
|
||||||
RUN yum install -y rubygem-ronn ruby
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,16 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# This builds a series of Debian repositories for each distribution.
|
|
||||||
|
|
||||||
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
|
|
||||||
|
|
||||||
for distro in debian-* ubuntu-*; do
|
|
||||||
if [ -n "`find ${distro} -name '*.deb' -type f`" ]; then
|
|
||||||
arches=`ls ${distro}/*.deb | cut -d _ -f 3 | cut -d . -f 1 | xargs | sed 's/ /,/g'`
|
|
||||||
distro_name=`echo $distro | cut -d '-' -f 2`
|
|
||||||
echo '---' $distro / $distro_name / $arches
|
|
||||||
aptly repo create -architectures=${arches} -comment="ZeroTier, Inc. Debian Packages" -component="main" -distribution=${distro_name} zt-release-${distro_name}
|
|
||||||
aptly repo add zt-release-${distro_name} ${distro}/*.deb
|
|
||||||
aptly publish repo zt-release-${distro_name} $distro_name
|
|
||||||
fi
|
|
||||||
done
|
|
|
@ -1,64 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
|
|
||||||
|
|
||||||
GPG_KEY=contact@zerotier.com
|
|
||||||
|
|
||||||
rm -rf /tmp/zt-rpm-repo
|
|
||||||
mkdir /tmp/zt-rpm-repo
|
|
||||||
|
|
||||||
for distro in centos-* fedora-* amazon-*; do
|
|
||||||
dname=`echo $distro | cut -d '-' -f 1`
|
|
||||||
if [ "$dname" = "centos" ]; then
|
|
||||||
dname=el
|
|
||||||
fi
|
|
||||||
if [ "$dname" = "fedora" ]; then
|
|
||||||
dname=fc
|
|
||||||
fi
|
|
||||||
if [ "$dname" = "amazon" ]; then
|
|
||||||
dname=amzn1
|
|
||||||
fi
|
|
||||||
dvers=`echo $distro | cut -d '-' -f 2`
|
|
||||||
|
|
||||||
mkdir -p /tmp/zt-rpm-repo/$dname/$dvers
|
|
||||||
|
|
||||||
cp -v $distro/*.rpm /tmp/zt-rpm-repo/$dname/$dvers
|
|
||||||
done
|
|
||||||
|
|
||||||
rpmsign --resign --key-id=$GPG_KEY --digest-algo=sha256 `find /tmp/zt-rpm-repo -type f -name '*.rpm'`
|
|
||||||
|
|
||||||
for db in `find /tmp/zt-rpm-repo -mindepth 2 -maxdepth 2 -type d`; do
|
|
||||||
createrepo --database $db
|
|
||||||
done
|
|
||||||
|
|
||||||
# Stupid RHEL stuff
|
|
||||||
cd /tmp/zt-rpm-repo/el
|
|
||||||
ln -sf 6 6Client
|
|
||||||
ln -sf 6 6Workstation
|
|
||||||
ln -sf 6 6Server
|
|
||||||
ln -sf 6 6.0
|
|
||||||
ln -sf 6 6.1
|
|
||||||
ln -sf 6 6.2
|
|
||||||
ln -sf 6 6.3
|
|
||||||
ln -sf 6 6.4
|
|
||||||
ln -sf 6 6.5
|
|
||||||
ln -sf 6 6.6
|
|
||||||
ln -sf 6 6.7
|
|
||||||
ln -sf 6 6.8
|
|
||||||
ln -sf 6 6.9
|
|
||||||
ln -sf 7 7Client
|
|
||||||
ln -sf 7 7Workstation
|
|
||||||
ln -sf 7 7Server
|
|
||||||
ln -sf 7 7.0
|
|
||||||
ln -sf 7 7.1
|
|
||||||
ln -sf 7 7.2
|
|
||||||
ln -sf 7 7.3
|
|
||||||
ln -sf 7 7.4
|
|
||||||
ln -sf 7 7.5
|
|
||||||
ln -sf 7 7.6
|
|
||||||
ln -sf 7 7.7
|
|
||||||
ln -sf 7 7.8
|
|
||||||
ln -sf 7 7.9
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo Repo created in /tmp/zt-rpm-repo
|
|
|
@ -1,12 +0,0 @@
|
||||||
FROM ubuntu:14.04
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y build-essential debhelper libhttp-parser-dev liblz4-dev libnatpmp-dev dh-systemd ruby-ronn g++ make devscripts clang-3.6
|
|
||||||
|
|
||||||
RUN ln -sf /usr/bin/clang++-3.6 /usr/bin/clang++
|
|
||||||
RUN ln -sf /usr/bin/clang-3.6 /usr/bin/clang
|
|
||||||
|
|
||||||
RUN dpkg --purge libhttp-parser-dev
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,12 +0,0 @@
|
||||||
FROM 32bit/ubuntu:14.04
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y build-essential debhelper libhttp-parser-dev liblz4-dev libnatpmp-dev dh-systemd ruby-ronn g++ make devscripts clang-3.6
|
|
||||||
|
|
||||||
RUN ln -sf /usr/bin/clang++-3.6 /usr/bin/clang++
|
|
||||||
RUN ln -sf /usr/bin/clang-3.6 /usr/bin/clang
|
|
||||||
|
|
||||||
RUN dpkg --purge libhttp-parser-dev
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,12 +0,0 @@
|
||||||
FROM ubuntu:wily
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y build-essential debhelper libhttp-parser-dev liblz4-dev libnatpmp-dev dh-systemd ruby-ronn g++ make devscripts clang-3.7
|
|
||||||
|
|
||||||
RUN ln -sf /usr/bin/clang++-3.7 /usr/bin/clang++
|
|
||||||
RUN ln -sf /usr/bin/clang-3.7 /usr/bin/clang
|
|
||||||
|
|
||||||
RUN dpkg --purge libhttp-parser-dev
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,12 +0,0 @@
|
||||||
FROM daald/ubuntu32:wily
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y build-essential debhelper libhttp-parser-dev liblz4-dev libnatpmp-dev dh-systemd ruby-ronn g++ make devscripts clang-3.7
|
|
||||||
|
|
||||||
RUN ln -sf /usr/bin/clang++-3.7 /usr/bin/clang++
|
|
||||||
RUN ln -sf /usr/bin/clang-3.7 /usr/bin/clang
|
|
||||||
|
|
||||||
RUN dpkg --purge libhttp-parser-dev
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,14 +0,0 @@
|
||||||
FROM ubuntu:xenial
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y build-essential debhelper libhttp-parser-dev liblz4-dev libnatpmp-dev dh-systemd ruby-ronn g++ make devscripts clang-3.8
|
|
||||||
|
|
||||||
#RUN ln -sf /usr/bin/clang++-3.8 /usr/bin/clang++
|
|
||||||
#RUN ln -sf /usr/bin/clang-3.8 /usr/bin/clang
|
|
||||||
|
|
||||||
RUN rm -f /usr/bin/clang++ /usr/bin/clang
|
|
||||||
|
|
||||||
RUN dpkg --purge libhttp-parser-dev
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,14 +0,0 @@
|
||||||
FROM f69m/ubuntu32:xenial
|
|
||||||
MAINTAINER Adam Ierymenko <adam.ierymenko@zerotier.com>
|
|
||||||
|
|
||||||
RUN apt-get update
|
|
||||||
RUN apt-get install -y build-essential debhelper libhttp-parser-dev liblz4-dev libnatpmp-dev dh-systemd ruby-ronn g++ make devscripts clang-3.8
|
|
||||||
|
|
||||||
#RUN ln -sf /usr/bin/clang++-3.8 /usr/bin/clang++
|
|
||||||
#RUN ln -sf /usr/bin/clang-3.8 /usr/bin/clang
|
|
||||||
|
|
||||||
RUN rm -f /usr/bin/clang++ /usr/bin/clang
|
|
||||||
|
|
||||||
RUN dpkg --purge libhttp-parser-dev
|
|
||||||
|
|
||||||
ADD zt1-src.tar.gz /
|
|
|
@ -1,112 +0,0 @@
|
||||||
CREATE TABLE Config (
|
|
||||||
k varchar(16) PRIMARY KEY NOT NULL,
|
|
||||||
v varchar(1024) NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE Network (
|
|
||||||
id char(16) PRIMARY KEY NOT NULL,
|
|
||||||
name varchar(128) NOT NULL,
|
|
||||||
private integer NOT NULL DEFAULT(1),
|
|
||||||
enableBroadcast integer NOT NULL DEFAULT(1),
|
|
||||||
allowPassiveBridging integer NOT NULL DEFAULT(0),
|
|
||||||
multicastLimit integer NOT NULL DEFAULT(32),
|
|
||||||
creationTime integer NOT NULL DEFAULT(0),
|
|
||||||
revision integer NOT NULL DEFAULT(1),
|
|
||||||
memberRevisionCounter integer NOT NULL DEFAULT(1),
|
|
||||||
flags integer NOT NULL DEFAULT(0)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE AuthToken (
|
|
||||||
id integer PRIMARY KEY NOT NULL,
|
|
||||||
networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
|
|
||||||
authMode integer NOT NULL DEFAULT(1),
|
|
||||||
useCount integer NOT NULL DEFAULT(0),
|
|
||||||
maxUses integer NOT NULL DEFAULT(0),
|
|
||||||
expiresAt integer NOT NULL DEFAULT(0),
|
|
||||||
token varchar(256) NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX AuthToken_networkId_token ON AuthToken(networkId,token);
|
|
||||||
|
|
||||||
CREATE TABLE Node (
|
|
||||||
id char(10) PRIMARY KEY NOT NULL,
|
|
||||||
identity varchar(4096) NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IpAssignment (
|
|
||||||
networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
|
|
||||||
nodeId char(10) REFERENCES Node(id) ON DELETE CASCADE,
|
|
||||||
type integer NOT NULL DEFAULT(0),
|
|
||||||
ip blob(16) NOT NULL,
|
|
||||||
ipNetmaskBits integer NOT NULL DEFAULT(0),
|
|
||||||
ipVersion integer NOT NULL DEFAULT(4)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE UNIQUE INDEX IpAssignment_networkId_ip ON IpAssignment (networkId, ip);
|
|
||||||
|
|
||||||
CREATE INDEX IpAssignment_networkId_nodeId ON IpAssignment (networkId, nodeId);
|
|
||||||
|
|
||||||
CREATE TABLE IpAssignmentPool (
|
|
||||||
networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
|
|
||||||
ipRangeStart blob(16) NOT NULL,
|
|
||||||
ipRangeEnd blob(16) NOT NULL,
|
|
||||||
ipVersion integer NOT NULL DEFAULT(4)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE UNIQUE INDEX IpAssignmentPool_networkId_ipRangeStart ON IpAssignmentPool (networkId,ipRangeStart);
|
|
||||||
|
|
||||||
CREATE TABLE Member (
|
|
||||||
networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
|
|
||||||
nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,
|
|
||||||
authorized integer NOT NULL DEFAULT(0),
|
|
||||||
activeBridge integer NOT NULL DEFAULT(0),
|
|
||||||
memberRevision integer NOT NULL DEFAULT(0),
|
|
||||||
flags integer NOT NULL DEFAULT(0),
|
|
||||||
lastRequestTime integer NOT NULL DEFAULT(0),
|
|
||||||
lastPowDifficulty integer NOT NULL DEFAULT(0),
|
|
||||||
lastPowTime integer NOT NULL DEFAULT(0),
|
|
||||||
recentHistory blob,
|
|
||||||
PRIMARY KEY (networkId, nodeId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX Member_networkId_nodeId ON Member(networkId,nodeId);
|
|
||||||
CREATE INDEX Member_networkId_activeBridge ON Member(networkId, activeBridge);
|
|
||||||
CREATE INDEX Member_networkId_memberRevision ON Member(networkId, memberRevision);
|
|
||||||
CREATE INDEX Member_networkId_lastRequestTime ON Member(networkId, lastRequestTime);
|
|
||||||
|
|
||||||
CREATE TABLE Route (
|
|
||||||
networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
|
|
||||||
target blob(16) NOT NULL,
|
|
||||||
via blob(16),
|
|
||||||
targetNetmaskBits integer NOT NULL,
|
|
||||||
ipVersion integer NOT NULL,
|
|
||||||
flags integer NOT NULL,
|
|
||||||
metric integer NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX Route_networkId ON Route (networkId);
|
|
||||||
|
|
||||||
CREATE TABLE Rule (
|
|
||||||
networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
|
|
||||||
capId integer,
|
|
||||||
ruleNo integer NOT NULL,
|
|
||||||
ruleType integer NOT NULL DEFAULT(0),
|
|
||||||
"addr" blob(16),
|
|
||||||
"int1" integer,
|
|
||||||
"int2" integer,
|
|
||||||
"int3" integer,
|
|
||||||
"int4" integer
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX Rule_networkId_capId ON Rule (networkId,capId);
|
|
||||||
|
|
||||||
CREATE TABLE MemberTC (
|
|
||||||
networkId char(16) NOT NULL REFERENCES Network(id) ON DELETE CASCADE,
|
|
||||||
nodeId char(10) NOT NULL REFERENCES Node(id) ON DELETE CASCADE,
|
|
||||||
tagId integer,
|
|
||||||
tagValue integer,
|
|
||||||
capId integer,
|
|
||||||
capMaxCustodyChainLength integer NOT NULL DEFAULT(1)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX MemberTC_networkId_nodeId ON MemberTC (networkId,nodeId);
|
|
|
@ -1,134 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# This script builds the installer for *nix systems. Windows must do everything
|
|
||||||
# completely differently, as usual.
|
|
||||||
|
|
||||||
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
|
|
||||||
|
|
||||||
if [ ! -f zerotier-one ]; then
|
|
||||||
echo "Could not find 'zerotier-one' binary, please build before running this script."
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
machine=`uname -m`
|
|
||||||
system=`uname -s`
|
|
||||||
|
|
||||||
vmajor=`cat version.h | grep -F ZEROTIER_ONE_VERSION_MAJOR | cut -d ' ' -f 3`
|
|
||||||
vminor=`cat version.h | grep -F ZEROTIER_ONE_VERSION_MINOR | cut -d ' ' -f 3`
|
|
||||||
revision=`cat version.h | grep -F ZEROTIER_ONE_VERSION_REVISION | cut -d ' ' -f 3`
|
|
||||||
|
|
||||||
if [ -z "$vmajor" -o -z "$vminor" -o -z "$revision" ]; then
|
|
||||||
echo "Unable to extract version info from version.h, aborting installer build."
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -rf build-installer
|
|
||||||
mkdir build-installer
|
|
||||||
|
|
||||||
case "$system" in
|
|
||||||
|
|
||||||
Linux)
|
|
||||||
# Canonicalize $machine for some architectures... we use x86
|
|
||||||
# and x64 for Intel stuff. ARM and others should be fine if
|
|
||||||
# we ever ship officially for those.
|
|
||||||
debian_arch=$machine
|
|
||||||
case "$machine" in
|
|
||||||
i386|i486|i586|i686)
|
|
||||||
machine="x86"
|
|
||||||
debian_arch="i386"
|
|
||||||
;;
|
|
||||||
x86_64|amd64|x64)
|
|
||||||
machine="x64"
|
|
||||||
debian_arch="amd64"
|
|
||||||
;;
|
|
||||||
armv6l|arm|armhf|arm7l|armv7l)
|
|
||||||
machine="armv6l"
|
|
||||||
debian_arch="armhf"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
echo "Assembling Linux installer for $machine and version $vmajor.$vminor.$revision"
|
|
||||||
|
|
||||||
mkdir -p 'build-installer/var/lib/zerotier-one/ui'
|
|
||||||
cp -fp 'ext/installfiles/linux/uninstall.sh' 'build-installer/var/lib/zerotier-one'
|
|
||||||
cp -fp 'zerotier-one' 'build-installer/var/lib/zerotier-one'
|
|
||||||
for f in ui/*.html ui/*.js ui/*.css ui/*.jsx ; do
|
|
||||||
cp -fp "$f" 'build-installer/var/lib/zerotier-one/ui'
|
|
||||||
done
|
|
||||||
mkdir -p 'build-installer/tmp'
|
|
||||||
cp -fp 'ext/installfiles/linux/init.d/zerotier-one' 'build-installer/tmp/init.d_zerotier-one'
|
|
||||||
cp -fp 'ext/installfiles/linux/systemd/zerotier-one.service' 'build-installer/tmp/systemd_zerotier-one.service'
|
|
||||||
|
|
||||||
targ="ZeroTierOneInstaller-linux-${machine}-${vmajor}_${vminor}_${revision}"
|
|
||||||
# Use gzip in Linux since some minimal Linux systems do not have bunzip2
|
|
||||||
rm -f build-installer-tmp.tar.gz
|
|
||||||
cd build-installer
|
|
||||||
tar -cf - * | gzip -9 >../build-installer-tmp.tar.gz
|
|
||||||
cd ..
|
|
||||||
rm -f $targ
|
|
||||||
cat ext/installfiles/linux/install.tmpl.sh build-installer-tmp.tar.gz >$targ
|
|
||||||
chmod 0755 $targ
|
|
||||||
rm -f build-installer-tmp.tar.gz
|
|
||||||
ls -l $targ
|
|
||||||
|
|
||||||
if [ -f /usr/bin/dpkg-deb -a "$UID" -eq 0 ]; then
|
|
||||||
echo
|
|
||||||
echo Found dpkg-deb and you are root, trying to build Debian package.
|
|
||||||
|
|
||||||
rm -rf build-installer-deb
|
|
||||||
|
|
||||||
debbase="build-installer-deb/zerotier-one_${vmajor}.${vminor}.${revision}_$debian_arch"
|
|
||||||
debfolder="${debbase}/DEBIAN"
|
|
||||||
mkdir -p $debfolder
|
|
||||||
|
|
||||||
cat 'ext/installfiles/linux/DEBIAN/control.in' | sed "s/__VERSION__/${vmajor}.${vminor}.${revision}/" | sed "s/__ARCH__/${debian_arch}/" >$debfolder/control
|
|
||||||
cat $debfolder/control
|
|
||||||
cp -f 'ext/installfiles/linux/DEBIAN/conffiles' "${debfolder}/conffiles"
|
|
||||||
|
|
||||||
mkdir -p "${debbase}/var/lib/zerotier-one/updates.d"
|
|
||||||
cp -f $targ "${debbase}/var/lib/zerotier-one/updates.d"
|
|
||||||
|
|
||||||
rm -f "${debfolder}/postinst" "${debfolder}/prerm"
|
|
||||||
|
|
||||||
echo '#!/bin/bash' >${debfolder}/postinst
|
|
||||||
echo "/var/lib/zerotier-one/updates.d/${targ} >>/dev/null 2>&1" >>${debfolder}/postinst
|
|
||||||
echo "/bin/rm -f /var/lib/zerotier-one/updates.d/*" >>${debfolder}/postinst
|
|
||||||
chmod a+x ${debfolder}/postinst
|
|
||||||
|
|
||||||
echo '#!/bin/bash' >${debfolder}/prerm
|
|
||||||
echo 'export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin' >>${debfolder}/prerm
|
|
||||||
echo 'if [ "$1" != "upgrade" ]; then' >>${debfolder}/prerm
|
|
||||||
echo ' /var/lib/zerotier-one/uninstall.sh >>/dev/null 2>&1' >>${debfolder}/prerm
|
|
||||||
echo 'fi' >>${debfolder}/prerm
|
|
||||||
chmod a+x ${debfolder}/prerm
|
|
||||||
|
|
||||||
dpkg-deb --build $debbase
|
|
||||||
|
|
||||||
mv -f build-installer-deb/*.deb .
|
|
||||||
rm -rf build-installer-deb
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f /usr/bin/rpmbuild ]; then
|
|
||||||
echo
|
|
||||||
echo Found rpmbuild, trying to build RedHat/CentOS package.
|
|
||||||
|
|
||||||
rm -f /tmp/zerotier-one.spec
|
|
||||||
curr_dir=`pwd`
|
|
||||||
cat ext/installfiles/linux/RPM/zerotier-one.spec.in | sed "s/__VERSION__/${vmajor}.${vminor}.${revision}/g" | sed "s/__INSTALLER__/${targ}/g" >/tmp/zerotier-one.spec
|
|
||||||
|
|
||||||
rpmbuild -ba /tmp/zerotier-one.spec
|
|
||||||
|
|
||||||
rm -f /tmp/zerotier-one.spec
|
|
||||||
fi
|
|
||||||
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo "Unsupported platform: $system"
|
|
||||||
exit 2
|
|
||||||
|
|
||||||
esac
|
|
||||||
|
|
||||||
rm -rf build-installer
|
|
||||||
|
|
||||||
exit 0
|
|
|
@ -1,182 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
|
||||||
shopt -s expand_aliases
|
|
||||||
|
|
||||||
dryRun=0
|
|
||||||
|
|
||||||
echo "*** ZeroTier One install/update ***"
|
|
||||||
echo
|
|
||||||
|
|
||||||
if [ "$UID" -ne 0 ]; then
|
|
||||||
echo "Not running as root so doing dry run (no modifications to system)..."
|
|
||||||
dryRun=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $dryRun -gt 0 ]; then
|
|
||||||
alias ln="echo '>> ln'"
|
|
||||||
alias rm="echo '>> rm'"
|
|
||||||
alias mv="echo '>> mv'"
|
|
||||||
alias cp="echo '>> cp'"
|
|
||||||
alias chown="echo '>> chown'"
|
|
||||||
alias chgrp="echo '>> chgrp'"
|
|
||||||
alias chmod="echo '>> chmod'"
|
|
||||||
alias chkconfig="echo '>> chkconfig'"
|
|
||||||
alias zerotier-cli="echo '>> zerotier-cli'"
|
|
||||||
alias service="echo '>> service'"
|
|
||||||
alias systemctl="echo '>> systemctl'"
|
|
||||||
fi
|
|
||||||
|
|
||||||
scriptPath="`dirname "$0"`/`basename "$0"`"
|
|
||||||
if [ ! -r "$scriptPath" ]; then
|
|
||||||
scriptPath="$0"
|
|
||||||
if [ ! -r "$scriptPath" ]; then
|
|
||||||
echo "Installer cannot determine its own path; $scriptPath is not readable."
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check for systemd vs. old school SysV init
|
|
||||||
SYSTEMDUNITDIR=
|
|
||||||
if [ -e /bin/systemctl -o -e /usr/bin/systemctl -o -e /usr/local/bin/systemctl -o -e /sbin/systemctl -o -e /usr/sbin/systemctl ]; then
|
|
||||||
# Second check: test if systemd appears to actually be running. Apparently Ubuntu
|
|
||||||
# thought it was a good idea to ship with systemd installed but not used. Issue #133
|
|
||||||
if [ -d /var/run/systemd/system -o -d /run/systemd/system ]; then
|
|
||||||
if [ -e /usr/bin/pkg-config ]; then
|
|
||||||
SYSTEMDUNITDIR=`/usr/bin/pkg-config systemd --variable=systemdsystemunitdir`
|
|
||||||
fi
|
|
||||||
if [ -z "$SYSTEMDUNITDIR" -o ! -d "$SYSTEMDUNITDIR" ]; then
|
|
||||||
if [ -d /usr/lib/systemd/system ]; then
|
|
||||||
SYSTEMDUNITDIR=/usr/lib/systemd/system
|
|
||||||
fi
|
|
||||||
if [ -d /etc/systemd/system ]; then
|
|
||||||
SYSTEMDUNITDIR=/etc/systemd/system
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Find the end of this script, which is where we have appended binary data.
|
|
||||||
endMarkerIndex=`grep -a -b -E '^################' "$scriptPath" | head -c 16 | cut -d : -f 1`
|
|
||||||
if [ "$endMarkerIndex" -le 100 ]; then
|
|
||||||
echo 'Internal error: unable to find end of script / start of binary data marker.'
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
blobStart=`expr $endMarkerIndex + 17`
|
|
||||||
if [ "$blobStart" -le "$endMarkerIndex" ]; then
|
|
||||||
echo 'Internal error: unable to find end of script / start of binary data marker.'
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -n 'Getting version of existing install... '
|
|
||||||
origVersion=NONE
|
|
||||||
if [ -x /var/lib/zerotier-one/zerotier-one ]; then
|
|
||||||
origVersion=`/var/lib/zerotier-one/zerotier-one -v`
|
|
||||||
fi
|
|
||||||
echo $origVersion
|
|
||||||
|
|
||||||
echo 'Extracting files...'
|
|
||||||
if [ $dryRun -gt 0 ]; then
|
|
||||||
echo ">> tail -c +$blobStart \"$scriptPath\" | gunzip -c | tar -xvop -C / -f -"
|
|
||||||
tail -c +$blobStart "$scriptPath" | gunzip -c | tar -t -f - | sed 's/^/>> /'
|
|
||||||
else
|
|
||||||
tail -c +$blobStart "$scriptPath" | gunzip -c | tar -xvop --no-overwrite-dir -C / -f -
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $dryRun -eq 0 -a ! -x "/var/lib/zerotier-one/zerotier-one" ]; then
|
|
||||||
echo 'Archive extraction failed, cannot find zerotier-one binary in "/var/lib/zerotier-one".'
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -n 'Getting version of new install... '
|
|
||||||
newVersion=`/var/lib/zerotier-one/zerotier-one -v`
|
|
||||||
echo $newVersion
|
|
||||||
|
|
||||||
echo 'Creating symlinks...'
|
|
||||||
|
|
||||||
rm -f /usr/bin/zerotier-cli /usr/bin/zerotier-idtool
|
|
||||||
ln -sf /var/lib/zerotier-one/zerotier-one /usr/bin/zerotier-cli
|
|
||||||
ln -sf /var/lib/zerotier-one/zerotier-one /usr/bin/zerotier-idtool
|
|
||||||
|
|
||||||
echo 'Installing zerotier-one service...'
|
|
||||||
|
|
||||||
if [ -n "$SYSTEMDUNITDIR" -a -d "$SYSTEMDUNITDIR" ]; then
|
|
||||||
# SYSTEMD
|
|
||||||
|
|
||||||
# If this was updated or upgraded from an init.d based system, clean up the old
|
|
||||||
# init.d stuff before installing directly via systemd.
|
|
||||||
if [ -f /etc/init.d/zerotier-one ]; then
|
|
||||||
if [ -e /sbin/chkconfig -o -e /usr/sbin/chkconfig -o -e /bin/chkconfig -o -e /usr/bin/chkconfig ]; then
|
|
||||||
chkconfig zerotier-one off
|
|
||||||
fi
|
|
||||||
rm -f /etc/init.d/zerotier-one
|
|
||||||
fi
|
|
||||||
|
|
||||||
cp -f /tmp/systemd_zerotier-one.service "$SYSTEMDUNITDIR/zerotier-one.service"
|
|
||||||
chown 0 "$SYSTEMDUNITDIR/zerotier-one.service"
|
|
||||||
chgrp 0 "$SYSTEMDUNITDIR/zerotier-one.service"
|
|
||||||
chmod 0644 "$SYSTEMDUNITDIR/zerotier-one.service"
|
|
||||||
rm -f /tmp/systemd_zerotier-one.service /tmp/init.d_zerotier-one
|
|
||||||
|
|
||||||
systemctl enable zerotier-one.service
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo 'Done! Installed and service configured to start at system boot.'
|
|
||||||
echo
|
|
||||||
echo "To start now or restart the service if it's already running:"
|
|
||||||
echo ' sudo systemctl restart zerotier-one.service'
|
|
||||||
else
|
|
||||||
# SYSV INIT -- also covers upstart which supports SysVinit backward compatibility
|
|
||||||
|
|
||||||
cp -f /tmp/init.d_zerotier-one /etc/init.d/zerotier-one
|
|
||||||
chmod 0755 /etc/init.d/zerotier-one
|
|
||||||
rm -f /tmp/systemd_zerotier-one.service /tmp/init.d_zerotier-one
|
|
||||||
|
|
||||||
if [ -f /sbin/chkconfig -o -f /usr/sbin/chkconfig -o -f /usr/bin/chkconfig -o -f /bin/chkconfig ]; then
|
|
||||||
chkconfig zerotier-one on
|
|
||||||
else
|
|
||||||
# Yes Virginia, some systems lack chkconfig.
|
|
||||||
if [ -d /etc/rc0.d ]; then
|
|
||||||
rm -f /etc/rc0.d/???zerotier-one
|
|
||||||
ln -sf /etc/init.d/zerotier-one /etc/rc0.d/K89zerotier-one
|
|
||||||
fi
|
|
||||||
if [ -d /etc/rc1.d ]; then
|
|
||||||
rm -f /etc/rc1.d/???zerotier-one
|
|
||||||
ln -sf /etc/init.d/zerotier-one /etc/rc1.d/K89zerotier-one
|
|
||||||
fi
|
|
||||||
if [ -d /etc/rc2.d ]; then
|
|
||||||
rm -f /etc/rc2.d/???zerotier-one
|
|
||||||
ln -sf /etc/init.d/zerotier-one /etc/rc2.d/S11zerotier-one
|
|
||||||
fi
|
|
||||||
if [ -d /etc/rc3.d ]; then
|
|
||||||
rm -f /etc/rc3.d/???zerotier-one
|
|
||||||
ln -sf /etc/init.d/zerotier-one /etc/rc3.d/S11zerotier-one
|
|
||||||
fi
|
|
||||||
if [ -d /etc/rc4.d ]; then
|
|
||||||
rm -f /etc/rc4.d/???zerotier-one
|
|
||||||
ln -sf /etc/init.d/zerotier-one /etc/rc4.d/S11zerotier-one
|
|
||||||
fi
|
|
||||||
if [ -d /etc/rc5.d ]; then
|
|
||||||
rm -f /etc/rc5.d/???zerotier-one
|
|
||||||
ln -sf /etc/init.d/zerotier-one /etc/rc5.d/S11zerotier-one
|
|
||||||
fi
|
|
||||||
if [ -d /etc/rc6.d ]; then
|
|
||||||
rm -f /etc/rc6.d/???zerotier-one
|
|
||||||
ln -sf /etc/init.d/zerotier-one /etc/rc6.d/K89zerotier-one
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo 'Done! Installed and service configured to start at system boot.'
|
|
||||||
echo
|
|
||||||
echo "To start now or restart the service if it's already running:"
|
|
||||||
echo ' sudo service zerotier-one restart'
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
# Do not remove the last line or add a carriage return to it! The installer
|
|
||||||
# looks for an unterminated line beginning with 16 #'s in itself to find
|
|
||||||
# the binary blob data, which is appended after it.
|
|
||||||
|
|
||||||
################
|
|
|
@ -1,76 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
|
||||||
|
|
||||||
if [ "$UID" -ne 0 ]; then
|
|
||||||
echo "Must be run as root; try: sudo $0"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Detect systemd vs. regular init
|
|
||||||
SYSTEMDUNITDIR=
|
|
||||||
if [ -e /bin/systemctl -o -e /usr/bin/systemctl -o -e /usr/local/bin/systemctl -o -e /sbin/systemctl -o -e /usr/sbin/systemctl ]; then
|
|
||||||
if [ -e /usr/bin/pkg-config ]; then
|
|
||||||
SYSTEMDUNITDIR=`/usr/bin/pkg-config systemd --variable=systemdsystemunitdir`
|
|
||||||
fi
|
|
||||||
if [ -z "$SYSTEMDUNITDIR" -o ! -d "$SYSTEMDUNITDIR" ]; then
|
|
||||||
if [ -d /usr/lib/systemd/system ]; then
|
|
||||||
SYSTEMDUNITDIR=/usr/lib/systemd/system
|
|
||||||
fi
|
|
||||||
if [ -d /etc/systemd/system ]; then
|
|
||||||
SYSTEMDUNITDIR=/etc/systemd/system
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Killing any running zerotier-one service..."
|
|
||||||
if [ -n "$SYSTEMDUNITDIR" -a -d "$SYSTEMDUNITDIR" ]; then
|
|
||||||
systemctl stop zerotier-one.service
|
|
||||||
systemctl disable zerotier-one.service
|
|
||||||
else
|
|
||||||
if [ -f /sbin/service -o -f /usr/sbin/service -o -f /bin/service -o -f /usr/bin/service ]; then
|
|
||||||
service zerotier-one stop
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep 1
|
|
||||||
if [ -f /var/lib/zerotier-one/zerotier-one.pid ]; then
|
|
||||||
kill -TERM `cat /var/lib/zerotier-one/zerotier-one.pid`
|
|
||||||
sleep 1
|
|
||||||
fi
|
|
||||||
if [ -f /var/lib/zerotier-one/zerotier-one.pid ]; then
|
|
||||||
kill -KILL `cat /var/lib/zerotier-one/zerotier-one.pid`
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f /etc/init.d/zerotier-one ]; then
|
|
||||||
echo "Removing SysV init items..."
|
|
||||||
if [ -f /sbin/chkconfig -o -f /usr/sbin/chkconfig -o -f /bin/chkconfig -o -f /usr/bin/chkconfig ]; then
|
|
||||||
chkconfig zerotier-one off
|
|
||||||
fi
|
|
||||||
rm -f /etc/init.d/zerotier-one
|
|
||||||
find /etc/rc*.d -type f -name '???zerotier-one' -print0 | xargs -0 rm -f
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$SYSTEMDUNITDIR" -a -d "$SYSTEMDUNITDIR" -a -f "$SYSTEMDUNITDIR/zerotier-one.service" ]; then
|
|
||||||
echo "Removing systemd service..."
|
|
||||||
rm -f "$SYSTEMDUNITDIR/zerotier-one.service"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Erasing binary and support files..."
|
|
||||||
if [ -d /var/lib/zerotier-one ]; then
|
|
||||||
cd /var/lib/zerotier-one
|
|
||||||
rm -rf zerotier-one *.persist identity.public *.log *.pid *.sh updates.d networks.d iddb.d root-topology ui
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Erasing anything installed into system bin directories..."
|
|
||||||
rm -f /usr/local/bin/zerotier-cli /usr/bin/zerotier-cli /usr/local/bin/zerotier-idtool /usr/bin/zerotier-idtool
|
|
||||||
|
|
||||||
echo "Done."
|
|
||||||
echo
|
|
||||||
echo "Your ZeroTier One identity is still preserved in /var/lib/zerotier-one"
|
|
||||||
echo "as identity.secret and can be manually deleted if you wish. Save it if"
|
|
||||||
echo "you wish to re-use the address of this node, as it cannot be regenerated."
|
|
||||||
|
|
||||||
echo
|
|
||||||
|
|
||||||
exit 0
|
|
|
@ -1,7 +0,0 @@
|
||||||
World Definitions and Generator Code
|
|
||||||
======
|
|
||||||
|
|
||||||
This little bit of code is used to generate world updates. Ordinary users probably will never need this unless they want to test or experiment.
|
|
||||||
|
|
||||||
See mkworld.cpp for documentation. To build from this directory use 'source ./build.sh'.
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
c++ -I.. -o mkworld ../node/C25519.cpp ../node/Salsa20.cpp ../node/SHA512.cpp ../node/Identity.cpp ../node/Utils.cpp ../node/InetAddress.cpp ../osdep/OSUtils.cpp mkworld.cpp
|
|
|
@ -1,149 +0,0 @@
|
||||||
/*
|
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
|
||||||
* Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This utility makes the World from the configuration specified below.
|
|
||||||
* It probably won't be much use to anyone outside ZeroTier, Inc. except
|
|
||||||
* for testing and experimentation purposes.
|
|
||||||
*
|
|
||||||
* If you want to make your own World you must edit this file.
|
|
||||||
*
|
|
||||||
* When run, it expects two files in the current directory:
|
|
||||||
*
|
|
||||||
* previous.c25519 - key pair to sign this world (key from previous world)
|
|
||||||
* current.c25519 - key pair whose public key should be embedded in this world
|
|
||||||
*
|
|
||||||
* If these files do not exist, they are both created with the same key pair
|
|
||||||
* and a self-signed initial World is born.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include <node/Constants.hpp>
|
|
||||||
#include <node/World.hpp>
|
|
||||||
#include <node/C25519.hpp>
|
|
||||||
#include <node/Identity.hpp>
|
|
||||||
#include <node/InetAddress.hpp>
|
|
||||||
#include <osdep/OSUtils.hpp>
|
|
||||||
|
|
||||||
using namespace ZeroTier;
|
|
||||||
|
|
||||||
int main(int argc,char **argv)
|
|
||||||
{
|
|
||||||
std::string previous,current;
|
|
||||||
if ((!OSUtils::readFile("previous.c25519",previous))||(!OSUtils::readFile("current.c25519",current))) {
|
|
||||||
C25519::Pair np(C25519::generate());
|
|
||||||
previous = std::string();
|
|
||||||
previous.append((const char *)np.pub.data,ZT_C25519_PUBLIC_KEY_LEN);
|
|
||||||
previous.append((const char *)np.priv.data,ZT_C25519_PRIVATE_KEY_LEN);
|
|
||||||
current = previous;
|
|
||||||
OSUtils::writeFile("previous.c25519",previous);
|
|
||||||
OSUtils::writeFile("current.c25519",current);
|
|
||||||
fprintf(stderr,"INFO: created initial world keys: previous.c25519 and current.c25519 (both initially the same)"ZT_EOL_S);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((previous.length() != (ZT_C25519_PUBLIC_KEY_LEN + ZT_C25519_PRIVATE_KEY_LEN))||(current.length() != (ZT_C25519_PUBLIC_KEY_LEN + ZT_C25519_PRIVATE_KEY_LEN))) {
|
|
||||||
fprintf(stderr,"FATAL: previous.c25519 or current.c25519 empty or invalid"ZT_EOL_S);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
C25519::Pair previousKP;
|
|
||||||
memcpy(previousKP.pub.data,previous.data(),ZT_C25519_PUBLIC_KEY_LEN);
|
|
||||||
memcpy(previousKP.priv.data,previous.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
|
|
||||||
C25519::Pair currentKP;
|
|
||||||
memcpy(currentKP.pub.data,current.data(),ZT_C25519_PUBLIC_KEY_LEN);
|
|
||||||
memcpy(currentKP.priv.data,current.data() + ZT_C25519_PUBLIC_KEY_LEN,ZT_C25519_PRIVATE_KEY_LEN);
|
|
||||||
|
|
||||||
// =========================================================================
|
|
||||||
// EDIT BELOW HERE
|
|
||||||
|
|
||||||
std::vector<World::Root> roots;
|
|
||||||
|
|
||||||
const uint64_t id = ZT_WORLD_ID_EARTH;
|
|
||||||
const uint64_t ts = 1452708876314ULL; // January 13th, 2016
|
|
||||||
|
|
||||||
// Alice
|
|
||||||
roots.push_back(World::Root());
|
|
||||||
roots.back().identity = Identity("9d219039f3:0:01f0922a98e3b34ebcbff333269dc265d7a020aab69d72be4d4acc9c8c9294785771256cd1d942a90d1bd1d2dca3ea84ef7d85afe6611fb43ff0b74126d90a6e");
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("188.166.94.177/9993")); // Amsterdam
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("2a03:b0c0:2:d0::7d:1/9993")); // Amsterdam
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("154.66.197.33/9993")); // Johannesburg
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("2c0f:f850:154:197::33/9993")); // Johannesburg
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("159.203.97.171/9993")); // New York
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("2604:a880:800:a1::54:6001/9993")); // New York
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("169.57.143.104/9993")); // Sao Paolo
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("2607:f0d0:1d01:57::2/9993")); // Sao Paolo
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("107.170.197.14/9993")); // San Francisco
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("2604:a880:1:20::200:e001/9993")); // San Francisco
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("128.199.197.217/9993")); // Singapore
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("2400:6180:0:d0::b7:4001/9993")); // Singapore
|
|
||||||
|
|
||||||
// Bob
|
|
||||||
roots.push_back(World::Root());
|
|
||||||
roots.back().identity = Identity("8841408a2e:0:bb1d31f2c323e264e9e64172c1a74f77899555ed10751cd56e86405cde118d02dffe555d462ccf6a85b5631c12350c8d5dc409ba10b9025d0f445cf449d92b1c");
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("45.32.198.130/9993")); // Dallas
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("2001:19f0:6400:81c3:5400:00ff:fe18:1d61/9993")); // Dallas
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("46.101.160.249/9993")); // Frankfurt
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("2a03:b0c0:3:d0::6a:3001/9993")); // Frankfurt
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("107.191.46.210/9993")); // Paris
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("2001:19f0:6800:83a4::64/9993")); // Paris
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("45.32.246.179/9993")); // Sydney
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("2001:19f0:5800:8bf8:5400:ff:fe15:b39a/9993")); // Sydney
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("45.32.248.87/9993")); // Tokyo
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("2001:19f0:7000:9bc9:5400:00ff:fe15:c4f5/9993")); // Tokyo
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("159.203.2.154/9993")); // Toronto
|
|
||||||
roots.back().stableEndpoints.push_back(InetAddress("2604:a880:cad:d0::26:7001/9993")); // Toronto
|
|
||||||
|
|
||||||
// END WORLD DEFINITION
|
|
||||||
// =========================================================================
|
|
||||||
|
|
||||||
fprintf(stderr,"INFO: generating and signing id==%llu ts==%llu"ZT_EOL_S,(unsigned long long)id,(unsigned long long)ts);
|
|
||||||
|
|
||||||
World nw = World::make(World::TYPE_PLANET,id,ts,currentKP.pub,roots,previousKP);
|
|
||||||
|
|
||||||
Buffer<ZT_WORLD_MAX_SERIALIZED_LENGTH> outtmp;
|
|
||||||
nw.serialize(outtmp,false);
|
|
||||||
World testw;
|
|
||||||
testw.deserialize(outtmp,0);
|
|
||||||
if (testw != nw) {
|
|
||||||
fprintf(stderr,"FATAL: serialization test failed!"ZT_EOL_S);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
OSUtils::writeFile("world.bin",std::string((const char *)outtmp.data(),outtmp.size()));
|
|
||||||
fprintf(stderr,"INFO: world.bin written with %u bytes of binary world data."ZT_EOL_S,outtmp.size());
|
|
||||||
|
|
||||||
fprintf(stdout,ZT_EOL_S);
|
|
||||||
fprintf(stdout,"#define ZT_DEFAULT_WORLD_LENGTH %u"ZT_EOL_S,outtmp.size());
|
|
||||||
fprintf(stdout,"static const unsigned char ZT_DEFAULT_WORLD[ZT_DEFAULT_WORLD_LENGTH] = {");
|
|
||||||
for(unsigned int i=0;i<outtmp.size();++i) {
|
|
||||||
const unsigned char *d = (const unsigned char *)outtmp.data();
|
|
||||||
if (i > 0)
|
|
||||||
fprintf(stdout,",");
|
|
||||||
fprintf(stdout,"0x%.2x",(unsigned int)d[i]);
|
|
||||||
}
|
|
||||||
fprintf(stdout,"};"ZT_EOL_S);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,210 +0,0 @@
|
||||||
/*
|
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
|
||||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZT_SQLITENETWORKCONTROLLER_HPP
|
|
||||||
#define ZT_SQLITENETWORKCONTROLLER_HPP
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
#include <set>
|
|
||||||
#include <list>
|
|
||||||
|
|
||||||
#include "../node/Constants.hpp"
|
|
||||||
|
|
||||||
#include "../node/NetworkController.hpp"
|
|
||||||
#include "../node/Mutex.hpp"
|
|
||||||
#include "../node/Utils.hpp"
|
|
||||||
#include "../node/Address.hpp"
|
|
||||||
#include "../node/InetAddress.hpp"
|
|
||||||
|
|
||||||
#include "../osdep/OSUtils.hpp"
|
|
||||||
#include "../osdep/Thread.hpp"
|
|
||||||
#include "../osdep/BlockingQueue.hpp"
|
|
||||||
|
|
||||||
#include "../ext/json/json.hpp"
|
|
||||||
|
|
||||||
#include "JSONDB.hpp"
|
|
||||||
|
|
||||||
// Number of background threads to start -- not actually started until needed
|
|
||||||
#define ZT_EMBEDDEDNETWORKCONTROLLER_BACKGROUND_THREAD_COUNT 4
|
|
||||||
|
|
||||||
// TTL for circuit tests
|
|
||||||
#define ZT_EMBEDDEDNETWORKCONTROLLER_CIRCUIT_TEST_EXPIRATION 120000
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
|
||||||
|
|
||||||
class Node;
|
|
||||||
|
|
||||||
class EmbeddedNetworkController : public NetworkController
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* @param node Parent node
|
|
||||||
* @param dbPath Path to store data
|
|
||||||
*/
|
|
||||||
EmbeddedNetworkController(Node *node,const char *dbPath);
|
|
||||||
virtual ~EmbeddedNetworkController();
|
|
||||||
|
|
||||||
virtual void init(const Identity &signingId,Sender *sender);
|
|
||||||
|
|
||||||
virtual void request(
|
|
||||||
uint64_t nwid,
|
|
||||||
const InetAddress &fromAddr,
|
|
||||||
uint64_t requestPacketId,
|
|
||||||
const Identity &identity,
|
|
||||||
const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData);
|
|
||||||
|
|
||||||
unsigned int handleControlPlaneHttpGET(
|
|
||||||
const std::vector<std::string> &path,
|
|
||||||
const std::map<std::string,std::string> &urlArgs,
|
|
||||||
const std::map<std::string,std::string> &headers,
|
|
||||||
const std::string &body,
|
|
||||||
std::string &responseBody,
|
|
||||||
std::string &responseContentType);
|
|
||||||
unsigned int handleControlPlaneHttpPOST(
|
|
||||||
const std::vector<std::string> &path,
|
|
||||||
const std::map<std::string,std::string> &urlArgs,
|
|
||||||
const std::map<std::string,std::string> &headers,
|
|
||||||
const std::string &body,
|
|
||||||
std::string &responseBody,
|
|
||||||
std::string &responseContentType);
|
|
||||||
unsigned int handleControlPlaneHttpDELETE(
|
|
||||||
const std::vector<std::string> &path,
|
|
||||||
const std::map<std::string,std::string> &urlArgs,
|
|
||||||
const std::map<std::string,std::string> &headers,
|
|
||||||
const std::string &body,
|
|
||||||
std::string &responseBody,
|
|
||||||
std::string &responseContentType);
|
|
||||||
|
|
||||||
void threadMain()
|
|
||||||
throw();
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct _RQEntry
|
|
||||||
{
|
|
||||||
uint64_t nwid;
|
|
||||||
uint64_t requestPacketId;
|
|
||||||
InetAddress fromAddr;
|
|
||||||
Identity identity;
|
|
||||||
Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> metaData;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Gathers a bunch of statistics about members of a network, IP assignments, etc. that we need in various places
|
|
||||||
struct _NetworkMemberInfo
|
|
||||||
{
|
|
||||||
_NetworkMemberInfo() : authorizedMemberCount(0),activeMemberCount(0),totalMemberCount(0),mostRecentDeauthTime(0) {}
|
|
||||||
std::set<Address> activeBridges;
|
|
||||||
std::set<InetAddress> allocatedIps;
|
|
||||||
unsigned long authorizedMemberCount;
|
|
||||||
unsigned long activeMemberCount;
|
|
||||||
unsigned long totalMemberCount;
|
|
||||||
uint64_t mostRecentDeauthTime;
|
|
||||||
uint64_t nmiTimestamp; // time this NMI structure was computed
|
|
||||||
};
|
|
||||||
|
|
||||||
static void _circuitTestCallback(ZT_Node *node,ZT_CircuitTest *test,const ZT_CircuitTestReport *report);
|
|
||||||
void _request(uint64_t nwid,const InetAddress &fromAddr,uint64_t requestPacketId,const Identity &identity,const Dictionary<ZT_NETWORKCONFIG_METADATA_DICT_CAPACITY> &metaData);
|
|
||||||
void _getNetworkMemberInfo(uint64_t now,uint64_t nwid,_NetworkMemberInfo &nmi);
|
|
||||||
inline void _clearNetworkMemberInfoCache(const uint64_t nwid) { Mutex::Lock _l(_nmiCache_m); _nmiCache.erase(nwid); }
|
|
||||||
void _pushMemberUpdate(uint64_t now,uint64_t nwid,const nlohmann::json &member);
|
|
||||||
|
|
||||||
// These init objects with default and static/informational fields
|
|
||||||
inline void _initMember(nlohmann::json &member)
|
|
||||||
{
|
|
||||||
if (!member.count("authorized")) member["authorized"] = false;
|
|
||||||
if (!member.count("authHistory")) member["authHistory"] = nlohmann::json::array();
|
|
||||||
if (!member.count("ipAssignments")) member["ipAssignments"] = nlohmann::json::array();
|
|
||||||
if (!member.count("recentLog")) member["recentLog"] = nlohmann::json::array();
|
|
||||||
if (!member.count("activeBridge")) member["activeBridge"] = false;
|
|
||||||
if (!member.count("tags")) member["tags"] = nlohmann::json::array();
|
|
||||||
if (!member.count("capabilities")) member["capabilities"] = nlohmann::json::array();
|
|
||||||
if (!member.count("creationTime")) member["creationTime"] = OSUtils::now();
|
|
||||||
if (!member.count("noAutoAssignIps")) member["noAutoAssignIps"] = false;
|
|
||||||
if (!member.count("revision")) member["revision"] = 0ULL;
|
|
||||||
if (!member.count("lastDeauthorizedTime")) member["lastDeauthorizedTime"] = 0ULL;
|
|
||||||
if (!member.count("lastAuthorizedTime")) member["lastAuthorizedTime"] = 0ULL;
|
|
||||||
member["objtype"] = "member";
|
|
||||||
}
|
|
||||||
inline void _initNetwork(nlohmann::json &network)
|
|
||||||
{
|
|
||||||
if (!network.count("private")) network["private"] = true;
|
|
||||||
if (!network.count("creationTime")) network["creationTime"] = OSUtils::now();
|
|
||||||
if (!network.count("name")) network["name"] = "";
|
|
||||||
if (!network.count("multicastLimit")) network["multicastLimit"] = (uint64_t)32;
|
|
||||||
if (!network.count("enableBroadcast")) network["enableBroadcast"] = true;
|
|
||||||
if (!network.count("v4AssignMode")) network["v4AssignMode"] = {{"zt",false}};
|
|
||||||
if (!network.count("v6AssignMode")) network["v6AssignMode"] = {{"rfc4193",false},{"zt",false},{"6plane",false}};
|
|
||||||
if (!network.count("authTokens")) network["authTokens"] = nlohmann::json::array();
|
|
||||||
if (!network.count("capabilities")) network["capabilities"] = nlohmann::json::array();
|
|
||||||
if (!network.count("tags")) network["tags"] = nlohmann::json::array();
|
|
||||||
if (!network.count("routes")) network["routes"] = nlohmann::json::array();
|
|
||||||
if (!network.count("ipAssignmentPools")) network["ipAssignmentPools"] = nlohmann::json::array();
|
|
||||||
if (!network.count("rules")) {
|
|
||||||
// If unspecified, rules are set to allow anything and behave like a flat L2 segment
|
|
||||||
network["rules"] = {{
|
|
||||||
{ "not",false },
|
|
||||||
{ "or", false },
|
|
||||||
{ "type","ACTION_ACCEPT" }
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
network["objtype"] = "network";
|
|
||||||
}
|
|
||||||
inline void _addNetworkNonPersistedFields(nlohmann::json &network,uint64_t now,const _NetworkMemberInfo &nmi)
|
|
||||||
{
|
|
||||||
network["clock"] = now;
|
|
||||||
network["authorizedMemberCount"] = nmi.authorizedMemberCount;
|
|
||||||
network["activeMemberCount"] = nmi.activeMemberCount;
|
|
||||||
network["totalMemberCount"] = nmi.totalMemberCount;
|
|
||||||
}
|
|
||||||
inline void _addMemberNonPersistedFields(nlohmann::json &member,uint64_t now)
|
|
||||||
{
|
|
||||||
member["clock"] = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
const uint64_t _startTime;
|
|
||||||
|
|
||||||
BlockingQueue<_RQEntry *> _queue;
|
|
||||||
Thread _threads[ZT_EMBEDDEDNETWORKCONTROLLER_BACKGROUND_THREAD_COUNT];
|
|
||||||
bool _threadsStarted;
|
|
||||||
Mutex _threads_m;
|
|
||||||
|
|
||||||
std::map<uint64_t,_NetworkMemberInfo> _nmiCache;
|
|
||||||
Mutex _nmiCache_m;
|
|
||||||
|
|
||||||
JSONDB _db;
|
|
||||||
Mutex _db_m;
|
|
||||||
|
|
||||||
Node *const _node;
|
|
||||||
std::string _path;
|
|
||||||
|
|
||||||
NetworkController::Sender *_sender;
|
|
||||||
Identity _signingId;
|
|
||||||
|
|
||||||
std::list< ZT_CircuitTest > _tests;
|
|
||||||
Mutex _tests_m;
|
|
||||||
|
|
||||||
std::map< std::pair<uint64_t,uint64_t>,uint64_t > _lastRequestTime; // last request time by <address,networkId>
|
|
||||||
Mutex _lastRequestTime_m;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ZeroTier
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,219 +0,0 @@
|
||||||
/*
|
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
|
||||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "JSONDB.hpp"
|
|
||||||
|
|
||||||
#define ZT_JSONDB_HTTP_TIMEOUT 60000
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
|
||||||
|
|
||||||
static const nlohmann::json _EMPTY_JSON(nlohmann::json::object());
|
|
||||||
static const std::map<std::string,std::string> _ZT_JSONDB_GET_HEADERS;
|
|
||||||
|
|
||||||
JSONDB::JSONDB(const std::string &basePath) :
|
|
||||||
_basePath(basePath),
|
|
||||||
_ready(false)
|
|
||||||
{
|
|
||||||
if ((_basePath.length() > 7)&&(_basePath.substr(0,7) == "http://")) {
|
|
||||||
// TODO: this doesn't yet support IPv6 since bracketed address notiation isn't supported.
|
|
||||||
// Typically it's used with 127.0.0.1 anyway.
|
|
||||||
std::string hn = _basePath.substr(7);
|
|
||||||
std::size_t hnend = hn.find_first_of('/');
|
|
||||||
if (hnend != std::string::npos)
|
|
||||||
hn = hn.substr(0,hnend);
|
|
||||||
std::size_t hnsep = hn.find_last_of(':');
|
|
||||||
if (hnsep != std::string::npos)
|
|
||||||
hn[hnsep] = '/';
|
|
||||||
_httpAddr.fromString(hn);
|
|
||||||
if (hnend != std::string::npos)
|
|
||||||
_basePath = _basePath.substr(7 + hnend);
|
|
||||||
if (_basePath.length() == 0)
|
|
||||||
_basePath = "/";
|
|
||||||
if (_basePath[0] != '/')
|
|
||||||
_basePath = std::string("/") + _basePath;
|
|
||||||
} else {
|
|
||||||
OSUtils::mkdir(_basePath.c_str());
|
|
||||||
OSUtils::lockDownFile(_basePath.c_str(),true); // networks might contain auth tokens, etc., so restrict directory permissions
|
|
||||||
}
|
|
||||||
_ready = _reload(_basePath,std::string());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool JSONDB::writeRaw(const std::string &n,const std::string &obj)
|
|
||||||
{
|
|
||||||
if (!_isValidObjectName(n))
|
|
||||||
return false;
|
|
||||||
if (_httpAddr) {
|
|
||||||
std::map<std::string,std::string> headers;
|
|
||||||
std::string body;
|
|
||||||
std::map<std::string,std::string> reqHeaders;
|
|
||||||
char tmp[64];
|
|
||||||
Utils::snprintf(tmp,sizeof(tmp),"%lu",(unsigned long)obj.length());
|
|
||||||
reqHeaders["Content-Length"] = tmp;
|
|
||||||
reqHeaders["Content-Type"] = "application/json";
|
|
||||||
const unsigned int sc = Http::PUT(1048576,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast<const struct sockaddr *>(&_httpAddr),(_basePath+"/"+n).c_str(),reqHeaders,obj.data(),(unsigned long)obj.length(),headers,body);
|
|
||||||
return (sc == 200);
|
|
||||||
} else {
|
|
||||||
const std::string path(_genPath(n,true));
|
|
||||||
if (!path.length())
|
|
||||||
return false;
|
|
||||||
return OSUtils::writeFile(path.c_str(),obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool JSONDB::put(const std::string &n,const nlohmann::json &obj)
|
|
||||||
{
|
|
||||||
const bool r = writeRaw(n,OSUtils::jsonDump(obj));
|
|
||||||
_db[n].obj = obj;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
const nlohmann::json &JSONDB::get(const std::string &n)
|
|
||||||
{
|
|
||||||
while (!_ready) {
|
|
||||||
Thread::sleep(250);
|
|
||||||
_ready = _reload(_basePath,std::string());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_isValidObjectName(n))
|
|
||||||
return _EMPTY_JSON;
|
|
||||||
std::map<std::string,_E>::iterator e(_db.find(n));
|
|
||||||
if (e != _db.end())
|
|
||||||
return e->second.obj;
|
|
||||||
|
|
||||||
std::string buf;
|
|
||||||
if (_httpAddr) {
|
|
||||||
std::map<std::string,std::string> headers;
|
|
||||||
const unsigned int sc = Http::GET(1048576,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast<const struct sockaddr *>(&_httpAddr),(_basePath+"/"+n).c_str(),_ZT_JSONDB_GET_HEADERS,headers,buf);
|
|
||||||
if (sc != 200)
|
|
||||||
return _EMPTY_JSON;
|
|
||||||
} else {
|
|
||||||
const std::string path(_genPath(n,false));
|
|
||||||
if (!path.length())
|
|
||||||
return _EMPTY_JSON;
|
|
||||||
if (!OSUtils::readFile(path.c_str(),buf))
|
|
||||||
return _EMPTY_JSON;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
_E &e2 = _db[n];
|
|
||||||
e2.obj = OSUtils::jsonParse(buf);
|
|
||||||
return e2.obj;
|
|
||||||
} catch ( ... ) {
|
|
||||||
_db.erase(n);
|
|
||||||
return _EMPTY_JSON;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void JSONDB::erase(const std::string &n)
|
|
||||||
{
|
|
||||||
if (!_isValidObjectName(n))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_httpAddr) {
|
|
||||||
std::string body;
|
|
||||||
std::map<std::string,std::string> headers;
|
|
||||||
Http::DEL(1048576,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast<const struct sockaddr *>(&_httpAddr),(_basePath+"/"+n).c_str(),_ZT_JSONDB_GET_HEADERS,headers,body);
|
|
||||||
} else {
|
|
||||||
std::string path(_genPath(n,true));
|
|
||||||
if (!path.length())
|
|
||||||
return;
|
|
||||||
OSUtils::rm(path.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
_db.erase(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool JSONDB::_reload(const std::string &p,const std::string &b)
|
|
||||||
{
|
|
||||||
if (_httpAddr) {
|
|
||||||
std::string body;
|
|
||||||
std::map<std::string,std::string> headers;
|
|
||||||
const unsigned int sc = Http::GET(2147483647,ZT_JSONDB_HTTP_TIMEOUT,reinterpret_cast<const struct sockaddr *>(&_httpAddr),_basePath.c_str(),_ZT_JSONDB_GET_HEADERS,headers,body);
|
|
||||||
if (sc == 200) {
|
|
||||||
try {
|
|
||||||
nlohmann::json dbImg(OSUtils::jsonParse(body));
|
|
||||||
std::string tmp;
|
|
||||||
if (dbImg.is_object()) {
|
|
||||||
for(nlohmann::json::iterator i(dbImg.begin());i!=dbImg.end();++i) {
|
|
||||||
if (i.value().is_object()) {
|
|
||||||
tmp = i.key();
|
|
||||||
_db[tmp].obj = i.value();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch ( ... ) {} // invalid JSON, so maybe incomplete request
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
std::vector<std::string> dl(OSUtils::listDirectory(p.c_str(),true));
|
|
||||||
for(std::vector<std::string>::const_iterator di(dl.begin());di!=dl.end();++di) {
|
|
||||||
if ((di->length() > 5)&&(di->substr(di->length() - 5) == ".json")) {
|
|
||||||
this->get(b + di->substr(0,di->length() - 5));
|
|
||||||
} else {
|
|
||||||
this->_reload((p + ZT_PATH_SEPARATOR + *di),(b + *di + ZT_PATH_SEPARATOR));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool JSONDB::_isValidObjectName(const std::string &n)
|
|
||||||
{
|
|
||||||
if (n.length() == 0)
|
|
||||||
return false;
|
|
||||||
const char *p = n.c_str();
|
|
||||||
char c;
|
|
||||||
// For security reasons we should not allow dots, backslashes, or other path characters or potential path characters.
|
|
||||||
while ((c = *(p++))) {
|
|
||||||
if (!( ((c >= 'a')&&(c <= 'z')) || ((c >= 'A')&&(c <= 'Z')) || ((c >= '0')&&(c <= '9')) || (c == '/') || (c == '_') || (c == '~') || (c == '-') ))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string JSONDB::_genPath(const std::string &n,bool create)
|
|
||||||
{
|
|
||||||
std::vector<std::string> pt(OSUtils::split(n.c_str(),"/","",""));
|
|
||||||
if (pt.size() == 0)
|
|
||||||
return std::string();
|
|
||||||
|
|
||||||
char sep;
|
|
||||||
if (_httpAddr) {
|
|
||||||
sep = '/';
|
|
||||||
create = false;
|
|
||||||
} else {
|
|
||||||
sep = ZT_PATH_SEPARATOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string p(_basePath);
|
|
||||||
if (create) OSUtils::mkdir(p.c_str());
|
|
||||||
for(unsigned long i=0,j=(unsigned long)(pt.size()-1);i<j;++i) {
|
|
||||||
p.push_back(sep);
|
|
||||||
p.append(pt[i]);
|
|
||||||
if (create) OSUtils::mkdir(p.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
p.push_back(sep);
|
|
||||||
p.append(pt[pt.size()-1]);
|
|
||||||
p.append(".json");
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ZeroTier
|
|
|
@ -1,116 +0,0 @@
|
||||||
/*
|
|
||||||
* ZeroTier One - Network Virtualization Everywhere
|
|
||||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZT_JSONDB_HPP
|
|
||||||
#define ZT_JSONDB_HPP
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "../node/Constants.hpp"
|
|
||||||
#include "../node/Utils.hpp"
|
|
||||||
#include "../node/InetAddress.hpp"
|
|
||||||
#include "../node/Mutex.hpp"
|
|
||||||
#include "../ext/json/json.hpp"
|
|
||||||
#include "../osdep/OSUtils.hpp"
|
|
||||||
#include "../osdep/Http.hpp"
|
|
||||||
#include "../osdep/Thread.hpp"
|
|
||||||
|
|
||||||
namespace ZeroTier {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hierarchical JSON store that persists into the filesystem or via HTTP
|
|
||||||
*/
|
|
||||||
class JSONDB
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
JSONDB(const std::string &basePath);
|
|
||||||
|
|
||||||
bool writeRaw(const std::string &n,const std::string &obj);
|
|
||||||
|
|
||||||
bool put(const std::string &n,const nlohmann::json &obj);
|
|
||||||
|
|
||||||
inline bool put(const std::string &n1,const std::string &n2,const nlohmann::json &obj) { return this->put((n1 + "/" + n2),obj); }
|
|
||||||
inline bool put(const std::string &n1,const std::string &n2,const std::string &n3,const nlohmann::json &obj) { return this->put((n1 + "/" + n2 + "/" + n3),obj); }
|
|
||||||
inline bool put(const std::string &n1,const std::string &n2,const std::string &n3,const std::string &n4,const nlohmann::json &obj) { return this->put((n1 + "/" + n2 + "/" + n3 + "/" + n4),obj); }
|
|
||||||
inline bool put(const std::string &n1,const std::string &n2,const std::string &n3,const std::string &n4,const std::string &n5,const nlohmann::json &obj) { return this->put((n1 + "/" + n2 + "/" + n3 + "/" + n4 + "/" + n5),obj); }
|
|
||||||
|
|
||||||
const nlohmann::json &get(const std::string &n);
|
|
||||||
|
|
||||||
inline const nlohmann::json &get(const std::string &n1,const std::string &n2) { return this->get((n1 + "/" + n2)); }
|
|
||||||
inline const nlohmann::json &get(const std::string &n1,const std::string &n2,const std::string &n3) { return this->get((n1 + "/" + n2 + "/" + n3)); }
|
|
||||||
inline const nlohmann::json &get(const std::string &n1,const std::string &n2,const std::string &n3,const std::string &n4) { return this->get((n1 + "/" + n2 + "/" + n3 + "/" + n4)); }
|
|
||||||
inline const nlohmann::json &get(const std::string &n1,const std::string &n2,const std::string &n3,const std::string &n4,const std::string &n5) { return this->get((n1 + "/" + n2 + "/" + n3 + "/" + n4 + "/" + n5)); }
|
|
||||||
|
|
||||||
void erase(const std::string &n);
|
|
||||||
|
|
||||||
inline void erase(const std::string &n1,const std::string &n2) { this->erase(n1 + "/" + n2); }
|
|
||||||
inline void erase(const std::string &n1,const std::string &n2,const std::string &n3) { this->erase(n1 + "/" + n2 + "/" + n3); }
|
|
||||||
inline void erase(const std::string &n1,const std::string &n2,const std::string &n3,const std::string &n4) { this->erase(n1 + "/" + n2 + "/" + n3 + "/" + n4); }
|
|
||||||
inline void erase(const std::string &n1,const std::string &n2,const std::string &n3,const std::string &n4,const std::string &n5) { this->erase(n1 + "/" + n2 + "/" + n3 + "/" + n4 + "/" + n5); }
|
|
||||||
|
|
||||||
template<typename F>
|
|
||||||
inline void filter(const std::string &prefix,F func)
|
|
||||||
{
|
|
||||||
while (!_ready) {
|
|
||||||
Thread::sleep(250);
|
|
||||||
_ready = _reload(_basePath,std::string());
|
|
||||||
}
|
|
||||||
|
|
||||||
for(std::map<std::string,_E>::iterator i(_db.lower_bound(prefix));i!=_db.end();) {
|
|
||||||
if ((i->first.length() >= prefix.length())&&(!memcmp(i->first.data(),prefix.data(),prefix.length()))) {
|
|
||||||
if (!func(i->first,get(i->first))) {
|
|
||||||
std::map<std::string,_E>::iterator i2(i); ++i2;
|
|
||||||
this->erase(i->first);
|
|
||||||
i = i2;
|
|
||||||
} else ++i;
|
|
||||||
} else break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator==(const JSONDB &db) const { return ((_basePath == db._basePath)&&(_db == db._db)); }
|
|
||||||
inline bool operator!=(const JSONDB &db) const { return (!(*this == db)); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool _reload(const std::string &p,const std::string &b);
|
|
||||||
bool _isValidObjectName(const std::string &n);
|
|
||||||
std::string _genPath(const std::string &n,bool create);
|
|
||||||
|
|
||||||
struct _E
|
|
||||||
{
|
|
||||||
nlohmann::json obj;
|
|
||||||
inline bool operator==(const _E &e) const { return (obj == e.obj); }
|
|
||||||
inline bool operator!=(const _E &e) const { return (obj != e.obj); }
|
|
||||||
};
|
|
||||||
|
|
||||||
InetAddress _httpAddr;
|
|
||||||
std::string _basePath;
|
|
||||||
std::map<std::string,_E> _db;
|
|
||||||
volatile bool _ready;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace ZeroTier
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,248 +0,0 @@
|
||||||
Network Controller Microservice
|
|
||||||
======
|
|
||||||
|
|
||||||
Every ZeroTier virtual network has a *network controller*. This is our reference implementation and is the same one we use to power our own hosted services at [my.zerotier.com](https://my.zerotier.com/). Network controllers act as configuration servers and certificate authorities for the members of networks. Controllers are located on the network by simply parsing out the first 10 digits of a network's 16-digit network ID: these are the address of the controller.
|
|
||||||
|
|
||||||
As of ZeroTier One version 1.2.0 this code is included in normal builds for desktop, laptop, and server (Linux, etc.) targets, allowing any device to create virtual networks without having to be rebuilt from source with special flags to enable this feature. While this does offer a convenient way to create ad-hoc networks or experiment, we recommend running a dedicated controller somewhere secure and stable for any "serious" use case.
|
|
||||||
|
|
||||||
Controller data is stored in JSON format under `controller.d` in the ZeroTier working directory. It can be copied, rsync'd, placed in `git`, etc. The files under `controller.d` should not be modified in place while the controller is running or data loss may result, and if they are edited directly take care not to save corrupt JSON since that can also lead to data loss when the controller is restarted. Going through the API is strongly preferred to directly modifying these files.
|
|
||||||
|
|
||||||
### Upgrading from Older (1.1.14 or earlier) Versions
|
|
||||||
|
|
||||||
Older versions of this code used a SQLite database instead of in-filesystem JSON. A migration utility called `migrate-sqlite` is included here and *must* be used to migrate this data to the new format. If the controller is started with an old `controller.db` in its working directory it will terminate after printing an error to *stderr*. This is done to prevent "surprises" for those running DIY controllers using the old code.
|
|
||||||
|
|
||||||
The migration tool is written in nodeJS and can be used like this:
|
|
||||||
|
|
||||||
cd migrate-sqlite
|
|
||||||
npm install
|
|
||||||
node migrate.js </path/to/controller.db> </path/to/controller.d>
|
|
||||||
|
|
||||||
Very old versions of nodeJS may have issues. We tested it with version 7.
|
|
||||||
|
|
||||||
### Scalability and Reliability
|
|
||||||
|
|
||||||
Controllers can in theory host up to 2^24 networks and serve many millions of devices (or more), but we recommend spreading large numbers of networks across many controllers for load balancing and fault tolerance reasons. Since the controller uses the filesystem as its data store we recommend fast filesystems and fast SSD drives for heavily loaded controllers.
|
|
||||||
|
|
||||||
Since ZeroTier nodes are mobile and do not need static IPs, implementing high availability fail-over for controllers is easy. Just replicate their working directories from master to backup and have something automatically fire up the backup if the master goes down. Many modern orchestration tools have built-in support for this. It would also be possible in theory to run controllers on a replicated or distributed filesystem, but we haven't tested this yet.
|
|
||||||
|
|
||||||
### Dockerizing Controllers
|
|
||||||
|
|
||||||
ZeroTier network controllers can easily be run in Docker or other container systems. Since containers do not need to actually join networks, extra privilege options like "--device=/dev/net/tun --privileged" are not needed. You'll just need to map the local JSON API port of the running controller and allow it to access the Internet (over UDP/9993 at a minimum) so things can reach and query it.
|
|
||||||
|
|
||||||
### Network Controller API
|
|
||||||
|
|
||||||
The controller API is hosted via the same JSON API endpoint that ZeroTier One uses for local control (usually at 127.0.0.1 port 9993). All controller options are routed under the `/controller` base path.
|
|
||||||
|
|
||||||
The controller microservice does not implement any fine-grained access control (authentication is via authtoken.secret just like the regular JSON API) or other complex mangement features. It just takes network and network member configurations and reponds to controller queries. We have an enterprise product called [ZeroTier Central](https://my.zerotier.com/) that we host as a service (and that companies can license to self-host) that does this.
|
|
||||||
|
|
||||||
All working network IDs on a controller must begin with the controller's ZeroTier address. The API will *allow* "foreign" networks to be added but the controller will have no way of doing anything with them since nobody will know to query it. (In the future we might support secondaries, which would make this relevant.)
|
|
||||||
|
|
||||||
The JSON API is *very* sensitive about types. Integers must be integers and strings strings, etc. Incorrectly typed and unrecognized fields may result in ignored fields or a 400 (bad request) error.
|
|
||||||
|
|
||||||
#### `/controller`
|
|
||||||
|
|
||||||
* Purpose: Check for controller function and return controller status
|
|
||||||
* Methods: GET
|
|
||||||
* Returns: { object }
|
|
||||||
|
|
||||||
| Field | Type | Description | Writable |
|
|
||||||
| ------------------ | ----------- | ------------------------------------------------- | -------- |
|
|
||||||
| controller | boolean | Always 'true' | no |
|
|
||||||
| apiVersion | integer | Controller API version, currently 3 | no |
|
|
||||||
| clock | integer | Current clock on controller, ms since epoch | no |
|
|
||||||
|
|
||||||
#### `/controller/network`
|
|
||||||
|
|
||||||
* Purpose: List all networks hosted by this controller
|
|
||||||
* Methods: GET
|
|
||||||
* Returns: [ string, ... ]
|
|
||||||
|
|
||||||
This returns an array of 16-digit hexadecimal network IDs.
|
|
||||||
|
|
||||||
#### `/controller/network/<network ID>`
|
|
||||||
|
|
||||||
* Purpose: Create, configure, and delete hosted networks
|
|
||||||
* Methods: GET, POST, DELETE
|
|
||||||
* Returns: { object }
|
|
||||||
|
|
||||||
By making queries to this path you can create, configure, and delete networks. DELETE is final, so don't do it unless you really mean it.
|
|
||||||
|
|
||||||
When POSTing new networks take care that their IDs are not in use, otherwise you may overwrite an existing one. To create a new network with a random unused ID, POST to `/controller/network/##########______`. The #'s are the controller's 10-digit ZeroTier address and they're followed by six underscores. Check the `nwid` field of the returned JSON object for your network's newly allocated ID. Subsequent POSTs to this network must refer to its actual path.
|
|
||||||
|
|
||||||
| Field | Type | Description | Writable |
|
|
||||||
| --------------------- | ------------- | ------------------------------------------------- | -------- |
|
|
||||||
| id | string | 16-digit network ID | no |
|
|
||||||
| nwid | string | 16-digit network ID (old, but still around) | no |
|
|
||||||
| clock | integer | Current clock, ms since epoch | no |
|
|
||||||
| name | string | A short name for this network | YES |
|
|
||||||
| private | boolean | Is access control enabled? | YES |
|
|
||||||
| enableBroadcast | boolean | Ethernet ff:ff:ff:ff:ff:ff allowed? | YES |
|
|
||||||
| allowPassiveBridging | boolean | Allow any member to bridge (very experimental) | YES |
|
|
||||||
| v4AssignMode | object | IPv4 management and assign options (see below) | YES |
|
|
||||||
| v6AssignMode | object | IPv6 management and assign options (see below) | YES |
|
|
||||||
| multicastLimit | integer | Maximum recipients for a multicast packet | YES |
|
|
||||||
| creationTime | integer | Time network was first created | no |
|
|
||||||
| revision | integer | Network config revision counter | no |
|
|
||||||
| authorizedMemberCount | integer | Number of authorized members (for private nets) | no |
|
|
||||||
| activeMemberCount | integer | Number of members that appear to be online | no |
|
|
||||||
| totalMemberCount | integer | Total known members of this network | no |
|
|
||||||
| routes | array[object] | Managed IPv4 and IPv6 routes; see below | YES |
|
|
||||||
| ipAssignmentPools | array[object] | IP auto-assign ranges; see below | YES |
|
|
||||||
| rules | array[object] | Traffic rules; see below | YES |
|
|
||||||
|
|
||||||
Recent changes:
|
|
||||||
|
|
||||||
* The `ipLocalRoutes` field appeared in older versions but is no longer present. Routes will now show up in `routes`.
|
|
||||||
* The `relays` field is gone since network preferred relays are gone. This capability is replaced by VL1 level federation ("federated roots").
|
|
||||||
|
|
||||||
Other important points:
|
|
||||||
|
|
||||||
* Networks without rules won't carry any traffic. If you don't specify any on network creation an "accept anything" rule set will automatically be added.
|
|
||||||
* Managed IP address assignments and IP assignment pools that do not fall within a route configured in `routes` are ignored and won't be used or sent to members.
|
|
||||||
* The default for `private` is `true` and this is probably what you want. Turning `private` off means *anyone* can join your network with only its 16-digit network ID. It's also impossible to de-authorize a member as these networks don't issue or enforce certificates. Such "party line" networks are used for decentralized app backplanes, gaming, and testing but are otherwise not common.
|
|
||||||
|
|
||||||
**Auto-Assign Modes:**
|
|
||||||
|
|
||||||
Auto assign modes (`v4AssignMode` and `v6AssignMode`) contain objects that map assignment modes to booleans.
|
|
||||||
|
|
||||||
For IPv4 the only valid setting is `zt` which, if true, causes IPv4 addresses to be auto-assigned from `ipAssignmentPools` to members that do not have an IPv4 assignment. Note that active bridges are exempt and will not get auto-assigned IPs since this can interfere with bridging. (You can still manually assign one if you want.)
|
|
||||||
|
|
||||||
IPv6 includes this option and two others: `6plane` and `rfc4193`. These assign private IPv6 addresses to each member based on a deterministic assignment scheme that allows members to emulate IPv6 NDP to skip multicast for better performance and scalability. The `rfc4193` mode gives every member a /128 on a /88 network, while `6plane` gives every member a /80 within a /40 network but uses NDP emulation to route *all* IPs under that /80 to its owner. The `6plane` mode is great for use cases like Docker since it allows every member to assign IPv6 addresses within its /80 that just work instantly and globally across the network.
|
|
||||||
|
|
||||||
**IP assignment pool object format:**
|
|
||||||
|
|
||||||
| Field | Type | Description |
|
|
||||||
| --------------------- | ------------- | ------------------------------------------------- |
|
|
||||||
| ipRangeStart | string | Starting IP address in range |
|
|
||||||
| ipRangeEnd | string | Ending IP address in range (inclusive) |
|
|
||||||
|
|
||||||
Pools are only used if auto-assignment is on for the given address type (IPv4 or IPv6) and if the entire range falls within a managed route.
|
|
||||||
|
|
||||||
IPv6 ranges work just like IPv4 ranges and look like this:
|
|
||||||
|
|
||||||
{
|
|
||||||
"ipRangeStart": "fd00:feed:feed:beef:0000:0000:0000:0000",
|
|
||||||
"ipRangeEnd": "fd00:feed:feed:beef:ffff:ffff:ffff:ffff"
|
|
||||||
}
|
|
||||||
|
|
||||||
(You can POST a shortened-form IPv6 address but the API will always report back un-shortened canonical form addresses.)
|
|
||||||
|
|
||||||
That defines a range within network `fd00:feed:feed:beef::/64` that contains up to 2^64 addresses. If an IPv6 range is large enough, the controller will assign addresses by placing each member's device ID into the address in a manner similar to the RFC4193 and 6PLANE modes. Otherwise it will assign addresses at random.
|
|
||||||
|
|
||||||
**Rule object format:**
|
|
||||||
|
|
||||||
Each rule is actually a sequence of zero or more `MATCH_` entries in the rule array followed by an `ACTION_` entry that describes what to do if all the preceding entries match. An `ACTION_` without any preceding `MATCH_` entries is always taken, so setting a single `ACTION_ACCEPT` rule yields a network that allows all traffic. If no rules are present the default action is `ACTION_DROP`.
|
|
||||||
|
|
||||||
Rules are evaluated in the order in which they appear in the array. There is currently a limit of 256 entries per network. Capabilities should be used if a larger and more complex rule set is needed since they allow rules to be grouped by purpose and only shipped to members that need them.
|
|
||||||
|
|
||||||
Each rule table entry has two common fields.
|
|
||||||
|
|
||||||
| Field | Type | Description |
|
|
||||||
| --------------------- | ------------- | ------------------------------------------------- |
|
|
||||||
| type | string | Entry type (all caps, case sensitive) |
|
|
||||||
| not | boolean | If true, MATCHes match if they don't match |
|
|
||||||
|
|
||||||
The following fields may or may not be present depending on rule type:
|
|
||||||
|
|
||||||
| Field | Type | Description |
|
|
||||||
| --------------------- | ------------- | ------------------------------------------------- |
|
|
||||||
| zt | string | 10-digit hex ZeroTier address |
|
|
||||||
| etherType | integer | Ethernet frame type |
|
|
||||||
| mac | string | Hex MAC address (with or without :'s) |
|
|
||||||
| ip | string | IPv4 or IPv6 address |
|
|
||||||
| ipTos | integer | IP type of service |
|
|
||||||
| ipProtocol | integer | IP protocol (e.g. TCP) |
|
|
||||||
| start | integer | Start of an integer range (e.g. port range) |
|
|
||||||
| end | integer | End of an integer range (inclusive) |
|
|
||||||
| id | integer | Tag ID |
|
|
||||||
| value | integer | Tag value or comparison value |
|
|
||||||
| mask | integer | Bit mask (for characteristics flags) |
|
|
||||||
|
|
||||||
The entry types and their additional fields are:
|
|
||||||
|
|
||||||
| Entry type | Description | Fields |
|
|
||||||
| ------------------------------- | ----------------------------------------------------------------- | -------------- |
|
|
||||||
| `ACTION_DROP` | Drop any packets matching this rule | (none) |
|
|
||||||
| `ACTION_ACCEPT` | Accept any packets matching this rule | (none) |
|
|
||||||
| `ACTION_TEE` | Send a copy of this packet to a node (rule parsing continues) | `zt` |
|
|
||||||
| `ACTION_REDIRECT` | Redirect this packet to another node | `zt` |
|
|
||||||
| `ACTION_DEBUG_LOG` | Output debug info on match (if built with rules engine debug) | (none) |
|
|
||||||
| `MATCH_SOURCE_ZEROTIER_ADDRESS` | Match VL1 ZeroTier address of packet sender. | `zt` |
|
|
||||||
| `MATCH_DEST_ZEROTIER_ADDRESS` | Match VL1 ZeroTier address of recipient | `zt` |
|
|
||||||
| `MATCH_ETHERTYPE` | Match Ethernet frame type | `etherType` |
|
|
||||||
| `MATCH_MAC_SOURCE` | Match source Ethernet MAC address | `mac` |
|
|
||||||
| `MATCH_MAC_DEST` | Match destination Ethernet MAC address | `mac` |
|
|
||||||
| `MATCH_IPV4_SOURCE` | Match source IPv4 address | `ip` |
|
|
||||||
| `MATCH_IPV4_DEST` | Match destination IPv4 address | `ip` |
|
|
||||||
| `MATCH_IPV6_SOURCE` | Match source IPv6 address | `ip` |
|
|
||||||
| `MATCH_IPV6_DEST` | Match destination IPv6 address | `ip` |
|
|
||||||
| `MATCH_IP_TOS` | Match IP TOS field | `ipTos` |
|
|
||||||
| `MATCH_IP_PROTOCOL` | Match IP protocol field | `ipProtocol` |
|
|
||||||
| `MATCH_IP_SOURCE_PORT_RANGE` | Match a source IP port range | `start`,`end` |
|
|
||||||
| `MATCH_IP_DEST_PORT_RANGE` | Match a destination IP port range | `start`,`end` |
|
|
||||||
| `MATCH_CHARACTERISTICS` | Match on characteristics flags | `mask`,`value` |
|
|
||||||
| `MATCH_FRAME_SIZE_RANGE` | Match a range of Ethernet frame sizes | `start`,`end` |
|
|
||||||
| `MATCH_TAGS_SAMENESS` | Match if both sides' tags differ by no more than value | `id`,`value` |
|
|
||||||
| `MATCH_TAGS_BITWISE_AND` | Match if both sides' tags AND to value | `id`,`value` |
|
|
||||||
| `MATCH_TAGS_BITWISE_OR` | Match if both sides' tags OR to value | `id`,`value` |
|
|
||||||
| `MATCH_TAGS_BITWISE_XOR` | Match if both sides` tags XOR to value | `id`,`value` |
|
|
||||||
|
|
||||||
Important notes about rules engine behavior:
|
|
||||||
|
|
||||||
* IPv4 and IPv6 IP address rules do not match for frames that are not IPv4 or IPv6 respectively.
|
|
||||||
* `ACTION_DEBUG_LOG` is a no-op on nodes not built with `ZT_RULES_ENGINE_DEBUGGING` enabled (see Network.cpp). If that is enabled nodes will dump a trace of rule evaluation results to *stdout* when this action is encountered but will otherwise keep evaluating rules. This is used for basic "smoke testing" of the rules engine.
|
|
||||||
* Multicast packets and packets destined for bridged devices treated a little differently. They are matched more than once. They are matched at the point of send with a NULL ZeroTier destination address, meaning that `MATCH_DEST_ZEROTIER_ADDRESS` is useless. That's because the true VL1 destination is not yet known. Then they are matched again for each true VL1 destination. On these later subsequent matches TEE actions are ignored and REDIRECT rules are interpreted as DROPs. This prevents multiple TEE or REDIRECT packets from being sent to third party devices.
|
|
||||||
* Rules in capabilities are always matched as if the current device is the sender (inbound == false). A capability specifies sender side rules that can be enforced on both sides.
|
|
||||||
|
|
||||||
#### `/controller/network/<network ID>/member`
|
|
||||||
|
|
||||||
* Purpose: Get a set of all members on this network
|
|
||||||
* Methods: GET
|
|
||||||
* Returns: { object }
|
|
||||||
|
|
||||||
This returns a JSON object containing all member IDs as keys and their `memberRevisionCounter` values as values.
|
|
||||||
|
|
||||||
#### `/controller/network/<network ID>/active`
|
|
||||||
|
|
||||||
* Purpose: Get a set of all active members on this network
|
|
||||||
* Methods: GET
|
|
||||||
* Returns: { object }
|
|
||||||
|
|
||||||
This returns an object containing all currently online members and the most recent `recentLog` entries for their last request.
|
|
||||||
|
|
||||||
#### `/controller/network/<network ID>/member/<address>`
|
|
||||||
|
|
||||||
* Purpose: Create, authorize, or remove a network member
|
|
||||||
* Methods: GET, POST, DELETE
|
|
||||||
* Returns: { object }
|
|
||||||
|
|
||||||
| Field | Type | Description | Writable |
|
|
||||||
| --------------------- | ------------- | ------------------------------------------------- | -------- |
|
|
||||||
| id | string | Member's 10-digit ZeroTier address | no |
|
|
||||||
| address | string | Member's 10-digit ZeroTier address | no |
|
|
||||||
| nwid | string | 16-digit network ID | no |
|
|
||||||
| clock | integer | Current clock, ms since epoch | no |
|
|
||||||
| authorized | boolean | Is member authorized? (for private networks) | YES |
|
|
||||||
| authHistory | array[object] | History of auth changes, latest at end | no |
|
|
||||||
| activeBridge | boolean | Member is able to bridge to other Ethernet nets | YES |
|
|
||||||
| identity | string | Member's public ZeroTier identity (if known) | no |
|
|
||||||
| ipAssignments | array[string] | Managed IP address assignments | YES |
|
|
||||||
| memberRevision | integer | Member revision counter | no |
|
|
||||||
| recentLog | array[object] | Recent member activity log; see below | no |
|
|
||||||
|
|
||||||
Note that managed IP assignments are only used if they fall within a managed route. Otherwise they are ignored.
|
|
||||||
|
|
||||||
**Recent log object format:**
|
|
||||||
|
|
||||||
| Field | Type | Description |
|
|
||||||
| --------------------- | ------------- | ------------------------------------------------- |
|
|
||||||
| ts | integer | Time of request, ms since epoch |
|
|
||||||
| auth | boolean | Was member authorized? |
|
|
||||||
| authBy | string | How was member authorized? |
|
|
||||||
| vMajor | integer | Client major version or -1 if unknown |
|
|
||||||
| vMinor | integer | Client minor version or -1 if unknown |
|
|
||||||
| vRev | integer | Client revision or -1 if unknown |
|
|
||||||
| vProto | integer | ZeroTier protocol version reported by client |
|
|
||||||
| fromAddr | string | Physical address if known |
|
|
||||||
|
|
||||||
The controller can only know a member's `fromAddr` if it's able to establish a direct path to it. Members behind very restrictive firewalls may not have this information since the controller will be receiving the member's requests by way of a relay. ZeroTier does not back-trace IP paths as packets are relayed since this would add a lot of protocol overhead.
|
|
|
@ -1,320 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var sqlite3 = require('sqlite3').verbose();
|
|
||||||
var fs = require('fs');
|
|
||||||
var async = require('async');
|
|
||||||
|
|
||||||
function blobToIPv4(b)
|
|
||||||
{
|
|
||||||
if (!b)
|
|
||||||
return null;
|
|
||||||
if (b.length !== 16)
|
|
||||||
return null;
|
|
||||||
return b.readUInt8(12).toString()+'.'+b.readUInt8(13).toString()+'.'+b.readUInt8(14).toString()+'.'+b.readUInt8(15).toString();
|
|
||||||
}
|
|
||||||
function blobToIPv6(b)
|
|
||||||
{
|
|
||||||
if (!b)
|
|
||||||
return null;
|
|
||||||
if (b.length !== 16)
|
|
||||||
return null;
|
|
||||||
var s = '';
|
|
||||||
for(var i=0;i<16;++i) {
|
|
||||||
var x = b.readUInt8(i).toString(16);
|
|
||||||
if (x.length === 1)
|
|
||||||
s += '0';
|
|
||||||
s += x;
|
|
||||||
if ((((i+1) & 1) === 0)&&(i !== 15))
|
|
||||||
s += ':';
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.argv.length !== 4) {
|
|
||||||
console.log('ZeroTier Old Sqlite3 Controller DB Migration Utility');
|
|
||||||
console.log('(c)2017 ZeroTier, Inc. [GPL3]');
|
|
||||||
console.log('');
|
|
||||||
console.log('Usage: node migrate.js </path/to/controller.db> </path/to/controller.d>');
|
|
||||||
console.log('');
|
|
||||||
console.log('The first argument must be the path to the old Sqlite3 controller.db');
|
|
||||||
console.log('file. The second must be the path to the EMPTY controller.d database');
|
|
||||||
console.log('directory for a new (1.1.17 or newer) controller. If this path does');
|
|
||||||
console.log('not exist it will be created.');
|
|
||||||
console.log('');
|
|
||||||
console.log('WARNING: this will ONLY work correctly on a 1.1.14 controller database.');
|
|
||||||
console.log('If your controller is old you should first upgrade to 1.1.14 and run the');
|
|
||||||
console.log('controller so that it will brings its Sqlite3 database up to the latest');
|
|
||||||
console.log('version before running this migration.');
|
|
||||||
console.log('');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
var oldDbPath = process.argv[2];
|
|
||||||
var newDbPath = process.argv[3];
|
|
||||||
|
|
||||||
console.log('Starting migrate of "'+oldDbPath+'" to "'+newDbPath+'"...');
|
|
||||||
console.log('');
|
|
||||||
|
|
||||||
var old = new sqlite3.Database(oldDbPath);
|
|
||||||
|
|
||||||
var networks = {};
|
|
||||||
|
|
||||||
var nodeIdentities = {};
|
|
||||||
var networkCount = 0;
|
|
||||||
var memberCount = 0;
|
|
||||||
var routeCount = 0;
|
|
||||||
var ipAssignmentPoolCount = 0;
|
|
||||||
var ipAssignmentCount = 0;
|
|
||||||
var ruleCount = 0;
|
|
||||||
var oldSchemaVersion = -1;
|
|
||||||
|
|
||||||
async.series([function(nextStep) {
|
|
||||||
|
|
||||||
old.each('SELECT v from Config WHERE k = \'schemaVersion\'',function(err,row) {
|
|
||||||
oldSchemaVersion = parseInt(row.v)||-1;
|
|
||||||
},nextStep);
|
|
||||||
|
|
||||||
},function(nextStep) {
|
|
||||||
|
|
||||||
if (oldSchemaVersion !== 4) {
|
|
||||||
console.log('FATAL: this MUST be run on a 1.1.14 controller.db! Upgrade your old');
|
|
||||||
console.log('controller to 1.1.14 first and run it once to bring its DB up to date.');
|
|
||||||
return process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Reading networks...');
|
|
||||||
old.each('SELECT * FROM Network',function(err,row) {
|
|
||||||
if ((typeof row.id === 'string')&&(row.id.length === 16)) {
|
|
||||||
var flags = parseInt(row.flags)||0;
|
|
||||||
networks[row.id] = {
|
|
||||||
id: row.id,
|
|
||||||
nwid: row.id,
|
|
||||||
objtype: 'network',
|
|
||||||
authTokens: [],
|
|
||||||
capabilities: [],
|
|
||||||
creationTime: parseInt(row.creationTime)||0,
|
|
||||||
enableBroadcast: !!row.enableBroadcast,
|
|
||||||
ipAssignmentPools: [],
|
|
||||||
lastModified: Date.now(),
|
|
||||||
multicastLimit: row.multicastLimit||32,
|
|
||||||
name: row.name||'',
|
|
||||||
private: !!row.private,
|
|
||||||
revision: parseInt(row.revision)||1,
|
|
||||||
rules: [{ 'type': 'ACTION_ACCEPT' }], // populated later if there are defined rules, otherwise default is allow all
|
|
||||||
routes: [],
|
|
||||||
v4AssignMode: {
|
|
||||||
'zt': ((flags & 1) !== 0)
|
|
||||||
},
|
|
||||||
v6AssignMode: {
|
|
||||||
'6plane': ((flags & 4) !== 0),
|
|
||||||
'rfc4193': ((flags & 2) !== 0),
|
|
||||||
'zt': ((flags & 8) !== 0)
|
|
||||||
},
|
|
||||||
_members: {} // temporary
|
|
||||||
};
|
|
||||||
++networkCount;
|
|
||||||
//console.log(networks[row.id]);
|
|
||||||
}
|
|
||||||
},nextStep);
|
|
||||||
|
|
||||||
},function(nextStep) {
|
|
||||||
|
|
||||||
console.log(' '+networkCount+' networks.');
|
|
||||||
console.log('Reading network route definitions...');
|
|
||||||
old.each('SELECT * from Route WHERE ipVersion = 4 OR ipVersion = 6',function(err,row) {
|
|
||||||
var network = networks[row.networkId];
|
|
||||||
if (network) {
|
|
||||||
var rt = {
|
|
||||||
target: (((row.ipVersion == 4) ? blobToIPv4(row.target) : blobToIPv6(row.target))+'/'+row.targetNetmaskBits),
|
|
||||||
via: ((row.via) ? ((row.ipVersion == 4) ? blobToIPv4(row.via) : blobToIPv6(row.via)) : null)
|
|
||||||
};
|
|
||||||
network.routes.push(rt);
|
|
||||||
++routeCount;
|
|
||||||
}
|
|
||||||
},nextStep);
|
|
||||||
|
|
||||||
},function(nextStep) {
|
|
||||||
|
|
||||||
console.log(' '+routeCount+' routes in '+networkCount+' networks.');
|
|
||||||
console.log('Reading IP assignment pools...');
|
|
||||||
old.each('SELECT * FROM IpAssignmentPool WHERE ipVersion = 4 OR ipVersion = 6',function(err,row) {
|
|
||||||
var network = networks[row.networkId];
|
|
||||||
if (network) {
|
|
||||||
var p = {
|
|
||||||
ipRangeStart: ((row.ipVersion == 4) ? blobToIPv4(row.ipRangeStart) : blobToIPv6(row.ipRangeStart)),
|
|
||||||
ipRangeEnd: ((row.ipVersion == 4) ? blobToIPv4(row.ipRangeEnd) : blobToIPv6(row.ipRangeEnd))
|
|
||||||
};
|
|
||||||
network.ipAssignmentPools.push(p);
|
|
||||||
++ipAssignmentPoolCount;
|
|
||||||
}
|
|
||||||
},nextStep);
|
|
||||||
|
|
||||||
},function(nextStep) {
|
|
||||||
|
|
||||||
console.log(' '+ipAssignmentPoolCount+' IP assignment pools in '+networkCount+' networks.');
|
|
||||||
console.log('Reading known node identities...');
|
|
||||||
old.each('SELECT * FROM Node',function(err,row) {
|
|
||||||
nodeIdentities[row.id] = row.identity;
|
|
||||||
},nextStep);
|
|
||||||
|
|
||||||
},function(nextStep) {
|
|
||||||
|
|
||||||
console.log(' '+Object.keys(nodeIdentities).length+' known identities.');
|
|
||||||
console.log('Reading network members...');
|
|
||||||
old.each('SELECT * FROM Member',function(err,row) {
|
|
||||||
var network = networks[row.networkId];
|
|
||||||
if (network) {
|
|
||||||
network._members[row.nodeId] = {
|
|
||||||
id: row.nodeId,
|
|
||||||
address: row.nodeId,
|
|
||||||
objtype: 'member',
|
|
||||||
authorized: !!row.authorized,
|
|
||||||
activeBridge: !!row.activeBridge,
|
|
||||||
authHistory: [],
|
|
||||||
capabilities: [],
|
|
||||||
creationTime: 0,
|
|
||||||
identity: nodeIdentities[row.nodeId]||null,
|
|
||||||
ipAssignments: [],
|
|
||||||
lastAuthorizedTime: (row.authorized) ? Date.now() : 0,
|
|
||||||
lastDeauthorizedTime: (row.authorized) ? 0 : Date.now(),
|
|
||||||
lastModified: Date.now(),
|
|
||||||
lastRequestMetaData: '',
|
|
||||||
noAutoAssignIps: false,
|
|
||||||
nwid: row.networkId,
|
|
||||||
revision: parseInt(row.memberRevision)||1,
|
|
||||||
tags: [],
|
|
||||||
recentLog: []
|
|
||||||
};
|
|
||||||
++memberCount;
|
|
||||||
//console.log(network._members[row.nodeId]);
|
|
||||||
}
|
|
||||||
},nextStep);
|
|
||||||
|
|
||||||
},function(nextStep) {
|
|
||||||
|
|
||||||
console.log(' '+memberCount+' members of '+networkCount+' networks.');
|
|
||||||
console.log('Reading static IP assignments...');
|
|
||||||
old.each('SELECT * FROM IpAssignment WHERE ipVersion = 4 OR ipVersion = 6',function(err,row) {
|
|
||||||
var network = networks[row.networkId];
|
|
||||||
if (network) {
|
|
||||||
var member = network._members[row.nodeId];
|
|
||||||
if ((member)&&((member.authorized)||(!network['private']))) { // don't mirror assignments to unauthorized members to avoid conflicts
|
|
||||||
if (row.ipVersion == 4) {
|
|
||||||
member.ipAssignments.push(blobToIPv4(row.ip));
|
|
||||||
++ipAssignmentCount;
|
|
||||||
} else if (row.ipVersion == 6) {
|
|
||||||
member.ipAssignments.push(blobToIPv6(row.ip));
|
|
||||||
++ipAssignmentCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},nextStep);
|
|
||||||
|
|
||||||
},function(nextStep) {
|
|
||||||
|
|
||||||
// Old versions only supported Ethertype whitelisting, so that's
|
|
||||||
// all we mirror forward. The other fields were always unused.
|
|
||||||
|
|
||||||
console.log(' '+ipAssignmentCount+' IP assignments for '+memberCount+' authorized members of '+networkCount+' networks.');
|
|
||||||
console.log('Reading allowed Ethernet types (old basic rules)...');
|
|
||||||
var etherTypesByNetwork = {};
|
|
||||||
old.each('SELECT DISTINCT networkId,ruleNo,etherType FROM Rule WHERE "action" = \'accept\'',function(err,row) {
|
|
||||||
if (row.networkId in networks) {
|
|
||||||
var et = parseInt(row.etherType)||0;
|
|
||||||
var ets = etherTypesByNetwork[row.networkId];
|
|
||||||
if (!ets)
|
|
||||||
etherTypesByNetwork[row.networkId] = [ et ];
|
|
||||||
else ets.push(et);
|
|
||||||
}
|
|
||||||
},function(err) {
|
|
||||||
if (err) return nextStep(err);
|
|
||||||
for(var nwid in etherTypesByNetwork) {
|
|
||||||
var ets = etherTypesByNetwork[nwid].sort();
|
|
||||||
var network = networks[nwid];
|
|
||||||
if (network) {
|
|
||||||
var rules = [];
|
|
||||||
if (ets.indexOf(0) >= 0) {
|
|
||||||
// If 0 is in the list, all Ethernet types are allowed so we accept all.
|
|
||||||
rules.push({ 'type': 'ACTION_ACCEPT' });
|
|
||||||
} else {
|
|
||||||
// Otherwise we whitelist.
|
|
||||||
for(var i=0;i<ets.length;++i) {
|
|
||||||
rules.push({
|
|
||||||
'etherType': ets[i],
|
|
||||||
'not': true,
|
|
||||||
'or': false,
|
|
||||||
'type': 'MATCH_ETHERTYPE'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
rules.push({ 'type': 'ACTION_DROP' });
|
|
||||||
rules.push({ 'type': 'ACTION_ACCEPT' });
|
|
||||||
}
|
|
||||||
network.rules = rules;
|
|
||||||
++ruleCount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nextStep(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
}],function(err) {
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
console.log('FATAL: '+err.toString());
|
|
||||||
return process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(' '+ruleCount+' ethernet type whitelists converted to new format rules.');
|
|
||||||
old.close();
|
|
||||||
console.log('Done reading and converting Sqlite3 database! Writing JSONDB files...');
|
|
||||||
|
|
||||||
try {
|
|
||||||
fs.mkdirSync(newDbPath,0o700);
|
|
||||||
} catch (e) {}
|
|
||||||
var nwBase = newDbPath+'/network';
|
|
||||||
try {
|
|
||||||
fs.mkdirSync(nwBase,0o700);
|
|
||||||
} catch (e) {}
|
|
||||||
nwBase = nwBase + '/';
|
|
||||||
var nwids = Object.keys(networks).sort();
|
|
||||||
var fileCount = 0;
|
|
||||||
for(var ni=0;ni<nwids.length;++ni) {
|
|
||||||
var network = networks[nwids[ni]];
|
|
||||||
|
|
||||||
var mids = Object.keys(network._members).sort();
|
|
||||||
if (mids.length > 0) {
|
|
||||||
try {
|
|
||||||
fs.mkdirSync(nwBase+network.id);
|
|
||||||
} catch (e) {}
|
|
||||||
var mbase = nwBase+network.id+'/member';
|
|
||||||
try {
|
|
||||||
fs.mkdirSync(mbase,0o700);
|
|
||||||
} catch (e) {}
|
|
||||||
mbase = mbase + '/';
|
|
||||||
|
|
||||||
for(var mi=0;mi<mids.length;++mi) {
|
|
||||||
var member = network._members[mids[mi]];
|
|
||||||
fs.writeFileSync(mbase+member.id+'.json',JSON.stringify(member,null,1),{ mode: 0o600 });
|
|
||||||
++fileCount;
|
|
||||||
//console.log(mbase+member.id+'.json');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
delete network._members; // temporary field, not part of actual JSONDB, so don't write
|
|
||||||
fs.writeFileSync(nwBase+network.id+'.json',JSON.stringify(network,null,1),{ mode: 0o600 });
|
|
||||||
++fileCount;
|
|
||||||
//console.log(nwBase+network.id+'.json');
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('');
|
|
||||||
console.log('SUCCESS! Wrote '+fileCount+' JSONDB files.');
|
|
||||||
|
|
||||||
console.log('');
|
|
||||||
console.log('You should still inspect the new DB before going live. Also be sure');
|
|
||||||
console.log('to "chown -R" and "chgrp -R" the new DB to the user and group under');
|
|
||||||
console.log('which the ZeroTier One instance acting as controller will be running.');
|
|
||||||
console.log('The controller must be able to read and write the DB, of course.');
|
|
||||||
console.log('');
|
|
||||||
console.log('Have fun!');
|
|
||||||
|
|
||||||
return process.exit(0);
|
|
||||||
});
|
|
|
@ -1,15 +0,0 @@
|
||||||
{
|
|
||||||
"name": "migrate-sqlite",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "Migrate old SQLite to new JSON filesystem DB for ZeroTier network controller",
|
|
||||||
"main": "migrate.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
|
||||||
},
|
|
||||||
"author": "Adam Ierymenko <adam.ierymenko@zerotier.com>",
|
|
||||||
"license": "GPL-3.0",
|
|
||||||
"dependencies": {
|
|
||||||
"async": "^2.1.4",
|
|
||||||
"sqlite3": "^3.1.8"
|
|
||||||
}
|
|
||||||
}
|
|
24
debian/changelog
vendored
|
@ -1,24 +0,0 @@
|
||||||
zerotier-one (1.2.4-nt1) unstable; urgency=medium
|
|
||||||
|
|
||||||
* Imported Upstream version 1.2.4
|
|
||||||
|
|
||||||
-- didyouexpectthat <github@didyouexpect.us> Fri, 12 Jan 2018 18:26:28 -0800
|
|
||||||
|
|
||||||
zerotier-one (1.1.14-nt3) unstable; urgency=medium
|
|
||||||
|
|
||||||
* Clean up authtoken CGI
|
|
||||||
|
|
||||||
-- NAStools <dev@nas.tools> Fri, 09 Dec 2016 10:20:55 -0800
|
|
||||||
|
|
||||||
zerotier-one (1.1.14-nt2) unstable; urgency=medium
|
|
||||||
|
|
||||||
* Include UI from macOS client
|
|
||||||
* Configure package to use UI from macOS client
|
|
||||||
|
|
||||||
-- NAStools <dev@nas.tools> Tue, 29 Nov 2016 18:02:28 -0800
|
|
||||||
|
|
||||||
zerotier-one (1.1.14-nt1) unstable; urgency=medium
|
|
||||||
|
|
||||||
* Initial release
|
|
||||||
|
|
||||||
-- NAStools <dev@nas.tools> Tue, 01 Nov 2016 16:30:45 -0700
|
|
1
debian/compat
vendored
|
@ -1 +0,0 @@
|
||||||
9
|
|
19
debian/control
vendored
|
@ -1,19 +0,0 @@
|
||||||
Source: zerotier-one
|
|
||||||
Maintainer: NAStools <github@didyouexpect.us>
|
|
||||||
Section: net
|
|
||||||
Priority: optional
|
|
||||||
Standards-Version: 3.9.6
|
|
||||||
Build-Depends: debhelper (>= 9), liblz4-dev, libnatpmp-dev, ruby-ronn, dh-systemd
|
|
||||||
Vcs-Git: git://github.com/didyouexpectthat/zerotierone
|
|
||||||
Vcs-Browser: https://github.com/didyouexpectthat/zerotierone
|
|
||||||
Homepage: https://www.zerotier.com
|
|
||||||
|
|
||||||
Package: nastools-zerotier-one
|
|
||||||
Architecture: any
|
|
||||||
Depends: readynasos (>= 6.9.2), ${shlibs:Depends}, ${misc:Depends},
|
|
||||||
libnatpmp1, iproute2, libstdc++6
|
|
||||||
Description: ZeroTier network virtualization service
|
|
||||||
ZeroTier One lets you join ZeroTier virtual networks and
|
|
||||||
have them appear as tun/tap ports on your system. See
|
|
||||||
https://www.zerotier.com/ for instructions and
|
|
||||||
documentation.
|
|
24
debian/copyright
vendored
|
@ -1,24 +0,0 @@
|
||||||
Format: http://dep.debian.net/deps/dep5
|
|
||||||
Upstream-Name: zerotier-one
|
|
||||||
Source: https://github.com/zerotier/ZeroTierOne
|
|
||||||
|
|
||||||
Files: *
|
|
||||||
Copyright: 2011-2016 ZeroTier, Inc.
|
|
||||||
License: GPL-3.0+
|
|
||||||
|
|
||||||
License: GPL-3.0+
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
.
|
|
||||||
This package is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
.
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
.
|
|
||||||
On Debian systems, the complete text of the GNU General
|
|
||||||
Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
|
14
debian/gbp.conf
vendored
|
@ -1,14 +0,0 @@
|
||||||
[DEFAULT]
|
|
||||||
pristine-tar = True
|
|
||||||
debian-branch = master
|
|
||||||
debian-tag = readynas/%(version)s
|
|
||||||
debian-tag-msg = %(pkg)s ReadyNAS OS release %(version)s
|
|
||||||
|
|
||||||
[git-buildpackage]
|
|
||||||
export-dir = ../build-area/
|
|
||||||
color = on
|
|
||||||
pristine-tar-commit = True
|
|
||||||
|
|
||||||
[git-dch]
|
|
||||||
# ignore merge commit messages
|
|
||||||
git-log = --no-merges
|
|
6
debian/install
vendored
|
@ -1,6 +0,0 @@
|
||||||
debian/readynas/config.xml apps/nastools-zerotier-one
|
|
||||||
debian/readynas/fvapp-nastools-zerotier-one.service apps/nastools-zerotier-one
|
|
||||||
debian/readynas/logo.png apps/nastools-zerotier-one
|
|
||||||
debian/readynas/https.conf apps/nastools-zerotier-one
|
|
||||||
debian/readynas/authtoken apps/nastools-zerotier-one/cgi
|
|
||||||
zerotier-one apps/nastools-zerotier-one/sbin
|
|
3
debian/links
vendored
|
@ -1,3 +0,0 @@
|
||||||
apps/nastools-zerotier-one/sbin/zerotier-one usr/sbin/zerotier-cli
|
|
||||||
apps/nastools-zerotier-one/sbin/zerotier-one usr/sbin/zerotier-idtool
|
|
||||||
apps/nastools-zerotier-one/sbin/zerotier-one usr/sbin/zerotier-one
|
|
7
debian/lintian-overrides
vendored
|
@ -1,7 +0,0 @@
|
||||||
## Overrides from NAStools
|
|
||||||
# Overrides for ReadyNAS packaging
|
|
||||||
nastools-zerotier-one: non-standard-toplevel-dir apps/
|
|
||||||
nastools-zerotier-one: file-in-unusual-dir apps/nastools-zerotier-one/*
|
|
||||||
|
|
||||||
# Debian's libminiupnpc is too old, so let ZT include its own
|
|
||||||
nastools-zerotier-one: embedded-library apps/nastools-zerotier-one/sbin/zerotier-one: libminiupnpc
|
|
3
debian/manpages
vendored
|
@ -1,3 +0,0 @@
|
||||||
doc/zerotier-cli.1
|
|
||||||
doc/zerotier-idtool.1
|
|
||||||
doc/zerotier-one.8
|
|
|
@ -1,23 +0,0 @@
|
||||||
From: NAStools <dev@nas.tools>
|
|
||||||
Date: Tue, 1 Nov 2016 16:09:41 -0700
|
|
||||||
Subject: Update platformDefaultHomePath() for ReadyNAS OS
|
|
||||||
|
|
||||||
---
|
|
||||||
osdep/OSUtils.cpp | 4 ++--
|
|
||||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp
|
|
||||||
index 3a04308..0a9ade6 100644
|
|
||||||
--- a/osdep/OSUtils.cpp
|
|
||||||
+++ b/osdep/OSUtils.cpp
|
|
||||||
@@ -244,8 +244,8 @@ std::string OSUtils::platformDefaultHomePath()
|
|
||||||
// BSD likes /var/db instead of /var/lib
|
|
||||||
return std::string("/var/db/zerotier-one");
|
|
||||||
#else
|
|
||||||
- // Use /var/lib for Linux and other *nix
|
|
||||||
- return std::string("/var/lib/zerotier-one");
|
|
||||||
+ // Use /apps/nastools-zerotier-one/var for ReadyNAS OS
|
|
||||||
+ return std::string("/apps/nastools-zerotier-one/var");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
1
debian/patches/series
vendored
|
@ -1 +0,0 @@
|
||||||
0001-Update-platformDefaultHomePath-for-ReadyNAS-OS.patch
|
|
14
debian/postinst
vendored
|
@ -1,14 +0,0 @@
|
||||||
#!/bin/sh -e
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
configure)
|
|
||||||
adduser --system --group --home /var/lib/zerotier-one --no-create-home zerotier-one
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# avahi explicitly doesn't broadcast over ZeroTier
|
|
||||||
# so tell avahi to change the config
|
|
||||||
# avahi already reloads config on file change
|
|
||||||
sed -i 's/,zt0//' /etc/avahi/avahi-daemon.conf
|
|
||||||
|
|
||||||
#DEBHELPER#
|
|