2013-07-04 20:56:19 +00:00
|
|
|
/*
|
2019-08-23 16:23:39 +00:00
|
|
|
* Copyright (c)2019 ZeroTier, Inc.
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
2019-08-23 16:23:39 +00:00
|
|
|
* Use of this software is governed by the Business Source License included
|
|
|
|
* in the LICENSE.TXT file in the project's root directory.
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
2019-08-23 16:23:39 +00:00
|
|
|
* Change Date: 2023-01-01
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
2019-08-23 16:23:39 +00:00
|
|
|
* On the date above, in accordance with the Business Source License, use
|
|
|
|
* of this software will be governed by version 2.0 of the Apache License.
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
2019-08-23 16:23:39 +00:00
|
|
|
/****/
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2013-12-07 00:49:20 +00:00
|
|
|
#ifndef ZT_N_PACKET_HPP
|
|
|
|
#define ZT_N_PACKET_HPP
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2013-09-17 19:53:59 +00:00
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
|
2014-10-29 00:25:34 +00:00
|
|
|
#include "Constants.hpp"
|
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
#include "Address.hpp"
|
2013-09-16 17:02:10 +00:00
|
|
|
#include "Poly1305.hpp"
|
2013-07-04 20:56:19 +00:00
|
|
|
#include "Salsa20.hpp"
|
|
|
|
#include "Utils.hpp"
|
|
|
|
#include "Buffer.hpp"
|
|
|
|
|
|
|
|
/**
|
2015-10-07 23:11:50 +00:00
|
|
|
* Protocol version -- incremented only for major changes
|
2013-07-11 02:58:43 +00:00
|
|
|
*
|
2019-05-14 20:54:27 +00:00
|
|
|
* 1 - 0.2.0 ... 0.2.5
|
|
|
|
* 2 - 0.3.0 ... 0.4.5
|
|
|
|
* + Added signature and originating peer to multicast frame
|
|
|
|
* + Double size of multicast frame bloom filter
|
|
|
|
* 3 - 0.5.0 ... 0.6.0
|
|
|
|
* + Yet another multicast redesign
|
|
|
|
* + New crypto completely changes key agreement cipher
|
|
|
|
* 4 - 0.6.0 ... 1.0.6
|
|
|
|
* + BREAKING CHANGE: New identity format based on hashcash design
|
|
|
|
* 5 - 1.1.0 ... 1.1.5
|
|
|
|
* + Supports echo
|
|
|
|
* + Supports in-band world (root server definition) updates
|
|
|
|
* + Clustering! (Though this will work with protocol v4 clients.)
|
|
|
|
* + Otherwise backward compatible with protocol v4
|
|
|
|
* 6 - 1.1.5 ... 1.1.10
|
|
|
|
* + Network configuration format revisions including binary values
|
|
|
|
* 7 - 1.1.10 ... 1.1.17
|
|
|
|
* + Introduce trusted paths for local SDN use
|
|
|
|
* 8 - 1.1.17 ... 1.2.0
|
|
|
|
* + Multipart network configurations for large network configs
|
|
|
|
* + Tags and Capabilities
|
2019-08-27 03:18:28 +00:00
|
|
|
* + ZT_ALWAYS_INLINE push of CertificateOfMembership deprecated
|
2019-05-14 20:54:27 +00:00
|
|
|
* 9 - 1.2.0 ... 1.2.14
|
2019-07-17 21:53:33 +00:00
|
|
|
* 10 - 1.4.0 ... 1.6.0
|
2019-05-14 20:54:27 +00:00
|
|
|
* + Multipath capability and load balancing
|
2019-08-14 17:35:57 +00:00
|
|
|
* 11 - 2.0.0 ... CURRENT
|
2019-07-16 18:33:11 +00:00
|
|
|
* + Peer-to-peer multicast replication (optional)
|
2019-07-17 15:52:08 +00:00
|
|
|
* + Old planet/moon stuff is DEAD!
|
2019-08-28 20:04:58 +00:00
|
|
|
* + AES-256-GMAC-CTR encryption is now the default
|
2019-08-21 16:27:45 +00:00
|
|
|
* + NIST P-384 (type 1) identities now supported
|
|
|
|
* + WILL_RELAY allows mesh-like operation
|
|
|
|
* + Ephemeral keys are now negotiated opportunistically
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
2019-07-17 21:53:33 +00:00
|
|
|
#define ZT_PROTO_VERSION 11
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2014-09-30 23:28:25 +00:00
|
|
|
/**
|
|
|
|
* Minimum supported protocol version
|
|
|
|
*/
|
2019-09-08 02:15:21 +00:00
|
|
|
#define ZT_PROTO_VERSION_MIN 6
|
2014-09-30 23:28:25 +00:00
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
/**
|
|
|
|
* Maximum hop count allowed by packet structure (3 bits, 0-7)
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2015-07-06 19:34:35 +00:00
|
|
|
* This is a protocol constant. It's the maximum allowed by the length
|
|
|
|
* of the hop counter -- three bits. See node/Constants.hpp for the
|
|
|
|
* pragmatic forwarding limit, which is typically lower.
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
|
|
|
#define ZT_PROTO_MAX_HOPS 7
|
|
|
|
|
2014-10-02 17:54:34 +00:00
|
|
|
/**
|
2019-08-15 22:43:35 +00:00
|
|
|
* NONE/Poly1305 (using Salsa20/12 to generate poly1305 key)
|
2014-10-02 17:54:34 +00:00
|
|
|
*/
|
2019-08-15 22:32:16 +00:00
|
|
|
#define ZT_PROTO_CIPHER_SUITE__POLY1305_NONE 0
|
2014-10-02 17:54:34 +00:00
|
|
|
|
|
|
|
/**
|
2019-08-15 22:43:35 +00:00
|
|
|
* Salsa2012/Poly1305
|
2014-10-02 17:54:34 +00:00
|
|
|
*/
|
2019-08-15 22:32:16 +00:00
|
|
|
#define ZT_PROTO_CIPHER_SUITE__POLY1305_SALSA2012 1
|
2014-10-02 17:54:34 +00:00
|
|
|
|
|
|
|
/**
|
2019-09-08 02:15:21 +00:00
|
|
|
* No encryption or authentication at all
|
2014-10-02 17:54:34 +00:00
|
|
|
*
|
2019-09-08 02:15:21 +00:00
|
|
|
* For trusted paths the MAC field is the trusted path ID.
|
2016-07-12 15:29:50 +00:00
|
|
|
*/
|
2019-09-08 02:15:21 +00:00
|
|
|
#define ZT_PROTO_CIPHER_SUITE__NONE 2
|
2016-07-12 15:29:50 +00:00
|
|
|
|
|
|
|
/**
|
2019-09-08 02:15:21 +00:00
|
|
|
* AES-GMAC_SIV with AES-256
|
2014-10-02 17:54:34 +00:00
|
|
|
*/
|
2019-09-08 02:15:21 +00:00
|
|
|
#define ZT_PROTO_CIPHER_SUITE__AES256_GMAC_SIV 3
|
2014-10-02 17:54:34 +00:00
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
/**
|
|
|
|
* Header flag indicating that a packet is fragmented
|
|
|
|
*
|
|
|
|
* If this flag is set, the receiver knows to expect more than one fragment.
|
|
|
|
* See Packet::Fragment for details.
|
|
|
|
*/
|
|
|
|
#define ZT_PROTO_FLAG_FRAGMENTED 0x40
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verb flag indicating payload is compressed with LZ4
|
|
|
|
*/
|
|
|
|
#define ZT_PROTO_VERB_FLAG_COMPRESSED 0x80
|
|
|
|
|
2015-07-06 19:34:35 +00:00
|
|
|
// Field indexes in packet header
|
2013-07-04 20:56:19 +00:00
|
|
|
#define ZT_PACKET_IDX_IV 0
|
|
|
|
#define ZT_PACKET_IDX_DEST 8
|
|
|
|
#define ZT_PACKET_IDX_SOURCE 13
|
|
|
|
#define ZT_PACKET_IDX_FLAGS 18
|
2013-09-16 17:02:10 +00:00
|
|
|
#define ZT_PACKET_IDX_MAC 19
|
2013-07-04 20:56:19 +00:00
|
|
|
#define ZT_PACKET_IDX_VERB 27
|
|
|
|
#define ZT_PACKET_IDX_PAYLOAD 28
|
|
|
|
|
|
|
|
/**
|
2013-09-26 21:45:19 +00:00
|
|
|
* Packet buffer size (can be changed)
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
2017-09-01 23:25:34 +00:00
|
|
|
#define ZT_PROTO_MAX_PACKET_LENGTH (ZT_MAX_PACKET_FRAGMENTS * ZT_DEFAULT_PHYSMTU)
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-06 19:34:35 +00:00
|
|
|
* Minimum viable packet length (a.k.a. header length)
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
|
|
|
#define ZT_PROTO_MIN_PACKET_LENGTH ZT_PACKET_IDX_PAYLOAD
|
|
|
|
|
2015-07-06 19:34:35 +00:00
|
|
|
// Indexes of fields in fragment header
|
2013-07-04 20:56:19 +00:00
|
|
|
#define ZT_PACKET_FRAGMENT_IDX_PACKET_ID 0
|
|
|
|
#define ZT_PACKET_FRAGMENT_IDX_DEST 8
|
|
|
|
#define ZT_PACKET_FRAGMENT_IDX_FRAGMENT_INDICATOR 13
|
|
|
|
#define ZT_PACKET_FRAGMENT_IDX_FRAGMENT_NO 14
|
|
|
|
#define ZT_PACKET_FRAGMENT_IDX_HOPS 15
|
|
|
|
#define ZT_PACKET_FRAGMENT_IDX_PAYLOAD 16
|
|
|
|
|
|
|
|
/**
|
2015-07-06 19:34:35 +00:00
|
|
|
* Magic number found at ZT_PACKET_FRAGMENT_IDX_FRAGMENT_INDICATOR
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
|
|
|
#define ZT_PACKET_FRAGMENT_INDICATOR ZT_ADDRESS_RESERVED_PREFIX
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Minimum viable fragment length
|
|
|
|
*/
|
|
|
|
#define ZT_PROTO_MIN_FRAGMENT_LENGTH ZT_PACKET_FRAGMENT_IDX_PAYLOAD
|
|
|
|
|
2018-06-08 00:25:27 +00:00
|
|
|
// Field indices for parsing verbs -------------------------------------------
|
2013-08-02 21:17:34 +00:00
|
|
|
|
2014-09-26 21:18:25 +00:00
|
|
|
// Some verbs have variable-length fields. Those aren't fully defined here
|
|
|
|
// yet-- instead they are parsed using relative indexes in IncomingPacket.
|
|
|
|
// See their respective handler functions.
|
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
#define ZT_PROTO_VERB_HELLO_IDX_PROTOCOL_VERSION (ZT_PACKET_IDX_PAYLOAD)
|
|
|
|
#define ZT_PROTO_VERB_HELLO_IDX_MAJOR_VERSION (ZT_PROTO_VERB_HELLO_IDX_PROTOCOL_VERSION + 1)
|
|
|
|
#define ZT_PROTO_VERB_HELLO_IDX_MINOR_VERSION (ZT_PROTO_VERB_HELLO_IDX_MAJOR_VERSION + 1)
|
|
|
|
#define ZT_PROTO_VERB_HELLO_IDX_REVISION (ZT_PROTO_VERB_HELLO_IDX_MINOR_VERSION + 1)
|
|
|
|
#define ZT_PROTO_VERB_HELLO_IDX_TIMESTAMP (ZT_PROTO_VERB_HELLO_IDX_REVISION + 2)
|
|
|
|
#define ZT_PROTO_VERB_HELLO_IDX_IDENTITY (ZT_PROTO_VERB_HELLO_IDX_TIMESTAMP + 8)
|
2013-08-02 21:17:34 +00:00
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
#define ZT_PROTO_VERB_ERROR_IDX_IN_RE_VERB (ZT_PACKET_IDX_PAYLOAD)
|
|
|
|
#define ZT_PROTO_VERB_ERROR_IDX_IN_RE_PACKET_ID (ZT_PROTO_VERB_ERROR_IDX_IN_RE_VERB + 1)
|
|
|
|
#define ZT_PROTO_VERB_ERROR_IDX_ERROR_CODE (ZT_PROTO_VERB_ERROR_IDX_IN_RE_PACKET_ID + 8)
|
|
|
|
#define ZT_PROTO_VERB_ERROR_IDX_PAYLOAD (ZT_PROTO_VERB_ERROR_IDX_ERROR_CODE + 1)
|
2013-08-02 21:17:34 +00:00
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
#define ZT_PROTO_VERB_OK_IDX_IN_RE_VERB (ZT_PACKET_IDX_PAYLOAD)
|
|
|
|
#define ZT_PROTO_VERB_OK_IDX_IN_RE_PACKET_ID (ZT_PROTO_VERB_OK_IDX_IN_RE_VERB + 1)
|
|
|
|
#define ZT_PROTO_VERB_OK_IDX_PAYLOAD (ZT_PROTO_VERB_OK_IDX_IN_RE_PACKET_ID + 8)
|
2013-08-02 21:17:34 +00:00
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
#define ZT_PROTO_VERB_WHOIS_IDX_ZTADDRESS (ZT_PACKET_IDX_PAYLOAD)
|
2013-08-02 21:17:34 +00:00
|
|
|
|
2013-10-17 10:41:52 +00:00
|
|
|
#define ZT_PROTO_VERB_RENDEZVOUS_IDX_FLAGS (ZT_PACKET_IDX_PAYLOAD)
|
|
|
|
#define ZT_PROTO_VERB_RENDEZVOUS_IDX_ZTADDRESS (ZT_PROTO_VERB_RENDEZVOUS_IDX_FLAGS + 1)
|
2013-07-04 20:56:19 +00:00
|
|
|
#define ZT_PROTO_VERB_RENDEZVOUS_IDX_PORT (ZT_PROTO_VERB_RENDEZVOUS_IDX_ZTADDRESS + 5)
|
|
|
|
#define ZT_PROTO_VERB_RENDEZVOUS_IDX_ADDRLEN (ZT_PROTO_VERB_RENDEZVOUS_IDX_PORT + 2)
|
|
|
|
#define ZT_PROTO_VERB_RENDEZVOUS_IDX_ADDRESS (ZT_PROTO_VERB_RENDEZVOUS_IDX_ADDRLEN + 1)
|
2013-08-02 21:17:34 +00:00
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
#define ZT_PROTO_VERB_FRAME_IDX_NETWORK_ID (ZT_PACKET_IDX_PAYLOAD)
|
|
|
|
#define ZT_PROTO_VERB_FRAME_IDX_ETHERTYPE (ZT_PROTO_VERB_FRAME_IDX_NETWORK_ID + 8)
|
|
|
|
#define ZT_PROTO_VERB_FRAME_IDX_PAYLOAD (ZT_PROTO_VERB_FRAME_IDX_ETHERTYPE + 2)
|
2013-08-02 21:17:34 +00:00
|
|
|
|
2014-06-11 04:41:34 +00:00
|
|
|
#define ZT_PROTO_VERB_EXT_FRAME_IDX_NETWORK_ID (ZT_PACKET_IDX_PAYLOAD)
|
|
|
|
#define ZT_PROTO_VERB_EXT_FRAME_LEN_NETWORK_ID 8
|
2014-06-12 18:40:30 +00:00
|
|
|
#define ZT_PROTO_VERB_EXT_FRAME_IDX_FLAGS (ZT_PROTO_VERB_EXT_FRAME_IDX_NETWORK_ID + ZT_PROTO_VERB_EXT_FRAME_LEN_NETWORK_ID)
|
|
|
|
#define ZT_PROTO_VERB_EXT_FRAME_LEN_FLAGS 1
|
2014-09-30 23:28:25 +00:00
|
|
|
#define ZT_PROTO_VERB_EXT_FRAME_IDX_COM (ZT_PROTO_VERB_EXT_FRAME_IDX_FLAGS + ZT_PROTO_VERB_EXT_FRAME_LEN_FLAGS)
|
2014-06-12 18:40:30 +00:00
|
|
|
#define ZT_PROTO_VERB_EXT_FRAME_IDX_TO (ZT_PROTO_VERB_EXT_FRAME_IDX_FLAGS + ZT_PROTO_VERB_EXT_FRAME_LEN_FLAGS)
|
2014-06-11 04:41:34 +00:00
|
|
|
#define ZT_PROTO_VERB_EXT_FRAME_LEN_TO 6
|
|
|
|
#define ZT_PROTO_VERB_EXT_FRAME_IDX_FROM (ZT_PROTO_VERB_EXT_FRAME_IDX_TO + ZT_PROTO_VERB_EXT_FRAME_LEN_TO)
|
|
|
|
#define ZT_PROTO_VERB_EXT_FRAME_LEN_FROM 6
|
|
|
|
#define ZT_PROTO_VERB_EXT_FRAME_IDX_ETHERTYPE (ZT_PROTO_VERB_EXT_FRAME_IDX_FROM + ZT_PROTO_VERB_EXT_FRAME_LEN_FROM)
|
|
|
|
#define ZT_PROTO_VERB_EXT_FRAME_LEN_ETHERTYPE 2
|
2014-06-21 16:25:10 +00:00
|
|
|
#define ZT_PROTO_VERB_EXT_FRAME_IDX_PAYLOAD (ZT_PROTO_VERB_EXT_FRAME_IDX_ETHERTYPE + ZT_PROTO_VERB_EXT_FRAME_LEN_ETHERTYPE)
|
2014-06-11 04:41:34 +00:00
|
|
|
|
2013-08-02 21:17:34 +00:00
|
|
|
#define ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_NETWORK_ID (ZT_PACKET_IDX_PAYLOAD)
|
|
|
|
#define ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN (ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_NETWORK_ID + 8)
|
|
|
|
#define ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT (ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST_IDX_DICT_LEN + 2)
|
|
|
|
|
2014-09-26 21:18:25 +00:00
|
|
|
#define ZT_PROTO_VERB_MULTICAST_GATHER_IDX_NETWORK_ID (ZT_PACKET_IDX_PAYLOAD)
|
|
|
|
#define ZT_PROTO_VERB_MULTICAST_GATHER_IDX_FLAGS (ZT_PROTO_VERB_MULTICAST_GATHER_IDX_NETWORK_ID + 8)
|
|
|
|
#define ZT_PROTO_VERB_MULTICAST_GATHER_IDX_MAC (ZT_PROTO_VERB_MULTICAST_GATHER_IDX_FLAGS + 1)
|
|
|
|
#define ZT_PROTO_VERB_MULTICAST_GATHER_IDX_ADI (ZT_PROTO_VERB_MULTICAST_GATHER_IDX_MAC + 6)
|
|
|
|
#define ZT_PROTO_VERB_MULTICAST_GATHER_IDX_GATHER_LIMIT (ZT_PROTO_VERB_MULTICAST_GATHER_IDX_ADI + 4)
|
2016-08-23 18:29:02 +00:00
|
|
|
#define ZT_PROTO_VERB_MULTICAST_GATHER_IDX_COM (ZT_PROTO_VERB_MULTICAST_GATHER_IDX_GATHER_LIMIT + 4)
|
2014-09-26 21:18:25 +00:00
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
#define ZT_PROTO_VERB_HELLO__OK__IDX_TIMESTAMP (ZT_PROTO_VERB_OK_IDX_PAYLOAD)
|
2013-09-20 17:36:14 +00:00
|
|
|
#define ZT_PROTO_VERB_HELLO__OK__IDX_PROTOCOL_VERSION (ZT_PROTO_VERB_HELLO__OK__IDX_TIMESTAMP + 8)
|
|
|
|
#define ZT_PROTO_VERB_HELLO__OK__IDX_MAJOR_VERSION (ZT_PROTO_VERB_HELLO__OK__IDX_PROTOCOL_VERSION + 1)
|
|
|
|
#define ZT_PROTO_VERB_HELLO__OK__IDX_MINOR_VERSION (ZT_PROTO_VERB_HELLO__OK__IDX_MAJOR_VERSION + 1)
|
|
|
|
#define ZT_PROTO_VERB_HELLO__OK__IDX_REVISION (ZT_PROTO_VERB_HELLO__OK__IDX_MINOR_VERSION + 1)
|
2013-08-03 16:53:46 +00:00
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
#define ZT_PROTO_VERB_WHOIS__OK__IDX_IDENTITY (ZT_PROTO_VERB_OK_IDX_PAYLOAD)
|
2013-08-03 16:53:46 +00:00
|
|
|
|
|
|
|
#define ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_NETWORK_ID (ZT_PROTO_VERB_OK_IDX_PAYLOAD)
|
|
|
|
#define ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_DICT_LEN (ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_NETWORK_ID + 8)
|
|
|
|
#define ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_DICT (ZT_PROTO_VERB_NETWORK_CONFIG_REQUEST__OK__IDX_DICT_LEN + 2)
|
|
|
|
|
2014-10-02 20:50:37 +00:00
|
|
|
#define ZT_PROTO_VERB_MULTICAST_GATHER__OK__IDX_NETWORK_ID (ZT_PROTO_VERB_OK_IDX_PAYLOAD)
|
|
|
|
#define ZT_PROTO_VERB_MULTICAST_GATHER__OK__IDX_MAC (ZT_PROTO_VERB_MULTICAST_GATHER__OK__IDX_NETWORK_ID + 8)
|
|
|
|
#define ZT_PROTO_VERB_MULTICAST_GATHER__OK__IDX_ADI (ZT_PROTO_VERB_MULTICAST_GATHER__OK__IDX_MAC + 6)
|
|
|
|
#define ZT_PROTO_VERB_MULTICAST_GATHER__OK__IDX_GATHER_RESULTS (ZT_PROTO_VERB_MULTICAST_GATHER__OK__IDX_ADI + 4)
|
|
|
|
|
|
|
|
#define ZT_PROTO_VERB_MULTICAST_FRAME__OK__IDX_NETWORK_ID (ZT_PROTO_VERB_OK_IDX_PAYLOAD)
|
|
|
|
#define ZT_PROTO_VERB_MULTICAST_FRAME__OK__IDX_MAC (ZT_PROTO_VERB_MULTICAST_FRAME__OK__IDX_NETWORK_ID + 8)
|
|
|
|
#define ZT_PROTO_VERB_MULTICAST_FRAME__OK__IDX_ADI (ZT_PROTO_VERB_MULTICAST_FRAME__OK__IDX_MAC + 6)
|
|
|
|
#define ZT_PROTO_VERB_MULTICAST_FRAME__OK__IDX_FLAGS (ZT_PROTO_VERB_MULTICAST_FRAME__OK__IDX_ADI + 4)
|
2014-10-29 23:24:19 +00:00
|
|
|
#define ZT_PROTO_VERB_MULTICAST_FRAME__OK__IDX_COM_AND_GATHER_RESULTS (ZT_PROTO_VERB_MULTICAST_FRAME__OK__IDX_FLAGS + 1)
|
2014-10-02 20:50:37 +00:00
|
|
|
|
2013-08-03 16:53:46 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
namespace ZeroTier {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ZeroTier packet
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* Packet format:
|
2019-09-05 19:17:04 +00:00
|
|
|
* <[8] 64-bit packet ID / crypto IV>
|
2013-07-04 20:56:19 +00:00
|
|
|
* <[5] destination ZT address>
|
|
|
|
* <[5] source ZT address>
|
2016-04-28 19:31:10 +00:00
|
|
|
* <[1] flags/cipher/hops>
|
2016-07-12 15:29:50 +00:00
|
|
|
* <[8] 64-bit MAC (or trusted path ID in trusted path mode)>
|
2013-07-04 20:56:19 +00:00
|
|
|
* [... -- begin encryption envelope -- ...]
|
2016-04-28 19:31:10 +00:00
|
|
|
* <[1] encrypted flags (MS 3 bits) and verb (LS 5 bits)>
|
2013-07-04 20:56:19 +00:00
|
|
|
* [... verb-specific payload ...]
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* Packets smaller than 28 bytes are invalid and silently discarded.
|
|
|
|
*
|
2017-03-01 18:22:57 +00:00
|
|
|
* The 64-bit packet ID is a strongly random value used as a crypto IV.
|
|
|
|
* Its least significant 3 bits are also used as a monotonically increasing
|
|
|
|
* (and looping) counter for sending packets to a particular recipient. This
|
|
|
|
* can be used for link quality monitoring and reporting and has no crypto
|
|
|
|
* impact as it does not increase the likelihood of an IV collision. (The
|
|
|
|
* crypto we use is not sensitive to the nature of the IV, only that it does
|
|
|
|
* not repeat.)
|
|
|
|
*
|
2015-05-15 00:41:05 +00:00
|
|
|
* The flags/cipher/hops bit field is: FFCCCHHH where C is a 3-bit cipher
|
|
|
|
* selection allowing up to 7 cipher suites, F is outside-envelope flags,
|
2015-05-14 01:53:37 +00:00
|
|
|
* and H is hop count.
|
2014-10-02 17:54:34 +00:00
|
|
|
*
|
|
|
|
* The three-bit hop count is the only part of a packet that is mutable in
|
|
|
|
* transit without invalidating the MAC. All other bits in the packet are
|
|
|
|
* immutable. This is because intermediate nodes can increment the hop
|
|
|
|
* count up to 7 (protocol max).
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
|
|
|
* For unencrypted packets, MAC is computed on plaintext. Only HELLO is ever
|
|
|
|
* sent in the clear, as it's the "here is my public key" message.
|
|
|
|
*/
|
|
|
|
class Packet : public Buffer<ZT_PROTO_MAX_PACKET_LENGTH>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* A packet fragment
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* Fragments are sent if a packet is larger than UDP MTU. The first fragment
|
|
|
|
* is sent with its normal header with the fragmented flag set. Remaining
|
|
|
|
* fragments are sent this way.
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* The fragmented bit indicates that there is at least one fragment. Fragments
|
|
|
|
* themselves contain the total, so the receiver must "learn" this from the
|
|
|
|
* first fragment it receives.
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* Fragments are sent with the following format:
|
|
|
|
* <[8] packet ID of packet whose fragment this belongs to>
|
|
|
|
* <[5] destination ZT address>
|
|
|
|
* <[1] 0xff, a reserved address, signals that this isn't a normal packet>
|
|
|
|
* <[1] total fragments (most significant 4 bits), fragment no (LS 4 bits)>
|
2014-10-02 17:54:34 +00:00
|
|
|
* <[1] ZT hop count (top 5 bits unused and must be zero)>
|
2013-07-04 20:56:19 +00:00
|
|
|
* <[...] fragment data>
|
|
|
|
*
|
|
|
|
* The protocol supports a maximum of 16 fragments. If a fragment is received
|
|
|
|
* before its main packet header, it should be cached for a brief period of
|
|
|
|
* time to see if its parent arrives. Loss of any fragment constitutes packet
|
|
|
|
* loss; there is no retransmission mechanism. The receiver must wait for full
|
|
|
|
* receipt to authenticate and decrypt; there is no per-fragment MAC. (But if
|
|
|
|
* fragments are corrupt, the MAC will fail for the whole assembled packet.)
|
|
|
|
*/
|
|
|
|
class Fragment : public Buffer<ZT_PROTO_MAX_PACKET_LENGTH>
|
|
|
|
{
|
|
|
|
public:
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Fragment() :
|
2019-08-28 18:28:51 +00:00
|
|
|
Buffer<ZT_PROTO_MAX_PACKET_LENGTH>() {}
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
template<unsigned int C2>
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Fragment(const Buffer<C2> &b) :
|
2019-08-28 18:28:51 +00:00
|
|
|
Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(b) {}
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Fragment(const void *data,unsigned int len) :
|
2019-08-28 18:28:51 +00:00
|
|
|
Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(data,len) {}
|
2015-04-08 02:31:11 +00:00
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
/**
|
|
|
|
* Initialize from a packet
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @param p Original assembled packet
|
|
|
|
* @param fragStart Start of fragment (raw index in packet data)
|
|
|
|
* @param fragLen Length of fragment in bytes
|
|
|
|
* @param fragNo Which fragment (>= 1, since 0 is Packet with end chopped off)
|
|
|
|
* @param fragTotal Total number of fragments (including 0)
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Fragment(const Packet &p,unsigned int fragStart,unsigned int fragLen,unsigned int fragNo,unsigned int fragTotal)
|
2013-07-04 20:56:19 +00:00
|
|
|
{
|
|
|
|
init(p,fragStart,fragLen,fragNo,fragTotal);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize from a packet
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @param p Original assembled packet
|
|
|
|
* @param fragStart Start of fragment (raw index in packet data)
|
|
|
|
* @param fragLen Length of fragment in bytes
|
|
|
|
* @param fragNo Which fragment (>= 1, since 0 is Packet with end chopped off)
|
|
|
|
* @param fragTotal Total number of fragments (including 0)
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE void init(const Packet &p,unsigned int fragStart,unsigned int fragLen,unsigned int fragNo,unsigned int fragTotal)
|
2013-07-04 20:56:19 +00:00
|
|
|
{
|
|
|
|
if ((fragStart + fragLen) > p.size())
|
2017-07-17 21:21:09 +00:00
|
|
|
throw ZT_EXCEPTION_OUT_OF_BOUNDS;
|
2013-07-04 20:56:19 +00:00
|
|
|
setSize(fragLen + ZT_PROTO_MIN_FRAGMENT_LENGTH);
|
|
|
|
|
|
|
|
// NOTE: this copies both the IV/packet ID and the destination address.
|
2014-10-29 00:25:34 +00:00
|
|
|
memcpy(field(ZT_PACKET_FRAGMENT_IDX_PACKET_ID,13),p.field(ZT_PACKET_IDX_IV,13),13);
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2013-07-09 18:06:55 +00:00
|
|
|
(*this)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_INDICATOR] = ZT_PACKET_FRAGMENT_INDICATOR;
|
|
|
|
(*this)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_NO] = (char)(((fragTotal & 0xf) << 4) | (fragNo & 0xf));
|
|
|
|
(*this)[ZT_PACKET_FRAGMENT_IDX_HOPS] = 0;
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2014-10-29 00:25:34 +00:00
|
|
|
memcpy(field(ZT_PACKET_FRAGMENT_IDX_PAYLOAD,fragLen),p.field(fragStart,fragLen),fragLen);
|
2013-07-04 20:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get this fragment's destination
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @return Destination ZT address
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Address destination() const { return Address(field(ZT_PACKET_FRAGMENT_IDX_DEST,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return True if fragment is of a valid length
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE bool lengthValid() const { return (size() >= ZT_PACKET_FRAGMENT_IDX_PAYLOAD); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ID of packet this is a fragment of
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE uint64_t packetId() const { return at<uint64_t>(ZT_PACKET_FRAGMENT_IDX_PACKET_ID); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Total number of fragments in packet
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE unsigned int totalFragments() const { return (((unsigned int)((*this)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_NO]) >> 4) & 0xf); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Fragment number of this fragment
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE unsigned int fragmentNumber() const { return ((unsigned int)((*this)[ZT_PACKET_FRAGMENT_IDX_FRAGMENT_NO]) & 0xf); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Fragment ZT hop count
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE unsigned int hops() const { return (unsigned int)((*this)[ZT_PACKET_FRAGMENT_IDX_HOPS]); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Increment this packet's hop count
|
|
|
|
*/
|
2019-08-28 20:04:58 +00:00
|
|
|
ZT_ALWAYS_INLINE unsigned int incrementHops()
|
2013-07-04 20:56:19 +00:00
|
|
|
{
|
2019-08-28 20:04:58 +00:00
|
|
|
return (unsigned int)((*this)[ZT_PACKET_FRAGMENT_IDX_HOPS] = (((*this)[ZT_PACKET_FRAGMENT_IDX_HOPS]) + 1));
|
2013-07-04 20:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-09 18:06:55 +00:00
|
|
|
* @return Length of payload in bytes
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE unsigned int payloadLength() const { return ((size() > ZT_PACKET_FRAGMENT_IDX_PAYLOAD) ? (size() - ZT_PACKET_FRAGMENT_IDX_PAYLOAD) : 0); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
2013-07-09 18:06:55 +00:00
|
|
|
* @return Raw packet payload
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
2019-08-28 18:28:51 +00:00
|
|
|
ZT_ALWAYS_INLINE const unsigned char *payload() const { return field(ZT_PACKET_FRAGMENT_IDX_PAYLOAD,size() - ZT_PACKET_FRAGMENT_IDX_PAYLOAD); }
|
2013-07-04 20:56:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ZeroTier protocol verbs
|
|
|
|
*/
|
|
|
|
enum Verb /* Max value: 32 (5 bits) */
|
|
|
|
{
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
|
|
|
* No operation (ignored, no reply)
|
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_NOP = 0x00,
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
2017-02-04 21:17:00 +00:00
|
|
|
* Announcement of a node's existence and vitals:
|
2013-07-06 17:34:35 +00:00
|
|
|
* <[1] protocol version>
|
2013-07-04 20:56:19 +00:00
|
|
|
* <[1] software major version>
|
|
|
|
* <[1] software minor version>
|
|
|
|
* <[2] software revision>
|
2017-02-04 18:21:31 +00:00
|
|
|
* <[8] timestamp for determining latency>
|
2013-07-06 17:34:35 +00:00
|
|
|
* <[...] binary serialized identity (see Identity)>
|
2017-02-06 15:17:45 +00:00
|
|
|
* <[...] physical destination address of packet>
|
2019-08-20 22:34:30 +00:00
|
|
|
*
|
2017-02-06 15:17:45 +00:00
|
|
|
* HELLO is sent in the clear as it is how peers share their identity
|
2019-07-17 15:52:08 +00:00
|
|
|
* public keys.
|
2015-04-07 03:17:21 +00:00
|
|
|
*
|
2017-02-06 15:17:45 +00:00
|
|
|
* Destination address is the actual wire address to which the packet
|
|
|
|
* was sent. See InetAddress::serialize() for format.
|
2015-04-07 03:17:21 +00:00
|
|
|
*
|
2017-02-06 15:17:45 +00:00
|
|
|
* OK payload:
|
|
|
|
* <[8] HELLO timestamp field echo>
|
|
|
|
* <[1] protocol version>
|
|
|
|
* <[1] software major version>
|
|
|
|
* <[1] software minor version>
|
|
|
|
* <[2] software revision>
|
|
|
|
* <[...] physical destination address of packet>
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
2017-02-06 15:17:45 +00:00
|
|
|
* With the exception of the timestamp, the other fields pertain to the
|
|
|
|
* respondent who is sending OK and are not echoes.
|
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* ERROR has no payload.
|
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_HELLO = 0x01,
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
|
|
|
* Error response:
|
2013-07-06 17:34:35 +00:00
|
|
|
* <[1] in-re verb>
|
|
|
|
* <[8] in-re packet ID>
|
|
|
|
* <[1] error code>
|
|
|
|
* <[...] error-dependent payload>
|
2019-09-03 21:44:13 +00:00
|
|
|
*
|
|
|
|
* If this is not in response to a single packet then verb can be
|
|
|
|
* NOP and packet ID can be zero.
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_ERROR = 0x02,
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
|
|
|
* Success response:
|
2013-07-06 17:34:35 +00:00
|
|
|
* <[1] in-re verb>
|
|
|
|
* <[8] in-re packet ID>
|
|
|
|
* <[...] request-specific payload>
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_OK = 0x03,
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
|
|
|
* Query an identity by address:
|
2013-07-06 17:34:35 +00:00
|
|
|
* <[5] address to look up>
|
2016-08-23 18:29:02 +00:00
|
|
|
* [<[...] additional addresses to look up>
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
|
|
|
* OK response payload:
|
2013-07-06 17:34:35 +00:00
|
|
|
* <[...] binary serialized identity>
|
2016-08-23 18:29:02 +00:00
|
|
|
* [<[...] additional binary serialized identities>]
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
2015-11-08 21:57:02 +00:00
|
|
|
* If querying a cluster, duplicate OK responses may occasionally occur.
|
2016-08-23 18:29:02 +00:00
|
|
|
* These must be tolerated, which is easy since they'll have info you
|
|
|
|
* already have.
|
2015-11-08 21:57:02 +00:00
|
|
|
*
|
2016-08-23 18:29:02 +00:00
|
|
|
* If the address is not found, no response is generated. The semantics
|
|
|
|
* of WHOIS is similar to ARP and NDP in that persistent retrying can
|
|
|
|
* be performed.
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_WHOIS = 0x04,
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
2016-08-23 18:29:02 +00:00
|
|
|
* Relay-mediated NAT traversal or firewall punching initiation:
|
2013-10-17 10:41:52 +00:00
|
|
|
* <[1] flags (unused, currently 0)>
|
2013-07-04 20:56:19 +00:00
|
|
|
* <[5] ZeroTier address of peer that might be found at this address>
|
|
|
|
* <[2] 16-bit protocol address port>
|
|
|
|
* <[1] protocol address length (4 for IPv4, 16 for IPv6)>
|
|
|
|
* <[...] protocol address (network byte order)>
|
|
|
|
*
|
2016-11-18 00:20:41 +00:00
|
|
|
* An upstream node can send this to inform both sides of a relay of
|
|
|
|
* information they might use to establish a direct connection.
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
2013-12-31 19:03:45 +00:00
|
|
|
* Upon receipt a peer sends HELLO to establish a direct link.
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
|
|
|
* No OK or ERROR is generated.
|
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_RENDEZVOUS = 0x05,
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
|
|
|
* ZT-to-ZT unicast ethernet frame (shortened EXT_FRAME):
|
2013-07-04 20:56:19 +00:00
|
|
|
* <[8] 64-bit network ID>
|
2013-07-06 17:34:35 +00:00
|
|
|
* <[2] 16-bit ethertype>
|
|
|
|
* <[...] ethernet payload>
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
|
|
|
* MAC addresses are derived from the packet's source and destination
|
2014-09-30 15:38:03 +00:00
|
|
|
* ZeroTier addresses. This is a shortened EXT_FRAME that elides full
|
|
|
|
* Ethernet framing and other optional flags and features when they
|
|
|
|
* are not necessary.
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
2013-09-27 20:03:13 +00:00
|
|
|
* ERROR may be generated if a membership certificate is needed for a
|
|
|
|
* closed network. Payload will be network ID.
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_FRAME = 0x06,
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
|
|
|
* Full Ethernet frame with MAC addressing and optional fields:
|
2014-06-10 22:25:15 +00:00
|
|
|
* <[8] 64-bit network ID>
|
2014-09-30 15:38:03 +00:00
|
|
|
* <[1] flags>
|
2014-06-10 22:25:15 +00:00
|
|
|
* <[6] destination MAC or all zero for destination node>
|
|
|
|
* <[6] source MAC or all zero for node of origin>
|
|
|
|
* <[2] 16-bit ethertype>
|
|
|
|
* <[...] ethernet payload>
|
|
|
|
*
|
2014-09-30 15:38:03 +00:00
|
|
|
* Flags:
|
2016-08-04 01:04:08 +00:00
|
|
|
* 0x01 - Certificate of network membership attached (DEPRECATED)
|
2016-09-23 23:08:38 +00:00
|
|
|
* 0x02 - Most significant bit of subtype (see below)
|
|
|
|
* 0x04 - Middle bit of subtype (see below)
|
|
|
|
* 0x08 - Least significant bit of subtype (see below)
|
|
|
|
* 0x10 - ACK requested in the form of OK(EXT_FRAME)
|
|
|
|
*
|
|
|
|
* Subtypes (0..7):
|
|
|
|
* 0x0 - Normal frame (bridging can be determined by checking MAC)
|
|
|
|
* 0x1 - TEEd outbound frame
|
|
|
|
* 0x2 - REDIRECTed outbound frame
|
|
|
|
* 0x3 - WATCHed outbound frame (TEE with ACK, ACK bit also set)
|
|
|
|
* 0x4 - TEEd inbound frame
|
|
|
|
* 0x5 - REDIRECTed inbound frame
|
|
|
|
* 0x6 - WATCHed inbound frame
|
|
|
|
* 0x7 - (reserved for future use)
|
2017-10-24 21:57:02 +00:00
|
|
|
*
|
2016-09-27 00:05:39 +00:00
|
|
|
* An extended frame carries full MAC addressing, making it a
|
|
|
|
* superset of VERB_FRAME. It is used for bridged traffic,
|
|
|
|
* redirected or observed traffic via rules, and can in theory
|
|
|
|
* be used for multicast though MULTICAST_FRAME exists for that
|
|
|
|
* purpose and has additional options and capabilities.
|
2014-06-10 22:25:15 +00:00
|
|
|
*
|
2016-09-26 23:17:02 +00:00
|
|
|
* OK payload (if ACK flag is set):
|
|
|
|
* <[8] 64-bit network ID>
|
2014-06-10 22:25:15 +00:00
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_EXT_FRAME = 0x07,
|
2013-07-11 02:58:43 +00:00
|
|
|
|
2015-10-07 23:11:50 +00:00
|
|
|
/**
|
|
|
|
* ECHO request (a.k.a. ping):
|
2016-01-06 00:41:54 +00:00
|
|
|
* <[...] arbitrary payload>
|
2015-10-07 23:11:50 +00:00
|
|
|
*
|
|
|
|
* This generates OK with a copy of the transmitted payload. No ERROR
|
2015-12-22 00:15:39 +00:00
|
|
|
* is generated. Response to ECHO requests is optional and ECHO may be
|
|
|
|
* ignored if a node detects a possible flood.
|
2015-10-07 23:11:50 +00:00
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_ECHO = 0x08,
|
2013-09-26 21:45:19 +00:00
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
|
|
|
* Announce interest in multicast group(s):
|
2013-09-26 21:45:19 +00:00
|
|
|
* <[8] 64-bit network ID>
|
|
|
|
* <[6] multicast Ethernet address>
|
|
|
|
* <[4] multicast additional distinguishing information (ADI)>
|
|
|
|
* [... additional tuples of network/address/adi ...]
|
|
|
|
*
|
|
|
|
* OK/ERROR are not generated.
|
2013-07-11 02:58:43 +00:00
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_MULTICAST_LIKE = 0x09,
|
2013-07-27 20:20:08 +00:00
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
2016-09-23 23:08:38 +00:00
|
|
|
* Network credentials push:
|
2017-03-06 23:12:28 +00:00
|
|
|
* [<[...] one or more certificates of membership>]
|
2016-08-04 16:51:15 +00:00
|
|
|
* <[1] 0x00, null byte marking end of COM array>
|
2016-08-04 01:04:08 +00:00
|
|
|
* <[2] 16-bit number of capabilities>
|
|
|
|
* <[...] one or more serialized Capability>
|
|
|
|
* <[2] 16-bit number of tags>
|
|
|
|
* <[...] one or more serialized Tags>
|
2016-09-23 23:08:38 +00:00
|
|
|
* <[2] 16-bit number of revocations>
|
|
|
|
* <[...] one or more serialized Revocations>
|
2017-02-23 19:47:36 +00:00
|
|
|
* <[2] 16-bit number of certificates of ownership>
|
|
|
|
* <[...] one or more serialized CertificateOfOwnership>
|
2013-07-27 20:20:08 +00:00
|
|
|
*
|
2016-09-23 23:08:38 +00:00
|
|
|
* This can be sent by anyone at any time to push network credentials.
|
|
|
|
* These will of course only be accepted if they are properly signed.
|
|
|
|
* Credentials can be for any number of networks.
|
2016-08-23 18:29:02 +00:00
|
|
|
*
|
2016-09-27 00:05:39 +00:00
|
|
|
* The use of a zero byte to terminate the COM section is for legacy
|
2018-06-08 00:25:27 +00:00
|
|
|
* backward compatibility. Newer fields are prefixed with a length.
|
2016-09-27 00:05:39 +00:00
|
|
|
*
|
2015-07-07 17:00:34 +00:00
|
|
|
* OK/ERROR are not generated.
|
2013-07-27 20:20:08 +00:00
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_NETWORK_CREDENTIALS = 0x0a,
|
2013-07-29 17:56:20 +00:00
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
2016-08-04 01:04:08 +00:00
|
|
|
* Network configuration request:
|
|
|
|
* <[8] 64-bit network ID>
|
|
|
|
* <[2] 16-bit length of request meta-data dictionary>
|
|
|
|
* <[...] string-serialized request meta-data>
|
2016-08-10 00:00:01 +00:00
|
|
|
* <[8] 64-bit revision of netconf we currently have>
|
2016-08-09 16:34:13 +00:00
|
|
|
* <[8] 64-bit timestamp of netconf we currently have>
|
2013-07-29 17:56:20 +00:00
|
|
|
*
|
2016-08-04 01:04:08 +00:00
|
|
|
* This message requests network configuration from a node capable of
|
2016-09-26 23:17:02 +00:00
|
|
|
* providing it.
|
|
|
|
*
|
2018-06-08 00:25:27 +00:00
|
|
|
* Responses to this are always whole configs intended for the recipient.
|
2016-09-26 23:17:02 +00:00
|
|
|
* For patches and other updates a NETWORK_CONFIG is sent instead.
|
2013-07-29 17:56:20 +00:00
|
|
|
*
|
2016-09-26 23:17:02 +00:00
|
|
|
* It would be valid and correct as of 1.2.0 to use NETWORK_CONFIG always,
|
2019-03-19 23:43:43 +00:00
|
|
|
* but OK(NETWORK_CONFIG_REQUEST) should be sent for compatibility.
|
2017-10-24 21:57:02 +00:00
|
|
|
*
|
2013-07-29 17:56:20 +00:00
|
|
|
* OK response payload:
|
|
|
|
* <[8] 64-bit network ID>
|
2016-08-09 16:34:13 +00:00
|
|
|
* <[2] 16-bit length of network configuration dictionary chunk>
|
|
|
|
* <[...] network configuration dictionary (may be incomplete)>
|
2016-09-27 18:33:48 +00:00
|
|
|
* [ ... end of legacy single chunk response ... ]
|
|
|
|
* <[1] 8-bit flags>
|
|
|
|
* <[8] 64-bit config update ID (should never be 0)>
|
2016-08-09 16:34:13 +00:00
|
|
|
* <[4] 32-bit total length of assembled dictionary>
|
2016-09-27 18:33:48 +00:00
|
|
|
* <[4] 32-bit index of chunk>
|
|
|
|
* [ ... end signed portion ... ]
|
|
|
|
* <[1] 8-bit chunk signature type>
|
|
|
|
* <[2] 16-bit length of chunk signature>
|
|
|
|
* <[...] chunk signature>
|
|
|
|
*
|
|
|
|
* The chunk signature signs the entire payload of the OK response.
|
|
|
|
* Currently only one signature type is supported: ed25519 (1).
|
|
|
|
*
|
|
|
|
* Each config chunk is signed to prevent memory exhaustion or
|
|
|
|
* traffic crowding DOS attacks against config fragment assembly.
|
|
|
|
*
|
|
|
|
* If the packet is from the network controller it is permitted to end
|
|
|
|
* before the config update ID or other chunking related or signature
|
|
|
|
* fields. This is to support older controllers that don't include
|
|
|
|
* these fields and may be removed in the future.
|
2013-07-29 17:56:20 +00:00
|
|
|
*
|
2013-10-17 10:41:52 +00:00
|
|
|
* ERROR response payload:
|
|
|
|
* <[8] 64-bit network ID>
|
2013-07-29 17:56:20 +00:00
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_NETWORK_CONFIG_REQUEST = 0x0b,
|
|
|
|
|
|
|
|
/**
|
2016-09-26 23:17:02 +00:00
|
|
|
* Network configuration data push:
|
2016-09-23 23:08:38 +00:00
|
|
|
* <[8] 64-bit network ID>
|
|
|
|
* <[2] 16-bit length of network configuration dictionary chunk>
|
|
|
|
* <[...] network configuration dictionary (may be incomplete)>
|
2016-09-27 18:33:48 +00:00
|
|
|
* <[1] 8-bit flags>
|
|
|
|
* <[8] 64-bit config update ID (should never be 0)>
|
2016-09-23 23:08:38 +00:00
|
|
|
* <[4] 32-bit total length of assembled dictionary>
|
2016-09-27 18:33:48 +00:00
|
|
|
* <[4] 32-bit index of chunk>
|
|
|
|
* [ ... end signed portion ... ]
|
|
|
|
* <[1] 8-bit chunk signature type>
|
|
|
|
* <[2] 16-bit length of chunk signature>
|
|
|
|
* <[...] chunk signature>
|
2016-08-04 01:04:08 +00:00
|
|
|
*
|
2016-09-23 23:08:38 +00:00
|
|
|
* This is a direct push variant for network config updates. It otherwise
|
2016-09-27 18:33:48 +00:00
|
|
|
* carries the same payload as OK(NETWORK_CONFIG_REQUEST) and has the same
|
|
|
|
* semantics.
|
2016-09-26 23:17:02 +00:00
|
|
|
*
|
2016-09-27 19:22:25 +00:00
|
|
|
* The legacy mode missing the additional chunking fields is not supported
|
|
|
|
* here.
|
|
|
|
*
|
2016-09-26 23:17:02 +00:00
|
|
|
* Flags:
|
2016-09-27 18:33:48 +00:00
|
|
|
* 0x01 - Use fast propagation
|
|
|
|
*
|
|
|
|
* An OK should be sent if the config is successfully received and
|
|
|
|
* accepted.
|
|
|
|
*
|
|
|
|
* OK payload:
|
|
|
|
* <[8] 64-bit network ID>
|
|
|
|
* <[8] 64-bit config update ID>
|
2016-08-04 01:04:08 +00:00
|
|
|
*/
|
2016-09-26 23:17:02 +00:00
|
|
|
VERB_NETWORK_CONFIG = 0x0c,
|
2013-07-29 17:56:20 +00:00
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
|
|
|
* Request endpoints for multicast distribution:
|
2014-09-19 01:28:14 +00:00
|
|
|
* <[8] 64-bit network ID>
|
2019-09-10 23:20:28 +00:00
|
|
|
* <[1] flags (unused, must be 0)>
|
2014-09-19 01:28:14 +00:00
|
|
|
* <[6] MAC address of multicast group being queried>
|
|
|
|
* <[4] 32-bit ADI for multicast group being queried>
|
2014-10-10 00:58:31 +00:00
|
|
|
* <[4] 32-bit requested max number of multicast peers>
|
2019-08-20 22:34:30 +00:00
|
|
|
*
|
2015-11-08 21:57:02 +00:00
|
|
|
* More than one OK response can occur if the response is broken up across
|
|
|
|
* multiple packets or if querying a clustered node.
|
|
|
|
*
|
2014-09-19 01:28:14 +00:00
|
|
|
* OK response payload:
|
|
|
|
* <[8] 64-bit network ID>
|
|
|
|
* <[6] MAC address of multicast group being queried>
|
|
|
|
* <[4] 32-bit ADI for multicast group being queried>
|
2014-09-30 23:28:25 +00:00
|
|
|
* [begin gather results -- these same fields can be in OK(MULTICAST_FRAME)]
|
2014-09-22 20:18:24 +00:00
|
|
|
* <[4] 32-bit total number of known members in this multicast group>
|
2014-09-19 01:28:14 +00:00
|
|
|
* <[2] 16-bit number of members enumerated in this packet>
|
|
|
|
* <[...] series of 5-byte ZeroTier addresses of enumerated members>
|
|
|
|
*
|
2015-11-08 21:57:02 +00:00
|
|
|
* ERROR is not generated; queries that return no response are dropped.
|
2014-09-19 01:28:14 +00:00
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_MULTICAST_GATHER = 0x0d,
|
2014-09-19 01:28:14 +00:00
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
|
|
|
* Multicast frame:
|
2014-09-24 20:45:58 +00:00
|
|
|
* <[8] 64-bit network ID>
|
2014-09-26 21:18:25 +00:00
|
|
|
* <[1] flags>
|
2019-09-08 02:15:21 +00:00
|
|
|
* [<[...] network certificate of membership (DEPRECATED)>]
|
|
|
|
* [<[4] 32-bit implicit gather limit (DEPRECATED)>]
|
2019-09-09 17:44:31 +00:00
|
|
|
* [<[5] ZeroTier address of originating sender (including w/0x08)>]
|
|
|
|
* [<[2] 16-bit bloom filter multiplier>]
|
|
|
|
* [<[2] 16-bit length of propagation bloom filter in bytes]
|
|
|
|
* [<[...] propagation bloom filter>]
|
2014-10-09 19:42:25 +00:00
|
|
|
* [<[6] source MAC>]
|
|
|
|
* <[6] destination MAC (multicast address)>
|
|
|
|
* <[4] 32-bit multicast ADI (multicast address extension)>
|
2014-09-19 01:28:14 +00:00
|
|
|
* <[2] 16-bit ethertype>
|
|
|
|
* <[...] ethernet payload>
|
2019-09-09 17:44:31 +00:00
|
|
|
* [<[2] 16-bit length of signature>]
|
|
|
|
* [<[...] signature (algorithm depends on sender identity)>]
|
2014-09-19 01:28:14 +00:00
|
|
|
*
|
2014-09-26 21:18:25 +00:00
|
|
|
* Flags:
|
2016-08-04 01:04:08 +00:00
|
|
|
* 0x01 - Network certificate of membership attached (DEPRECATED)
|
2019-07-16 18:33:11 +00:00
|
|
|
* 0x02 - Implicit gather limit field is present (DEPRECATED)
|
2014-10-09 19:42:25 +00:00
|
|
|
* 0x04 - Source MAC is specified -- otherwise it's computed from sender
|
2019-09-09 17:44:31 +00:00
|
|
|
* 0x08 - Propagation bloom filter is included
|
|
|
|
* 0x10 - Signature by sending identity is included
|
|
|
|
*
|
|
|
|
* Version 1.x only supports sender-side replication. Version 2.x also
|
|
|
|
* supports peer to peer and hub and spoke models. For that there is
|
|
|
|
* a new field: a bloom filter that tracks recipients by ZeroTier address.
|
|
|
|
*
|
|
|
|
* Bits in the bloom filter are set by multiplying the address by the
|
|
|
|
* indicated multiplier and then taking that modulo the number of bits
|
|
|
|
* in the filter. Both the length of the filter and this multiplier are
|
|
|
|
* variable and can be selected based on the sender's knowledge of
|
|
|
|
* the total recipient set to minimize the chance of collision, as a
|
|
|
|
* collision would result in a multicast not reaching one particular
|
|
|
|
* recipient. The algorithm for selecting these is not defined by the
|
|
|
|
* protocol.
|
|
|
|
*
|
|
|
|
* The ZeroTier address of the originating sender is also included
|
|
|
|
* before the bloom filter if flag bit 0x08 is set.
|
|
|
|
*
|
|
|
|
* Version 2.x also supports an optional signature of the packet's
|
|
|
|
* payload by the sending ZeroTier node. This can be used to validate
|
|
|
|
* multicasts propagated cooperatively, since unlike sender side
|
|
|
|
* replication the message MAC alone cannot be used for this. This
|
|
|
|
* imposes a non-trivial CPU cost on the sender and so it's optional.
|
2019-09-09 22:49:17 +00:00
|
|
|
* Note that the bloom filter itself is not included in the signature
|
|
|
|
* because it can be changed in transit.
|
2019-09-09 17:44:31 +00:00
|
|
|
*
|
|
|
|
* OK is not sent.
|
2019-08-20 22:34:30 +00:00
|
|
|
*
|
2019-09-08 02:15:21 +00:00
|
|
|
* ERROR_MULTICAST_STFU is generated if a recipient no longer wishes to
|
|
|
|
* receive these multicasts. It's essentially a source quench. Its
|
|
|
|
* payload is:
|
2014-09-19 01:28:14 +00:00
|
|
|
*
|
|
|
|
* ERROR response payload:
|
2014-09-30 23:28:25 +00:00
|
|
|
* <[8] 64-bit network ID>
|
2014-09-19 01:28:14 +00:00
|
|
|
* <[6] multicast group MAC>
|
|
|
|
* <[4] 32-bit multicast group ADI>
|
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_MULTICAST_FRAME = 0x0e,
|
|
|
|
|
2015-10-07 20:35:46 +00:00
|
|
|
/**
|
|
|
|
* Push of potential endpoints for direct communication:
|
2015-07-06 19:34:35 +00:00
|
|
|
* <[2] 16-bit number of paths>
|
|
|
|
* <[...] paths>
|
|
|
|
*
|
|
|
|
* Path record format:
|
2016-04-18 23:44:23 +00:00
|
|
|
* <[1] 8-bit path flags>
|
2015-07-06 21:08:13 +00:00
|
|
|
* <[2] length of extended path characteristics or 0 for none>
|
|
|
|
* <[...] extended path characteristics>
|
2015-07-06 19:34:35 +00:00
|
|
|
* <[1] address type>
|
2015-07-06 22:28:48 +00:00
|
|
|
* <[1] address length in bytes>
|
2015-07-06 19:34:35 +00:00
|
|
|
* <[...] address>
|
|
|
|
*
|
|
|
|
* Path record flags:
|
2016-04-18 23:44:23 +00:00
|
|
|
* 0x01 - Forget this path if currently known (not implemented yet)
|
2015-06-13 16:08:00 +00:00
|
|
|
*
|
2015-06-29 23:01:01 +00:00
|
|
|
* The receiver may, upon receiving a push, attempt to establish a
|
2015-07-06 19:34:35 +00:00
|
|
|
* direct link to one or more of the indicated addresses. It is the
|
|
|
|
* responsibility of the sender to limit which peers it pushes direct
|
2015-07-06 21:08:13 +00:00
|
|
|
* paths to to those with whom it has a trust relationship. The receiver
|
|
|
|
* must obey any restrictions provided such as exclusivity or blacklists.
|
|
|
|
* OK responses to this message are optional.
|
2015-06-13 16:08:00 +00:00
|
|
|
*
|
2015-07-06 21:08:13 +00:00
|
|
|
* Note that a direct path push does not imply that learned paths can't
|
|
|
|
* be used unless they are blacklisted explicitly or unless flag 0x01
|
|
|
|
* is set.
|
|
|
|
*
|
2015-07-13 17:03:04 +00:00
|
|
|
* OK and ERROR are not generated.
|
2015-06-13 16:08:00 +00:00
|
|
|
*/
|
2016-08-04 01:04:08 +00:00
|
|
|
VERB_PUSH_DIRECT_PATHS = 0x10,
|
2015-09-27 18:37:39 +00:00
|
|
|
|
2018-05-31 00:45:29 +00:00
|
|
|
/**
|
2018-06-08 00:25:27 +00:00
|
|
|
* An acknowledgment of receipt of a series of recent packets from another
|
2018-05-31 00:45:29 +00:00
|
|
|
* peer. This is used to calculate relative throughput values and to detect
|
|
|
|
* packet loss. Only VERB_FRAME and VERB_EXT_FRAME packets are counted.
|
|
|
|
*
|
|
|
|
* ACK response format:
|
|
|
|
* <[4] 32-bit number of bytes received since last ACK>
|
|
|
|
*
|
|
|
|
* Upon receipt of this packet, the local peer will verify that the correct
|
|
|
|
* number of bytes were received by the remote peer. If these values do
|
|
|
|
* not agree that could be an indicator of packet loss.
|
|
|
|
*
|
|
|
|
* Additionally, the local peer knows the interval of time that has
|
|
|
|
* elapsed since the last received ACK. With this information it can compute
|
|
|
|
* a rough estimate of the current throughput.
|
|
|
|
*
|
|
|
|
* This is sent at a maximum rate of once per every ZT_PATH_ACK_INTERVAL
|
|
|
|
*/
|
|
|
|
VERB_ACK = 0x12,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A packet containing timing measurements useful for estimating path quality.
|
|
|
|
* Composed of a list of <packet ID:internal sojourn time> pairs for an
|
|
|
|
* arbitrary set of recent packets. This is used to sample for latency and
|
|
|
|
* packet delay variance (PDV, "jitter").
|
|
|
|
*
|
|
|
|
* QoS record format:
|
|
|
|
*
|
|
|
|
* <[8] 64-bit packet ID of previously-received packet>
|
|
|
|
* <[1] 8-bit packet sojourn time>
|
|
|
|
* <...repeat until end of max 1400 byte packet...>
|
|
|
|
*
|
|
|
|
* The number of possible records per QoS packet is: (1400 * 8) / 72 = 155
|
|
|
|
* This packet should be sent very rarely (every few seconds) as it can be
|
|
|
|
* somewhat large if the connection is saturated. Future versions might use
|
2018-06-08 00:25:27 +00:00
|
|
|
* a bloom table to probabilistically determine these values in a vastly
|
2018-05-31 00:45:29 +00:00
|
|
|
* more space-efficient manner.
|
|
|
|
*
|
|
|
|
* Note: The 'internal packet sojourn time' is a slight misnomer as it is a
|
|
|
|
* measure of the amount of time between when a packet was received and the
|
|
|
|
* egress time of its tracking QoS packet.
|
|
|
|
*
|
|
|
|
* This is sent at a maximum rate of once per every ZT_PATH_QOS_INTERVAL
|
|
|
|
*/
|
|
|
|
VERB_QOS_MEASUREMENT = 0x13,
|
2015-10-07 20:35:46 +00:00
|
|
|
|
2016-08-23 21:38:20 +00:00
|
|
|
/**
|
|
|
|
* A message with arbitrary user-definable content:
|
|
|
|
* <[8] 64-bit arbitrary message type ID>
|
|
|
|
* [<[...] message payload>]
|
|
|
|
*
|
|
|
|
* This can be used to send arbitrary messages over VL1. It generates no
|
|
|
|
* OK or ERROR and has no special semantics outside of whatever the user
|
|
|
|
* (via the ZeroTier core API) chooses to give it.
|
2017-01-09 23:55:07 +00:00
|
|
|
*
|
|
|
|
* Message type IDs less than or equal to 65535 are reserved for use by
|
|
|
|
* ZeroTier, Inc. itself. We recommend making up random ones for your own
|
|
|
|
* implementations.
|
2016-08-23 21:38:20 +00:00
|
|
|
*/
|
2017-07-07 23:58:05 +00:00
|
|
|
VERB_USER_MESSAGE = 0x14,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A trace for remote debugging or diagnostics:
|
2017-07-13 17:51:05 +00:00
|
|
|
* <[...] null-terminated dictionary containing trace information>
|
|
|
|
* [<[...] additional null-terminated dictionaries>]
|
2017-07-07 23:58:05 +00:00
|
|
|
*
|
|
|
|
* This message contains a remote trace event. Remote trace events can
|
|
|
|
* be sent to observers configured at the network level for those that
|
2018-06-08 00:25:27 +00:00
|
|
|
* pertain directly to activity on a network, or to global observers if
|
2017-07-07 23:58:05 +00:00
|
|
|
* locally configured.
|
|
|
|
*/
|
2019-08-21 16:27:45 +00:00
|
|
|
VERB_REMOTE_TRACE = 0x15,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A signed locator for this node:
|
|
|
|
* <[8] 64-bit flags>
|
|
|
|
* <[2] 16-bit length of locator>
|
|
|
|
* <[...] serialized locator>
|
|
|
|
*
|
|
|
|
* This message is sent in response to OK(HELLO) and can be pushed
|
|
|
|
* opportunitistically. Its payload is a signed Locator object that
|
|
|
|
* attests to where and how this Node may be reached. A locator can
|
|
|
|
* contain static IPs/ports or other ZeroTier nodes that can be used
|
|
|
|
* to reach this one.
|
|
|
|
*
|
|
|
|
* These Locator objects can be stored e.g. by roots in LF to publish
|
|
|
|
* node reachability. Since they're signed any node can verify that
|
|
|
|
* the originating node approves of their content.
|
|
|
|
*/
|
2019-08-21 21:57:57 +00:00
|
|
|
VERB_SET_LOCATOR = 0x16,
|
2019-08-21 16:27:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of peers this node will relay traffic to/from:
|
|
|
|
* <[2] 16-bit number of peers>
|
|
|
|
* <[16] 128-bit hash of node public key>
|
|
|
|
* <[2] 16-bit latency to node or 0 if unspecified>
|
|
|
|
* <[4] 32-bit max bandwidth in megabits or 0 if unspecified>
|
2019-08-21 17:44:52 +00:00
|
|
|
* [<[...] additional hash,latency,bandwidth tuples>]
|
2019-08-21 16:27:45 +00:00
|
|
|
*
|
|
|
|
* This messages can be pushed to indicate that this peer is willing
|
|
|
|
* to relay traffic to other peers. It contains a list of 128-bit
|
|
|
|
* hashes (the first 128 bits of a SHA512) of identity public keys
|
|
|
|
* of currently reachable and willing-to-relay-for nodes.
|
|
|
|
*
|
|
|
|
* This can be used to initiate mesh-like behavior in ZeroTier. The
|
|
|
|
* peers for which this node is willing to relay are reported as
|
|
|
|
* hashes of their identity public keys. This prevents this message
|
|
|
|
* from revealing explicit information about linked peers. The
|
|
|
|
* receiving peer can only "see" a will-relay entry if it knows the
|
|
|
|
* identity of the peer it is trying to reach.
|
|
|
|
*/
|
|
|
|
VERB_WILL_RELAY = 0x17,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A push of one or more ephemeral key pairs:
|
2019-09-04 23:38:55 +00:00
|
|
|
* <[1] 8-bit length of random padding>
|
2019-08-21 16:27:45 +00:00
|
|
|
* <[...] random padding>
|
|
|
|
* <[1] 8-bit number of keys in message>
|
2019-09-04 23:38:55 +00:00
|
|
|
* [... begin keys ...]
|
2019-08-21 16:27:45 +00:00
|
|
|
* <[1] 8-bit key type>
|
|
|
|
* <[...] public key (length determined by type)>
|
2019-09-04 23:38:55 +00:00
|
|
|
* [<[...] additional keys ...>]
|
|
|
|
* [... end keys ...]
|
2019-08-21 16:27:45 +00:00
|
|
|
*
|
|
|
|
* This verb is used to push ephemeral keys. A node replies to each
|
|
|
|
* ephemeral key push with an OK message containing its own current
|
|
|
|
* ephemeral keys that it wants to use for p2p communication.
|
|
|
|
*
|
|
|
|
* These are ephemeral public keys. Currently keys of type C25519
|
|
|
|
* and P-384 are supported and both will be pushed.
|
|
|
|
*
|
|
|
|
* If more than one key is pushed, key agreement is performed using
|
|
|
|
* all keys for which both peers pushed the same key type. The raw
|
|
|
|
* results of these keys are then hashed together in order of key
|
|
|
|
* type ID with SHA384 to yield a session key. If the desired session
|
|
|
|
* key is shorter than 384 bits the first N bits are used.
|
|
|
|
*
|
|
|
|
* The random padding component can be used to ranomize the length
|
|
|
|
* of these packets so adversaries can't easily selectively block
|
|
|
|
* ephemeral key exchange by exploiting a fixed packet length.
|
|
|
|
*
|
|
|
|
* OK response payload:
|
|
|
|
* <[...] responder's keys, same format as verb payload>
|
|
|
|
*/
|
|
|
|
VERB_EPHEMERAL_KEY = 0x18
|
2015-09-27 18:37:39 +00:00
|
|
|
};
|
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
/**
|
|
|
|
* Error codes for VERB_ERROR
|
|
|
|
*/
|
|
|
|
enum ErrorCode
|
|
|
|
{
|
|
|
|
/* No error, not actually used in transit */
|
2016-08-04 01:04:08 +00:00
|
|
|
ERROR_NONE = 0x00,
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/* Invalid request */
|
2016-08-04 01:04:08 +00:00
|
|
|
ERROR_INVALID_REQUEST = 0x01,
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/* Bad/unsupported protocol version */
|
2016-08-04 01:04:08 +00:00
|
|
|
ERROR_BAD_PROTOCOL_VERSION = 0x02,
|
2013-07-04 20:56:19 +00:00
|
|
|
|
2015-11-08 21:57:02 +00:00
|
|
|
/* Unknown object queried */
|
2016-08-04 01:04:08 +00:00
|
|
|
ERROR_OBJ_NOT_FOUND = 0x03,
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/* HELLO pushed an identity whose address is already claimed */
|
2016-08-04 01:04:08 +00:00
|
|
|
ERROR_IDENTITY_COLLISION = 0x04,
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/* Verb or use case not supported/enabled by this node */
|
2016-08-04 01:04:08 +00:00
|
|
|
ERROR_UNSUPPORTED_OPERATION = 0x05,
|
2013-10-16 21:47:26 +00:00
|
|
|
|
2016-09-09 02:48:05 +00:00
|
|
|
/* Network membership certificate update needed */
|
|
|
|
ERROR_NEED_MEMBERSHIP_CERTIFICATE = 0x06,
|
|
|
|
|
2013-10-16 21:47:26 +00:00
|
|
|
/* Tried to join network, but you're not a member */
|
2016-08-04 01:04:08 +00:00
|
|
|
ERROR_NETWORK_ACCESS_DENIED_ = 0x07, /* extra _ at end to avoid Windows name conflict */
|
2014-09-19 01:28:14 +00:00
|
|
|
|
|
|
|
/* Multicasts to this group are not wanted */
|
2019-09-08 02:15:21 +00:00
|
|
|
ERROR_MULTICAST_STFU = 0x08,
|
2019-09-03 21:44:13 +00:00
|
|
|
|
|
|
|
/* Cannot deliver a forwarded ZeroTier packet (e.g. hops exceeded, no routes) */
|
|
|
|
/* Payload: <packet ID>, <destination>, <... additional packet ID / destinations> */
|
|
|
|
ERROR_CANNOT_DELIVER = 0x09
|
2013-07-04 20:56:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<unsigned int C2>
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Packet(const Buffer<C2> &b) :
|
2018-05-31 00:45:29 +00:00
|
|
|
Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(b)
|
2013-07-04 20:56:19 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Packet(const void *data,unsigned int len) :
|
2015-04-08 02:31:11 +00:00
|
|
|
Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(data,len)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
/**
|
|
|
|
* Construct a new empty packet with a unique random packet ID
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* Flags and hops will be zero. Other fields and data region are undefined.
|
|
|
|
* Use the header access methods (setDestination() and friends) to fill out
|
|
|
|
* the header. Payload should be appended; initial size is header size.
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Packet() :
|
2013-07-04 20:56:19 +00:00
|
|
|
Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(ZT_PROTO_MIN_PACKET_LENGTH)
|
|
|
|
{
|
2019-08-28 21:26:13 +00:00
|
|
|
setAt<uint64_t>(ZT_PACKET_IDX_IV,Packet::nextPacketId());
|
2015-05-15 00:41:05 +00:00
|
|
|
(*this)[ZT_PACKET_IDX_FLAGS] = 0; // zero flags, cipher ID, and hops
|
2013-07-04 20:56:19 +00:00
|
|
|
}
|
|
|
|
|
2014-09-22 20:18:24 +00:00
|
|
|
/**
|
|
|
|
* Make a copy of a packet with a new initialization vector and destination address
|
|
|
|
*
|
|
|
|
* This can be used to take one draft prototype packet and quickly make copies to
|
|
|
|
* encrypt for different destinations.
|
|
|
|
*
|
|
|
|
* @param prototype Prototype packet
|
|
|
|
* @param dest Destination ZeroTier address for new packet
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Packet(const Packet &prototype,const Address &dest) :
|
2014-09-22 20:18:24 +00:00
|
|
|
Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(prototype)
|
|
|
|
{
|
2019-08-28 21:26:13 +00:00
|
|
|
setAt<uint64_t>(ZT_PACKET_IDX_IV,Packet::nextPacketId());
|
2014-09-22 20:18:24 +00:00
|
|
|
setDestination(dest);
|
|
|
|
}
|
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
/**
|
|
|
|
* Construct a new empty packet with a unique random packet ID
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @param dest Destination ZT address
|
|
|
|
* @param source Source ZT address
|
|
|
|
* @param v Verb
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Packet(const Address &dest,const Address &source,const Verb v) :
|
2013-07-04 20:56:19 +00:00
|
|
|
Buffer<ZT_PROTO_MAX_PACKET_LENGTH>(ZT_PROTO_MIN_PACKET_LENGTH)
|
|
|
|
{
|
2019-08-28 21:26:13 +00:00
|
|
|
setAt<uint64_t>(ZT_PACKET_IDX_IV,Packet::nextPacketId());
|
2013-07-04 20:56:19 +00:00
|
|
|
setDestination(dest);
|
|
|
|
setSource(source);
|
2013-07-09 18:06:55 +00:00
|
|
|
(*this)[ZT_PACKET_IDX_FLAGS] = 0; // zero flags and hops
|
2013-07-04 20:56:19 +00:00
|
|
|
setVerb(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset this packet structure for reuse in place
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @param dest Destination ZT address
|
|
|
|
* @param source Source ZT address
|
|
|
|
* @param v Verb
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE void reset(const Address &dest,const Address &source,const Verb v)
|
2013-07-04 20:56:19 +00:00
|
|
|
{
|
|
|
|
setSize(ZT_PROTO_MIN_PACKET_LENGTH);
|
2019-08-28 21:26:13 +00:00
|
|
|
setAt<uint64_t>(ZT_PACKET_IDX_IV,Packet::nextPacketId());
|
2013-07-04 20:56:19 +00:00
|
|
|
setDestination(dest);
|
|
|
|
setSource(source);
|
2015-05-15 00:41:05 +00:00
|
|
|
(*this)[ZT_PACKET_IDX_FLAGS] = 0; // zero flags, cipher ID, and hops
|
2013-07-04 20:56:19 +00:00
|
|
|
setVerb(v);
|
|
|
|
}
|
|
|
|
|
2013-07-11 20:19:06 +00:00
|
|
|
/**
|
|
|
|
* Generate a new IV / packet ID in place
|
|
|
|
*
|
|
|
|
* This can be used to re-use a packet buffer multiple times to send
|
|
|
|
* technically different but otherwise identical copies of the same
|
|
|
|
* packet.
|
|
|
|
*/
|
2019-08-28 21:26:13 +00:00
|
|
|
ZT_ALWAYS_INLINE void newInitializationVector() { setAt<uint64_t>(ZT_PACKET_IDX_IV,Packet::nextPacketId()); }
|
2013-07-11 20:19:06 +00:00
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
/**
|
|
|
|
* Set this packet's destination
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @param dest ZeroTier address of destination
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE void setDestination(const Address &dest) { dest.copyTo(field(ZT_PACKET_IDX_DEST,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set this packet's source
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @param source ZeroTier address of source
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE void setSource(const Address &source) { source.copyTo(field(ZT_PACKET_IDX_SOURCE,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get this packet's destination
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @return Destination ZT address
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Address destination() const { return Address(field(ZT_PACKET_IDX_DEST,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get this packet's source
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @return Source ZT address
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Address source() const { return Address(field(ZT_PACKET_IDX_SOURCE,ZT_ADDRESS_LENGTH),ZT_ADDRESS_LENGTH); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return True if packet is of valid length
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE bool lengthValid() const { return (size() >= ZT_PROTO_MIN_PACKET_LENGTH); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return True if packet is fragmented (expect fragments)
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE bool fragmented() const { return (((unsigned char)(*this)[ZT_PACKET_IDX_FLAGS] & ZT_PROTO_FLAG_FRAGMENTED) != 0); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set this packet's fragmented flag
|
|
|
|
*
|
|
|
|
* @param f Fragmented flag value
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE void setFragmented(bool f)
|
2013-07-04 20:56:19 +00:00
|
|
|
{
|
|
|
|
if (f)
|
2013-07-09 18:06:55 +00:00
|
|
|
(*this)[ZT_PACKET_IDX_FLAGS] |= (char)ZT_PROTO_FLAG_FRAGMENTED;
|
|
|
|
else (*this)[ZT_PACKET_IDX_FLAGS] &= (char)(~ZT_PROTO_FLAG_FRAGMENTED);
|
2013-07-04 20:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return True if compressed (result only valid if unencrypted)
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE bool compressed() const { return (((unsigned char)(*this)[ZT_PACKET_IDX_VERB] & ZT_PROTO_VERB_FLAG_COMPRESSED) != 0); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ZeroTier forwarding hops (0 to 7)
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE unsigned int hops() const { return ((unsigned int)(*this)[ZT_PACKET_IDX_FLAGS] & 0x07); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Increment this packet's hop count
|
|
|
|
*/
|
2019-08-28 20:04:58 +00:00
|
|
|
ZT_ALWAYS_INLINE unsigned char incrementHops()
|
2013-07-04 20:56:19 +00:00
|
|
|
{
|
2014-10-02 17:54:34 +00:00
|
|
|
unsigned char &b = (*this)[ZT_PACKET_IDX_FLAGS];
|
2019-08-28 20:04:58 +00:00
|
|
|
const unsigned char h = (b + 1) & 0x07;
|
|
|
|
b = (b & 0xf8) | h;
|
|
|
|
return (unsigned int)h;
|
2013-07-04 20:56:19 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 17:54:34 +00:00
|
|
|
/**
|
|
|
|
* @return Cipher suite selector: 0 - 7 (see #defines)
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE unsigned int cipher() const
|
2014-10-02 18:08:59 +00:00
|
|
|
{
|
2015-05-15 00:41:05 +00:00
|
|
|
return (((unsigned int)(*this)[ZT_PACKET_IDX_FLAGS] & 0x38) >> 3);
|
2014-10-02 18:08:59 +00:00
|
|
|
}
|
2014-10-02 17:54:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set this packet's cipher suite
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE void setCipher(unsigned int c)
|
2014-10-02 17:54:34 +00:00
|
|
|
{
|
|
|
|
unsigned char &b = (*this)[ZT_PACKET_IDX_FLAGS];
|
2015-05-15 00:41:05 +00:00
|
|
|
b = (b & 0xc7) | (unsigned char)((c << 3) & 0x38); // bits: FFCCCHHH
|
2014-10-02 17:54:34 +00:00
|
|
|
}
|
|
|
|
|
2016-07-12 15:29:50 +00:00
|
|
|
/**
|
|
|
|
* Get the trusted path ID for this packet (only meaningful if cipher is trusted path)
|
|
|
|
*
|
|
|
|
* @return Trusted path ID (from MAC field)
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE uint64_t trustedPathId() const { return at<uint64_t>(ZT_PACKET_IDX_MAC); }
|
2016-07-12 15:29:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set this packet's trusted path ID and set the cipher spec to trusted path
|
|
|
|
*
|
|
|
|
* @param tpid Trusted path ID
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE void setTrusted(const uint64_t tpid)
|
2016-07-12 15:29:50 +00:00
|
|
|
{
|
2019-09-08 02:15:21 +00:00
|
|
|
setCipher(ZT_PROTO_CIPHER_SUITE__NONE);
|
2016-07-12 15:29:50 +00:00
|
|
|
setAt(ZT_PACKET_IDX_MAC,tpid);
|
|
|
|
}
|
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
/**
|
|
|
|
* Get this packet's unique ID (the IV field interpreted as uint64_t)
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2017-03-01 18:22:57 +00:00
|
|
|
* Note that the least significant 3 bits of this ID will change when armor()
|
|
|
|
* is called to armor the packet for transport. This is because armor() will
|
|
|
|
* mask the last 3 bits against the send counter for QoS monitoring use prior
|
|
|
|
* to actually using the IV to encrypt and MAC the packet. Be aware of this
|
|
|
|
* when grabbing the packetId of a new packet prior to armor/send.
|
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @return Packet ID
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE uint64_t packetId() const { return at<uint64_t>(ZT_PACKET_IDX_IV); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set packet verb
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* This also has the side-effect of clearing any verb flags, such as
|
|
|
|
* compressed, and so must only be done during packet composition.
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @param v New packet verb
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE void setVerb(Verb v) { (*this)[ZT_PACKET_IDX_VERB] = (char)v; }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Packet verb (not including flag bits)
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE Verb verb() const { return (Verb)((*this)[ZT_PACKET_IDX_VERB] & 0x1f); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Length of packet payload
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE unsigned int payloadLength() const { return ((size() < ZT_PROTO_MIN_PACKET_LENGTH) ? 0 : (size() - ZT_PROTO_MIN_PACKET_LENGTH)); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
2013-07-09 18:06:55 +00:00
|
|
|
* @return Raw packet payload
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE const unsigned char *payload() const { return field(ZT_PACKET_IDX_PAYLOAD,size() - ZT_PACKET_IDX_PAYLOAD); }
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-24 21:35:05 +00:00
|
|
|
* Armor packet for transport
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
2013-09-24 21:35:05 +00:00
|
|
|
* @param key 32-byte key
|
|
|
|
* @param encryptPayload If true, encrypt packet payload, else just MAC
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
2018-01-08 21:06:24 +00:00
|
|
|
void armor(const void *key,bool encryptPayload);
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-24 21:35:05 +00:00
|
|
|
* Verify and (if encrypted) decrypt packet
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
2016-07-12 15:29:50 +00:00
|
|
|
* This does not handle trusted path mode packets and will return false
|
|
|
|
* for these. These are handled in IncomingPacket if the sending physical
|
|
|
|
* address and MAC field match a trusted path.
|
|
|
|
*
|
2013-09-24 21:35:05 +00:00
|
|
|
* @param key 32-byte key
|
|
|
|
* @return False if packet is invalid or failed MAC authenticity check
|
2013-07-04 20:56:19 +00:00
|
|
|
*/
|
2015-05-05 01:39:53 +00:00
|
|
|
bool dearmor(const void *key);
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to compress payload if not already (must be unencrypted)
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* This requires that the payload at least contain the verb byte already
|
|
|
|
* set. The compressed flag in the verb is set if compression successfully
|
|
|
|
* results in a size reduction. If no size reduction occurs, compression
|
|
|
|
* is not done and the flag is left cleared.
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @return True if compression occurred
|
|
|
|
*/
|
2015-05-05 01:39:53 +00:00
|
|
|
bool compress();
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to decompress payload if it is compressed (must be unencrypted)
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* If payload is compressed, it is decompressed and the compressed verb
|
|
|
|
* flag is cleared. Otherwise nothing is done and true is returned.
|
2015-07-13 17:03:04 +00:00
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @return True if data is now decompressed and valid, false on error
|
|
|
|
*/
|
2015-05-05 01:39:53 +00:00
|
|
|
bool uncompress();
|
2013-07-04 20:56:19 +00:00
|
|
|
|
|
|
|
private:
|
2013-09-25 14:55:27 +00:00
|
|
|
static const unsigned char ZERO_KEY[32];
|
|
|
|
|
2019-08-28 21:26:13 +00:00
|
|
|
static uint64_t nextPacketId();
|
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
/**
|
2013-09-16 17:02:10 +00:00
|
|
|
* Deterministically mangle a 256-bit crypto key based on packet
|
2013-07-04 20:56:19 +00:00
|
|
|
*
|
2014-10-02 17:54:34 +00:00
|
|
|
* This uses extra data from the packet to mangle the secret, giving us an
|
|
|
|
* effective IV that is somewhat more than 64 bits. This is "free" for
|
|
|
|
* Salsa20 since it has negligible key setup time so using a different
|
|
|
|
* key each time is fine.
|
|
|
|
*
|
2013-07-04 20:56:19 +00:00
|
|
|
* @param in Input key (32 bytes)
|
|
|
|
* @param out Output buffer (32 bytes)
|
|
|
|
*/
|
2019-08-27 03:18:28 +00:00
|
|
|
ZT_ALWAYS_INLINE void _salsa20MangleKey(const unsigned char *in,unsigned char *out) const
|
2013-07-04 20:56:19 +00:00
|
|
|
{
|
2014-10-02 17:54:34 +00:00
|
|
|
const unsigned char *d = (const unsigned char *)data();
|
|
|
|
|
2013-09-24 21:35:05 +00:00
|
|
|
// IV and source/destination addresses. Using the addresses divides the
|
|
|
|
// key space into two halves-- A->B and B->A (since order will change).
|
2013-07-04 20:56:19 +00:00
|
|
|
for(unsigned int i=0;i<18;++i) // 8 + (ZT_ADDRESS_LENGTH * 2) == 18
|
2014-10-02 17:54:34 +00:00
|
|
|
out[i] = in[i] ^ d[i];
|
2013-09-16 17:02:10 +00:00
|
|
|
|
|
|
|
// Flags, but with hop count masked off. Hop count is altered by forwarding
|
|
|
|
// nodes. It's one of the only parts of a packet modifiable by people
|
|
|
|
// without the key.
|
2014-10-02 17:54:34 +00:00
|
|
|
out[18] = in[18] ^ (d[ZT_PACKET_IDX_FLAGS] & 0xf8);
|
2013-09-16 17:02:10 +00:00
|
|
|
|
|
|
|
// Raw packet size in bytes -- thus each packet size defines a new
|
|
|
|
// key space.
|
2013-07-09 18:06:55 +00:00
|
|
|
out[19] = in[19] ^ (unsigned char)(size() & 0xff);
|
|
|
|
out[20] = in[20] ^ (unsigned char)((size() >> 8) & 0xff); // little endian
|
2013-09-16 17:02:10 +00:00
|
|
|
|
2013-07-04 20:56:19 +00:00
|
|
|
// Rest of raw key is used unchanged
|
|
|
|
for(unsigned int i=21;i<32;++i)
|
|
|
|
out[i] = in[i];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ZeroTier
|
|
|
|
|
|
|
|
#endif
|