mirror of
https://github.com/ntop/n2n.git
synced 2024-09-19 16:41:11 +02:00
Code reorganization
This commit is contained in:
parent
26f4e58cd2
commit
3eb82b2a32
26
Makefile.in
26
Makefile.in
|
@ -5,10 +5,7 @@ GIT_COMMITS=@GIT_COMMITS@
|
|||
|
||||
########
|
||||
|
||||
CC?=gcc
|
||||
DEBUG?=-g3
|
||||
OPTIMIZATION?=-O3 #-march=native
|
||||
WARN?=-Wall
|
||||
CC=@CC@
|
||||
|
||||
#Ultrasparc64 users experiencing SIGBUS should try the following gcc options
|
||||
#(thanks to Robert Gibbon)
|
||||
|
@ -16,7 +13,7 @@ PLATOPTS_SPARC64=-mcpu=ultrasparc -pipe -fomit-frame-pointer -ffast-math -finlin
|
|||
|
||||
N2N_OBJS_OPT=
|
||||
LIBS_EDGE_OPT=@N2N_LIBS@
|
||||
CFLAGS=@CFLAGS@
|
||||
CFLAGS=@CFLAGS@ -I ./include
|
||||
LDFLAGS=@LDFLAGS@
|
||||
|
||||
OPENSSL_CFLAGS=$(shell pkg-config openssl; echo $$?)
|
||||
|
@ -48,12 +45,9 @@ MAN7DIR=$(MANDIR)/man7
|
|||
MAN8DIR=$(MANDIR)/man8
|
||||
|
||||
N2N_LIB=libn2n.a
|
||||
N2N_OBJS=n2n.o wire.o minilzo.o twofish.o speck.o \
|
||||
edge_utils.o sn_utils.o \
|
||||
transform_null.o transform_tf.o transform_aes.o transform_cc20.o transform_speck.o \
|
||||
header_encryption.o pearson.o \
|
||||
tuntap_freebsd.o tuntap_netbsd.o tuntap_linux.o random_numbers.o \
|
||||
tuntap_osx.o
|
||||
N2N_OBJS=$(patsubst src/%.c, src/%.o, $(wildcard src/*.c))
|
||||
N2N_DEPS=$(wildcard include/*.h) $(wildcard src/*.c) Makefile
|
||||
|
||||
LIBS_EDGE+=$(LIBS_EDGE_OPT)
|
||||
LIBS_SN=
|
||||
|
||||
|
@ -77,19 +71,19 @@ all: $(APPS) $(DOCS) tools
|
|||
tools: $(N2N_LIB)
|
||||
$(MAKE) -C $@
|
||||
|
||||
edge: edge.c $(N2N_LIB) n2n_wire.h n2n.h Makefile
|
||||
edge: src/edge.c $(N2N_LIB) $(N2N_DEPS)
|
||||
$(CC) $(CFLAGS) $< $(LDFLAGS) $(N2N_LIB) $(LIBS_EDGE) -o $@
|
||||
|
||||
supernode: sn.c $(N2N_LIB) n2n.h Makefile
|
||||
supernode: src/sn.c $(N2N_LIB) $(N2N_DEPS)
|
||||
$(CC) $(CFLAGS) $< $(LDFLAGS) $(N2N_LIB) $(LIBS_SN) -o $@
|
||||
|
||||
example_edge_embed_quick_edge_init: example_edge_embed_quick_edge_init.c $(N2N_LIB) n2n.h
|
||||
example_edge_embed_quick_edge_init: src/example_edge_embed_quick_edge_init.c $(N2N_DEPS)
|
||||
$(CC) $(CFLAGS) $< $(LDFLAGS) $(N2N_LIB) $(LIBS_EDGE) -o $@
|
||||
|
||||
example_sn_embed: example_sn_embed.c $(N2N_LIB) n2n.h
|
||||
example_sn_embed: src/example_sn_embed.c $(N2N_DEPS)
|
||||
$(CC) $(CFLAGS) $< $(LDFLAGS) $(N2N_LIB) $(LIBS_EDGE) -o $@
|
||||
|
||||
example_edge_embed: example_edge_embed.c $(N2N_LIB) n2n.h
|
||||
example_edge_embed: src/example_edge_embed.c $(N2N_DEPS)
|
||||
$(CC) $(CFLAGS) $< $(LDFLAGS) $(N2N_LIB) $(LIBS_EDGE) -o $@
|
||||
|
||||
%.gz : %
|
||||
|
|
|
@ -15,6 +15,7 @@ fi
|
|||
|
||||
N2N_LIBS=
|
||||
|
||||
AC_PROG_CC([clang])
|
||||
AC_CHECK_LIB([zstd], [ZSTD_compress])
|
||||
|
||||
if test "x$ac_cv_lib_zstd_ZSTD_compress" != xyes; then
|
||||
|
@ -92,6 +93,7 @@ fi
|
|||
|
||||
DATE=`date +"%Y-%m-%d"`
|
||||
|
||||
AC_SUBST(CC)
|
||||
AC_SUBST(CFLAGS)
|
||||
AC_SUBST(LDFLAGS)
|
||||
AC_SUBST(N2N_MAJOR)
|
||||
|
@ -104,7 +106,7 @@ AC_SUBST(GIT_RELEASE)
|
|||
AC_SUBST(N2N_DEFINES)
|
||||
AC_SUBST(N2N_LIBS)
|
||||
AC_SUBST(ADDITIONAL_TOOLS)
|
||||
AC_CONFIG_HEADERS(config.h)
|
||||
AC_CONFIG_HEADERS(include/config.h)
|
||||
AC_CONFIG_FILES(Makefile)
|
||||
AC_CONFIG_FILES(tools/Makefile)
|
||||
|
||||
|
|
34
include/edge_utils_win32.h
Normal file
34
include/edge_utils_win32.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* (C) 2007-20 - 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/>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <process.h>
|
||||
|
||||
/* Multicast peers discovery disabled due to https://github.com/ntop/n2n/issues/65 */
|
||||
#define SKIP_MULTICAST_PEERS_DISCOVERY
|
||||
|
||||
struct tunread_arg {
|
||||
n2n_edge_t *eee;
|
||||
int *keep_running;
|
||||
};
|
||||
|
||||
extern HANDLE startTunReadThread(struct tunread_arg *arg);
|
||||
|
||||
#endif
|
||||
|
|
@ -16,11 +16,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "n2n.h"
|
||||
#include "speck.h"
|
||||
|
||||
|
||||
/* Header encryption indicators */
|
||||
|
@ -28,15 +23,12 @@
|
|||
#define HEADER_ENCRYPTION_NONE 1
|
||||
#define HEADER_ENCRYPTION_ENABLED 2
|
||||
|
||||
|
||||
uint32_t packet_header_decrypt (uint8_t packet[], uint8_t packet_len,
|
||||
char * community_name, he_context_t * ctx);
|
||||
|
||||
|
||||
int8_t packet_header_decrypt_if_required (uint8_t packet[], uint16_t packet_len,
|
||||
struct sn_community * communities);
|
||||
|
||||
|
||||
int32_t packet_header_encrypt (uint8_t packet[], uint8_t header_len, he_context_t * ctx);
|
||||
|
||||
|
|
@ -64,6 +64,8 @@
|
|||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
|
@ -74,6 +76,16 @@
|
|||
|
||||
#ifdef __linux__
|
||||
#define N2N_CAN_NAME_IFACE 1
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
#include <net/if_arp.h>
|
||||
#include <net/if.h>
|
||||
#include <linux/if_tun.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#define GRND_NONBLOCK 1
|
||||
#endif /* #ifdef __linux__ */
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
|
@ -83,7 +95,12 @@
|
|||
#include <syslog.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#if defined (__RDRND__) || defined (__RDSEED__)
|
||||
#include <immintrin.h>
|
||||
#endif
|
||||
|
||||
#define ETH_ADDR_LEN 6
|
||||
|
||||
struct ether_hdr
|
||||
{
|
||||
uint8_t dhost[ETH_ADDR_LEN];
|
||||
|
@ -93,10 +110,17 @@ struct ether_hdr
|
|||
|
||||
typedef struct ether_hdr ether_hdr_t;
|
||||
|
||||
#ifdef HAVE_LIBZSTD
|
||||
#include <zstd.h>
|
||||
#endif
|
||||
|
||||
#ifdef __ANDROID_NDK__
|
||||
#undef N2N_HAVE_DAEMON
|
||||
#undef N2N_HAVE_SETUID
|
||||
#undef N2N_CAN_NAME_IFACE
|
||||
#include "android/edge_android.h"
|
||||
#include <tun2tap/tun2tap.h>
|
||||
#define ARP_PERIOD_INTERVAL (10) /* sec */
|
||||
#endif /* #ifdef __ANDROID_NDK__ */
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
@ -106,27 +130,37 @@ typedef struct ether_hdr ether_hdr_t;
|
|||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdint.h>
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
#include "minilzo.h"
|
||||
#include "n2n_define.h"
|
||||
|
||||
#define closesocket(a) close(a)
|
||||
#endif /* #ifndef WIN32 */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "uthash.h"
|
||||
#include "lzoconf.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include "win32/wintap.h"
|
||||
#include <sys/stat.h>
|
||||
#else
|
||||
#include <pwd.h>
|
||||
#endif /* #ifdef WIN32 */
|
||||
|
||||
#include "n2n_wire.h"
|
||||
#include "n2n_transforms.h"
|
||||
#include "random_numbers.h"
|
||||
#include "pearson.h"
|
||||
#include "portable_endian.h"
|
||||
#include "speck.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#define N2N_IFNAMSIZ 64
|
||||
|
@ -147,43 +181,6 @@ typedef struct tuntap_dev {
|
|||
#define SOCKET int
|
||||
#endif /* #ifndef WIN32 */
|
||||
|
||||
#define QUICKLZ 1
|
||||
|
||||
/* N2N packet header indicators. */
|
||||
#define MSG_TYPE_REGISTER 1
|
||||
#define MSG_TYPE_DEREGISTER 2
|
||||
#define MSG_TYPE_PACKET 3
|
||||
#define MSG_TYPE_REGISTER_ACK 4
|
||||
#define MSG_TYPE_REGISTER_SUPER 5
|
||||
#define MSG_TYPE_REGISTER_SUPER_ACK 6
|
||||
#define MSG_TYPE_REGISTER_SUPER_NAK 7
|
||||
#define MSG_TYPE_FEDERATION 8
|
||||
#define MSG_TYPE_PEER_INFO 9
|
||||
#define MSG_TYPE_QUERY_PEER 10
|
||||
#define MSG_TYPE_MAX_TYPE 10
|
||||
|
||||
/* N2N compression indicators. */
|
||||
/* Compression is disabled by default for outgoing packets if no cli
|
||||
* option is given. All edges are built with decompression support so
|
||||
* they are able to understand each other (this applies to lzo only). */
|
||||
#define N2N_COMPRESSION_ID_NONE 0 /* default, see edge_init_conf_defaults(...) in edge_utils.c */
|
||||
#define N2N_COMPRESSION_ID_LZO 1 /* set if '-z1' or '-z' cli option is present, see setOption(...) in edge.c */
|
||||
#ifdef N2N_HAVE_ZSTD
|
||||
#define N2N_COMPRESSION_ID_ZSTD 2 /* set if '-z2' cli option is present, available only if compiled with zstd lib */
|
||||
#define ZSTD_COMPRESSION_LEVEL 7 /* 1 (faster) ... 22 (more compression) */
|
||||
#endif
|
||||
// with the next major packet structure update, make '0' = invalid, and '1' = no compression
|
||||
// '2' = LZO, '3' = ZSTD, ... REVISIT then (also: change all occurences in source).
|
||||
|
||||
#define N2N_COMPRESSION_ID_BITLEN 3 /* number of bits used for encoding compression id in the uppermost
|
||||
bits of transform_id; will be obsolete as soon as compression gets
|
||||
its own field in the packet. REVISIT then. */
|
||||
|
||||
/* forward delcaration of header encryption context, see 'header_encryption.h' */
|
||||
typedef struct speck_context_t he_context_t;
|
||||
|
||||
#define DEFAULT_MTU 1290
|
||||
|
||||
/** Uncomment this to enable the MTU check, then try to ssh to generate a fragmented packet. */
|
||||
/** NOTE: see doc/MTU.md for an explanation on the 1400 value */
|
||||
//#define MTU_ASSERT_VALUE 1400
|
||||
|
@ -206,17 +203,7 @@ struct peer_info {
|
|||
UT_hash_handle hh; /* makes this structure hashable */
|
||||
};
|
||||
|
||||
#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_NUM_SUPERNODES 2
|
||||
#define N2N_EDGE_SUP_ATTEMPTS 3 /* Number of failed attmpts before moving on to next supernode. */
|
||||
#define N2N_PATHNAME_MAXLEN 256
|
||||
#define N2N_EDGE_MGMT_PORT 5644
|
||||
|
||||
|
||||
typedef struct speck_context_t he_context_t;
|
||||
typedef char n2n_sn_name_t[N2N_EDGE_SN_HOST_SIZE];
|
||||
|
||||
typedef struct n2n_route {
|
||||
|
@ -252,39 +239,42 @@ typedef struct n2n_edge n2n_edge_t; /* Opaque, see edge_utils.c */
|
|||
|
||||
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. */
|
||||
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;
|
||||
|
||||
struct sn_community
|
||||
struct sn_community
|
||||
{
|
||||
char community[N2N_COMMUNITY_SIZE];
|
||||
uint8_t header_encryption; /* Header encryption indicator. */
|
||||
he_context_t *header_encryption_ctx; /* Header encryption cipher context. */
|
||||
struct peer_info *edges; /* Link list of registered edges. */
|
||||
char community[N2N_COMMUNITY_SIZE];
|
||||
uint8_t header_encryption; /* Header encryption indicator. */
|
||||
he_context_t *header_encryption_ctx; /* Header encryption cipher context. */
|
||||
struct peer_info *edges; /* Link list of registered edges. */
|
||||
|
||||
UT_hash_handle hh; /* makes this structure hashable */
|
||||
UT_hash_handle hh; /* makes this structure hashable */
|
||||
};
|
||||
|
||||
typedef struct n2n_sn
|
||||
typedef struct n2n_sn
|
||||
{
|
||||
time_t start_time; /* Used to measure uptime. */
|
||||
sn_stats_t stats;
|
||||
int daemon; /* If non-zero then daemonise. */
|
||||
uint16_t lport; /* Local UDP port to bind to. */
|
||||
int sock; /* Main socket for UDP traffic with edges. */
|
||||
int mgmt_sock; /* management socket. */
|
||||
int lock_communities; /* If true, only loaded communities can be used. */
|
||||
struct sn_community *communities;
|
||||
time_t start_time; /* Used to measure uptime. */
|
||||
sn_stats_t stats;
|
||||
int daemon; /* If non-zero then daemonise. */
|
||||
uint16_t lport; /* Local UDP port to bind to. */
|
||||
int sock; /* Main socket for UDP traffic with edges. */
|
||||
int mgmt_sock; /* management socket. */
|
||||
int lock_communities; /* If true, only loaded communities can be used. */
|
||||
struct sn_community *communities;
|
||||
} n2n_sn_t;
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
#include "header_encryption.h"
|
||||
#include "twofish.h"
|
||||
|
||||
#ifdef __ANDROID_NDK__
|
||||
#include <android/log.h>
|
||||
#endif /* #ifdef __ANDROID_NDK__ */
|
||||
|
@ -298,21 +288,6 @@ typedef struct sn_stats
|
|||
|
||||
/* ************************************** */
|
||||
|
||||
#define SUPERNODE_IP "127.0.0.1"
|
||||
#define SUPERNODE_PORT 1234
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
#ifndef max
|
||||
#define max(a, b) ((a < b) ? b : a)
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) ((a > b) ? b : a)
|
||||
#endif
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
/* Transop Init Functions */
|
||||
int n2n_transop_null_init(const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt);
|
||||
int n2n_transop_twofish_init(const n2n_edge_conf_t *conf, n2n_trans_op_t *ttt);
|
||||
|
@ -333,7 +308,7 @@ void traceEvent(int eventTraceLevel, char* file, int line, char * format, ...);
|
|||
|
||||
/* Tuntap API */
|
||||
int tuntap_open(tuntap_dev *device, char *dev, const char *address_mode, char *device_ip,
|
||||
char *device_mask, const char * device_mac, int mtu);
|
||||
char *device_mask, const char * device_mac, int mtu);
|
||||
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);
|
||||
|
@ -352,10 +327,10 @@ void print_edge_stats(const n2n_edge_t *eee);
|
|||
|
||||
/* Sockets */
|
||||
char* sock_to_cstr( n2n_sock_str_t out,
|
||||
const n2n_sock_t * sock );
|
||||
const n2n_sock_t * sock );
|
||||
SOCKET open_socket(int local_port, int bind_any);
|
||||
int sock_equal( const n2n_sock_t * a,
|
||||
const n2n_sock_t * b );
|
||||
const n2n_sock_t * b );
|
||||
|
||||
/* Operations on peer_info lists. */
|
||||
size_t purge_peer_list( struct peer_info ** peer_list,
|
94
include/n2n_define.h
Normal file
94
include/n2n_define.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
/**
|
||||
* (C) 2007-20 - 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/>
|
||||
*
|
||||
*/
|
||||
|
||||
#define QUICKLZ 1
|
||||
|
||||
/* N2N packet header indicators. */
|
||||
#define MSG_TYPE_REGISTER 1
|
||||
#define MSG_TYPE_DEREGISTER 2
|
||||
#define MSG_TYPE_PACKET 3
|
||||
#define MSG_TYPE_REGISTER_ACK 4
|
||||
#define MSG_TYPE_REGISTER_SUPER 5
|
||||
#define MSG_TYPE_REGISTER_SUPER_ACK 6
|
||||
#define MSG_TYPE_REGISTER_SUPER_NAK 7
|
||||
#define MSG_TYPE_FEDERATION 8
|
||||
#define MSG_TYPE_PEER_INFO 9
|
||||
#define MSG_TYPE_QUERY_PEER 10
|
||||
#define MSG_TYPE_MAX_TYPE 10
|
||||
|
||||
#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 IFACE_UPDATE_INTERVAL (30) /* sec. How long it usually takes to get an IP lease. */
|
||||
#define TRANSOP_TICK_INTERVAL (10) /* sec */
|
||||
|
||||
#define ETH_FRAMESIZE 14
|
||||
#define IP4_SRCOFFSET 12
|
||||
#define IP4_DSTOFFSET 16
|
||||
#define IP4_MIN_SIZE 20
|
||||
#define UDP_SIZE 8
|
||||
|
||||
/* heap allocation for compression as per lzo example doc */
|
||||
#define HEAP_ALLOC(var,size) lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ]
|
||||
static HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS);
|
||||
|
||||
|
||||
/* N2N compression indicators. */
|
||||
/* Compression is disabled by default for outgoing packets if no cli
|
||||
* option is given. All edges are built with decompression support so
|
||||
* they are able to understand each other (this applies to lzo only). */
|
||||
#define N2N_COMPRESSION_ID_NONE 0 /* default, see edge_init_conf_defaults(...) in edge_utils.c */
|
||||
#define N2N_COMPRESSION_ID_LZO 1 /* set if '-z1' or '-z' cli option is present, see setOption(...) in edge.c */
|
||||
#ifdef N2N_HAVE_ZSTD
|
||||
#define N2N_COMPRESSION_ID_ZSTD 2 /* set if '-z2' cli option is present, available only if compiled with zstd lib */
|
||||
#define ZSTD_COMPRESSION_LEVEL 7 /* 1 (faster) ... 22 (more compression) */
|
||||
#endif
|
||||
// with the next major packet structure update, make '0' = invalid, and '1' = no compression
|
||||
// '2' = LZO, '3' = ZSTD, ... REVISIT then (also: change all occurences in source).
|
||||
|
||||
#define N2N_COMPRESSION_ID_BITLEN 3 /* number of bits used for encoding compression id in the uppermost
|
||||
bits of transform_id; will be obsolete as soon as compression gets
|
||||
its own field in the packet. REVISIT then. */
|
||||
|
||||
#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_NUM_SUPERNODES 2
|
||||
#define N2N_EDGE_SUP_ATTEMPTS 3 /* Number of failed attmpts before moving on to next supernode. */
|
||||
#define N2N_PATHNAME_MAXLEN 256
|
||||
#define N2N_EDGE_MGMT_PORT 5644
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
#define SUPERNODE_IP "127.0.0.1"
|
||||
#define SUPERNODE_PORT 1234
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
#ifndef max
|
||||
#define max(a, b) ((a < b) ? b : a)
|
||||
#endif
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) ((a > b) ? b : a)
|
||||
#endif
|
||||
|
38
include/random_numbers.h
Normal file
38
include/random_numbers.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* (C) 2007-20 - 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/>
|
||||
*
|
||||
*/
|
||||
|
||||
/* The WIN32 code is still untested and thus commented
|
||||
#if defined (WIN32)
|
||||
#include <Wincrypt.h>
|
||||
#endif
|
||||
*/
|
||||
|
||||
struct rn_generator_state_t {
|
||||
uint64_t a, b;
|
||||
};
|
||||
|
||||
struct splitmix64_state_t {
|
||||
uint64_t s;
|
||||
};
|
||||
|
||||
|
||||
int n2n_srand (uint64_t seed);
|
||||
|
||||
uint64_t n2n_rand ();
|
||||
|
||||
uint64_t n2n_seed ();
|
|
@ -1,34 +0,0 @@
|
|||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
#if defined (__linux__)
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
#define GRND_NONBLOCK 1
|
||||
#endif
|
||||
|
||||
#if defined (__RDRND__) || defined (__RDSEED__)
|
||||
#include <immintrin.h>
|
||||
#endif
|
||||
|
||||
/* The WIN32 code is still untested and thus commented
|
||||
#if defined (WIN32)
|
||||
#include <Wincrypt.h>
|
||||
#endif */
|
||||
|
||||
|
||||
struct rn_generator_state_t {
|
||||
uint64_t a, b;
|
||||
};
|
||||
|
||||
struct splitmix64_state_t {
|
||||
uint64_t s;
|
||||
};
|
||||
|
||||
|
||||
int n2n_srand (uint64_t seed);
|
||||
|
||||
uint64_t n2n_rand ();
|
||||
|
||||
uint64_t n2n_seed ();
|
|
@ -17,12 +17,6 @@
|
|||
*/
|
||||
|
||||
#include "n2n.h"
|
||||
#include "random_numbers.h"
|
||||
#ifdef WIN32
|
||||
#include <sys/stat.h>
|
||||
#else
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#define N2N_NETMASK_STR_SIZE 16 /* dotted decimal 12 numbers + 3 dots */
|
||||
#define N2N_MACNAMSIZ 18 /* AA:BB:CC:DD:EE:FF + NULL*/
|
File diff suppressed because it is too large
Load Diff
49
src/edge_utils_win32.c
Normal file
49
src/edge_utils_win32.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* (C) 2007-20 - 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/>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include "edge_utils_win32.h"
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
static DWORD* tunReadThread(LPVOID lpArg) {
|
||||
struct tunread_arg *arg = (struct tunread_arg*)lpArg;
|
||||
|
||||
while(*arg->keep_running)
|
||||
readFromTAPSocket(arg->eee);
|
||||
|
||||
return((DWORD*)NULL);
|
||||
}
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
/** Start a second thread in Windows because TUNTAP interfaces do not expose
|
||||
* file descriptors. */
|
||||
HANDLE startTunReadThread(struct tunread_arg *arg) {
|
||||
DWORD dwThreadId;
|
||||
|
||||
return(CreateThread(NULL, /* security attributes */
|
||||
0, /* use default stack size */
|
||||
(LPTHREAD_START_ROUTINE)tunReadThread, /* thread function */
|
||||
(void*)arg, /* argument to thread function */
|
||||
0, /* thread creation flags */
|
||||
&dwThreadId)); /* thread id out */
|
||||
}
|
||||
#endif
|
||||
|
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
|
||||
#include "n2n.h"
|
||||
#include "random_numbers.h"
|
||||
|
||||
/*
|
||||
This tool demonstrates how to easily embed
|
|
@ -16,17 +16,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "header_encryption.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "random_numbers.h"
|
||||
#include "pearson.h"
|
||||
#include "portable_endian.h"
|
||||
|
||||
#include "n2n.h"
|
||||
|
||||
#define HASH_FIND_COMMUNITY(head, name, out) HASH_FIND_STR(head, name, out)
|
||||
|
||||
/* ********************************************************************** */
|
||||
|
||||
uint32_t packet_header_decrypt (uint8_t packet[], uint8_t packet_len,
|
||||
char * community_name, he_context_t * ctx) {
|
||||
|
@ -58,6 +53,7 @@ uint32_t packet_header_decrypt (uint8_t packet[], uint8_t packet_len,
|
|||
return (0); // unsuccessful
|
||||
}
|
||||
|
||||
/* ********************************************************************** */
|
||||
|
||||
int8_t packet_header_decrypt_if_required (uint8_t packet[], uint16_t packet_len,
|
||||
struct sn_community *communities) {
|
||||
|
@ -113,6 +109,7 @@ int8_t packet_header_decrypt_if_required (uint8_t packet[], uint16_t packet_len,
|
|||
}
|
||||
}
|
||||
|
||||
/* ********************************************************************** */
|
||||
|
||||
int32_t packet_header_encrypt (uint8_t packet[], uint8_t header_len, he_context_t * ctx) {
|
||||
uint8_t iv[16];
|
||||
|
@ -134,6 +131,7 @@ int32_t packet_header_encrypt (uint8_t packet[], uint8_t header_len, he_context_
|
|||
return (0);
|
||||
}
|
||||
|
||||
/* ********************************************************************** */
|
||||
|
||||
void packet_header_setup_key (char * community_name, he_context_t * ctx) {
|
||||
|
|
@ -1,12 +1,29 @@
|
|||
/**
|
||||
* (C) 2007-20 - 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"
|
||||
|
||||
/* The following code offers an alterate pseudo random number generator
|
||||
namely XORSHIFT128+ to use instead of C's rand(). Its performance is
|
||||
on par with C's rand().
|
||||
*/
|
||||
|
||||
|
||||
#include "random_numbers.h"
|
||||
|
||||
|
||||
/* The state must be seeded in a way that it is not all zero, choose some
|
||||
arbitrary defaults (in this case: taken from splitmix64) */
|
||||
static struct rn_generator_state_t rn_current_state = {
|
|
@ -17,8 +17,6 @@
|
|||
*/
|
||||
|
||||
#include "n2n.h"
|
||||
#include "n2n_transforms.h"
|
||||
#include "random_numbers.h"
|
||||
|
||||
#ifdef N2N_HAVE_AES
|
||||
|
|
@ -17,8 +17,6 @@
|
|||
*/
|
||||
|
||||
#include "n2n.h"
|
||||
#include "n2n_transforms.h"
|
||||
#include "random_numbers.h"
|
||||
|
||||
#ifdef HAVE_OPENSSL_1_1
|
||||
|
|
@ -17,10 +17,6 @@
|
|||
*/
|
||||
|
||||
#include "n2n.h"
|
||||
#include "n2n_transforms.h"
|
||||
#include "speck.h"
|
||||
#include "random_numbers.h"
|
||||
#include "pearson.h"
|
||||
|
||||
#define N2N_SPECK_TRANSFORM_VERSION 1 /* version of the transform encoding */
|
||||
#define N2N_SPECK_IVEC_SIZE 16
|
|
@ -17,13 +17,6 @@
|
|||
*/
|
||||
|
||||
#include "n2n.h"
|
||||
#include "n2n_transforms.h"
|
||||
#include "twofish.h"
|
||||
#include "random_numbers.h"
|
||||
#ifndef _MSC_VER
|
||||
/* Not included in Visual Studio 2008 */
|
||||
#include <strings.h> /* index() */
|
||||
#endif
|
||||
|
||||
#define N2N_TWOFISH_NUM_SA 32 /* space for SAa */
|
||||
|
|
@ -16,16 +16,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "n2n.h"
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
#include <net/if_arp.h>
|
||||
#include <net/if.h>
|
||||
#include <linux/if_tun.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include "random_numbers.h"
|
||||
#include "n2n.h"
|
||||
|
||||
/* ********************************** */
|
||||
|
|
@ -35,13 +35,7 @@
|
|||
#ifndef __TWOFISH_LIBRARY_SOURCE__
|
||||
#define __TWOFISH_LIBRARY_SOURCE__
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include "twofish.h"
|
||||
#include "random_numbers.h"
|
||||
#include "n2n.h"
|
||||
|
||||
/* Fixed 8x8 permutation S-boxes */
|
||||
static const uint8_t TwoFish_P[2][256] =
|
|
@ -16,8 +16,8 @@ endif
|
|||
|
||||
LIBS_EDGE_OPT=@N2N_LIBS@
|
||||
LIBS_EDGE+=$(LIBS_EDGE_OPT)
|
||||
HEADERS=../n2n_wire.h ../n2n.h ../twofish.h ../n2n_transforms.h
|
||||
CFLAGS+=-I.. @CFLAGS@
|
||||
HEADERS=$(wildcard include/*.h)
|
||||
CFLAGS+=-I../include @CFLAGS@
|
||||
LDFLAGS+=-L..
|
||||
CFLAGS+=$(DEBUG) $(OPTIMIZATION) $(WARN)
|
||||
LDFLAGS=@LDFLAGS@
|
||||
|
|
Loading…
Reference in New Issue
Block a user