[B.A.T.M.A.N.] [PATCH 06/10] batman-adv: Adding ndp debugfs output

Linus Lüssing linus.luessing at ascom.ch
Fri Dec 31 16:46:21 CET 2010


Lists all neighbours and their tq/rq values detected and measured by the
Neighbor Discovery Protocol (NDP).

Signed-off-by: Linus Lüssing <linus.luessing at ascom.ch>
---
 bat_debugfs.c |    9 ++++++++
 ndp.c         |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ndp.h         |    1 +
 3 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/bat_debugfs.c b/bat_debugfs.c
index 0ae81d0..602aa15 100644
--- a/bat_debugfs.c
+++ b/bat_debugfs.c
@@ -25,6 +25,7 @@
 
 #include "bat_debugfs.h"
 #include "translation-table.h"
+#include "ndp.h"
 #include "originator.h"
 #include "hard-interface.h"
 #include "gateway_common.h"
@@ -222,6 +223,12 @@ static void debug_log_cleanup(struct bat_priv *bat_priv)
 }
 #endif
 
+static int neighbors_open(struct inode *inode, struct file *file)
+{
+	struct net_device *net_dev = (struct net_device *)inode->i_private;
+	return single_open(file, ndp_seq_print_text, net_dev);
+}
+
 static int originators_open(struct inode *inode, struct file *file)
 {
 	struct net_device *net_dev = (struct net_device *)inode->i_private;
@@ -275,6 +282,7 @@ struct bat_debuginfo bat_debuginfo_##_name = {	\
 		}				\
 };
 
+static BAT_DEBUGINFO(neighbors, S_IRUGO, neighbors_open);
 static BAT_DEBUGINFO(originators, S_IRUGO, originators_open);
 static BAT_DEBUGINFO(gateways, S_IRUGO, gateways_open);
 static BAT_DEBUGINFO(softif_neigh, S_IRUGO, softif_neigh_open);
@@ -283,6 +291,7 @@ static BAT_DEBUGINFO(transtable_local, S_IRUGO, transtable_local_open);
 static BAT_DEBUGINFO(vis_data, S_IRUGO, vis_data_open);
 
 static struct bat_debuginfo *mesh_debuginfos[] = {
+	&bat_debuginfo_neighbors,
 	&bat_debuginfo_originators,
 	&bat_debuginfo_gateways,
 	&bat_debuginfo_softif_neigh,
diff --git a/ndp.c b/ndp.c
index dbb0e9e..9f498f9 100644
--- a/ndp.c
+++ b/ndp.c
@@ -275,3 +275,63 @@ ret:
 	spin_unlock_bh(&batman_if->neigh_list_lock);
 	return ret;
 }
+
+int ndp_seq_print_text(struct seq_file *seq, void *offset)
+{
+	struct neigh_node *neigh_node;
+	struct batman_if *batman_if;
+	struct hlist_node *node;
+	int last_seen_secs;
+	int last_seen_msecs;
+	int batman_count = 0;
+	struct net_device *net_dev = (struct net_device *)seq->private;
+	struct bat_priv *bat_priv = netdev_priv(net_dev);
+
+	if ((!bat_priv->primary_if) ||
+	    (bat_priv->primary_if->if_status != IF_ACTIVE)) {
+		if (!bat_priv->primary_if)
+			return seq_printf(seq, "BATMAN mesh %s disabled - "
+				    "please specify interfaces to enable it\n",
+				    net_dev->name);
+
+		return seq_printf(seq, "BATMAN mesh %s "
+				  "disabled - primary interface not active\n",
+				  net_dev->name);
+	}
+
+	seq_printf(seq, "[B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%pM (%s)]\n",
+		   SOURCE_VERSION, REVISION_VERSION_STR,
+		   bat_priv->primary_if->net_dev->name,
+		   bat_priv->primary_if->net_dev->dev_addr, net_dev->name);
+	seq_printf(seq, "  %-15s %s (%s/%i) [%10s]\n",
+		   "Neighbor", "last-seen", "#TQ,#RQ", TQ_MAX_VALUE, "IF");
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(batman_if, &if_list, list) {
+		if (batman_if->if_status != IF_ACTIVE)
+			continue;
+
+		spin_lock_bh(&batman_if->neigh_list_lock);
+		hlist_for_each_entry(neigh_node, node, &batman_if->neigh_list,
+				    list) {
+			last_seen_secs = jiffies_to_msecs(jiffies -
+						neigh_node->last_valid) / 1000;
+			last_seen_msecs = jiffies_to_msecs(jiffies -
+						neigh_node->last_valid) % 1000;
+
+			seq_printf(seq, "%pM %4i.%03is     (%3i,%3i) [%10s]\n",
+				   neigh_node->addr, last_seen_secs,
+				   last_seen_msecs, neigh_node->tq_avg,
+				   neigh_node->rq, batman_if->net_dev->name);
+
+			batman_count++;
+		}
+		spin_unlock_bh(&batman_if->neigh_list_lock);
+	}
+	rcu_read_unlock();
+
+	if ((batman_count == 0))
+		seq_printf(seq, "No batman nodes in range ...\n");
+
+	return 0;
+}
diff --git a/ndp.h b/ndp.h
index a828362..f528bcf 100644
--- a/ndp.h
+++ b/ndp.h
@@ -32,5 +32,6 @@ uint8_t ndp_fetch_tq(struct batman_packet_ndp *packet,
 void ndp_purge_neighbors(void);
 int ndp_update_neighbor(uint8_t my_tq, uint32_t seqno,
 			struct batman_if *batman_if, uint8_t *neigh_addr);
+int ndp_seq_print_text(struct seq_file *seq, void *offset);
 
 #endif /* _NET_BATMAN_ADV_NDP_H_ */
-- 
1.7.1



More information about the B.A.T.M.A.N mailing list