From e0492a7e698a2a02376f4d1f629d83cf436a8250 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 11 Aug 2020 13:24:27 -0700 Subject: [PATCH] More Go CLI work, and some cleanup. --- cmd/zerotier/cli/help.go | 7 ++++--- cmd/zerotier/cli/locator.go | 7 +++++++ cmd/zerotier/cli/misc.go | 24 ++++++++++++++++++++++++ cmd/zerotier/cli/network.go | 3 +++ cmd/zerotier/cli/peer.go | 20 ++++++++++++++++++-- core/AES.cpp | 37 ++++++++++++++++++------------------- 6 files changed, 74 insertions(+), 24 deletions(-) diff --git a/cmd/zerotier/cli/help.go b/cmd/zerotier/cli/help.go index 00d828b72..fae4a13f9 100644 --- a/cmd/zerotier/cli/help.go +++ b/cmd/zerotier/cli/help.go @@ -46,9 +46,10 @@ Common Operations: blacklist if Toggle interface prefix blacklisting portmap Toggle use of uPnP or NAT-PMP -· peer list List VL1 peers -· peer
[command] [option] - Peer management commands - show Show peer details (default) +· peer [address] [command] [option] - Peer management commands + list List peers + listroots List root peers + show Show peer details try [...] Try peer at explicit endpoint · network list List VL2 networks diff --git a/cmd/zerotier/cli/locator.go b/cmd/zerotier/cli/locator.go index f05cfe79a..ac4627739 100644 --- a/cmd/zerotier/cli/locator.go +++ b/cmd/zerotier/cli/locator.go @@ -20,6 +20,13 @@ func Locator(args []string) int { } switch args[0] { + + case "new": + + case "verify": + + case "show": + } return 0 diff --git a/cmd/zerotier/cli/misc.go b/cmd/zerotier/cli/misc.go index f7044a3e3..f0b03746e 100644 --- a/cmd/zerotier/cli/misc.go +++ b/cmd/zerotier/cli/misc.go @@ -211,3 +211,27 @@ func readJSONFile(p string, obj interface{}) error { } return json.Unmarshal(b, obj) } + +func isValidAddress(a string) bool { + if len(a) == zerotier.AddressStringLength { + for _, c := range a { + if !strings.ContainsRune("0123456789abcdefABCDEF", c) { + return false + } + } + return true + } + return false +} + +func isValidNetworkID(a string) bool { + if len(a) == zerotier.NetworkIDStringLength { + for _, c := range a { + if !strings.ContainsRune("0123456789abcdefABCDEF", c) { + return false + } + } + return true + } + return false +} diff --git a/cmd/zerotier/cli/network.go b/cmd/zerotier/cli/network.go index e2cb0dceb..8391cc665 100644 --- a/cmd/zerotier/cli/network.go +++ b/cmd/zerotier/cli/network.go @@ -141,8 +141,10 @@ func Network(basePath string, authTokenGenerator func() string, args []string, j showNetwork(nwids, &network, jsonOutput) } else { switch args[1] { + case "show", "info": showNetwork(nwids, &network, jsonOutput) + case "set": if len(args) > 3 { Help() @@ -178,6 +180,7 @@ func Network(basePath string, authTokenGenerator func() string, args []string, j fmt.Printf("globalroutes\t%s\n", allowedBlocked(network.Settings.AllowGlobalRoutes)) fmt.Printf("defaultroute\t%s\n", allowedBlocked(network.Settings.AllowDefaultRouteOverride)) } + } } diff --git a/cmd/zerotier/cli/peer.go b/cmd/zerotier/cli/peer.go index 2f1e7f9cc..5ad8c7562 100644 --- a/cmd/zerotier/cli/peer.go +++ b/cmd/zerotier/cli/peer.go @@ -73,11 +73,27 @@ func Peer(basePath string, authTokenGenerator func() string, args []string, json authToken := authTokenGenerator() - if len(args) == 1 && args[0] == "list" { - return listPeers(basePath, authToken, jsonOutput, false) + //var addr zerotier.Address + if isValidAddress(args[0]) { + //addr, _ = zerotier.NewAddressFromString(args[0]) + args = args[1:] + if len(args) < 1 { + Help() + return 1 + } } switch args[0] { + + case "list": + return listPeers(basePath, authToken, jsonOutput, false) + case "listroots": + return listPeers(basePath, authToken, jsonOutput, true) + + case "show": + + case "try": + } return 0 diff --git a/core/AES.cpp b/core/AES.cpp index 739c12fcb..fa4ee4576 100644 --- a/core/AES.cpp +++ b/core/AES.cpp @@ -62,25 +62,24 @@ ZT_INLINE uint8x16_t s_clmul_armneon_crypto(uint8x16_t h, uint8x16_t y, const ui #endif // ZT_AES_NEON -ZT_INLINE void s_bmul32(const uint32_t x, const uint32_t y, uint32_t &rh, uint32_t &rl) noexcept -{ - 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; - uint64_t z2 = (((uint64_t)x0 * y2) ^ ((uint64_t)x1 * y1) ^ ((uint64_t)x2 * y0) ^ ((uint64_t)x3 * y3)) & 0x4444444444444444ULL; - z2 |= z0; - uint64_t z3 = (((uint64_t)x0 * y3) ^ ((uint64_t)x1 * y2) ^ ((uint64_t)x2 * y1) ^ ((uint64_t)x3 * y0)) & 0x8888888888888888ULL; - uint64_t z = z2 | z3; - rh = (uint32_t)(z >> 32U); - rl = (uint32_t)z; +#define s_bmul32(x, y, rh, rl) { \ + uint32_t x0t = (x) & 0x11111111U; \ + uint32_t x1t = (x) & 0x22222222U; \ + uint32_t x2t = (x) & 0x44444444U; \ + uint32_t x3t = (x) & 0x88888888U; \ + uint32_t y0t = (y) & 0x11111111U; \ + uint32_t y1t = (y) & 0x22222222U; \ + uint32_t y2t = (y) & 0x44444444U; \ + uint32_t y3t = (y) & 0x88888888U; \ + uint64_t z0t = (((uint64_t)x0t * y0t) ^ ((uint64_t)x1t * y3t) ^ ((uint64_t)x2t * y2t) ^ ((uint64_t)x3t * y1t)) & 0x1111111111111111ULL; \ + uint64_t z1t = (((uint64_t)x0t * y1t) ^ ((uint64_t)x1t * y0t) ^ ((uint64_t)x2t * y3t) ^ ((uint64_t)x3t * y2t)) & 0x2222222222222222ULL; \ + z0t |= z1t; \ + uint64_t z2t = (((uint64_t)x0t * y2t) ^ ((uint64_t)x1t * y1t) ^ ((uint64_t)x2t * y0t) ^ ((uint64_t)x3t * y3t)) & 0x4444444444444444ULL; \ + z2t |= z0t; \ + uint64_t z3t = (((uint64_t)x0t * y3t) ^ ((uint64_t)x1t * y2t) ^ ((uint64_t)x2t * y1t) ^ ((uint64_t)x3t * y0t)) & 0x8888888888888888ULL; \ + uint64_t zt = z2t | z3t; \ + (rh) = (uint32_t)(zt >> 32U); \ + (rl) = (uint32_t)zt; \ } void s_gfmul(const uint64_t hh, const uint64_t hl, uint64_t &y0, uint64_t &y1) noexcept