From patchwork Thu Jun 9 14:58:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Wunderlich X-Patchwork-Id: 16354 X-Patchwork-Delegate: mareklindner@neomailbox.ch 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 B09E381CFA; Thu, 9 Jun 2016 16:59:45 +0200 (CEST) Authentication-Results: open-mesh.org; dmarc=none header.from=simonwunderlich.de Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2001:4d88:2000:24::c0de; helo=mail.mail.packetmixer.de; envelope-from=sw@simonwunderlich.de; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dmarc=none header.from=simonwunderlich.de Received: from mail.mail.packetmixer.de (packetmixer.de [IPv6:2001:4d88:2000:24::c0de]) by open-mesh.org (Postfix) with ESMTPS id B049E81CFF for ; Thu, 9 Jun 2016 16:58:59 +0200 (CEST) Received: from kero.packetmixer.de (p2003007C6F7E2400527B9DFFFECE2EDC.dip0.t-ipconnect.de [IPv6:2003:7c:6f7e:2400:527b:9dff:fece:2edc]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mail.packetmixer.de (Postfix) with ESMTPSA id C2144174001; Thu, 9 Jun 2016 16:58:59 +0200 (CEST) From: Simon Wunderlich To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 9 Jun 2016 16:58:52 +0200 Message-Id: <1465484333-8187-5-git-send-email-sw@simonwunderlich.de> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1465484333-8187-1-git-send-email-sw@simonwunderlich.de> References: <1465484333-8187-1-git-send-email-sw@simonwunderlich.de> Subject: [B.A.T.M.A.N.] [PATCH v9 4/5] batctl: Split translate_mac 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" From: Sven Eckelmann The debugfs tables cannot be used by the batctl in network namespaces. These have to use netlink. Thus the translate_mac should be less tightly linked to the debugfs tables to implement optional netlink support. Signed-off-by: Sven Eckelmann --- functions.c | 46 +++++++++++++++++++++++++++++++++++----------- functions.h | 3 ++- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/functions.c b/functions.c index 5b76062..f994ced 100644 --- a/functions.c +++ b/functions.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -371,7 +372,9 @@ out: return res; } -struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac) +static int translate_mac_debugfs(const char *mesh_iface, + const struct ether_addr *mac, + struct ether_addr *mac_out) { enum { tg_start, @@ -381,26 +384,23 @@ struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac) } pos; char full_path[MAX_PATH+1]; char *debugfs_mnt; - static struct ether_addr in_mac; - struct ether_addr *mac_result, *mac_tmp; + struct ether_addr *mac_tmp; FILE *f = NULL; size_t len = 0; char *line = NULL; char *input, *saveptr, *token; int line_invalid; - - memcpy(&in_mac, mac, sizeof(in_mac)); - mac_result = &in_mac; + bool found = false; debugfs_mnt = debugfs_mount(NULL); if (!debugfs_mnt) - goto out; + return -EOPNOTSUPP; debugfs_make_path(DEBUG_BATIF_PATH_FMT "/" DEBUG_TRANSTABLE_GLOBAL, mesh_iface, full_path, sizeof(full_path)); f = fopen(full_path, "r"); if (!f) - goto out; + return -EOPNOTSUPP; while (getline(&line, &len, f) != -1) { line_invalid = 0; @@ -419,8 +419,8 @@ struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac) break; case tg_mac: mac_tmp = ether_aton(token); - if (!mac_tmp || memcmp(mac_tmp, &in_mac, - sizeof(in_mac)) != 0) + if (!mac_tmp || memcmp(mac_tmp, mac, + ETH_ALEN) != 0) line_invalid = 1; else pos = tg_via; @@ -434,7 +434,8 @@ struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac) if (!mac_tmp) { line_invalid = 1; } else { - mac_result = mac_tmp; + memcpy(mac_out, mac_tmp, ETH_ALEN); + found = true; goto out; } break; @@ -449,6 +450,29 @@ out: if (f) fclose(f); free(line); + + if (found) + return 0; + else + return -ENOENT; +} + +struct ether_addr *translate_mac(const char *mesh_iface, + const struct ether_addr *mac) +{ + struct ether_addr in_mac; + static struct ether_addr out_mac; + struct ether_addr *mac_result; + + /* input mac has to be copied because it could be in the shared + * ether_aton buffer + */ + memcpy(&in_mac, mac, sizeof(in_mac)); + memcpy(&out_mac, mac, sizeof(out_mac)); + mac_result = &out_mac; + + translate_mac_debugfs(mesh_iface, &in_mac, mac_result); + return mac_result; } diff --git a/functions.h b/functions.h index 2d29d52..1f311ca 100644 --- a/functions.h +++ b/functions.h @@ -40,7 +40,8 @@ int read_file(const char *dir, const char *path, int read_opt, float orig_timeout, float watch_interval, size_t header_lines); int write_file(const char *dir, const char *fname, const char *arg1, const char *arg2); -struct ether_addr *translate_mac(char *mesh_iface, struct ether_addr *mac); +struct ether_addr *translate_mac(const char *mesh_iface, + const struct ether_addr *mac); struct ether_addr *resolve_mac(const char *asc); int vlan_get_link(const char *ifname, char **parent);