1.10.4 merge into main (#1893)

* add note about forceTcpRelay

* Create a sample systemd unit for tcp proxy

* set gitattributes for rust & cargo so hashes dont conflict on Windows

* Revert "set gitattributes for rust & cargo so hashes dont conflict on Windows"

This reverts commit 032dc5c108.

* Turn off autocrlf for rust source

Doesn't appear to play nice well when it comes to git and vendored cargo package hashes

* Fix #1883 (#1886)

Still unknown as to why, but the call to `nc->GetProperties()` can fail
when setting a friendly name on the Windows virtual ethernet adapter.
Ensure that `ncp` is not null before continuing and accessing the device
GUID.

* Don't vendor packages for zeroidc (#1885)

* Added docker environment way to join networks (#1871)

* add StringUtils

* fix headers
use recommended headers and remove unused headers

* move extern "C"
only JNI functions need to be exported

* cleanup

* fix ANDROID-50: RESULT_ERROR_BAD_PARAMETER typo

* fix typo in log message

* fix typos in JNI method signatures

* fix typo

* fix ANDROID-51: fieldName is uninitialized

* fix ANDROID-35: memory leak

* fix missing DeleteLocalRef in loops

* update to use unique error codes

* add GETENV macro

* add LOG_TAG defines

* ANDROID-48: add ZT_jnicache.cpp

* ANDROID-48: use ZT_jnicache.cpp and remove ZT_jnilookup.cpp and ZT_jniarray.cpp

* add Event.fromInt

* add PeerRole.fromInt

* add ResultCode.fromInt

* fix ANDROID-36: issues with ResultCode

* add VirtualNetworkConfigOperation.fromInt

* fix ANDROID-40: VirtualNetworkConfigOperation out-of-sync with ZT_VirtualNetworkConfigOperation enum

* add VirtualNetworkStatus.fromInt

* fix ANDROID-37: VirtualNetworkStatus out-of-sync with ZT_VirtualNetworkStatus enum

* add VirtualNetworkType.fromInt

* make NodeStatus a plain data class

* fix ANDROID-52: synchronization bug with nodeMap

* Node init work: separate Node construction and init

* add Node.toString

* make PeerPhysicalPath a plain data class

* remove unused PeerPhysicalPath.fixed

* add array functions

* make Peer a plain data class

* make Version a plain data class

* fix ANDROID-42: copy/paste error

* fix ANDROID-49: VirtualNetworkConfig.equals is wrong

* reimplement VirtualNetworkConfig.equals

* reimplement VirtualNetworkConfig.compareTo

* add VirtualNetworkConfig.hashCode

* make VirtualNetworkConfig a plain data class

* remove unused VirtualNetworkConfig.enabled

* reimplement VirtualNetworkDNS.equals

* add VirtualNetworkDNS.hashCode

* make VirtualNetworkDNS a plain data class

* reimplement VirtualNetworkRoute.equals

* reimplement VirtualNetworkRoute.compareTo

* reimplement VirtualNetworkRoute.toString

* add VirtualNetworkRoute.hashCode

* make VirtualNetworkRoute a plain data class

* add isSocketAddressEmpty

* add addressPort

* add fromSocketAddressObject

* invert logic in a couple of places and return early

* newInetAddress and newInetSocketAddress work
allow newInetSocketAddress to return NULL if given empty address

* fix ANDROID-38: stack corruption in onSendPacketRequested

* use GETENV macro

* JniRef work
JniRef does not use callbacks struct, so remove
fix NewGlobalRef / DeleteGlobalRef mismatch

* use PRId64 macros

* switch statement work

* comments and logging

* Modifier 'public' is redundant for interface members

* NodeException can be made a checked Exception

* 'NodeException' does not define a 'serialVersionUID' field

* 'finalize()' should not be overridden
this is fine to do because ZeroTierOneService calls close() when it is done

* error handling, error reporting, asserts, logging

* simplify loadLibrary

* rename Node.networks -> Node.networkConfigs

* Windows file permissions fix (#1887)

* Allow macOS interfaces to use multiple IP addresses (#1879)

Co-authored-by: Sean OMeara <someara@users.noreply.github.com>
Co-authored-by: Grant Limberg <glimberg@users.noreply.github.com>

* Fix condition where full HELLOs might not be sent when necessary (#1877)

Co-authored-by: Grant Limberg <glimberg@users.noreply.github.com>

* 1.10.4 version bumps

* Add security policy to repo (#1889)

* [+] add e2k64 arch (#1890)

* temp fix for ANDROID-56: crash inside newNetworkConfig from too many args

* 1.10.4 release notes

---------

Co-authored-by: travis laduke <travisladuke@gmail.com>
Co-authored-by: Grant Limberg <grant.limberg@zerotier.com>
Co-authored-by: Grant Limberg <glimberg@users.noreply.github.com>
Co-authored-by: Leonardo Amaral <leleobhz@users.noreply.github.com>
Co-authored-by: Brenton Bostick <bostick@gmail.com>
Co-authored-by: Sean OMeara <someara@users.noreply.github.com>
Co-authored-by: Joseph Henry <joseph-henry@users.noreply.github.com>
Co-authored-by: Roman Peshkichev <roman.peshkichev@gmail.com>
This commit is contained in:
Adam Ierymenko 2023-03-07 16:50:34 -05:00 committed by GitHub
parent dea47f601d
commit 1c5897895b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13322 changed files with 3150 additions and 3572096 deletions

View file

@ -29,197 +29,305 @@ package com.zerotier.sdk;
import android.util.Log;
import java.lang.Comparable;
import java.lang.Override;
import java.lang.String;
import java.util.ArrayList;
import com.zerotier.sdk.util.StringUtils;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConfig> {
/**
* Virtual network configuration
*
* Defined in ZeroTierOne.h as ZT_VirtualNetworkConfig
*/
public class VirtualNetworkConfig implements Comparable<VirtualNetworkConfig> {
private final static String TAG = "VirtualNetworkConfig";
public static final int MAX_MULTICAST_SUBSCRIPTIONS = 4096;
public static final int ZT_MAX_ZT_ASSIGNED_ADDRESSES = 16;
private long nwid;
private long mac;
private String name;
private VirtualNetworkStatus status;
private VirtualNetworkType type;
private int mtu;
private boolean dhcp;
private boolean bridge;
private boolean broadcastEnabled;
private int portError;
private boolean enabled;
private long netconfRevision;
private InetSocketAddress[] assignedAddresses;
private VirtualNetworkRoute[] routes;
private VirtualNetworkDNS dns;
private final long nwid;
private VirtualNetworkConfig() {
private final long mac;
private final String name;
private final VirtualNetworkStatus status;
private final VirtualNetworkType type;
private final int mtu;
private final boolean dhcp;
private final boolean bridge;
private final boolean broadcastEnabled;
//
// ANDROID-56: temporarily remove parameters to prevent crashing
//
// private final int portError;
//
// private final long netconfRevision;
private final InetSocketAddress[] assignedAddresses;
private final VirtualNetworkRoute[] routes;
private final VirtualNetworkDNS dns;
public VirtualNetworkConfig(long nwid, long mac, String name, VirtualNetworkStatus status, VirtualNetworkType type, int mtu, boolean dhcp, boolean bridge, boolean broadcastEnabled, InetSocketAddress[] assignedAddresses, VirtualNetworkRoute[] routes, VirtualNetworkDNS dns) {
this.nwid = nwid;
this.mac = mac;
this.name = name;
this.status = status;
this.type = type;
if (mtu < 0) {
throw new RuntimeException("mtu < 0: " + mtu);
}
this.mtu = mtu;
this.dhcp = dhcp;
this.bridge = bridge;
this.broadcastEnabled = broadcastEnabled;
// this.portError = portError;
// if (netconfRevision < 0) {
// throw new RuntimeException("netconfRevision < 0: " + netconfRevision);
// }
// this.netconfRevision = netconfRevision;
this.assignedAddresses = assignedAddresses;
this.routes = routes;
this.dns = dns;
}
public boolean equals(VirtualNetworkConfig cfg) {
ArrayList<String> aaCurrent = new ArrayList<>();
ArrayList<String> aaNew = new ArrayList<>();
for (InetSocketAddress s : assignedAddresses) {
aaCurrent.add(s.toString());
}
for (InetSocketAddress s : cfg.assignedAddresses) {
aaNew.add(s.toString());
}
Collections.sort(aaCurrent);
Collections.sort(aaNew);
boolean aaEqual = aaCurrent.equals(aaNew);
@Override
public String toString() {
return "VirtualNetworkConfig(" + StringUtils.networkIdToString(nwid) + ", " + StringUtils.macAddressToString(mac) + ", " + name + ", " + status + ", " + type + ", " + mtu + ", " + dhcp + ", " + bridge + ", " + broadcastEnabled + ", " + Arrays.toString(assignedAddresses) + ", " + Arrays.toString(routes) + ", " + dns + ")";
}
ArrayList<String> rCurrent = new ArrayList<>();
ArrayList<String> rNew = new ArrayList<>();
for (VirtualNetworkRoute r : routes) {
rCurrent.add(r.toString());
@Override
public boolean equals(Object o) {
if (!(o instanceof VirtualNetworkConfig)) {
return false;
}
for (VirtualNetworkRoute r : cfg.routes) {
rNew.add(r.toString());
}
Collections.sort(rCurrent);
Collections.sort(rNew);
boolean routesEqual = rCurrent.equals(rNew);
VirtualNetworkConfig cfg = (VirtualNetworkConfig) o;
if (this.nwid != cfg.nwid) {
Log.i(TAG, "nwid Changed. Old: " + Long.toHexString(this.nwid) + " (" + Long.toString(this.nwid) + "), " +
"New: " + Long.toHexString(cfg.nwid) + " (" + Long.toString(cfg.nwid) + ")");
Log.i(TAG, "NetworkID Changed. Old: " + StringUtils.networkIdToString(this.nwid) + " (" + this.nwid + "), " +
"New: " + StringUtils.networkIdToString(cfg.nwid) + " (" + cfg.nwid + ")");
return false;
}
if (this.mac != cfg.mac) {
Log.i(TAG, "MAC Changed. Old: " + Long.toHexString(this.mac) + ", New: " + Long.toHexString(cfg.mac));
Log.i(TAG, "MAC Changed. Old: " + StringUtils.macAddressToString(this.mac) + ", New: " + StringUtils.macAddressToString(cfg.mac));
return false;
}
if (!this.name.equals(cfg.name)) {
Log.i(TAG, "Name Changed. Old: " + this.name + " New: "+ cfg.name);
Log.i(TAG, "Name Changed. Old: " + this.name + ", New: " + cfg.name);
return false;
}
if (!this.type.equals(cfg.type)) {
Log.i(TAG, "TYPE changed. Old " + this.type + ", New: " + cfg.type);
if (this.status != cfg.status) {
Log.i(TAG, "Status Changed. Old: " + this.status + ", New: " + cfg.status);
return false;
}
if (this.type != cfg.type) {
Log.i(TAG, "Type changed. Old " + this.type + ", New: " + cfg.type);
return false;
}
if (this.mtu != cfg.mtu) {
Log.i(TAG, "MTU Changed. Old: " + this.mtu + ", New: " + cfg.mtu);
Log.i(TAG, "MTU Changed. Old: " + this.mtu + ", New: " + cfg.mtu);
return false;
}
if (this.dhcp != cfg.dhcp) {
Log.i(TAG, "DHCP Flag Changed. Old: " + this.dhcp + ", New: " + cfg.dhcp);
return false;
}
if (this.bridge != cfg.bridge) {
Log.i(TAG, "Bridge Flag Changed. Old: " + this.bridge + ", New: " + cfg.bridge);
return false;
}
if (this.broadcastEnabled != cfg.broadcastEnabled) {
Log.i(TAG, "Broadcast Flag Changed. Old: "+ this.broadcastEnabled +", New: " + this.broadcastEnabled);
Log.i(TAG, "Broadcast Flag Changed. Old: "+ this.broadcastEnabled + ", New: " + cfg.broadcastEnabled);
return false;
}
if (this.portError != cfg.portError) {
Log.i(TAG, "Port Error Changed. Old: " + this.portError + ", New: " + this.portError);
}
// if (this.portError != cfg.portError) {
// Log.i(TAG, "Port Error Changed. Old: " + this.portError + ", New: " + cfg.portError);
//
// return false;
// }
//
// if (this.netconfRevision != cfg.netconfRevision) {
// Log.i(TAG, "NetConfRevision Changed. Old: " + this.netconfRevision + ", New: " + cfg.netconfRevision);
//
// return false;
// }
if (this.enabled != cfg.enabled) {
Log.i(TAG, "Enabled Changed. Old: " + this.enabled + ", New: " + this.enabled);
}
if (!Arrays.equals(assignedAddresses, cfg.assignedAddresses)) {
ArrayList<String> aaCurrent = new ArrayList<>();
ArrayList<String> aaNew = new ArrayList<>();
for (InetSocketAddress s : assignedAddresses) {
aaCurrent.add(s.toString());
}
for (InetSocketAddress s : cfg.assignedAddresses) {
aaNew.add(s.toString());
}
Collections.sort(aaCurrent);
Collections.sort(aaNew);
if (!aaEqual) {
Log.i(TAG, "Assigned Addresses Changed");
Log.i(TAG, "Old:");
for (String s : aaCurrent) {
Log.i(TAG, " " + s);
}
Log.i(TAG, "");
Log.i(TAG, "New:");
for (String s : aaNew) {
Log.i(TAG, " " +s);
}
Log.i(TAG, "");
return false;
}
if (!routesEqual) {
if (!Arrays.equals(routes, cfg.routes)) {
ArrayList<String> rCurrent = new ArrayList<>();
ArrayList<String> rNew = new ArrayList<>();
for (VirtualNetworkRoute r : routes) {
rCurrent.add(r.toString());
}
for (VirtualNetworkRoute r : cfg.routes) {
rNew.add(r.toString());
}
Collections.sort(rCurrent);
Collections.sort(rNew);
Log.i(TAG, "Managed Routes Changed");
Log.i(TAG, "Old:");
for (String s : rCurrent) {
Log.i(TAG, " " + s);
}
Log.i(TAG, "");
Log.i(TAG, "New:");
for (String s : rNew) {
Log.i(TAG, " " + s);
}
Log.i(TAG, "");
return false;
}
boolean dnsEquals = false;
if (this.dns == null || cfg.dns == null) {
dnsEquals = true;
} else if (this.dns != null) {
dnsEquals = this.dns.equals(cfg.dns);
boolean dnsEquals;
if (this.dns == null) {
//noinspection RedundantIfStatement
if (cfg.dns == null) {
dnsEquals = true;
} else {
dnsEquals = false;
}
} else {
if (cfg.dns == null) {
dnsEquals = false;
} else {
dnsEquals = this.dns.equals(cfg.dns);
}
}
return this.nwid == cfg.nwid &&
this.mac == cfg.mac &&
this.name.equals(cfg.name) &&
this.status.equals(cfg.status) &&
this.type.equals(cfg.type) &&
this.mtu == cfg.mtu &&
this.dhcp == cfg.dhcp &&
this.bridge == cfg.bridge &&
this.broadcastEnabled == cfg.broadcastEnabled &&
this.portError == cfg.portError &&
this.enabled == cfg.enabled &&
dnsEquals &&
aaEqual && routesEqual;
if (!dnsEquals) {
return false;
}
return true;
}
@Override
public int compareTo(VirtualNetworkConfig cfg) {
if(cfg.nwid == this.nwid) {
return 0;
} else {
return this.nwid > cfg.nwid ? 1 : -1;
}
return Long.compare(this.nwid, cfg.nwid);
}
@Override
public int hashCode() {
int result = 17;
result = 37 * result + (int) (nwid ^ (nwid >>> 32));
result = 37 * result + (int) (mac ^ (mac >>> 32));
result = 37 * result + name.hashCode();
result = 37 * result + status.hashCode();
result = 37 * result + type.hashCode();
result = 37 * result + mtu;
result = 37 * result + (dhcp ? 1 : 0);
result = 37 * result + (bridge ? 1 : 0);
result = 37 * result + (broadcastEnabled ? 1 : 0);
// result = 37 * result + portError;
// result = 37 * result + (int) (netconfRevision ^ (netconfRevision >>> 32));
result = 37 * result + Arrays.hashCode(assignedAddresses);
result = 37 * result + Arrays.hashCode(routes);
result = 37 * result + (dns == null ? 0 : dns.hashCode());
return result;
}
/**
* 64-bit ZeroTier network ID
*/
public final long networkId() {
public long getNwid() {
return nwid;
}
/**
* Ethernet MAC (40 bits) that should be assigned to port
* Ethernet MAC (48 bits) that should be assigned to port
*/
public final long macAddress() {
public long getMac() {
return mac;
}
/**
* Network name (from network configuration master)
*/
public final String name() {
public String getName() {
return name;
}
/**
* Network configuration request status
*/
public final VirtualNetworkStatus networkStatus() {
public VirtualNetworkStatus getStatus() {
return status;
}
/**
* Network type
*/
public final VirtualNetworkType networkType() {
public VirtualNetworkType getType() {
return type;
}
/**
* Maximum interface MTU
*/
public final int mtu() {
public int getMtu() {
return mtu;
}
@ -230,7 +338,7 @@ public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConf
* for security or other reasons. This is simply a netconf parameter that
* means 'DHCP is available on this network.'</p>
*/
public final boolean isDhcpAvailable() {
public boolean isDhcp() {
return dhcp;
}
@ -240,35 +348,35 @@ public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConf
* <p>This is informational. If this is false, bridged packets will simply
* be dropped and bridging won't work.</p>
*/
public final boolean isBridgeEnabled() {
public boolean isBridge() {
return bridge;
}
/**
* If true, this network supports and allows broadcast (ff:ff:ff:ff:ff:ff) traffic
*/
public final boolean broadcastEnabled() {
public boolean isBroadcastEnabled() {
return broadcastEnabled;
}
/**
* If the network is in PORT_ERROR state, this is the error most recently returned by the port config callback
*/
public final int portError() {
return portError;
}
// public int getPortError() {
// return portError;
// }
/**
* Network config revision as reported by netconf master
*
* <p>If this is zero, it means we're still waiting for our netconf.</p>
*/
public final long netconfRevision() {
return netconfRevision;
}
// public long getNetconfRevision() {
// return netconfRevision;
// }
/**
* ZeroTier-assigned addresses (in {@link java.net.InetSocketAddress} objects)
* ZeroTier-assigned addresses (in {@link InetSocketAddress} objects)
*
* For IP, the port number of the sockaddr_XX structure contains the number
* of bits in the address netmask. Only the IP address and port are used.
@ -277,16 +385,21 @@ public final class VirtualNetworkConfig implements Comparable<VirtualNetworkConf
* This is only used for ZeroTier-managed address assignments sent by the
* virtual network's configuration master.
*/
public final InetSocketAddress[] assignedAddresses() {
public InetSocketAddress[] getAssignedAddresses() {
return assignedAddresses;
}
/**
* ZeroTier-assigned routes (in {@link com.zerotier.sdk.VirtualNetworkRoute} objects)
*
* @return
* ZeroTier-assigned routes (in {@link VirtualNetworkRoute} objects)
*/
public final VirtualNetworkRoute[] routes() { return routes; }
public VirtualNetworkRoute[] getRoutes() {
return routes;
}
public final VirtualNetworkDNS dns() { return dns; }
/**
* Network specific DNS configuration
*/
public VirtualNetworkDNS getDns() {
return dns;
}
}