connection.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef TINC_CONNECTION_H
  2. #define TINC_CONNECTION_H
  3. /*
  4. connection.h -- header for connection.c
  5. Copyright (C) 2000-2016 Guus Sliepen <guus@tinc-vpn.org>,
  6. 2000-2005 Ivo Timmermans
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License along
  16. with this program; if not, write to the Free Software Foundation, Inc.,
  17. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. */
  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 unused_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 proxy_passed: 1; /* 1 if we are connecting via a proxy and we have finished talking with it */
  37. unsigned int tarpit: 1; /* 1 if the connection should be added to the tarpit */
  38. unsigned int unused: 21;
  39. } connection_status_t;
  40. #include "edge.h"
  41. #include "net.h"
  42. #include "node.h"
  43. typedef struct connection_t {
  44. char *name; /* name he claims to have */
  45. union sockaddr_t address; /* his real (internet) ip */
  46. char *hostname; /* the hostname of its real ip */
  47. int protocol_version; /* used protocol */
  48. int socket; /* socket used for this connection */
  49. uint32_t options; /* options for this connection */
  50. connection_status_t status; /* status info */
  51. int estimated_weight; /* estimation for the weight of the edge for this connection */
  52. struct timeval start; /* time this connection was started, used for above estimation */
  53. struct outgoing_t *outgoing; /* used to keep track of outgoing connections */
  54. struct node_t *node; /* node associated with the other end */
  55. struct edge_t *edge; /* edge associated with this connection */
  56. RSA *rsa_key; /* his public/private key */
  57. const EVP_CIPHER *incipher; /* Cipher he will use to send data to us */
  58. const EVP_CIPHER *outcipher; /* Cipher we will use to send data to him */
  59. EVP_CIPHER_CTX *inctx; /* Context of encrypted meta data that will come from him to us */
  60. EVP_CIPHER_CTX *outctx; /* Context of encrypted meta data that will be sent from us to him */
  61. uint64_t inbudget; /* Encrypted bytes send budget */
  62. uint64_t outbudget; /* Encrypted bytes receive budget */
  63. char *inkey; /* His symmetric meta key + iv */
  64. char *outkey; /* Our symmetric meta key + iv */
  65. int inkeylength; /* Length of his key + iv */
  66. int outkeylength; /* Length of our key + iv */
  67. const EVP_MD *indigest;
  68. const EVP_MD *outdigest;
  69. int inmaclength;
  70. int outmaclength;
  71. int incompression;
  72. int outcompression;
  73. char *mychallenge; /* challenge we received from him */
  74. char *hischallenge; /* challenge we sent to him */
  75. char buffer[MAXBUFSIZE]; /* metadata input buffer */
  76. int buflen; /* bytes read into buffer */
  77. int reqlen; /* length of incoming request */
  78. length_t tcplen; /* length of incoming TCPpacket */
  79. int allow_request; /* defined if there's only one request possible */
  80. char *outbuf; /* metadata output buffer */
  81. int outbufstart; /* index of first meaningful byte in output buffer */
  82. int outbuflen; /* number of meaningful bytes in output buffer */
  83. int outbufsize; /* number of bytes allocated to output buffer */
  84. time_t last_ping_time; /* last time we saw some activity from the other end or pinged them */
  85. time_t last_flushed_time; /* last time buffer was empty. Only meaningful if outbuflen > 0 */
  86. avl_tree_t *config_tree; /* Pointer to configuration tree belonging to him */
  87. } connection_t;
  88. extern avl_tree_t *connection_tree;
  89. extern connection_t *everyone;
  90. extern void init_connections(void);
  91. extern void exit_connections(void);
  92. extern connection_t *new_connection(void) __attribute__((__malloc__));
  93. extern void free_connection(connection_t *c);
  94. extern void free_connection_partially(connection_t *c);
  95. extern void connection_add(connection_t *c);
  96. extern void connection_del(connection_t *c);
  97. extern void dump_connections(void);
  98. #endif