protocol.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef TINC_PROTOCOL_H
  2. #define TINC_PROTOCOL_H
  3. /*
  4. protocol.h -- header for protocol.c
  5. Copyright (C) 1999-2005 Ivo Timmermans,
  6. 2000-2015 Guus Sliepen <guus@tinc-vpn.org>
  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. /* Protocol version. Different versions are incompatible,
  20. incompatible version have different protocols.
  21. */
  22. #define PROT_CURRENT 17
  23. /* Silly Windows */
  24. #ifdef ERROR
  25. #undef ERROR
  26. #endif
  27. /* Request numbers */
  28. typedef enum request_t {
  29. PROXY = -2,
  30. ALL = -1, /* Guardian for allow_request */
  31. ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK,
  32. STATUS, ERROR, TERMREQ,
  33. PING, PONG,
  34. ADD_SUBNET, DEL_SUBNET,
  35. ADD_EDGE, DEL_EDGE,
  36. KEY_CHANGED, REQ_KEY, ANS_KEY,
  37. PACKET,
  38. LAST /* Guardian for the highest request number */
  39. } request_t;
  40. typedef struct past_request_t {
  41. char *request;
  42. time_t firstseen;
  43. } past_request_t;
  44. extern bool tunnelserver;
  45. extern bool strictsubnets;
  46. /* Maximum size of strings in a request.
  47. * scanf terminates %2048s with a NUL character,
  48. * but the NUL character can be written after the 2048th non-NUL character.
  49. */
  50. #define MAX_STRING_SIZE 2049
  51. #define MAX_STRING "%2048s"
  52. #include "edge.h"
  53. #include "net.h"
  54. #include "node.h"
  55. #include "subnet.h"
  56. /* Basic functions */
  57. extern bool send_request(struct connection_t *c, const char *format, ...) __attribute__((__format__(printf, 2, 3)));
  58. extern void forward_request(struct connection_t *c);
  59. extern bool receive_request(struct connection_t *c);
  60. extern bool check_id(const char *name);
  61. extern void init_requests(void);
  62. extern void exit_requests(void);
  63. extern bool seen_request(char *request);
  64. extern void age_past_requests(void);
  65. /* Requests */
  66. extern bool send_id(struct connection_t *c);
  67. extern bool send_metakey(struct connection_t *c);
  68. extern bool send_challenge(struct connection_t *c);
  69. extern bool send_chal_reply(struct connection_t *c);
  70. extern bool send_ack(struct connection_t *c);
  71. extern bool send_ping(struct connection_t *c);
  72. extern bool send_pong(struct connection_t *c);
  73. extern bool send_add_subnet(struct connection_t *c, const struct subnet_t *subnet);
  74. extern bool send_del_subnet(struct connection_t *c, const struct subnet_t *subnet);
  75. extern bool send_add_edge(struct connection_t *c, const struct edge_t *e);
  76. extern bool send_del_edge(struct connection_t *c, const struct edge_t *e);
  77. extern void send_key_changed(void);
  78. extern bool send_req_key(struct node_t *n);
  79. extern bool send_ans_key(struct node_t *n);
  80. extern bool send_tcppacket(struct connection_t *c, const struct vpn_packet_t *packet);
  81. /* Request handlers */
  82. extern bool id_h(struct connection_t *c);
  83. extern bool metakey_h(struct connection_t *c);
  84. extern bool challenge_h(struct connection_t *c);
  85. extern bool chal_reply_h(struct connection_t *c);
  86. extern bool ack_h(struct connection_t *c);
  87. extern bool ping_h(struct connection_t *c);
  88. extern bool pong_h(struct connection_t *c);
  89. extern bool add_subnet_h(struct connection_t *c);
  90. extern bool del_subnet_h(struct connection_t *c);
  91. extern bool add_edge_h(struct connection_t *c);
  92. extern bool del_edge_h(struct connection_t *c);
  93. extern bool key_changed_h(struct connection_t *c);
  94. extern bool req_key_h(struct connection_t *c);
  95. extern bool ans_key_h(struct connection_t *c);
  96. extern bool tcppacket_h(struct connection_t *c);
  97. #endif