Intercept.h 5.2 KB

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