Skip to content
This repository
Browse code

Whitespace fixes.

  • Loading branch information...
commit 66d9d1cf83fbf0b72ccb2aea8e0a033ba2998dcf 1 parent 10f87b1
Leonid Evdokimov authored July 13, 2008
30  base.c
... ...
@@ -1,5 +1,3 @@
1  
-/* $Id$ */
2  
-
3 1
 #include <sys/types.h>
4 2
 #include <sys/stat.h>
5 3
 #include <fcntl.h>
@@ -118,7 +116,7 @@ static int getdestaddr_ipf(int fd, const struct sockaddr_in *client, const struc
118 116
 	}
119 117
 #endif
120 118
 	if (x < 0) {
121  
-		if (errno != ESRCH) 
  119
+		if (errno != ESRCH)
122 120
 			log_errno(LOG_WARNING, "ioctl(SIOCGNATL)\n");
123 121
 		return -1;
124 122
 	} else {
@@ -196,7 +194,7 @@ int getdestaddr(int fd, const struct sockaddr_in *client, const struct sockaddr_
196 194
 	return instance.redirector->getdestaddr(fd, client, bindaddr, destaddr);
197 195
 }
198 196
 
199  
-static redirector_subsys redirector_subsystems[] = 
  197
+static redirector_subsys redirector_subsystems[] =
200 198
 {
201 199
 #ifdef __FreeBSD__
202 200
 	{ .name = "ipf", .init = redir_init_ipf, .fini = redir_close_private, .getdestaddr = getdestaddr_ipf },
@@ -213,7 +211,7 @@ static redirector_subsys redirector_subsystems[] =
213 211
 /***********************************************************************
214 212
  * `base` config parsing
215 213
  */
216  
-static parser_entry base_entries[] = 
  214
+static parser_entry base_entries[] =
217 215
 {
218 216
 	{ .key = "chroot",     .type = pt_pchar,   .addr = &instance.chroot },
219 217
 	{ .key = "user",       .type = pt_pchar,   .addr = &instance.user },
@@ -239,7 +237,7 @@ static int base_onenter(parser_section *section)
239 237
 static int base_onexit(parser_section *section)
240 238
 {
241 239
 	const char *err = NULL;
242  
-	
  240
+
243 241
 	if (instance.redirector_name) {
244 242
 		redirector_subsys *ss;
245 243
 		FOREACH(ss, redirector_subsystems) {
@@ -255,7 +253,7 @@ static int base_onexit(parser_section *section)
255 253
 	else {
256 254
 		err = "no `redirector` set";
257 255
 	}
258  
-	
  256
+
259 257
 	if (err)
260 258
 		parser_error(section->context, err);
261 259
 
@@ -265,11 +263,11 @@ static int base_onexit(parser_section *section)
265 263
 	return err ? -1 : 0;
266 264
 }
267 265
 
268  
-static parser_section base_conf_section = 
269  
-{ 
270  
-	.name    = "base", 
271  
-	.entries = base_entries, 
272  
-	.onenter = base_onenter, 
  266
+static parser_section base_conf_section =
  267
+{
  268
+	.name    = "base",
  269
+	.entries = base_entries,
  270
+	.onenter = base_onenter,
273 271
 	.onexit  = base_onexit
274 272
 };
275 273
 
@@ -286,7 +284,7 @@ static int base_init()
286 284
 		log_error(LOG_ERR, "there is no configured instance of `base`, check config file");
287 285
 		return -1;
288 286
 	}
289  
-	
  287
+
290 288
 	if (instance.redirector->init && instance.redirector->init() < 0)
291 289
 		return -1;
292 290
 
@@ -309,8 +307,8 @@ static int base_init()
309 307
 	}
310 308
 
311 309
 	if (log_preopen(
312  
-			instance.log_name ? instance.log_name : instance.daemon ? "syslog:daemon" : "stderr", 
313  
-			instance.log_debug, 
  310
+			instance.log_name ? instance.log_name : instance.daemon ? "syslog:daemon" : "stderr",
  311
+			instance.log_debug,
314 312
 			instance.log_info
315 313
 	) < 0 ) {
316 314
 		goto fail;
@@ -392,7 +390,7 @@ static int base_init()
392 390
 	return -1;
393 391
 }
394 392
 
395  
-app_subsys base_subsys = 
  393
+app_subsys base_subsys =
396 394
 {
397 395
 	.init = base_init,
398 396
 	.conf_section = &base_conf_section,
3  base.h
... ...
@@ -1,7 +1,8 @@
1 1
 #ifndef BASE_H_SUN_JUN__3_20_15_57_2007
2 2
 #define BASE_H_SUN_JUN__3_20_15_57_2007
3  
-/* $Id$ */
  3
+
4 4
 int getdestaddr(int fd, const struct sockaddr_in *client, const struct sockaddr_in *bindaddr, struct sockaddr_in *destaddr);
  5
+
5 6
 /* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */
6 7
 /* vim:set foldmethod=marker foldlevel=32 foldmarker={,}: */
7 8
 #endif /* BASE_H_SUN_JUN__3_20_15_57_2007 */
19  http-connect.c
... ...
@@ -1,5 +1,4 @@
1 1
 /** http-connect upstream module for redsocks
2  
- * $Id$ 
3 2
  */
4 3
 
5 4
 #include <assert.h>
@@ -26,10 +25,10 @@ static void httpc_client_init(redsocks_client *client)
26 25
 {
27 26
 	if (client->instance->config.login)
28 27
 		redsocks_log_error(client, LOG_WARNING, "login is ignored for http-connect connections");
29  
-	
  28
+
30 29
 	if (client->instance->config.password)
31 30
 		redsocks_log_error(client, LOG_WARNING, "password is ignored for http-connect connections");
32  
-	
  31
+
33 32
 	client->state = httpc_new;
34 33
 }
35 34
 
@@ -41,6 +40,8 @@ static void httpc_read_cb(struct bufferevent *buffev, void *_arg)
41 40
 
42 41
 	assert(client->state >= httpc_request_sent);
43 42
 
  43
+	redsocks_touch_client(client);
  44
+
44 45
 	if (client->state == httpc_request_sent) {
45 46
 		size_t len = EVBUFFER_LENGTH(buffev->input);
46 47
 		char *line = evbuffer_readline(buffev->input);
@@ -66,7 +67,7 @@ static void httpc_read_cb(struct bufferevent *buffev, void *_arg)
66 67
 
67 68
 	if (dropped)
68 69
 		return;
69  
-	
  70
+
70 71
 	while (client->state == httpc_reply_came) {
71 72
 		char *line = evbuffer_readline(buffev->input);
72 73
 		if (line) {
@@ -96,8 +97,8 @@ static struct evbuffer *httpc_mkconnect(redsocks_client *client)
96 97
 		goto fail;
97 98
 	}
98 99
 
99  
-	len = evbuffer_add_printf(buff, 
100  
-		"CONNECT %s:%u HTTP/1.0\r\n\r\n", 
  100
+	len = evbuffer_add_printf(buff,
  101
+		"CONNECT %s:%u HTTP/1.0\r\n\r\n",
101 102
 		inet_ntoa(client->destaddr.sin_addr),
102 103
 		ntohs(client->destaddr.sin_port)
103 104
 	);
@@ -105,7 +106,7 @@ static struct evbuffer *httpc_mkconnect(redsocks_client *client)
105 106
 		redsocks_log_errno(client, LOG_ERR, "evbufer_add_printf");
106 107
 		goto fail;
107 108
 	}
108  
-	
  109
+
109 110
 	retval = buff;
110 111
 	buff = NULL;
111 112
 
@@ -120,6 +121,8 @@ static void httpc_write_cb(struct bufferevent *buffev, void *_arg)
120 121
 {
121 122
 	redsocks_client *client = _arg;
122 123
 
  124
+	redsocks_touch_client(client);
  125
+
123 126
 	if (client->state == httpc_new) {
124 127
 		redsocks_write_helper_ex(
125 128
 			buffev, client,
@@ -132,7 +135,7 @@ static void httpc_write_cb(struct bufferevent *buffev, void *_arg)
132 135
 }
133 136
 
134 137
 
135  
-relay_subsys http_connect_subsys = 
  138
+relay_subsys http_connect_subsys =
136 139
 {
137 140
 	.name        = "http-connect",
138 141
 	.payload_len = 0,
29  http-relay.c
... ...
@@ -1,5 +1,4 @@
1 1
 /** http-relay upstream module for redsocks
2  
- * $Id$ 
3 2
  */
4 3
 
5 4
 #include <assert.h>
@@ -27,10 +26,10 @@ static void httpr_client_init(redsocks_client *client)
27 26
 
28 27
 	if (client->instance->config.login)
29 28
 		redsocks_log_error(client, LOG_WARNING, "login is ignored for http-relay connections");
30  
-	
  29
+
31 30
 	if (client->instance->config.password)
32 31
 		redsocks_log_error(client, LOG_WARNING, "password is ignored for http-relay connections");
33  
-	
  32
+
34 33
 	client->state = httpr_new;
35 34
 	memset(httpr, 0, sizeof(*httpr));
36 35
 }
@@ -53,6 +52,8 @@ static void httpr_relay_write_cb(struct bufferevent *buffev, void *_arg)
53 52
 
54 53
 	assert(httpr->buff);
55 54
 
  55
+	redsocks_touch_client(client);
  56
+
56 57
 	len = bufferevent_write_buffer(client->relay, httpr->buff);
57 58
 	// free is done either at _start_relay or at _drop_client
58 59
 
@@ -87,7 +88,7 @@ static char *fmt_http_host(struct sockaddr_in addr)
87 88
 	if (ntohs(addr.sin_port) == 80)
88 89
 		return inet_ntoa(addr.sin_addr);
89 90
 	else {
90  
-		snprintf(host, sizeof(host), 
  91
+		snprintf(host, sizeof(host),
91 92
 				"%s:%u",
92 93
 				inet_ntoa(addr.sin_addr),
93 94
 				ntohs(addr.sin_port)
@@ -102,11 +103,11 @@ static int httpr_toss_http_firstline(redsocks_client *client)
102 103
 	char *uri = NULL;
103 104
 	struct evbuffer *buff = NULL;
104 105
 	char *host = fmt_http_host(client->destaddr);
105  
-	
  106
+
106 107
 	assert(httpr->firstline);
107  
-	
  108
+
108 109
 	uri = strchr(httpr->firstline, ' ');
109  
-	if (uri) 
  110
+	if (uri)
110 111
 		uri += 1; // one char further
111 112
 	else {
112 113
 		redsocks_log_error(client, LOG_NOTICE, "malformed request came");
@@ -135,7 +136,7 @@ static int httpr_toss_http_firstline(redsocks_client *client)
135 136
 	evbuffer_free(httpr->buff);
136 137
 	httpr->buff = buff;
137 138
 	return 0;
138  
-	
  139
+
139 140
 addition_fail:
140 141
 	redsocks_log_error(client, LOG_ERR, "evbuffer_add");
141 142
 fail:
@@ -150,7 +151,9 @@ static void httpr_client_read_cb(struct bufferevent *buffev, void *_arg)
150 151
 	httpr_client *httpr = (void*)(client +1);
151 152
 	char *line = NULL;
152 153
 	int connect_relay = 0;
153  
-	
  154
+
  155
+	redsocks_touch_client(client);
  156
+
154 157
 	while ( (line = evbuffer_readline(buffev->input)) && !connect_relay) {
155 158
 		int skip_line = 0;
156 159
 		int do_drop = 0;
@@ -200,7 +203,7 @@ static void httpr_client_read_cb(struct bufferevent *buffev, void *_arg)
200 203
 		if (line && !skip_line)
201 204
 			if (httpr_append_header(client, line) < 0)
202 205
 				do_drop = 1;
203  
-		
  206
+
204 207
 		free(line);
205 208
 
206 209
 		if (do_drop) {
@@ -208,7 +211,7 @@ static void httpr_client_read_cb(struct bufferevent *buffev, void *_arg)
208 211
 			return;
209 212
 		}
210 213
 	}
211  
-	
  214
+
212 215
 	if (connect_relay)
213 216
 		redsocks_connect_relay(client);
214 217
 }
@@ -223,7 +226,7 @@ static void httpr_connect_relay(redsocks_client *client)
223 226
 		redsocks_log_errno(client, LOG_ERR, "evbuffer_new");
224 227
 		redsocks_drop_client(client);
225 228
 	}
226  
-	
  229
+
227 230
 	client->client->readcb = httpr_client_read_cb;
228 231
 	error = bufferevent_enable(client->client, EV_READ);
229 232
 	if (error) {
@@ -232,7 +235,7 @@ static void httpr_connect_relay(redsocks_client *client)
232 235
 	}
233 236
 }
234 237
 
235  
-relay_subsys http_relay_subsys = 
  238
+relay_subsys http_relay_subsys =
236 239
 {
237 240
 	.name          = "http-relay",
238 241
 	.payload_len   = sizeof(httpr_client),
2  list.h
... ...
@@ -1,7 +1,7 @@
1 1
 #ifndef _LINUX_LIST_H
2 2
 #define _LINUX_LIST_H
3 3
 /** That's taken from linux-2.6.18.2 source tree with light modifications
4  
- * I don't know what copyright to place here but that's GPLv2 code so 
  4
+ * I don't know what copyright to place here but that's GPLv2 code so
5 5
  * I assume I'm free to reuse it.
6 6
  */
7 7
 #include "utils.h" // container_of
8  log.c
... ...
@@ -1,5 +1,3 @@
1  
-/* $Id$ */
2  
-
3 1
 #include <stdio.h>
4 2
 #include <string.h>
5 3
 #include <errno.h>
@@ -60,7 +58,7 @@ int log_preopen(const char *dst, bool log_debug, bool log_info)
60 58
 			{ "local7", LOG_LOCAL7 },
61 59
 		};
62 60
 
63  
-		FOREACH(ptpl, tpl) 
  61
+		FOREACH(ptpl, tpl)
64 62
 			if (strcmp(facility_name, ptpl->name) == 0) {
65 63
 				facility = ptpl->value;
66 64
 				break;
@@ -71,7 +69,7 @@ int log_preopen(const char *dst, bool log_debug, bool log_info)
71 69
 		}
72 70
 
73 71
 		openlog("redsocks", LOG_NDELAY | LOG_PID, facility);
74  
-		
  72
+
75 73
 		logmask = setlogmask(0);
76 74
 		if (!log_debug)
77 75
 			logmask &= ~(LOG_MASK(LOG_DEBUG));
@@ -104,7 +102,7 @@ void _log_vwrite(const char *file, int line, const char *func, int do_errno, int
104 102
 		evbuffer_add_vprintf(buff, fmt, ap);
105 103
 		message = buff->buffer;
106 104
 	}
107  
-	else 
  105
+	else
108 106
 		message = lowmem;
109 107
 
110 108
 	log_msg(file, line, func, priority, message, do_errno ? strerror(saved_errno) : NULL);
2  log.h
... ...
@@ -1,6 +1,6 @@
1 1
 #ifndef LOG_H_WED_JAN_24_18_21_27_2007
2 2
 #define LOG_H_WED_JAN_24_18_21_27_2007
3  
-/* $Id$ */
  3
+
4 4
 #include <stdarg.h>
5 5
 #include <stdbool.h>
6 6
 #include <syslog.h>
8  main.c
... ...
@@ -1,5 +1,3 @@
1  
-/* $Id$ */
2  
-
3 1
 #include <sys/time.h>
4 2
 #include <sys/types.h>
5 3
 #include <stdlib.h>
@@ -44,14 +42,14 @@ int main(int argc, char **argv)
44 42
 			return EXIT_FAILURE;
45 43
 		}
46 44
 	}
47  
-	
  45
+
48 46
 
49 47
 	FILE *f = fopen(confname, "r");
50 48
 	if (!f) {
51 49
 		perror("Unable to open config file");
52 50
 		return EXIT_FAILURE;
53 51
 	}
54  
-	
  52
+
55 53
 	parser_context* parser = parser_start(f, NULL);
56 54
 	if (!parser) {
57 55
 		perror("Not enough memory for parser");
@@ -83,7 +81,7 @@ int main(int argc, char **argv)
83 81
 			return EXIT_FAILURE;
84 82
 		}
85 83
 	}
86  
-		
  84
+
87 85
 	log_error(LOG_NOTICE, "redsocks started");
88 86
 
89 87
 	event_dispatch();
1  main.h
... ...
@@ -1,6 +1,5 @@
1 1
 #ifndef MAIN_H_TUE_JAN_23_15_38_25_2007
2 2
 #define MAIN_H_TUE_JAN_23_15_38_25_2007
3  
-/* $Id$ */
4 3
 
5 4
 #include "parser.h"
6 5
 
26  parser.c
... ...
@@ -1,5 +1,3 @@
1  
-/* $Id$ */
2  
-
3 1
 #include <stdlib.h>
4 2
 #include <stdio.h>
5 3
 #include <ctype.h>
@@ -88,7 +86,7 @@ static char *gettoken(parser_context *context, char **iter)
88 86
 {
89 87
 	char *ret = NULL;
90 88
 	size_t len = 0;
91  
-	enum { 
  89
+	enum {
92 90
 		gt_cstr,
93 91
 		gt_plainstr
94 92
 	} copytype;
@@ -139,10 +137,10 @@ static char *gettoken(parser_context *context, char **iter)
139 137
 					p++;
140 138
 				else if (p[1] == '/' || p[1] == '*') // comment token is coming!
141 139
 					break;
142  
-				else 
  140
+				else
143 141
 					return NULL;
144 142
 			}
145  
-			else 
  143
+			else
146 144
 				break;
147 145
 		}
148 146
 		len = p - *iter;
@@ -168,7 +166,7 @@ static char *gettoken(parser_context *context, char **iter)
168 166
 		copytype = gt_plainstr;
169 167
 		len = 2;
170 168
 	}
171  
-	
  169
+
172 170
 	ret = malloc(len + 1);
173 171
 	if (!ret) {
174 172
 		parser_error(context, "malloc failed");
@@ -200,7 +198,7 @@ static char *gettoken(parser_context *context, char **iter)
200 198
 		*iter += len;
201 199
 		ret[len] = 0;
202 200
 	}
203  
-			
  201
+
204 202
 	return ret;
205 203
 }
206 204
 
@@ -227,13 +225,13 @@ static int vp_pbool(parser_context *context, void *addr, const char *token)
227 225
 			*(bool*)addr = true;
228 226
 			return 0;
229 227
 		}
230  
-	
  228
+
231 229
 	FOREACH(tpl, strfalse)
232 230
 		if (strcmp(token, *tpl) == 0) {
233 231
 			*(bool*)addr = false;
234 232
 			return 0;
235 233
 		}
236  
-	
  234
+
237 235
 	parser_error(context, "boolean is not parsed");
238 236
 	return -1;
239 237
 }
@@ -294,7 +292,7 @@ static int vp_in_addr2(parser_context *context, void *addr, const char *token)
294 292
 		*mask = '\0';
295 293
 		mask++;
296 294
 	}
297  
-	
  295
+
298 296
 	if (inet_aton(host, &ia)) {
299 297
 		memcpy(addr, &ia, sizeof(ia));
300 298
 	}
@@ -329,7 +327,7 @@ static int vp_in_addr2(parser_context *context, void *addr, const char *token)
329 327
 	return retval;
330 328
 }
331 329
 
332  
-static value_parser value_parser_by_type[] = 
  330
+static value_parser value_parser_by_type[] =
333 331
 {
334 332
 	[pt_bool] = vp_pbool,
335 333
 	[pt_pchar] = vp_pchar,
@@ -347,7 +345,7 @@ int parser_run(parser_context *context)
347 345
 	bool need_more_data  = true;
348 346
 	while ( !context->error && !feof(context->fd) ) {
349 347
 		assert(context->buffer.filled < context->buffer.size); // ``<`` and not ``<=``
350  
-		
  348
+
351 349
 		if (need_more_space) {
352 350
 			char *new = realloc(context->buffer.data, context->buffer.size * 2);
353 351
 			if (!new) {
@@ -358,7 +356,7 @@ int parser_run(parser_context *context)
358 356
 			context->buffer.size *= 2;
359 357
 			need_more_space = false;
360 358
 		}
361  
-		
  359
+
362 360
 		if (need_more_data) { // read one line per call
363 361
 			char *sbegin = context->buffer.data + context->buffer.filled;
364 362
 			int len;
@@ -367,7 +365,7 @@ int parser_run(parser_context *context)
367 365
 					parser_error(context, "file read failure");
368 366
 					return -1;
369 367
 				}
370  
-				else 
  368
+				else
371 369
 					continue;
372 370
 			}
373 371
 			len = strlen(sbegin);
1  parser.h
... ...
@@ -1,6 +1,5 @@
1 1
 #ifndef PARSER_H_THU_JAN_11_04_49_38_2007
2 2
 #define PARSER_H_THU_JAN_11_04_49_38_2007
3  
-/* $Id$ */
4 3
 
5 4
 #include <stdio.h>
6 5
 #include <stdbool.h>
8  reddns.c
... ...
@@ -1,5 +1,3 @@
1  
-/* $Id$ */
2  
-
3 1
 #include <arpa/inet.h>
4 2
 #include <stdlib.h>
5 3
 #include <string.h>
@@ -30,13 +28,13 @@ int reddns_onenter(parser_section *section)
30 28
 int reddns_onexit(parser_section *section)
31 29
 {
32 30
 	reddns_config *conf = section->data;
33  
-	fprintf(stderr, 
  31
+	fprintf(stderr,
34 32
 			"%s {\n"
35 33
 			"local_port = %u;\n"
36 34
 			"fakeip_net = %s/%s;\n"
37 35
 			"ip = %s;\n"
38 36
 			"port = %u;\n"
39  
-			"}\n", 
  37
+			"}\n",
40 38
 			__FUNCTION__,
41 39
 			conf->bindaddr.sin_port,
42 40
 			strdup(inet_ntoa(conf->fakenet)),
@@ -64,7 +62,7 @@ parser_section reddns_conf_section = {
64 62
 };
65 63
 
66 64
 int reddns_init() {
67  
-	return 0;	
  65
+	return 0;
68 66
 }
69 67
 
70 68
 int reddns_fini() {
108  redsocks.c
... ...
@@ -1,5 +1,3 @@
1  
-/* $Id$ */
2  
-
3 1
 #include <arpa/inet.h>
4 2
 #include <stdlib.h>
5 3
 #include <string.h>
@@ -33,7 +31,7 @@ static int fcntl_nonblock(int fd)
33 31
 {
34 32
 	int error;
35 33
 	int flags;
36  
-   
  34
+
37 35
 	flags = fcntl(fd, F_GETFL);
38 36
 	if (flags == -1)
39 37
 		return -1;
@@ -49,7 +47,7 @@ extern relay_subsys http_connect_subsys;
49 47
 extern relay_subsys http_relay_subsys;
50 48
 extern relay_subsys socks4_subsys;
51 49
 extern relay_subsys socks5_subsys;
52  
-static relay_subsys *relay_subsystems[] = 
  50
+static relay_subsys *relay_subsystems[] =
53 51
 {
54 52
 	&http_connect_subsys,
55 53
 	&http_relay_subsys,
@@ -57,12 +55,12 @@ static relay_subsys *relay_subsystems[] =
57 55
 	&socks5_subsys,
58 56
 };
59 57
 
60  
-static redsocks_instance instance = 
  58
+static redsocks_instance instance =
61 59
 { // almost NULL-initializer
62 60
 	.clients = LIST_HEAD_INIT(instance.clients)
63 61
 };
64 62
 
65  
-static parser_entry redsocks_entries[] = 
  63
+static parser_entry redsocks_entries[] =
66 64
 {
67 65
 	{ .key = "local_ip",   .type = pt_in_addr, .addr = &instance.config.bindaddr.sin_addr },
68 66
 	{ .key = "local_port", .type = pt_uint16,  .addr = &instance.config.bindaddr.sin_port },
@@ -92,7 +90,7 @@ static int redsocks_onexit(parser_section *section)
92 90
 	const char *err = NULL;
93 91
 	instance.config.bindaddr.sin_port = htons(instance.config.bindaddr.sin_port);
94 92
 	instance.config.relayaddr.sin_port = htons(instance.config.relayaddr.sin_port);
95  
-	
  93
+
96 94
 	if (instance.config.type) {
97 95
 		relay_subsys **ss;
98 96
 		FOREACH(ss, relay_subsystems) {
@@ -107,23 +105,23 @@ static int redsocks_onexit(parser_section *section)
107 105
 	else {
108 106
 		err = "no `type` for redsocks";
109 107
 	}
110  
-	
  108
+
111 109
 	if (err)
112 110
 		parser_error(section->context, err);
113 111
 
114 112
 	return err ? -1 : 0;
115 113
 }
116 114
 
117  
-static parser_section redsocks_conf_section = 
118  
-{ 
119  
-	.name    = "redsocks", 
120  
-	.entries = redsocks_entries, 
121  
-	.onenter = redsocks_onenter, 
  115
+static parser_section redsocks_conf_section =
  116
+{
  117
+	.name    = "redsocks",
  118
+	.entries = redsocks_entries,
  119
+	.onenter = redsocks_onenter,
122 120
 	.onexit  = redsocks_onexit
123 121
 };
124 122
 
125 123
 void redsocks_log_write(
126  
-		const char *file, int line, const char *func, int do_errno, 
  124
+		const char *file, int line, const char *func, int do_errno,
127 125
 		redsocks_client *client, int priority, const char *orig_fmt, ...
128 126
 ) {
129 127
 	int saved_errno = errno;
@@ -142,7 +140,7 @@ void redsocks_log_write(
142 140
 		strncpy(destaddr_str, "???", sizeof(destaddr_str));
143 141
 
144 142
 	if (fmt) {
145  
-		evbuffer_add_printf(fmt, "[%s:%i->%s:%i]: %s", 
  143
+		evbuffer_add_printf(fmt, "[%s:%i->%s:%i]: %s",
146 144
 				clientaddr_str, ntohs(client->clientaddr.sin_port),
147 145
 				destaddr_str, ntohs(client->destaddr.sin_port),
148 146
 				orig_fmt);
@@ -157,6 +155,22 @@ void redsocks_log_write(
157 155
 	va_end(ap);
158 156
 }
159 157
 
  158
+static time_t redsocks_time(time_t *t)
  159
+{
  160
+	time_t retval;
  161
+	retval = time(t);
  162
+	if (retval == ((time_t) -1))
  163
+		log_errno(LOG_WARNING, "time");
  164
+	return retval;
  165
+}
  166
+
  167
+
  168
+void redsocks_touch_client(redsocks_client *client)
  169
+{
  170
+	redsocks_time(&client->last_event);
  171
+}
  172
+
  173
+
160 174
 static void redsocks_relay_readcb(redsocks_client *client, struct bufferevent *from, struct bufferevent *to)
161 175
 {
162 176
 	if (EVBUFFER_LENGTH(to->output) < to->wm_write.high) {
@@ -189,31 +203,35 @@ static void redsocks_relay_writecb(redsocks_client *client, struct bufferevent *
189 203
 static void redsocks_relay_relayreadcb(struct bufferevent *from, void *_client)
190 204
 {
191 205
 	redsocks_client *client = _client;
  206
+	redsocks_touch_client(client);
192 207
 	redsocks_relay_readcb(client, client->relay, client->client);
193 208
 }
194 209
 
195 210
 static void redsocks_relay_relaywritecb(struct bufferevent *to, void *_client)
196 211
 {
197 212
 	redsocks_client *client = _client;
  213
+	redsocks_touch_client(client);
198 214
 	redsocks_relay_writecb(client, client->client, client->relay);
199 215
 }
200 216
 
201 217
 static void redsocks_relay_clientreadcb(struct bufferevent *from, void *_client)
202 218
 {
203 219
 	redsocks_client *client = _client;
  220
+	redsocks_touch_client(client);
204 221
 	redsocks_relay_readcb(client, client->client, client->relay);
205 222
 }
206 223
 
207 224
 static void redsocks_relay_clientwritecb(struct bufferevent *to, void *_client)
208 225
 {
209 226
 	redsocks_client *client = _client;
  227
+	redsocks_touch_client(client);
210 228
 	redsocks_relay_writecb(client, client->relay, client->client);
211 229
 }
212 230
 
213 231
 void redsocks_start_relay(redsocks_client *client)
214 232
 {
215 233
 	int error;
216  
-	
  234
+
217 235
 	if (client->instance->relay_ss->fini)
218 236
 		client->instance->relay_ss->fini(client);
219 237
 
@@ -225,12 +243,12 @@ void redsocks_start_relay(redsocks_client *client)
225 243
 	client->relay->wm_write.high = REDSOCKS_RELAY_HALFBUFF;
226 244
 	client->client->wm_read.high = REDSOCKS_RELAY_HALFBUFF;
227 245
 	client->client->wm_write.high = REDSOCKS_RELAY_HALFBUFF;
228  
-	
  246
+
229 247
 	client->client->readcb = redsocks_relay_clientreadcb;
230 248
 	client->client->writecb = redsocks_relay_clientwritecb;
231 249
 	client->relay->readcb = redsocks_relay_relayreadcb;
232 250
 	client->relay->writecb = redsocks_relay_relaywritecb;
233  
-	
  251
+
234 252
 	error = bufferevent_enable(client->client, EV_READ | EV_WRITE);
235 253
 	if (!error)
236 254
 		error = bufferevent_enable(client->relay, EV_READ | EV_WRITE);
@@ -260,7 +278,7 @@ void redsocks_drop_client(redsocks_client *client)
260 278
 		close(EVENT_FD(&client->relay->ev_write));
261 279
 		bufferevent_free(client->relay);
262 280
 	}
263  
-	
  281
+
264 282
 	list_del(&client->list);
265 283
 	free(client);
266 284
 }
@@ -294,7 +312,7 @@ static void redsocks_shutdown(redsocks_client *client, struct bufferevent *buffe
294 312
 	strev = buffev == client->client ? "client" : "relay";
295 313
 	pevshut = buffev == client->client ? &client->client_evshut : &client->relay_evshut;
296 314
 
297  
-	// if EV_WRITE is already shut and we're going to shutdown read then 
  315
+	// if EV_WRITE is already shut and we're going to shutdown read then
298 316
 	// we're either going to abort data flow (bad behaviour) or confirm EOF
299 317
 	// and in this case socket is already SHUT_RD'ed
300 318
 	if ( !(how == SHUT_RD && (*pevshut & EV_WRITE)) )
@@ -334,6 +352,8 @@ static void redsocks_event_error(struct bufferevent *buffev, short what, void *_
334 352
 	redsocks_client *client = _arg;
335 353
 	assert(buffev == client->relay || buffev == client->client);
336 354
 
  355
+	redsocks_touch_client(client);
  356
+
337 357
 	if (what == (EVBUFFER_READ|EVBUFFER_EOF)) {
338 358
 		struct bufferevent *antiev;
339 359
 		if (buffev == client->relay)
@@ -360,12 +380,12 @@ static void redsocks_event_error(struct bufferevent *buffev, short what, void *_
360 380
 	}
361 381
 }
362 382
 
363  
-int sizes_equal(size_t a, size_t b) 
  383
+int sizes_equal(size_t a, size_t b)
364 384
 {
365 385
 	return a == b;
366 386
 }
367 387
 
368  
-int sizes_greater_equal(size_t a, size_t b) 
  388
+int sizes_greater_equal(size_t a, size_t b)
369 389
 {
370 390
 	return a >= b;
371 391
 }
@@ -416,12 +436,12 @@ void redsocks_write_helper_ex(
416 436
 	int len;
417 437
 	struct evbuffer *buff = NULL;
418 438
 	int drop = 1;
419  
-	
  439
+
420 440
 	if (mkmessage) {
421 441
 		buff = mkmessage(client);
422 442
 		if (!buff)
423 443
 			goto fail;
424  
-		
  444
+
425 445
 		len = bufferevent_write_buffer(client->relay, buff);
426 446
 		if (len < 0) {
427 447
 			redsocks_log_errno(client, LOG_ERR, "bufferevent_write_buffer");
@@ -434,7 +454,7 @@ void redsocks_write_helper_ex(
434 454
 	buffev->wm_read.high = wm_high;
435 455
 	bufferevent_enable(buffev, EV_READ);
436 456
 	drop = 0;
437  
-	
  457
+
438 458
 fail:
439 459
 	if (buff)
440 460
 		evbuffer_free(buff);
@@ -456,9 +476,13 @@ static void redsocks_relay_connected(struct bufferevent *buffev, void *_arg)
456 476
 
457 477
 	assert(buffev == client->relay);
458 478
 
  479
+	redsocks_touch_client(client);
  480
+
459 481
 	pseudo_errno = redsocks_socket_geterrno(client, buffev);
460  
-	if (pseudo_errno == -1)
  482
+	if (pseudo_errno == -1) {
  483
+		redsocks_log_errno(client, LOG_NOTICE, "redsocks_socket_geterrno");
461 484
 		goto fail;
  485
+	}
462 486
 
463 487
 	if (pseudo_errno) {
464 488
 		errno = pseudo_errno;
@@ -472,7 +496,7 @@ static void redsocks_relay_connected(struct bufferevent *buffev, void *_arg)
472 496
 	return;
473 497
 
474 498
 fail:
475  
-	redsocks_event_error(buffev, EVBUFFER_WRITE | EVBUFFER_ERROR, _arg);
  499
+	redsocks_drop_client(client);
476 500
 }
477 501
 
478 502
 void redsocks_connect_relay(redsocks_client *client)
@@ -528,7 +552,7 @@ static void redsocks_accept_client(int fd, short what, void *_arg)
528 552
 	socklen_t          addrlen = sizeof(clientaddr);
529 553
 	int client_fd = -1;
530 554
 	int error;
531  
-	
  555
+
532 556
 	// working with client_fd
533 557
 	client_fd = accept(fd, (struct sockaddr*)&clientaddr, &addrlen);
534 558
 	if (client_fd == -1) {
@@ -552,7 +576,12 @@ static void redsocks_accept_client(int fd, short what, void *_arg)
552 576
 	memcpy(&client->destaddr, &destaddr, sizeof(destaddr));
553 577
 	INIT_LIST_HEAD(&client->list);
554 578
 	self->relay_ss->init(client);
555  
-	
  579
+
  580
+	if (redsocks_time(&client->first_event) == ((time_t)-1))
  581
+		goto fail;
  582
+
  583
+	redsocks_touch_client(client);
  584
+
556 585
 	client->client = bufferevent_new(client_fd, NULL, NULL, redsocks_event_error, client);
557 586
 	if (!client->client) {
558 587
 		log_errno(LOG_ERR, "bufferevent_new");
@@ -567,9 +596,9 @@ static void redsocks_accept_client(int fd, short what, void *_arg)
567 596
 		redsocks_log_errno(client, LOG_ERR, "bufferevent_enable");
568 597
 		goto fail;
569 598
 	}
570  
-	
  599
+
571 600
 	redsocks_log_error(client, LOG_INFO, "accepted");
572  
-	
  601
+
573 602
 	if (self->relay_ss->connect_relay)
574 603
 		self->relay_ss->connect_relay(client);
575 604
 	else
@@ -587,8 +616,8 @@ static void redsocks_accept_client(int fd, short what, void *_arg)
587 616
 
588 617
 static const char *redsocks_evshut_str(unsigned short evshut)
589 618
 {
590  
-	return 
591  
-		evshut == EV_READ ? "SHUT_RD" : 
  619
+	return
  620
+		evshut == EV_READ ? "SHUT_RD" :
592 621
 		evshut == EV_WRITE ? "SHUT_WR" :
593 622
 		evshut == (EV_READ|EV_WRITE) ? "SHUT_RDWR" :
594 623
 		evshut == 0 ? "" :
@@ -599,15 +628,18 @@ static void redsocks_debug_dump(int sig, short what, void *_arg)
599 628
 {
600 629
 	redsocks_instance *self = _arg;
601 630
 	redsocks_client *client = NULL;
602  
-	
  631
+	time_t now = redsocks_time(NULL);
  632
+
603 633
 	log_error(LOG_DEBUG, "Dumping client list:");
604 634
 	list_for_each_entry(client, &self->clients, list) {
605 635
 		const char *s_client_evshut = redsocks_evshut_str(client->client_evshut);
606 636
 		const char *s_relay_evshut = redsocks_evshut_str(client->relay_evshut);
607 637
 
608  
-		redsocks_log_error(client, LOG_DEBUG, "client: %i%s%s, relay: %i%s%s",
  638
+		redsocks_log_error(client, LOG_DEBUG, "client: %i%s%s, relay: %i%s%s, age: %i sec, idle: %i sec.",
609 639
 			EVENT_FD(&client->client->ev_write), s_client_evshut[0] ? " " : "", s_client_evshut,
610  
-			EVENT_FD(&client->relay->ev_write), s_relay_evshut[0] ? " " : "", s_relay_evshut);
  640
+			EVENT_FD(&client->relay->ev_write), s_relay_evshut[0] ? " " : "", s_relay_evshut,
  641
+			now - client->first_event,
  642
+			now - client->last_event);
611 643
 	}
612 644
 	log_error(LOG_DEBUG, "End of client list.");
613 645
 }
@@ -669,7 +701,7 @@ static int redsocks_init()
669 701
 		log_errno(LOG_ERR, "event_add");
670 702
 		goto fail;
671 703
 	}
672  
-	
  704
+
673 705
 	return 0;
674 706
 fail:
675 707
 	if (signal_initialized(&instance.debug_dumper)) {
@@ -701,7 +733,7 @@ static int redsocks_fini()
701 733
 	return 0;
702 734
 }
703 735
 
704  
-app_subsys redsocks_subsys = 
  736
+app_subsys redsocks_subsys =
705 737
 {
706 738
 	.init = redsocks_init,
707 739
 	.fini = redsocks_fini,
7  redsocks.h
... ...
@@ -1,7 +1,5 @@
1 1
 #ifndef REDSOCKS_H_WED_JAN_24_22_17_11_2007
2 2
 #define REDSOCKS_H_WED_JAN_24_22_17_11_2007
3  
-/* $Id$ */
4  
-
5 3
 #include <sys/time.h>
6 4
 #include <sys/types.h>
7 5
 #include <arpa/inet.h>
@@ -54,17 +52,20 @@ typedef struct redsocks_client_t {
54 52
 	int                 state;         // it's used by bottom layer
55 53
 	unsigned short      client_evshut;
56 54
 	unsigned short      relay_evshut;
  55
+	time_t              first_event;
  56
+	time_t              last_event;
57 57
 } redsocks_client;
58 58
 
59 59
 
60 60
 void redsocks_drop_client(redsocks_client *client);
  61
+void redsocks_touch_client(redsocks_client *client);
61 62
 void redsocks_connect_relay(redsocks_client *client);
62 63
 void redsocks_start_relay(redsocks_client *client);
63 64
 
64 65
 typedef int (*size_comparator)(size_t a, size_t b);
65 66
 int sizes_equal(size_t a, size_t b);
66 67
 int sizes_greater_equal(size_t a, size_t b);
67  
-/** helper for functions when we expect ONLY reply of some size and anything else is error 
  68
+/** helper for functions when we expect ONLY reply of some size and anything else is error
68 69
  */
69 70
 int redsocks_read_expected(redsocks_client *client, struct evbuffer *input, void *data, size_comparator comparator, size_t expected);
70 71
 
10  socks4.c
... ...
@@ -1,5 +1,3 @@
1  
-/* $Id$ */
2  
-
3 1
 #include <stdlib.h>
4 2
 #include <string.h>
5 3
 #include <assert.h>
@@ -42,7 +40,7 @@ void socks4_client_init(redsocks_client *client)
42 40
 {
43 41
 	if (client->instance->config.password)
44 42
 		redsocks_log_error(client, LOG_WARNING, "password is ignored for socks4 connections");
45  
-	
  43
+
46 44
 	client->state = socks4_new;
47 45
 }
48 46
 
@@ -53,6 +51,8 @@ static void socks4_read_cb(struct bufferevent *buffev, void *_arg)
53 51
 
54 52
 	assert(client->state >= socks4_request_sent);
55 53
 
  54
+	redsocks_touch_client(client);
  55
+
56 56
 	if (client->state == socks4_request_sent) {
57 57
 		socks4_reply reply;
58 58
 
@@ -100,6 +100,8 @@ static void socks4_write_cb(struct bufferevent *buffev, void *_arg)
100 100
 {
101 101
 	redsocks_client *client = _arg;
102 102
 
  103
+	redsocks_touch_client(client);
  104
+
103 105
 	if (client->state == socks4_new) {
104 106
 		redsocks_write_helper(
105 107
 			buffev, client,
@@ -112,7 +114,7 @@ static void socks4_write_cb(struct bufferevent *buffev, void *_arg)
112 114
 }
113 115
 
114 116
 
115  
-relay_subsys socks4_subsys = 
  117
+relay_subsys socks4_subsys =
116 118
 {
117 119
 	.name        = "socks4",
118 120
 	.payload_len = 0,
14  socks5.c
... ...
@@ -1,5 +1,3 @@
1  
-/* $Id$ */
2  
-
3 1
 #include <stdlib.h>
4 2
 #include <string.h>
5 3
 #include <assert.h>
@@ -99,7 +97,7 @@ const int socks5_status_Command_not_supported = 7;
99 97
 const int socks5_status_Address_type_not_supported = 8;
100 98
 
101 99
 const char *socks5_strstatus[] = {
102  
-	"ok", 
  100
+	"ok",
103 101
 	"server failure",
104 102
 	"connection not allowed by ruleset",
105 103
 	"network unreachable",
@@ -153,7 +151,7 @@ static struct evbuffer *socks5_mkpassword(redsocks_client *client)
153 151
 	size_t plen = strlen(password);
154 152
 	size_t length =  1 /* version */ + 1 + ulen + 1 + plen;
155 153
 	uint8_t req[length];
156  
-	
  154
+
157 155
 	req[0] = socks5_password_ver; // RFC 1929 says so
158 156
 	req[1] = ulen;
159 157
 	memcpy(&req[2], login, ulen);
@@ -182,6 +180,8 @@ static void socks5_write_cb(struct bufferevent *buffev, void *_arg)
182 180
 {
183 181
 	redsocks_client *client = _arg;
184 182
 
  183
+	redsocks_touch_client(client);
  184
+
185 185
 	if (client->state == socks5_new) {
186 186
 		redsocks_write_helper(
187 187
 			buffev, client,
@@ -196,7 +196,7 @@ static void socks5_read_auth_methods(struct bufferevent *buffev, redsocks_client
196 196
 
197 197
 	if (redsocks_read_expected(client, buffev->input, &reply, sizes_equal, sizeof(reply)) < 0)
198 198
 		return;
199  
-		
  199
+
200 200
 	if (reply.ver != socks5_ver) {
201 201
 		redsocks_log_error(client, LOG_NOTICE, "Socks5 server reported unexpected auth methods reply version...");
202 202
 		redsocks_drop_client(client);
@@ -287,6 +287,8 @@ static void socks5_read_cb(struct bufferevent *buffev, void *_arg)
287 287
 	redsocks_client *client = _arg;
288 288
 	socks5_client *socks5 = (void*)(client + 1);
289 289
 
  290
+	redsocks_touch_client(client);
  291
+
290 292
 	if (client->state == socks5_method_sent) {
291 293
 		socks5_read_auth_methods(buffev, client, socks5);
292 294
 	}
@@ -318,7 +320,7 @@ static void socks5_read_cb(struct bufferevent *buffev, void *_arg)
318 320
 	}
319 321
 }
320 322
 
321  
-relay_subsys socks5_subsys = 
  323
+relay_subsys socks5_subsys =
322 324
 {
323 325
 	.name        = "socks5",
324 326
 	.payload_len = sizeof(socks5_client),

0 notes on commit 66d9d1c

Please sign in to comment.
Something went wrong with that request. Please try again.