New upstream version 3.1.1
This commit is contained in:
parent
4e9934e5ec
commit
e7b41df57b
229 changed files with 57000 additions and 12055 deletions
88
include/aes.h
Normal file
88
include/aes.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "n2n.h" // HAVE_OPENSSL_1_1, traceEvent ...
|
||||
|
||||
|
||||
#ifndef AES_H
|
||||
#define AES_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "portable_endian.h"
|
||||
|
||||
#define AES_BLOCK_SIZE 16
|
||||
#define AES_IV_SIZE (AES_BLOCK_SIZE)
|
||||
|
||||
#define AES256_KEY_BYTES (256/8)
|
||||
#define AES192_KEY_BYTES (192/8)
|
||||
#define AES128_KEY_BYTES (128/8)
|
||||
|
||||
|
||||
#if defined (HAVE_OPENSSL_1_1) // openSSL 1.1 ---------------------------------------------------------------------
|
||||
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
typedef struct aes_context_t {
|
||||
EVP_CIPHER_CTX *enc_ctx; /* openssl's reusable evp_* en/de-cryption context */
|
||||
EVP_CIPHER_CTX *dec_ctx; /* openssl's reusable evp_* en/de-cryption context */
|
||||
const EVP_CIPHER *cipher; /* cipher to use: e.g. EVP_aes_128_cbc */
|
||||
uint8_t key[AES256_KEY_BYTES]; /* the pure key data for payload encryption & decryption */
|
||||
AES_KEY ecb_dec_key; /* one step ecb decryption key */
|
||||
} aes_context_t;
|
||||
|
||||
#elif defined (__AES__) && defined (__SSE2__) // Intel's AES-NI ---------------------------------------------------
|
||||
|
||||
#include <immintrin.h>
|
||||
|
||||
typedef struct aes_context_t {
|
||||
__m128i rk_enc[15];
|
||||
__m128i rk_dec[15];
|
||||
int Nr;
|
||||
} aes_context_t;
|
||||
|
||||
#else // plain C --------------------------------------------------------------------------------------------------
|
||||
|
||||
typedef struct aes_context_t {
|
||||
uint32_t enc_rk[60]; // round keys for encryption
|
||||
uint32_t dec_rk[60]; // round keys for decryption
|
||||
int Nr; // number of rounds
|
||||
} aes_context_t;
|
||||
|
||||
#endif // ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int aes_cbc_encrypt (unsigned char *out, const unsigned char *in, size_t in_len,
|
||||
const unsigned char *iv, aes_context_t *ctx);
|
||||
|
||||
int aes_cbc_decrypt (unsigned char *out, const unsigned char *in, size_t in_len,
|
||||
const unsigned char *iv, aes_context_t *ctx);
|
||||
|
||||
int aes_ecb_decrypt (unsigned char *out, const unsigned char *in, aes_context_t *ctx);
|
||||
|
||||
int aes_init (const unsigned char *key, size_t key_size, aes_context_t **ctx);
|
||||
|
||||
int aes_deinit (aes_context_t *ctx);
|
||||
|
||||
|
||||
#endif // AES_H
|
43
include/auth.h
Normal file
43
include/auth.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "n2n.h"
|
||||
|
||||
|
||||
#ifndef AUTH_H
|
||||
#define AUTH_H
|
||||
|
||||
|
||||
int bin_to_ascii (char *out, uint8_t *in, size_t in_len);
|
||||
|
||||
int ascii_to_bin (uint8_t *out, char *in);
|
||||
|
||||
int generate_private_key (n2n_private_public_key_t key, char *in);
|
||||
|
||||
int generate_public_key (n2n_private_public_key_t pub, n2n_private_public_key_t prv);
|
||||
|
||||
int generate_shared_secret (n2n_private_public_key_t shared, n2n_private_public_key_t prv, n2n_private_public_key_t pub);
|
||||
|
||||
int bind_private_key_to_username (n2n_private_public_key_t prv, char *username);
|
||||
|
||||
int calculate_dynamic_key (uint8_t out_key[N2N_AUTH_CHALLENGE_SIZE],
|
||||
uint32_t key_time, n2n_community_t comm, n2n_community_t fed);
|
||||
|
||||
|
||||
#endif
|
78
include/cc20.h
Normal file
78
include/cc20.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CC20_H
|
||||
#define CC20_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "n2n.h" // HAVE_OPENSSL_1_1, traceEvent ...
|
||||
|
||||
|
||||
#define CC20_IV_SIZE 16
|
||||
#define CC20_KEY_BYTES (256/8)
|
||||
|
||||
|
||||
#ifdef HAVE_OPENSSL_1_1 // openSSL 1.1 ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
typedef struct cc20_context_t {
|
||||
EVP_CIPHER_CTX *ctx; /* openssl's reusable evp_* en/de-cryption context */
|
||||
const EVP_CIPHER *cipher; /* cipher to use: e.g. EVP_chacha20() */
|
||||
uint8_t key[CC20_KEY_BYTES]; /* the pure key data for payload encryption & decryption */
|
||||
} cc20_context_t;
|
||||
|
||||
|
||||
#elif defined (__SSE2__) // SSE2 ---------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include <immintrin.h>
|
||||
|
||||
typedef struct cc20_context {
|
||||
uint32_t keystream32[16];
|
||||
uint8_t key[CC20_KEY_BYTES];
|
||||
} cc20_context_t;
|
||||
|
||||
|
||||
#else // plain C --------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
typedef struct cc20_context {
|
||||
uint32_t keystream32[16];
|
||||
uint32_t state[16];
|
||||
uint8_t key[CC20_KEY_BYTES];
|
||||
} cc20_context_t;
|
||||
|
||||
|
||||
#endif // openSSL 1.1, plain C ------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int cc20_crypt (unsigned char *out, const unsigned char *in, size_t in_len,
|
||||
const unsigned char *iv, cc20_context_t *ctx);
|
||||
|
||||
int cc20_init (const unsigned char *key, cc20_context_t **ctx);
|
||||
|
||||
int cc20_deinit (cc20_context_t *ctx);
|
||||
|
||||
|
||||
#endif // CC20_H
|
20
include/curve25519.h
Normal file
20
include/curve25519.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
void curve25519 (unsigned char *q, const unsigned char *n, const unsigned char *p);
|
52
include/edge_utils_win32.h
Normal file
52
include/edge_utils_win32.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _EDGE_UTILS_WIN32_H_
|
||||
#define _EDGE_UTILS_WIN32_H_
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
#include <process.h>
|
||||
#include <n2n.h>
|
||||
#include <winsock2.h>
|
||||
#include <iphlpapi.h>
|
||||
|
||||
|
||||
/* Multicast peers discovery disabled due to https://github.com/ntop/n2n/issues/65 */
|
||||
|
||||
/* Currently, multicast is performed by specifying the default routing network adapter.
|
||||
* If the solution is determined to be stable and effective,
|
||||
* all macro definitions "SKIP_MULTICAST_PEERS_DISCOVERY" will be completely deleted in the future.
|
||||
*/
|
||||
//#define SKIP_MULTICAST_PEERS_DISCOVERY
|
||||
|
||||
// TODO: this struct is pretty empty now, collapse it to just n2n_edge_t ?
|
||||
struct tunread_arg {
|
||||
n2n_edge_t *eee;
|
||||
};
|
||||
|
||||
extern HANDLE startTunReadThread (struct tunread_arg *arg);
|
||||
int get_best_interface_ip (n2n_edge_t * eee, dec_ip_str_t ip_addr);
|
||||
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#endif /* _EDGE_UTILS_WIN32_H_ */
|
||||
|
35
include/header_encryption.h
Normal file
35
include/header_encryption.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
int packet_header_decrypt (uint8_t packet[], uint16_t packet_len,
|
||||
char *community_name,
|
||||
he_context_t *ctx, he_context_t *ctx_iv,
|
||||
uint64_t *stamp);
|
||||
|
||||
int packet_header_encrypt (uint8_t packet[], uint16_t header_len, uint16_t packet_len,
|
||||
he_context_t *ctx, he_context_t *ctx_iv,
|
||||
uint64_t stamp);
|
||||
|
||||
void packet_header_setup_key (const char *community_name,
|
||||
he_context_t **ctx_static, he_context_t **ctx_dynamic,
|
||||
he_context_t **ctx_iv_static, he_context_t **ctx_iv_dynamic);
|
||||
|
||||
void packet_header_change_dynamic_key (uint8_t *key_dynamic,
|
||||
he_context_t **ctx_dynamic,
|
||||
he_context_t **ctx_iv_dynamic);
|
6
include/hexdump.h
Normal file
6
include/hexdump.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef HEXDUMP_H
|
||||
#define HEXDUMP_H
|
||||
|
||||
void fhexdump(unsigned int display_addr, void *in, int size, FILE *stream);
|
||||
|
||||
#endif
|
472
include/lzoconf.h
Normal file
472
include/lzoconf.h
Normal file
|
@ -0,0 +1,472 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* lzoconf.h -- configuration of the LZO data compression library
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
The LZO library 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 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __LZOCONF_H_INCLUDED
|
||||
#define __LZOCONF_H_INCLUDED 1
|
||||
|
||||
#define LZO_VERSION 0x20a0 /* 2.10 */
|
||||
#define LZO_VERSION_STRING "2.10"
|
||||
#define LZO_VERSION_DATE "Mar 01 2017"
|
||||
|
||||
/* internal Autoconf configuration file - only used when building LZO */
|
||||
#if defined(LZO_HAVE_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// LZO requires a conforming <limits.h>
|
||||
************************************************************************/
|
||||
|
||||
#if !defined(CHAR_BIT) || (CHAR_BIT != 8)
|
||||
# error "invalid CHAR_BIT"
|
||||
#endif
|
||||
#if !defined(UCHAR_MAX) || !defined(USHRT_MAX) || !defined(UINT_MAX) || !defined(ULONG_MAX)
|
||||
# error "check your compiler installation"
|
||||
#endif
|
||||
#if (USHRT_MAX < 1) || (UINT_MAX < 1) || (ULONG_MAX < 1)
|
||||
# error "your limits.h macros are broken"
|
||||
#endif
|
||||
|
||||
/* get OS and architecture defines */
|
||||
#ifndef __LZODEFS_H_INCLUDED
|
||||
#include <lzo/lzodefs.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// some core defines
|
||||
************************************************************************/
|
||||
|
||||
/* memory checkers */
|
||||
#if !defined(__LZO_CHECKER)
|
||||
# if defined(__BOUNDS_CHECKING_ON)
|
||||
# define __LZO_CHECKER 1
|
||||
# elif defined(__CHECKER__)
|
||||
# define __LZO_CHECKER 1
|
||||
# elif defined(__INSURE__)
|
||||
# define __LZO_CHECKER 1
|
||||
# elif defined(__PURIFY__)
|
||||
# define __LZO_CHECKER 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// integral and pointer types
|
||||
************************************************************************/
|
||||
|
||||
/* lzo_uint must match size_t */
|
||||
#if !defined(LZO_UINT_MAX)
|
||||
# if (LZO_ABI_LLP64)
|
||||
# if (LZO_OS_WIN64)
|
||||
typedef unsigned __int64 lzo_uint;
|
||||
typedef __int64 lzo_int;
|
||||
# define LZO_TYPEOF_LZO_INT LZO_TYPEOF___INT64
|
||||
# else
|
||||
typedef lzo_ullong_t lzo_uint;
|
||||
typedef lzo_llong_t lzo_int;
|
||||
# define LZO_TYPEOF_LZO_INT LZO_TYPEOF_LONG_LONG
|
||||
# endif
|
||||
# define LZO_SIZEOF_LZO_INT 8
|
||||
# define LZO_UINT_MAX 0xffffffffffffffffull
|
||||
# define LZO_INT_MAX 9223372036854775807LL
|
||||
# define LZO_INT_MIN (-1LL - LZO_INT_MAX)
|
||||
# elif (LZO_ABI_IP32L64) /* MIPS R5900 */
|
||||
typedef unsigned int lzo_uint;
|
||||
typedef int lzo_int;
|
||||
# define LZO_SIZEOF_LZO_INT LZO_SIZEOF_INT
|
||||
# define LZO_TYPEOF_LZO_INT LZO_TYPEOF_INT
|
||||
# define LZO_UINT_MAX UINT_MAX
|
||||
# define LZO_INT_MAX INT_MAX
|
||||
# define LZO_INT_MIN INT_MIN
|
||||
# elif (ULONG_MAX >= LZO_0xffffffffL)
|
||||
typedef unsigned long lzo_uint;
|
||||
typedef long lzo_int;
|
||||
# define LZO_SIZEOF_LZO_INT LZO_SIZEOF_LONG
|
||||
# define LZO_TYPEOF_LZO_INT LZO_TYPEOF_LONG
|
||||
# define LZO_UINT_MAX ULONG_MAX
|
||||
# define LZO_INT_MAX LONG_MAX
|
||||
# define LZO_INT_MIN LONG_MIN
|
||||
# else
|
||||
# error "lzo_uint"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* The larger type of lzo_uint and lzo_uint32_t. */
|
||||
#if (LZO_SIZEOF_LZO_INT >= 4)
|
||||
# define lzo_xint lzo_uint
|
||||
#else
|
||||
# define lzo_xint lzo_uint32_t
|
||||
#endif
|
||||
|
||||
typedef int lzo_bool;
|
||||
|
||||
/* sanity checks */
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_int) == LZO_SIZEOF_LZO_INT)
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == LZO_SIZEOF_LZO_INT)
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_xint) >= sizeof(lzo_uint))
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_xint) >= sizeof(lzo_uint32_t))
|
||||
|
||||
#ifndef __LZO_MMODEL
|
||||
#define __LZO_MMODEL /*empty*/
|
||||
#endif
|
||||
|
||||
/* no typedef here because of const-pointer issues */
|
||||
#define lzo_bytep unsigned char __LZO_MMODEL *
|
||||
#define lzo_charp char __LZO_MMODEL *
|
||||
#define lzo_voidp void __LZO_MMODEL *
|
||||
#define lzo_shortp short __LZO_MMODEL *
|
||||
#define lzo_ushortp unsigned short __LZO_MMODEL *
|
||||
#define lzo_intp lzo_int __LZO_MMODEL *
|
||||
#define lzo_uintp lzo_uint __LZO_MMODEL *
|
||||
#define lzo_xintp lzo_xint __LZO_MMODEL *
|
||||
#define lzo_voidpp lzo_voidp __LZO_MMODEL *
|
||||
#define lzo_bytepp lzo_bytep __LZO_MMODEL *
|
||||
|
||||
#define lzo_int8_tp lzo_int8_t __LZO_MMODEL *
|
||||
#define lzo_uint8_tp lzo_uint8_t __LZO_MMODEL *
|
||||
#define lzo_int16_tp lzo_int16_t __LZO_MMODEL *
|
||||
#define lzo_uint16_tp lzo_uint16_t __LZO_MMODEL *
|
||||
#define lzo_int32_tp lzo_int32_t __LZO_MMODEL *
|
||||
#define lzo_uint32_tp lzo_uint32_t __LZO_MMODEL *
|
||||
#if defined(lzo_int64_t)
|
||||
#define lzo_int64_tp lzo_int64_t __LZO_MMODEL *
|
||||
#define lzo_uint64_tp lzo_uint64_t __LZO_MMODEL *
|
||||
#endif
|
||||
|
||||
/* Older LZO versions used to support ancient systems and memory models
|
||||
* such as 16-bit MSDOS with __huge pointers or Cray PVP, but these
|
||||
* obsolete configurations are not supported any longer.
|
||||
*/
|
||||
#if defined(__LZO_MMODEL_HUGE)
|
||||
#error "__LZO_MMODEL_HUGE memory model is unsupported"
|
||||
#endif
|
||||
#if (LZO_MM_PVP)
|
||||
#error "LZO_MM_PVP memory model is unsupported"
|
||||
#endif
|
||||
#if (LZO_SIZEOF_INT < 4)
|
||||
#error "LZO_SIZEOF_INT < 4 is unsupported"
|
||||
#endif
|
||||
#if (__LZO_UINTPTR_T_IS_POINTER)
|
||||
#error "__LZO_UINTPTR_T_IS_POINTER is unsupported"
|
||||
#endif
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(int) >= 4)
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) >= 4)
|
||||
/* Strange configurations where sizeof(lzo_uint) != sizeof(size_t) should
|
||||
* work but have not received much testing lately, so be strict here.
|
||||
*/
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(size_t))
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(ptrdiff_t))
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(lzo_uint) == sizeof(lzo_uintptr_t))
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(void *) == sizeof(lzo_uintptr_t))
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(char *) == sizeof(lzo_uintptr_t))
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(long *) == sizeof(lzo_uintptr_t))
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(void *) == sizeof(lzo_voidp))
|
||||
LZO_COMPILE_TIME_ASSERT_HEADER(sizeof(char *) == sizeof(lzo_bytep))
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// function types
|
||||
************************************************************************/
|
||||
|
||||
/* name mangling */
|
||||
#if !defined(__LZO_EXTERN_C)
|
||||
# ifdef __cplusplus
|
||||
# define __LZO_EXTERN_C extern "C"
|
||||
# else
|
||||
# define __LZO_EXTERN_C extern
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* calling convention */
|
||||
#if !defined(__LZO_CDECL)
|
||||
# define __LZO_CDECL __lzo_cdecl
|
||||
#endif
|
||||
|
||||
/* DLL export information */
|
||||
#if !defined(__LZO_EXPORT1)
|
||||
# define __LZO_EXPORT1 /*empty*/
|
||||
#endif
|
||||
#if !defined(__LZO_EXPORT2)
|
||||
# define __LZO_EXPORT2 /*empty*/
|
||||
#endif
|
||||
|
||||
/* __cdecl calling convention for public C and assembly functions */
|
||||
#if !defined(LZO_PUBLIC)
|
||||
# define LZO_PUBLIC(r) __LZO_EXPORT1 r __LZO_EXPORT2 __LZO_CDECL
|
||||
#endif
|
||||
#if !defined(LZO_EXTERN)
|
||||
# define LZO_EXTERN(r) __LZO_EXTERN_C LZO_PUBLIC(r)
|
||||
#endif
|
||||
#if !defined(LZO_PRIVATE)
|
||||
# define LZO_PRIVATE(r) static r __LZO_CDECL
|
||||
#endif
|
||||
|
||||
/* function types */
|
||||
typedef int
|
||||
(__LZO_CDECL *lzo_compress_t) ( const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem );
|
||||
|
||||
typedef int
|
||||
(__LZO_CDECL *lzo_decompress_t) ( const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem );
|
||||
|
||||
typedef int
|
||||
(__LZO_CDECL *lzo_optimize_t) ( lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem );
|
||||
|
||||
typedef int
|
||||
(__LZO_CDECL *lzo_compress_dict_t)(const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem,
|
||||
const lzo_bytep dict, lzo_uint dict_len );
|
||||
|
||||
typedef int
|
||||
(__LZO_CDECL *lzo_decompress_dict_t)(const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem,
|
||||
const lzo_bytep dict, lzo_uint dict_len );
|
||||
|
||||
|
||||
/* Callback interface. Currently only the progress indicator ("nprogress")
|
||||
* is used, but this may change in a future release. */
|
||||
|
||||
struct lzo_callback_t;
|
||||
typedef struct lzo_callback_t lzo_callback_t;
|
||||
#define lzo_callback_p lzo_callback_t __LZO_MMODEL *
|
||||
|
||||
/* malloc & free function types */
|
||||
typedef lzo_voidp (__LZO_CDECL *lzo_alloc_func_t)
|
||||
(lzo_callback_p self, lzo_uint items, lzo_uint size);
|
||||
typedef void (__LZO_CDECL *lzo_free_func_t)
|
||||
(lzo_callback_p self, lzo_voidp ptr);
|
||||
|
||||
/* a progress indicator callback function */
|
||||
typedef void (__LZO_CDECL *lzo_progress_func_t)
|
||||
(lzo_callback_p, lzo_uint, lzo_uint, int);
|
||||
|
||||
struct lzo_callback_t
|
||||
{
|
||||
/* custom allocators (set to 0 to disable) */
|
||||
lzo_alloc_func_t nalloc; /* [not used right now] */
|
||||
lzo_free_func_t nfree; /* [not used right now] */
|
||||
|
||||
/* a progress indicator callback function (set to 0 to disable) */
|
||||
lzo_progress_func_t nprogress;
|
||||
|
||||
/* INFO: the first parameter "self" of the nalloc/nfree/nprogress
|
||||
* callbacks points back to this struct, so you are free to store
|
||||
* some extra info in the following variables. */
|
||||
lzo_voidp user1;
|
||||
lzo_xint user2;
|
||||
lzo_xint user3;
|
||||
};
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// error codes and prototypes
|
||||
************************************************************************/
|
||||
|
||||
/* Error codes for the compression/decompression functions. Negative
|
||||
* values are errors, positive values will be used for special but
|
||||
* normal events.
|
||||
*/
|
||||
#define LZO_E_OK 0
|
||||
#define LZO_E_ERROR (-1)
|
||||
#define LZO_E_OUT_OF_MEMORY (-2) /* [lzo_alloc_func_t failure] */
|
||||
#define LZO_E_NOT_COMPRESSIBLE (-3) /* [not used right now] */
|
||||
#define LZO_E_INPUT_OVERRUN (-4)
|
||||
#define LZO_E_OUTPUT_OVERRUN (-5)
|
||||
#define LZO_E_LOOKBEHIND_OVERRUN (-6)
|
||||
#define LZO_E_EOF_NOT_FOUND (-7)
|
||||
#define LZO_E_INPUT_NOT_CONSUMED (-8)
|
||||
#define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */
|
||||
#define LZO_E_INVALID_ARGUMENT (-10)
|
||||
#define LZO_E_INVALID_ALIGNMENT (-11) /* pointer argument is not properly aligned */
|
||||
#define LZO_E_OUTPUT_NOT_CONSUMED (-12)
|
||||
#define LZO_E_INTERNAL_ERROR (-99)
|
||||
|
||||
|
||||
#ifndef lzo_sizeof_dict_t
|
||||
# define lzo_sizeof_dict_t ((unsigned)sizeof(lzo_bytep))
|
||||
#endif
|
||||
|
||||
/* lzo_init() should be the first function you call.
|
||||
* Check the return code !
|
||||
*
|
||||
* lzo_init() is a macro to allow checking that the library and the
|
||||
* compiler's view of various types are consistent.
|
||||
*/
|
||||
#define lzo_init() __lzo_init_v2(LZO_VERSION,(int)sizeof(short),(int)sizeof(int),\
|
||||
(int)sizeof(long),(int)sizeof(lzo_uint32_t),(int)sizeof(lzo_uint),\
|
||||
(int)lzo_sizeof_dict_t,(int)sizeof(char *),(int)sizeof(lzo_voidp),\
|
||||
(int)sizeof(lzo_callback_t))
|
||||
LZO_EXTERN(int) __lzo_init_v2(unsigned,int,int,int,int,int,int,int,int,int);
|
||||
|
||||
/* version functions (useful for shared libraries) */
|
||||
LZO_EXTERN(unsigned) lzo_version(void);
|
||||
LZO_EXTERN(const char *) lzo_version_string(void);
|
||||
LZO_EXTERN(const char *) lzo_version_date(void);
|
||||
LZO_EXTERN(const lzo_charp) _lzo_version_string(void);
|
||||
LZO_EXTERN(const lzo_charp) _lzo_version_date(void);
|
||||
|
||||
/* string functions */
|
||||
LZO_EXTERN(int)
|
||||
lzo_memcmp(const lzo_voidp a, const lzo_voidp b, lzo_uint len);
|
||||
LZO_EXTERN(lzo_voidp)
|
||||
lzo_memcpy(lzo_voidp dst, const lzo_voidp src, lzo_uint len);
|
||||
LZO_EXTERN(lzo_voidp)
|
||||
lzo_memmove(lzo_voidp dst, const lzo_voidp src, lzo_uint len);
|
||||
LZO_EXTERN(lzo_voidp)
|
||||
lzo_memset(lzo_voidp buf, int c, lzo_uint len);
|
||||
|
||||
/* checksum functions */
|
||||
LZO_EXTERN(lzo_uint32_t)
|
||||
lzo_adler32(lzo_uint32_t c, const lzo_bytep buf, lzo_uint len);
|
||||
LZO_EXTERN(lzo_uint32_t)
|
||||
lzo_crc32(lzo_uint32_t c, const lzo_bytep buf, lzo_uint len);
|
||||
LZO_EXTERN(const lzo_uint32_tp)
|
||||
lzo_get_crc32_table(void);
|
||||
|
||||
/* misc. */
|
||||
LZO_EXTERN(int) _lzo_config_check(void);
|
||||
typedef union {
|
||||
lzo_voidp a00; lzo_bytep a01; lzo_uint a02; lzo_xint a03; lzo_uintptr_t a04;
|
||||
void *a05; unsigned char *a06; unsigned long a07; size_t a08; ptrdiff_t a09;
|
||||
#if defined(lzo_int64_t)
|
||||
lzo_uint64_t a10;
|
||||
#endif
|
||||
} lzo_align_t;
|
||||
|
||||
/* align a char pointer on a boundary that is a multiple of 'size' */
|
||||
LZO_EXTERN(unsigned) __lzo_align_gap(const lzo_voidp p, lzo_uint size);
|
||||
#define LZO_PTR_ALIGN_UP(p,size) \
|
||||
((p) + (lzo_uint) __lzo_align_gap((const lzo_voidp)(p),(lzo_uint)(size)))
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// deprecated macros - only for backward compatibility
|
||||
************************************************************************/
|
||||
|
||||
/* deprecated - use 'lzo_bytep' instead of 'lzo_byte *' */
|
||||
#define lzo_byte unsigned char
|
||||
/* deprecated type names */
|
||||
#define lzo_int32 lzo_int32_t
|
||||
#define lzo_uint32 lzo_uint32_t
|
||||
#define lzo_int32p lzo_int32_t __LZO_MMODEL *
|
||||
#define lzo_uint32p lzo_uint32_t __LZO_MMODEL *
|
||||
#define LZO_INT32_MAX LZO_INT32_C(2147483647)
|
||||
#define LZO_UINT32_MAX LZO_UINT32_C(4294967295)
|
||||
#if defined(lzo_int64_t)
|
||||
#define lzo_int64 lzo_int64_t
|
||||
#define lzo_uint64 lzo_uint64_t
|
||||
#define lzo_int64p lzo_int64_t __LZO_MMODEL *
|
||||
#define lzo_uint64p lzo_uint64_t __LZO_MMODEL *
|
||||
#define LZO_INT64_MAX LZO_INT64_C(9223372036854775807)
|
||||
#define LZO_UINT64_MAX LZO_UINT64_C(18446744073709551615)
|
||||
#endif
|
||||
/* deprecated types */
|
||||
typedef union { lzo_bytep a; lzo_uint b; } __lzo_pu_u;
|
||||
typedef union { lzo_bytep a; lzo_uint32_t b; } __lzo_pu32_u;
|
||||
/* deprecated defines */
|
||||
#if !defined(LZO_SIZEOF_LZO_UINT)
|
||||
# define LZO_SIZEOF_LZO_UINT LZO_SIZEOF_LZO_INT
|
||||
#endif
|
||||
|
||||
#if defined(LZO_CFG_COMPAT)
|
||||
|
||||
#define __LZOCONF_H 1
|
||||
|
||||
#if defined(LZO_ARCH_I086)
|
||||
# define __LZO_i386 1
|
||||
#elif defined(LZO_ARCH_I386)
|
||||
# define __LZO_i386 1
|
||||
#endif
|
||||
|
||||
#if defined(LZO_OS_DOS16)
|
||||
# define __LZO_DOS 1
|
||||
# define __LZO_DOS16 1
|
||||
#elif defined(LZO_OS_DOS32)
|
||||
# define __LZO_DOS 1
|
||||
#elif defined(LZO_OS_WIN16)
|
||||
# define __LZO_WIN 1
|
||||
# define __LZO_WIN16 1
|
||||
#elif defined(LZO_OS_WIN32)
|
||||
# define __LZO_WIN 1
|
||||
#endif
|
||||
|
||||
#define __LZO_CMODEL /*empty*/
|
||||
#define __LZO_DMODEL /*empty*/
|
||||
#define __LZO_ENTRY __LZO_CDECL
|
||||
#define LZO_EXTERN_CDECL LZO_EXTERN
|
||||
#define LZO_ALIGN LZO_PTR_ALIGN_UP
|
||||
|
||||
#define lzo_compress_asm_t lzo_compress_t
|
||||
#define lzo_decompress_asm_t lzo_decompress_t
|
||||
|
||||
#endif /* LZO_CFG_COMPAT */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/* vim:set ts=4 sw=4 et: */
|
3286
include/lzodefs.h
Normal file
3286
include/lzodefs.h
Normal file
File diff suppressed because it is too large
Load diff
125
include/minilzo.h
Normal file
125
include/minilzo.h
Normal file
|
@ -0,0 +1,125 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* minilzo.h -- mini subset of the LZO real-time data compression library
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
The LZO library 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 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
*/
|
||||
|
||||
/*
|
||||
* NOTE:
|
||||
* the full LZO package can be found at
|
||||
* http://www.oberhumer.com/opensource/lzo/
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MINILZO_H_INCLUDED
|
||||
#define __MINILZO_H_INCLUDED 1
|
||||
|
||||
#define MINILZO_VERSION 0x20a0 /* 2.10 */
|
||||
|
||||
#if defined(__LZOCONF_H_INCLUDED)
|
||||
# error "you cannot use both LZO and miniLZO"
|
||||
#endif
|
||||
|
||||
/* internal Autoconf configuration file - only used when building miniLZO */
|
||||
#ifdef MINILZO_HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#ifndef __LZODEFS_H_INCLUDED
|
||||
#include "lzodefs.h"
|
||||
#endif
|
||||
#undef LZO_HAVE_CONFIG_H
|
||||
#include "lzoconf.h"
|
||||
|
||||
#if !defined(LZO_VERSION) || (LZO_VERSION != MINILZO_VERSION)
|
||||
# error "version mismatch in header files"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
|
||||
/* Memory required for the wrkmem parameter.
|
||||
* When the required size is 0, you can also pass a NULL pointer.
|
||||
*/
|
||||
|
||||
#define LZO1X_MEM_COMPRESS LZO1X_1_MEM_COMPRESS
|
||||
#define LZO1X_1_MEM_COMPRESS ((lzo_uint32_t) (16384L * lzo_sizeof_dict_t))
|
||||
#define LZO1X_MEM_DECOMPRESS (0)
|
||||
|
||||
|
||||
/* compression */
|
||||
LZO_EXTERN(int)
|
||||
lzo1x_1_compress ( const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem );
|
||||
|
||||
/* decompression */
|
||||
LZO_EXTERN(int)
|
||||
lzo1x_decompress ( const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem /* NOT USED */ );
|
||||
|
||||
/* safe decompression with overrun testing */
|
||||
LZO_EXTERN(int)
|
||||
lzo1x_decompress_safe ( const lzo_bytep src, lzo_uint src_len,
|
||||
lzo_bytep dst, lzo_uintp dst_len,
|
||||
lzo_voidp wrkmem /* NOT USED */ );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/* vim:set ts=4 sw=4 et: */
|
295
include/n2n.h
Normal file
295
include/n2n.h
Normal file
|
@ -0,0 +1,295 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _N2N_H_
|
||||
#define _N2N_H_
|
||||
|
||||
/*
|
||||
tunctl -t tun0
|
||||
tunctl -t tun1
|
||||
ifconfig tun0 1.2.3.4 up
|
||||
ifconfig tun1 1.2.3.5 up
|
||||
./edge -d tun0 -l 2000 -r 127.0.0.1:3000 -c hello
|
||||
./edge -d tun1 -l 3000 -r 127.0.0.1:2000 -c hello
|
||||
|
||||
|
||||
tunctl -u UID -t tunX
|
||||
*/
|
||||
|
||||
#define SN_MANUAL_MAC /* allows supernode MAC address to be set manually */
|
||||
|
||||
#define N2N_HAVE_DAEMON /* needs to be defined before it gets undefined */
|
||||
#define N2N_HAVE_TCP /* needs to be defined before it gets undefined */
|
||||
|
||||
/* #define N2N_CAN_NAME_IFACE */
|
||||
|
||||
/* Moved here to define _CRT_SECURE_NO_WARNINGS before all the including takes place */
|
||||
#ifdef WIN32
|
||||
#ifndef CMAKE_BUILD
|
||||
#include "config.h" /* Visual C++ */
|
||||
#else
|
||||
#include "winconfig.h"
|
||||
#endif
|
||||
#define N2N_CAN_NAME_IFACE 1
|
||||
#undef N2N_HAVE_DAEMON
|
||||
#undef N2N_HAVE_TCP /* as explained on https://github.com/ntop/n2n/pull/627#issuecomment-782093706 */
|
||||
#undef N2N_HAVE_SETUID
|
||||
#else
|
||||
#ifndef CMAKE_BUILD
|
||||
#include "config.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define PACKAGE_BUILDDATE (__DATE__ " " __TIME__)
|
||||
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <getopt.h>
|
||||
#endif /* #ifndef _MSC_VER */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/param.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#define N2N_CAN_NAME_IFACE 1
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.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>
|
||||
#endif /* #ifdef __linux__ */
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <netinet/in_systm.h>
|
||||
#endif /* #ifdef __FreeBSD__ */
|
||||
|
||||
#include <syslog.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#ifdef HAVE_ZSTD
|
||||
#include <zstd.h>
|
||||
#endif
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
#if defined (HAVE_OPENSSL_1_1)
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
#endif
|
||||
|
||||
#define closesocket(a) close(a)
|
||||
#endif /* #ifndef WIN32 */
|
||||
|
||||
#include "minilzo.h"
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include "lzoconf.h"
|
||||
#include "uthash.h"
|
||||
#include "n2n_define.h"
|
||||
#include "n2n_typedefs.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winsock2.h> /* for tcp */
|
||||
#define SHUT_RDWR SD_BOTH /* for tcp */
|
||||
#include "wintap.h"
|
||||
#include <sys/stat.h>
|
||||
#else
|
||||
#include <pwd.h>
|
||||
#endif /* #ifdef WIN32 */
|
||||
|
||||
#include "n2n_wire.h"
|
||||
#include "random_numbers.h"
|
||||
#include "pearson.h"
|
||||
#include "portable_endian.h"
|
||||
#include "aes.h"
|
||||
#include "cc20.h"
|
||||
#include "speck.h"
|
||||
#include "curve25519.h"
|
||||
#include "n2n_regex.h"
|
||||
#include "sn_selection.h"
|
||||
#include "network_traffic_filter.h"
|
||||
#include "auth.h"
|
||||
|
||||
#if defined(HAVE_MINIUPNP) || defined(HAVE_NATPMP)
|
||||
#include "n2n_port_mapping.h"
|
||||
#endif // HAVE_MINIUPNP || HAVE_NATPMP
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
#include "header_encryption.h"
|
||||
#include "tf.h"
|
||||
|
||||
#ifndef TRACE_ERROR
|
||||
#define TRACE_ERROR 0, __FILE__, __LINE__
|
||||
#define TRACE_WARNING 1, __FILE__, __LINE__
|
||||
#define TRACE_NORMAL 2, __FILE__, __LINE__
|
||||
#define TRACE_INFO 3, __FILE__, __LINE__
|
||||
#define TRACE_DEBUG 4, __FILE__, __LINE__
|
||||
#endif
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
/* Transop Init Functions */
|
||||
int n2n_transop_null_init (const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt);
|
||||
int n2n_transop_tf_init (const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt);
|
||||
int n2n_transop_aes_init (const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt);
|
||||
int n2n_transop_cc20_init (const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt);
|
||||
int n2n_transop_speck_init (const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt);
|
||||
int n2n_transop_lzo_init (const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt);
|
||||
#ifdef HAVE_ZSTD
|
||||
int n2n_transop_zstd_init (const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt);
|
||||
#endif
|
||||
|
||||
/* Log */
|
||||
void setTraceLevel (int level);
|
||||
void setUseSyslog (int use_syslog);
|
||||
void setTraceFile (FILE *f);
|
||||
int getTraceLevel ();
|
||||
void closeTraceFile ();
|
||||
void traceEvent (int eventTraceLevel, char* file, int line, char * format, ...);
|
||||
|
||||
/* Tuntap API */
|
||||
int tuntap_open (struct tuntap_dev *device, char *dev, const char *address_mode, char *device_ip,
|
||||
char *device_mask, const char * device_mac, int mtu
|
||||
#ifdef WIN32
|
||||
, int metric
|
||||
#endif
|
||||
);
|
||||
int tuntap_read (struct tuntap_dev *tuntap, unsigned char *buf, int len);
|
||||
int tuntap_write (struct tuntap_dev *tuntap, unsigned char *buf, int len);
|
||||
void tuntap_close (struct tuntap_dev *tuntap);
|
||||
void tuntap_get_address (struct tuntap_dev *tuntap);
|
||||
|
||||
/* Utils */
|
||||
char* intoa (uint32_t addr, char* buf, uint16_t buf_len);
|
||||
uint32_t bitlen2mask (uint8_t bitlen);
|
||||
uint8_t mask2bitlen (uint32_t mask);
|
||||
char* macaddr_str (macstr_t buf, const n2n_mac_t mac);
|
||||
int str2mac (uint8_t * outmac /* 6 bytes */, const char * s);
|
||||
int supernode2sock (n2n_sock_t * sn, const n2n_sn_name_t addrIn);
|
||||
uint8_t is_multi_broadcast (const n2n_mac_t dest_mac);
|
||||
uint8_t is_broadcast (const n2n_mac_t dest_mac);
|
||||
uint8_t is_null_mac (const n2n_mac_t dest_mac);
|
||||
char* msg_type2str (uint16_t msg_type);
|
||||
void hexdump (const uint8_t * buf, size_t len);
|
||||
void print_n2n_version ();
|
||||
int is_empty_ip_address (const n2n_sock_t * sock);
|
||||
void print_edge_stats (const n2n_edge_t *eee);
|
||||
int memrnd (uint8_t *address, size_t len);
|
||||
int memxor (uint8_t *destination, const uint8_t *source, size_t len);
|
||||
|
||||
/* Sockets */
|
||||
char* sock_to_cstr (n2n_sock_str_t out,
|
||||
const n2n_sock_t * sock);
|
||||
char * ip_subnet_to_str (dec_ip_bit_str_t buf, const n2n_ip_subnet_t *ipaddr);
|
||||
SOCKET open_socket (int local_port, in_addr_t address, int type);
|
||||
int sock_equal (const n2n_sock_t * a,
|
||||
const n2n_sock_t * b);
|
||||
|
||||
/* Header encryption */
|
||||
uint64_t time_stamp (void);
|
||||
uint64_t initial_time_stamp (void);
|
||||
int time_stamp_verify_and_update (uint64_t stamp, uint64_t * previous_stamp, int allow_jitter);
|
||||
|
||||
/* Operations on peer_info lists. */
|
||||
size_t purge_peer_list (struct peer_info ** peer_list,
|
||||
SOCKET socket_not_to_close,
|
||||
n2n_tcp_connection_t **tcp_connections,
|
||||
time_t purge_before);
|
||||
|
||||
size_t clear_peer_list (struct peer_info ** peer_list);
|
||||
|
||||
size_t purge_expired_nodes (struct peer_info **peer_list,
|
||||
SOCKET socket_not_to_close,
|
||||
n2n_tcp_connection_t **tcp_connections,
|
||||
time_t *p_last_purge,
|
||||
int frequency, int timeout);
|
||||
|
||||
/* Edge conf */
|
||||
void edge_init_conf_defaults (n2n_edge_conf_t *conf);
|
||||
int edge_verify_conf (const n2n_edge_conf_t *conf);
|
||||
int edge_conf_add_supernode (n2n_edge_conf_t *conf, const char *ip_and_port);
|
||||
const n2n_edge_conf_t* edge_get_conf (const n2n_edge_t *eee);
|
||||
void edge_term_conf (n2n_edge_conf_t *conf);
|
||||
|
||||
/* Public functions */
|
||||
n2n_edge_t* edge_init (const n2n_edge_conf_t *conf, int *rv);
|
||||
void update_supernode_reg (n2n_edge_t * eee, time_t nowTime);
|
||||
void readFromIPSocket (n2n_edge_t * eee, int in_sock);
|
||||
void edge_term (n2n_edge_t *eee);
|
||||
void edge_set_callbacks (n2n_edge_t *eee, const n2n_edge_callbacks_t *callbacks);
|
||||
void edge_set_userdata (n2n_edge_t *eee, void *user_data);
|
||||
void* edge_get_userdata (n2n_edge_t *eee);
|
||||
void edge_send_packet2net (n2n_edge_t *eee, uint8_t *tap_pkt, size_t len);
|
||||
void edge_read_from_tap (n2n_edge_t *eee);
|
||||
int edge_get_n2n_socket (n2n_edge_t *eee);
|
||||
int edge_get_management_socket (n2n_edge_t *eee);
|
||||
int run_edge_loop (n2n_edge_t *eee);
|
||||
int quick_edge_init (char *device_name, char *community_name,
|
||||
char *encrypt_key, char *device_mac,
|
||||
char *local_ip_address,
|
||||
char *supernode_ip_address_port,
|
||||
int *keep_on_running);
|
||||
int comm_init (struct sn_community *comm, char *cmn);
|
||||
int sn_init_defaults (n2n_sn_t *sss);
|
||||
void sn_init (n2n_sn_t *sss);
|
||||
void sn_term (n2n_sn_t *sss);
|
||||
int supernode2sock (n2n_sock_t * sn, const n2n_sn_name_t addrIn);
|
||||
struct peer_info* add_sn_to_list_by_mac_or_sock (struct peer_info **sn_list, n2n_sock_t *sock, const n2n_mac_t mac, int *skip_add);
|
||||
int run_sn_loop (n2n_sn_t *sss);
|
||||
int assign_one_ip_subnet (n2n_sn_t *sss, struct sn_community *comm);
|
||||
const char* compression_str (uint8_t cmpr);
|
||||
const char* transop_str (enum n2n_transform tr);
|
||||
|
||||
void readFromMgmtSocket (n2n_edge_t *eee);
|
||||
|
||||
void mgmt_event_post (enum n2n_event_topic topic, int data0, void *data1);
|
||||
#endif /* _N2N_H_ */
|
221
include/n2n_define.h
Normal file
221
include/n2n_define.h
Normal file
|
@ -0,0 +1,221 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
/* 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_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
|
||||
#define MSG_TYPE_RE_REGISTER_SUPER 12
|
||||
|
||||
/* Max available space to add supernodes' informations (sockets and MACs) in REGISTER_SUPER_ACK
|
||||
* Field sizes of REGISTER_SUPER_ACK as used in encode/decode fucntions in src/wire.c
|
||||
*/
|
||||
#define REG_SUPER_ACK_PAYLOAD_SPACE (DEFAULT_MTU - (sizeof(n2n_common_t) + sizeof(n2n_REGISTER_SUPER_ACK_t)))
|
||||
|
||||
/* Space needed to store socket and MAC address of a supernode */
|
||||
#define REG_SUPER_ACK_PAYLOAD_ENTRY_SIZE (sizeof(n2n_REGISTER_SUPER_ACK_payload_t))
|
||||
|
||||
#define BOOTSTRAP_TIMEOUT 3
|
||||
#define PURGE_REGISTRATION_FREQUENCY 30
|
||||
#define RE_REG_AND_PURGE_FREQUENCY 10
|
||||
#define REGISTRATION_TIMEOUT 60
|
||||
|
||||
#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. */
|
||||
|
||||
#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 */
|
||||
|
||||
/* 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. */
|
||||
#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 */
|
||||
#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 */
|
||||
|
||||
#define IFACE_UPDATE_INTERVAL (30) /* sec. How long it usually takes to get an IP lease. */
|
||||
#define TRANSOP_TICK_INTERVAL (10) /* sec */
|
||||
|
||||
#define SORT_COMMUNITIES_INTERVAL 90 /* sec. until supernode sorts communities' hash list again */
|
||||
|
||||
#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) */
|
||||
#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 */
|
||||
|
||||
#define ETH_FRAMESIZE 14
|
||||
#define IP4_SRCOFFSET 12
|
||||
#define IP4_DSTOFFSET 16
|
||||
#define IP4_MIN_SIZE 20
|
||||
#define UDP_SIZE 8
|
||||
|
||||
/* parameters for replay protection */
|
||||
#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
|
||||
* set to 0x0000000000000000LL if increasing (or equal) time stamps allowed only */
|
||||
#define TIME_STAMP_ALLOW_JITTER 1 /* constant for allowing or... */
|
||||
#define TIME_STAMP_NO_JITTER 0 /* not allowing jitter to be considered */
|
||||
|
||||
/* 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_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) */
|
||||
|
||||
/* Federation name and indicators */
|
||||
#define FEDERATION_NAME "*Federation"
|
||||
enum federation {IS_NO_FEDERATION = 0,IS_FEDERATION = 1};
|
||||
|
||||
/* (un)purgeable community indicator (supernode) */
|
||||
#define COMMUNITY_UNPURGEABLE 0
|
||||
#define COMMUNITY_PURGEABLE 1
|
||||
|
||||
/* (un)purgeable supernode indicator */
|
||||
enum sn_purge {SN_PURGEABLE = 0, SN_UNPURGEABLE = 1};
|
||||
|
||||
/* Header encryption indicators */
|
||||
#define HEADER_ENCRYPTION_UNKNOWN 0
|
||||
#define HEADER_ENCRYPTION_NONE 1
|
||||
#define HEADER_ENCRYPTION_ENABLED 2
|
||||
|
||||
/* REGISTER_SUPER_ACK packet hash length with user/pw auth, up to 16 bytes */
|
||||
#define N2N_REG_SUP_HASH_CHECK_LEN 16
|
||||
|
||||
#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
|
||||
|
||||
enum n2n_event_topic {
|
||||
N2N_EVENT_DEBUG = 0,
|
||||
N2N_EVENT_TEST = 1,
|
||||
N2N_EVENT_PEER = 2,
|
||||
};
|
||||
|
||||
#define N2N_EVENT_PEER_PURGE 1
|
||||
#define N2N_EVENT_PEER_CLEAR 2
|
||||
#define N2N_EVENT_PEER_DEL_P2P 3
|
||||
#define N2N_EVENT_PEER_ADD_P2P 4
|
||||
|
||||
#define N2N_MGMT_PASSWORD "n2n" /* default password for management port access (so far, json only) */
|
||||
|
||||
|
||||
#define N2N_TCP_BACKLOG_QUEUE_SIZE 3 /* number of concurrently pending connections to be accepted */
|
||||
/* NOT the number of max. TCP connections */
|
||||
|
||||
#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 */
|
||||
|
||||
/* flag used in add_sn_to_list_by_mac_or_sock */
|
||||
enum skip_add {SN_ADD = 0, SN_ADD_SKIP = 1, SN_ADD_ADDED = 2};
|
||||
|
||||
#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 */
|
||||
|
||||
#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 */
|
||||
|
||||
#define N2N_SN_LPORT_DEFAULT 7654
|
||||
#define N2N_SN_PKTBUF_SIZE 2048
|
||||
|
||||
|
||||
/* The way TUNTAP allocated IP. */
|
||||
#define TUNTAP_IP_MODE_SN_ASSIGN 0
|
||||
#define TUNTAP_IP_MODE_STATIC 1
|
||||
#define TUNTAP_IP_MODE_DHCP 2
|
||||
|
||||
/* 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
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
#define SUPERNODE_IP "127.0.0.1"
|
||||
#define SUPERNODE_PORT 1234
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
#define N2N_PKT_VERSION 3
|
||||
#define N2N_DEFAULT_TTL 2 /* can be forwarded twice at most */
|
||||
#define N2N_COMMUNITY_SIZE 20
|
||||
#define N2N_PRIVATE_PUBLIC_KEY_SIZE 32
|
||||
#define N2N_USER_KEY_LINE_STARTER '*'
|
||||
#define N2N_MAC_SIZE 6
|
||||
#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
|
||||
#define N2N_DESC_SIZE 16
|
||||
#define N2N_PKT_BUF_SIZE 2048
|
||||
#define N2N_SOCKBUF_SIZE 64 /* string representation of INET or INET6 sockets */
|
||||
|
||||
#define N2N_MULTICAST_PORT 1968
|
||||
#define N2N_MULTICAST_GROUP "224.0.0.68"
|
||||
|
||||
#ifdef WIN32
|
||||
#define N2N_IFNAMSIZ 64
|
||||
#else
|
||||
#define N2N_IFNAMSIZ 16 /* 15 chars * NULL */
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
#define SN_SELECTION_CRITERION_DATA_TYPE uint64_t
|
||||
#define SN_SELECTION_CRITERION_BUF_SIZE 16
|
||||
|
||||
#define N2N_TRANSFORM_ID_USER_START 64
|
||||
#define N2N_TRANSFORM_ID_MAX 65535
|
||||
|
||||
#ifndef max
|
||||
#define max(a, b) (((a) < (b)) ? (b) : (a))
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) (((a) >(b)) ? (b) : (a))
|
||||
#endif
|
51
include/n2n_port_mapping.h
Normal file
51
include/n2n_port_mapping.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _N2N_PORT_MAPPING_H_
|
||||
#define _N2N_PORT_MAPPING_H_
|
||||
|
||||
#ifdef HAVE_PORT_FORWARDING
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef HAVE_MINIUPNP
|
||||
#ifdef CMAKE_BUILD
|
||||
// CMAKE uses static linked lib as submodule which requires different includes than
|
||||
// the dynamically linked, intalled library in case of plain make
|
||||
#include <miniupnpc.h>
|
||||
#include <upnpcommands.h>
|
||||
#include <upnperrors.h>
|
||||
#else
|
||||
#include <miniupnpc/miniupnpc.h>
|
||||
#include <miniupnpc/upnpcommands.h>
|
||||
#include <miniupnpc/upnperrors.h>
|
||||
#endif // CMAKE_BUILD
|
||||
#endif // HAVE_MINIUPNP
|
||||
|
||||
|
||||
#ifdef HAVE_NATPMP
|
||||
#include "natpmp.h"
|
||||
#endif // HAVE_NATPMP
|
||||
|
||||
|
||||
void n2n_chg_port_mapping (struct n2n_edge *eee, const uint16_t port);
|
||||
|
||||
|
||||
#endif // HAVE_PORT_FORWARDING
|
||||
#endif // _N2N_PORT_MAPPING_H_
|
76
include/n2n_regex.h
Normal file
76
include/n2n_regex.h
Normal file
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
// taken from https://github.com/kokke/tiny-regex-c
|
||||
// under Unlicense as of August 4, 2020
|
||||
|
||||
/*
|
||||
*
|
||||
* Mini regex-module inspired by Rob Pike's regex code described in:
|
||||
*
|
||||
* http://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html
|
||||
*
|
||||
*
|
||||
*
|
||||
* Supports:
|
||||
* ---------
|
||||
* '.' Dot, matches any character
|
||||
* '^' Start anchor, matches beginning of string
|
||||
* '$' End anchor, matches end of string
|
||||
* '*' Asterisk, match zero or more (greedy)
|
||||
* '+' Plus, match one or more (greedy)
|
||||
* '?' Question, match zero or one (non-greedy)
|
||||
* '[abc]' Character class, match if one of {'a', 'b', 'c'}
|
||||
* '[^abc]' Inverted class, match if NOT one of {'a', 'b', 'c'} -- NOTE: feature is currently broken!
|
||||
* '[a-zA-Z]' Character ranges, the character set of the ranges { a-z | A-Z }
|
||||
* '\s' Whitespace, \t \f \r \n \v and spaces
|
||||
* '\S' Non-whitespace
|
||||
* '\w' Alphanumeric, [a-zA-Z0-9_]
|
||||
* '\W' Non-alphanumeric
|
||||
* '\d' Digits, [0-9]
|
||||
* '\D' Non-digits
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _N2N_REGEX_
|
||||
#define _N2N_REGEX_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* Compile regex string pattern to a regex_t-array. */
|
||||
re_t re_compile (const char* pattern);
|
||||
|
||||
|
||||
/* Find matches of the compiled pattern inside text. */
|
||||
int re_matchp (re_t pattern, const char* text, int* matchlenght);
|
||||
|
||||
|
||||
/* Find matches of the txt pattern inside text (will compile automatically first). */
|
||||
int re_match (const char* pattern, const char* text, int* matchlenght);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
868
include/n2n_typedefs.h
Normal file
868
include/n2n_typedefs.h
Normal file
|
@ -0,0 +1,868 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _N2N_TYPEDEFS_H_
|
||||
#define _N2N_TYPEDEFS_H_
|
||||
|
||||
|
||||
typedef uint8_t n2n_community_t[N2N_COMMUNITY_SIZE];
|
||||
typedef uint8_t n2n_private_public_key_t[N2N_PRIVATE_PUBLIC_KEY_SIZE];
|
||||
typedef uint8_t n2n_mac_t[N2N_MAC_SIZE];
|
||||
typedef uint32_t n2n_cookie_t;
|
||||
typedef uint8_t n2n_desc_t[N2N_DESC_SIZE];
|
||||
typedef char n2n_sock_str_t[N2N_SOCKBUF_SIZE]; /* tracing string buffer */
|
||||
|
||||
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
#include "getopt.h"
|
||||
|
||||
/* Other Win environments are expected to support stdint.h */
|
||||
|
||||
/* stdint.h typedefs (C99) (not present in Visual Studio) */
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned char uint8_t;
|
||||
|
||||
/* sys/types.h typedefs (not present in Visual Studio) */
|
||||
typedef unsigned int u_int32_t;
|
||||
typedef unsigned short u_int16_t;
|
||||
typedef unsigned char u_int8_t;
|
||||
|
||||
#ifndef __MINGW32__
|
||||
typedef int ssize_t;
|
||||
#endif
|
||||
|
||||
typedef unsigned long in_addr_t;
|
||||
|
||||
#include "n2n_win32.h"
|
||||
|
||||
#endif /* #if defined(_MSC_VER) || defined(__MINGW32__) */
|
||||
|
||||
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
#include <machine/endian.h>
|
||||
#endif
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
#include <endian.h>
|
||||
#define __BYTE_ORDER BYTE_ORDER
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
#ifndef __LITTLE_ENDIAN__
|
||||
#define __LITTLE_ENDIAN__
|
||||
#endif /* __LITTLE_ENDIAN__ */
|
||||
#else
|
||||
#define __BIG_ENDIAN__
|
||||
#endif/* BYTE_ORDER */
|
||||
#endif/* __OPENBSD__ */
|
||||
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#ifndef __LITTLE_ENDIAN__
|
||||
#define __LITTLE_ENDIAN__
|
||||
#endif
|
||||
#else
|
||||
#ifndef __BIG_ENDIAN__
|
||||
#define __BIG_ENDIAN__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#ifndef __LITTLE_ENDIAN__
|
||||
#define __LITTLE_ENDIAN__ 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !(defined(__LITTLE_ENDIAN__) || defined(__BIG_ENDIAN__))
|
||||
#if defined(__mips__)
|
||||
#undef __LITTLE_ENDIAN__
|
||||
#undef __LITTLE_ENDIAN
|
||||
#define __BIG_ENDIAN__
|
||||
#endif
|
||||
|
||||
/* Everything else */
|
||||
#if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__))
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#define __LITTLE_ENDIAN__
|
||||
#else
|
||||
#define __BIG_ENDIAN__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* *************************************** */
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define PACK_STRUCT __attribute__((__packed__))
|
||||
#else
|
||||
#define PACK_STRUCT
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
#pragma pack(push,1)
|
||||
#endif
|
||||
|
||||
|
||||
// those are definitely not typedefs (with a view to the filename) but neither are they defines
|
||||
static const n2n_mac_t broadcast_mac = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
static const n2n_mac_t multicast_mac = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0x00 }; /* First 3 bytes are meaningful */
|
||||
static const n2n_mac_t ipv6_multicast_mac = { 0x33, 0x33, 0x00, 0x00, 0x00, 0x00 }; /* First 2 bytes are meaningful */
|
||||
static const n2n_mac_t null_mac = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
|
||||
#define ETH_ADDR_LEN 6
|
||||
|
||||
struct ether_hdr {
|
||||
uint8_t dhost[ETH_ADDR_LEN];
|
||||
uint8_t shost[ETH_ADDR_LEN];
|
||||
uint16_t type; /* higher layer protocol encapsulated */
|
||||
} PACK_STRUCT;
|
||||
|
||||
typedef struct ether_hdr ether_hdr_t;
|
||||
|
||||
|
||||
struct n2n_iphdr {
|
||||
#if defined(__LITTLE_ENDIAN__)
|
||||
u_int8_t ihl:4, version:4;
|
||||
#elif defined(__BIG_ENDIAN__)
|
||||
u_int8_t version:4, ihl:4;
|
||||
#else
|
||||
# error "Byte order must be defined"
|
||||
#endif
|
||||
u_int8_t tos;
|
||||
u_int16_t tot_len;
|
||||
u_int16_t id;
|
||||
u_int16_t frag_off;
|
||||
u_int8_t ttl;
|
||||
u_int8_t protocol;
|
||||
u_int16_t check;
|
||||
u_int32_t saddr;
|
||||
u_int32_t daddr;
|
||||
} PACK_STRUCT;
|
||||
|
||||
struct n2n_tcphdr {
|
||||
u_int16_t source;
|
||||
u_int16_t dest;
|
||||
u_int32_t seq;
|
||||
u_int32_t ack_seq;
|
||||
#if defined(__LITTLE_ENDIAN__)
|
||||
u_int16_t res1:4, doff:4, fin:1, syn:1, rst:1, psh:1, ack:1, urg:1, ece:1, cwr:1;
|
||||
#elif defined(__BIG_ENDIAN__)
|
||||
u_int16_t doff:4, res1:4, cwr:1, ece:1, urg:1, ack:1, psh:1, rst:1, syn:1, fin:1;
|
||||
#else
|
||||
# error "Byte order must be defined"
|
||||
#endif
|
||||
u_int16_t window;
|
||||
u_int16_t check;
|
||||
u_int16_t urg_ptr;
|
||||
} PACK_STRUCT;
|
||||
|
||||
struct n2n_udphdr {
|
||||
u_int16_t source;
|
||||
u_int16_t dest;
|
||||
u_int16_t len;
|
||||
u_int16_t check;
|
||||
} PACK_STRUCT;
|
||||
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct port_range {
|
||||
uint16_t start_port; // range contain 'start_port' self
|
||||
uint16_t end_port; // range contain 'end_port' self
|
||||
} port_range_t;
|
||||
|
||||
typedef struct filter_rule_key {
|
||||
in_addr_t src_net_cidr;
|
||||
uint8_t src_net_bit_len;
|
||||
port_range_t src_port_range;
|
||||
in_addr_t dst_net_cidr;
|
||||
uint8_t dst_net_bit_len;
|
||||
port_range_t dst_port_range;
|
||||
uint8_t bool_tcp_configured;
|
||||
uint8_t bool_udp_configured;
|
||||
uint8_t bool_icmp_configured;
|
||||
} filter_rule_key_t;
|
||||
|
||||
typedef struct filter_rule {
|
||||
filter_rule_key_t key;
|
||||
|
||||
uint8_t bool_accept_icmp;
|
||||
uint8_t bool_accept_udp;
|
||||
uint8_t bool_accept_tcp;
|
||||
|
||||
UT_hash_handle hh; /* makes this structure hashable */
|
||||
} filter_rule_t;
|
||||
|
||||
|
||||
#ifndef WIN32
|
||||
typedef struct tuntap_dev {
|
||||
int fd;
|
||||
int if_idx;
|
||||
n2n_mac_t mac_addr;
|
||||
uint32_t ip_addr;
|
||||
uint32_t device_mask;
|
||||
uint16_t mtu;
|
||||
char dev_name[N2N_IFNAMSIZ];
|
||||
} tuntap_dev;
|
||||
|
||||
#define SOCKET int
|
||||
#endif /* #ifndef WIN32 */
|
||||
|
||||
/** 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 */
|
||||
//#define MTU_ASSERT_VALUE 1400
|
||||
|
||||
/** Common type used to hold stringified IP addresses. */
|
||||
typedef char ipstr_t[32];
|
||||
|
||||
/** Common type used to hold stringified MAC addresses. */
|
||||
#define N2N_MACSTR_SIZE 32
|
||||
typedef char macstr_t[N2N_MACSTR_SIZE];
|
||||
typedef char dec_ip_str_t[N2N_NETMASK_STR_SIZE];
|
||||
typedef char dec_ip_bit_str_t[N2N_NETMASK_STR_SIZE + 4];
|
||||
|
||||
typedef struct speck_context_t he_context_t;
|
||||
typedef char n2n_sn_name_t[N2N_EDGE_SN_HOST_SIZE];
|
||||
|
||||
typedef enum n2n_pc {
|
||||
n2n_ping = 0, /* Not used */
|
||||
n2n_register = 1, /* Register edge to edge */
|
||||
n2n_deregister = 2, /* Deregister this edge */
|
||||
n2n_packet = 3, /* PACKET data content */
|
||||
n2n_register_ack = 4, /* ACK of a registration from edge to edge */
|
||||
n2n_register_super = 5, /* Register edge to supernode */
|
||||
n2n_unregister_super = 6, /* Deregister edge from supernode */
|
||||
n2n_register_super_ack = 7, /* ACK from supernode to edge */
|
||||
n2n_register_super_nak = 8, /* NAK from supernode to edge - registration refused */
|
||||
n2n_federation = 9, /* Not used by edge */
|
||||
n2n_peer_info = 10, /* Send info on a peer from sn to edge */
|
||||
n2n_query_peer = 11, /* ask supernode for info on a peer */
|
||||
n2n_re_register_super = 12 /* ask edge to re-register with supernode */
|
||||
} n2n_pc_t;
|
||||
|
||||
#define N2N_FLAGS_OPTIONS 0x0080
|
||||
#define N2N_FLAGS_SOCKET 0x0040
|
||||
#define N2N_FLAGS_FROM_SUPERNODE 0x0020
|
||||
|
||||
/* The bits in flag that are the packet type */
|
||||
#define N2N_FLAGS_TYPE_MASK 0x001f /* 0 - 31 */
|
||||
#define N2N_FLAGS_BITS_MASK 0xffe0
|
||||
|
||||
#define IPV4_SIZE 4
|
||||
#define IPV6_SIZE 16
|
||||
|
||||
|
||||
#define N2N_AUTH_MAX_TOKEN_SIZE 48 /* max token size in bytes */
|
||||
#define N2N_AUTH_CHALLENGE_SIZE 16 /* challenge always is of same size as dynamic key */
|
||||
#define N2N_AUTH_ID_TOKEN_SIZE 16
|
||||
#define N2N_AUTH_PW_TOKEN_SIZE (N2N_PRIVATE_PUBLIC_KEY_SIZE + N2N_AUTH_CHALLENGE_SIZE)
|
||||
|
||||
#define N2N_EUNKNOWN -1
|
||||
#define N2N_ENOTIMPL -2
|
||||
#define N2N_EINVAL -3
|
||||
#define N2N_ENOSPACE -4
|
||||
|
||||
|
||||
#define N2N_VERSION_STRING_SIZE 20
|
||||
typedef char n2n_version_t[N2N_VERSION_STRING_SIZE];
|
||||
|
||||
|
||||
#define SN_SELECTION_STRATEGY_LOAD 1
|
||||
#define SN_SELECTION_STRATEGY_RTT 2
|
||||
#define SN_SELECTION_STRATEGY_MAC 3
|
||||
|
||||
|
||||
typedef struct n2n_ip_subnet {
|
||||
uint32_t net_addr; /* Host order IP address. */
|
||||
uint8_t net_bitlen; /* Subnet prefix. */
|
||||
} n2n_ip_subnet_t;
|
||||
|
||||
typedef struct n2n_sock {
|
||||
uint8_t family; /* AF_INET or AF_INET6; or 0 if invalid */
|
||||
uint16_t port; /* host order */
|
||||
union {
|
||||
uint8_t v6[IPV6_SIZE]; /* byte sequence */
|
||||
uint8_t v4[IPV4_SIZE]; /* byte sequence */
|
||||
} addr;
|
||||
} n2n_sock_t;
|
||||
|
||||
typedef enum {
|
||||
n2n_auth_none = 0,
|
||||
n2n_auth_simple_id = 1,
|
||||
n2n_auth_user_password = 2
|
||||
} n2n_auth_scheme_t;
|
||||
|
||||
typedef enum {
|
||||
update_edge_no_change = 0,
|
||||
update_edge_sock_change = 1,
|
||||
update_edge_new_sn = 2,
|
||||
update_edge_auth_fail = -1
|
||||
} update_edge_ret_value_t;
|
||||
|
||||
typedef struct n2n_auth {
|
||||
uint16_t scheme; /* What kind of auth */
|
||||
uint16_t token_size; /* Size of auth token */
|
||||
uint8_t token[N2N_AUTH_MAX_TOKEN_SIZE]; /* Auth data interpreted based on scheme */
|
||||
} n2n_auth_t;
|
||||
|
||||
typedef struct n2n_common {
|
||||
/* NOTE: wire representation is different! */
|
||||
/* int version; */
|
||||
|
||||
uint8_t ttl;
|
||||
uint8_t pc;
|
||||
uint16_t flags;
|
||||
n2n_community_t community;
|
||||
} n2n_common_t;
|
||||
|
||||
typedef struct n2n_REGISTER {
|
||||
n2n_cookie_t cookie; /**< Link REGISTER and REGISTER_ACK */
|
||||
n2n_mac_t srcMac; /**< MAC of registering party */
|
||||
n2n_mac_t dstMac; /**< MAC of target edge */
|
||||
n2n_sock_t sock; /**< Supernode's view of edge socket OR edge's preferred local socket */
|
||||
n2n_ip_subnet_t dev_addr; /**< IP address of the tuntap adapter. */
|
||||
n2n_desc_t dev_desc; /**< Hint description correlated with the edge */
|
||||
} n2n_REGISTER_t;
|
||||
|
||||
typedef struct n2n_REGISTER_ACK {
|
||||
n2n_cookie_t cookie; /**< Return cookie from REGISTER */
|
||||
n2n_mac_t srcMac; /**< MAC of acknowledging party (supernode or edge) */
|
||||
n2n_mac_t dstMac; /**< Reflected MAC of registering edge from REGISTER */
|
||||
n2n_sock_t sock; /**< Supernode's view of edge socket (IP Addr, port) */
|
||||
} n2n_REGISTER_ACK_t;
|
||||
|
||||
typedef struct n2n_PACKET {
|
||||
n2n_mac_t srcMac;
|
||||
n2n_mac_t dstMac;
|
||||
n2n_sock_t sock;
|
||||
uint8_t transform;
|
||||
uint8_t compression;
|
||||
} n2n_PACKET_t;
|
||||
|
||||
/* Linked with n2n_register_super in n2n_pc_t. Only from edge to supernode. */
|
||||
typedef struct n2n_REGISTER_SUPER {
|
||||
n2n_cookie_t cookie; /**< Link REGISTER_SUPER and REGISTER_SUPER_ACK */
|
||||
n2n_mac_t edgeMac; /**< MAC to register with edge sending socket */
|
||||
n2n_sock_t sock; /**< Sending socket associated with edgeMac */
|
||||
n2n_ip_subnet_t dev_addr; /**< IP address of the tuntap adapter. */
|
||||
n2n_desc_t dev_desc; /**< Hint description correlated with the edge */
|
||||
n2n_auth_t auth; /**< Authentication scheme and tokens */
|
||||
uint32_t key_time; /**< key time for dynamic key, used between federatred supernodes only */
|
||||
} n2n_REGISTER_SUPER_t;
|
||||
|
||||
|
||||
/* Linked with n2n_register_super_ack in n2n_pc_t. Only from supernode to edge. */
|
||||
typedef struct n2n_REGISTER_SUPER_ACK {
|
||||
n2n_cookie_t cookie; /**< Return cookie from REGISTER_SUPER */
|
||||
n2n_mac_t srcMac; /**< MAC of answering supernode */
|
||||
n2n_ip_subnet_t dev_addr; /**< Assign an IP address to the tuntap adapter of edge. */
|
||||
uint16_t lifetime; /**< How long the registration will live */
|
||||
n2n_sock_t sock; /**< Sending sockets associated with edge */
|
||||
n2n_auth_t auth; /**< Authentication scheme and tokens */
|
||||
|
||||
/** The packet format provides additional supernode definitions here.
|
||||
* uint8_t count, then for each count there is one
|
||||
* n2n_sock_t.
|
||||
*/
|
||||
uint8_t num_sn; /**< Number of supernodes that were send
|
||||
* even if we cannot store them all. */
|
||||
|
||||
uint32_t key_time; /**< key time for dynamic key, used between federatred supernodes only */
|
||||
} n2n_REGISTER_SUPER_ACK_t;
|
||||
|
||||
|
||||
/* Linked with n2n_register_super_ack in n2n_pc_t. Only from supernode to edge. */
|
||||
typedef struct n2n_REGISTER_SUPER_NAK {
|
||||
n2n_cookie_t cookie; /* Return cookie from REGISTER_SUPER */
|
||||
n2n_mac_t srcMac;
|
||||
n2n_auth_t auth; /* Authentication scheme and tokens */
|
||||
} n2n_REGISTER_SUPER_NAK_t;
|
||||
|
||||
|
||||
/* REGISTER_SUPER_ACK may contain extra payload (their number given by num_sn)
|
||||
* of following type describing a(nother) supernode */
|
||||
typedef struct n2n_REGISTER_SUPER_ACK_payload {
|
||||
n2n_sock_t sock; /**< socket of supernode */
|
||||
n2n_mac_t mac; /**< MAC of supernode */
|
||||
} n2n_REGISTER_SUPER_ACK_payload_t;
|
||||
|
||||
|
||||
/* Linked with n2n_unregister_super in n2n_pc_t. */
|
||||
typedef struct n2n_UNREGISTER_SUPER {
|
||||
n2n_auth_t auth;
|
||||
n2n_mac_t srcMac;
|
||||
} n2n_UNREGISTER_SUPER_t;
|
||||
|
||||
|
||||
typedef struct n2n_PEER_INFO {
|
||||
uint16_t aflags;
|
||||
n2n_mac_t srcMac;
|
||||
n2n_mac_t mac;
|
||||
n2n_sock_t sock;
|
||||
n2n_sock_t preferred_sock;
|
||||
uint32_t load;
|
||||
n2n_version_t version;
|
||||
time_t uptime;
|
||||
} n2n_PEER_INFO_t;
|
||||
|
||||
|
||||
typedef struct n2n_QUERY_PEER {
|
||||
uint16_t aflags;
|
||||
n2n_mac_t srcMac;
|
||||
n2n_sock_t sock;
|
||||
n2n_mac_t targetMac;
|
||||
|
||||
} n2n_QUERY_PEER_t;
|
||||
|
||||
typedef struct n2n_buf n2n_buf_t;
|
||||
|
||||
struct peer_info {
|
||||
n2n_mac_t mac_addr;
|
||||
n2n_ip_subnet_t dev_addr;
|
||||
n2n_desc_t dev_desc;
|
||||
n2n_sock_t sock;
|
||||
SOCKET socket_fd;
|
||||
n2n_sock_t preferred_sock;
|
||||
n2n_cookie_t last_cookie;
|
||||
n2n_auth_t auth;
|
||||
int timeout;
|
||||
uint8_t purgeable;
|
||||
time_t last_seen;
|
||||
time_t last_p2p;
|
||||
time_t last_sent_query;
|
||||
SN_SELECTION_CRITERION_DATA_TYPE selection_criterion;
|
||||
uint64_t last_valid_time_stamp;
|
||||
char *ip_addr;
|
||||
uint8_t local;
|
||||
time_t uptime;
|
||||
n2n_version_t version;
|
||||
|
||||
UT_hash_handle hh; /* makes this structure hashable */
|
||||
};
|
||||
|
||||
typedef struct peer_info peer_info_t;
|
||||
|
||||
typedef struct n2n_route {
|
||||
in_addr_t net_addr;
|
||||
uint8_t net_bitlen;
|
||||
in_addr_t gateway;
|
||||
} n2n_route_t;
|
||||
|
||||
typedef struct n2n_edge n2n_edge_t;
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
typedef enum {
|
||||
N2N_ACCEPT = 0,
|
||||
N2N_DROP = 1
|
||||
} n2n_verdict;
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
typedef enum {
|
||||
FPP_UNKNOWN = 0,
|
||||
FPP_ARP = 1,
|
||||
FPP_TCP = 2,
|
||||
FPP_UDP = 3,
|
||||
FPP_ICMP = 4,
|
||||
FPP_IGMP = 5
|
||||
} filter_packet_proto;
|
||||
|
||||
|
||||
typedef struct packet_address_proto_info {
|
||||
in_addr_t src_ip;
|
||||
uint16_t src_port;
|
||||
in_addr_t dst_ip;
|
||||
uint16_t dst_port;
|
||||
filter_packet_proto proto;
|
||||
}packet_address_proto_info_t;
|
||||
|
||||
typedef struct filter_rule_pair_cache {
|
||||
packet_address_proto_info_t key;
|
||||
|
||||
uint8_t bool_allow_traffic;
|
||||
uint32_t active_count;
|
||||
|
||||
UT_hash_handle hh; /* makes this structure hashable */
|
||||
} filter_rule_pair_cache_t;
|
||||
|
||||
struct network_traffic_filter;
|
||||
typedef struct network_traffic_filter network_traffic_filter_t;
|
||||
|
||||
struct network_traffic_filter {
|
||||
n2n_verdict (*filter_packet_from_peer)(network_traffic_filter_t* filter, n2n_edge_t *eee,
|
||||
const n2n_sock_t *peer, uint8_t *payload, uint16_t payload_size);
|
||||
|
||||
n2n_verdict (*filter_packet_from_tap)(network_traffic_filter_t* filter, n2n_edge_t *eee, uint8_t *payload, uint16_t payload_size);
|
||||
|
||||
filter_rule_t *rules;
|
||||
|
||||
filter_rule_pair_cache_t *connections_rule_cache;
|
||||
|
||||
uint32_t work_count_scene_last_clear;
|
||||
|
||||
};
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
/* Callbacks allow external programs to attach functions in response to
|
||||
* N2N events. */
|
||||
typedef struct n2n_edge_callbacks {
|
||||
/* The supernode registration has been updated */
|
||||
void (*sn_registration_updated)(n2n_edge_t *eee, time_t now, const n2n_sock_t *sn);
|
||||
|
||||
/* A packet has been received from a peer. N2N_DROP can be returned to
|
||||
* drop the packet. The packet payload can be modified. This only allows
|
||||
* the packet size to be reduced */
|
||||
n2n_verdict (*packet_from_peer)(n2n_edge_t *eee, const n2n_sock_t *peer, uint8_t *payload, uint16_t *payload_size);
|
||||
|
||||
/* A packet has been received from the TAP interface. N2N_DROP can be
|
||||
* returned to drop the packet. The packet payload can be modified.
|
||||
* This only allows the packet size to be reduced */
|
||||
n2n_verdict (*packet_from_tap)(n2n_edge_t *eee, uint8_t *payload, uint16_t *payload_size);
|
||||
|
||||
/* Called whenever the IP address of the TAP interface changes. */
|
||||
void (*ip_address_changed)(n2n_edge_t *eee, uint32_t old_ip, uint32_t new_ip);
|
||||
|
||||
/* Called periodically in the main loop. */
|
||||
void (*main_loop_period)(n2n_edge_t *eee, time_t now);
|
||||
|
||||
/* Called when a new socket to supernode is created. */
|
||||
void (*sock_opened)(n2n_edge_t *eee);
|
||||
} n2n_edge_callbacks_t;
|
||||
|
||||
typedef struct n2n_tuntap_priv_config {
|
||||
char tuntap_dev_name[N2N_IFNAMSIZ];
|
||||
char ip_mode[N2N_IF_MODE_SIZE];
|
||||
dec_ip_str_t ip_addr;
|
||||
dec_ip_str_t netmask;
|
||||
char device_mac[N2N_MACNAMSIZ];
|
||||
int mtu;
|
||||
int metric;
|
||||
uint8_t daemon;
|
||||
#ifndef WIN32
|
||||
uid_t userid;
|
||||
gid_t groupid;
|
||||
#endif
|
||||
} n2n_tuntap_priv_config_t;
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
typedef enum n2n_transform {
|
||||
N2N_TRANSFORM_ID_INVAL = 0,
|
||||
N2N_TRANSFORM_ID_NULL = 1,
|
||||
N2N_TRANSFORM_ID_TWOFISH = 2,
|
||||
N2N_TRANSFORM_ID_AES = 3,
|
||||
N2N_TRANSFORM_ID_CHACHA20 = 4,
|
||||
N2N_TRANSFORM_ID_SPECK = 5,
|
||||
} n2n_transform_t;
|
||||
|
||||
struct n2n_trans_op; /* Circular definition */
|
||||
|
||||
typedef int (*n2n_transdeinit_f)(struct n2n_trans_op * arg);
|
||||
typedef void (*n2n_transtick_f)(struct n2n_trans_op * arg, time_t now);
|
||||
typedef int (*n2n_transform_f)(struct n2n_trans_op * arg,
|
||||
uint8_t * outbuf,
|
||||
size_t out_len,
|
||||
const uint8_t * inbuf,
|
||||
size_t in_len,
|
||||
const n2n_mac_t peer_mac);
|
||||
/** Holds the info associated with a data transform plugin.
|
||||
*
|
||||
* When a packet arrives the transform ID is extracted. This defines the code
|
||||
* to use to decode the packet content. The transform code then decodes the
|
||||
* packet and consults its internal key lookup.
|
||||
*/
|
||||
typedef struct n2n_trans_op {
|
||||
void * priv; /* opaque data. Key schedule goes here. */
|
||||
uint8_t no_encryption; /* 1 if this transop does not perform encryption */
|
||||
n2n_transform_t transform_id;
|
||||
size_t tx_cnt;
|
||||
size_t rx_cnt;
|
||||
|
||||
n2n_transdeinit_f deinit; /* destructor function */
|
||||
n2n_transtick_f tick; /* periodic maintenance */
|
||||
n2n_transform_f fwd; /* encode a payload */
|
||||
n2n_transform_f rev; /* decode a payload */
|
||||
} n2n_trans_op_t;
|
||||
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
|
||||
typedef struct n2n_resolve_ip_sock {
|
||||
char *org_ip; /* pointer to original ip/named address string (used read only) */
|
||||
n2n_sock_t sock; /* resolved socket */
|
||||
n2n_sock_t *org_sock; /* pointer to original socket where 'sock' gets copied to from time to time */
|
||||
int error_code; /* result of last resolution attempt */
|
||||
|
||||
UT_hash_handle hh; /* makes this structure hashable */
|
||||
} n2n_resolve_ip_sock_t;
|
||||
|
||||
|
||||
// structure to hold resolver thread's parameters
|
||||
typedef struct n2n_resolve_parameter {
|
||||
n2n_resolve_ip_sock_t *list; /* pointer to list of to be resolved nodes */
|
||||
uint8_t changed; /* indicates a change */
|
||||
#ifdef HAVE_PTHREAD
|
||||
pthread_t id; /* thread id */
|
||||
pthread_mutex_t access; /* mutex for shared access */
|
||||
#endif
|
||||
uint8_t request; /* flags main thread's need for intermediate resolution */
|
||||
time_t check_interval;/* interval to checik resolover results */
|
||||
time_t last_checked; /* last time the resolver results were cheked */
|
||||
time_t last_resolved; /* last time the resolver completed */
|
||||
} n2n_resolve_parameter_t;
|
||||
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
|
||||
// structure to hold port mapping thread's parameters
|
||||
typedef struct n2n_port_map_parameter {
|
||||
#ifdef HAVE_PTHREAD
|
||||
pthread_t id; /* thread id */
|
||||
pthread_mutex_t access; /* mutex for shared access */
|
||||
#endif
|
||||
uint16_t mgmt_port;
|
||||
uint16_t mapped_port;
|
||||
uint16_t new_port; /* REVISIT: remove with management port subscriptions */
|
||||
} n2n_port_map_parameter_t;
|
||||
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
|
||||
typedef struct n2n_edge_conf {
|
||||
struct peer_info *supernodes; /**< List of supernodes */
|
||||
n2n_route_t *routes; /**< Networks to route through n2n */
|
||||
n2n_community_t community_name; /**< The community. 16 full octets. */
|
||||
n2n_desc_t dev_desc; /**< The device description (hint) */
|
||||
n2n_private_public_key_t *public_key; /**< edge's public key (for user/password based authentication) */
|
||||
n2n_private_public_key_t *shared_secret; /**< shared secret derived from federation public key, username and password */
|
||||
he_context_t *shared_secret_ctx; /**< context holding the roundkeys derived from shared secret */
|
||||
n2n_private_public_key_t *federation_public_key; /**< federation public key provided by command line */
|
||||
uint8_t header_encryption; /**< Header encryption indicator. */
|
||||
he_context_t *header_encryption_ctx_static; /**< Header encryption cipher context. */
|
||||
he_context_t *header_encryption_ctx_dynamic; /**< Header encryption cipher context. */
|
||||
he_context_t *header_iv_ctx_static; /**< Header IV ecnryption cipher context, REMOVE as soon as separate fileds for checksum and replay protection available */
|
||||
he_context_t *header_iv_ctx_dynamic; /**< Header IV ecnryption cipher context, REMOVE as soon as separate fileds for checksum and replay protection available */
|
||||
n2n_transform_t transop_id; /**< The transop to use. */
|
||||
uint8_t compression; /**< Compress outgoing data packets before encryption */
|
||||
uint16_t num_routes; /**< Number of routes in routes */
|
||||
uint8_t tuntap_ip_mode; /**< Interface IP address allocated mode, eg. DHCP. */
|
||||
uint8_t allow_routing; /**< Accept packet no to interface address. */
|
||||
uint8_t drop_multicast; /**< Multicast ethernet addresses. */
|
||||
uint8_t disable_pmtu_discovery; /**< Disable the Path MTU discovery. */
|
||||
uint8_t allow_p2p; /**< Allow P2P connection */
|
||||
uint8_t sn_num; /**< Number of supernode addresses defined. */
|
||||
uint8_t tos; /** TOS for sent packets */
|
||||
char *encrypt_key;
|
||||
int register_interval; /**< Interval for supernode registration, also used for UDP NAT hole punching. */
|
||||
int register_ttl; /**< TTL for registration packet when UDP NAT hole punching through supernode. */
|
||||
in_addr_t bind_address; /**< The address to bind to if provided (-b) */
|
||||
n2n_sock_t preferred_sock; /**< propagated local sock for better p2p in LAN (-e) */
|
||||
uint8_t preferred_sock_auto; /**< indicates desired auto detect for preferred sock */
|
||||
int local_port;
|
||||
int mgmt_port;
|
||||
uint8_t connect_tcp; /** connection to supernode 0 = UDP; 1 = TCP */
|
||||
n2n_auth_t auth;
|
||||
filter_rule_t *network_traffic_filter_rules;
|
||||
int metric; /**< Network interface metric (Windows only). */
|
||||
uint8_t sn_selection_strategy; /**< encodes currently chosen supernode selection strategy. */
|
||||
uint8_t number_max_sn_pings; /**< Number of maximum concurrently allowed supernode pings. */
|
||||
uint64_t mgmt_password_hash; /**< contains hash of managament port password. */
|
||||
uint8_t port_forwarding; /**< indicates if port forwarding UPNP/PMP is enabled */
|
||||
} n2n_edge_conf_t;
|
||||
|
||||
|
||||
struct n2n_edge_stats {
|
||||
uint32_t tx_p2p;
|
||||
uint32_t rx_p2p;
|
||||
uint32_t tx_sup;
|
||||
uint32_t rx_sup;
|
||||
uint32_t tx_sup_broadcast;
|
||||
uint32_t rx_sup_broadcast;
|
||||
};
|
||||
|
||||
struct n2n_edge {
|
||||
n2n_edge_conf_t conf;
|
||||
|
||||
/* Status */
|
||||
int *keep_running; /**< Pointer to edge loop stop/go flag */
|
||||
struct peer_info *curr_sn; /**< Currently active supernode. */
|
||||
uint8_t sn_wait; /**< Whether we are waiting for a supernode response. */
|
||||
uint8_t sn_pong; /**< Whether we have seen a PONG since last time reset. */
|
||||
size_t sup_attempts; /**< Number of remaining attempts to this supernode. */
|
||||
tuntap_dev device; /**< All about the TUNTAP device */
|
||||
n2n_trans_op_t transop; /**< The transop to use when encoding */
|
||||
n2n_trans_op_t transop_lzo; /**< The transop for LZO compression */
|
||||
#ifdef HAVE_ZSTD
|
||||
n2n_trans_op_t transop_zstd; /**< The transop for ZSTD compression */
|
||||
#endif
|
||||
n2n_route_t *sn_route_to_clean; /**< Supernode route to clean */
|
||||
n2n_edge_callbacks_t cb; /**< API callbacks */
|
||||
void *user_data; /**< Can hold user data */
|
||||
SN_SELECTION_CRITERION_DATA_TYPE sn_selection_criterion_common_data;
|
||||
|
||||
/* Sockets */
|
||||
/* supernode socket is in eee->curr_sn->sock (of type n2n_sock_t) */
|
||||
int sock;
|
||||
int close_socket_counter; /**< counter for close-event before re-opening */
|
||||
int udp_mgmt_sock; /**< socket for status info. */
|
||||
|
||||
#ifndef SKIP_MULTICAST_PEERS_DISCOVERY
|
||||
n2n_sock_t multicast_peer; /**< Multicast peer group (for local edges) */
|
||||
int udp_multicast_sock; /**< socket for local multicast registrations. */
|
||||
int multicast_joined; /**< 1 if the group has been joined.*/
|
||||
#endif
|
||||
|
||||
/* Peers */
|
||||
struct peer_info * known_peers; /**< Edges we are connected to. */
|
||||
struct peer_info * pending_peers; /**< Edges we have tried to register with. */
|
||||
|
||||
/* Timers */
|
||||
time_t last_register_req; /**< Check if time to re-register with super*/
|
||||
time_t last_p2p; /**< Last time p2p traffic was received. */
|
||||
time_t last_sup; /**< Last time a packet arrived from supernode. */
|
||||
time_t last_sweep; /**< Last time a sweep was performed. */
|
||||
time_t start_time; /**< For calculating uptime */
|
||||
|
||||
|
||||
struct n2n_edge_stats stats; /**< Statistics */
|
||||
|
||||
n2n_resolve_parameter_t *resolve_parameter; /**< Pointer to name resolver's parameter block */
|
||||
uint8_t resolution_request; /**< Flag an immediate DNS resolution request */
|
||||
|
||||
n2n_port_map_parameter_t *port_map_parameter; /**< Pointer to port mapping thread's parameter block */
|
||||
|
||||
n2n_tuntap_priv_config_t tuntap_priv_conf; /**< Tuntap config */
|
||||
|
||||
network_traffic_filter_t *network_traffic_filter;
|
||||
};
|
||||
|
||||
typedef struct sn_stats {
|
||||
size_t errors; /* Number of errors encountered. */
|
||||
size_t reg_super; /* Number of REGISTER_SUPER requests received. */
|
||||
size_t reg_super_nak; /* Number of REGISTER_SUPER requests declined. */
|
||||
size_t fwd; /* Number of messages forwarded. */
|
||||
size_t broadcast; /* Number of messages broadcast to a community. */
|
||||
time_t last_fwd; /* Time when last message was forwarded. */
|
||||
time_t last_reg_super; /* Time when last REGISTER_SUPER was received. */
|
||||
} sn_stats_t;
|
||||
|
||||
typedef struct node_supernode_association {
|
||||
|
||||
n2n_mac_t mac; /* mac address of an edge */
|
||||
const struct sockaddr_in sock; /* network order socket of that edge's supernode */
|
||||
time_t last_seen; /* time mark to keep track of purging requirements */
|
||||
|
||||
UT_hash_handle hh; /* makes this structure hashable */
|
||||
} node_supernode_association_t;
|
||||
|
||||
typedef struct sn_user {
|
||||
n2n_private_public_key_t public_key;
|
||||
n2n_private_public_key_t shared_secret;
|
||||
he_context_t *shared_secret_ctx;
|
||||
n2n_desc_t name;
|
||||
|
||||
UT_hash_handle hh;
|
||||
} sn_user_t;
|
||||
|
||||
struct sn_community {
|
||||
char community[N2N_COMMUNITY_SIZE];
|
||||
uint8_t is_federation; /* if not-zero, then the current community is the federation of supernodes */
|
||||
uint8_t purgeable; /* indicates purgeable community (fixed-name, predetermined (-c parameter) communties usually are unpurgeable) */
|
||||
uint8_t header_encryption; /* Header encryption indicator. */
|
||||
he_context_t *header_encryption_ctx_static; /* Header encryption cipher context. */
|
||||
he_context_t *header_encryption_ctx_dynamic; /* Header encryption cipher context. */
|
||||
he_context_t *header_iv_ctx_static; /* Header IV encryption cipher context, REMOVE as soon as separate fields for checksum and replay protection available */
|
||||
he_context_t *header_iv_ctx_dynamic; /* Header IV encryption cipher context, REMOVE as soon as separate fields for checksum and replay protection available */
|
||||
uint8_t dynamic_key[N2N_AUTH_CHALLENGE_SIZE]; /* dynamic key */
|
||||
struct peer_info *edges; /* Link list of registered edges. */
|
||||
node_supernode_association_t *assoc; /* list of other edges from this community and their supernodes */
|
||||
sn_user_t *allowed_users; /* list of allowed users */
|
||||
int64_t number_enc_packets; /* Number of encrypted packets handled so far, required for sorting from time to time */
|
||||
n2n_ip_subnet_t auto_ip_net; /* Address range of auto ip address service. */
|
||||
|
||||
UT_hash_handle hh; /* makes this structure hashable */
|
||||
};
|
||||
|
||||
/* Typedef'd pointer to get abstract datatype. */
|
||||
typedef struct regex_t* re_t;
|
||||
|
||||
struct sn_community_regular_expression {
|
||||
re_t rule; /* compiles regular expression */
|
||||
|
||||
UT_hash_handle hh; /* makes this structure hashable */
|
||||
};
|
||||
|
||||
|
||||
typedef struct n2n_tcp_connection {
|
||||
int socket_fd; /* file descriptor for tcp socket */
|
||||
struct sockaddr sock; /* network order socket */
|
||||
|
||||
uint16_t expected; /* number of bytes expected to be read */
|
||||
uint16_t position; /* current position in the buffer */
|
||||
uint8_t buffer[N2N_PKT_BUF_SIZE + sizeof(uint16_t)]; /* buffer for data collected from tcp socket incl. prepended length */
|
||||
uint8_t inactive; /* connection not be handled if set, already closed and to be deleted soon */
|
||||
|
||||
UT_hash_handle hh; /* makes this structure hashable */
|
||||
} n2n_tcp_connection_t;
|
||||
|
||||
|
||||
typedef struct n2n_sn {
|
||||
int *keep_running; /* Pointer to sn loop stop/go flag */
|
||||
time_t start_time; /* Used to measure uptime. */
|
||||
n2n_version_t version; /* version string sent to edges along with PEER_INFO a.k.a. PONG */
|
||||
sn_stats_t stats;
|
||||
int daemon; /* If non-zero then daemonise. */
|
||||
n2n_mac_t mac_addr;
|
||||
uint16_t lport; /* Local UDP port to bind to. */
|
||||
uint16_t mport; /* Management UDP port to bind to. */
|
||||
int sock; /* Main socket for UDP traffic with edges. */
|
||||
int tcp_sock; /* auxiliary socket for optional TCP connections */
|
||||
n2n_tcp_connection_t *tcp_connections;/* list of established TCP connections */
|
||||
int mgmt_sock; /* management socket. */
|
||||
n2n_ip_subnet_t min_auto_ip_net; /* Address range of auto_ip service. */
|
||||
n2n_ip_subnet_t max_auto_ip_net; /* Address range of auto_ip service. */
|
||||
#ifndef WIN32
|
||||
uid_t userid;
|
||||
gid_t groupid;
|
||||
#endif
|
||||
int lock_communities; /* If true, only loaded and matching communities can be used. */
|
||||
char *community_file;
|
||||
struct sn_community *communities;
|
||||
struct sn_community_regular_expression *rules;
|
||||
struct sn_community *federation;
|
||||
n2n_private_public_key_t private_key; /* private federation key derived from federation name */
|
||||
n2n_auth_t auth;
|
||||
uint32_t dynamic_key_time; /* UTC time of last dynamic key generation (second accuracy) */
|
||||
uint8_t override_spoofing_protection; /* set if overriding MAC/IP spoofing protection (cli option '-M') */
|
||||
n2n_resolve_parameter_t *resolve_parameter;/*Pointer to name resolver's parameter block */
|
||||
uint64_t mgmt_password_hash;/* contains hash of managament port password */
|
||||
} n2n_sn_t;
|
||||
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
#endif /* _N2N_TYPEDEFS_H_ */
|
226
include/n2n_wire.h
Normal file
226
include/n2n_wire.h
Normal file
|
@ -0,0 +1,226 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined( N2N_WIRE_H_ )
|
||||
#define N2N_WIRE_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifndef _MSC_VER
|
||||
/* Not included in Visual Studio 2008 */
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if defined(WIN32)
|
||||
#include "n2n_win32.h"
|
||||
#else /* #if defined(WIN32) */
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h> /* AF_INET and AF_INET6 */
|
||||
#endif /* #if defined(WIN32) */
|
||||
|
||||
#include "sn_selection.h"
|
||||
|
||||
|
||||
int encode_uint8 (uint8_t * base,
|
||||
size_t * idx,
|
||||
const uint8_t v);
|
||||
|
||||
int decode_uint8 (uint8_t * out,
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_uint16 (uint8_t * base,
|
||||
size_t * idx,
|
||||
const uint16_t v);
|
||||
|
||||
int decode_uint16 (uint16_t * out,
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_uint32 (uint8_t * base,
|
||||
size_t * idx,
|
||||
const uint32_t v);
|
||||
|
||||
int decode_uint32 (uint32_t * out,
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_uint64 (uint8_t * base,
|
||||
size_t * idx,
|
||||
const uint64_t v);
|
||||
|
||||
int decode_uint64 (uint64_t * out,
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_buf (uint8_t * base,
|
||||
size_t * idx,
|
||||
const void * p,
|
||||
size_t s);
|
||||
|
||||
int decode_buf (uint8_t * out,
|
||||
size_t bufsize,
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_mac (uint8_t * base,
|
||||
size_t * idx,
|
||||
const n2n_mac_t m);
|
||||
|
||||
int decode_mac (n2n_mac_t out,
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_cookie (uint8_t * base,
|
||||
size_t * idx,
|
||||
const n2n_cookie_t c);
|
||||
|
||||
int decode_cookie (n2n_cookie_t * out,
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_common (uint8_t * base,
|
||||
size_t * idx,
|
||||
const n2n_common_t * common);
|
||||
|
||||
int decode_common (n2n_common_t * out,
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_sock (uint8_t * base,
|
||||
size_t * idx,
|
||||
const n2n_sock_t * sock);
|
||||
|
||||
int decode_sock (n2n_sock_t * sock,
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_REGISTER (uint8_t * base,
|
||||
size_t * idx,
|
||||
const n2n_common_t * common,
|
||||
const n2n_REGISTER_t * reg);
|
||||
|
||||
int decode_REGISTER (n2n_REGISTER_t * pkt,
|
||||
const n2n_common_t * cmn, /* info on how to interpret it */
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_REGISTER_SUPER (uint8_t * base,
|
||||
size_t * idx,
|
||||
const n2n_common_t * common,
|
||||
const n2n_REGISTER_SUPER_t * reg);
|
||||
|
||||
int decode_REGISTER_SUPER (n2n_REGISTER_SUPER_t * pkt,
|
||||
const n2n_common_t * cmn, /* info on how to interpret it */
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_UNREGISTER_SUPER (uint8_t *base,
|
||||
size_t *idx,
|
||||
const n2n_common_t *common,
|
||||
const n2n_UNREGISTER_SUPER_t *unreg);
|
||||
|
||||
int decode_UNREGISTER_SUPER (n2n_UNREGISTER_SUPER_t *unreg,
|
||||
const n2n_common_t *cmn, /* info on how to interpret it */
|
||||
const uint8_t *base,
|
||||
size_t *rem,
|
||||
size_t *idx);
|
||||
|
||||
int encode_REGISTER_ACK (uint8_t * base,
|
||||
size_t * idx,
|
||||
const n2n_common_t * common,
|
||||
const n2n_REGISTER_ACK_t * reg);
|
||||
|
||||
int decode_REGISTER_ACK (n2n_REGISTER_ACK_t * pkt,
|
||||
const n2n_common_t * cmn, /* info on how to interpret it */
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_REGISTER_SUPER_ACK (uint8_t * base,
|
||||
size_t * idx,
|
||||
const n2n_common_t * cmn,
|
||||
const n2n_REGISTER_SUPER_ACK_t * reg,
|
||||
uint8_t * tmpbuf);
|
||||
|
||||
int decode_REGISTER_SUPER_ACK (n2n_REGISTER_SUPER_ACK_t * reg,
|
||||
const n2n_common_t * cmn, /* info on how to interpret it */
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx,
|
||||
uint8_t * tmpbuf);
|
||||
|
||||
int encode_REGISTER_SUPER_NAK (uint8_t * base,
|
||||
size_t * idx,
|
||||
const n2n_common_t * cmn,
|
||||
const n2n_REGISTER_SUPER_NAK_t * nak);
|
||||
|
||||
int decode_REGISTER_SUPER_NAK (n2n_REGISTER_SUPER_NAK_t * nak,
|
||||
const n2n_common_t * cmn, /* info on how to interpret it */
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int fill_sockaddr (struct sockaddr * addr,
|
||||
size_t addrlen,
|
||||
const n2n_sock_t * sock);
|
||||
|
||||
int encode_PACKET (uint8_t * base,
|
||||
size_t * idx,
|
||||
const n2n_common_t * common,
|
||||
const n2n_PACKET_t * pkt);
|
||||
|
||||
int decode_PACKET (n2n_PACKET_t * pkt,
|
||||
const n2n_common_t * cmn, /* info on how to interpret it */
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_PEER_INFO (uint8_t * base,
|
||||
size_t * idx,
|
||||
const n2n_common_t * common,
|
||||
const n2n_PEER_INFO_t * pkt);
|
||||
|
||||
int decode_PEER_INFO (n2n_PEER_INFO_t * pkt,
|
||||
const n2n_common_t * cmn, /* info on how to interpret it */
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
int encode_QUERY_PEER (uint8_t * base,
|
||||
size_t * idx,
|
||||
const n2n_common_t * common,
|
||||
const n2n_QUERY_PEER_t * pkt);
|
||||
|
||||
int decode_QUERY_PEER (n2n_QUERY_PEER_t * pkt,
|
||||
const n2n_common_t * cmn, /* info on how to interpret it */
|
||||
const uint8_t * base,
|
||||
size_t * rem,
|
||||
size_t * idx);
|
||||
|
||||
#endif /* #if !defined( N2N_WIRE_H_ ) */
|
37
include/network_traffic_filter.h
Normal file
37
include/network_traffic_filter.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
//
|
||||
// Zhou Bin <joshuafc@foxmail.com>
|
||||
//
|
||||
|
||||
#ifndef N2N_NETWORK_TRAFFIC_FILTER_H
|
||||
#define N2N_NETWORK_TRAFFIC_FILTER_H
|
||||
|
||||
#include "n2n_typedefs.h"
|
||||
|
||||
network_traffic_filter_t* create_network_traffic_filter ();
|
||||
|
||||
void destroy_network_traffic_filter (network_traffic_filter_t* filter);
|
||||
|
||||
void network_traffic_filter_add_rule (network_traffic_filter_t* filter, filter_rule_t* rules);
|
||||
|
||||
//rule_str format: src_ip/len:[b_port,e_port],dst_ip/len:[s_port,e_port],TCP+/-,UDP+/-,ICMP+/-
|
||||
uint8_t process_traffic_filter_rule_str (const char* rule_str, filter_rule_t* rule_struct);
|
||||
|
||||
#endif //N2N_NETWORK_TRAFFIC_FILTER_H
|
36
include/pearson.h
Normal file
36
include/pearson.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "portable_endian.h"
|
||||
|
||||
|
||||
void pearson_hash_256 (uint8_t *out, const uint8_t *in, size_t len);
|
||||
|
||||
void pearson_hash_128 (uint8_t *out, const uint8_t *in, size_t len);
|
||||
|
||||
uint64_t pearson_hash_64 (const uint8_t *in, size_t len);
|
||||
|
||||
uint32_t pearson_hash_32 (const uint8_t *in, size_t len);
|
||||
|
||||
uint16_t pearson_hash_16 (const uint8_t *in, size_t len);
|
||||
|
||||
void pearson_hash_init ();
|
245
include/portable_endian.h
Normal file
245
include/portable_endian.h
Normal file
|
@ -0,0 +1,245 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// taken from
|
||||
// https://raw.githubusercontent.com/pyca/bcrypt/master/src/_csrc/portable_endian.h
|
||||
// as of June 11, 2020
|
||||
|
||||
// "License": Public Domain
|
||||
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
|
||||
// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
|
||||
// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
|
||||
// an example on how to get the endian conversion functions on different platforms.
|
||||
|
||||
#ifndef PORTABLE_ENDIAN_H__
|
||||
#define PORTABLE_ENDIAN_H__
|
||||
|
||||
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
|
||||
|
||||
# define __WINDOWS__
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) || defined(__CYGWIN__)
|
||||
/* Define necessary macros for the header to expose all fields. */
|
||||
# if !defined(_BSD_SOURCE)
|
||||
# define _BSD_SOURCE
|
||||
# endif
|
||||
# if !defined(__USE_BSD)
|
||||
# define __USE_BSD
|
||||
# endif
|
||||
# if !defined(_DEFAULT_SOURCE)
|
||||
# define _DEFAULT_SOURCE
|
||||
# endif
|
||||
# include <endian.h>
|
||||
# include <features.h>
|
||||
/* See http://linux.die.net/man/3/endian */
|
||||
# if defined(htobe16) && defined(htole16) && defined(be16toh) && defined(le16toh) && defined(htobe32) && defined(htole32) && defined(be32toh) && defined(htole32) && defined(htobe64) && defined(htole64) && defined(htobe64) && defined(be64toh) && defined(htole64) && defined(le64toh)
|
||||
/* Do nothing. The macros we need already exist. */
|
||||
# elif !defined(__GLIBC__) || !defined(__GLIBC_MINOR__) || ((__GLIBC__ < 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 9)))
|
||||
# include <arpa/inet.h>
|
||||
# if defined(__BYTE_ORDER) && (__BYTE_ORDER == __LITTLE_ENDIAN)
|
||||
# define htobe16(x) htons(x)
|
||||
# define htole16(x) (x)
|
||||
# define be16toh(x) ntohs(x)
|
||||
# define le16toh(x) (x)
|
||||
|
||||
# define htobe32(x) htonl(x)
|
||||
# define htole32(x) (x)
|
||||
# define be32toh(x) ntohl(x)
|
||||
# define le32toh(x) (x)
|
||||
|
||||
# define htobe64(x) (((uint64_t)htonl(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)htonl(((uint32_t)(x)))) << 32))
|
||||
# define htole64(x) (x)
|
||||
# define be64toh(x) (((uint64_t)ntohl(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)ntohl(((uint32_t)(x)))) << 32))
|
||||
# define le64toh(x) (x)
|
||||
# elif defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN)
|
||||
# define htobe16(x) (x)
|
||||
# define htole16(x) (((((uint16_t)(x)) >> 8))|((((uint16_t)(x)) << 8)))
|
||||
# define be16toh(x) (x)
|
||||
# define le16toh(x) (((((uint16_t)(x)) >> 8))|((((uint16_t)(x)) << 8)))
|
||||
|
||||
# define htobe32(x) (x)
|
||||
# define htole32(x) (((uint32_t)htole16(((uint16_t)(((uint32_t)(x)) >> 16)))) | (((uint32_t)htole16(((uint16_t)(x)))) << 16))
|
||||
# define be32toh(x) (x)
|
||||
# define le32toh(x) (((uint32_t)le16toh(((uint16_t)(((uint32_t)(x)) >> 16)))) | (((uint32_t)le16toh(((uint16_t)(x)))) << 16))
|
||||
|
||||
# define htobe64(x) (x)
|
||||
# define htole64(x) (((uint64_t)htole32(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)htole32(((uint32_t)(x)))) << 32))
|
||||
# define be64toh(x) (x)
|
||||
# define le64toh(x) (((uint64_t)le32toh(((uint32_t)(((uint64_t)(x)) >> 32)))) | (((uint64_t)le32toh(((uint32_t)(x)))) << 32))
|
||||
# else
|
||||
# error Byte Order not supported or not defined.
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
# include <libkern/OSByteOrder.h>
|
||||
|
||||
# define htobe16(x) OSSwapHostToBigInt16(x)
|
||||
# define htole16(x) OSSwapHostToLittleInt16(x)
|
||||
# define be16toh(x) OSSwapBigToHostInt16(x)
|
||||
# define le16toh(x) OSSwapLittleToHostInt16(x)
|
||||
|
||||
# define htobe32(x) OSSwapHostToBigInt32(x)
|
||||
# define htole32(x) OSSwapHostToLittleInt32(x)
|
||||
# define be32toh(x) OSSwapBigToHostInt32(x)
|
||||
# define le32toh(x) OSSwapLittleToHostInt32(x)
|
||||
|
||||
# define htobe64(x) OSSwapHostToBigInt64(x)
|
||||
# define htole64(x) OSSwapHostToLittleInt64(x)
|
||||
# define be64toh(x) OSSwapBigToHostInt64(x)
|
||||
# define le64toh(x) OSSwapLittleToHostInt64(x)
|
||||
|
||||
# define __BYTE_ORDER BYTE_ORDER
|
||||
# define __BIG_ENDIAN BIG_ENDIAN
|
||||
# define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
# define __PDP_ENDIAN PDP_ENDIAN
|
||||
|
||||
#elif defined(__OpenBSD__)
|
||||
|
||||
# include <sys/endian.h>
|
||||
|
||||
#elif defined(__HAIKU__)
|
||||
|
||||
# include <endian.h>
|
||||
|
||||
#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
|
||||
# include <sys/endian.h>
|
||||
|
||||
# if !defined(be16toh)
|
||||
# define be16toh(x) betoh16(x)
|
||||
# define le16toh(x) letoh16(x)
|
||||
# endif
|
||||
|
||||
# if !defined(be32toh)
|
||||
# define be32toh(x) betoh32(x)
|
||||
# define le32toh(x) letoh32(x)
|
||||
# endif
|
||||
|
||||
# if !defined(be64toh)
|
||||
# define be64toh(x) betoh64(x)
|
||||
# define le64toh(x) letoh64(x)
|
||||
# endif
|
||||
|
||||
#elif defined(__WINDOWS__)
|
||||
|
||||
# if BYTE_ORDER == LITTLE_ENDIAN
|
||||
|
||||
# define htobe16(x) _byteswap_ushort(x)
|
||||
# define htole16(x) (x)
|
||||
# define be16toh(x) _byteswap_ushort(x)
|
||||
# define le16toh(x) (x)
|
||||
|
||||
# define htobe32(x) _byteswap_ulong(x)
|
||||
# define htole32(x) (x)
|
||||
# define be32toh(x) _byteswap_ulong(x)
|
||||
# define le32toh(x) (x)
|
||||
|
||||
# define htobe64(x) (((uint64_t)htobe32(((uint32_t)(((uint64_t)(x)) >> 32))) & 0x00000000FFFFFFFFULL) | (((uint64_t)htobe32(((uint32_t)(x)))) << 32))
|
||||
# define be64toh(x) (((uint64_t)be32toh(((uint32_t)(((uint64_t)(x)) >> 32))) & 0x00000000FFFFFFFFULL) | (((uint64_t)be32toh(((uint32_t)(x)))) << 32))
|
||||
# define htole64(x) (x)
|
||||
# define le64toh(x) (x)
|
||||
|
||||
# elif BYTE_ORDER == BIG_ENDIAN
|
||||
|
||||
/* that would be xbox 360 */
|
||||
# define htobe16(x) (x)
|
||||
# define htole16(x) __builtin_bswap16(x)
|
||||
# define be16toh(x) (x)
|
||||
# define le16toh(x) __builtin_bswap16(x)
|
||||
|
||||
# define htobe32(x) (x)
|
||||
# define htole32(x) __builtin_bswap32(x)
|
||||
# define be32toh(x) (x)
|
||||
# define le32toh(x) __builtin_bswap32(x)
|
||||
|
||||
# define htobe64(x) (x)
|
||||
# define htole64(x) __builtin_bswap64(x)
|
||||
# define be64toh(x) (x)
|
||||
# define le64toh(x) __builtin_bswap64(x)
|
||||
|
||||
# else
|
||||
|
||||
# error byte order not supported
|
||||
|
||||
# endif
|
||||
|
||||
# define __BYTE_ORDER BYTE_ORDER
|
||||
# define __BIG_ENDIAN BIG_ENDIAN
|
||||
# define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
# define __PDP_ENDIAN PDP_ENDIAN
|
||||
|
||||
#elif defined(__sun)
|
||||
|
||||
# include <sys/byteorder.h>
|
||||
|
||||
# define htobe16(x) BE_16(x)
|
||||
# define htole16(x) LE_16(x)
|
||||
# define be16toh(x) BE_16(x)
|
||||
# define le16toh(x) LE_16(x)
|
||||
|
||||
# define htobe32(x) BE_32(x)
|
||||
# define htole32(x) LE_32(x)
|
||||
# define be32toh(x) BE_32(x)
|
||||
# define le32toh(x) LE_32(x)
|
||||
|
||||
# define htobe64(x) BE_64(x)
|
||||
# define htole64(x) LE_64(x)
|
||||
# define be64toh(x) BE_64(x)
|
||||
# define le64toh(x) LE_64(x)
|
||||
|
||||
#elif defined _AIX /* AIX is always big endian */
|
||||
# define be64toh(x) (x)
|
||||
# define be32toh(x) (x)
|
||||
# define be16toh(x) (x)
|
||||
# define le32toh(x) \
|
||||
((((x) & 0xff) << 24) | \
|
||||
(((x) & 0xff00) << 8) | \
|
||||
(((x) & 0xff0000) >> 8) | \
|
||||
(((x) & 0xff000000) >> 24))
|
||||
# define le64toh(x) \
|
||||
((((x) & 0x00000000000000ffL) << 56) | \
|
||||
(((x) & 0x000000000000ff00L) << 40) | \
|
||||
(((x) & 0x0000000000ff0000L) << 24) | \
|
||||
(((x) & 0x00000000ff000000L) << 8) | \
|
||||
(((x) & 0x000000ff00000000L) >> 8) | \
|
||||
(((x) & 0x0000ff0000000000L) >> 24) | \
|
||||
(((x) & 0x00ff000000000000L) >> 40) | \
|
||||
(((x) & 0xff00000000000000L) >> 56))
|
||||
# ifndef htobe64
|
||||
# define htobe64(x) be64toh(x)
|
||||
# endif
|
||||
# ifndef htobe32
|
||||
# define htobe32(x) be32toh(x)
|
||||
# endif
|
||||
# ifndef htobe16
|
||||
# define htobe16(x) be16toh(x)
|
||||
# endif
|
||||
|
||||
|
||||
#else
|
||||
|
||||
# error platform not supported
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
69
include/random_numbers.h
Normal file
69
include/random_numbers.h
Normal file
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef RND_H
|
||||
#define RND_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <time.h> /* time, clock */
|
||||
|
||||
#include "n2n.h" /* traceEvent */
|
||||
|
||||
|
||||
// syscall and inquiring random number from hardware generators might fail, so we will retry
|
||||
#define RND_RETRIES 1000
|
||||
|
||||
#if defined (__linux__)
|
||||
#include <sys/syscall.h> /* syscall, SYS_getrandom */
|
||||
#ifdef SYS_getrandom
|
||||
#define GRND_NONBLOCK 1
|
||||
#include <errno.h> /* errno, EAGAIN */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined (__RDRND__) || defined (__RDSEED__)
|
||||
#include <immintrin.h> /* _rdrand64_step, rdseed4_step */
|
||||
#endif
|
||||
|
||||
#if defined (WIN32)
|
||||
#include <wincrypt.h> // HCTYPTPROV, Crypt*-functions
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct rn_generator_state_t {
|
||||
uint64_t a, b;
|
||||
} rn_generator_state_t;
|
||||
|
||||
typedef struct splitmix64_state_t {
|
||||
uint64_t s;
|
||||
} splitmix64_state_t;
|
||||
|
||||
|
||||
int n2n_srand (uint64_t seed);
|
||||
|
||||
uint64_t n2n_rand (void);
|
||||
|
||||
uint64_t n2n_seed (void);
|
||||
|
||||
uint32_t n2n_rand_sqr (uint32_t max_n);
|
||||
|
||||
|
||||
#endif // RND_H
|
46
include/sn_selection.h
Normal file
46
include/sn_selection.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SN_SELECTION_
|
||||
#define _SN_SELECTION_
|
||||
|
||||
typedef char selection_criterion_str_t[SN_SELECTION_CRITERION_BUF_SIZE];
|
||||
|
||||
#include "n2n.h"
|
||||
|
||||
/* selection criterion's functions */
|
||||
int sn_selection_criterion_init (peer_info_t *peer);
|
||||
int sn_selection_criterion_default (SN_SELECTION_CRITERION_DATA_TYPE *selection_criterion);
|
||||
int sn_selection_criterion_bad (SN_SELECTION_CRITERION_DATA_TYPE *selection_criterion);
|
||||
int sn_selection_criterion_good (SN_SELECTION_CRITERION_DATA_TYPE *selection_criterion);
|
||||
int sn_selection_criterion_calculate (n2n_edge_t *eee, peer_info_t *peer, SN_SELECTION_CRITERION_DATA_TYPE *data);
|
||||
|
||||
/* common data's functions */
|
||||
int sn_selection_criterion_common_data_default (n2n_edge_t *eee);
|
||||
|
||||
/* sorting function */
|
||||
int sn_selection_sort (peer_info_t **peer_list);
|
||||
|
||||
/* gathering data function */
|
||||
SN_SELECTION_CRITERION_DATA_TYPE sn_selection_criterion_gather_data (n2n_sn_t *sss);
|
||||
|
||||
/* management port output function */
|
||||
extern char * sn_selection_criterion_str (n2n_edge_t *eee, selection_criterion_str_t out, peer_info_t *peer);
|
||||
|
||||
|
||||
#endif /* _SN_SELECTION_ */
|
142
include/speck.h
Normal file
142
include/speck.h
Normal file
|
@ -0,0 +1,142 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// cipher SPECK -- 128 bit block size -- 128 and 256 bit key size -- CTR mode
|
||||
// taken from (and modified: removed pure crypto-stream generation and seperated key expansion)
|
||||
// https://github.com/nsacyber/simon-speck-supercop/blob/master/crypto_stream/speck128256ctr/
|
||||
|
||||
|
||||
#ifndef SPECK_H
|
||||
#define SPECK_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "portable_endian.h"
|
||||
|
||||
|
||||
#define u32 uint32_t
|
||||
#define u64 uint64_t
|
||||
|
||||
#define N2N_SPECK_IVEC_SIZE 16
|
||||
#define SPECK_KEY_BYTES (256/8)
|
||||
|
||||
|
||||
#if defined (__AVX512F__) // AVX512 support -----------------------------------------------------------------------
|
||||
|
||||
|
||||
#include <immintrin.h>
|
||||
#include <string.h> /* memcpy() */
|
||||
|
||||
#define u512 __m512i
|
||||
|
||||
#define SPECK_ALIGNED_CTX 64
|
||||
|
||||
typedef struct {
|
||||
u512 rk[34];
|
||||
u64 key[34];
|
||||
u32 keysize;
|
||||
} speck_context_t;
|
||||
|
||||
|
||||
#elif defined (__AVX2__) // AVX2 support --------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include <immintrin.h>
|
||||
|
||||
#define u256 __m256i
|
||||
|
||||
#define SPECK_ALIGNED_CTX 32
|
||||
|
||||
typedef struct {
|
||||
u256 rk[34];
|
||||
u64 key[34];
|
||||
u32 keysize;
|
||||
} speck_context_t;
|
||||
|
||||
|
||||
#elif defined (__SSE2__) // SSE support ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include <immintrin.h>
|
||||
|
||||
#define u128 __m128i
|
||||
|
||||
#define SPECK_ALIGNED_CTX 16
|
||||
#define SPECK_CTX_BYVAL 1
|
||||
|
||||
typedef struct {
|
||||
u128 rk[34];
|
||||
u64 key[34];
|
||||
u32 keysize;
|
||||
} speck_context_t;
|
||||
|
||||
|
||||
#elif defined (__ARM_NEON) && defined (SPECK_ARM_NEON) // NEON support ---------------------------------------
|
||||
|
||||
|
||||
#include <arm_neon.h>
|
||||
|
||||
#define u128 uint64x2_t
|
||||
|
||||
typedef struct {
|
||||
u128 rk[34];
|
||||
u64 key[34];
|
||||
u32 keysize;
|
||||
} speck_context_t;
|
||||
|
||||
|
||||
#else // plain C --------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
typedef struct {
|
||||
u64 key[34];
|
||||
u32 keysize;
|
||||
} speck_context_t;
|
||||
|
||||
|
||||
#endif // ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int speck_ctr (unsigned char *out, const unsigned char *in, unsigned long long inlen,
|
||||
const unsigned char *n,
|
||||
speck_context_t *ctx);
|
||||
|
||||
int speck_init (speck_context_t **ctx, const unsigned char *k, int keysize);
|
||||
|
||||
int speck_deinit (speck_context_t *ctx);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// cipher SPECK -- 128 bit block size -- 128 bit key size -- ECB mode
|
||||
// follows endianess rules as used in official implementation guide and NOT as in original 2013 cipher presentation
|
||||
// used for IV in header encryption (one block) and challenge encryption (user/password)
|
||||
// for now: just plain C -- probably no need for AVX, SSE, NEON
|
||||
|
||||
|
||||
int speck_128_decrypt (unsigned char *inout, speck_context_t *ctx);
|
||||
|
||||
int speck_128_encrypt (unsigned char *inout, speck_context_t *ctx);
|
||||
|
||||
|
||||
#endif // SPECK_H
|
87
include/tf.h
Normal file
87
include/tf.h
Normal file
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* (C) 2007-22 - ntop.org and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// taken (and modified) from github/fudanchii/twofish as of August 2020
|
||||
// which itself is a modified copy of Andrew T. Csillag's implementation
|
||||
// published on github/drewcsillag/twofish
|
||||
|
||||
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Andrew T. Csillag
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef TF_H
|
||||
#define TF_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "portable_endian.h"
|
||||
|
||||
|
||||
#define TF_BLOCK_SIZE 16
|
||||
#define TF_IV_SIZE (TF_BLOCK_SIZE)
|
||||
|
||||
|
||||
typedef struct tf_context_t {
|
||||
int N;
|
||||
uint32_t K[40];
|
||||
uint32_t QF[4][256];
|
||||
} tf_context_t;
|
||||
|
||||
|
||||
int tf_ecb_decrypt (unsigned char *out, const unsigned char *in, tf_context_t *ctx);
|
||||
|
||||
int tf_ecb_encrypt (unsigned char *out, const unsigned char *in, tf_context_t *ctx);
|
||||
|
||||
int tf_cbc_encrypt (unsigned char *out, const unsigned char *in, size_t in_len,
|
||||
const unsigned char *iv, tf_context_t *ctx);
|
||||
|
||||
int tf_cbc_decrypt (unsigned char *out, const unsigned char *in, size_t in_len,
|
||||
const unsigned char *iv, tf_context_t *ctx);
|
||||
|
||||
int tf_init (const unsigned char *key, size_t key_size, tf_context_t **ctx);
|
||||
|
||||
int tf_deinit (tf_context_t *ctx);
|
||||
|
||||
|
||||
#endif // TF_H
|
1249
include/uthash.h
Normal file
1249
include/uthash.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue