mirror of
https://github.com/ntop/n2n.git
synced 2024-09-19 16:41:11 +02:00
commit
0f5faada07
|
@ -10,9 +10,10 @@ if(NOT DEFINED N2N_OPTION_AES)
|
|||
set(N2N_OPTION_AES ON)
|
||||
endif(NOT DEFINED N2N_OPTION_AES)
|
||||
|
||||
add_definitions(-DN2N_VERSION='\"${N2N_VERSION}\"' -DN2N_OSNAME='\"${N2N_OSNAME}\"')
|
||||
add_definitions(-DN2N_VERSION="${N2N_VERSION}" -DN2N_OSNAME="${N2N_OSNAME}")
|
||||
|
||||
if(N2N_OPTION_AES)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
add_definitions(-DN2N_HAVE_AES)
|
||||
endif(N2N_OPTION_AES)
|
||||
|
||||
|
|
4
Makefile
4
Makefile
|
@ -45,8 +45,10 @@ MAN8DIR=$(MANDIR)/man8
|
|||
|
||||
N2N_LIB=n2n.a
|
||||
N2N_OBJS=n2n.o n2n_keyfile.o wire.o minilzo.o twofish.o \
|
||||
egde_utils.o \
|
||||
transform_null.o transform_tf.o transform_aes.o \
|
||||
tuntap_freebsd.o tuntap_netbsd.o tuntap_linux.o tuntap_osx.o version.o
|
||||
tuntap_freebsd.o tuntap_netbsd.o tuntap_linux.o \
|
||||
tuntap_osx.o version.o
|
||||
LIBS_EDGE+=$(LIBS_EDGE_OPT)
|
||||
LIBS_SN=
|
||||
|
||||
|
|
|
@ -114,6 +114,6 @@ AES (-O3) 12532
|
|||
TF (-O3) 14046
|
||||
NULL (-O3) 10659
|
||||
|
||||
(C) 2007-2010 - Luca Deri <deri@ntop.org> and Richard Andrews <andrews@ntop.org>
|
||||
-----------------
|
||||
|
||||
(C) 2016 - ntop
|
||||
(C) 2007-18 - ntop.org and contributors
|
||||
|
|
18
benchmark.c
18
benchmark.c
|
@ -1,3 +1,21 @@
|
|||
/*
|
||||
* (C) 2007-18 - 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_wire.h"
|
||||
#include "n2n_transforms.h"
|
||||
#include "n2n.h"
|
||||
|
|
8
contributors.txt
Normal file
8
contributors.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
Code contributions courtesy of:
|
||||
* Richard Andrews <andrews@ntop.org>
|
||||
* Don Bindner <don.bindner@gmail.com>
|
||||
* Sylwester Sosnowski <syso-n2n@no-route.org>
|
||||
* Wilfried "Wonka" Klaebe
|
||||
* Lukasz Taczuk
|
||||
* Alaric Snell-Pym <alaric@kitten-technologies.co.uk>
|
||||
* Babak Farrokhi <babak@farrokhi.net> [FreeBSD port]
|
19
doc/n2n_on_MacOS.txt
Normal file
19
doc/n2n_on_MacOS.txt
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
Using n2n on MacOS
|
||||
------------------
|
||||
|
||||
In order to use n2n on MacOS you need to first install support for the tap interface.
|
||||
if you are a brew (https://brew.sh) user you can do it in a couple of steps
|
||||
|
||||
- brew tap homebrew/cask
|
||||
- brew cask install tuntap
|
||||
|
||||
Note that in the latest OS versions (for instance MacOS High Sierra), you may need to
|
||||
need to enable their kernel extension in
|
||||
|
||||
System Preferences → Security & Privacy → General
|
||||
|
||||
For more information refer to vendor documentation or the Apple Technical Note:
|
||||
|
||||
https://developer.apple.com/library/content/technotes/tn2459/_index.html
|
||||
|
1563
egde_utils.c
Normal file
1563
egde_utils.c
Normal file
File diff suppressed because it is too large
Load Diff
56
n2n.c
56
n2n.c
|
@ -1,6 +1,5 @@
|
|||
/*
|
||||
* (C) 2007-09 - Luca Deri <deri@ntop.org>
|
||||
* Richard Andrews <andrews@ntop.org>
|
||||
/**
|
||||
* (C) 2007-18 - 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
|
||||
|
@ -13,11 +12,7 @@
|
|||
* 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/>
|
||||
*
|
||||
* Code contributions courtesy of:
|
||||
* Massimo Torquati <torquati@ntop.org>
|
||||
* Matt Gilg
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -235,12 +230,11 @@ void hexdump(const uint8_t * buf, size_t len)
|
|||
void print_n2n_version() {
|
||||
printf("Welcome to n2n v.%s for %s\n"
|
||||
"Built on %s\n"
|
||||
"Copyright 2007-09 - http://www.ntop.org\n\n",
|
||||
"Copyright 2007-18 - ntop.org and contributors\n\n",
|
||||
n2n_sw_version, n2n_sw_osName, n2n_sw_buildDate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* *********************************************** */
|
||||
|
||||
/** Find the peer entry in list with mac_addr equal to mac.
|
||||
*
|
||||
|
@ -412,41 +406,45 @@ extern int str2mac( uint8_t * outmac /* 6 bytes */, const char * s )
|
|||
}
|
||||
|
||||
extern char * sock_to_cstr(n2n_sock_str_t out,
|
||||
const n2n_sock_t * sock )
|
||||
{
|
||||
int r;
|
||||
|
||||
const n2n_sock_t * sock) {
|
||||
if(NULL == out) { return NULL; }
|
||||
memset(out, 0, N2N_SOCKBUF_SIZE);
|
||||
|
||||
if ( AF_INET6 == sock->family )
|
||||
{
|
||||
if(AF_INET6 == sock->family) {
|
||||
/* INET6 not written yet */
|
||||
r = snprintf( out, N2N_SOCKBUF_SIZE, "XXXX:%hu", sock->port );
|
||||
snprintf(out, N2N_SOCKBUF_SIZE, "XXXX:%hu", sock->port);
|
||||
return out;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
const uint8_t * a = sock->addr.v4;
|
||||
r = snprintf( out, N2N_SOCKBUF_SIZE, "%hu.%hu.%hu.%hu:%hu",
|
||||
(a[0] & 0xff), (a[1] & 0xff), (a[2] & 0xff), (a[3] & 0xff), sock->port );
|
||||
|
||||
snprintf(out, N2N_SOCKBUF_SIZE, "%hu.%hu.%hu.%hu:%hu",
|
||||
(unsigned short)(a[0] & 0xff),
|
||||
(unsigned short)(a[1] & 0xff),
|
||||
(unsigned short)(a[2] & 0xff),
|
||||
(unsigned short)(a[3] & 0xff),
|
||||
(unsigned short)sock->port);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
/* @return zero if the two sockets are equivalent. */
|
||||
int sock_equal(const n2n_sock_t * a,
|
||||
const n2n_sock_t * b )
|
||||
{
|
||||
const n2n_sock_t * b) {
|
||||
if(a->port != b->port) { return 1; }
|
||||
if(a->family != b->family) { return 1; }
|
||||
switch (a->family) /* they are the same */
|
||||
{
|
||||
|
||||
switch(a->family) {
|
||||
case AF_INET:
|
||||
if ( 0 != memcmp( a->addr.v4, b->addr.v4, IPV4_SIZE ) ) { return 1;};
|
||||
if(0 != memcmp(a->addr.v4, b->addr.v4, IPV4_SIZE)) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( 0 != memcmp( a->addr.v6, b->addr.v6, IPV6_SIZE ) ) { return 1;};
|
||||
if(0 != memcmp(a->addr.v6, b->addr.v6, IPV6_SIZE)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
123
n2n.h
123
n2n.h
|
@ -1,6 +1,5 @@
|
|||
/*
|
||||
* (C) 2007-09 - Luca Deri <deri@ntop.org>
|
||||
* Richard Andrews <andrews@ntop.org>
|
||||
/**
|
||||
* (C) 2007-18 - 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
|
||||
|
@ -13,11 +12,7 @@
|
|||
* 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/>
|
||||
*
|
||||
* Code contributions courtesy of:
|
||||
* Babak Farrokhi <babak@farrokhi.net> [FreeBSD port]
|
||||
* Lukasz Taczuk
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -36,14 +31,7 @@
|
|||
tunctl -u UID -t tunX
|
||||
*/
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#define _DARWIN_
|
||||
#endif
|
||||
|
||||
|
||||
/* Some capability defaults which can be reset for particular platforms. */
|
||||
#define N2N_HAVE_DAEMON 1
|
||||
#define N2N_HAVE_SETUID 1
|
||||
/* #define N2N_CAN_NAME_IFACE */
|
||||
|
||||
/* Moved here to define _CRT_SECURE_NO_WARNINGS before all the including takes place */
|
||||
|
@ -99,11 +87,6 @@ struct ether_hdr
|
|||
|
||||
typedef struct ether_hdr ether_hdr_t;
|
||||
|
||||
#ifdef __sun__
|
||||
#include <sys/sysmacros.h> /* MIN() and MAX() declared here */
|
||||
#undef N2N_HAVE_DAEMON
|
||||
#endif /* #ifdef __sun__ */
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/udp.h>
|
||||
|
@ -111,6 +94,9 @@ typedef struct ether_hdr ether_hdr_t;
|
|||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <sys/stat.h>
|
||||
#include "minilzo.h"
|
||||
|
||||
#define closesocket(a) close(a)
|
||||
#endif /* #ifndef WIN32 */
|
||||
|
@ -124,6 +110,7 @@ typedef struct ether_hdr ether_hdr_t;
|
|||
#endif /* #ifdef WIN32 */
|
||||
|
||||
#include "n2n_wire.h"
|
||||
#include "n2n_transforms.h"
|
||||
|
||||
/* N2N_IFNAMSIZ is needed on win32 even if dev_name is not used after declaration */
|
||||
#define N2N_IFNAMSIZ 16 /* 15 chars * NULL */
|
||||
|
@ -177,6 +164,59 @@ struct peer_info {
|
|||
struct n2n_edge; /* defined in edge.c */
|
||||
typedef struct n2n_edge n2n_edge_t;
|
||||
|
||||
#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_MAX_TRANSFORMS 16
|
||||
#define N2N_EDGE_MGMT_PORT 5644
|
||||
|
||||
|
||||
typedef char n2n_sn_name_t[N2N_EDGE_SN_HOST_SIZE];
|
||||
|
||||
struct n2n_edge {
|
||||
int daemon; /**< Non-zero if edge should detach and run in the background. */
|
||||
uint8_t re_resolve_supernode_ip;
|
||||
|
||||
n2n_sock_t supernode;
|
||||
|
||||
size_t sn_idx; /**< Currently active supernode. */
|
||||
size_t sn_num; /**< Number of supernode addresses defined. */
|
||||
n2n_sn_name_t sn_ip_array[N2N_EDGE_NUM_SUPERNODES];
|
||||
int sn_wait; /**< Whether we are waiting for a supernode response. */
|
||||
|
||||
n2n_community_t community_name; /**< The community. 16 full octets. */
|
||||
char keyschedule[N2N_PATHNAME_MAXLEN];
|
||||
int null_transop; /**< Only allowed if no key sources defined. */
|
||||
|
||||
int udp_sock;
|
||||
int udp_mgmt_sock; /**< socket for status info. */
|
||||
|
||||
tuntap_dev device; /**< All about the TUNTAP device */
|
||||
int dyn_ip_mode; /**< Interface IP address is dynamically allocated, eg. DHCP. */
|
||||
int allow_routing; /**< Accept packet no to interface address. */
|
||||
int drop_multicast; /**< Multicast ethernet addresses. */
|
||||
|
||||
n2n_trans_op_t transop[N2N_MAX_TRANSFORMS]; /* one for each transform at fixed positions */
|
||||
size_t tx_transop_idx; /**< The transop to use when encoding. */
|
||||
|
||||
struct peer_info * known_peers; /**< Edges we are connected to. */
|
||||
struct peer_info * pending_peers; /**< Edges we have tried to register with. */
|
||||
time_t last_register_req; /**< Check if time to re-register with super*/
|
||||
size_t register_lifetime; /**< Time distance after last_register_req at which to re-register. */
|
||||
time_t last_p2p; /**< Last time p2p traffic was received. */
|
||||
time_t last_sup; /**< Last time a packet arrived from supernode. */
|
||||
size_t sup_attempts; /**< Number of remaining attempts to this supernode. */
|
||||
n2n_cookie_t last_cookie; /**< Cookie sent in last REGISTER_SUPER. */
|
||||
|
||||
time_t start_time; /**< For calculating uptime */
|
||||
|
||||
/* Statistics */
|
||||
size_t tx_p2p;
|
||||
size_t rx_p2p;
|
||||
size_t tx_sup;
|
||||
size_t rx_sup;
|
||||
};
|
||||
|
||||
/* ************************************** */
|
||||
|
||||
|
@ -251,4 +291,47 @@ size_t purge_expired_registrations( struct peer_info ** peer_list );
|
|||
/* version.c */
|
||||
extern char *n2n_sw_version, *n2n_sw_osName, *n2n_sw_buildDate;
|
||||
|
||||
/* egde_utils.c */
|
||||
int edge_init(n2n_edge_t * eee);
|
||||
void supernode2addr(n2n_sock_t * sn, const n2n_sn_name_t addrIn);
|
||||
void update_supernode_reg(n2n_edge_t * eee, time_t nowTime);
|
||||
int is_empty_ip_address(const n2n_sock_t * sock);
|
||||
void update_peer_address(n2n_edge_t * eee,
|
||||
uint8_t from_supernode,
|
||||
const n2n_mac_t mac,
|
||||
const n2n_sock_t * peer,
|
||||
time_t when);
|
||||
int transop_enum_to_index(n2n_transform_t id);
|
||||
int edge_init_keyschedule(n2n_edge_t * eee);
|
||||
void update_peer_address(n2n_edge_t * eee,
|
||||
uint8_t from_supernode,
|
||||
const n2n_mac_t mac,
|
||||
const n2n_sock_t * peer,
|
||||
time_t when);
|
||||
int is_empty_ip_address(const n2n_sock_t * sock);
|
||||
void send_register(n2n_edge_t * eee,
|
||||
const n2n_sock_t * remote_peer);
|
||||
void send_packet2net(n2n_edge_t * eee,
|
||||
uint8_t *tap_pkt, size_t len);
|
||||
void check_peer(n2n_edge_t * eee,
|
||||
uint8_t from_supernode,
|
||||
const n2n_mac_t mac,
|
||||
const n2n_sock_t * peer);
|
||||
void try_send_register(n2n_edge_t * eee,
|
||||
uint8_t from_supernode,
|
||||
const n2n_mac_t mac,
|
||||
const n2n_sock_t * peer);
|
||||
void set_peer_operational(n2n_edge_t * eee,
|
||||
const n2n_mac_t mac,
|
||||
const n2n_sock_t * peer);
|
||||
const char * supernode_ip(const n2n_edge_t * eee);
|
||||
int edge_init_twofish(n2n_edge_t * eee, uint8_t *encrypt_pwd,
|
||||
uint32_t encrypt_pwd_len);
|
||||
int run_edge_loop(n2n_edge_t * eee);
|
||||
void edge_term(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);
|
||||
|
||||
#endif /* _N2N_H_ */
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
/* (c) 2009 Richard Andrews <andrews@ntop.org> */
|
||||
/* Contributions from:
|
||||
* - Jozef Kralik
|
||||
/**
|
||||
* (C) 2007-18 - 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"
|
||||
|
|
|
@ -1,4 +1,20 @@
|
|||
/* (c) 2009 Richard Andrews <andrews@ntop.org> */
|
||||
/**
|
||||
* (C) 2007-18 - 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/>
|
||||
*
|
||||
*/
|
||||
|
||||
/** Key files
|
||||
*
|
||||
|
|
|
@ -1,4 +1,20 @@
|
|||
/* (c) 2009 Richard Andrews <andrews@ntop.org> */
|
||||
/**
|
||||
* (C) 2007-18 - 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_TRANSFORMS_H_)
|
||||
#define N2N_TRANSFORMS_H_
|
||||
|
@ -21,8 +37,7 @@
|
|||
struct n2n_trans_op;
|
||||
typedef struct n2n_trans_op n2n_trans_op_t;
|
||||
|
||||
struct n2n_tostat
|
||||
{
|
||||
struct n2n_tostat {
|
||||
uint8_t can_tx; /* Does this transop have a valid SA for encoding. */
|
||||
n2n_cipherspec_t tx_spec; /* If can_tx, the spec used to encode. */
|
||||
};
|
||||
|
@ -48,8 +63,7 @@ typedef int (*n2n_transform_f)( n2n_trans_op_t * arg,
|
|||
* to use to decode the packet content. The transform code then decodes the
|
||||
* packet and consults its internal key lookup.
|
||||
*/
|
||||
struct n2n_trans_op
|
||||
{
|
||||
struct n2n_trans_op {
|
||||
void * priv; /* opaque data. Key schedule goes here. */
|
||||
|
||||
n2n_transform_t transform_id; /* link header enum to a transform */
|
||||
|
|
19
n2n_wire.h
19
n2n_wire.h
|
@ -1,8 +1,19 @@
|
|||
/* (c) 2009 Richard Andrews <andrews@ntop.org>
|
||||
/**
|
||||
* (C) 2007-18 - 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/>
|
||||
*
|
||||
* Contributions by:
|
||||
* Luca Deri
|
||||
* Lukasz Taczuk
|
||||
*/
|
||||
|
||||
#if !defined( N2N_WIRE_H_ )
|
||||
|
|
|
@ -28,7 +28,7 @@ PKG_AND_VERSION="${PACKAGE}-${PKG_VERSION}"
|
|||
TEMPDIR="tmp"
|
||||
|
||||
SOURCE_MANIFEST="
|
||||
README
|
||||
README.md
|
||||
edge.c
|
||||
lzoconf.h
|
||||
lzodefs.h
|
||||
|
|
22
sn.c
22
sn.c
|
@ -1,12 +1,22 @@
|
|||
/* Supernode for n2n-2.x */
|
||||
|
||||
/* (c) 2009 Richard Andrews <andrews@ntop.org>
|
||||
/**
|
||||
* (C) 2007-18 - 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/>
|
||||
*
|
||||
* Contributions by:
|
||||
* Lukasz Taczuk
|
||||
* Struan Bartlett
|
||||
*/
|
||||
|
||||
/* Supernode for n2n-2.x */
|
||||
|
||||
#include "n2n.h"
|
||||
|
||||
|
|
18
test.c
18
test.c
|
@ -1,3 +1,21 @@
|
|||
/**
|
||||
* (C) 2007-18 - 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"
|
||||
#include "n2n_keyfile.h"
|
||||
#include <assert.h>
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
/* (c) 2009 Richard Andrews <andrews@ntop.org> */
|
||||
/* Contributions from:
|
||||
* - Jozef Kralik
|
||||
/**
|
||||
* (C) 2007-18 - 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"
|
||||
|
|
|
@ -1,4 +1,20 @@
|
|||
/* (c) 2009 Richard Andrews <andrews@ntop.org> */
|
||||
/**
|
||||
* (C) 2007-18 - 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"
|
||||
#include "n2n_transforms.h"
|
||||
|
|
|
@ -1,4 +1,20 @@
|
|||
/* (c) 2009 Richard Andrews <andrews@ntop.org> */
|
||||
/**
|
||||
* (C) 2007-18 - 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"
|
||||
#include "n2n_transforms.h"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* (C) 2007-09 - Luca Deri <deri@ntop.org>
|
||||
/**
|
||||
* (C) 2007-18 - 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
|
||||
|
@ -13,6 +13,7 @@
|
|||
*
|
||||
* 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"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* (C) 2007-09 - Luca Deri <deri@ntop.org>
|
||||
/**
|
||||
* (C) 2007-18 - 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
|
||||
|
@ -12,13 +12,16 @@
|
|||
* 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/>
|
||||
* along with this program; if not see see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "n2n.h"
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
static void read_mac(char *ifname, n2n_mac_t mac_addr) {
|
||||
int _sock, res;
|
||||
struct ifreq ifr;
|
||||
|
@ -30,8 +33,10 @@ static void read_mac(char *ifname, n2n_mac_t mac_addr) {
|
|||
_sock=socket(PF_INET, SOCK_DGRAM, 0);
|
||||
strcpy(ifr.ifr_name, ifname);
|
||||
res = ioctl(_sock,SIOCGIFHWADDR,&ifr);
|
||||
|
||||
if(res < 0) {
|
||||
perror ("Get hw addr");
|
||||
traceEvent(TRACE_ERROR, "Unable to read interfce %s MAC", ifname);
|
||||
} else
|
||||
memcpy(mac_addr, ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
|
||||
|
||||
|
@ -120,22 +125,29 @@ int tuntap_open(tuntap_dev *device,
|
|||
return(device->fd);
|
||||
}
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
int tuntap_read(struct tuntap_dev *tuntap, unsigned char *buf, int len) {
|
||||
return(read(tuntap->fd, buf, len));
|
||||
}
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
int tuntap_write(struct tuntap_dev *tuntap, unsigned char *buf, int len) {
|
||||
return(write(tuntap->fd, buf, len));
|
||||
}
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
void tuntap_close(struct tuntap_dev *tuntap) {
|
||||
close(tuntap->fd);
|
||||
}
|
||||
|
||||
/* *************************************************** */
|
||||
|
||||
/* Fill out the ip_addr value from the interface. Called to pick up dynamic
|
||||
* address changes. */
|
||||
void tuntap_get_address(struct tuntap_dev *tuntap)
|
||||
{
|
||||
void tuntap_get_address(struct tuntap_dev *tuntap) {
|
||||
FILE * fp=NULL;
|
||||
ssize_t nread=0;
|
||||
char buf[N2N_LINUX_SYSTEMCMD_SIZE];
|
||||
|
@ -145,21 +157,25 @@ void tuntap_get_address(struct tuntap_dev *tuntap)
|
|||
|
||||
/* If the interface has no address (0.0.0.0) there will be no inet addr
|
||||
* line and the returned string will be empty. */
|
||||
snprintf( buf, sizeof(buf), "/sbin/ifconfig %s | /bin/sed -e '/inet addr:/!d' -e 's/^.*inet addr://' -e 's/ .*$//'",
|
||||
snprintf( buf, sizeof(buf),
|
||||
"/sbin/ifconfig %s | /bin/sed -e '/inet addr:/!d' -e 's/^.*inet addr://' -e 's/ .*$//'",
|
||||
tuntap->dev_name);
|
||||
fp = popen(buf, "r");
|
||||
if (fp )
|
||||
{
|
||||
|
||||
if (fp) {
|
||||
memset(buf, 0, N2N_LINUX_SYSTEMCMD_SIZE); /* make sure buf is NULL terminated. */
|
||||
nread=fread(buf, 1, 15, fp);
|
||||
nread = fread(buf, N2N_LINUX_SYSTEMCMD_SIZE-1, 1, fp);
|
||||
fclose(fp);
|
||||
fp = NULL;
|
||||
|
||||
traceEvent(TRACE_INFO, "ifconfig address = %s", buf);
|
||||
|
||||
if(nread > 0) {
|
||||
buf[nread] = '\0';
|
||||
tuntap->ip_addr = inet_addr(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* #ifdef __linux__ */
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/*
|
||||
* (C) 2007-09 - Luca Deri <deri@ntop.org>
|
||||
* (C) 2009 - Alaric Snell-Pym <alaric@kitten-technologies.co.uk>
|
||||
/**
|
||||
* (C) 2007-18 - 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
|
||||
|
@ -14,6 +13,7 @@
|
|||
*
|
||||
* 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"
|
||||
|
@ -62,46 +62,45 @@ int tuntap_open(tuntap_dev *device /* ignored */,
|
|||
traceEvent(TRACE_ERROR, "Unable to open tap device (%s)", strerror(errno));
|
||||
return(-1);
|
||||
} else {
|
||||
char buf[256];
|
||||
char cmd[256];
|
||||
FILE *fd;
|
||||
|
||||
traceEvent(TRACE_NORMAL, "Succesfully open %s", tap_device);
|
||||
|
||||
device->ip_addr = inet_addr(device_ip);
|
||||
|
||||
if ( device_mac && device_mac[0] != '\0' )
|
||||
{
|
||||
if( device_mac && device_mac[0] != '\0') {
|
||||
/* Set the hw address before bringing the if up. */
|
||||
snprintf(buf, sizeof(buf), "ifconfig %s link %s active",
|
||||
snprintf(cmd, sizeof(cmd), "ifconfig %s link %s active",
|
||||
tap_device, device_mac);
|
||||
system(buf);
|
||||
system(cmd);
|
||||
}
|
||||
|
||||
snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s mtu %d up",
|
||||
snprintf(cmd, sizeof(cmd), "ifconfig %s %s netmask %s mtu %d up",
|
||||
tap_device, device_ip, device_mask, mtu);
|
||||
system(buf);
|
||||
system(cmd);
|
||||
|
||||
traceEvent(TRACE_NORMAL, "Interface %s up and running (%s/%s)",
|
||||
tap_device, device_ip, device_mask);
|
||||
|
||||
/* Read MAC address */
|
||||
snprintf(cmd, sizeof(cmd), "ifconfig %s |grep address|cut -c 11-28", tap_device);
|
||||
/* traceEvent(TRACE_INFO, "%s", cmd); */
|
||||
|
||||
snprintf(buf, sizeof(buf), "ifconfig %s |grep address|cut -c 11-28", tap_device);
|
||||
/* traceEvent(TRACE_INFO, "%s", buf); */
|
||||
|
||||
fd = popen(buf, "r");
|
||||
fd = popen(cmd, "r");
|
||||
if(fd < 0) {
|
||||
tun_close(device);
|
||||
return(-1);
|
||||
} else {
|
||||
int a, b, c, d, e, f;
|
||||
char buf[256];
|
||||
|
||||
buf[0] = 0;
|
||||
fgets(buf, sizeof(buf), fd);
|
||||
pclose(fd);
|
||||
|
||||
if(buf[0] == '\0') {
|
||||
traceEvent(TRACE_ERROR, "Unable to read %s interface MAC address", tap_device);
|
||||
traceEvent(TRACE_ERROR, "Unable to read %s interface MAC address [%s]", tap_device, cmd);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
11
tuntap_osx.c
11
tuntap_osx.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* (C) 2007-09 - Luca Deri <deri@ntop.org>
|
||||
/**
|
||||
* (C) 2007-18 - 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
|
||||
|
@ -13,11 +13,12 @@
|
|||
*
|
||||
* 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"
|
||||
|
||||
#ifdef _DARWIN_
|
||||
#ifdef __APPLE__
|
||||
|
||||
void tun_close(tuntap_dev *device);
|
||||
|
||||
|
@ -77,7 +78,7 @@ int tuntap_open(tuntap_dev *device /* ignored */,
|
|||
|
||||
fd = popen(buf, "r");
|
||||
if(fd < 0) {
|
||||
tun_close(device);
|
||||
tuntap_close(device);
|
||||
return(-1);
|
||||
} else {
|
||||
int a, b, c, d, e, f;
|
||||
|
@ -129,4 +130,4 @@ void tuntap_get_address(struct tuntap_dev *tuntap)
|
|||
{
|
||||
}
|
||||
|
||||
#endif /* _DARWIN_ */
|
||||
#endif /* __APPLE__ */
|
||||
|
|
18
wire.c
18
wire.c
|
@ -1,4 +1,20 @@
|
|||
/* (c) 2009 Richard Andrews <andrews@ntop.org> */
|
||||
/**
|
||||
* (C) 2007-18 - 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/>
|
||||
*
|
||||
*/
|
||||
|
||||
/** Routines for encoding and decoding n2n packets on the wire.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user