Intercept.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2015 ZeroTier, Inc.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. #ifndef _INTERCEPT_H
  28. #define _INTERCEPT_H 1
  29. #include <sys/socket.h>
  30. /* Userland RPC codes */
  31. #define RPC_UNDEFINED 0
  32. #define RPC_CONNECT 1
  33. #define RPC_CONNECT_SOCKARG 2
  34. #define RPC_SELECT 3
  35. #define RPC_POLL 4
  36. #define RPC_CLOSE 5
  37. #define RPC_READ 6
  38. #define RPC_WRITE 7
  39. #define RPC_BIND 8
  40. #define RPC_ACCEPT 9
  41. #define RPC_LISTEN 10
  42. #define RPC_SOCKET 11
  43. #define RPC_SHUTDOWN 12
  44. /* Administration RPC codes */
  45. #define RPC_FD_MAP_COMPLETION 20 // Give the service the value we "see" for the new buffer fd
  46. #define RPC_RETVAL 21 // not RPC per se, but something we should codify
  47. #define RPC_KILL_INTERCEPT 22 // Tells the service we need to shut down all connections
  48. /* Connection statuses */
  49. #define UNSTARTED 0
  50. #define CONNECTING 1
  51. #define CONNECTED 2
  52. #define SENDING 3
  53. #define RECEIVING 4
  54. #define SENTV4REQ 5
  55. #define GOTV4REQ 6
  56. #define SENTV5METHOD 7
  57. #define GOTV5METHOD 8
  58. #define SENTV5AUTH 9
  59. #define GOTV5AUTH 10
  60. #define SENTV5CONNECT 11
  61. #define GOTV5CONNECT 12
  62. #define DONE 13
  63. #define FAILED 14
  64. /* Flags to indicate what events a
  65. socket was select()ed for */
  66. #define READ (POLLIN|POLLRDNORM)
  67. #define WRITE (POLLOUT|POLLWRNORM|POLLWRBAND)
  68. #define EXCEPT (POLLRDBAND|POLLPRI)
  69. #define READWRITE (READ|WRITE)
  70. #define READWRITEEXCEPT (READ|WRITE|EXCEPT)
  71. /* for AF_UNIX sockets */
  72. #define MAX_PATH_NAME_SIZE 64
  73. // bind
  74. #define BIND_SIG int sockfd, const struct sockaddr *addr, socklen_t addrlen
  75. struct bind_st
  76. {
  77. int sockfd;
  78. struct sockaddr addr;
  79. socklen_t addrlen;
  80. int __tid;
  81. };
  82. // connect
  83. #define CONNECT_SIG int __fd, const struct sockaddr * __addr, socklen_t __len
  84. struct connect_st
  85. {
  86. int __fd;
  87. struct sockaddr __addr;
  88. socklen_t __len;
  89. int __tid;
  90. };
  91. // close
  92. #define CLOSE_SIG int fd
  93. struct close_st
  94. {
  95. int fd;
  96. };
  97. // read
  98. #define DEFAULT_READ_BUFFER_SIZE 1024 * 63
  99. // read buffer sizes (on test machine) min: 4096 default: 87380 max:6147872
  100. #define READ_SIG int __fd, void *__buf, size_t __nbytes
  101. struct read_st
  102. {
  103. int fd;
  104. size_t count;
  105. unsigned char buf[DEFAULT_READ_BUFFER_SIZE];
  106. };
  107. #define DEFAULT_WRITE_BUFFER_SIZE 1024 * 63
  108. // write buffer sizes (on test machine) min: 4096 default: 16384 max:4194304
  109. #define WRITE_SIG int __fd, const void *__buf, size_t __n
  110. struct write_st
  111. {
  112. int fd;
  113. size_t count;
  114. char buf[DEFAULT_WRITE_BUFFER_SIZE];
  115. };
  116. #define LISTEN_SIG int sockfd, int backlog
  117. struct listen_st
  118. {
  119. int sockfd;
  120. int backlog;
  121. int __tid;
  122. };
  123. #define SOCKET_SIG int socket_family, int socket_type, int protocol
  124. struct socket_st
  125. {
  126. int socket_family;
  127. int socket_type;
  128. int protocol;
  129. int __tid;
  130. };
  131. #define ACCEPT4_SIG int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags
  132. #define ACCEPT_SIG int sockfd, struct sockaddr *addr, socklen_t *addrlen
  133. struct accept_st
  134. {
  135. int sockfd;
  136. struct sockaddr addr;
  137. socklen_t addrlen;
  138. int __tid;
  139. };
  140. #define SHUTDOWN_SIG int socket, int how
  141. struct shutdown_st
  142. {
  143. int socket;
  144. int how;
  145. };
  146. #define CONNECT_SOCKARG struct sockaddr *
  147. #define SELECT_SIG int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout
  148. #define POLL_SIG struct pollfd *__fds, nfds_t __nfds, int __timeout
  149. #define IOCTL_SIG int __fd, unsigned long int __request, ...
  150. #define FCNTL_SIG int __fd, int __cmd, ...
  151. #define CLONE_SIG int (*fn) (void *arg), void *child_stack, int flags, void *arg
  152. #define DAEMON_SIG int nochdir, int noclose
  153. #define SETSOCKOPT_SIG int socket, int level, int option_name, const void *option_value, socklen_t option_len
  154. #define GETSOCKOPT_SIG int sockfd, int level, int optname, void *optval, socklen_t *optlen
  155. /* LWIP error beautification */
  156. /*
  157. const char *lwiperror(int n)
  158. {
  159. switch(n)
  160. {
  161. case 0:
  162. return "ERR_OK";
  163. case -1:
  164. return "ERR_MEM (out of memory)";
  165. case -2:
  166. return "ERR_BUF (buffer error)";
  167. case -3:
  168. return "ERR_TIMEOUT (timeout)";
  169. case -4:
  170. return "ERR_RTE (routing problem)";
  171. case -5:
  172. return "ERR_INPROGRESS (operation in progress)";
  173. case -6:
  174. return "ERR_VAL (illegal value)";
  175. case -7:
  176. return "ERR_WOULDBLOCK (operation would block)";
  177. case -8:
  178. return "ERR_USE (address in use)";
  179. case -9:
  180. return "ERR_ISCONN (already connected)";
  181. case -10:
  182. return "Fatal: ERR_ABRT (connection aborted)";
  183. case -11:
  184. return "Fatal: ERR_RST (connection reset)";
  185. case -12:
  186. return "Fatal: ERR_CLSD (connection closed)";
  187. case -13:
  188. return "Fatal: ERR_CONN (not connected)";
  189. case -14:
  190. return "Fatal: ERR_ARG (illegal argument)";
  191. case -15:
  192. return "Fatal: ERR_IF (low level netif error)";
  193. default:
  194. return "UNKNOWN_RET_VAL";
  195. }
  196. }
  197. */
  198. #endif