Browse code

tcp: fix connection alias replacing

When the TCP_ALIAS_REPLACE is set and an alias has to be added to
a connection that had 0 aliases (it can happen due to
TCP_ALIAS_REPLACE flag), the connection aliases count was wrongly
forced to 1.
For more details see:
http://lists.sip-router.org/pipermail/sr-users/2012-October/074932.html

Patch-by Jijo

Andrei Pelinescu-Onciul authored on 10/10/2012 08:02:00
Showing 1 changed files
... ...
@@ -1339,11 +1339,14 @@ int tcpconn_finish_connect( struct tcp_connection* c,
1339 1339
 			/* remove all the aliases except the first one and re-add them
1340 1340
 			 * (there shouldn't be more then the 3 default aliases at this 
1341 1341
 			 * stage) */
1342
-			for (r=1; r<c->aliases; r++){
1343
-				a=&c->con_aliases[r];
1344
-				tcpconn_listrm(tcpconn_aliases_hash[a->hash], a, next, prev);
1342
+			if (c->aliases > 1) {
1343
+				for (r=1; r<c->aliases; r++){
1344
+					a=&c->con_aliases[r];
1345
+					tcpconn_listrm(tcpconn_aliases_hash[a->hash],
1346
+									a, next, prev);
1347
+				}
1348
+				c->aliases=1;
1345 1349
 			}
1346
-			c->aliases=1;
1347 1350
 			/* add the local_ip:0 and local_ip:local_port aliases */
1348 1351
 			_tcpconn_add_alias_unsafe(c, c->rcv.src_port, &c->rcv.dst_ip,
1349 1352
 												0, new_conn_alias_flags);