Browse code

- tcp alias replace improvement/fix - more debugging fixes

Andrei Pelinescu-Onciul authored on 28/12/2007 20:43:32
Showing 1 changed files
... ...
@@ -1315,7 +1315,10 @@ inline static int _tcpconn_add_alias_unsafe(struct tcp_connection* c, int port,
1315 1315
 	unsigned hash;
1316 1316
 	struct tcp_conn_alias* a;
1317 1317
 	struct tcp_conn_alias* nxt;
1318
+	struct tcp_connection* p;
1318 1319
 	int is_local_ip_any;
1320
+	int i;
1321
+	int r;
1319 1322
 	
1320 1323
 	a=0;
1321 1324
 	is_local_ip_any=ip_addr_any(l_ip);
... ...
@@ -1337,11 +1340,37 @@ inline static int _tcpconn_add_alias_unsafe(struct tcp_connection* c, int port,
1337 1337
 						 * the alias was not already added */
1338 1338
 						continue;
1339 1339
 					else if (flags & TCP_ALIAS_REPLACE){
1340
-						/* remove the current one */
1341
-						tcpconn_listrm(tcpconn_aliases_hash[hash],
1342
-														a, next, prev);
1343
-						a->next=0;
1344
-						a->prev=0;
1340
+						/* remove the alias =>
1341
+						 * remove the current alias and all the following
1342
+						 *  ones from the corresponding connection, shift the 
1343
+						 *  connection aliases array and re-add the other 
1344
+						 *  aliases (!= current one) */
1345
+						p=a->parent;
1346
+						for (i=0; (i<p->aliases) && (&(p->con_aliases[i])!=a);
1347
+								i++);
1348
+						if (unlikely(i==p->aliases)){
1349
+							LOG(L_CRIT, "BUG: _tcpconn_add_alias_unsafe: "
1350
+									" alias %p not found in con %p (id %d)\n",
1351
+									a, p, p->id);
1352
+							goto error_not_found;
1353
+						}
1354
+						for (r=i; r<p->aliases; r++){
1355
+							tcpconn_listrm(
1356
+								tcpconn_aliases_hash[p->con_aliases[r].hash],
1357
+								&p->con_aliases[r], next, prev);
1358
+						}
1359
+						if (likely((i+1)<p->aliases)){
1360
+							memmove(&p->con_aliases[i], &p->con_aliases[i+1],
1361
+											(p->aliases-i-1)*
1362
+												sizeof(p->con_aliases[0]));
1363
+						}
1364
+						p->aliases--;
1365
+						/* re-add the remaining aliases */
1366
+						for (r=i; r<p->aliases; r++){
1367
+							tcpconn_listadd(
1368
+								tcpconn_aliases_hash[p->con_aliases[r].hash], 
1369
+								&p->con_aliases[r], next, prev);
1370
+						}
1345 1371
 					}else
1346 1372
 						goto error_sec;
1347 1373
 				}else goto ok;
... ...
@@ -3218,12 +3247,13 @@ static ticks_t tcpconn_main_timeout(ticks_t t, struct timer_ln* tl, void* data)
3218 3218
 #endif /* TCP_BUF_WRITE */
3219 3219
 	DBG("tcp_main: timeout for %p\n", c);
3220 3220
 	if (likely(c->flags & F_CONN_HASHED)){
3221
-		c->flags&=~F_CONN_HASHED;
3221
+		c->flags&=~(F_CONN_HASHED|F_CONN_MAIN_TIMER);
3222 3222
 		c->state=S_CONN_BAD;
3223 3223
 		TCPCONN_LOCK;
3224 3224
 			_tcpconn_detach(c);
3225 3225
 		TCPCONN_UNLOCK;
3226 3226
 	}else{
3227
+		c->flags&=~F_CONN_MAIN_TIMER;
3227 3228
 		LOG(L_CRIT, "BUG: tcp_main: timer: called with unhashed connection %p"
3228 3229
 				"\n", c);
3229 3230
 		tcpconn_ref(c); /* ugly hack to try to go on */