aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorAntonio Quartulli <antonio@open-mesh.com>2013-09-02 06:15:04 -0400
committerAntonio Quartulli <antonio@meshcoding.com>2013-10-23 09:33:10 -0400
commita3285a8f20dace536ecc6a2f349150ea1d0bb391 (patch)
treed4cd1de827c780d4226d5f9b2f5018d5edd6a4ed /net
parent737a2a229774ef983ef783149384bae3e3aa38ac (diff)
batman-adv: add bat_neigh_cmp API function
This new API allows to compare the two neighbours based on the metric avoiding the user to deal with any routing algorithm specific detail Signed-off-by: Antonio Quartulli <antonio@open-mesh.com> Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net')
-rw-r--r--net/batman-adv/bat_iv_ogm.c20
-rw-r--r--net/batman-adv/main.c3
-rw-r--r--net/batman-adv/types.h3
3 files changed, 25 insertions, 1 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 4aabd554ca75..b288d90855d1 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -1475,6 +1475,25 @@ next:
1475 seq_puts(seq, "No batman nodes in range ...\n"); 1475 seq_puts(seq, "No batman nodes in range ...\n");
1476} 1476}
1477 1477
1478/**
1479 * batadv_iv_ogm_neigh_cmp - compare the metrics of two neighbors
1480 * @neigh1: the first neighbor object of the comparison
1481 * @neigh2: the second neighbor object of the comparison
1482 *
1483 * Returns a value less, equal to or greater than 0 if the metric via neigh1 is
1484 * lower, the same as or higher than the metric via neigh2
1485 */
1486static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1,
1487 struct batadv_neigh_node *neigh2)
1488{
1489 uint8_t tq1, tq2;
1490
1491 tq1 = neigh1->bat_iv.tq_avg;
1492 tq2 = neigh2->bat_iv.tq_avg;
1493
1494 return tq1 - tq2;
1495}
1496
1478static struct batadv_algo_ops batadv_batman_iv __read_mostly = { 1497static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
1479 .name = "BATMAN_IV", 1498 .name = "BATMAN_IV",
1480 .bat_iface_enable = batadv_iv_ogm_iface_enable, 1499 .bat_iface_enable = batadv_iv_ogm_iface_enable,
@@ -1483,6 +1502,7 @@ static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
1483 .bat_primary_iface_set = batadv_iv_ogm_primary_iface_set, 1502 .bat_primary_iface_set = batadv_iv_ogm_primary_iface_set,
1484 .bat_ogm_schedule = batadv_iv_ogm_schedule, 1503 .bat_ogm_schedule = batadv_iv_ogm_schedule,
1485 .bat_ogm_emit = batadv_iv_ogm_emit, 1504 .bat_ogm_emit = batadv_iv_ogm_emit,
1505 .bat_neigh_cmp = batadv_iv_ogm_neigh_cmp,
1486 .bat_orig_print = batadv_iv_ogm_orig_print, 1506 .bat_orig_print = batadv_iv_ogm_orig_print,
1487}; 1507};
1488 1508
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 3159a148c1ac..1f2f1ac67a4c 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -501,7 +501,8 @@ int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
501 !bat_algo_ops->bat_iface_update_mac || 501 !bat_algo_ops->bat_iface_update_mac ||
502 !bat_algo_ops->bat_primary_iface_set || 502 !bat_algo_ops->bat_primary_iface_set ||
503 !bat_algo_ops->bat_ogm_schedule || 503 !bat_algo_ops->bat_ogm_schedule ||
504 !bat_algo_ops->bat_ogm_emit) { 504 !bat_algo_ops->bat_ogm_emit ||
505 !bat_algo_ops->bat_neigh_cmp) {
505 pr_info("Routing algo '%s' does not implement required ops\n", 506 pr_info("Routing algo '%s' does not implement required ops\n",
506 bat_algo_ops->name); 507 bat_algo_ops->name);
507 ret = -EINVAL; 508 ret = -EINVAL;
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 72fd617b2e73..7a00932a55bd 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -992,6 +992,7 @@ struct batadv_forw_packet {
992 * @bat_primary_iface_set: called when primary interface is selected / changed 992 * @bat_primary_iface_set: called when primary interface is selected / changed
993 * @bat_ogm_schedule: prepare a new outgoing OGM for the send queue 993 * @bat_ogm_schedule: prepare a new outgoing OGM for the send queue
994 * @bat_ogm_emit: send scheduled OGM 994 * @bat_ogm_emit: send scheduled OGM
995 * @bat_neigh_cmp: compare the metrics of two neighbors
995 * @bat_orig_print: print the originator table (optional) 996 * @bat_orig_print: print the originator table (optional)
996 */ 997 */
997struct batadv_algo_ops { 998struct batadv_algo_ops {
@@ -1003,6 +1004,8 @@ struct batadv_algo_ops {
1003 void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface); 1004 void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
1004 void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface); 1005 void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
1005 void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet); 1006 void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
1007 int (*bat_neigh_cmp)(struct batadv_neigh_node *neigh1,
1008 struct batadv_neigh_node *neigh2);
1006 /* orig_node handling API */ 1009 /* orig_node handling API */
1007 void (*bat_orig_print)(struct batadv_priv *priv, struct seq_file *seq); 1010 void (*bat_orig_print)(struct batadv_priv *priv, struct seq_file *seq);
1008}; 1011};