2000-03-26 00:33:07 +00:00
|
|
|
/*
|
|
|
|
net.h -- header for net.c
|
2009-09-24 21:42:30 +00:00
|
|
|
Copyright (C) 1998-2005 Ivo Timmermans
|
2012-03-10 12:23:08 +00:00
|
|
|
2000-2012 Guus Sliepen <guus@tinc-vpn.org>
|
2000-03-26 00:33:07 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 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.
|
|
|
|
|
2009-09-24 22:01:00 +00:00
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2000-03-26 00:33:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __TINC_NET_H__
|
|
|
|
#define __TINC_NET_H__
|
|
|
|
|
2003-03-28 13:41:49 +00:00
|
|
|
#include <openssl/evp.h>
|
2000-03-26 00:33:07 +00:00
|
|
|
|
2003-07-18 12:16:24 +00:00
|
|
|
#include "ipv6.h"
|
|
|
|
|
2002-03-22 11:43:48 +00:00
|
|
|
#ifdef ENABLE_JUMBOGRAMS
|
2004-04-15 14:09:56 +00:00
|
|
|
#define MTU 9018 /* 9000 bytes payload + 14 bytes ethernet header + 4 bytes VLAN tag */
|
2002-03-22 11:43:48 +00:00
|
|
|
#else
|
2004-04-15 14:09:56 +00:00
|
|
|
#define MTU 1518 /* 1500 bytes payload + 14 bytes ethernet header + 4 bytes VLAN tag */
|
2002-03-22 11:43:48 +00:00
|
|
|
#endif
|
2000-03-26 00:33:07 +00:00
|
|
|
|
2003-05-07 11:21:58 +00:00
|
|
|
#define MAXSIZE (MTU + 4 + EVP_MAX_BLOCK_LENGTH + EVP_MAX_MD_SIZE + MTU/64 + 20) /* MTU + seqno + padding + HMAC + compressor overhead */
|
2003-05-06 21:13:18 +00:00
|
|
|
#define MAXBUFSIZE ((MAXSIZE > 2048 ? MAXSIZE : 2048) + 128) /* Enough room for a request with a MAXSIZEd packet or a 8192 bits RSA key */
|
|
|
|
|
2002-09-09 21:25:28 +00:00
|
|
|
#define MAXSOCKETS 128 /* Overkill... */
|
2000-10-28 21:25:21 +00:00
|
|
|
|
2002-09-09 21:25:28 +00:00
|
|
|
typedef struct mac_t {
|
|
|
|
uint8_t x[6];
|
2000-10-11 10:35:17 +00:00
|
|
|
} mac_t;
|
|
|
|
|
2002-09-09 21:25:28 +00:00
|
|
|
typedef struct ipv4_t {
|
|
|
|
uint8_t x[4];
|
2002-02-18 16:25:19 +00:00
|
|
|
} ipv4_t;
|
2002-02-10 21:57:54 +00:00
|
|
|
|
2002-09-09 21:25:28 +00:00
|
|
|
typedef struct ipv6_t {
|
|
|
|
uint16_t x[8];
|
2002-02-10 21:57:54 +00:00
|
|
|
} ipv6_t;
|
|
|
|
|
2000-10-11 10:35:17 +00:00
|
|
|
typedef short length_t;
|
2000-09-14 14:32:34 +00:00
|
|
|
|
2003-10-08 12:09:37 +00:00
|
|
|
#define AF_UNKNOWN 255
|
2003-08-22 11:18:42 +00:00
|
|
|
|
|
|
|
struct sockaddr_unknown {
|
|
|
|
uint16_t family;
|
|
|
|
uint16_t pad1;
|
|
|
|
uint32_t pad2;
|
|
|
|
char *address;
|
|
|
|
char *port;
|
|
|
|
};
|
|
|
|
|
2003-07-22 20:55:21 +00:00
|
|
|
typedef union sockaddr_t {
|
2002-09-09 21:25:28 +00:00
|
|
|
struct sockaddr sa;
|
|
|
|
struct sockaddr_in in;
|
|
|
|
struct sockaddr_in6 in6;
|
2003-08-22 11:18:42 +00:00
|
|
|
struct sockaddr_unknown unknown;
|
2003-07-07 11:11:33 +00:00
|
|
|
#ifdef HAVE_STRUCT_SOCKADDR_STORAGE
|
|
|
|
struct sockaddr_storage storage;
|
2003-07-06 17:15:25 +00:00
|
|
|
#endif
|
2002-02-18 16:25:19 +00:00
|
|
|
} sockaddr_t;
|
|
|
|
|
2002-02-26 22:47:51 +00:00
|
|
|
#ifdef SA_LEN
|
|
|
|
#define SALEN(s) SA_LEN(&s)
|
2002-02-20 22:15:32 +00:00
|
|
|
#else
|
2002-02-26 22:47:51 +00:00
|
|
|
#define SALEN(s) (s.sa_family==AF_INET?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6))
|
2002-02-20 22:15:32 +00:00
|
|
|
#endif
|
|
|
|
|
2000-03-26 00:33:07 +00:00
|
|
|
typedef struct vpn_packet_t {
|
2002-09-09 21:25:28 +00:00
|
|
|
length_t len; /* the actual number of bytes in the `data' field */
|
|
|
|
int priority; /* priority or TOS */
|
|
|
|
uint32_t seqno; /* 32 bits sequence number (network byte order of course) */
|
|
|
|
uint8_t data[MAXSIZE];
|
2000-03-26 00:33:07 +00:00
|
|
|
} vpn_packet_t;
|
|
|
|
|
2003-07-22 20:55:21 +00:00
|
|
|
typedef struct listen_socket_t {
|
|
|
|
int tcp;
|
|
|
|
int udp;
|
|
|
|
sockaddr_t sa;
|
|
|
|
} listen_socket_t;
|
|
|
|
|
2003-07-17 15:06:27 +00:00
|
|
|
#include "conf.h"
|
2009-01-20 12:12:41 +00:00
|
|
|
#include "list.h"
|
2003-07-17 15:06:27 +00:00
|
|
|
|
2002-02-10 21:57:54 +00:00
|
|
|
typedef struct outgoing_t {
|
2002-09-09 21:25:28 +00:00
|
|
|
char *name;
|
|
|
|
int timeout;
|
|
|
|
struct config_t *cfg;
|
|
|
|
struct addrinfo *ai;
|
|
|
|
struct addrinfo *aip;
|
2009-10-20 20:14:47 +00:00
|
|
|
struct event *event;
|
2002-02-10 21:57:54 +00:00
|
|
|
} outgoing_t;
|
|
|
|
|
2009-01-20 12:12:41 +00:00
|
|
|
extern list_t *outgoing_list;
|
|
|
|
|
2006-01-19 17:13:18 +00:00
|
|
|
extern int maxoutbufsize;
|
2001-06-08 18:02:10 +00:00
|
|
|
extern int seconds_till_retry;
|
2002-02-18 16:25:19 +00:00
|
|
|
extern int addressfamily;
|
2010-11-13 18:05:50 +00:00
|
|
|
extern unsigned replaywin;
|
2012-02-22 22:17:43 +00:00
|
|
|
extern bool localdiscovery;
|
2001-06-08 18:02:10 +00:00
|
|
|
|
2002-03-18 22:47:20 +00:00
|
|
|
extern listen_socket_t listen_socket[MAXSOCKETS];
|
2002-03-01 13:18:54 +00:00
|
|
|
extern int listen_sockets;
|
2002-02-18 16:25:19 +00:00
|
|
|
extern int keyexpires;
|
|
|
|
extern int keylifetime;
|
2010-11-13 18:05:49 +00:00
|
|
|
extern int udp_rcvbuf;
|
|
|
|
extern int udp_sndbuf;
|
2003-07-22 20:55:21 +00:00
|
|
|
extern bool do_prune;
|
|
|
|
extern bool do_purge;
|
2002-02-18 16:25:19 +00:00
|
|
|
extern char *myport;
|
2002-03-01 14:09:31 +00:00
|
|
|
extern time_t now;
|
2010-06-04 12:53:52 +00:00
|
|
|
extern int contradicting_add_edge;
|
|
|
|
extern int contradicting_del_edge;
|
2002-02-18 16:25:19 +00:00
|
|
|
|
2011-05-28 21:36:52 +00:00
|
|
|
extern volatile bool running;
|
|
|
|
|
2003-07-17 15:06:27 +00:00
|
|
|
/* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
|
|
|
|
#include "connection.h"
|
|
|
|
#include "node.h"
|
|
|
|
|
2002-02-18 16:25:19 +00:00
|
|
|
extern void retry_outgoing(outgoing_t *);
|
2002-02-26 23:26:41 +00:00
|
|
|
extern void handle_incoming_vpn_data(int);
|
2003-07-17 15:06:27 +00:00
|
|
|
extern void finish_connecting(struct connection_t *);
|
|
|
|
extern void do_outgoing_connection(struct connection_t *);
|
2003-07-22 20:55:21 +00:00
|
|
|
extern bool handle_new_meta_connection(int);
|
2003-07-24 12:08:16 +00:00
|
|
|
extern int setup_listen_socket(const sockaddr_t *);
|
|
|
|
extern int setup_vpn_in_socket(const sockaddr_t *);
|
|
|
|
extern void send_packet(const struct node_t *, vpn_packet_t *);
|
2011-05-28 21:36:52 +00:00
|
|
|
extern void receive_tcppacket(struct connection_t *, const char *, int);
|
2003-07-24 12:08:16 +00:00
|
|
|
extern void broadcast_packet(const struct node_t *, vpn_packet_t *);
|
2009-05-18 12:25:10 +00:00
|
|
|
extern bool setup_network(void);
|
2002-02-10 21:57:54 +00:00
|
|
|
extern void setup_outgoing_connection(struct outgoing_t *);
|
|
|
|
extern void try_outgoing_connections(void);
|
2000-03-26 00:33:07 +00:00
|
|
|
extern void close_network_connections(void);
|
2003-08-02 20:50:38 +00:00
|
|
|
extern int main_loop(void);
|
2003-07-22 20:55:21 +00:00
|
|
|
extern void terminate_connection(struct connection_t *, bool);
|
2001-10-27 12:13:17 +00:00
|
|
|
extern void flush_queue(struct node_t *);
|
2003-07-22 20:55:21 +00:00
|
|
|
extern bool read_rsa_public_key(struct connection_t *);
|
2003-12-20 19:47:53 +00:00
|
|
|
extern void send_mtu_probe(struct node_t *);
|
2011-05-28 21:36:52 +00:00
|
|
|
extern void load_all_subnets(void);
|
2000-11-30 23:18:21 +00:00
|
|
|
|
2003-07-29 22:59:01 +00:00
|
|
|
#ifndef HAVE_MINGW
|
|
|
|
#define closesocket(s) close(s)
|
2009-09-15 20:59:01 +00:00
|
|
|
#else
|
|
|
|
extern CRITICAL_SECTION mutex;
|
2003-07-29 22:59:01 +00:00
|
|
|
#endif
|
|
|
|
|
2002-09-09 21:25:28 +00:00
|
|
|
#endif /* __TINC_NET_H__ */
|