Use the HAVE_OPENSSL_xxx_H defined from m4/openssl.m4 during
[oweals/tinc.git] / src / connlist.h
1 /*
2     connlist.h -- header for connlist.c
3     Copyright (C) 2000 Guus Sliepen <guus@sliepen.warande.net>,
4                   2000 Ivo Timmermans <itimmermans@bigfoot.com>
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: connlist.h,v 1.1.2.13 2000/11/15 01:06:10 zarq Exp $
21 */
22
23 #ifndef __TINC_CONNLIST_H__
24 #define __TINC_CONNLIST_H__
25
26 #include "config.h"
27
28 #ifdef HAVE_OPENSSL_EVP_H
29 # include <openssl/evp.h>
30 #else
31 # include <evp.h>
32 #endif
33
34 #ifdef HAVE_OPENSSL_RSA_H
35 # include <openssl/rsa.h>
36 #else
37 # include <rsa.h>
38 #endif
39
40 #include "net.h"
41 #include "conf.h"
42
43 typedef struct status_bits_t {
44   int pinged:1;                    /* sent ping */
45   int meta:1;                      /* meta connection exists */
46   int active:1;                    /* 1 if active.. */
47   int outgoing:1;                  /* I myself asked for this conn */
48   int termreq:1;                   /* the termination of this connection was requested */
49   int remove:1;                    /* Set to 1 if you want this connection removed */
50   int timeout:1;                   /* 1 if gotten timeout */
51   int validkey:1;                  /* 1 if we currently have a valid key for him */
52   int waitingforkey:1;             /* 1 if we already sent out a request */
53   int dataopen:1;                  /* 1 if we have a valid UDP connection open */
54   int encryptout:1;                /* 1 if we can encrypt outgoing traffic */
55   int decryptin:1;                 /* 1 if we have to decrypt incoming traffic */
56   int unused:18;
57 } status_bits_t;
58
59 typedef struct option_bits_t {
60   int unused:32;
61 } option_bits_t;
62
63 typedef struct conn_list_t {
64   char *name;                      /* name of this connection */
65   ipv4_t address;                  /* his real (internet) ip */
66   char *hostname;                  /* the hostname of its real ip */
67   short unsigned int port;         /* his portnumber */
68   int protocol_version;            /* used protocol */
69   long unsigned int options;       /* options turned on for this connection */
70
71   int flags;                       /* his flags */
72   int socket;                      /* our udp vpn socket */
73   int meta_socket;                 /* our tcp meta socket */
74   status_bits_t status;            /* status info */
75   packet_queue_t *sq;              /* pending outgoing packets */
76   packet_queue_t *rq;              /* pending incoming packets (they have no
77                                       valid key to be decrypted with) */
78   RSA *rsa_key;                    /* the public/private key */
79
80   EVP_CIPHER_CTX *cipher_inctx;    /* Context of encrypted meta data that will come from him to us */
81   EVP_CIPHER_CTX *cipher_outctx;   /* Context of encrypted meta data that will be sent from us to him */
82   char *cipher_inkey;              /* His symmetric meta key */
83   char *cipher_outkey;             /* Our symmetric meta key */
84
85   EVP_CIPHER *cipher_pkttype;      /* Cipher type for encrypted vpn packets */ 
86   char *cipher_pktkey;             /* Cipher key and iv */
87   int cipher_pktkeylength;         /* Cipher key and iv length*/
88
89   char *buffer;                    /* metadata input buffer */
90   int buflen;                      /* bytes read into buffer */
91   int reqlen;                      /* length of first request in buffer */
92   int allow_request;               /* defined if there's only one request possible */
93
94   time_t last_ping_time;           /* last time we saw some activity from the other end */  
95
96   char *mychallenge;               /* challenge we received from him */
97   char *hischallenge;              /* challenge we sent to him */
98
99   struct conn_list_t *nexthop;     /* nearest meta-hop in this direction */
100   
101   struct subnet_t *subnets;        /* Pointer to a list of subnets belonging to this connection */
102
103   struct config_t *config;         /* Pointer to configuration tree belonging to this host */
104
105   struct conn_list_t *next;        /* after all, it's a list of connections */
106   struct conn_list_t *prev;        /* doubly linked for O(1) deletions */
107 } conn_list_t;
108
109 #include "subnet.h"
110
111 extern conn_list_t *conn_list;
112 extern conn_list_t *myself;
113
114 extern conn_list_t *new_conn_list();
115 extern void free_conn_list(conn_list_t *);
116 extern void conn_list_add(conn_list_t *);
117 extern void conn_list_del(conn_list_t *);
118 extern conn_list_t *lookup_id(char *);
119 extern void dump_conn_list(void);
120 extern int read_host_config(conn_list_t *);
121 extern void destroy_conn_list(void);
122 extern void prune_conn_list(void);
123
124 #endif /* __TINC_CONNLIST_H__ */