75d59df235a137bdea86be13076f89d6deb4bdc5
[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.33 2001/06/08 18:02:10 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 #define SALTLEN 2       /* to spice things up for the NSA... */
33
34 #define MAC_ADDR_S "%02x:%02x:%02x:%02x:%02x:%02x"
35 #define MAC_ADDR_V(x) ((unsigned char*)&(x))[0],((unsigned char*)&(x))[1], \
36                       ((unsigned char*)&(x))[2],((unsigned char*)&(x))[3], \
37                       ((unsigned char*)&(x))[4],((unsigned char*)&(x))[5]
38
39 #define IP_ADDR_S "%d.%d.%d.%d"
40
41 #ifdef WORDS_BIGENDIAN
42 # define IP_ADDR_V(x) ((unsigned char*)&(x))[0],((unsigned char*)&(x))[1], \
43                       ((unsigned char*)&(x))[2],((unsigned char*)&(x))[3]
44 #else
45 # define IP_ADDR_V(x) ((unsigned char*)&(x))[3],((unsigned char*)&(x))[2], \
46                       ((unsigned char*)&(x))[1],((unsigned char*)&(x))[0]
47 #endif
48
49 #define MAXBUFSIZE 4096 /* Probably way too much, but it must fit every possible request. */
50
51 /* tap types */
52 #define TAP_TYPE_ETHERTAP 0
53 #define TAP_TYPE_TUNTAP   1
54
55 typedef struct mac_t
56 {
57   unsigned char x[6];
58 } mac_t;
59
60 typedef unsigned long ipv4_t;
61
62 typedef struct ipv6_t
63 {
64   unsigned short x[8];
65 } ipv6_t;
66
67 typedef unsigned short port_t;
68
69 typedef short length_t;
70
71 typedef struct vpn_packet_t {
72   length_t len;                 /* the actual number of bytes in the `data' field */
73   unsigned char salt[SALTLEN];  /* two bytes of randomness */
74   unsigned char data[MAXSIZE];
75 } vpn_packet_t;
76
77 typedef struct queue_element_t {
78   void *packet;
79   struct queue_element_t *prev;
80   struct queue_element_t *next;
81 } queue_element_t;
82
83 typedef struct packet_queue_t {
84   queue_element_t *head;
85   queue_element_t *tail;
86 } packet_queue_t;
87
88 typedef struct enc_key_t {
89   int length;
90   char *key;
91   time_t expiry;
92 } enc_key_t;
93
94 extern int tap_fd;
95
96 extern int total_tap_in;
97 extern int total_tap_out;
98 extern int total_socket_in;
99 extern int total_socket_out;
100
101 extern int seconds_till_retry;
102
103 extern char *request_name[256];
104 extern char *status_text[10];
105
106 #include "connection.h"         /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
107
108 extern int str2opt(const char *);
109 extern char *opt2str(int);
110 extern void send_packet(connection_t *, vpn_packet_t *);
111 extern void receive_packet(connection_t *, vpn_packet_t *);
112 extern void receive_tcppacket(connection_t *, char *, int);
113 extern void accept_packet(vpn_packet_t *);
114 extern void broadcast_packet(connection_t *, vpn_packet_t *);
115 extern int setup_network_connections(void);
116 extern void close_network_connections(void);
117 extern void main_loop(void);
118 extern void terminate_connection(connection_t *);
119 extern void flush_queue(connection_t *);
120
121 #include <config.h>
122 #ifdef HAVE_OPENSSL_RSA_H
123 # include <openssl/rsa.h>
124 #else
125 # include <rsa.h>
126 #endif
127
128 extern int read_rsa_public_key(connection_t *);
129
130 #endif /* __TINC_NET_H__ */