Files: 26b4bcd089f6c3a3c43d1380969c939e600b3ef2 / common.h
3734 bytesRaw
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | (res == -1) { \ |
27 | perror(str); \ |
28 | exit(1); \ |
29 | } |
30 | |
31 | |
32 | (res == -1) { \ |
33 | log_message(LOG_CRIT, | , str, errno); \
34 | return res; \ |
35 | } |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | enum connection_state { |
46 | ST_PROBING=1, /* Waiting for timeout to find where to forward */ |
47 | ST_SHOVELING /* Connexion is established */ |
48 | }; |
49 | |
50 | typedef int T_PROTO_ID; /* Index into protocols[] array */ |
51 | |
52 | /* For each protocol we need: */ |
53 | struct proto { |
54 | int affected; /* are we actually using it? */ |
55 | char* description; /* a string that says what it is (for logging and command-line parsing) */ |
56 | char* service; /* service name to do libwrap checks */ |
57 | struct addrinfo saddr; /* where to switch that protocol */ |
58 | int (*probe)(const char*, int); /* function to probe that protocol */ |
59 | }; |
60 | |
61 | /* A table in common.c contains all the known protocols */ |
62 | extern struct proto protocols[]; |
63 | extern int num_known_protocols; |
64 | |
65 | /* this is used to pass protocols through the command-line parameter parsing */ |
66 | |
67 | |
68 | /* A 'queue' is composed of a file descriptor (which can be read from or |
69 | * written to), and a queue for defered write data */ |
70 | struct queue { |
71 | int fd; |
72 | void *begin_defered_data; |
73 | void *defered_data; |
74 | int defered_data_size; |
75 | }; |
76 | |
77 | struct connection { |
78 | enum connection_state state; |
79 | time_t probe_timeout; |
80 | |
81 | /* q[0]: queue for external connection (client); |
82 | * q[1]: queue for internal connection (httpd or sshd); |
83 | * */ |
84 | struct queue q[2]; |
85 | }; |
86 | |
87 | |
88 | |
89 | |
90 | |
91 | |
92 | /* common.c */ |
93 | void init_cnx(struct connection *cnx); |
94 | int connect_addr(struct addrinfo *addr, char* cnx_name); |
95 | int fd2fd(struct queue *target, struct queue *from); |
96 | char* sprintaddr(char* buf, size_t size, struct addrinfo *a); |
97 | void resolve_name(struct addrinfo **out, char* fullname); |
98 | T_PROTO_ID probe_client_protocol(struct connection *cnx); |
99 | void log_connection(struct connection *cnx); |
100 | int check_access_rights(int in_socket, char* service); |
101 | void setup_signals(void); |
102 | void setup_syslog(char* bin_name); |
103 | void drop_privileges(char* user_name); |
104 | void write_pid_file(char* pidfile); |
105 | void printsettings(void); |
106 | void parse_cmdline(int argc, char* argv[]); |
107 | void log_message(int type, char* msg, ...); |
108 | void dump_connection(struct connection *cnx); |
109 | |
110 | void append_protocols(struct option *options, int n_opts, struct proto *prot, int n_prots); |
111 | int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list); |
112 | |
113 | int defer_write(struct queue *q, void* data, int data_size); |
114 | int flush_defered(struct queue *q); |
115 | |
116 | extern int probing_timeout, verbose, inetd, foreground, numeric; |
117 | extern struct sockaddr_storage addr_ssl, addr_ssh, addr_openvpn; |
118 | extern struct addrinfo *addr_listen; |
119 | extern const char* USAGE_STRING; |
120 | extern char* user_name, *pid_file; |
121 | extern const char* server_type; |
122 | |
123 | /* sslh-fork.c */ |
124 | void start_shoveler(int); |
125 | |
126 | void main_loop(int *listen_sockets, int num_addr_listen); |
127 |
Built with git-ssb-web