node.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef TINC_NODE_H
  2. #define TINC_NODE_H
  3. /*
  4. node.h -- header for node.c
  5. Copyright (C) 2001-2016 Guus Sliepen <guus@tinc-vpn.org>,
  6. 2001-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 "avl_tree.h"
  20. #include "connection.h"
  21. #include "event.h"
  22. #include "subnet.h"
  23. typedef struct node_status_t {
  24. unsigned int unused_active: 1; /* 1 if active (not used for nodes) */
  25. unsigned int validkey: 1; /* 1 if we currently have a valid key for him */
  26. unsigned int unused_waitingforkey: 1; /* 1 if we already sent out a request */
  27. unsigned int visited: 1; /* 1 if this node has been visited by one of the graph algorithms */
  28. unsigned int reachable: 1; /* 1 if this node is reachable in the graph */
  29. unsigned int indirect: 1; /* 1 if this node is not directly reachable by us */
  30. unsigned int unused: 26;
  31. } node_status_t;
  32. typedef struct node_t {
  33. char *name; /* name of this node */
  34. uint32_t options; /* options turned on for this node */
  35. int sock; /* Socket to use for outgoing UDP packets */
  36. sockaddr_t address; /* his real (internet) ip to send UDP packets to */
  37. char *hostname; /* the hostname of its real ip */
  38. node_status_t status;
  39. time_t last_req_key;
  40. const EVP_CIPHER *incipher; /* Cipher type for UDP packets received from him */
  41. char *inkey; /* Cipher key and iv */
  42. int inkeylength; /* Cipher key and iv length */
  43. EVP_CIPHER_CTX *inctx; /* Cipher context */
  44. const EVP_CIPHER *outcipher; /* Cipher type for UDP packets sent to him*/
  45. char *outkey; /* Cipher key and iv */
  46. int outkeylength; /* Cipher key and iv length */
  47. EVP_CIPHER_CTX *outctx; /* Cipher context */
  48. const EVP_MD *indigest; /* Digest type for MAC of packets received from him */
  49. int inmaclength; /* Length of MAC */
  50. const EVP_MD *outdigest; /* Digest type for MAC of packets sent to him*/
  51. int outmaclength; /* Length of MAC */
  52. int incompression; /* Compressionlevel, 0 = no compression */
  53. int outcompression; /* Compressionlevel, 0 = no compression */
  54. struct node_t *nexthop; /* nearest node from us to him */
  55. struct edge_t *prevedge; /* nearest node from him to us */
  56. struct node_t *via; /* next hop for UDP packets */
  57. avl_tree_t *subnet_tree; /* Pointer to a tree of subnets belonging to this node */
  58. avl_tree_t *edge_tree; /* Edges with this node as one of the endpoints */
  59. struct connection_t *connection; /* Connection associated with this node (if a direct connection exists) */
  60. uint32_t sent_seqno; /* Sequence number last sent to this node */
  61. uint32_t received_seqno; /* Sequence number last received from this node */
  62. uint32_t farfuture; /* Packets in a row that have arrived from the far future */
  63. unsigned char *late; /* Bitfield marking late packets */
  64. length_t mtu; /* Maximum size of packets to send to this node */
  65. length_t minmtu; /* Probed minimum MTU */
  66. length_t maxmtu; /* Probed maximum MTU */
  67. int mtuprobes; /* Number of probes */
  68. event_t *mtuevent; /* Probe event */
  69. } node_t;
  70. extern struct node_t *myself;
  71. extern avl_tree_t *node_tree;
  72. extern avl_tree_t *node_udp_tree;
  73. extern void init_nodes(void);
  74. extern void exit_nodes(void);
  75. extern node_t *new_node(void) __attribute__((__malloc__));
  76. extern void free_node(node_t *n);
  77. extern void node_add(node_t *n);
  78. extern void node_del(node_t *n);
  79. extern node_t *lookup_node(char *name);
  80. extern node_t *lookup_node_udp(const sockaddr_t *sa);
  81. extern void update_node_udp(node_t *n, const sockaddr_t *sa);
  82. extern void dump_nodes(void);
  83. #endif