From patchwork Sun Jun 5 18:47:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 16324 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 79D6181B45; Sun, 5 Jun 2016 20:48:48 +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=k8v2fvMB; 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 7A52D81B0D for ; Sun, 5 Jun 2016 20:47:26 +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 E07E71100E8; Sun, 5 Jun 2016 20:47:25 +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=1465152446; bh=UQ5xdDuUSGa0zCRHEg8n4SMM4dn6Z1dwI55V8LpOCM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k8v2fvMByIrPfWSAaPT7uEOQSzb1CrK6t/35a1Szmwqiej9YAPZOjBYNYtmZ9sMGF bgjOXm2fzX7OiWP0tyKmqksz+NqQf4kwtbYJFs/lcIZ+EVDFyK2rHrhOQmoNWlFJKZ EkffGvwH544Y/ZHzOmCZGdFV3FToGxJWqkXfJ9+8= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Sun, 5 Jun 2016 20:47:07 +0200 Message-Id: <1465152428-17299-9-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 09/10] alfred: vis: Save device index in interface list 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 netlink messages don't contain the complete names. Instead the device indexes are used. To avoid extra overhead of retrieving the device name for each index, the interface list can just be used again as cache by making it queryable via the ifindex. Signed-off-by: Sven Eckelmann --- vis/vis.c | 13 ++++++++++--- vis/vis.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/vis/vis.c b/vis/vis.c index 7eab781..bac451b 100644 --- a/vis/vis.c +++ b/vis/vis.c @@ -125,9 +125,10 @@ static int get_if_mac(char *ifname, uint8_t *mac) return 0; } -static int get_if_index(struct globals *globals, char *ifname) +static int get_if_index_byname(struct globals *globals, char *ifname) { struct iface_list_entry *i_entry; + int devindex; int i; if (!ifname) @@ -139,6 +140,11 @@ static int get_if_index(struct globals *globals, char *ifname) return i; i++; } + + devindex = if_nametoindex(ifname); + if (!devindex) + return -1; + i_entry = malloc(sizeof(*i_entry)); if (!i_entry) return -1; @@ -148,6 +154,7 @@ static int get_if_index(struct globals *globals, char *ifname) return -1; } + i_entry->devindex = devindex; strncpy(i_entry->name, ifname, sizeof(i_entry->name)); /* just to be safe ... */ i_entry->name[sizeof(i_entry->name) - 1] = 0; @@ -301,7 +308,7 @@ static int register_interfaces(struct globals *globals) *content_newline = '\0'; if (strcmp(file_content, "active") == 0) - get_if_index(globals, iface_dir->d_name); + get_if_index_byname(globals, iface_dir->d_name); free_line: free(file_content); @@ -364,7 +371,7 @@ static int parse_orig_list(struct globals *globals) if (!mac) continue; - ifindex = get_if_index(globals, iface); + ifindex = get_if_index_byname(globals, iface); if (ifindex < 0) continue; diff --git a/vis/vis.h b/vis/vis.h index 4c98064..c25a75b 100644 --- a/vis/vis.h +++ b/vis/vis.h @@ -77,6 +77,7 @@ struct vis_v1 { struct iface_list_entry { char name[256]; uint8_t mac[ETH_ALEN]; + int devindex; struct list_head list; };