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.

84 lines
1.9 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
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
10 years ago
11 years ago
11 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 (64 * 1024)
  34. struct server_ctx {
  35. ev_io io;
  36. int fd;
  37. int method;
  38. int timeout;
  39. const char *iface;
  40. struct cache *conn_cache;
  41. #ifdef UDPRELAY_LOCAL
  42. const struct sockaddr *remote_addr;
  43. int remote_addr_len;
  44. #ifdef UDPRELAY_TUNNEL
  45. ss_addr_t tunnel_addr;
  46. #endif
  47. #endif
  48. #ifdef UDPRELAY_REMOTE
  49. struct ev_loop *loop;
  50. #endif
  51. };
  52. #ifdef UDPRELAY_REMOTE
  53. struct query_ctx {
  54. struct ResolvQuery *query;
  55. struct sockaddr_storage src_addr;
  56. int buf_len;
  57. char *buf; // server send from, remote recv into
  58. int addr_header_len;
  59. char addr_header[384];
  60. struct server_ctx *server_ctx;
  61. };
  62. #endif
  63. struct remote_ctx {
  64. ev_io io;
  65. ev_timer watcher;
  66. int fd;
  67. int addr_header_len;
  68. char addr_header[384];
  69. struct sockaddr_storage src_addr;
  70. struct sockaddr_storage dst_addr;
  71. struct server_ctx *server_ctx;
  72. };
  73. #endif // _UDPRELAY_H