The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 1 | #ifndef _LIBSLIRP_H |
| 2 | #define _LIBSLIRP_H |
| 3 | |
| 4 | #include <stdint.h> |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 5 | #include <stdio.h> |
David 'Digit' Turner | cc330d4 | 2013-12-14 23:26:42 +0100 | [diff] [blame] | 6 | #include "android/sockets.h" |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 7 | #include "slirp.h" |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 8 | #ifdef _WIN32 |
| 9 | # define WIN32_LEAN_AND_MEAN |
| 10 | # define socket_close winsock2_socket_close3 |
| 11 | # include <winsock2.h> |
| 12 | # undef socket_close |
| 13 | #else |
| 14 | # include <sys/select.h> |
| 15 | #endif |
| 16 | |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 21 | struct mbuf; |
| 22 | |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 23 | int inet_strtoip(const char* str, uint32_t *ip); |
| 24 | char* inet_iptostr(uint32_t ip); |
| 25 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 26 | void slirp_init(int restricted, const char *special_ip); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 27 | |
| 28 | void slirp_select_fill(int *pnfds, |
| 29 | fd_set *readfds, fd_set *writefds, fd_set *xfds); |
| 30 | |
| 31 | void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds); |
| 32 | |
| 33 | void slirp_input(const uint8_t *pkt, int pkt_len); |
| 34 | |
| 35 | /* you must provide the following functions: */ |
| 36 | int slirp_can_output(void); |
| 37 | void slirp_output(const uint8_t *pkt, int pkt_len); |
| 38 | |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 39 | /* ---------------------------------------------------*/ |
| 40 | /* User mode network stack restrictions */ |
| 41 | void slirp_drop_udp(); |
| 42 | void slirp_drop_tcp(); |
| 43 | void slirp_add_allow(unsigned long dst_addr, int dst_lport, |
| 44 | int dst_hport, u_int8_t proto); |
| 45 | void slirp_drop_log_fd(FILE* fd); |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 46 | |
| 47 | /** Get the drop log fd */ |
| 48 | FILE* get_slirp_drop_log_fd(void); |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 49 | int slirp_should_drop(unsigned long dst_addr, |
| 50 | int dst_port, |
| 51 | u_int8_t proto); |
| 52 | int slirp_drop_log(const char* format, ...); |
| 53 | |
| 54 | /* for network forwards */ |
| 55 | void slirp_add_net_forward(unsigned long dest_ip, unsigned long dest_mask, |
| 56 | int dest_lport, int dest_hport, |
| 57 | unsigned long redirect_ip, int redirect_port); |
| 58 | |
| 59 | int slirp_should_net_forward(unsigned long remote_ip, int remote_port, |
| 60 | unsigned long *redirect_ip, int *redirect_port); |
| 61 | /* ---------------------------------------------------*/ |
| 62 | |
| 63 | /** |
| 64 | * Additional network stack modifications, aiming to detect and log |
| 65 | * any network activity initiated by any binary outisde the context of |
| 66 | * the running browser. |
| 67 | */ |
| 68 | |
| 69 | void slirp_dns_log_fd(FILE* fd); |
rich cannings | d952f28 | 2011-03-01 15:40:09 -0800 | [diff] [blame] | 70 | /** Get the dns log fd */ |
| 71 | FILE* get_slirp_dns_log_fd(void); |
rich cannings | 7339b55 | 2011-02-16 13:43:44 -0800 | [diff] [blame] | 72 | /** Logs the DNS name in DNS query issued by the VM. */ |
| 73 | int slirp_log_dns(struct mbuf* m, int dropped); |
| 74 | /** IP packet dump of DNS queris and responses. */ |
| 75 | int slirp_dump_dns(struct mbuf* m); |
| 76 | /** Sets an upper limit for the number of allowed DNS requests from |
| 77 | * the VM. |
| 78 | */ |
| 79 | void slirp_set_max_dns_conns(int max_dns_conns); |
| 80 | /* Returns the max number of allowed DNS requests.*/ |
| 81 | int slirp_get_max_dns_conns(); |
| 82 | |
| 83 | /** |
| 84 | * Modifications for implementing "-net-forward-tcp2sink' option. |
| 85 | */ |
| 86 | |
| 87 | void slirp_forward_dropped_tcp2sink(unsigned long sink_ip, int sink_port); |
| 88 | int slirp_should_forward_dropped_tcp2sink(); |
| 89 | unsigned long slirp_get_tcp_sink_ip(); |
| 90 | int slirp_get_tcp_sink_port(); |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | /* ---------------------------------------------------*/ |
| 96 | |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 97 | void slirp_redir_loop(void (*func)(void *opaque, int is_udp, |
| 98 | const SockAddress *laddr, |
| 99 | const SockAddress *faddr), |
| 100 | void *opaque); |
| 101 | int slirp_redir_rm(int is_udp, int host_port); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 102 | int slirp_redir(int is_udp, int host_port, |
| 103 | uint32_t guest_addr, int guest_port); |
| 104 | |
| 105 | int slirp_unredir(int is_udp, int host_port); |
| 106 | |
| 107 | int slirp_add_dns_server(const SockAddress* dns_addr); |
| 108 | int slirp_get_system_dns_servers(void); |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 109 | int slirp_add_exec(int do_pty, const void *args, int addr_low_byte, |
| 110 | int guest_port); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 111 | |
| 112 | extern const char *tftp_prefix; |
| 113 | extern char slirp_hostname[33]; |
David 'Digit' Turner | 5d8f37a | 2009-09-14 14:32:27 -0700 | [diff] [blame] | 114 | extern const char *bootp_filename; |
| 115 | |
| 116 | void slirp_stats(void); |
| 117 | void slirp_socket_recv(int addr_low_byte, int guest_port, const uint8_t *buf, |
| 118 | int size); |
| 119 | size_t slirp_socket_can_recv(int addr_low_byte, int guest_port); |
The Android Open Source Project | 8b23a6c | 2009-03-03 19:30:32 -0800 | [diff] [blame] | 120 | |
| 121 | #ifdef __cplusplus |
| 122 | } |
| 123 | #endif |
| 124 | |
| 125 | #endif |