seq_puts(seq, "No batman nodes in range ...\n");
 }
 
+/**
+ * batadv_iv_ogm_neigh_cmp - compare the metrics of two neighbors
+ * @neigh1: the first neighbor object of the comparison
+ * @neigh2: the second neighbor object of the comparison
+ *
+ * Returns a value less, equal to or greater than 0 if the metric via neigh1 is
+ * lower, the same as or higher than the metric via neigh2
+ */
+static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1,
+                                  struct batadv_neigh_node *neigh2)
+{
+       uint8_t tq1, tq2;
+
+       tq1 = neigh1->bat_iv.tq_avg;
+       tq2 = neigh2->bat_iv.tq_avg;
+
+       return tq1 - tq2;
+}
+
 static struct batadv_algo_ops batadv_batman_iv __read_mostly = {
        .name = "BATMAN_IV",
        .bat_iface_enable = batadv_iv_ogm_iface_enable,
        .bat_primary_iface_set = batadv_iv_ogm_primary_iface_set,
        .bat_ogm_schedule = batadv_iv_ogm_schedule,
        .bat_ogm_emit = batadv_iv_ogm_emit,
+       .bat_neigh_cmp = batadv_iv_ogm_neigh_cmp,
        .bat_orig_print = batadv_iv_ogm_orig_print,
 };
 
 
            !bat_algo_ops->bat_iface_update_mac ||
            !bat_algo_ops->bat_primary_iface_set ||
            !bat_algo_ops->bat_ogm_schedule ||
-           !bat_algo_ops->bat_ogm_emit) {
+           !bat_algo_ops->bat_ogm_emit ||
+           !bat_algo_ops->bat_neigh_cmp) {
                pr_info("Routing algo '%s' does not implement required ops\n",
                        bat_algo_ops->name);
                ret = -EINVAL;
 
  * @bat_primary_iface_set: called when primary interface is selected / changed
  * @bat_ogm_schedule: prepare a new outgoing OGM for the send queue
  * @bat_ogm_emit: send scheduled OGM
+ * @bat_neigh_cmp: compare the metrics of two neighbors
  * @bat_orig_print: print the originator table (optional)
  */
 struct batadv_algo_ops {
        void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
        void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
        void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
+       int (*bat_neigh_cmp)(struct batadv_neigh_node *neigh1,
+                            struct batadv_neigh_node *neigh2);
        /* orig_node handling API */
        void (*bat_orig_print)(struct batadv_priv *priv, struct seq_file *seq);
 };