Intercept.h 5.0 KB

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