From 3863f882469117afd6a2ad7ce25711b619f43b27 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 25 Sep 2008 17:05:50 +0200 Subject: ftfw: fix race that triggers a double insertion into tx_list This patch fixes a race condition that can trigger a double insertion to the tx_list. This happens if we receive two resync request very close or resync just after a nack or vice-versa. Signed-off-by: Pablo Neira Ayuso --- src/sync-ftfw.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sync-ftfw.c b/src/sync-ftfw.c index 4c1b536..8dd5554 100644 --- a/src/sync-ftfw.c +++ b/src/sync-ftfw.c @@ -196,6 +196,10 @@ static int do_cache_to_tx(void *data1, void *data2) struct us_conntrack *u = data2; struct cache_ftfw *cn = cache_get_extra(STATE_SYNC(internal), u); + /* repeated request for resync? */ + if (!list_empty(&cn->tx_list)) + return 0; + /* add to tx list */ list_add_tail(&cn->tx_list, &tx_list); tx_list_len++; @@ -264,8 +268,11 @@ static void rs_list_to_tx(struct cache *c, unsigned int from, unsigned int to) dp("resending nack'ed (oldseq=%u)\n", cn->seq); list_del_init(&cn->rs_list); rs_list_len--; - list_add_tail(&cn->tx_list, &tx_list); - tx_list_len++; + /* we received a request for resync before this nack? */ + if (list_empty(&cn->tx_list)) { + list_add_tail(&cn->tx_list, &tx_list); + tx_list_len++; + } write_evfd(STATE_SYNC(evfd)); } } -- cgit v1.2.3