connection.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. connection.h -- header for connection.c
  3. Copyright (C) 2000-2012 Guus Sliepen <guus@tinc-vpn.org>,
  4. 2000-2005 Ivo Timmermans
  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. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #ifndef __TINC_CONNECTION_H__
  18. #define __TINC_CONNECTION_H__
  19. #include <openssl/rsa.h>
  20. #include <openssl/evp.h>
  21. #include "avl_tree.h"
  22. #define OPTION_INDIRECT 0x0001
  23. #define OPTION_TCPONLY 0x0002
  24. #define OPTION_PMTU_DISCOVERY 0x0004
  25. #define OPTION_CLAMP_MSS 0x0008
  26. typedef struct connection_status_t {
  27. unsigned int pinged:1; /* sent ping */
  28. unsigned int active:1; /* 1 if active.. */
  29. unsigned int connecting:1; /* 1 if we are waiting for a non-blocking connect() to finish */
  30. unsigned int termreq:1; /* the termination of this connection was requested */
  31. unsigned int remove:1; /* Set to 1 if you want this connection removed */
  32. unsigned int timeout:1; /* 1 if gotten timeout */
  33. unsigned int encryptout:1; /* 1 if we can encrypt outgoing traffic */
  34. unsigned int decryptin:1; /* 1 if we have to decrypt incoming traffic */
  35. unsigned int mst:1; /* 1 if this connection is part of a minimum spanning tree */
  36. unsigned int unused:23;
  37. } connection_status_t;
  38. #include "edge.h"
  39. #include "net.h"
  40. #include "node.h"
  41. typedef struct connection_t {
  42. char *name; /* name he claims to have */
  43. union sockaddr_t address; /* his real (internet) ip */
  44. char *hostname; /* the hostname of its real ip */
  45. int protocol_version; /* used protocol */
  46. int socket; /* socket used for this connection */
  47. uint32_t options; /* options for this connection */
  48. connection_status_t status; /* status info */
  49. int estimated_weight; /* estimation for the weight of the edge for this connection */
  50. struct timeval start; /* time this connection was started, used for above estimation */
  51. struct outgoing_t *outgoing; /* used to keep track of outgoing connections */
  52. struct node_t *node; /* node associated with the other end */
  53. struct edge_t *edge; /* edge associated with this connection */
  54. RSA *rsa_key; /* his public/private key */
  55. const EVP_CIPHER *incipher; /* Cipher he will use to send data to us */
  56. const EVP_CIPHER *outcipher; /* Cipher we will use to send data to him */
  57. EVP_CIPHER_CTX *inctx; /* Context of encrypted meta data that will come from him to us */
  58. EVP_CIPHER_CTX *outctx; /* Context of encrypted meta data that will be sent from us to him */
  59. char *inkey; /* His symmetric meta key + iv */
  60. char *outkey; /* Our symmetric meta key + iv */
  61. int inkeylength; /* Length of his key + iv */
  62. int outkeylength; /* Length of our key + iv */
  63. const EVP_MD *indigest;
  64. const EVP_MD *outdigest;
  65. int inmaclength;
  66. int outmaclength;
  67. int incompression;
  68. int outcompression;
  69. char *mychallenge; /* challenge we received from him */
  70. char *hischallenge; /* challenge we sent to him */
  71. char buffer[MAXBUFSIZE]; /* metadata input buffer */
  72. int buflen; /* bytes read into buffer */
  73. int reqlen; /* length of incoming request */
  74. int tcplen; /* length of incoming TCPpacket */
  75. int allow_request; /* defined if there's only one request possible */
  76. char *outbuf; /* metadata output buffer */
  77. int outbufstart; /* index of first meaningful byte in output buffer */
  78. int outbuflen; /* number of meaningful bytes in output buffer */
  79. int outbufsize; /* number of bytes allocated to output buffer */
  80. time_t last_ping_time; /* last time we saw some activity from the other end or pinged them */
  81. time_t last_flushed_time; /* last time buffer was empty. Only meaningful if outbuflen > 0 */
  82. avl_tree_t *config_tree; /* Pointer to configuration tree belonging to him */
  83. } connection_t;
  84. extern avl_tree_t *connection_tree;
  85. extern connection_t *everyone;
  86. extern void init_connections(void);
  87. extern void exit_connections(void);
  88. extern connection_t *new_connection(void) __attribute__ ((__malloc__));
  89. extern void free_connection(connection_t *);
  90. extern void connection_add(connection_t *);
  91. extern void connection_del(connection_t *);
  92. extern void dump_connections(void);
  93. #endif /* __TINC_CONNECTION_H__ */