Warning removal, Go work...

This commit is contained in:
Adam Ierymenko 2020-08-10 12:35:26 -07:00
parent f1b6cb2ace
commit f97e9e1f5d
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
14 changed files with 153 additions and 135 deletions

View file

@ -20,7 +20,7 @@ import (
"zerotier/pkg/zerotier"
)
func Cert(basePath, authToken string, args []string, jsonOutput bool) int {
func Cert(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool) int {
if len(args) < 1 {
Help()
return 1

View file

@ -13,7 +13,7 @@
package cli
func Controller(basePath, authToken string, args []string, jsonOutput bool) int {
func Controller(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool) int {
if len(args) < 1 {
Help()
return 1

View file

@ -39,12 +39,19 @@ Common Operations:
status Show node status and configuration
join [-options] <network> Join a virtual network
-a <token> Token to submit to controller
-c <identity | fingerprint> Controller identity or fingerprint
leave <network> Leave a virtual network
set [option] [value] - Get or set node configuration
port <port> Primary P2P port
secondaryport <port/0> Secondary P2P port (0 to disable)
blacklist cidr <IP/bits> <boolean> Toggle physical path blacklisting
blacklist if <prefix> <boolean> Toggle interface prefix blacklisting
portmap <boolean> Toggle use of uPnP or NAT-PMP
networks List VL2 virtual networks
peer list List VL1 peers
peer <address> [command] [option] - Peer management commands
show Show peer details (default)
try <endpoint> [...] Try peer at explicit endpoint
network list List VL2 networks
network <network> [command] [option] - Network management commands
show Show network details (default)
set [option] [value] - Get or set network options
@ -54,24 +61,17 @@ Common Operations:
globalroutes <boolean> Can global IP space routes be set?
defaultroute <boolean> Can default route be overridden?
peers List VL1 peers
peer <address> [command] [option] - Peer management commands
show Show peer details (default)
try <endpoint> [...] Try peer at explicit endpoint
set [option] [value] - Get or set node configuration
port <port> Primary P2P port
secondaryport <port/0> Secondary P2P port (0 to disable)
blacklist cidr <IP/bits> <boolean> Toggle physical path blacklisting
blacklist if <prefix> <boolean> Toggle interface prefix blacklisting
portmap <boolean> Toggle use of uPnP or NAT-PMP
join [-options] <network> Join a virtual network
-a <token> Token to submit to controller
-c <identity | fingerprint> Controller identity or fingerprint
leave <network> Leave a virtual network
Advanced Operations:
service Start node (seldom used from CLI)
controller <command> [option] - Local controller management commands
networks List networks run by local controller
list List networks run by local controller
new Create a new network
set <network> [setting] [value] Show or modify network settings
members <network> List members of a network
@ -92,8 +92,8 @@ Advanced Operations:
verify <identity> <locator> Verify locator signature
show <locator> Show contents of a locator
certs List certificates
cert <command> [args] - Certificate management
list List certificates in local node store
show [serial] List or show details of a certificate
newsid <secret out> Create a new subject unique ID
newcsr <subject> <secret> <csr out> Create a subject CSR

View file

@ -23,7 +23,9 @@ import (
"zerotier/pkg/zerotier"
)
func Join(basePath, authToken string, args []string) int {
func Join(basePath string, authTokenGenerator func() string, args []string) int {
authToken := authTokenGenerator()
joinOpts := flag.NewFlagSet("join", flag.ContinueOnError)
controllerAuthToken := joinOpts.String("a", "", "")
controllerFingerprint := joinOpts.String("c", "", "")

View file

@ -19,7 +19,9 @@ import (
"zerotier/pkg/zerotier"
)
func Leave(basePath, authToken string, args []string) int {
func Leave(basePath string, authTokenGenerator func() string, args []string) int {
authToken := authTokenGenerator()
if len(args) != 1 {
Help()
return 1

View file

@ -84,7 +84,9 @@ func showNetwork(nwids string, network *zerotier.APINetwork, jsonOutput bool) {
}
}
func Network(basePath, authToken string, args []string, jsonOutput bool) int {
func Network(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool) int {
authToken := authTokenGenerator()
if len(args) < 1 {
Help()
return 1

View file

@ -18,9 +18,9 @@ import (
"zerotier/pkg/zerotier"
)
func Networks(basePath, authToken string, args []string, jsonOutput bool) int {
func Networks(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool) int {
var networks []zerotier.APINetwork
apiGet(basePath, authToken, "/network", &networks)
apiGet(basePath, authTokenGenerator(), "/network", &networks)
if jsonOutput {
fmt.Println(jsonDump(networks))

View file

@ -13,7 +13,7 @@
package cli
func Peer(basePath, authToken string, args []string, jsonOutput bool) int {
func Peer(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool) int {
if len(args) < 1 {
Help()
return 1

View file

@ -20,9 +20,9 @@ import (
"zerotier/pkg/zerotier"
)
func Peers(basePath, authToken string, args []string, jsonOutput bool, rootsOnly bool) int {
func Peers(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool, rootsOnly bool) int {
var peers []zerotier.Peer
apiGet(basePath, authToken, "/peer", &peers)
apiGet(basePath, authTokenGenerator(), "/peer", &peers)
if rootsOnly {
roots := make([]zerotier.Peer, 0, len(peers))

View file

@ -13,6 +13,6 @@
package cli
func Set(basePath, authToken string, args []string) int {
func Set(basePath string, authTokenGenerator func() string, args []string) int {
return 0
}

View file

@ -18,9 +18,9 @@ import (
"zerotier/pkg/zerotier"
)
func Status(basePath, authToken string, args []string, jsonOutput bool) int {
func Status(basePath string, authTokenGenerator func() string, args []string, jsonOutput bool) int {
var status zerotier.APIStatus
apiGet(basePath, authToken, "/status", &status)
apiGet(basePath, authTokenGenerator(), "/status", &status)
if jsonOutput {
fmt.Println(jsonDump(&status))

View file

@ -27,12 +27,21 @@ import (
"zerotier/pkg/zerotier"
)
func authToken(basePath, tflag, tTflag string) string {
var authToken string
// authToken returns a function that reads the authorization token if needed.
// If the authorization token can't be read, the function terminates the program with a fatal error.
func authToken(basePath, tflag, tTflag string) func () string {
savedAuthToken := new(string)
return func() string {
authToken := *savedAuthToken
if len(authToken) > 0 {
return authToken
}
if len(tflag) > 0 {
at, err := ioutil.ReadFile(tflag)
if err != nil || len(at) == 0 {
fmt.Println("FATAL: unable to read local service API authorization token from " + tflag)
os.Exit(1)
return ""
}
authToken = string(at)
@ -64,6 +73,7 @@ func authToken(basePath, tflag, tTflag string) string {
for _, p := range authTokenPaths {
fmt.Println(" " + p)
}
os.Exit(1)
return ""
}
}
@ -71,21 +81,20 @@ func authToken(basePath, tflag, tTflag string) string {
authToken = strings.TrimSpace(authToken)
if len(authToken) == 0 {
fmt.Println("FATAL: unable to read API authorization token from command line or any filesystem location.")
os.Exit(1)
return ""
}
*savedAuthToken = authToken
return authToken
}
}
func main() {
// Reduce Go's thread and memory footprint. This would slow things down if the Go code
// were doing a lot, but it's not. It just manages the core and is not directly involved
// in pushing a lot of packets around. If that ever changes this should be adjusted.
if runtime.NumCPU() > 1 {
runtime.GOMAXPROCS(2)
} else {
runtime.GOMAXPROCS(1)
}
debug.SetGCPercent(10)
globalOpts := flag.NewFlagSet("global", flag.ContinueOnError)

View file

@ -18,12 +18,12 @@
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
#define Te1_r(x) ZT_ROR32(Te0[x], 8)
#define Te2_r(x) ZT_ROR32(Te0[x], 16)
#define Te3_r(x) ZT_ROR32(Te0[x], 24)
#define Td1_r(x) ZT_ROR32(Td0[x], 8)
#define Td2_r(x) ZT_ROR32(Td0[x], 16)
#define Td3_r(x) ZT_ROR32(Td0[x], 24)
#define Te1_r(x) ZT_ROR32(Te0[x], 8U)
#define Te2_r(x) ZT_ROR32(Te0[x], 16U)
#define Te3_r(x) ZT_ROR32(Te0[x], 24U)
#define Td1_r(x) ZT_ROR32(Td0[x], 8U)
#define Td2_r(x) ZT_ROR32(Td0[x], 16U)
#define Td3_r(x) ZT_ROR32(Td0[x], 24U)
namespace ZeroTier {
@ -64,14 +64,14 @@ ZT_INLINE uint8x16_t s_clmul_armneon_crypto(uint8x16_t h, uint8x16_t y, const ui
ZT_INLINE void s_bmul32(const uint32_t x, const uint32_t y, uint32_t &rh, uint32_t &rl) noexcept
{
uint32_t x0 = x & 0x11111111;
uint32_t x1 = x & 0x22222222;
uint32_t x2 = x & 0x44444444;
uint32_t x3 = x & 0x88888888;
uint32_t y0 = y & 0x11111111;
uint32_t y1 = y & 0x22222222;
uint32_t y2 = y & 0x44444444;
uint32_t y3 = y & 0x88888888;
uint32_t x0 = x & 0x11111111U;
uint32_t x1 = x & 0x22222222U;
uint32_t x2 = x & 0x44444444U;
uint32_t x3 = x & 0x88888888U;
uint32_t y0 = y & 0x11111111U;
uint32_t y1 = y & 0x22222222U;
uint32_t y2 = y & 0x44444444U;
uint32_t y3 = y & 0x88888888U;
uint64_t z0 = (((uint64_t)x0 * y0) ^ ((uint64_t)x1 * y3) ^ ((uint64_t)x2 * y2) ^ ((uint64_t)x3 * y1)) & 0x1111111111111111ULL;
uint64_t z1 = (((uint64_t)x0 * y1) ^ ((uint64_t)x1 * y0) ^ ((uint64_t)x2 * y3) ^ ((uint64_t)x3 * y2)) & 0x2222222222222222ULL;
z0 |= z1;
@ -134,7 +134,7 @@ void s_gfmul(const uint64_t hh,const uint64_t hl,uint64_t &y0,uint64_t &y1) noex
zhh = zhh << 1U | zhl >> 63U;
zhl = zhl << 1U | zlh >> 63U;
zlh = zlh << 1U | zll >> 63U;
zll <<= 1;
zll <<= 1U;
zlh ^= (zll << 63U) ^ (zll << 62U) ^ (zll << 57U);
zhh ^= zlh ^ (zlh >> 1U) ^ (zlh >> 2U) ^ (zlh >> 7U);
zhl ^= zll ^ (zll >> 1U) ^ (zll >> 2U) ^ (zll >> 7U) ^ (zlh << 63U) ^ (zlh << 62U) ^ (zlh << 57U);
@ -1299,15 +1299,15 @@ void AES::_initSW(const uint8_t key[32]) noexcept
void AES::_encryptSW(const uint8_t in[16], uint8_t out[16]) const noexcept
{
const uint32_t *const restrict rk = _k.sw.ek;
const uint32_t m8 = 0xff;
const uint32_t m8_24 = 0xff000000;
const uint32_t m8_16 = 0x00ff0000;
const uint32_t m8 = 0x000000ff;
const uint32_t m8_8 = 0x0000ff00;
uint32_t s0, s1, s2, s3;
s0 = Utils::loadBigEndian< uint32_t >(in) ^ rk[0];
s1 = Utils::loadBigEndian< uint32_t >(in + 4) ^ rk[1];
s2 = Utils::loadBigEndian< uint32_t >(in + 8) ^ rk[2];
s3 = Utils::loadBigEndian< uint32_t >(in + 12) ^ rk[3];
const uint32_t m8_16 = 0x00ff0000;
const uint32_t m8_24 = 0xff000000;
uint32_t s0 = Utils::loadBigEndian< uint32_t >(in) ^rk[0];
uint32_t s1 = Utils::loadBigEndian< uint32_t >(in + 4) ^rk[1];
uint32_t s2 = Utils::loadBigEndian< uint32_t >(in + 8) ^rk[2];
uint32_t s3 = Utils::loadBigEndian< uint32_t >(in + 12) ^rk[3];
uint32_t t0, t1, t2, t3;
t0 = Te0[s0 >> 24U] ^ Te1_r((s1 >> 16U) & m8) ^ Te2_r((s2 >> 8U) & m8) ^ Te3_r(s3 & m8) ^ rk[4];
t1 = Te0[s1 >> 24U] ^ Te1_r((s2 >> 16U) & m8) ^ Te2_r((s3 >> 8U) & m8) ^ Te3_r(s0 & m8) ^ rk[5];
@ -1365,6 +1365,7 @@ void AES::_encryptSW(const uint8_t in[16], uint8_t out[16]) const noexcept
s1 = (Te2_r(t1 >> 24U) & m8_24) ^ (Te3_r((t2 >> 16U) & m8) & m8_16) ^ (Te0[(t3 >> 8U) & m8] & m8_8) ^ (Te1_r(t0 & m8) & m8) ^ rk[57];
s2 = (Te2_r(t2 >> 24U) & m8_24) ^ (Te3_r((t3 >> 16U) & m8) & m8_16) ^ (Te0[(t0 >> 8U) & m8] & m8_8) ^ (Te1_r(t1 & m8) & m8) ^ rk[58];
s3 = (Te2_r(t3 >> 24U) & m8_24) ^ (Te3_r((t0 >> 16U) & m8) & m8_16) ^ (Te0[(t1 >> 8U) & m8] & m8_8) ^ (Te1_r(t2 & m8) & m8) ^ rk[59];
Utils::storeBigEndian< uint32_t >(out, s0);
Utils::storeBigEndian< uint32_t >(out + 4, s1);
Utils::storeBigEndian< uint32_t >(out + 8, s2);
@ -1374,12 +1375,13 @@ void AES::_encryptSW(const uint8_t in[16], uint8_t out[16]) const noexcept
void AES::_decryptSW(const uint8_t in[16], uint8_t out[16]) const noexcept
{
const uint32_t *restrict rk = _k.sw.dk;
uint32_t s0, s1, s2, s3, t0, t1, t2, t3;
const uint32_t m8 = 0xff;
s0 = Utils::loadBigEndian< uint32_t >(in) ^ rk[0];
s1 = Utils::loadBigEndian< uint32_t >(in + 4) ^ rk[1];
s2 = Utils::loadBigEndian< uint32_t >(in + 8) ^ rk[2];
s3 = Utils::loadBigEndian< uint32_t >(in + 12) ^ rk[3];
const uint32_t m8 = 0x000000ff;
uint32_t s0 = Utils::loadBigEndian< uint32_t >(in) ^rk[0];
uint32_t s1 = Utils::loadBigEndian< uint32_t >(in + 4) ^rk[1];
uint32_t s2 = Utils::loadBigEndian< uint32_t >(in + 8) ^rk[2];
uint32_t s3 = Utils::loadBigEndian< uint32_t >(in + 12) ^rk[3];
uint32_t t0, t1, t2, t3;
t0 = Td0[s0 >> 24U] ^ Td1_r((s3 >> 16U) & m8) ^ Td2_r((s2 >> 8U) & m8) ^ Td3_r(s1 & m8) ^ rk[4];
t1 = Td0[s1 >> 24U] ^ Td1_r((s0 >> 16U) & m8) ^ Td2_r((s3 >> 8U) & m8) ^ Td3_r(s2 & m8) ^ rk[5];
t2 = Td0[s2 >> 24U] ^ Td1_r((s1 >> 16U) & m8) ^ Td2_r((s0 >> 8U) & m8) ^ Td3_r(s3 & m8) ^ rk[6];
@ -1432,11 +1434,15 @@ void AES::_decryptSW(const uint8_t in[16], uint8_t out[16]) const noexcept
t1 = Td0[s1 >> 24U] ^ Td1_r((s0 >> 16U) & m8) ^ Td2_r((s3 >> 8U) & m8) ^ Td3_r(s2 & m8) ^ rk[53];
t2 = Td0[s2 >> 24U] ^ Td1_r((s1 >> 16U) & m8) ^ Td2_r((s0 >> 8U) & m8) ^ Td3_r(s3 & m8) ^ rk[54];
t3 = Td0[s3 >> 24U] ^ Td1_r((s2 >> 16U) & m8) ^ Td2_r((s1 >> 8U) & m8) ^ Td3_r(s0 & m8) ^ rk[55];
rk += 56;
Utils::storeBigEndian< uint32_t >(out, (Td4[(t0 >> 24U)] << 24U) ^ (Td4[(t3 >> 16U) & m8] << 16U) ^ (Td4[(t2 >> 8U) & m8] << 8U) ^ (Td4[(t1) & m8]) ^ rk[0]);
Utils::storeBigEndian< uint32_t >(out + 4, (Td4[(t1 >> 24U)] << 24U) ^ (Td4[(t0 >> 16U) & m8] << 16U) ^ (Td4[(t3 >> 8U) & m8] << 8U) ^ (Td4[(t2) & m8]) ^ rk[1]);
Utils::storeBigEndian< uint32_t >(out + 8, (Td4[(t2 >> 24U)] << 24U) ^ (Td4[(t1 >> 16U) & m8] << 16U) ^ (Td4[(t0 >> 8U) & m8] << 8U) ^ (Td4[(t3) & m8]) ^ rk[2]);
Utils::storeBigEndian< uint32_t >(out + 12, (Td4[(t3 >> 24U)] << 24U) ^ (Td4[(t2 >> 16U) & m8] << 16U) ^ (Td4[(t1 >> 8U) & m8] << 8U) ^ (Td4[(t0) & m8]) ^ rk[3]);
s0 = (Td4[t0 >> 24U] << 24U) ^ (Td4[(t3 >> 16U) & m8] << 16U) ^ (Td4[(t2 >> 8U) & m8] << 8U) ^ (Td4[(t1) & m8]) ^ rk[56];
s1 = (Td4[t1 >> 24U] << 24U) ^ (Td4[(t0 >> 16U) & m8] << 16U) ^ (Td4[(t3 >> 8U) & m8] << 8U) ^ (Td4[(t2) & m8]) ^ rk[57];
s2 = (Td4[t2 >> 24U] << 24U) ^ (Td4[(t1 >> 16U) & m8] << 16U) ^ (Td4[(t0 >> 8U) & m8] << 8U) ^ (Td4[(t3) & m8]) ^ rk[58];
s3 = (Td4[t3 >> 24U] << 24U) ^ (Td4[(t2 >> 16U) & m8] << 16U) ^ (Td4[(t1 >> 8U) & m8] << 8U) ^ (Td4[(t0) & m8]) ^ rk[59];
Utils::storeBigEndian< uint32_t >(out, s0);
Utils::storeBigEndian< uint32_t >(out + 4, s1);
Utils::storeBigEndian< uint32_t >(out + 8, s2);
Utils::storeBigEndian< uint32_t >(out + 12, s3);
}
#ifdef ZT_AES_AESNI

View file

@ -7,9 +7,6 @@ Derived from public domain code by D. J. Bernstein.
// Modified slightly for ZeroTier but remains in the public domain as per
// its original license.
#include <cstdint>
#include <cstring>
#include "C25519.hpp"
#include "SHA512.hpp"
#include "Utils.hpp"