From patchwork Sun Jun 5 18:47:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 16322 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 4B1C681B33; Sun, 5 Jun 2016 20:48:20 +0200 (CEST) Authentication-Results: open-mesh.org; dmarc=none header.from=narfation.org Authentication-Results: open-mesh.org; dkim=fail reason="verification failed; unprotected key" header.d=narfation.org header.i=@narfation.org header.b=rgV4xNds; dkim-adsp=fail (unprotected policy); dkim-atps=neutral Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2001:4d88:2000:7::2; helo=v3-1039.vlinux.de; envelope-from=sven@narfation.org; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dmarc=pass header.from=narfation.org Received: from v3-1039.vlinux.de (narfation.org [IPv6:2001:4d88:2000:7::2]) by open-mesh.org (Postfix) with ESMTPS id 0C4EF81AC9 for ; Sun, 5 Jun 2016 20:47:25 +0200 (CEST) Received: from sven-desktop.home.narfation.org (p4FCB293D.dip0.t-ipconnect.de [79.203.41.61]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 94C4A110119; Sun, 5 Jun 2016 20:47:24 +0200 (CEST) Authentication-Results: v3-1039.vlinux.de; dmarc=none header.from=narfation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=narfation.org; s=20121; t=1465152444; bh=P0dtnoRk9AyNWnQnmNFZT1V/CDX5oTMbRJccG6is7l4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rgV4xNdsEBOnI1UaM3LXpQlaxDXB31IEQKjubwuflBWu8eweOych2kJTN363QCeE2 DpSsrgnvsO6/Sesvoj/OzKp1uIKLKyeAanI8zcQxCYhx/Rg6W6wzZh13yxU29pkQne 2aJmyGAfQvHd298BVvFG0+Q54gKCpBGvEb7szduA= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Sun, 5 Jun 2016 20:47:05 +0200 Message-Id: <1465152428-17299-7-git-send-email-sven@narfation.org> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1465152428-17299-1-git-send-email-sven@narfation.org> References: <1465152428-17299-1-git-send-email-sven@narfation.org> Subject: [B.A.T.M.A.N.] [PATCH 07/10] alfred: Split get_tq from debugfs backend X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" 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 --- 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; }