From patchwork Tue Nov 1 15:20:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Sarton X-Patchwork-Id: 16800 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 48F7A831C5; Tue, 1 Nov 2016 16:20:13 +0100 (CET) Authentication-Results: open-mesh.org; dmarc=none header.from=t-online.de Received: from mailout12.t-online.de (mailout12.t-online.de [194.25.134.22]) by open-mesh.org (Postfix) with ESMTPS id 8838F831AA for ; Tue, 1 Nov 2016 16:20:11 +0100 (CET) Authentication-Results: open-mesh.org; dmarc=none header.from=t-online.de Received: from fwd21.aul.t-online.de (fwd21.aul.t-online.de [172.20.27.66]) by mailout12.t-online.de (Postfix) with SMTP id 4228641E4144 for ; Tue, 1 Nov 2016 16:20:11 +0100 (CET) Received: from pc3.jjsarton.de (XLmZ-kZbghA8xH7198wMHhxjmafwipViOp4plgjVrASujDJsY9n2kF++DnfWlpHZ2h@[109.75.223.223]) by fwd21.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-SHA encrypted) esmtp id 1c1arA-24F79k0; Tue, 1 Nov 2016 16:20:08 +0100 From: Jean-Jacques Sarton To: b.a.t.m.a.n@lists.open-mesh.org Openpgp: id=F1A7034CEF4FAA67C999A7B033D25B891DC2C10B Message-ID: <735c49a8-6ccd-9932-5835-27b59b3f1c98@t-online.de> Date: Tue, 1 Nov 2016 16:20:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-ID: XLmZ-kZbghA8xH7198wMHhxjmafwipViOp4plgjVrASujDJsY9n2kF++DnfWlpHZ2h X-TOI-MSGID: a3a354bc-fc46-4c53-8e11-e50286aa112a Subject: [B.A.T.M.A.N.] =?utf-8?q?PATCH_a=C3=B6fred_don=27t_start_idz_with?= =?utf-8?q?in_a_network_spaxce?= 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" Hello I hope that this will be a valid patch. This patch shall allow to use the debugfs as previouly, including the check for valify of the interface used. For netns the check seem to be implemented within the function netlink_query_common(). For netlink we check if the originators ans transtable_global informations are accessible through netlink. Signed-off-by: jj.sarton@t-online.de diff --git a/batadv_query.c b/batadv_query.c index a671b79..dc8a042 100644 --- a/batadv_query.c +++ b/batadv_query.c @@ -136,7 +136,7 @@ int ipv6_to_mac(const struct in6_addr *addr, struct ether_addr *mac) return 0; } -int batadv_interface_check(const char *mesh_iface) +int batadv_interface_check_debugfs(const char *mesh_iface) { char full_path[MAX_PATH + 1]; FILE *f; @@ -166,6 +166,18 @@ int batadv_interface_check(const char *mesh_iface) return 0; } +int batadv_interface_check(const char *mesh_iface) +{ + int ret = 0; + enable_net_admin_capability(1); + ret = batadv_interface_check_netlink(mesh_iface); + enable_net_admin_capability(0); + + if ( ret < 0 ) + return batadv_interface_check_debugfs(mesh_iface); + return 0; +} + static int translate_mac_debugfs(const char *mesh_iface, const struct ether_addr *mac, struct ether_addr *mac_out) diff --git a/netlink.c b/netlink.c index 1b5695c..9288770 100644 --- a/netlink.c +++ b/netlink.c @@ -365,3 +365,30 @@ int get_tq_netlink(const char *mesh_iface, const struct ether_addr *mac, return 0; } + +int batadv_interface_check_netlink(const char *mesh_iface) +{ + struct get_tq_netlink_opts opts = { + .tq = 0, + .found = false, + .query_opts = { + .err = 0, + }, + }; + int ret = 0; + + memset(&opts.mac, 0, ETH_ALEN); + + ret = netlink_query_common(mesh_iface, BATADV_CMD_GET_ORIGINATORS, + get_tq_netlink_cb, &opts.query_opts); + if (ret < 0) + return ret; + + memset(&opts.mac, 0, ETH_ALEN); + ret = netlink_query_common(mesh_iface, BATADV_CMD_GET_TRANSTABLE_GLOBAL, + get_tq_netlink_cb, &opts.query_opts); + + if (ret < 0) + return ret; + return 0; +} diff --git a/netlink.h b/netlink.h index b08e872..9bc75a1 100644 --- a/netlink.h +++ b/netlink.h @@ -49,6 +49,7 @@ int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac, struct ether_addr *mac_out); int get_tq_netlink(const char *mesh_iface, const struct ether_addr *mac, uint8_t *tq); +int batadv_interface_check_netlink(const char *mesh_iface); extern struct nla_policy batadv_netlink_policy[];