public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 07/10] alfred: Split get_tq from debugfs backend
Date: Sun,  5 Jun 2016 20:47:05 +0200	[thread overview]
Message-ID: <1465152428-17299-7-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1465152428-17299-1-git-send-email-sven@narfation.org>

The debugfs tables cannot be used by the alfred in network namespaces.
These have to use netlink. Thus the get_tq should be less tightly linked to
the debugfs tables to implement optional netlink support.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 batadv_query.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/batadv_query.c b/batadv_query.c
index 9082576..a893995 100644
--- a/batadv_query.c
+++ b/batadv_query.c
@@ -272,7 +272,8 @@ struct ether_addr *translate_mac(const char *mesh_iface,
 	return mac_result;
 }
 
-uint8_t get_tq(const char *mesh_iface, struct ether_addr *mac)
+static int get_tq_debugfs(const char *mesh_iface, struct ether_addr *mac,
+			  uint8_t *tq)
 {
 	enum {
 		orig_mac,
@@ -288,7 +289,7 @@ uint8_t get_tq(const char *mesh_iface, struct ether_addr *mac)
 	char *line = NULL;
 	char *input, *saveptr, *token;
 	int line_invalid;
-	uint8_t tq = 0;
+	bool found = false;
 
 	memcpy(&in_mac, mac, sizeof(in_mac));
 
@@ -297,7 +298,7 @@ uint8_t get_tq(const char *mesh_iface, struct ether_addr *mac)
 
 	f = fopen(full_path, "r");
 	if (!f)
-		goto out;
+		return -EOPNOTSUPP;
 
 	while (getline(&line, &len, f) != -1) {
 		line_invalid = 0;
@@ -338,7 +339,8 @@ uint8_t get_tq(const char *mesh_iface, struct ether_addr *mac)
 					line_invalid = 1;
 				} else {
 					token[strlen(token) - 1] = '\0';
-					tq = strtol(token, NULL, 10);
+					*tq = strtol(token, NULL, 10);
+					found = true;
 					goto out;
 				}
 				break;
@@ -353,5 +355,24 @@ out:
 	if (f)
 		fclose(f);
 	free(line);
+
+	if (found)
+		return 0;
+	else
+		return -ENOENT;
+}
+
+uint8_t get_tq(const char *mesh_iface, struct ether_addr *mac)
+{
+	struct ether_addr in_mac;
+	uint8_t tq = 0;
+
+	/* input mac has to be copied because it could be in the shared
+	 * ether_aton buffer
+	 */
+	memcpy(&in_mac, mac, sizeof(in_mac));
+
+	get_tq_debugfs(mesh_iface, &in_mac, &tq);
+
 	return tq;
 }
-- 
2.8.1


  parent reply	other threads:[~2016-06-05 18:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-05 18:46 [B.A.T.M.A.N.] [PATCH 01/10] alfred: vis: Fix parsing of iface_status Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 02/10] alfred: Split list of objects in Makefile into separate lines Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 03/10] alfred: Add netlink dependencies Sven Eckelmann
2016-07-21 15:58   ` Simon Wunderlich
2016-07-21 16:01     ` Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 04/10] alfred: Add CAP_NET_ADMIN capabilities for netlink Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 05/10] alfred: Split translate_mac from debugfs backend Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 06/10] alfred: Translate mac addresses via netlink Sven Eckelmann
2016-06-05 18:47 ` Sven Eckelmann [this message]
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 08/10] alfred: Query TQ of originators " Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 09/10] alfred: vis: Save device index in interface list Sven Eckelmann
2016-06-05 18:47 ` [B.A.T.M.A.N.] [PATCH 10/10] alfred: vis: Add support for netlink Sven Eckelmann
2016-07-16  7:28 ` [B.A.T.M.A.N.] [PATCH 11/11] alfred: Switch netlink uapi header copyright to ISC Sven Eckelmann
2016-07-26 11:55 ` [B.A.T.M.A.N.] [PATCH 01/10] alfred: vis: Fix parsing of iface_status Simon Wunderlich

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=1465152428-17299-7-git-send-email-sven@narfation.org \
    --to=sven@narfation.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox