f3357248c236c8bf1979704964247288034cb177
[tinc] / src / net.h
1 /*
2     net.h -- header for net.c
3     Copyright (C) 1998-2001 Ivo Timmermans <zarq@iname.com>
4                   2000,2001 Guus Sliepen <guus@sliepen.warande.net>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20     $Id: net.h,v 1.9.4.27 2001/01/07 20:19:31 guus Exp $
21 */
22
23 #ifndef __TINC_NET_H__
24 #define __TINC_NET_H__
25
26 #include <sys/time.h>
27
28 #include "config.h"
29
30 #define MAXSIZE 1700  /* should be a bit more than the MTU for the tapdevice */
31 #define MTU 1600
32
33 #define MAC_ADDR_S "%02x:%02x:%02x:%02x:%02x:%02x"
34 #define MAC_ADDR_V(x) ((unsigned char*)&(x))[0],((unsigned char*)&(x))[1], \
35                       ((unsigned char*)&(x))[2],((unsigned char*)&(x))[3], \
36                       ((unsigned char*)&(x))[4],((unsigned char*)&(x))[5]
37
38 #define IP_ADDR_S "%d.%d.%d.%d"
39
40 #ifdef WORDS_BIGENDIAN
41 # define IP_ADDR_V(x) ((unsigned char*)&(x))[0],((unsigned char*)&(x))[1], \
42                       ((unsigned char*)&(x))[2],((unsigned char*)&(x))[3]
43 #else
44 # define IP_ADDR_V(x) ((unsigned char*)&(x))[3],((unsigned char*)&(x))[2], \
45                       ((unsigned char*)&(x))[1],((unsigned char*)&(x))[0]
46 #endif
47
48 #define MAXBUFSIZE 4096 /* Probably way too much, but it must fit every possible request. */
49
50 /* flags */
51 #define INDIRECTDATA        0x0001 /* Used to indicate that this host has to be reached indirect */
52 #define EXPORTINDIRECTDATA  0x0002 /* Used to indicate uplink that it has to tell others to do INDIRECTDATA */
53 #define TCPONLY             0x0004 /* Tells sender to send packets over TCP instead of UDP (for firewalls) */
54
55 /* tap types */
56 #define TAP_TYPE_ETHERTAP 0
57 #define TAP_TYPE_TUNTAP   1
58
59 typedef struct mac_t
60 {
61   unsigned char x[6];
62 } mac_t;
63
64 typedef unsigned long ipv4_t;
65
66 typedef ipv4_t ip_t; /* alias for ipv4_t */
67
68 typedef struct ipv6_t
69 {
70   unsigned short x[8];
71 } ipv6_t;
72
73 typedef unsigned short port_t;
74
75 typedef short length_t;
76
77 typedef struct vpn_packet_t {
78   length_t len;         /* the actual number of bytes in the `data' field */
79   unsigned char data[MAXSIZE];
80 } vpn_packet_t;
81
82 typedef struct queue_element_t {
83   void *packet;
84   struct queue_element_t *prev;
85   struct queue_element_t *next;
86 } queue_element_t;
87
88 typedef struct packet_queue_t {
89   queue_element_t *head;
90   queue_element_t *tail;
91 } packet_queue_t;
92
93 typedef struct enc_key_t {
94   int length;
95   char *key;
96   time_t expiry;
97 } enc_key_t;
98
99 extern int tap_fd;
100
101 extern int total_tap_in;
102 extern int total_tap_out;
103 extern int total_socket_in;
104 extern int total_socket_out;
105
106 extern char *unknown;
107
108 extern char *request_name[256];
109 extern char *status_text[10];
110
111 #include "connection.h"         /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
112
113 extern int str2opt(const char *);
114 extern char *opt2str(int);
115 extern int send_packet(ip_t, vpn_packet_t *);
116 extern int receive_packet(connection_t *, vpn_packet_t *);
117 extern int setup_network_connections(void);
118 extern void close_network_connections(void);
119 extern void main_loop(void);
120 extern int setup_vpn_connection(connection_t *);
121 extern void terminate_connection(connection_t *);
122 extern void flush_queue(connection_t *);
123
124 #include <config.h>
125 #ifdef HAVE_OPENSSL_RSA_H
126 # include <openssl/rsa.h>
127 #else
128 # include <rsa.h>
129 #endif
130
131 extern int read_rsa_public_key(connection_t *);
132
133 #endif /* __TINC_NET_H__ */