netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Antonio Quartulli <antonio@meshcoding.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
	Antonio Quartulli <antonio@open-mesh.com>,
	Marek Lindner <lindner_marek@yahoo.de>
Subject: [PATCH 09/16] batman-adv: adapt the TT component to use the new API functions
Date: Wed, 23 Oct 2013 18:04:56 +0200	[thread overview]
Message-ID: <1382544303-2694-10-git-send-email-antonio@meshcoding.com> (raw)
In-Reply-To: <1382544303-2694-1-git-send-email-antonio@meshcoding.com>

From: Antonio Quartulli <antonio@open-mesh.com>

Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
 net/batman-adv/translation-table.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 1d5a4f5..4c28251 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1280,18 +1280,20 @@ out:
 }
 
 /* batadv_transtable_best_orig - Get best originator list entry from tt entry
+ * @bat_priv: the bat priv with all the soft interface information
  * @tt_global_entry: global translation table entry to be analyzed
  *
  * This functon assumes the caller holds rcu_read_lock().
  * Returns best originator list entry or NULL on errors.
  */
 static struct batadv_tt_orig_list_entry *
-batadv_transtable_best_orig(struct batadv_tt_global_entry *tt_global_entry)
+batadv_transtable_best_orig(struct batadv_priv *bat_priv,
+			    struct batadv_tt_global_entry *tt_global_entry)
 {
-	struct batadv_neigh_node *router = NULL;
+	struct batadv_neigh_node *router, *best_router = NULL;
+	struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;
 	struct hlist_head *head;
 	struct batadv_tt_orig_list_entry *orig_entry, *best_entry = NULL;
-	int best_tq = 0;
 
 	head = &tt_global_entry->orig_list;
 	hlist_for_each_entry_rcu(orig_entry, head, list) {
@@ -1299,26 +1301,37 @@ batadv_transtable_best_orig(struct batadv_tt_global_entry *tt_global_entry)
 		if (!router)
 			continue;
 
-		if (router->bat_iv.tq_avg > best_tq) {
-			best_entry = orig_entry;
-			best_tq = router->bat_iv.tq_avg;
+		if (best_router &&
+		    bao->bat_neigh_cmp(router, best_router) <= 0) {
+			batadv_neigh_node_free_ref(router);
+			continue;
 		}
 
-		batadv_neigh_node_free_ref(router);
+		/* release the refcount for the "old" best */
+		if (best_router)
+			batadv_neigh_node_free_ref(best_router);
+
+		best_entry = orig_entry;
+		best_router = router;
 	}
 
+	if (best_router)
+		batadv_neigh_node_free_ref(best_router);
+
 	return best_entry;
 }
 
 /* batadv_tt_global_print_entry - print all orig nodes who announce the address
  * for this global entry
+ * @bat_priv: the bat priv with all the soft interface information
  * @tt_global_entry: global translation table entry to be printed
  * @seq: debugfs table seq_file struct
  *
  * This functon assumes the caller holds rcu_read_lock().
  */
 static void
-batadv_tt_global_print_entry(struct batadv_tt_global_entry *tt_global_entry,
+batadv_tt_global_print_entry(struct batadv_priv *bat_priv,
+			     struct batadv_tt_global_entry *tt_global_entry,
 			     struct seq_file *seq)
 {
 	struct batadv_tt_orig_list_entry *orig_entry, *best_entry;
@@ -1331,7 +1344,7 @@ batadv_tt_global_print_entry(struct batadv_tt_global_entry *tt_global_entry,
 	tt_common_entry = &tt_global_entry->common;
 	flags = tt_common_entry->flags;
 
-	best_entry = batadv_transtable_best_orig(tt_global_entry);
+	best_entry = batadv_transtable_best_orig(bat_priv, tt_global_entry);
 	if (best_entry) {
 		vlan = batadv_orig_node_vlan_get(best_entry->orig_node,
 						 tt_common_entry->vid);
@@ -1420,7 +1433,7 @@ int batadv_tt_global_seq_print_text(struct seq_file *seq, void *offset)
 			tt_global = container_of(tt_common_entry,
 						 struct batadv_tt_global_entry,
 						 common);
-			batadv_tt_global_print_entry(tt_global, seq);
+			batadv_tt_global_print_entry(bat_priv, tt_global, seq);
 		}
 		rcu_read_unlock();
 	}
@@ -1808,7 +1821,7 @@ struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,
 		goto out;
 
 	rcu_read_lock();
-	best_entry = batadv_transtable_best_orig(tt_global_entry);
+	best_entry = batadv_transtable_best_orig(bat_priv, tt_global_entry);
 	/* found anything? */
 	if (best_entry)
 		orig_node = best_entry->orig_node;
-- 
1.8.4

  parent reply	other threads:[~2013-10-23 16:05 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-23 16:04 pull request: batman-adv 2013-10-23 Antonio Quartulli
2013-10-23 16:04 ` [PATCH 02/16] batman-adv: make struct batadv_orig_node algorithm agnostic Antonio Quartulli
2013-10-23 16:04 ` [PATCH 03/16] batman-adv: add bat_orig_print API function Antonio Quartulli
2013-10-23 17:00   ` Joe Perches
2013-10-23 17:18     ` Antonio Quartulli
     [not found]       ` <20131023171810.GB2651-rVWd3aGhH2zPj3vggD0kEA@public.gmane.org>
2013-10-23 17:27         ` Joe Perches
2013-10-23 17:37           ` Antonio Quartulli
2013-10-23 16:04 ` [PATCH 04/16] batman-adv: add bat_neigh_cmp " Antonio Quartulli
2013-10-23 16:04 ` [PATCH 05/16] batman-adv: add bat_neigh_is_equiv_or_better " Antonio Quartulli
2013-10-23 16:04 ` [PATCH 06/16] batman-adv: adapt bonding to use the new API functions Antonio Quartulli
2013-10-23 16:04 ` [PATCH 07/16] batman-adv: adapt the neighbor purging routine " Antonio Quartulli
2013-10-23 16:04 ` [PATCH 08/16] batman-adv: provide orig_node routing API Antonio Quartulli
2013-10-23 16:04 ` Antonio Quartulli [this message]
2013-10-23 16:04 ` [PATCH 10/16] batman-adv: limit local translation table max size Antonio Quartulli
2013-10-23 16:04 ` [PATCH 11/16] batman-adv: send GW_DEL event in case of soft-iface destruction Antonio Quartulli
2013-10-23 16:04 ` [PATCH 12/16] batman-adv: invoke dev_get_by_index() outside of is_wifi_iface() Antonio Quartulli
     [not found] ` <1382544303-2694-1-git-send-email-antonio-x4xJYDvStAgysxA8WJXlww@public.gmane.org>
2013-10-23 16:04   ` [PATCH 01/16] batman-adv: make struct batadv_neigh_node algorithm agnostic Antonio Quartulli
2013-10-23 16:05   ` [PATCH 13/16] batman-adv: improve the TT component to support runtime flag changes Antonio Quartulli
2013-10-23 16:05 ` [PATCH 14/16] batman-adv: include the sync-flags when compute the global/local table CRC Antonio Quartulli
2013-10-23 16:05 ` [PATCH 15/16] batman-adv: Start new development cycle Antonio Quartulli
2013-10-23 16:05 ` [PATCH 16/16] batman-adv: generalize batman-adv icmp packet handling Antonio Quartulli
2013-10-23 21:13 ` pull request: batman-adv 2013-10-23 David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1382544303-2694-10-git-send-email-antonio@meshcoding.com \
    --to=antonio@meshcoding.com \
    --cc=antonio@open-mesh.com \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=lindner_marek@yahoo.de \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).