|
@ -64,6 +64,8 @@ |
|
|
#include <stdio.h> |
|
|
#include <stdio.h> |
|
|
#include <errno.h> |
|
|
#include <errno.h> |
|
|
#include <fcntl.h> |
|
|
#include <fcntl.h> |
|
|
|
|
|
#include <stdint.h> |
|
|
|
|
|
#include <time.h> |
|
|
|
|
|
|
|
|
#ifndef WIN32 |
|
|
#ifndef WIN32 |
|
|
#include <unistd.h> |
|
|
#include <unistd.h> |
|
@ -74,6 +76,16 @@ |
|
|
|
|
|
|
|
|
#ifdef __linux__ |
|
|
#ifdef __linux__ |
|
|
#define N2N_CAN_NAME_IFACE 1 |
|
|
#define N2N_CAN_NAME_IFACE 1 |
|
|
|
|
|
#include <linux/netlink.h> |
|
|
|
|
|
#include <linux/rtnetlink.h> |
|
|
|
|
|
#include <sys/syscall.h> |
|
|
|
|
|
#include <unistd.h> |
|
|
|
|
|
#include <net/if_arp.h> |
|
|
|
|
|
#include <net/if.h> |
|
|
|
|
|
#include <linux/if_tun.h> |
|
|
|
|
|
#include <linux/netlink.h> |
|
|
|
|
|
#include <linux/rtnetlink.h> |
|
|
|
|
|
#define GRND_NONBLOCK 1 |
|
|
#endif /* #ifdef __linux__ */ |
|
|
#endif /* #ifdef __linux__ */ |
|
|
|
|
|
|
|
|
#ifdef __FreeBSD__ |
|
|
#ifdef __FreeBSD__ |
|
@ -83,7 +95,12 @@ |
|
|
#include <syslog.h> |
|
|
#include <syslog.h> |
|
|
#include <sys/wait.h> |
|
|
#include <sys/wait.h> |
|
|
|
|
|
|
|
|
|
|
|
#if defined (__RDRND__) || defined (__RDSEED__) |
|
|
|
|
|
#include <immintrin.h> |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
#define ETH_ADDR_LEN 6 |
|
|
#define ETH_ADDR_LEN 6 |
|
|
|
|
|
|
|
|
struct ether_hdr |
|
|
struct ether_hdr |
|
|
{ |
|
|
{ |
|
|
uint8_t dhost[ETH_ADDR_LEN]; |
|
|
uint8_t dhost[ETH_ADDR_LEN]; |
|
@ -93,10 +110,17 @@ struct ether_hdr |
|
|
|
|
|
|
|
|
typedef struct ether_hdr ether_hdr_t; |
|
|
typedef struct ether_hdr ether_hdr_t; |
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBZSTD |
|
|
|
|
|
#include <zstd.h> |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
#ifdef __ANDROID_NDK__ |
|
|
#ifdef __ANDROID_NDK__ |
|
|
#undef N2N_HAVE_DAEMON |
|
|
#undef N2N_HAVE_DAEMON |
|
|
#undef N2N_HAVE_SETUID |
|
|
#undef N2N_HAVE_SETUID |
|
|
#undef N2N_CAN_NAME_IFACE |
|
|
#undef N2N_CAN_NAME_IFACE |
|
|
|
|
|
#include "android/edge_android.h" |
|
|
|
|
|
#include <tun2tap/tun2tap.h> |
|
|
|
|
|
#define ARP_PERIOD_INTERVAL (10) /* sec */ |
|
|
#endif /* #ifdef __ANDROID_NDK__ */ |
|
|
#endif /* #ifdef __ANDROID_NDK__ */ |
|
|
|
|
|
|
|
|
#include <netinet/in.h> |
|
|
#include <netinet/in.h> |
|
@ -106,27 +130,37 @@ typedef struct ether_hdr ether_hdr_t; |
|
|
#include <arpa/inet.h> |
|
|
#include <arpa/inet.h> |
|
|
#include <sys/types.h> |
|
|
#include <sys/types.h> |
|
|
#include <unistd.h> |
|
|
#include <unistd.h> |
|
|
|
|
|
#include <string.h> |
|
|
#include <assert.h> |
|
|
#include <assert.h> |
|
|
#include <sys/stat.h> |
|
|
#include <sys/stat.h> |
|
|
|
|
|
#include <stdint.h> |
|
|
#include <openssl/opensslv.h> |
|
|
#include <openssl/opensslv.h> |
|
|
#include <openssl/crypto.h> |
|
|
#include <openssl/crypto.h> |
|
|
|
|
|
|
|
|
#include "minilzo.h" |
|
|
#include "minilzo.h" |
|
|
|
|
|
#include "n2n_define.h" |
|
|
|
|
|
|
|
|
#define closesocket(a) close(a) |
|
|
#define closesocket(a) close(a) |
|
|
#endif /* #ifndef WIN32 */ |
|
|
#endif /* #ifndef WIN32 */ |
|
|
|
|
|
|
|
|
#include <string.h> |
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
#include <stdarg.h> |
|
|
#include <stdarg.h> |
|
|
|
|
|
|
|
|
#include "uthash.h" |
|
|
#include "uthash.h" |
|
|
|
|
|
#include "lzoconf.h" |
|
|
|
|
|
|
|
|
#ifdef WIN32 |
|
|
#ifdef WIN32 |
|
|
#include "win32/wintap.h" |
|
|
#include "win32/wintap.h" |
|
|
|
|
|
#include <sys/stat.h> |
|
|
|
|
|
#else |
|
|
|
|
|
#include <pwd.h> |
|
|
#endif /* #ifdef WIN32 */ |
|
|
#endif /* #ifdef WIN32 */ |
|
|
|
|
|
|
|
|
#include "n2n_wire.h" |
|
|
#include "n2n_wire.h" |
|
|
#include "n2n_transforms.h" |
|
|
#include "n2n_transforms.h" |
|
|
|
|
|
#include "random_numbers.h" |
|
|
|
|
|
#include "pearson.h" |
|
|
|
|
|
#include "portable_endian.h" |
|
|
|
|
|
#include "speck.h" |
|
|
|
|
|
|
|
|
#ifdef WIN32 |
|
|
#ifdef WIN32 |
|
|
#define N2N_IFNAMSIZ 64 |
|
|
#define N2N_IFNAMSIZ 64 |
|
@ -147,43 +181,6 @@ typedef struct tuntap_dev { |
|
|
#define SOCKET int |
|
|
#define SOCKET int |
|
|
#endif /* #ifndef WIN32 */ |
|
|
#endif /* #ifndef WIN32 */ |
|
|
|
|
|
|
|
|
#define QUICKLZ 1 |
|
|
|
|
|
|
|
|
|
|
|
/* N2N packet header indicators. */ |
|
|
|
|
|
#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_REGISTER_SUPER_ACK 6 |
|
|
|
|
|
#define MSG_TYPE_REGISTER_SUPER_NAK 7 |
|
|
|
|
|
#define MSG_TYPE_FEDERATION 8 |
|
|
|
|
|
#define MSG_TYPE_PEER_INFO 9 |
|
|
|
|
|
#define MSG_TYPE_QUERY_PEER 10 |
|
|
|
|
|
#define MSG_TYPE_MAX_TYPE 10 |
|
|
|
|
|
|
|
|
|
|
|
/* 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). */ |
|
|
|
|
|
#define N2N_COMPRESSION_ID_NONE 0 /* default, see edge_init_conf_defaults(...) in edge_utils.c */ |
|
|
|
|
|
#define N2N_COMPRESSION_ID_LZO 1 /* set if '-z1' or '-z' cli option is present, see setOption(...) in edge.c */ |
|
|
|
|
|
#ifdef N2N_HAVE_ZSTD |
|
|
|
|
|
#define N2N_COMPRESSION_ID_ZSTD 2 /* set if '-z2' cli option is present, available only if compiled with zstd lib */ |
|
|
|
|
|
#define ZSTD_COMPRESSION_LEVEL 7 /* 1 (faster) ... 22 (more compression) */ |
|
|
|
|
|
#endif |
|
|
|
|
|
// with the next major packet structure update, make '0' = invalid, and '1' = no compression
|
|
|
|
|
|
// '2' = LZO, '3' = ZSTD, ... REVISIT then (also: change all occurences in source).
|
|
|
|
|
|
|
|
|
|
|
|
#define N2N_COMPRESSION_ID_BITLEN 3 /* number of bits used for encoding compression id in the uppermost |
|
|
|
|
|
bits of transform_id; will be obsolete as soon as compression gets |
|
|
|
|
|
its own field in the packet. REVISIT then. */ |
|
|
|
|
|
|
|
|
|
|
|
/* forward delcaration of header encryption context, see 'header_encryption.h' */ |
|
|
|
|
|
typedef struct speck_context_t he_context_t; |
|
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_MTU 1290 |
|
|
|
|
|
|
|
|
|
|
|
/** Uncomment this to enable the MTU check, then try to ssh to generate a fragmented packet. */ |
|
|
/** Uncomment this to enable the MTU check, then try to ssh to generate a fragmented packet. */ |
|
|
/** NOTE: see doc/MTU.md for an explanation on the 1400 value */ |
|
|
/** NOTE: see doc/MTU.md for an explanation on the 1400 value */ |
|
|
//#define MTU_ASSERT_VALUE 1400
|
|
|
//#define MTU_ASSERT_VALUE 1400
|
|
@ -206,17 +203,7 @@ struct peer_info { |
|
|
UT_hash_handle hh; /* makes this structure hashable */ |
|
|
UT_hash_handle hh; /* makes this structure hashable */ |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
#define HASH_ADD_PEER(head,add) \ |
|
|
typedef struct speck_context_t he_context_t; |
|
|
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_NUM_SUPERNODES 2 |
|
|
|
|
|
#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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef char n2n_sn_name_t[N2N_EDGE_SN_HOST_SIZE]; |
|
|
typedef char n2n_sn_name_t[N2N_EDGE_SN_HOST_SIZE]; |
|
|
|
|
|
|
|
|
typedef struct n2n_route { |
|
|
typedef struct n2n_route { |
|
@ -261,7 +248,7 @@ typedef struct sn_stats |
|
|
time_t last_reg_super; /* Time when last REGISTER_SUPER was received. */ |
|
|
time_t last_reg_super; /* Time when last REGISTER_SUPER was received. */ |
|
|
} sn_stats_t; |
|
|
} sn_stats_t; |
|
|
|
|
|
|
|
|
struct sn_community |
|
|
struct sn_community |
|
|
{ |
|
|
{ |
|
|
char community[N2N_COMMUNITY_SIZE]; |
|
|
char community[N2N_COMMUNITY_SIZE]; |
|
|
uint8_t header_encryption; /* Header encryption indicator. */ |
|
|
uint8_t header_encryption; /* Header encryption indicator. */ |
|
@ -271,7 +258,7 @@ typedef struct sn_stats |
|
|
UT_hash_handle hh; /* makes this structure hashable */ |
|
|
UT_hash_handle hh; /* makes this structure hashable */ |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
typedef struct n2n_sn |
|
|
typedef struct n2n_sn |
|
|
{ |
|
|
{ |
|
|
time_t start_time; /* Used to measure uptime. */ |
|
|
time_t start_time; /* Used to measure uptime. */ |
|
|
sn_stats_t stats; |
|
|
sn_stats_t stats; |
|
@ -285,6 +272,9 @@ typedef struct sn_stats |
|
|
|
|
|
|
|
|
/* ************************************** */ |
|
|
/* ************************************** */ |
|
|
|
|
|
|
|
|
|
|
|
#include "header_encryption.h" |
|
|
|
|
|
#include "twofish.h" |
|
|
|
|
|
|
|
|
#ifdef __ANDROID_NDK__ |
|
|
#ifdef __ANDROID_NDK__ |
|
|
#include <android/log.h> |
|
|
#include <android/log.h> |
|
|
#endif /* #ifdef __ANDROID_NDK__ */ |
|
|
#endif /* #ifdef __ANDROID_NDK__ */ |
|
@ -298,21 +288,6 @@ typedef struct sn_stats |
|
|
|
|
|
|
|
|
/* ************************************** */ |
|
|
/* ************************************** */ |
|
|
|
|
|
|
|
|
#define SUPERNODE_IP "127.0.0.1" |
|
|
|
|
|
#define SUPERNODE_PORT 1234 |
|
|
|
|
|
|
|
|
|
|
|
/* ************************************** */ |
|
|
|
|
|
|
|
|
|
|
|
#ifndef max |
|
|
|
|
|
#define max(a, b) ((a < b) ? b : a) |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifndef min |
|
|
|
|
|
#define min(a, b) ((a > b) ? b : a) |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
/* ************************************** */ |
|
|
|
|
|
|
|
|
|
|
|
/* Transop Init Functions */ |
|
|
/* Transop Init Functions */ |
|
|
int n2n_transop_null_init(const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt); |
|
|
int n2n_transop_null_init(const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt); |
|
|
int n2n_transop_twofish_init(const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt); |
|
|
int n2n_transop_twofish_init(const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt); |