net.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #ifndef TINC_NET_H
  2. #define TINC_NET_H
  3. /*
  4. net.h -- header for net.c
  5. Copyright (C) 1998-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. #include <openssl/evp.h>
  20. #include "ipv6.h"
  21. #ifdef ENABLE_JUMBOGRAMS
  22. #define MTU 9018 /* 9000 bytes payload + 14 bytes ethernet header + 4 bytes VLAN tag */
  23. #else
  24. #define MTU 1518 /* 1500 bytes payload + 14 bytes ethernet header + 4 bytes VLAN tag */
  25. #endif
  26. #define MAXSIZE (MTU + 4 + EVP_MAX_BLOCK_LENGTH + EVP_MAX_MD_SIZE + MTU/64 + 20) /* MTU + seqno + padding + HMAC + compressor overhead */
  27. #define MAXBUFSIZE ((MAXSIZE > 2048 ? MAXSIZE : 2048) + 128) /* Enough room for a request with a MAXSIZEd packet or a 8192 bits RSA key */
  28. #define MAXSOCKETS 128 /* Overkill... */
  29. typedef struct mac_t {
  30. uint8_t x[6];
  31. } mac_t;
  32. typedef struct ipv4_t {
  33. uint8_t x[4];
  34. } ipv4_t;
  35. typedef struct ipv6_t {
  36. uint16_t x[8];
  37. } ipv6_t;
  38. typedef uint16_t length_t;
  39. #define AF_UNKNOWN 255
  40. struct sockaddr_unknown {
  41. uint16_t family;
  42. uint16_t pad1;
  43. uint32_t pad2;
  44. char *address;
  45. char *port;
  46. };
  47. typedef union sockaddr_t {
  48. struct sockaddr sa;
  49. struct sockaddr_in in;
  50. struct sockaddr_in6 in6;
  51. struct sockaddr_unknown unknown;
  52. #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
  53. struct sockaddr_storage storage;
  54. #endif
  55. } sockaddr_t;
  56. #ifdef SA_LEN
  57. #define SALEN(s) SA_LEN(&s)
  58. #else
  59. #define SALEN(s) (s.sa_family==AF_INET?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6))
  60. #endif
  61. typedef struct vpn_packet_t {
  62. length_t len; /* the actual number of bytes in the `data' field */
  63. int priority; /* priority or TOS */
  64. uint32_t seqno; /* 32 bits sequence number (network byte order of course) */
  65. uint8_t data[MAXSIZE];
  66. } vpn_packet_t;
  67. typedef struct listen_socket_t {
  68. int tcp;
  69. int udp;
  70. sockaddr_t sa;
  71. int priority;
  72. } listen_socket_t;
  73. #include "conf.h"
  74. #include "list.h"
  75. typedef struct outgoing_t {
  76. char *name;
  77. int timeout;
  78. struct config_t *cfg;
  79. struct addrinfo *ai;
  80. struct addrinfo *aip;
  81. struct event *event;
  82. } outgoing_t;
  83. extern list_t *outgoing_list;
  84. extern int maxoutbufsize;
  85. extern int seconds_till_retry;
  86. extern int addressfamily;
  87. extern unsigned replaywin;
  88. extern bool localdiscovery;
  89. extern listen_socket_t listen_socket[MAXSOCKETS];
  90. extern int listen_sockets;
  91. extern int keyexpires;
  92. extern int keylifetime;
  93. extern int udp_rcvbuf;
  94. extern int udp_sndbuf;
  95. extern bool do_prune;
  96. extern bool do_purge;
  97. extern char *myport;
  98. extern time_t now;
  99. extern int contradicting_add_edge;
  100. extern int contradicting_del_edge;
  101. extern volatile bool running;
  102. /* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
  103. #include "connection.h"
  104. #include "node.h"
  105. extern void retry_outgoing(outgoing_t *outgoing);
  106. extern void handle_incoming_vpn_data(int sock);
  107. extern void finish_connecting(struct connection_t *c);
  108. extern void do_outgoing_connection(struct connection_t *c);
  109. extern bool handle_new_meta_connection(int sock);
  110. extern int setup_listen_socket(const sockaddr_t *sa);
  111. extern int setup_vpn_in_socket(const sockaddr_t *sa);
  112. extern void send_packet(const struct node_t *n, vpn_packet_t *packet);
  113. extern void receive_tcppacket(struct connection_t *c, const char *buffer, length_t len);
  114. extern void broadcast_packet(const struct node_t *, vpn_packet_t *packet);
  115. extern char *get_name(void);
  116. extern bool setup_network(void);
  117. extern void setup_outgoing_connection(struct outgoing_t *outgoing);
  118. extern void try_outgoing_connections(void);
  119. extern void close_network_connections(void);
  120. extern int main_loop(void);
  121. extern void terminate_connection(struct connection_t *c, bool report);
  122. extern void flush_queue(struct node_t *n);
  123. extern bool read_rsa_public_key(struct connection_t *c);
  124. extern void send_mtu_probe(struct node_t *n);
  125. extern void load_all_subnets(void);
  126. extern void tarpit(int fd);
  127. #ifndef HAVE_MINGW
  128. #define closesocket(s) close(s)
  129. #else
  130. extern CRITICAL_SECTION mutex;
  131. #endif
  132. #endif