summaryrefslogtreecommitdiff
path: root/include/ZeroTierOne.h
blob: 93d5aa8b6442a32ec9a59b0bf8a43252b1907739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/*
 * ZeroTier One - Network Virtualization Everywhere
 * Copyright (C) 2011-2015  ZeroTier, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * --
 *
 * ZeroTier may be used and distributed under the terms of the GPLv3, which
 * are available at: http://www.gnu.org/licenses/gpl-3.0.html
 *
 * If you would like to embed ZeroTier into a commercial application or
 * redistribute it in a modified binary form, please contact ZeroTier Networks
 * LLC. Start here: http://www.zerotier.com/
 */

/*
 * This defines the external C API for ZeroTier One, the core network
 * virtualization engine.
 */

#ifndef ZT_ZEROTIERONE_H
#define ZT_ZEROTIERONE_H

#include <stdint.h>

/* ------------------------------------------------------------------------ */
/* Query result buffers                                                     */
/* ------------------------------------------------------------------------ */

/**
 * Node status result buffer
 */
struct ZT1_Node_Status
{
	/**
	 * Public identity in string form
	 */
	char publicIdentity[256];

	/**
	 * ZeroTier address in 10-digit hex form
	 */
	char address[16];

	/**
	 * ZeroTier address in least significant 40 bits of 64-bit integer
	 */
	uint64_t rawAddress;

	/**
	 * Number of known peers (including supernodes)
	 */
	unsigned int knownPeers;

	/**
	 * Number of upstream supernodes
	 */
	unsigned int supernodes;

	/**
	 * Number of peers with active direct links
	 */
	unsigned int directlyConnectedPeers;

	/**
	 * Number of peers that have recently communicated with us
	 */
	unsigned int alivePeers;

	/**
	 * Success rate at establishing direct links (0.0 to 1.0, approximate)
	 */
	float directLinkSuccessRate;

	/**
	 * True if connectivity appears good
	 */
	bool online;

	/**
	 * True if running; all other fields are technically undefined if this is false
	 */
	bool running;

	/**
	 * True if initialization is complete
	 */
	bool initialized;
};

/**
 * Physical address type
 */
enum ZT1_Node_PhysicalAddressType {
	ZT1_Node_PhysicalAddress_TYPE_NULL = 0,     /* none/invalid */
	ZT1_Node_PhysicalAddress_TYPE_IPV4 = 1,     /* 32-bit IPv4 address (and port) */
	ZT1_Node_PhysicalAddress_TYPE_IPV6 = 2,     /* 128-bit IPv6 address (and port) */
	ZT1_Node_PhysicalAddress_TYPE_ETHERNET = 3  /* 48-bit Ethernet MAC address */
};

/**
 * Physical address result buffer
 */
struct ZT1_Node_PhysicalAddress
{
	/**
	 * Physical address type
	 */
	enum ZT1_Node_PhysicalAddressType type;

	/**
	 * Address in raw binary form -- length depends on type
	 */
	unsigned char bits[16];

	/**
	 * Port or netmask bits (for IPV4 and IPV6)
	 */
	unsigned int port;

	/**
	 * Address in canonical human-readable form
	 */
	char ascii[64];

	/**
	 * Zone index identifier (thing after % on IPv6 link-local addresses only)
	 */
	char zoneIndex[16];
};

/**
 * Physical path type
 */
enum ZT1_Node_PhysicalPathType { /* These must be numerically the same as type in Path.hpp */
	ZT1_Node_PhysicalPath_TYPE_NULL = 0,     /* none/invalid */
	ZT1_Node_PhysicalPath_TYPE_UDP = 1,      /* UDP association */
	ZT1_Node_PhysicalPath_TYPE_TCP_OUT = 2,  /* outgoing TCP tunnel using pseudo-SSL */
	ZT1_Node_PhysicalPath_TYPE_TCP_IN = 3,   /* incoming TCP tunnel using pseudo-SSL */
	ZT1_Node_PhysicalPath_TYPE_ETHERNET = 4  /* raw ethernet frames over trusted backplane */
};

/**
 * Network path result buffer
 */
struct ZT1_Node_PhysicalPath
{
	/**
	 * Physical path type
	 */
	enum ZT1_Node_PhysicalPathType type;

	/**
	 * Physical address of endpoint
	 */
	struct ZT1_Node_PhysicalAddress address;

