You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.2 KiB

10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
9 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
9 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
9 years ago
11 years ago
  1. /*
  2. * udprelay.h - Define UDP relay's buffers and callbacks
  3. *
  4. * Copyright (C) 2013 - 2015, Max Lv <max.c.lv@gmail.com>
  5. *
  6. * This file is part of the shadowsocks-libev.
  7. *
  8. * shadowsocks-libev is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * shadowsocks-libev is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with shadowsocks-libev; see the file COPYING. If not, see
  20. * <http://www.gnu.org/licenses/>.
  21. */
  22. #ifndef _UDPRELAY_H
  23. #define _UDPRELAY_H
  24. #include <ev.h>
  25. #include <time.h>
  26. #include "encrypt.h"
  27. #include "jconf.h"
  28. #ifdef UDPRELAY_REMOTE
  29. #include "resolv.h"
  30. #endif
  31. #include "cache.h"
  32. #include "common.h"
  33. #define MAX_UDP_PACKET_SIZE (65507)
  34. #define MTU 1397 // 1492 - 1 - 28 - 2 - 64 = 1397, the default MTU for UDP relay
  35. struct server_ctx {
  36. ev_io io;
  37. int fd;
  38. int method;
  39. int auth;
  40. int timeout;
  41. const char *iface;
  42. struct cache *conn_cache;
  43. #ifdef UDPRELAY_LOCAL
  44. const struct sockaddr *remote_addr;
  45. int remote_addr_len;
  46. #ifdef UDPRELAY_TUNNEL
  47. ss_addr_t tunnel_addr;
  48. #endif
  49. #endif
  50. #ifdef UDPRELAY_REMOTE
  51. struct ev_loop *loop;
  52. #endif
  53. };
  54. #ifdef UDPRELAY_REMOTE
  55. struct query_ctx {
  56. struct ResolvQuery *query;
  57. struct sockaddr_storage src_addr;
  58. int buf_len;
  59. char *buf; // server send from, remote recv into
  60. int addr_header_len;
  61. char addr_header[384];
  62. struct server_ctx *server_ctx;
  63. struct remote_ctx *remote_ctx;
  64. };
  65. #endif
  66. struct remote_ctx {
  67. ev_io io;
  68. ev_timer watcher;
  69. int af;
  70. int fd;
  71. int addr_header_len;
  72. char addr_header[384];
  73. struct sockaddr_storage src_addr;
  74. struct server_ctx *server_ctx;
  75. };
  76. #ifdef ANDROID
  77. struct protect_ctx {
  78. int buf_len;
  79. char *buf;
  80. struct sockaddr_storage addr;
  81. int addr_len;
  82. struct remote_ctx *remote_ctx;
  83. };
  84. #endif
  85. #endif // _UDPRELAY_H