From patchwork Thu Oct 30 05:23:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Linus_L=C3=BCssing?= X-Patchwork-Id: 4194 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=188.40.49.9; helo=mail.passe0815.de; envelope-from=linus.luessing@c0d3.blue; receiver=b.a.t.m.a.n@lists.open-mesh.org Received: from mail.passe0815.de (mail.passe0815.de [188.40.49.9]) by open-mesh.org (Postfix) with ESMTP id 24FC9600E1F for ; Thu, 30 Oct 2014 06:23:56 +0100 (CET) Received: from mail.passe0815.de (localhost [127.0.0.1]) by mail.passe0815.de (Postfix) with ESMTP id 5D81F585E5E for ; Thu, 30 Oct 2014 06:23:56 +0100 (CET) Received: from localhost (unknown [46.246.43.148]) by mail.passe0815.de (Postfix) with ESMTPSA id A0555585E3D; Thu, 30 Oct 2014 06:23:54 +0100 (CET) From: =?UTF-8?q?Linus=20L=C3=BCssing?= To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 30 Oct 2014 06:23:40 +0100 Message-Id: <1414646620-6022-1-git-send-email-linus.luessing@c0d3.blue> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-GPG-Mailgate: Not encrypted, public key not found X-Mailman-Approved-At: Sat, 01 Nov 2014 12:59:25 +0100 Subject: [B.A.T.M.A.N.] [PATCH] batman-adv: fix delayed foreign originator recognition X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Oct 2014 05:23:56 -0000 Currently it can happen that the reception of an OGM from a new originator is not being accepted. More precisely it can happen that an originator struct gets allocated and initialized (batadv_orig_node_new()), even the TQ gets calculated and set correctly (batadv_iv_ogm_calc_tq()) but still the periodic orig_node purging thread will decide to delete it if it has a chance to jump between these two function calls. This is because batadv_orig_node_new() initializes the last_seen value to zero and its caller (batadv_iv_ogm_orig_get()) makes it visible to other threads by adding it to the hash table already. batadv_iv_ogm_calc_tq() will set the last_seen variable to the correct, current time a few lines later but if the purging thread jumps in between that it will think that the orig_node timed out and will wrongly schedule it for deletion already. If the purging interval is the same as the originator interval (which is the default: 1 second), then this game can continue for several rounds until the random OGM jitter added enough difference between these two (in tests, two to about four rounds seemed common). Fixing this by initializing the last_seen variable of an orig_node to the current time before adding it to the hash table. Signed-off-by: Linus Lüssing --- originator.c | 1 + 1 file changed, 1 insertion(+) diff --git a/originator.c b/originator.c index 6a48451..648bdba 100644 --- a/originator.c +++ b/originator.c @@ -678,6 +678,7 @@ struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv, atomic_set(&orig_node->last_ttvn, 0); orig_node->tt_buff = NULL; orig_node->tt_buff_len = 0; + orig_node->last_seen = jiffies; reset_time = jiffies - 1 - msecs_to_jiffies(BATADV_RESET_PROTECTION_MS); orig_node->bcast_seqno_reset = reset_time; #ifdef CONFIG_BATMAN_ADV_MCAST