Intercept.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. #define IDX_PID 0
  31. #define IDX_TID sizeof(pid_t)
  32. #define IDX_COUNT IDX_TID + sizeof(pid_t)
  33. #define IDX_TIME IDX_COUNT + sizeof(int)
  34. #define IDX_PAYLOAD IDX_TIME + 20 /* 20 being the length of the timestamp string */
  35. #define BUF_SZ 256
  36. #define PAYLOAD_SZ 223 /* BUF_SZ-IDX_PAYLOAD */
  37. #define ERR_OK 0
  38. /* Userland RPC codes */
  39. #define RPC_UNDEFINED 0
  40. #define RPC_CONNECT 1
  41. #define RPC_CONNECT_SOCKARG 2
  42. #define RPC_SELECT 3
  43. #define RPC_POLL 4
  44. #define RPC_CLOSE 5
  45. #define RPC_READ 6
  46. #define RPC_WRITE 7
  47. #define RPC_BIND 8
  48. #define RPC_ACCEPT 9
  49. #define RPC_LISTEN 10
  50. #define RPC_SOCKET 11
  51. #define RPC_SHUTDOWN 12
  52. #define RPC_GETSOCKNAME 13
  53. /* Administration RPC codes */
  54. #define RPC_MAP 20 /* Give the service the value we "see" for the new buffer fd */
  55. #define RPC_MAP_REQ 21 /* A call to determine whether an fd is mapped to the service */
  56. #define RPC_RETVAL 22 /* not RPC per se, but something we should codify */
  57. #define RPC_KILL_INTERCEPT 23 /* Tells the service we need to shut down all connections */
  58. /* Connection statuses */
  59. #define UNSTARTED 0
  60. #define CONNECTING 1
  61. #define CONNECTED 2
  62. #define SENDING 3
  63. #define RECEIVING 4
  64. #define SENTV4REQ 5
  65. #define GOTV4REQ 6
  66. #define SENTV5METHOD 7
  67. #define GOTV5METHOD 8
  68. #define SENTV5AUTH 9
  69. #define GOTV5AUTH 10
  70. #define SENTV5CONNECT 11
  71. #define GOTV5CONNECT 12
  72. #define DONE 13
  73. #define FAILED 14
  74. /* Flags to indicate what events a
  75. socket was select()ed for */
  76. #define READ (POLLIN|POLLRDNORM)
  77. #define WRITE (POLLOUT|POLLWRNORM|POLLWRBAND)
  78. #define EXCEPT (POLLRDBAND|POLLPRI)
  79. #define READWRITE (READ|WRITE)
  80. #define READWRITEEXCEPT (READ|WRITE|EXCEPT)
  81. /* for AF_UNIX sockets */
  82. #define MAX_PATH_NAME_SIZE 64
  83. /* bind */
  84. #define BIND_SIG int sockfd, const struct sockaddr *addr, socklen_t addrlen
  85. struct bind_st
  86. {
  87. int sockfd;
  88. struct sockaddr addr;
  89. socklen_t addrlen;
  90. int __tid;
  91. };
  92. /* connect */
  93. #define CONNECT_SIG int __fd, const struct sockaddr * __addr, socklen_t __len
  94. struct connect_st
  95. {
  96. int __fd;
  97. struct sockaddr __addr;
  98. socklen_t __len;
  99. int __tid;
  100. };
  101. /* close */
  102. #define CLOSE_SIG int fd
  103. struct close_st
  104. {
  105. int fd;
  106. };
  107. /* read */
  108. #define DEFAULT_READ_BUFFER_SIZE 1024 * 63
  109. /* read buffer sizes (on test machine) min: 4096 default: 87380 max:6147872 */
  110. #define READ_SIG int __fd, void *__buf, size_t __nbytes
  111. struct read_st
  112. {
  113. int fd;
  114. size_t count;
  115. unsigned char buf[DEFAULT_READ_BUFFER_SIZE];
  116. };
  117. /* write */
  118. #define DEFAULT_WRITE_BUFFER_SIZE 1024 * 63
  119. /* write buffer sizes (on test machine) min: 4096 default: 16384 max:4194304 */
  120. #define WRITE_SIG int __fd, const void *__buf, size_t __n
  121. struct write_st
  122. {
  123. int fd;
  124. size_t count;
  125. char buf[DEFAULT_WRITE_BUFFER_SIZE];
  126. };
  127. #define LISTEN_SIG int sockfd, int backlog
  128. struct listen_st
  129. {
  130. int sockfd;
  131. int backlog;
  132. int __tid;
  133. };
  134. #define SOCKET_SIG int socket_family, int socket_type, int protocol
  135. struct socket_st
  136. {
  137. int socket_family;
  138. int socket_type;
  139. int protocol;
  140. int __tid;
  141. };
  142. #define ACCEPT4_SIG int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags
  143. #define ACCEPT_SIG int sockfd, struct sockaddr *addr, socklen_t *addrlen
  144. struct accept_st
  145. {
  146. int sockfd;
  147. struct sockaddr addr;
  148. socklen_t addrlen;
  149. int __tid;
  150. };
  151. #define SHUTDOWN_SIG int socket, int how
  152. struct shutdown_st
  153. {
  154. int socket;
  155. int how;
  156. };
  157. struct getsockname_st
  158. {
  159. int sockfd;
  160. struct sockaddr addr;
  161. socklen_t addrlen;
  162. };
  163. #define CONNECT_SOCKARG struct sockaddr *
  164. #define SELECT_SIG int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout
  165. #define IOCTL_SIG int __fd, unsigned long int __request, ...
  166. #define FCNTL_SIG int __fd, int __cmd, ...
  167. #define DAEMON_SIG int nochdir, int noclose
  168. #define SETSOCKOPT_SIG int socket, int level, int option_name, const void *option_value, socklen_t option_len
  169. #define GETSOCKOPT_SIG int sockfd, int level, int optname, void *optval, socklen_t *optlen
  170. #define SYSCALL_SIG long number, ...
  171. #define CLONE_SIG int (*fn)(void *), void *child_stack, int flags, void *arg, ...
  172. #define POLL_SIG struct pollfd *fds, nfds_t nfds, int timeout
  173. #define GETSOCKNAME_SIG int sockfd, struct sockaddr *addr, socklen_t *addrlen
  174. #define DUP2_SIG int oldfd, int newfd
  175. #define DUP3_SIG int oldfd, int newfd, int flags
  176. #endif