	/**
	 * Time since last send in milliseconds or -1 for never
	 */
	long lastSend;

	/**
	 * Time since last receive in milliseconds or -1 for never
	 */
	long lastReceive;

	/**
	 * Time since last ping in milliseconds or -1 for never
	 */
	long lastPing;

	/**
	 * Is path active/connected? Non-fixed active paths may be garbage collected over time.
	 */
	bool active;

	/**
	 * Is path fixed? (i.e. not learned, static)
	 */
	bool fixed;
};

/**
 * What trust hierarchy role does this device have?
 */
enum ZT1_Node_PeerRole {
	ZT1_Node_Peer_SUPERNODE = 0, // planetary supernode
	ZT1_Node_Peer_HUB = 1,       // locally federated hub (coming soon)
	ZT1_Node_Peer_NODE = 2       // ordinary node
};

/**
 * Peer status result buffer
 */
struct ZT1_Node_Peer
{
	/**
	 * Remote peer version: major.minor.revision (or empty if unknown)
	 */
	char remoteVersion[16];

	/**
	 * ZeroTier address of peer as 10-digit hex string
	 */
	char address[16];

	/**
	 * ZeroTier address in least significant 40 bits of 64-bit integer
	 */
	uint64_t rawAddress;

	/**
	 * Last measured latency in milliseconds or zero if unknown
	 */
	unsigned int latency;

	/**
	 * What trust hierarchy role does this device have?
	 */
	enum ZT1_Node_PeerRole role;

	/**
	 * Array of network paths to peer
	 */
	struct ZT1_Node_PhysicalPath *paths;

	/**
	 * Number of paths (size of paths[])
	 */
	unsigned int numPaths;
};

/**
 * List of peers
 */
struct ZT1_Node_PeerList
{
	struct ZT1_Node_Peer *peers;
	unsigned int numPeers;
};

/**
 * Network status code
 */
enum ZT1_Node_NetworkStatus {
	ZT1_Node_Network_INITIALIZING = 0,
	ZT1_Node_Network_WAITING_FOR_FIRST_AUTOCONF = 1,
	ZT1_Node_Network_OK = 2,
	ZT1_Node_Network_ACCESS_DENIED = 3,
	ZT1_Node_Network_NOT_FOUND = 4,
	ZT1_Node_Network_INITIALIZATION_FAILED = 5,
	ZT1_Node_Network_NO_MORE_DEVICES = 6
};

/**
 * Network status result buffer
 */
struct ZT1_Node_Network
{
	/**
	 * 64-bit network ID
	 */
	uint64_t nwid;

	/**
	 * 64-bit network ID in hex form
	 */
	char nwidHex[32];

	/**
	 * Short network name
	 */
	char name[256];

	/**
	 * Longer network description
	 */
	char description[4096];

	/**
	 * Device name (system-dependent)
	 */
	char device[256];

	/**
	 * Status code in string format
	 */
	char statusStr[64];

	/**
	 * Ethernet MAC address of this endpoint in string form
	 */
	char macStr[32];

	/**
	 * Ethernet MAC address of this endpoint on the network in raw binary form
	 */
	unsigned char mac[6];

	/**
	 * Age of configuration in milliseconds or -1 if never refreshed
	 */
	long configAge;

	/**
	 * Assigned layer-3 IPv4 and IPv6 addresses
	 *
	 * Note that PhysicalAddress also supports other address types, but this
	 * list will only list IP address assignments. The port field will contain
	 * the number of bits in the netmask -- e.g. 192.168.1.1/24.
	 */
	struct ZT1_Node_PhysicalAddress *ips;

	/**
	 * Number of layer-3 IPs (size of ips[])
	 */
	unsigned int numIps;

	/**
	 * Network status code
	 */
	enum ZT1_Node_NetworkStatus status;

	/**
	 * True if traffic on network is enabled
	 */
	bool enabled;

	/**
	 * Is this a private network? If false, network lacks access control.
	 */
	bool isPrivate;
};

/**
 * Return buffer for list of networks
 */
struct ZT1_Node_NetworkList
{
	struct ZT1_Node_Network *networks;
	unsigned int numNetworks;
};

/* ------------------------------------------------------------------------ */
/* ZeroTier One C API                                                       */
/* ------------------------------------------------------------------------ */

/* coming soon... */

#endif