2020-06-21 22:26:27 +02:00
/**
2021-01-12 09:43:21 +01:00
* ( C ) 2007 - 21 - ntop . org and contributors
2020-06-21 22:26:27 +02:00
*
* 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
2020-12-24 14:56:29 +01:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
2020-06-21 22:26:27 +02:00
* 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 see < http : //www.gnu.org/licenses/>
*
*/
/* N2N packet header indicators. */
2020-12-24 14:56:29 +01:00
# define MSG_TYPE_REGISTER 1
# define MSG_TYPE_DEREGISTER 2
# define MSG_TYPE_PACKET 3
# define MSG_TYPE_REGISTER_ACK 4
# define MSG_TYPE_REGISTER_SUPER 5
# define MSG_TYPE_UNREGISTER_SUPER 6
# define MSG_TYPE_REGISTER_SUPER_ACK 7
# define MSG_TYPE_REGISTER_SUPER_NAK 8
# define MSG_TYPE_FEDERATION 9
# define MSG_TYPE_PEER_INFO 10
# define MSG_TYPE_QUERY_PEER 11
# define MSG_TYPE_MAX_TYPE 11
2021-07-24 00:01:50 +02:00
# define MSG_TYPE_RE_REGISTER_SUPER 12
2020-06-21 22:26:27 +02:00
2020-09-29 10:50:09 +02:00
/* Max available space to add supernodes' informations (sockets and MACs) in REGISTER_SUPER_ACK
2020-10-27 17:02:35 +01:00
* Field sizes of REGISTER_SUPER_ACK as used in encode / decode fucntions in src / wire . c
2021-01-12 09:43:21 +01:00
*/
# define REG_SUPER_ACK_PAYLOAD_SPACE (DEFAULT_MTU - (sizeof(n2n_common_t) + sizeof(n2n_REGISTER_SUPER_ACK_t)))
2020-09-29 10:50:09 +02:00
/* Space needed to store socket and MAC address of a supernode */
2020-12-24 14:56:29 +01:00
# define REG_SUPER_ACK_PAYLOAD_ENTRY_SIZE (sizeof(n2n_REGISTER_SUPER_ACK_payload_t))
2020-10-27 17:02:35 +01:00
2021-01-25 12:09:38 +01:00
# define BOOTSTRAP_TIMEOUT 3
2020-12-24 14:56:29 +01:00
# define PURGE_REGISTRATION_FREQUENCY 30
# define RE_REG_AND_PURGE_FREQUENCY 10
# define REGISTRATION_TIMEOUT 60
2020-09-29 10:50:09 +02:00
2020-12-24 14:56:29 +01:00
# define SOCKET_TIMEOUT_INTERVAL_SECS 10
# define REGISTER_SUPER_INTERVAL_DFL 20 /* sec, usually UDP NAT entries in a firewall expire after 30 seconds */
# define SWEEP_TIME 30 / * sec, indicates the value after which we have to sort the hash list of supernodes in edges
* and when we send out packets to query selection - relevant informations from supernodes . */
2020-11-10 16:34:49 +01:00
2021-02-01 13:46:36 +01:00
# define NUMBER_SN_PINGS_INITIAL 15 /* number of supernodes to concurrently ping during bootstrap and immediately afterwards */
# define NUMBER_SN_PINGS_REGULAR 5 /* number of supernodes to concurrently ping during regular edge operation */
2020-11-11 09:27:39 +01:00
/* Timeouts used in re_register_and_purge_supernodes. LAST_SEEN_SN_ACTIVE and LAST_SEEN_SN_INACTIVE
* values should be at least 3 * SOCKET_TIMEOUT_INTERVAL_SECS apart . */
2020-12-24 14:56:29 +01:00
# define LAST_SEEN_SN_ACTIVE 20 /* sec, indicates supernodes that are proven to be active */
# define LAST_SEEN_SN_INACTIVE 90 /* sec, indicates supernodes that are proven to be inactive: they will be purged */
2021-01-31 16:27:08 +01:00
# define LAST_SEEN_SN_NEW (LAST_SEEN_SN_INACTIVE - 3 * RE_REG_AND_PURGE_FREQUENCY) /* sec, indicates supernodes with unsure status, must be tested to check if they are active */
2020-06-21 22:26:27 +02:00
2020-12-24 14:56:29 +01:00
# define IFACE_UPDATE_INTERVAL (30) /* sec. How long it usually takes to get an IP lease. */
# define TRANSOP_TICK_INTERVAL (10) /* sec */
2020-06-21 22:26:27 +02:00
2020-12-24 14:56:29 +01:00
# define SORT_COMMUNITIES_INTERVAL 90 /* sec. until supernode sorts communities' hash list again */
2020-07-27 21:10:07 +02:00
2021-06-05 14:09:32 +02:00
# define AF_INVALID -1 /* to mark a socket invalid by an invalid address family (do not use AF_UNSPEC, it could turn into auto-detect) */
2021-06-04 00:07:12 +02:00
# define N2N_RESOLVE_INTERVAL 300 /* seconds until edge and supernode try to resolve supernode names again */
# define N2N_RESOLVE_CHECK_INTERVAL 30 /* seconds until main loop checking in on changes from resolver thread */
2020-06-21 22:26:27 +02:00
# define ETH_FRAMESIZE 14
# define IP4_SRCOFFSET 12
# define IP4_DSTOFFSET 16
# define IP4_MIN_SIZE 20
# define UDP_SIZE 8
2020-07-29 11:47:04 +02:00
/* parameters for replay protection */
2020-12-24 14:56:29 +01:00
# define TIME_STAMP_FRAME 0x0000001000000000LL /* clocks of different computers are allowed +/- 16 seconds to be off */
# define TIME_STAMP_JITTER 0x0000000027100000LL / * we allow a packet to arrive 160 ms (== 0x27100 us) before another
2021-01-12 09:43:21 +01:00
* set to 0x0000000000000000LL if increasing ( or equal ) time stamps allowed only */
2020-12-24 14:56:29 +01:00
# define TIME_STAMP_ALLOW_JITTER 1 /* constant for allowing or... */
# define TIME_STAMP_NO_JITTER 0 /* not allowing jitter to be considered */
2020-07-29 11:47:04 +02:00
2020-06-21 22:26:27 +02:00
/* N2N compression indicators. */
/* Compression is disabled by default for outgoing packets if no cli
* option is given . All edges are built with decompression support so
* they are able to understand each other ( this applies to lzo only ) . */
2020-12-24 14:56:29 +01:00
# define N2N_COMPRESSION_ID_INVALID 0
# define N2N_COMPRESSION_ID_NONE 1 /* default, see edge_init_conf_defaults(...) in edge_utils.c */
# define N2N_COMPRESSION_ID_LZO 2 /* set if '-z1' or '-z' cli option is present, see setOption(...) in edge.c */
# define N2N_COMPRESSION_ID_ZSTD 3 /* set if '-z2' cli option is present, available only if compiled with zstd lib */
# define ZSTD_COMPRESSION_LEVEL 7 /* 1 (faster) ... 22 (more compression) */
2020-06-21 22:26:27 +02:00
2020-09-24 20:00:32 +02:00
/* Federation name and indicators */
# define FEDERATION_NAME "*Federation"
enum federation { IS_NO_FEDERATION = 0 , IS_FEDERATION = 1 } ;
2020-08-04 11:33:58 +02:00
/* (un)purgeable community indicator (supernode) */
2020-12-24 14:56:29 +01:00
# define COMMUNITY_UNPURGEABLE 0
# define COMMUNITY_PURGEABLE 1
2020-08-04 11:33:58 +02:00
2020-10-11 21:54:06 +02:00
/* (un)purgeable supernode indicator */
2020-10-27 17:02:35 +01:00
enum sn_purge { SN_PURGEABLE = 0 , SN_UNPURGEABLE = 1 } ;
2020-10-11 11:57:48 +02:00
2020-06-22 20:49:19 +02:00
/* Header encryption indicators */
2020-12-24 14:56:29 +01:00
# define HEADER_ENCRYPTION_UNKNOWN 0
# define HEADER_ENCRYPTION_NONE 1
# define HEADER_ENCRYPTION_ENABLED 2
2021-07-20 23:07:38 +02:00
/* REGISTER_SUPER_ACK packet hash length with user/pw auth, up to 16 bytes */
# define N2N_REG_SUP_HASH_CHECK_LEN 16
2020-12-24 14:56:29 +01:00
# define DEFAULT_MTU 1290
# define HASH_ADD_PEER(head,add) \
HASH_ADD ( hh , head , mac_addr , sizeof ( n2n_mac_t ) , add )
# define HASH_FIND_PEER(head,mac,out) \
HASH_FIND ( hh , head , mac , sizeof ( n2n_mac_t ) , out )
# define N2N_EDGE_SN_HOST_SIZE 48
# define N2N_EDGE_SUP_ATTEMPTS 3 /* Number of failed attmpts before moving on to next supernode. */
# define N2N_PATHNAME_MAXLEN 256
# define N2N_EDGE_MGMT_PORT 5644
# define N2N_SN_MGMT_PORT 5645
2020-06-21 22:26:27 +02:00
2021-02-22 17:52:47 +01:00
# define N2N_TCP_BACKLOG_QUEUE_SIZE 3 /* number of concurrently pending connections to be accepted */
/* NOT the number of max. TCP connections */
2021-03-01 09:28:14 +01:00
# define N2N_CLOSE_SOCKET_COUNTER_MAX 15 /* number of times of edge's reconnects to supernode after */
/* which the socket explicitly is closed before reopening */
2020-10-27 17:02:35 +01:00
/* flag used in add_sn_to_list_by_mac_or_sock */
2020-11-10 16:34:49 +01:00
enum skip_add { SN_ADD = 0 , SN_ADD_SKIP = 1 , SN_ADD_ADDED = 2 } ;
2020-10-27 17:02:35 +01:00
2020-12-24 14:56:29 +01:00
# define N2N_NETMASK_STR_SIZE 16 /* dotted decimal 12 numbers + 3 dots */
# define N2N_MACNAMSIZ 18 /* AA:BB:CC:DD:EE:FF + NULL*/
# define N2N_IF_MODE_SIZE 16 /* static | dhcp */
2020-07-06 07:17:01 +02:00
2020-12-24 14:56:29 +01:00
# define N2N_EDGE_DEFAULT_DEV_NAME "edge0"
# define N2N_EDGE_DEFAULT_NETMASK "255.255.255.0" /* default netmask for edge ip address... */
# define N2N_EDGE_DEFAULT_CIDR_NM 24 /* ... also in cidr format */
2020-09-21 09:52:06 +02:00
2020-07-18 11:17:30 +02:00
# define N2N_SN_LPORT_DEFAULT 7654
# define N2N_SN_PKTBUF_SIZE 2048
2020-07-06 07:17:01 +02:00
2020-08-08 16:40:45 +02:00
/* The way TUNTAP allocated IP. */
# define TUNTAP_IP_MODE_SN_ASSIGN 0
2020-12-19 12:28:45 +01:00
# define TUNTAP_IP_MODE_STATIC 1
# define TUNTAP_IP_MODE_DHCP 2
2020-08-08 16:40:45 +02:00
2020-08-19 11:01:58 +02:00
/* Default network segment of the auto ip address service provided by sn. */
# define N2N_SN_MIN_AUTO_IP_NET_DEFAULT "10.128.0.0"
# define N2N_SN_MAX_AUTO_IP_NET_DEFAULT "10.255.255.0"
# define N2N_SN_AUTO_IP_NET_BIT_DEFAULT 24
2020-08-08 16:40:45 +02:00
2020-06-21 22:26:27 +02:00
/* ************************************** */
2020-12-24 14:56:29 +01:00
# define SUPERNODE_IP "127.0.0.1"
# define SUPERNODE_PORT 1234
2020-06-21 22:26:27 +02:00
/* ************************************** */
2020-12-24 14:56:29 +01:00
# define N2N_PKT_VERSION 3
# define N2N_DEFAULT_TTL 2 /* can be forwarded twice at most */
2021-01-17 13:52:17 +01:00
# define N2N_COMMUNITY_SIZE 20
2021-06-03 23:26:22 +02:00
# define N2N_PRIVATE_PUBLIC_KEY_SIZE 32
# define N2N_USER_KEY_LINE_STARTER '*'
2020-12-24 14:56:29 +01:00
# define N2N_MAC_SIZE 6
2021-10-03 14:34:29 +02:00
# define N2N_NO_REG_COOKIE 0x00000000
# define N2N_FORWARDED_REG_COOKIE 0x00001000
# define N2N_PORT_REG_COOKIE 0x00004000
# define N2N_REGULAR_REG_COOKIE 0x00010000
# define N2N_MCAST_REG_COOKIE 0x00400000
# define N2N_LOCAL_REG_COOKIE 0x01000000
2020-12-24 14:56:29 +01:00
# define N2N_DESC_SIZE 16
# define N2N_PKT_BUF_SIZE 2048
# define N2N_SOCKBUF_SIZE 64 /* string representation of INET or INET6 sockets */
2020-11-13 09:28:52 +01:00
2020-12-24 14:56:29 +01:00
# define N2N_MULTICAST_PORT 1968
# define N2N_MULTICAST_GROUP "224.0.0.68"
2020-11-13 09:28:52 +01:00
# ifdef WIN32
2020-12-24 14:56:29 +01:00
# define N2N_IFNAMSIZ 64
2020-11-13 09:28:52 +01:00
# else
2020-12-24 14:56:29 +01:00
# define N2N_IFNAMSIZ 16 /* 15 chars * NULL */
2020-11-13 09:28:52 +01:00
# endif
2021-07-26 09:08:05 +02:00
# ifdef _MSC_VER
# define N2N_THREAD_RETURN_DATATYPE DWORD WINAPI
# define N2N_THREAD_PARAMETER_DATATYPE LPVOID
# else
# define N2N_THREAD_RETURN_DATATYPE void*
# define N2N_THREAD_PARAMETER_DATATYPE void*
# endif
2020-12-24 14:56:29 +01:00
# define SN_SELECTION_CRITERION_DATA_TYPE uint32_t
2021-02-06 13:39:08 +01:00
# define SN_SELECTION_CRITERION_BUF_SIZE 16
2020-11-13 09:28:52 +01:00
2020-12-24 14:56:29 +01:00
# define N2N_TRANSFORM_ID_USER_START 64
# define N2N_TRANSFORM_ID_MAX 65535
2020-11-13 09:28:52 +01:00
2020-06-21 22:26:27 +02:00
# ifndef max
2021-06-03 23:26:22 +02:00
# define max(a, b) (((a) < (b)) ? (b) : (a))
2020-06-21 22:26:27 +02:00
# endif
# ifndef min
2021-06-03 23:26:22 +02:00
# define min(a, b) (((a) >(b)) ? (b) : (a))
2020-06-21 22:26:27 +02:00
# endif