From patchwork Wed Apr 4 12:42:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 1683 Return-Path: Received: from latitanza.investici.org (latitanza.investici.org [82.94.249.234]) by open-mesh.org (Postfix) with ESMTPS id 851836007D8 for ; Wed, 4 Apr 2012 14:41:19 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@autistici.org; dkim-adsp=pass Received: from [82.94.249.234] (latitanza [82.94.249.234]) (Authenticated sender: ordex@autistici.org) by localhost (Postfix) with ESMTPSA id A706B98561; Wed, 4 Apr 2012 12:41:18 +0000 (UTC) X-DKIM: Sendmail DKIM Filter v2.8.2 latitanza.investici.org A706B98561 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1333543279; bh=gl62aLWkOJxKmwM8ortBQ/biNL/k+Wxxp9yTKqzfa6A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=SuS47EsnJIogDyMNipg0b3opQ/MttCSRWZoH06xjG1dHPi+C3nCHDYpWcg0X/09il ywyx2zDJUfXEy0oJ8HyrEWYjuJMEKGyiUBPJx3KcO1Ix8Vi9aWvJox2nSNNiTqgb6M AwXzQ/11LlUCClQv9i6a03LUc1FCJ/aPrXKWxRIc= From: Antonio Quartulli To: b.a.t.m.a.n@lists.open-mesh.org Date: Wed, 4 Apr 2012 14:42:10 +0200 Message-Id: <1333543332-26942-3-git-send-email-ordex@autistici.org> X-Mailer: git-send-email 1.7.9.4 In-Reply-To: <1333543332-26942-1-git-send-email-ordex@autistici.org> References: <1333543332-26942-1-git-send-email-ordex@autistici.org> Subject: [B.A.T.M.A.N.] [PATCHv2 2/4] batman-adv: beautify tt_global_add() argument list X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 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: Wed, 04 Apr 2012 12:41:19 -0000 Instead of adding a new bool argument each time it is needed, it is better (and simpler) to pass an 8bit flag argument which contains all the needed flags Signed-off-by: Antonio Quartulli --- routing.c | 2 +- translation-table.c | 31 +++++++++++++++++-------------- translation-table.h | 3 +-- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/routing.c b/routing.c index 795d3af..2435237 100644 --- a/routing.c +++ b/routing.c @@ -683,7 +683,7 @@ int recv_roam_adv(struct sk_buff *skb, struct hard_iface *recv_if) roam_adv_packet->src, roam_adv_packet->client); tt_global_add(bat_priv, orig_node, roam_adv_packet->client, - atomic_read(&orig_node->last_ttvn) + 1, true, false); + TT_CLIENT_ROAM, atomic_read(&orig_node->last_ttvn) + 1); /* Roaming phase starts: I have new information but the ttvn has not * been incremented yet. This flag will make me check all the incoming diff --git a/translation-table.c b/translation-table.c index 3b728ea..a2c1240 100644 --- a/translation-table.c +++ b/translation-table.c @@ -588,24 +588,22 @@ static void tt_global_add_orig_entry(struct tt_global_entry *tt_global_entry, /* caller must hold orig_node refcount */ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, - const unsigned char *tt_addr, uint8_t ttvn, bool roaming, - bool wifi) + const unsigned char *tt_addr, uint8_t flags, uint8_t ttvn) { struct tt_global_entry *tt_global_entry = NULL; + struct tt_orig_list_entry *orig_entry; int ret = 0; int hash_added; tt_global_entry = tt_global_hash_find(bat_priv, tt_addr); if (!tt_global_entry) { - tt_global_entry = kzalloc(sizeof(*tt_global_entry), - GFP_ATOMIC); + tt_global_entry = kzalloc(sizeof(*tt_global_entry), GFP_ATOMIC); if (!tt_global_entry) goto out; memcpy(tt_global_entry->common.addr, tt_addr, ETH_ALEN); - - tt_global_entry->common.flags = NO_FLAGS; + tt_global_entry->common.flags = flags; tt_global_entry->roam_at = 0; atomic_set(&tt_global_entry->common.refcount, 2); @@ -639,14 +637,19 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, tt_global_entry->roam_at = 0; } - if (!tt_global_entry_has_orig(tt_global_entry, orig_node)) + orig_entry = tt_global_entry_has_orig(tt_global_entry, + orig_node); + if (!orig_entry) tt_global_add_orig_entry(tt_global_entry, orig_node, ttvn); + else + /* if we are "adding" global entry, we may want to + * update the ttvn anyway. Perhaps the global entry is + * here with a wrong ttvn because it was temporary added + * before */ + orig_entry->ttvn = ttvn; } - if (wifi) - tt_global_entry->common.flags |= TT_CLIENT_WIFI; - bat_dbg(DBG_TT, bat_priv, "Creating new global tt entry: %pM (via %pM)\n", tt_global_entry->common.addr, orig_node->orig); @@ -654,7 +657,7 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, out_remove: /* remove address from local hash if present */ tt_local_remove(bat_priv, tt_global_entry->common.addr, - "global tt received", roaming); + "global tt received", flags & TT_CLIENT_ROAM); ret = 1; out: if (tt_global_entry) @@ -1258,7 +1261,7 @@ static int tt_global_valid_entry(const void *entry_ptr, const void *data_ptr) tt_global_entry = container_of(tt_common_entry, struct tt_global_entry, common); - return tt_global_entry_has_orig(tt_global_entry, orig_node); + return (tt_global_entry_has_orig(tt_global_entry, orig_node) != NULL); } static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn, @@ -1665,9 +1668,9 @@ static void _tt_update_changes(struct bat_priv *bat_priv, (tt_change + i)->flags & TT_CLIENT_ROAM); else if (!tt_global_add(bat_priv, orig_node, - (tt_change + i)->addr, ttvn, false, + (tt_change + i)->addr, (tt_change + i)->flags & - TT_CLIENT_WIFI)) + TT_CLIENT_WIFI, ttvn)) /* In case of problem while storing a * global_entry, we stop the updating * procedure without committing the diff --git a/translation-table.h b/translation-table.h index c43374d..3239b72 100644 --- a/translation-table.h +++ b/translation-table.h @@ -34,8 +34,7 @@ int tt_local_seq_print_text(struct seq_file *seq, void *offset); void tt_global_add_orig(struct bat_priv *bat_priv, struct orig_node *orig_node, const unsigned char *tt_buff, int tt_buff_len); int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, - const unsigned char *addr, uint8_t ttvn, bool roaming, - bool wifi); + const unsigned char *addr, uint8_t flags, uint8_t ttvn); int tt_global_seq_print_text(struct seq_file *seq, void *offset); void tt_global_del_orig(struct bat_priv *bat_priv, struct orig_node *orig_node, const char *message);