load-tester: Fix race condition issuing same identity

Due to an unprotected incrementation, two load-tester initiators occasionally
use the same identifier under high load. The responder typically drops one of
the connections.

Use an atomic incrementation to avoid this race condition.

Signed-off-by: Christophe Gouault <[email protected]>
This commit is contained in:
Christophe Gouault
2014-04-24 17:54:15 +02:00
committed by Tobias Brunner
parent a68454bd68
commit 2cbaa63295
@@ -150,7 +150,7 @@ struct private_load_tester_config_t {
/** /**
* incremental numbering of generated configs * incremental numbering of generated configs
*/ */
u_int num; refcount_t num;
/** /**
* Dynamic source port, if used * Dynamic source port, if used
@@ -802,7 +802,7 @@ METHOD(backend_t, get_peer_cfg_by_name, peer_cfg_t*,
{ {
if (streq(name, "load-test")) if (streq(name, "load-test"))
{ {
return generate_config(this, this->num++); return generate_config(this, (u_int)ref_get(&this->num));
} }
return NULL; return NULL;
} }