All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Linus Lüssing" <linus.luessing@web.de>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCHv2 3/3] batctl: add unicast/multicast address filter option for TT output
Date: Sun,  2 Mar 2014 23:18:02 +0100	[thread overview]
Message-ID: <1393798682-7703-4-git-send-email-linus.luessing@web.de> (raw)
In-Reply-To: <1393798682-7703-1-git-send-email-linus.luessing@web.de>

This patch adds the new "-u" and "-m" options for the local and global
translation table output to only display announced unicast or multicast
mac addresses to enhance readability.

Signed-off-by: Linus Lüssing <linus.luessing@web.de>
---
 debug.c      |   32 +++++++++++++++++++++++++++++++-
 functions.c  |   22 ++++++++++++++++++++++
 functions.h  |    2 ++
 man/batctl.8 |    2 ++
 4 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/debug.c b/debug.c
index 6836857..acf452b 100644
--- a/debug.c
+++ b/debug.c
@@ -91,6 +91,10 @@ static void debug_table_usage(int debug_table)
 
 	if (debug_table == BATCTL_TABLE_ORIGINATORS)
 		fprintf(stderr, " \t -t timeout interval - don't print originators not seen for x.y seconds \n");
+	if (debug_table == BATCTL_TABLE_TRANSLOCAL ||
+	    debug_table == BATCTL_TABLE_TRANSGLOBAL) {
+		fprintf(stderr, " \t -u|-m print unicast or multicast mac addresses only\n");
+	}
 }
 
 int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
@@ -102,7 +106,7 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 	float watch_interval = 1;
 	opterr = 0;
 
-	while ((optchar = getopt(argc, argv, "hnw:t:H")) != -1) {
+	while ((optchar = getopt(argc, argv, "hnw:t:Hum")) != -1) {
 		switch (optchar) {
 		case 'h':
 			debug_table_usage(debug_table);
@@ -138,6 +142,26 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 		case 'H':
 			read_opt |= SKIP_HEADER;
 			break;
+		case 'u':
+			if (debug_table != BATCTL_TABLE_TRANSLOCAL &&
+			    debug_table != BATCTL_TABLE_TRANSGLOBAL) {
+				fprintf(stderr, "Error - unrecognised option '-%c'\n", optchar);
+				debug_table_usage(debug_table);
+				return EXIT_FAILURE;
+			}
+
+			read_opt |= UNICAST_ONLY;
+			break;
+		case 'm':
+			if (debug_table != BATCTL_TABLE_TRANSLOCAL &&
+			    debug_table != BATCTL_TABLE_TRANSGLOBAL) {
+				fprintf(stderr, "Error - unrecognised option '-%c'\n", optchar);
+				debug_table_usage(debug_table);
+				return EXIT_FAILURE;
+			}
+
+			read_opt |= MULTICAST_ONLY;
+			break;
 		case '?':
 			if (optopt == 't')
 				fprintf(stderr, "Error - option '-t' needs a number as argument\n");
@@ -156,6 +180,12 @@ int handle_debug_table(char *mesh_iface, int debug_table, int argc, char **argv)
 		}
 	}
 
+	if (read_opt & UNICAST_ONLY && read_opt & MULTICAST_ONLY) {
+		fprintf(stderr, "Error - '-u' and '-m' are exclusive options\n");
+		debug_table_usage(debug_table);
+		return EXIT_FAILURE;
+	}
+
 	debugfs_mnt = debugfs_mount(NULL);
 	if (!debugfs_mnt) {
 		fprintf(stderr, "Error - can't mount or find debugfs\n");
diff --git a/functions.c b/functions.c
index 36804bd..117dcff 100644
--- a/functions.c
+++ b/functions.c
@@ -175,6 +175,14 @@ static void file_open_problem_dbg(const char *dir, const char *fname,
 	}
 }
 
+static int str_is_mcast_addr(char *addr)
+{
+	struct ether_addr *mac_addr = ether_aton(addr);
+
+	return !mac_addr ? 0 :
+		mac_addr->ether_addr_octet[0] & 0x01;
+}
+
 int read_file(const char *dir, const char *fname, int read_opt,
 	      float orig_timeout, float watch_interval, size_t header_lines)
 {
@@ -224,6 +232,20 @@ read:
 			    && (last_seen > orig_timeout))
 				continue;
 
+		/* translation table: skip multicast */
+		if (line > header_lines &&
+		    read_opt & UNICAST_ONLY &&
+		    strlen(line_ptr) > strlen(" * xx:xx:xx:") &&
+		    str_is_mcast_addr(line_ptr+3))
+			continue;
+
+		/* translation table: skip unicast */
+		if (line > header_lines &&
+		    read_opt & MULTICAST_ONLY &&
+		    strlen(line_ptr) > strlen(" * xx:xx:xx:") &&
+		    !str_is_mcast_addr(line_ptr+3))
+			continue;
+
 		if (!(read_opt & USE_BAT_HOSTS)) {
 			printf("%s", line_ptr);
 			continue;
diff --git a/functions.h b/functions.h
index 14ba525..43c3d9c 100644
--- a/functions.h
+++ b/functions.h
@@ -57,6 +57,8 @@ enum {
 	NO_OLD_ORIGS = 0x40,
 	COMPAT_FILTER = 0x80,
 	SKIP_HEADER = 0x100,
+	UNICAST_ONLY = 0x200,
+	MULTICAST_ONLY = 0x400,
 };
 
 #endif
diff --git a/man/batctl.8 b/man/batctl.8
index a8e8868..6b43d5e 100644
--- a/man/batctl.8
+++ b/man/batctl.8
@@ -178,6 +178,8 @@ All of the debug tables support the following options:
 The originator table also supports the "\-t" filter option to remove all originators from the output that have not been seen
 for the specified amount of seconds (with optional decimal places).
 
+The local and global translation tables also support the "\-u" and "\-m" option to only display unicast or multicast translation table announcements respectively.
+
 List of debug tables:
 .RS 10
 \- originators|o
-- 
1.7.10.4


      parent reply	other threads:[~2014-03-02 22:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-02 22:17 [B.A.T.M.A.N.] [PATCHv2 0/3] batctl: multicast related patches Linus Lüssing
2014-03-02 22:18 ` [B.A.T.M.A.N.] [PATCHv2 1/3] batctl: fix wrong header lines number for local translation table Linus Lüssing
2014-03-11 10:43   ` Marek Lindner
2014-03-02 22:18 ` [B.A.T.M.A.N.] [PATCHv2 2/3] batctl: add switch for setting multicast_mode Linus Lüssing
2014-03-11 10:46   ` Marek Lindner
2014-03-02 22:18 ` Linus Lüssing [this message]

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=1393798682-7703-4-git-send-email-linus.luessing@web.de \
    --to=linus.luessing@web.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.