netio.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef DROPBEAR_NETIO_H
  2. #define DROPBEAR_NETIO_H
  3. #include "includes.h"
  4. #include "buffer.h"
  5. #include "queue.h"
  6. enum dropbear_prio {
  7. DROPBEAR_PRIO_NORMAL = 0, /* the rest - tcp-fwd, scp, rsync, git, etc */
  8. DROPBEAR_PRIO_LOWDELAY, /* pty shell, x11 */
  9. };
  10. void set_sock_nodelay(int sock);
  11. void set_sock_priority(int sock, enum dropbear_prio prio);
  12. int get_sock_port(int sock);
  13. void get_socket_address(int fd, char **local_host, char **local_port,
  14. char **remote_host, char **remote_port, int host_lookup);
  15. void getaddrstring(struct sockaddr_storage* addr,
  16. char **ret_host, char **ret_port, int host_lookup);
  17. int dropbear_listen(const char* address, const char* port,
  18. int *socks, unsigned int sockcount, char **errstring, int *maxfd);
  19. struct dropbear_progress_connection;
  20. /* result is DROPBEAR_SUCCESS or DROPBEAR_FAILURE.
  21. errstring is only set on DROPBEAR_FAILURE, returns failure message for the last attempted socket */
  22. typedef void(*connect_callback)(int result, int sock, void* data, const char* errstring);
  23. /* Always returns a progress connection, if it fails it will call the callback at a later point */
  24. struct dropbear_progress_connection * connect_remote (const char* remotehost, const char* remoteport,
  25. connect_callback cb, void *cb_data, const char* bind_address, const char* bind_port,
  26. enum dropbear_prio prio);
  27. /* Sets up for select() */
  28. void set_connect_fds(fd_set *writefd);
  29. /* Handles ready sockets after select() */
  30. void handle_connect_fds(const fd_set *writefd);
  31. /* Cleanup */
  32. void remove_connect_pending(void);
  33. /* Doesn't actually stop the connect, but adds a dummy callback instead */
  34. void cancel_connect(struct dropbear_progress_connection *c);
  35. void connect_set_writequeue(struct dropbear_progress_connection *c, struct Queue *writequeue);
  36. /* TODO: writev #ifdef guard */
  37. /* Fills out iov which contains iov_count slots, returning the number filled in iov_count */
  38. void packet_queue_to_iovec(const struct Queue *queue, struct iovec *iov, unsigned int *iov_count);
  39. void packet_queue_consume(struct Queue *queue, ssize_t written);
  40. #if DROPBEAR_SERVER_TCP_FAST_OPEN
  41. /* Try for any Linux builds, will fall back if the kernel doesn't support it */
  42. void set_listen_fast_open(int sock);
  43. /* Define values which may be supported by the kernel even if the libc is too old */
  44. #ifndef TCP_FASTOPEN
  45. #define TCP_FASTOPEN 23
  46. #endif
  47. #ifndef MSG_FASTOPEN
  48. #define MSG_FASTOPEN 0x20000000
  49. #endif
  50. #endif
  51. #endif