diff --git a/.gitignore b/.gitignore
index 3b018c424..8bf3c55bb 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,9 @@
# Main binaries created in *nix builds
-/zerotier-*
+/zerotier-one
+/zerotier-idtool
+/zerotier-cli
+/zerotier-selftest
+/zerotier
# OS-created garbage files from various platforms
.DS_Store
@@ -33,6 +37,7 @@ Thumbs.db
/examples/docker/test-*.env
/world/mkworld
/world/*.c25519
+zt1-src.tar.gz
# Miscellaneous temporaries, build files, etc.
*.log
@@ -54,18 +59,16 @@ Thumbs.db
*.rpm
*.autosave
*.tmp
+doc/*.1
+doc/*.2
+doc/*.8
.depend
node_modules
-cluster-geo/cluster-geo/config.js
-cluster-geo/cluster-geo/cache.*
-tests/http/zerotier-one
-tests/http/big-test-hosts
-netcon/httpstub
-
-# MacGap wrapper build files
-/ext/mac-ui-macgap1-wrapper/src/MacGap.xcodeproj/project.xcworkspace/xcuserdata/*
-/ext/mac-ui-macgap1-wrapper/src/MacGap.xcodeproj/xcuserdata/*
-/ext/mac-ui-macgap1-wrapper/src/build
+debian/files
+debian/zerotier-one
+debian/zerotier-one*.debhelper
+debian/*.log
+debian/zerotier-one.substvars
# Java/Android/JNI build droppings
java/obj/
@@ -79,3 +82,4 @@ java/build_win32/
windows/WinUI/obj/
windows/WinUI/bin/
windows/ZeroTierOne/Debug/
+/ext/installfiles/windows/chocolatey/zerotier-one/*.nupkg
diff --git a/AUTHORS.md b/AUTHORS.md
index b286e7ca3..aa9e91119 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -1,44 +1,80 @@
-## Authors
+## Primary Authors
- * ZeroTier protocol design and core network virtualization engine, ZeroTier One service, React web UI, packaging for most platforms, kitchen sink...
+ * ZeroTier Core and ZeroTier One virtual networking service
Adam Ierymenko / adam.ierymenko@zerotier.com
* Java JNI Interface to enable Android application development, and Android app itself (code for that is elsewhere)
Grant Limberg / glimberg@gmail.com
-## Contributors
+ * ZeroTier SDK (formerly known as Network Containers)
+ Joseph Henry / joseph.henry@zerotier.com
+
+## Third Party Contributors
* A number of fixes and improvements to the new controller, other stuff.
- Kees Bos / https://github.com/keesbos
+ Kees Bos / https://github.com/keesbos/
* Debugging and testing, OpenWRT support fixes.
Moritz Warning / moritzwarning@web.de
+ * Debian GNU/Linux packaging, manual pages, and license compliance edits.
+ Ben Finney
+
* Several others made smaller contributions, which GitHub tracks here:
- https://github.com/zerotier/ZeroTierOne/graphs/contributors
+ https://github.com/zerotier/ZeroTierOne/graphs/contributors/
-## Third Party Code
+## Third-Party Code
- * LZ4 compression algorithm by Yann Collet (BSD license)
- http://code.google.com/p/lz4/
+These are included in ext/ for platforms that do not have them available in common repositories. Otherwise they may be linked and the package may ship with them as dependencies.
- * http-parser by many authors (MIT license)
- https://github.com/joyent/http-parser
+ * LZ4 compression algorithm by Yann Collet
- * json-parser by James McLaughlin (BSD license)
- https://github.com/udp/json-parser
+ * Files: ext/lz4/*
+ * Home page: http://code.google.com/p/lz4/
+ * License grant: BSD attribution
- * TunTapOSX by Mattias Nissler (BSD license)
- http://tuntaposx.sourceforge.net
+ * http-parser by Joyent, Inc. (many authors)
- * tap-windows and tap-windows6 by the OpenVPN project (GPL)
- https://github.com/OpenVPN/tap-windows
- https://github.com/OpenVPN/tap-windows6
+ * Files: ext/http-parser/*
+ * Home page: https://github.com/joyent/http-parser/
+ * License grant: MIT/Expat
+
+ * json-parser by James McLaughlin
+
+ * Files: ext/json-parser/*
+ * Home page: https://github.com/udp/json-parser/
+ * License grant: BSD attribution
+
+ * 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 (public domain)
- http://cr.yp.to/
+ Daniel J. Bernstein
- * MiniUPNPC by Thomas Bernard [BSD]
- http://miniupnp.free.fr
+ * Files:
+ node/Salsa20.hpp
+ node/C25519.hpp
+ node/Poly1305.hpp
+ * Home page: http://cr.yp.to/
+ * License grant: public domain
+
+ * MiniUPNPC and libnatpmp by Thomas Bernard
+
+ * Files:
+ ext/libnatpmp/*
+ ext/miniupnpc/*
+ * Home page: http://miniupnp.free.fr/
+ * License grant: BSD attribution no-endorsement
diff --git a/COPYING b/COPYING
new file mode 100644
index 000000000..23d42dfa1
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,17 @@
+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 .
+
+..
+ Local variables:
+ coding: utf-8
+ mode: text
+ End:
+ vim: fileencoding=utf-8 filetype=text :
diff --git a/LICENSE.GPL-2 b/LICENSE.GPL-2
new file mode 100644
index 000000000..d159169d1
--- /dev/null
+++ b/LICENSE.GPL-2
@@ -0,0 +1,339 @@
+ 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.
+
+
+ Copyright (C)
+
+ 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.
+
+ , 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.
diff --git a/LICENSE.GPL-3 b/LICENSE.GPL-3
new file mode 100644
index 000000000..94a9ed024
--- /dev/null
+++ b/LICENSE.GPL-3
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ 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.
+
+
+ Copyright (C)
+
+ 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 .
+
+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:
+
+ Copyright (C)
+ 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
+.
+
+ 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
+.
diff --git a/LICENSE.txt b/LICENSE.txt
deleted file mode 100644
index 01c99074d..000000000
--- a/LICENSE.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-ZeroTier One is licensed under the terms of the GNU General Public License
-version 3, which are available here:
-
-http://gplv3.fsf.org/
-
-Modification and redistribution of ZeroTier One is permitted in source form.
-Binary distribution is permitted provided all copyright notices remain
-intact and any modifications to the source code are also distributed.
-
-ZeroTier One may not be embedded into any closed-source application (e.g. via
-linking), nor may closed-source derivatives be created, without a separately
-negotiated license from ZeroTier Networks LLC. See the terms of the GPLv3 for
-details.
diff --git a/OFFICIAL-RELEASE-STEPS.md b/OFFICIAL-RELEASE-STEPS.md
new file mode 100644
index 000000000..37e679141
--- /dev/null
+++ b/OFFICIAL-RELEASE-STEPS.md
@@ -0,0 +1,63 @@
+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
+
+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.
diff --git a/README.md b/README.md
index 123fbf019..a34a1a53a 100644
--- a/README.md
+++ b/README.md
@@ -1,35 +1,51 @@
-ZeroTier One
+ZeroTier - A Planetary Ethernet Switch
======
-ZeroTier is a software defined networking layer for Earth.
+ZeroTier is a software-based managed Ethernet switch for planet Earth.
-It can be used for on-premise network virtualization, as a peer to peer VPN for mobile teams, for hybrid or multi-data-center cloud deployments, or just about anywhere else secure software defined virtual networking is useful.
+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.
-ZeroTier One is our OS-level client service. It allows Mac, Linux, Windows, FreeBSD, and soon other types of clients to join ZeroTier virtual networks like conventional VPNs or VLANs. It can run on native systems, VMs, or containers (Docker, OpenVZ, etc.).
+This repository contains ZeroTier One, a service that provides ZeroTier network connectivity to devices running Windows, Mac, Linux, iOS, Android, and FreeBSD and makes joining virtual networks as easy as joining IRC or Slack channels. It also contains the OS-independent core ZeroTier protocol implementation in [node/](node/).
-Visit [ZeroTier's site](https://www.zerotier.com/) for more information. You can also download professionally packaged binary installers/packages for a variety of supported OSes there if you don't want to build ZeroTier One from source.
+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" can be anything really: desktops, laptops, phones, servers, VMs/VPSes, containers, and even (soon) apps.
+
+For testing we provide a public virtual network called *Earth* with network ID `8056c2e21c000001`. On Linux and Mac you can do this 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.
+
+*(IPv4 addresses for Earth are assigned from the block 28.0.0.0/7, which is not a part of the public Internet but is non-standard for private networks. It's used to avoid IP conflicts during testing. Your networks can run any IP addressing scheme you want.)*
+
+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. You can use [our hosted controller at my.zerotier.com](https://my.zerotier.com) which is free for up to 100 devices on an unlimited number of networks, or you can build your own controller and run it through its local JSON API. See [README.md in controller/](controller/) for more information.
### Building from Source
For Mac, Linux, and BSD, just type "make" (or "gmake" on BSD). You won't need much installed; here are the requirements for various platforms:
- * Mac: Xcode command line tools, and [Packages](http://s.sudre.free.fr/Software/Packages/about.html) if you want to build an OSX .pkg installer ("make mac-dist-pkg"). It should build on OSX 10.7 or newer.
- * Linux: gcc/g++ or clang/clang++ (Makefile will use clang by default if available.)
- * FreeBSD (and other BSD): C++ compiler (G++ usually) and GNU make (gmake).
+ * **Mac**: Xcode command line tools. It should build on OSX 10.7 or newer.
+ * **Linux**: gcc/g++ (4.9 or newer recommended) or clang/clang++ (3.4 or newer recommended) Makefile will use clang by default if available. The Linux build will auto-detect the presence of development headers for *json-parser*, *http-parser*, *li8bnatpmp*, and *libminiupnpc* and will link against the system libraries for these if they are present and recent enough. Otherwise the bundled versions in [ext/](ext/) will be used. Type `make install` to install the binaries and other files on the system, though this will not create init.d or systemd links.
+ * **FreeBSD**: C++ compiler (G++ usually) and GNU make (gmake).
Each supported platform has its own *make-XXX.mk* file that contains the actual make rules for the platform. The right .mk file is included by the main Makefile based on the GNU make *OSTYPE* variable. Take a look at the .mk file for your platform for other targets, debug build rules, etc.
-Windows, of course, is special. We build for Windows with Microsoft Visual Studio 2012 on Windows 7. A solution file is located in the *windows* subfolder. Newer versions of Visual Studio (and Windows) may work but haven't been tested. Older versions almost certainly will not, since they lack things like *stdint.h* and certain STL features. MinGW or other ports of gcc/clang to Windows should also work but haven't been tested. Build steps for Windows are a bit more complicated. For the moment you are on your own there.
+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.
-Mobile versions are in progress. They don't work yet, and in any case only the glue code will be included in this repository. The full mobile apps are in private repositories on our own git server.
+Windows, of course, is special. We build for Windows with Microsoft Visual Studio 2012 on Windows 7. A solution file is located in the *windows/* subfolder. Newer versions of Visual Studio (and Windows) may work but haven't been tested. Older versions almost certainly will not, since they lack things like *stdint.h* and certain STL features. MinGW or other ports of gcc/clang to Windows should also work but haven't been tested.
-### Supported Platforms
-
-CPU architecture shouldn't matter unless it's smaller than 32-bit or something really bizarre like a "middle-endian" processor. We have reports of ZeroTier One running on arm32, arm64, and MIPS. It builds and runs out of the box on Raspberry Pi, BeagleBone, BananaPi, and other ARM-based developer/hobbyist boards.
-
-ZeroTier is written in C and C++ (C++03 / ISO/IEC 14882:2003) and uses data structures and algorithms from the C++03 STL. We do not use any C++11 features (yet), since we want to support a few old and embedded platforms that don't have C++11 compilers. You *will* require a compiler and headers new enough to support 64-bit integers (long long) and the *stdint.h* header. The latter could also be faked by adding defines for things like *uint32\_t*, *int64\_t*, etc.
-
-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.
+32 and 64 bit X86 and ARM (e.g. Raspberry Pi, Android) are officially supported. Community members have built for MIPS and Sparc without issues.
### Running
@@ -45,10 +61,10 @@ The service is controlled via the JSON API, which by default is available at 127
Here's where home folders live (by default) on each OS:
- * Linux: /var/lib/zerotier-one
- * BSD: /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.)
+ * **Linux**: `/var/lib/zerotier-one`
+ * **FreeBSD**: `/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:
@@ -56,107 +72,17 @@ Running ZeroTier One on a Mac is the same, but OSX requires a kernel extension.
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*.
-We recommend using our binary packages on Windows, since there are several prerequisites such as a tap driver that must be installed on the system *and* in the home folder.
-
-### Joining A Network
-
-ZeroTier virtual networks are identified by 16-digit hexadecimal network IDs, while devices are identified by 10-digit addresses. To get your address run:
-
- sudo zerotier-cli status
-
-(Use ./zerotier-cli if you're running it right from your build folder.)
-
-You should see something like:
-
- 200 info ########## ONLINE #.#.#
-
-That 10-digit hex code is you. It's derived via a one-way proof of work function from your cryptographic public key. Your public key can be found in *identity.public* in ZeroTier's home folder, while *identity.secret* contains your full identity including the secret portion of the key pair.
-
-(The identity files define your device's *identity*. Moving them to another system will move that identity. Be careful when cloning virtual machines that have identities stored on them. If two devices have the same identity, they'll "fight" over it and you won't know which device will receive network packets.)
-
-If you want to do a quick test, you can join [Earth](https://www.zerotier.com/earth.html). It's a global public network that anyone can join. Type:
-
- sudo zerotier-cli join 8056c2e21c000001
-
-Then:
-
- sudo zerotier-cli listnetworks
-
-At first it'll be in *REQUESTING\_CONFIGURATION* state. In a few seconds to a minute you should see something like:
-
- 200 listnetworks 8056c2e21c000001 earth.zerotier.net ##:##:##:##:##:## OK PUBLIC zt0 ##.##.##.##/##
-
-Earth will assign you an IP address in the "unofficially available" globally unrouted 28.0.0.0/7 IP block so as to avoid conflicts with local networks. (Your networks can use any IP scheme, or can even leave IP addresses unmanaged.) Once you get an IP, you should be able to ping something:
-
- ping earth.zerotier.net
-
-Go to [http://earth.zerotier.net/](http://earth.zerotier.net/) to see a short little welcome page that will tell you your IP and Ethernet MAC address.
-
-Earth is a public place. If you don't want to stick around run:
-
- sudo zerotier-cli leave 8056c2e21c000001
-
-The network (and associated interface) should be gone.
-
-Networks are created and administrated by network controllers. Most users will want to use our hosted controllers. Visit [our web site](https://www.zerotier.com/) for more information. Later in this README there are brief instructions about building ZeroTier One with network controller support for those who want to try running their own.
-
-Macintosh and Windows installers also install a GUI application.
-
-### Installing
-
-We don't have a "make install" rule quite yet. On Linux you can type:
-
- make installer
-
-This will build a binary that, when run, will install ZeroTier One on most current Linux distributions. We also have RPM and DEB build files in *ext/installfiles/linux* that wrap this installer in packages for RedHat/CentOS and Debian/Ubuntu derived distributions. If *rpmbuild* is present on the system, the RPM will be built. If *dpkg-deb* is present, the DEB package will be built.
-
-On Mac the best way is to install [Packages](http://s.sudre.free.fr/Software/Packages/about.html) and use:
-
- make mac-dist-pkg
-
-This builds a .pkg file that can be installed.
-
-In FreeBSD there is now an official .pkg in the FreeBSD repository. Type "pkg install zerotier". It can also be built and installed from source.
-
-Linux/BSD and Mac installations have an *uninstall.sh* file in their ZeroTier home folder that cleanly removes ZeroTier One from the system. Run this with:
-
- sudo /path/to/ZeroTier/home/folder/uninstall.sh
-
-Windows installers are insane. We build our .MSI installers with [Advanced Installer Enterprise](http://www.advancedinstaller.com). The Advanced Installer project file is in *ext/installfiles/windows*. To avoid lasting psychological trauma we recommend leaving Windows installers alone and using the pre-built Windows binaries on our web site.
-
-### Using ZeroTier One in Docker Containers
-
-To run the ZeroTier One service in a Docker container, run it with "--device=/dev/net/tun --cap-add=NET_ADMIN". This will allow ZeroTier One to open a "tap" virtual network port inside the container.
-
-Alternately, you can use Ethernet bridging to bridge the *docker0* device on your system to a ZeroTier virtual network. This allows you to run ZeroTier One on the host and bridge the entire Docker network backplane to a virtual network or other hosts.
-
-We're working on better "official" Docker support. In the meantime there is a [user-contributed project here](https://github.com/davide/docker-zerotier).
-
-### Building with Network Controller Support
-
-**Warning: as of beta version 1.0.3 the new network controller is not heavily tested. We recommend waiting for 1.0.4 to deploy this in production.**
-
-Network controllers are nodes responsible for issuing configurations and certificates to members of ZeroTier virtual networks. Most users won't need to run their own, so this code is by default not included in the ZeroTier One binary.
-
-You can build a network controller on Linux or Mac with:
-
- make ZT_ENABLE_NETWORK_CONTROLLER=1
-
-This will build a version that contains the Sqlite-backed network controller and associated extensions to the JSON local service control API. You will need the development headers for sqlite3 installed. On Mac these ship as part of Xcode, while on Linux they'll be found in packages for the various distributions.
-
-See the JSON API documentation in [service/](service/) for more information about how to control controllers.
-
### 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 founder 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:
+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.
+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.
@@ -168,7 +94,7 @@ If a firewall between you and the Internet blocks ZeroTier's UDP traffic, you wi
### Contributing
-There are three main branches: **edge**, **test**, and **master**. Other branches may be for specific features, tests, or use cases. In general **edge** is "bleeding" and may or may not work, while **test** should be relatively stable and **master** is the latest tagged release. Pull requests should generally be done against **test** or **edge**, since pull requests against **master** may be working against a branch that is somewhat out of date.
+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
diff --git a/attic/BandwidthAccount.hpp b/attic/BandwidthAccount.hpp
deleted file mode 100644
index 3a6432c44..000000000
--- a/attic/BandwidthAccount.hpp
+++ /dev/null
@@ -1,153 +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 .
- *
- * --
- *
- * 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_BWACCOUNT_HPP
-#define ZT_BWACCOUNT_HPP
-
-#include "Constants.hpp"
-
-#include
-
-#include
-#include
-
-#include "Utils.hpp"
-
-#ifdef __WINDOWS__
-#define round(x) ((x-floor(x))>0.5 ? ceil(x) : floor(x))
-#endif
-
-namespace ZeroTier {
-
-/**
- * Bandwidth account used for rate limiting multicast groups
- *
- * This is used to apply a bank account model to multicast groups. Each
- * multicast packet counts against a balance, which accrues at a given
- * rate in bytes per second. Debt is possible. These parameters are
- * configurable.
- *
- * A bank account model permits bursting behavior, which correctly models
- * how OSes and apps typically use multicast. It's common for things to
- * spew lots of multicast messages at once, wait a while, then do it
- * again. A consistent bandwidth limit model doesn't fit.
- */
-class BandwidthAccount
-{
-public:
- /**
- * Create an uninitialized account
- *
- * init() must be called before this is used.
- */
- BandwidthAccount() throw() {}
-
- /**
- * Create and initialize
- *
- * @param preload Initial balance to place in account
- * @param maxb Maximum allowed balance (> 0)
- * @param acc Rate of accrual in bytes per second
- * @param now Current time
- */
- BandwidthAccount(uint32_t preload,uint32_t maxb,uint32_t acc,uint64_t now)
- throw()
- {
- init(preload,maxb,acc,now);
- }
-
- /**
- * Initialize or re-initialize account
- *
- * @param preload Initial balance to place in account
- * @param maxb Maximum allowed balance (> 0)
- * @param acc Rate of accrual in bytes per second
- * @param now Current time
- */
- inline void init(uint32_t preload,uint32_t maxb,uint32_t acc,uint64_t now)
- throw()
- {
- _lastTime = ((double)now / 1000.0);
- _balance = preload;
- _maxBalance = maxb;
- _accrual = acc;
- }
-
- /**
- * Update and retrieve balance of this account
- *
- * @param now Current time
- * @return New balance updated from current clock
- */
- inline uint32_t update(uint64_t now)
- throw()
- {
- double lt = _lastTime;
- double nowf = ((double)now / 1000.0);
- _lastTime = nowf;
- return (_balance = std::min(_maxBalance,(uint32_t)round((double)_balance + ((double)_accrual * (nowf - lt)))));
- }
-
- /**
- * Update balance and conditionally deduct
- *
- * If the deduction amount fits, it is deducted after update. Otherwise
- * balance is updated and false is returned.
- *
- * @param amt Amount to deduct
- * @param now Current time
- * @return True if amount fit within balance and was deducted
- */
- inline bool deduct(uint32_t amt,uint64_t now)
- throw()
- {
- if (update(now) >= amt) {
- _balance -= amt;
- return true;
- }
- return false;
- }
-
- /**
- * @return Most recent balance without update
- */
- inline uint32_t balance() const
- throw()
- {
- return _balance;
- }
-
-private:
- double _lastTime;
- uint32_t _balance;
- uint32_t _maxBalance;
- uint32_t _accrual;
-};
-
-} // namespace ZeroTier
-
-#endif
diff --git a/attic/OSXEthernetTap.cpp.pcap-with-bridge-test b/attic/OSXEthernetTap.cpp.pcap-with-bridge-test
index 60194421c..baae0a4b3 100644
--- a/attic/OSXEthernetTap.cpp.pcap-with-bridge-test
+++ b/attic/OSXEthernetTap.cpp.pcap-with-bridge-test
@@ -43,7 +43,6 @@
#include
#include
#include
-#include
#include
#include
#include
diff --git a/attic/OSXEthernetTap.cpp.utun-work-in-progress b/attic/OSXEthernetTap.cpp.utun-work-in-progress
index b7a05334d..f40483e8c 100644
--- a/attic/OSXEthernetTap.cpp.utun-work-in-progress
+++ b/attic/OSXEthernetTap.cpp.utun-work-in-progress
@@ -43,7 +43,6 @@
#include
#include
#include
-#include
#include
#include
#include
diff --git a/attic/SECURITY.md b/attic/SECURITY.md
new file mode 100644
index 000000000..d663f84a0
--- /dev/null
+++ b/attic/SECURITY.md
@@ -0,0 +1,84 @@
+ZeroTier Security
+======
+
+## Summary
+
+
+## Using ZeroTier Securely
+
+### Overall Recommendations
+
+*TL;DR: same as anything else: defense in depth defense in depth defense in depth.*
+
+We encourage our users to treat private ZeroTier networks as being rougly equivalent in security to WPA2-enterprise securied WiFi or on-premise wired Ethernet. (Public networks on the other hand are open by design.) That means they're networks with perimeters, but like all networks the compromise of any participating device or network controller allows an attacker to breach this perimeter.
+
+**Never trust the network.** Many modern security professionals discourage reliance on network perimeters as major components in any security strategy, and we strongly agree regardless of whether your network is physical or virtual.
+
+As part of a defense in depth approach **we specifically encourage the use of other secure protocols and authentication systems over ZeroTier networks**. While the use of secure encrypted protocols like SSH and SSL over ZeroTier adds a bit more overhead, it greatly reduces the chance of total compromise.
+
+Imagine that the per-day probability of a major "0-day" security flaw in ZeroTier and OpenSSH are both roughly 0.001 or one per thousand days. Using both at the same time gives you a cumulative 0-day risk of roughly 0.000001 or one per one million days.
+
+Those are made-up numbers. In reality these probabilities can't be known ahead of time. History shows that a 0-day could be found in anything tomorrow, next week, or never. But layers of security give you an overall posture that is the product -- more than the sum -- of its parts. That's how defense in depth works.
+
+### ZeroTier Specifics
+
+#### Protect Your Identity
+
+Each ZeroTier device has an identity. The secret portion of this identity is stored in a file called "identity.secret." *Protect this file.* If it's stolen your device's identity (as represented by its 10-digit ZeroTier address) can easily be stolen or impersonated and your traffic can be decrypted or man-in-the-middle'd.
+
+#### Protect Your Controller
+
+The second major component of ZeroTier network security is the network controller. It's responsible for issuing certificates and configuration information to all network members. That makes it a certificate authority. Compromise of the controller allows an attacker to join or disrupt any network the controller controls. It does *not*, however, allow an attacker to decrypt peer to peer unicast traffic.
+
+If you are using our controller-as-a-service at [my.zerotier.com](https://my.zerotier.com), you are delegating this responsibility to us.
+
+## Security Priorities
+
+These are our security "must-haves." If the system fails in any of these objectives it is broken.
+
+* ZeroTier must be secure against remote vulnerabilities. This includes things like unauthorized remote control, remote penetration of the device using ZeroTier as a vector, or remote injection of malware.
+
+* The content (but not meta-data) of communication must be secure against eavesdropping on the wire by any known means. (We can't warrant against secret vulnerabilities against ciphers, etc., or anything else we don't know about.)
+
+* Communication must be secure against man-in-the-middle attacks and remote device impersonation.
+
+## Security Non-Priorities
+
+There are a few aspects of security we knowingly do not address, since doing so would be beyond scope or would conflict too greatly with other priorities.
+
+* ZeroTier makes no effort to conceal communication meta-data such as source and destination addresses and the amount of information transferred between peers. To do this more or less requires onion routing or other "heavy" approaches to anonymity, and this is beyond scope.
+
+* ZeroTier does not implement complex certificate chains, X.509, or other feature-rich (some would say feature-laden) cryptographic stuff. We only implement the crypto we need to get the job done.
+
+* We don't take extraordinary measures to preserve security under conditions in which an endpoint device has been penetrated by other means (e.g. "rooted" by third party malware) or physicall compromised. If someone steals your keys they've stolen your keys, and if they've "pwned" your device they can easily eavesdrop on everything directly.
+
+## Insecurities and Areas for Improvement
+
+The only perfectly secure system is one that is off. All real world systems have potential security weaknesses. If possible, we like to know what these are and acknowledge their existence.
+
+In some cases we plan to improve these. In other cases we have deliberately decided to "punt" on them in favor of some other priority (see philosophy). We may or may not revisit this decision in the future.
+
+* We don't implement forward secrecy / ephemeral keys. A [discussion of this can be found at the closed GitHub issue for this feature](https://github.com/zerotier/ZeroTierOne/issues/204). In short: we've decided to "punt" on this feature because it introduces complexity and state negotiation. One of the design goals of ZeroTier is "reliability convergence" -- the reliability of ZeroTier virtual networks should rapidly converge with that of the underlying physical wire. Any state that must be negotiated prior to communication multiplies the probability of delay or failure due to packet loss. We *may* revisit this decision at a later date.
+
+## Secure Coding Practices
+
+The first line of defense employed against remote vulnerabilities and other major security flaws is the use of secure coding practices. These are, in no particular order:
+
+* All parsing of remote messages is performed via higher level safe bounds-checked data structures and interfaces. See node/Buffer.hpp for one of the core elements of this.
+
+* C++ exceptions are used to ensure that any unhandled failure or error condition (such as a bounds checking violation) results in the safe and complete termination of message processing. Invalid messages are dropped and ignored.
+
+* Minimalism is a secure coding practice. There is an exponential relationship between complexity and the probability of bugs, and complex designs are much harder to audit and reason about.
+
+* Our build scripts try to enable any OS and compiler level security features such as ASLR and "stack canaries" on non-debug builds.
+
+## Cryptographic Security Practices
+
+* We use [boring crypto](https://cr.yp.to/talks/2015.10.05/slides-djb-20151005-a4.pdf). A single symmetric algorithm (Salsa20/12), a single asymmetric algorithm (Curve25519 ECDH-256), and a single MAC (Poly1305). The way these algorithms are used is identical to how they're used in the NaCl reference implementation. The protocol supports selection of alternative algorithms but only for "future proofing" in the case that a serious flaw is discovered in any of these. Avoiding algorithm bloat and cryptographic state negotiation helps guard against down-grade, "oracle," and other protocol level attacks.
+
+* Authenticated encryption is employed with authentication being performed prior to any other operations on received messages. See also: [the cryptographic doom principle](https://moxie.org/blog/the-cryptographic-doom-principle/).
+
+* "Never branch on anything secret" -- deterministic-time comparisons and other operations are used in cryptographic operations. See Utils::secureEq() in node/Utils.hpp.
+
+* OS-derived crypographic random numbers (/dev/urandom or Windows CryptGenRandom) are further randomized using encryption by a secondary key with a secondary source of entropy to guard against CSPRNG bugs. Such OS-level CSPRNG bugs have been found in the past. See Utils::getSecureRandom() in node/Utils.hpp.
+
diff --git a/attic/decrypt b/attic/decrypt
deleted file mode 100755
index 5af3acd44..000000000
--- a/attic/decrypt
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/bash
-
-export PATH=/bin:/usr/bin
-
-if [ ! -e /usr/bin/openssl ]; then
- echo $0: requires /usr/bin/openssl, please install openssl tools
- exit 1
-fi
-
-if [ "$#" -lt 1 ]; then
- echo $0: Usage: $0 '' '[output]'
- exit 1
-fi
-
-if [ ! -r "$1" ]; then
- echo $0: $1 does not exist or is not readable.
- exit 1
-fi
-
-outpath=`echo "$1" | sed 's/[.]aes$//'`
-if [ "$#" -ge 2 ]; then
- outpath="$2"
-fi
-
-if [ -f "$outpath" ]; then
- echo $0: $outpath already exists, delete or rename first.
- exit 1
-fi
-
-openssl aes-256-cbc -d -salt -in "$1" -out "$outpath"
-
-echo $0: wrote "$outpath"
diff --git a/attic/encrypt b/attic/encrypt
deleted file mode 100755
index 243a46d79..000000000
--- a/attic/encrypt
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/bash
-
-export PATH=/bin:/usr/bin
-
-if [ ! -e /usr/bin/openssl ]; then
- echo $0: requires /usr/bin/openssl, please install openssl tools
- exit 1
-fi
-
-if [ "$#" -lt 1 ]; then
- echo $0: Usage: $0 '' '[output]'
- exit 1
-fi
-
-if [ ! -r "$1" ]; then
- echo $0: $1 does not exist or is not readable.
- exit 1
-fi
-
-outpath="$1.aes"
-if [ "$#" -ge 2 ]; then
- outpath="$2"
-fi
-
-if [ -f "$outpath" ]; then
- echo $0: $outpath already exists, delete or rename first.
- exit 1
-fi
-
-openssl aes-256-cbc -salt -in "$1" -out "$outpath"
-
-echo $0: wrote "$outpath"
diff --git a/ext/installfiles/linux/buildinstaller.sh b/attic/old-linux-installer/buildinstaller.sh
similarity index 95%
rename from ext/installfiles/linux/buildinstaller.sh
rename to attic/old-linux-installer/buildinstaller.sh
index 1f6f89355..21f2f73ed 100755
--- a/ext/installfiles/linux/buildinstaller.sh
+++ b/attic/old-linux-installer/buildinstaller.sh
@@ -91,14 +91,14 @@ case "$system" in
rm -f "${debfolder}/postinst" "${debfolder}/prerm"
echo '#!/bin/bash' >${debfolder}/postinst
- echo "/var/lib/zerotier-one/updates.d/${targ}" >>${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' >>${debfolder}/prerm
+ echo ' /var/lib/zerotier-one/uninstall.sh >>/dev/null 2>&1' >>${debfolder}/prerm
echo 'fi' >>${debfolder}/prerm
chmod a+x ${debfolder}/prerm
diff --git a/ext/installfiles/linux/install.tmpl.sh b/attic/old-linux-installer/install.tmpl.sh
similarity index 99%
rename from ext/installfiles/linux/install.tmpl.sh
rename to attic/old-linux-installer/install.tmpl.sh
index 24425cbb0..2d18d24ce 100644
--- a/ext/installfiles/linux/install.tmpl.sh
+++ b/attic/old-linux-installer/install.tmpl.sh
@@ -115,7 +115,7 @@ if [ -n "$SYSTEMDUNITDIR" -a -d "$SYSTEMDUNITDIR" ]; then
cp -f /tmp/systemd_zerotier-one.service "$SYSTEMDUNITDIR/zerotier-one.service"
chown 0 "$SYSTEMDUNITDIR/zerotier-one.service"
chgrp 0 "$SYSTEMDUNITDIR/zerotier-one.service"
- chmod 0755 "$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
diff --git a/ext/installfiles/linux/uninstall.sh b/attic/old-linux-installer/uninstall.sh
similarity index 98%
rename from ext/installfiles/linux/uninstall.sh
rename to attic/old-linux-installer/uninstall.sh
index bfc7ee6b5..d9495a18f 100755
--- a/ext/installfiles/linux/uninstall.sh
+++ b/attic/old-linux-installer/uninstall.sh
@@ -59,7 +59,7 @@ 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
+ 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..."
diff --git a/attic/rtbl/BSDRoutingTable.cpp b/attic/rtbl/BSDRoutingTable.cpp
deleted file mode 100644
index 6d44c3ecd..000000000
--- a/attic/rtbl/BSDRoutingTable.cpp
+++ /dev/null
@@ -1,331 +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 .
- *
- * --
- *
- * 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
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-
-#include "../node/Constants.hpp"
-#include "BSDRoutingTable.hpp"
-
-// All I wanted was the bloody rounting table. I didn't expect the Spanish inquisition.
-
-#define ZT_BSD_ROUTE_CMD "/sbin/route"
-
-namespace ZeroTier {
-
-BSDRoutingTable::BSDRoutingTable()
-{
-}
-
-BSDRoutingTable::~BSDRoutingTable()
-{
-}
-
-std::vector BSDRoutingTable::get(bool includeLinkLocal,bool includeLoopback) const
-{
- std::vector entries;
- int mib[6];
- size_t needed;
-
- mib[0] = CTL_NET;
- mib[1] = PF_ROUTE;
- mib[2] = 0;
- mib[3] = 0;
- mib[4] = NET_RT_DUMP;
- mib[5] = 0;
- if (!sysctl(mib,6,NULL,&needed,NULL,0)) {
- if (needed <= 0)
- return entries;
-
- char *buf = (char *)::malloc(needed);
- if (buf) {
- if (!sysctl(mib,6,buf,&needed,NULL,0)) {
- struct rt_msghdr *rtm;
- for(char *next=buf,*end=buf+needed;nextrtm_msglen;
-
- if (((rtm->rtm_flags & RTF_LLINFO) == 0)&&((rtm->rtm_flags & RTF_HOST) == 0)&&((rtm->rtm_flags & RTF_UP) != 0)&&((rtm->rtm_flags & RTF_MULTICAST) == 0)) {
- RoutingTable::Entry e;
- e.deviceIndex = -9999; // unset
-
- int which = 0;
- while (saptr < saend) {
- struct sockaddr *sa = (struct sockaddr *)saptr;
- unsigned int salen = sa->sa_len;
- if (!salen)
- break;
-
- // Skip missing fields in rtm_addrs bit field
- while ((rtm->rtm_addrs & 1) == 0) {
- rtm->rtm_addrs >>= 1;
- ++which;
- if (which > 6)
- break;
- }
- if (which > 6)
- break;
-
- rtm->rtm_addrs >>= 1;
- switch(which++) {
- case 0:
- //printf("RTA_DST\n");
- if (sa->sa_family == AF_INET6) {
- struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
- // Nobody expects the Spanish inquisition!
- if ((sin6->sin6_addr.s6_addr[0] == 0xfe)&&((sin6->sin6_addr.s6_addr[1] & 0xc0) == 0x80)) {
- // Our chief weapon is... in-band signaling!
- // Seriously who in the living fuck thought this was a good idea and
- // then had the sadistic idea to not document it anywhere? Of course it's
- // not like there is any documentation on BSD sysctls anyway.
- unsigned int interfaceIndex = ((((unsigned int)sin6->sin6_addr.s6_addr[2]) << 8) & 0xff) | (((unsigned int)sin6->sin6_addr.s6_addr[3]) & 0xff);
- sin6->sin6_addr.s6_addr[2] = 0;
- sin6->sin6_addr.s6_addr[3] = 0;
- if (!sin6->sin6_scope_id)
- sin6->sin6_scope_id = interfaceIndex;
- }
- }
- e.destination.set(sa);
- break;
- case 1:
- //printf("RTA_GATEWAY\n");
- switch(sa->sa_family) {
- case AF_LINK:
- e.deviceIndex = (int)((const struct sockaddr_dl *)sa)->sdl_index;
- break;
- case AF_INET:
- case AF_INET6:
- e.gateway.set(sa);
- break;
- }
- break;
- case 2: {
- if (e.destination.isV6()) {
- salen = sizeof(struct sockaddr_in6); // Confess!
- unsigned int bits = 0;
- for(int i=0;i<16;++i) {
- unsigned char c = (unsigned char)((const struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[i];
- if (c == 0xff)
- bits += 8;
- else break;
- /* must they be multiples of 8? Most of the BSD source I can find says yes..?
- else {
- while ((c & 0x80) == 0x80) {
- ++bits;
- c <<= 1;
- }
- break;
- }
- */
- }
- e.destination.setPort(bits);
- } else {
- salen = sizeof(struct sockaddr_in); // Confess!
- e.destination.setPort((unsigned int)Utils::countBits((uint32_t)((const struct sockaddr_in *)sa)->sin_addr.s_addr));
- }
- //printf("RTA_NETMASK\n");
- } break;
- /*
- case 3:
- //printf("RTA_GENMASK\n");
- break;
- case 4:
- //printf("RTA_IFP\n");
- break;
- case 5:
- //printf("RTA_IFA\n");
- break;
- case 6:
- //printf("RTA_AUTHOR\n");
- break;
- */
- }
-
- saptr += salen;
- }
-
- e.metric = (int)rtm->rtm_rmx.rmx_hopcount;
- if (e.metric < 0)
- e.metric = 0;
-
- if (((includeLinkLocal)||(!e.destination.isLinkLocal()))&&((includeLoopback)||((!e.destination.isLoopback())&&(!e.gateway.isLoopback()))))
- entries.push_back(e);
- }
-
- next = saend;
- }
- }
-
- ::free(buf);
- }
- }
-
- for(std::vector::iterator e1(entries.begin());e1!=entries.end();++e1) {
- if ((!e1->device[0])&&(e1->deviceIndex >= 0))
- if_indextoname(e1->deviceIndex,e1->device);
- }
- for(std::vector::iterator e1(entries.begin());e1!=entries.end();++e1) {
- if ((!e1->device[0])&&(e1->gateway)) {
- int bestMetric = 9999999;
- for(std::vector::iterator e2(entries.begin());e2!=entries.end();++e2) {
- if ((e1->gateway.within(e2->destination))&&(e2->metric <= bestMetric)) {
- bestMetric = e2->metric;
- Utils::scopy(e1->device,sizeof(e1->device),e2->device);
- }
- }
- }
- }
-
- std::sort(entries.begin(),entries.end());
-
- return entries;
-}
-
-RoutingTable::Entry BSDRoutingTable::set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric)
-{
- if ((!gateway)&&((!device)||(!device[0])))
- return RoutingTable::Entry();
-
- std::vector rtab(get(true,true));
-
- for(std::vector::iterator e(rtab.begin());e!=rtab.end();++e) {
- if (e->destination == destination) {
- if (((!device)||(!device[0]))||(!strcmp(device,e->device))) {
- long p = (long)fork();
- if (p > 0) {
- int exitcode = -1;
- ::waitpid(p,&exitcode,0);
- } else if (p == 0) {
- ::close(STDOUT_FILENO);
- ::close(STDERR_FILENO);
- ::execl(ZT_BSD_ROUTE_CMD,ZT_BSD_ROUTE_CMD,"delete",(destination.isV6() ? "-inet6" : "-inet"),destination.toString().c_str(),(const char *)0);
- ::_exit(-1);
- }
- }
- }
- }
-
- if (metric < 0)
- return RoutingTable::Entry();
-
- {
- char hcstr[64];
- Utils::snprintf(hcstr,sizeof(hcstr),"%d",metric);
- long p = (long)fork();
- if (p > 0) {
- int exitcode = -1;
- ::waitpid(p,&exitcode,0);
- } else if (p == 0) {
- ::close(STDOUT_FILENO);
- ::close(STDERR_FILENO);
- if (gateway) {
- ::execl(ZT_BSD_ROUTE_CMD,ZT_BSD_ROUTE_CMD,"add",(destination.isV6() ? "-inet6" : "-inet"),destination.toString().c_str(),gateway.toIpString().c_str(),"-hopcount",hcstr,(const char *)0);
- } else if ((device)&&(device[0])) {
- ::execl(ZT_BSD_ROUTE_CMD,ZT_BSD_ROUTE_CMD,"add",(destination.isV6() ? "-inet6" : "-inet"),destination.toString().c_str(),"-interface",device,"-hopcount",hcstr,(const char *)0);
- }
- ::_exit(-1);
- }
- }
-
- rtab = get(true,true);
- std::vector::iterator bestEntry(rtab.end());
- for(std::vector::iterator e(rtab.begin());e!=rtab.end();++e) {
- if ((e->destination == destination)&&(e->gateway.ipsEqual(gateway))) {
- if ((device)&&(device[0])) {
- if (!strcmp(device,e->device)) {
- if (metric == e->metric)
- bestEntry = e;
- }
- }
- if (bestEntry == rtab.end())
- bestEntry = e;
- }
- }
- if (bestEntry != rtab.end())
- return *bestEntry;
-
- return RoutingTable::Entry();
-}
-
-} // namespace ZeroTier
-
-// Enable and build to test routing table interface
-#if 0
-using namespace ZeroTier;
-int main(int argc,char **argv)
-{
- BSDRoutingTable rt;
-
- printf(" \n");
- std::vector ents(rt.get());
- for(std::vector::iterator e(ents.begin());e!=ents.end();++e)
- printf("%s\n",e->toString().c_str());
- printf("\n");
-
- printf("adding 1.1.1.0 and 2.2.2.0...\n");
- rt.set(InetAddress("1.1.1.0",24),InetAddress("1.2.3.4",0),(const char *)0,1);
- rt.set(InetAddress("2.2.2.0",24),InetAddress(),"en0",1);
- printf("\n");
-
- printf(" \n");
- ents = rt.get();
- for(std::vector::iterator e(ents.begin());e!=ents.end();++e)
- printf("%s\n",e->toString().c_str());
- printf("\n");
-
- printf("deleting 1.1.1.0 and 2.2.2.0...\n");
- rt.set(InetAddress("1.1.1.0",24),InetAddress("1.2.3.4",0),(const char *)0,-1);
- rt.set(InetAddress("2.2.2.0",24),InetAddress(),"en0",-1);
- printf("\n");
-
- printf(" \n");
- ents = rt.get();
- for(std::vector::iterator e(ents.begin());e!=ents.end();++e)
- printf("%s\n",e->toString().c_str());
- printf("\n");
-
- return 0;
-}
-#endif
diff --git a/attic/rtbl/BSDRoutingTable.hpp b/attic/rtbl/BSDRoutingTable.hpp
deleted file mode 100644
index 97969666a..000000000
--- a/attic/rtbl/BSDRoutingTable.hpp
+++ /dev/null
@@ -1,51 +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 .
- *
- * --
- *
- * 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_BSDROUTINGTABLE_HPP
-#define ZT_BSDROUTINGTABLE_HPP
-
-#include "../node/RoutingTable.hpp"
-
-namespace ZeroTier {
-
-/**
- * Routing table interface for BSD with sysctl() and BSD /sbin/route
- *
- * Has currently only been tested on OSX/Darwin.
- */
-class BSDRoutingTable : public RoutingTable
-{
-public:
- BSDRoutingTable();
- virtual ~BSDRoutingTable();
- virtual std::vector get(bool includeLinkLocal = false,bool includeLoopback = false) const;
- virtual RoutingTable::Entry set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric);
-};
-
-} // namespace ZeroTier
-
-#endif
diff --git a/attic/rtbl/LinuxRoutingTable.cpp b/attic/rtbl/LinuxRoutingTable.cpp
deleted file mode 100644
index 581054e26..000000000
--- a/attic/rtbl/LinuxRoutingTable.cpp
+++ /dev/null
@@ -1,235 +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 .
- *
- * --
- *
- * 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
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-
-#include "../node/Constants.hpp"
-#include "../node/Utils.hpp"
-#include "LinuxRoutingTable.hpp"
-
-#define ZT_LINUX_IP_COMMAND "/sbin/ip"
-
-namespace ZeroTier {
-
-LinuxRoutingTable::LinuxRoutingTable()
-{
-}
-
-LinuxRoutingTable::~LinuxRoutingTable()
-{
-}
-
-std::vector LinuxRoutingTable::get(bool includeLinkLocal,bool includeLoopback) const
-{
- char buf[131072];
- char *stmp,*stmp2;
- std::vector entries;
-
- {
- int fd = ::open("/proc/net/route",O_RDONLY);
- if (fd <= 0)
- buf[0] = (char)0;
- else {
- int n = (int)::read(fd,buf,sizeof(buf) - 1);
- ::close(fd);
- if (n < 0) n = 0;
- buf[n] = (char)0;
- }
- }
-
- int lineno = 0;
- for(char *line=Utils::stok(buf,"\r\n",&stmp);(line);line=Utils::stok((char *)0,"\r\n",&stmp)) {
- if (lineno == 0) {
- ++lineno;
- continue; // skip header
- }
-
- char *iface = (char *)0;
- uint32_t destination = 0;
- uint32_t gateway = 0;
- int metric = 0;
- uint32_t mask = 0;
-
- int fno = 0;
- for(char *f=Utils::stok(line,"\t \r\n",&stmp2);(f);f=Utils::stok((char *)0,"\t \r\n",&stmp2)) {
- switch(fno) {
- case 0: iface = f; break;
- case 1: destination = (uint32_t)Utils::hexStrToULong(f); break;
- case 2: gateway = (uint32_t)Utils::hexStrToULong(f); break;
- case 6: metric = (int)Utils::strToInt(f); break;
- case 7: mask = (uint32_t)Utils::hexStrToULong(f); break;
- }
- ++fno;
- }
-
- if ((iface)&&(destination)) {
- RoutingTable::Entry e;
- if (destination)
- e.destination.set(&destination,4,Utils::countBits(mask));
- e.gateway.set(&gateway,4,0);
- e.deviceIndex = 0; // not used on Linux
- e.metric = metric;
- Utils::scopy(e.device,sizeof(e.device),iface);
- if ((e.destination)&&((includeLinkLocal)||(!e.destination.isLinkLocal()))&&((includeLoopback)||((!e.destination.isLoopback())&&(!e.gateway.isLoopback())&&(strcmp(iface,"lo")))))
- entries.push_back(e);
- }
-
- ++lineno;
- }
-
- {
- int fd = ::open("/proc/net/ipv6_route",O_RDONLY);
- if (fd <= 0)
- buf[0] = (char)0;
- else {
- int n = (int)::read(fd,buf,sizeof(buf) - 1);
- ::close(fd);
- if (n < 0) n = 0;
- buf[n] = (char)0;
- }
- }
-
- for(char *line=Utils::stok(buf,"\r\n",&stmp);(line);line=Utils::stok((char *)0,"\r\n",&stmp)) {
- char *destination = (char *)0;
- unsigned int destPrefixLen = 0;
- char *gateway = (char *)0; // next hop in ipv6 terminology
- int metric = 0;
- char *device = (char *)0;
-
- int fno = 0;
- for(char *f=Utils::stok(line,"\t \r\n",&stmp2);(f);f=Utils::stok((char *)0,"\t \r\n",&stmp2)) {
- switch(fno) {
- case 0: destination = f; break;
- case 1: destPrefixLen = (unsigned int)Utils::hexStrToULong(f); break;
- case 4: gateway = f; break;
- case 5: metric = (int)Utils::hexStrToLong(f); break;
- case 9: device = f; break;
- }
- ++fno;
- }
-
- if ((device)&&(destination)) {
- unsigned char tmp[16];
- RoutingTable::Entry e;
- Utils::unhex(destination,tmp,16);
- if ((!Utils::isZero(tmp,16))&&(tmp[0] != 0xff))
- e.destination.set(tmp,16,destPrefixLen);
- Utils::unhex(gateway,tmp,16);
- e.gateway.set(tmp,16,0);
- e.deviceIndex = 0; // not used on Linux
- e.metric = metric;
- Utils::scopy(e.device,sizeof(e.device),device);
- if ((e.destination)&&((includeLinkLocal)||(!e.destination.isLinkLocal()))&&((includeLoopback)||((!e.destination.isLoopback())&&(!e.gateway.isLoopback())&&(strcmp(device,"lo")))))
- entries.push_back(e);
- }
- }
-
- std::sort(entries.begin(),entries.end());
- return entries;
-}
-
-RoutingTable::Entry LinuxRoutingTable::set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric)
-{
- char metstr[128];
-
- if ((!gateway)&&((!device)||(!device[0])))
- return RoutingTable::Entry();
-
- Utils::snprintf(metstr,sizeof(metstr),"%d",metric);
-
- if (metric < 0) {
- long pid = (long)vfork();
- if (pid == 0) {
- if (gateway) {
- if ((device)&&(device[0])) {
- ::execl(ZT_LINUX_IP_COMMAND,ZT_LINUX_IP_COMMAND,"route","del",destination.toString().c_str(),"via",gateway.toIpString().c_str(),"dev",device,(const char *)0);
- } else {
- ::execl(ZT_LINUX_IP_COMMAND,ZT_LINUX_IP_COMMAND,"route","del",destination.toString().c_str(),"via",gateway.toIpString().c_str(),(const char *)0);
- }
- } else {
- ::execl(ZT_LINUX_IP_COMMAND,ZT_LINUX_IP_COMMAND,"route","del",destination.toString().c_str(),"dev",device,(const char *)0);
- }
- ::_exit(-1);
- } else if (pid > 0) {
- int exitcode = -1;
- ::waitpid(pid,&exitcode,0);
- }
- } else {
- long pid = (long)vfork();
- if (pid == 0) {
- if (gateway) {
- if ((device)&&(device[0])) {
- ::execl(ZT_LINUX_IP_COMMAND,ZT_LINUX_IP_COMMAND,"route","replace",destination.toString().c_str(),"metric",metstr,"via",gateway.toIpString().c_str(),"dev",device,(const char *)0);
- } else {
- ::execl(ZT_LINUX_IP_COMMAND,ZT_LINUX_IP_COMMAND,"route","replace",destination.toString().c_str(),"metric",metstr,"via",gateway.toIpString().c_str(),(const char *)0);
- }
- } else {
- ::execl(ZT_LINUX_IP_COMMAND,ZT_LINUX_IP_COMMAND,"route","replace",destination.toString().c_str(),"metric",metstr,"dev",device,(const char *)0);
- }
- ::_exit(-1);
- } else if (pid > 0) {
- int exitcode = -1;
- ::waitpid(pid,&exitcode,0);
- }
- }
-
- std::vector rtab(get(true,true));
- std::vector::iterator bestEntry(rtab.end());
- for(std::vector::iterator e(rtab.begin());e!=rtab.end();++e) {
- if ((e->destination == destination)&&(e->gateway.ipsEqual(gateway))) {
- if ((device)&&(device[0])) {
- if (!strcmp(device,e->device)) {
- if (metric == e->metric)
- bestEntry = e;
- }
- }
- if (bestEntry == rtab.end())
- bestEntry = e;
- }
- }
- if (bestEntry != rtab.end())
- return *bestEntry;
-
- return RoutingTable::Entry();
-}
-
-} // namespace ZeroTier
diff --git a/attic/rtbl/LinuxRoutingTable.hpp b/attic/rtbl/LinuxRoutingTable.hpp
deleted file mode 100644
index 808ec7eab..000000000
--- a/attic/rtbl/LinuxRoutingTable.hpp
+++ /dev/null
@@ -1,49 +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 .
- *
- * --
- *
- * 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_LINUXROUTINGTABLE_HPP
-#define ZT_LINUXROUTINGTABLE_HPP
-
-#include "../node/RoutingTable.hpp"
-
-namespace ZeroTier {
-
-/**
- * Routing table interface via /proc/net/route, /proc/net/ipv6_route, and /sbin/route command
- */
-class LinuxRoutingTable : public RoutingTable
-{
-public:
- LinuxRoutingTable();
- virtual ~LinuxRoutingTable();
- virtual std::vector get(bool includeLinkLocal = false,bool includeLoopback = false) const;
- virtual RoutingTable::Entry set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric);
-};
-
-} // namespace ZeroTier
-
-#endif
diff --git a/attic/rtbl/RoutingTable.cpp b/attic/rtbl/RoutingTable.cpp
deleted file mode 100644
index bae4bea90..000000000
--- a/attic/rtbl/RoutingTable.cpp
+++ /dev/null
@@ -1,77 +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 .
- *
- * --
- *
- * 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
-#include
-#include
-#include
-
-#include "Constants.hpp"
-#include "RoutingTable.hpp"
-#include "Utils.hpp"
-
-namespace ZeroTier {
-
-std::string RoutingTable::Entry::toString() const
-{
- char tmp[1024];
- Utils::snprintf(tmp,sizeof(tmp),"%s %s %s %d",destination.toString().c_str(),((gateway) ? gateway.toIpString().c_str() : ""),device,metric);
- return std::string(tmp);
-}
-
-bool RoutingTable::Entry::operator==(const Entry &re) const
-{
- return ((destination == re.destination)&&(gateway == re.gateway)&&(strcmp(device,re.device) == 0)&&(metric == re.metric));
-}
-
-bool RoutingTable::Entry::operator<(const Entry &re) const
-{
- if (destination < re.destination)
- return true;
- else if (destination == re.destination) {
- if (gateway < re.gateway)
- return true;
- else if (gateway == re.gateway) {
- int tmp = (int)::strcmp(device,re.device);
- if (tmp < 0)
- return true;
- else if (tmp == 0)
- return (metric < re.metric);
- }
- }
- return false;
-}
-
-RoutingTable::RoutingTable()
-{
-}
-
-RoutingTable::~RoutingTable()
-{
-}
-
-} // namespace ZeroTier
diff --git a/attic/rtbl/RoutingTable.hpp b/attic/rtbl/RoutingTable.hpp
deleted file mode 100644
index e1c98984b..000000000
--- a/attic/rtbl/RoutingTable.hpp
+++ /dev/null
@@ -1,122 +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 .
- *
- * --
- *
- * 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_ROUTINGTABLE_HPP
-#define ZT_ROUTINGTABLE_HPP
-
-#include
-#include
-
-#include "InetAddress.hpp"
-#include "NonCopyable.hpp"
-
-namespace ZeroTier {
-
-/**
- * Base class for OS routing table interfaces
- */
-class RoutingTable : NonCopyable
-{
-public:
- class Entry
- {
- public:
- Entry() throw() { device[0] = (char)0; }
-
- /**
- * Destination IP and netmask bits (CIDR format)
- */
- InetAddress destination;
-
- /**
- * Gateway or null address if direct link-level route, netmask/port part of InetAddress not used
- */
- InetAddress gateway;
-
- /**
- * System device index or ID (not included in comparison operators, may not be set on all platforms)
- */
- int deviceIndex;
-
- /**
- * Metric or hop count -- higher = lower routing priority
- */
- int metric;
-
- /**
- * System device name
- */
- char device[128];
-
- /**
- * @return Human-readable representation of this route
- */
- std::string toString() const;
-
- /**
- * @return True if at least one required field is present (object is not null)
- */
- inline operator bool() const { return ((destination)||(gateway)||(device[0])); }
-
- bool operator==(const Entry &re) const;
- inline bool operator!=(const Entry &re) const { return (!(*this == re)); }
- bool operator<(const Entry &re) const;
- inline bool operator>(const Entry &re) const { return (re < *this); }
- inline bool operator<=(const Entry &re) const { return (!(re < *this)); }
- inline bool operator>=(const Entry &re) const { return (!(*this < re)); }
- };
-
- RoutingTable();
- virtual ~RoutingTable();
-
- /**
- * Get routing table
- *
- * @param includeLinkLocal If true, include link-local address routes (default: false)
- * @param includeLoopback Include loopback (default: false)
- * @return Sorted routing table entries
- */
- virtual std::vector get(bool includeLinkLocal = false,bool includeLoopback = false) const = 0;
-
- /**
- * Add or update a routing table entry
- *
- * If there is no change, the existing entry is returned. Use a value of -1
- * for metric to delete a route.
- *
- * @param destination Destination IP/netmask
- * @param gateway Gateway IP (netmask/port part unused) or NULL/zero for device-level route
- * @param device Device name (can be null for gateway routes)
- * @param metric Route metric or hop count (higher = lower priority) or negative to delete
- * @return Entry or null entry on failure (or delete)
- */
- virtual RoutingTable::Entry set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric) = 0;
-};
-
-} // namespace ZeroTier
-
-#endif
diff --git a/attic/rtbl/TestRoutingTable.cpp b/attic/rtbl/TestRoutingTable.cpp
deleted file mode 100644
index fd61b3140..000000000
--- a/attic/rtbl/TestRoutingTable.cpp
+++ /dev/null
@@ -1,50 +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 .
- *
- * --
- *
- * 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 "TestRoutingTable.hpp"
-
-namespace ZeroTier {
-
-TestRoutingTable::TestRoutingTable()
-{
-}
-
-TestRoutingTable::~TestRoutingTable()
-{
-}
-
-std::vector TestRoutingTable::get(bool includeLinkLocal,bool includeLoopback) const
-{
- return std::vector();
-}
-
-RoutingTable::Entry TestRoutingTable::set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric)
-{
- return RoutingTable::Entry();
-}
-
-} // namespace ZeroTier
diff --git a/attic/rtbl/TestRoutingTable.hpp b/attic/rtbl/TestRoutingTable.hpp
deleted file mode 100644
index 69bd3d9fb..000000000
--- a/attic/rtbl/TestRoutingTable.hpp
+++ /dev/null
@@ -1,50 +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 .
- *
- * --
- *
- * 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_TESTROUTINGTABLE_HPP
-#define ZT_TESTROUTINGTABLE_HPP
-
-#include "../node/RoutingTable.hpp"
-
-namespace ZeroTier {
-
-/**
- * Dummy routing table -- right now this just does nothing
- */
-class TestRoutingTable : public RoutingTable
-{
-public:
- TestRoutingTable();
- virtual ~TestRoutingTable();
-
- virtual std::vector get(bool includeLinkLocal = false,bool includeLoopback = false) const;
- virtual RoutingTable::Entry set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric);
-};
-
-} // namespace ZeroTier
-
-#endif
diff --git a/attic/rtbl/WindowsRoutingTable.cpp b/attic/rtbl/WindowsRoutingTable.cpp
deleted file mode 100644
index 00674620f..000000000
--- a/attic/rtbl/WindowsRoutingTable.cpp
+++ /dev/null
@@ -1,178 +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 .
- *
- * --
- *
- * 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
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-
-#include "../node/Constants.hpp"
-#include "WindowsRoutingTable.hpp"
-
-namespace ZeroTier {
-
-static void _copyInetAddressToSockaddrInet(const InetAddress &a,SOCKADDR_INET &sinet)
-{
- memset(&sinet,0,sizeof(sinet));
- if (a.isV4()) {
- sinet.Ipv4.sin_addr.S_un.S_addr = *((const uint32_t *)a.rawIpData());
- sinet.Ipv4.sin_family = AF_INET;
- sinet.Ipv4.sin_port = htons(a.port());
- } else if (a.isV6()) {
- memcpy(sinet.Ipv6.sin6_addr.u.Byte,a.rawIpData(),16);
- sinet.Ipv6.sin6_family = AF_INET6;
- sinet.Ipv6.sin6_port = htons(a.port());
- }
-}
-
-WindowsRoutingTable::WindowsRoutingTable()
-{
-}
-
-WindowsRoutingTable::~WindowsRoutingTable()
-{
-}
-
-std::vector WindowsRoutingTable::get(bool includeLinkLocal,bool includeLoopback) const
-{
- std::vector entries;
- PMIB_IPFORWARD_TABLE2 rtbl = NULL;
-
- if (GetIpForwardTable2(AF_UNSPEC,&rtbl) != NO_ERROR)
- return entries;
- if (!rtbl)
- return entries;
-
- for(ULONG r=0;rNumEntries;++r) {
- RoutingTable::Entry e;
- switch(rtbl->Table[r].DestinationPrefix.Prefix.si_family) {
- case AF_INET:
- e.destination.set(&(rtbl->Table[r].DestinationPrefix.Prefix.Ipv4.sin_addr.S_un.S_addr),4,rtbl->Table[r].DestinationPrefix.PrefixLength);
- break;
- case AF_INET6:
- e.destination.set(rtbl->Table[r].DestinationPrefix.Prefix.Ipv6.sin6_addr.u.Byte,16,rtbl->Table[r].DestinationPrefix.PrefixLength);
- break;
- }
- switch(rtbl->Table[r].NextHop.si_family) {
- case AF_INET:
- e.gateway.set(&(rtbl->Table[r].NextHop.Ipv4.sin_addr.S_un.S_addr),4,0);
- break;
- case AF_INET6:
- e.gateway.set(rtbl->Table[r].NextHop.Ipv6.sin6_addr.u.Byte,16,0);
- break;
- }
- e.deviceIndex = (int)rtbl->Table[r].InterfaceIndex;
- e.metric = (int)rtbl->Table[r].Metric;
- ConvertInterfaceLuidToNameA(&(rtbl->Table[r].InterfaceLuid),e.device,sizeof(e.device));
- if ((e.destination)&&((includeLinkLocal)||(!e.destination.isLinkLocal()))&&((includeLoopback)||((!e.destination.isLoopback())&&(!e.gateway.isLoopback()))))
- entries.push_back(e);
- }
-
- FreeMibTable(rtbl);
- std::sort(entries.begin(),entries.end());
- return entries;
-}
-
-RoutingTable::Entry WindowsRoutingTable::set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric)
-{
- NET_LUID luid;
- luid.Value = 0;
- if (ConvertInterfaceNameToLuidA(device,&luid) != NO_ERROR)
- return RoutingTable::Entry();
-
- bool needCreate = true;
- PMIB_IPFORWARD_TABLE2 rtbl = NULL;
- if (GetIpForwardTable2(AF_UNSPEC,&rtbl) != NO_ERROR)
- return RoutingTable::Entry();
- if (!rtbl)
- return RoutingTable::Entry();
- for(ULONG r=0;rNumEntries;++r) {
- if (rtbl->Table[r].InterfaceLuid.Value == luid.Value) {
- InetAddress rdest;
- switch(rtbl->Table[r].DestinationPrefix.Prefix.si_family) {
- case AF_INET:
- rdest.set(&(rtbl->Table[r].DestinationPrefix.Prefix.Ipv4.sin_addr.S_un.S_addr),4,rtbl->Table[r].DestinationPrefix.PrefixLength);
- break;
- case AF_INET6:
- rdest.set(rtbl->Table[r].DestinationPrefix.Prefix.Ipv6.sin6_addr.u.Byte,16,rtbl->Table[r].DestinationPrefix.PrefixLength);
- break;
- }
- if (rdest == destination) {
- if (metric >= 0) {
- _copyInetAddressToSockaddrInet(gateway,rtbl->Table[r].NextHop);
- rtbl->Table[r].Metric = metric;
- SetIpForwardEntry2(&(rtbl->Table[r]));
- needCreate = false;
- } else {
- DeleteIpForwardEntry2(&(rtbl->Table[r]));
- FreeMibTable(rtbl);
- return RoutingTable::Entry();
- }
- }
- }
- }
- FreeMibTable(rtbl);
-
- if ((metric >= 0)&&(needCreate)) {
- MIB_IPFORWARD_ROW2 nr;
- InitializeIpForwardEntry(&nr);
- nr.InterfaceLuid.Value = luid.Value;
- _copyInetAddressToSockaddrInet(destination,nr.DestinationPrefix.Prefix);
- nr.DestinationPrefix.PrefixLength = destination.netmaskBits();
- _copyInetAddressToSockaddrInet(gateway,nr.NextHop);
- nr.Metric = metric;
- nr.Protocol = MIB_IPPROTO_NETMGMT;
- DWORD result = CreateIpForwardEntry2(&nr);
- if (result != NO_ERROR)
- return RoutingTable::Entry();
- }
-
- std::vector rtab(get(true,true));
- std::vector::iterator bestEntry(rtab.end());
- for(std::vector::iterator e(rtab.begin());e!=rtab.end();++e) {
- if ((e->destination == destination)&&(e->gateway.ipsEqual(gateway))) {
- if ((device)&&(device[0])) {
- if (!strcmp(device,e->device)) {
- if (metric == e->metric)
- bestEntry = e;
- }
- }
- if (bestEntry == rtab.end())
- bestEntry = e;
- }
- }
- if (bestEntry != rtab.end())
- return *bestEntry;
- return RoutingTable::Entry();
-}
-
-} // namespace ZeroTier
diff --git a/attic/rtbl/WindowsRoutingTable.hpp b/attic/rtbl/WindowsRoutingTable.hpp
deleted file mode 100644
index 491c3424d..000000000
--- a/attic/rtbl/WindowsRoutingTable.hpp
+++ /dev/null
@@ -1,49 +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 .
- *
- * --
- *
- * 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_WINDOWSROUTINGTABLE_HPP
-#define ZT_WINDOWSROUTINGTABLE_HPP
-
-#include "../node/RoutingTable.hpp"
-
-namespace ZeroTier {
-
-/**
- * Interface to Microsoft Windows (Vista or newer) routing table
- */
-class WindowsRoutingTable : public RoutingTable
-{
-public:
- WindowsRoutingTable();
- virtual ~WindowsRoutingTable();
- virtual std::vector get(bool includeLinkLocal = false,bool includeLoopback = false) const;
- virtual RoutingTable::Entry set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric);
-};
-
-} // namespace ZeroTier
-
-#endif
diff --git a/cli/README.md b/cli/README.md
new file mode 100644
index 000000000..dabbd3023
--- /dev/null
+++ b/cli/README.md
@@ -0,0 +1,6 @@
+ZeroTier Newer-Spiffier Command Line Interface
+======
+
+This will be the future home of our new unified CLI for ZeroTier One, controllers, and Central (my.zerotier.com etc.).
+
+IT IS NOT DONE AND DOES NOT WORK EVEN A LITTLE BIT. GO AWAY.
diff --git a/cli/zerotier.cpp b/cli/zerotier.cpp
new file mode 100644
index 000000000..f9eec5d08
--- /dev/null
+++ b/cli/zerotier.cpp
@@ -0,0 +1,335 @@
+/*
+ * 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 .
+ */
+
+// Note: unlike the rest of ZT's code base, this requires C++11 due to
+// the JSON library it uses and other things.
+
+#include
+#include
+#include
+#include
+
+#include "../node/Constants.hpp"
+#include "../version.h"
+#include "../osdep/OSUtils.hpp"
+#include "../ext/json/json.hpp"
+
+#ifdef __WINDOWS__
+#include
+#include
+#include
+#include
+#else
+#include
+#include
+#endif
+
+#include
+#include
+#include