Big and bad commit of my current tree...
[oweals/tinc.git] / src / net.h
1 /*
2     net.h -- header for net.c
3     Copyright (C) 1998,1999,2000 Ivo Timmermans <zarq@iname.com>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19     $Id: net.h,v 1.9.4.14 2000/10/11 10:35:16 guus Exp $
20 */
21
22 #ifndef __TINC_NET_H__
23 #define __TINC_NET_H__
24
25 #include <sys/time.h>
26
27 #include "config.h"
28 #include "conf.h"
29 #include "connlist.h"
30
31 #define MAXSIZE 1700  /* should be a bit more than the MTU for the tapdevice */
32 #define MTU 1600
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 2048 /* Probably way too much, but it must fit every possible request. */
50
51 /* flags */
52 #define INDIRECTDATA        0x0001 /* Used to indicate that this host has to be reached indirect */
53 #define EXPORTINDIRECTDATA  0x0002 /* Used to indicate uplink that it has to tell others to do INDIRECTDATA */
54 #define TCPONLY             0x0004 /* Tells sender to send packets over TCP instead of UDP (for firewalls) */
55
56 typedef struct mac_t
57 {
58   unsigned char x[6];
59 } mac_t;
60
61 typedef unsigned long ipv4_t;
62
63 typedef ipv4_t ip_t; /* alias for ipv4_t */
64
65 typedef struct ipv6_t
66 {
67   unsigned short x[8];
68 } ipv6_t;
69
70 typedef unsigned short port_t;
71
72 typedef short length_t;
73
74 typedef struct vpn_packet_t {
75   length_t len;         /* the actual number of bytes in the `data' field */
76   unsigned char data[MAXSIZE];
77 } vpn_packet_t;
78
79 typedef struct passphrase_t {
80   unsigned short len;
81   unsigned char *phrase;
82 } passphrase_t;
83
84 typedef struct status_bits_t {
85   int pinged:1;                    /* sent ping */
86   int got_pong:1;                  /* received pong */
87   int meta:1;                      /* meta connection exists */
88   int active:1;                    /* 1 if active.. */
89   int outgoing:1;                  /* I myself asked for this conn */
90   int termreq:1;                   /* the termination of this connection was requested */
91   int remove:1;                    /* Set to 1 if you want this connection removed */
92   int timeout:1;                   /* 1 if gotten timeout */
93   int validkey:1;                  /* 1 if we currently have a valid key for him */
94   int waitingforkey:1;             /* 1 if we already sent out a request */
95   int dataopen:1;                  /* 1 if we have a valid UDP connection open */
96   int encryptout:1;                /* 1 if we can encrypt outgoing traffic */
97   int decryptin:1;                 /* 1 if we have to decrypt incoming traffic */
98   int unused:18;
99 } status_bits_t;
100
101 typedef struct option_bits_t {
102   int unused:32;
103 } option_bits_t;
104
105 typedef struct queue_element_t {
106   void *packet;
107   struct queue_element_t *prev;
108   struct queue_element_t *next;
109 } queue_element_t;
110
111 typedef struct packet_queue_t {
112   queue_element_t *head;
113   queue_element_t *tail;
114 } packet_queue_t;
115
116 typedef struct enc_key_t {
117   int length;
118   char *key;
119   time_t expiry;
120 } enc_key_t;
121
122 extern int tap_fd;
123
124 extern int total_tap_in;
125 extern int total_tap_out;
126 extern int total_socket_in;
127 extern int total_socket_out;
128
129 extern char *request_name[256];
130 extern char *status_text[10];
131
132 extern int str2opt(const char *);
133 extern char *opt2str(int);
134 extern int send_packet(ip_t, vpn_packet_t *);
135 extern int setup_network_connections(void);
136 extern void close_network_connections(void);
137 extern void main_loop(void);
138 extern int setup_vpn_connection(conn_list_t *);
139 extern void terminate_connection(conn_list_t *);
140 extern void flush_queues(conn_list_t*);
141 extern int xrecv(vpn_packet_t *);
142 extern void add_queue(packet_queue_t **, void *, size_t);
143
144 #endif /* __TINC_NET_H__ */