Removing cipher directory (all will be covered by OpenSSL).
[tinc] / 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.13 2000/10/01 03:21:49 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
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 2048 /* 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 typedef unsigned long ip_t;
56 typedef unsigned short port_t;
57 typedef short length_t;
58
59 struct conn_list_t;
60
61 typedef struct vpn_packet_t {
62   length_t len;         /* the actual number of bytes in the `data' field */
63   unsigned char data[MAXSIZE];
64 } vpn_packet_t;
65
66 typedef struct real_packet_t {
67   length_t len;         /* the length of the entire packet */
68   ip_t from;            /* where the packet came from */
69   vpn_packet_t data;    /* encrypted vpn_packet_t */
70 } real_packet_t;
71
72 typedef struct passphrase_t {
73   unsigned short len;
74   unsigned char *phrase;
75 } passphrase_t;
76
77 typedef struct status_bits_t {
78   int pinged:1;                    /* sent ping */
79   int got_pong:1;                  /* received pong */
80   int meta:1;                      /* meta connection exists */
81   int active:1;                    /* 1 if active.. */
82   int outgoing:1;                  /* I myself asked for this conn */
83   int termreq:1;                   /* the termination of this connection was requested */
84   int remove:1;                    /* Set to 1 if you want this connection removed */
85   int timeout:1;                   /* 1 if gotten timeout */
86   int validkey:1;                  /* 1 if we currently have a valid key for him */
87   int waitingforkey:1;             /* 1 if we already sent out a request */
88   int dataopen:1;                  /* 1 if we have a valid UDP connection open */
89   int encryptout:1;                /* 1 if we can encrypt outgoing traffic */
90   int encryptin:1;                 /* 1 if we have to decrypt incoming traffic */
91   int encrypted:1;
92   int unused:18;
93 } status_bits_t;
94
95 typedef struct option_bits_t {
96   int unused:32;
97 } option_bits_t;
98
99 typedef struct queue_element_t {
100   void *packet;
101   struct queue_element_t *prev;
102   struct queue_element_t *next;
103 } queue_element_t;
104
105 typedef struct packet_queue_t {
106   queue_element_t *head;
107   queue_element_t *tail;
108 } packet_queue_t;
109
110 typedef struct enc_key_t {
111   int length;
112   char *key;
113   time_t expiry;
114 } enc_key_t;
115
116 typedef struct conn_list_t {
117   char *name;                      /* name of this connection */
118   ip_t real_ip;                    /* his real (internet) ip */
119   char *hostname;                  /* the hostname of its real ip */
120   short unsigned int port;         /* his portnumber */
121   int protocol_version;            /* used protocol */
122   int options;                     /* options turned on for this connection */
123
124   int flags;                       /* his flags */
125   int socket;                      /* our udp vpn socket */
126   int meta_socket;                 /* our tcp meta socket */
127   status_bits_t status;            /* status info */
128   packet_queue_t *sq;              /* pending outgoing packets */
129   packet_queue_t *rq;              /* pending incoming packets (they have no
130                                       valid key to be decrypted with) */
131   enc_key_t *public_key;           /* the other party's public key */
132   enc_key_t *datakey;              /* encrypt data packets with this key */
133   enc_key_t *rsakey;
134
135   char *buffer;                    /* metadata input buffer */
136   int buflen;                      /* bytes read into buffer */
137   int reqlen;                      /* length of first request in buffer */
138   int allow_request;               /* defined if there's only one request possible */
139
140   time_t last_ping_time;           /* last time we saw some activity from the other end */  
141   int want_ping;                   /* 0 if there's no need to check for activity. Shouldn't this go into status? (GS) */
142
143   char *mychallenge;               /* challenge we received from him */
144   char *hischallenge;              /* challenge we sent to him */
145
146   struct conn_list_t *nexthop;     /* nearest meta-hop in this direction, will be changed to myuplink (GS) */
147   struct conn_list_t *hisuplink;   /* his nearest meta-hop in our direction */
148   struct conn_list_t *myuplink;    /* our nearest meta-hop in his direction */
149
150   struct subnet_t *subnets;        /* Pointer to a list of subnets belonging to this connection */
151
152   struct conn_list_t *next;        /* after all, it's a list of connections */
153 } conn_list_t;
154
155 extern int tap_fd;
156
157 extern int total_tap_in;
158 extern int total_tap_out;
159 extern int total_socket_in;
160 extern int total_socket_out;
161
162 extern conn_list_t *conn_list;
163 extern conn_list_t *myself;
164
165 extern char *request_name[256];
166 extern char *status_text[10];
167
168 extern int str2opt(const char *);
169 extern char *opt2str(int);
170 extern int send_packet(ip_t, vpn_packet_t *);
171 extern int setup_network_connections(void);
172 extern void close_network_connections(void);
173 extern void main_loop(void);
174 extern int setup_vpn_connection(conn_list_t *);
175 extern void terminate_connection(conn_list_t *);
176 extern void flush_queues(conn_list_t*);
177 extern int xrecv(conn_list_t *, void *);
178 extern void add_queue(packet_queue_t **, void *, size_t);
179
180 #endif /* __TINC_NET_H__ */