From patchwork Thu Nov 2 07:59:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Bhole X-Patchwork-Id: 833244 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ySHbL63FFz9t2f for ; Thu, 2 Nov 2017 19:01:18 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755629AbdKBIBP (ORCPT ); Thu, 2 Nov 2017 04:01:15 -0400 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]:33062 "EHLO tama500.ecl.ntt.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755601AbdKBIBM (ORCPT ); Thu, 2 Nov 2017 04:01:12 -0400 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id vA280r1c021323; Thu, 2 Nov 2017 17:00:53 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 848DA60283; Thu, 2 Nov 2017 17:00:53 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 775395F69F; Thu, 2 Nov 2017 17:00:53 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (unknown [129.60.241.220]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 713D6400A80; Thu, 2 Nov 2017 17:00:53 +0900 (JST) From: Prashant Bhole Subject: [PATCH net-next V2 1/3] tools: bpftool: open pinned object without type check Date: Thu, 2 Nov 2017 16:59:15 +0900 Message-Id: <20171102075917.2780-2-bhole_prashant_q7@lab.ntt.co.jp> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171102075917.2780-1-bhole_prashant_q7@lab.ntt.co.jp> References: <20171102075917.2780-1-bhole_prashant_q7@lab.ntt.co.jp> To: "David S . Miller" Cc: Prashant Bhole , netdev@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Quentin Monnet , Jakub Kicinski X-TM-AS-MML: disable Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This was needed for opening any file in bpf-fs without knowing its object type Signed-off-by: Prashant Bhole Acked-by: Quentin Monnet --- tools/bpf/bpftool/common.c | 15 +++++++++++++-- tools/bpf/bpftool/main.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c index f0288269dae8..4556947709ee 100644 --- a/tools/bpf/bpftool/common.c +++ b/tools/bpf/bpftool/common.c @@ -91,9 +91,8 @@ static int mnt_bpffs(const char *target, char *buff, size_t bufflen) return 0; } -int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type) +int open_obj_pinned(char *path) { - enum bpf_obj_type type; int fd; fd = bpf_obj_get(path); @@ -105,6 +104,18 @@ int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type) return -1; } + return fd; +} + +int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type) +{ + enum bpf_obj_type type; + int fd; + + fd = open_obj_pinned(path); + if (fd < 0) + return -1; + type = get_fd_type(fd); if (type < 0) { close(fd); diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h index d315d01be645..4b5685005cb0 100644 --- a/tools/bpf/bpftool/main.h +++ b/tools/bpf/bpftool/main.h @@ -86,6 +86,7 @@ int cmd_select(const struct cmd *cmds, int argc, char **argv, int get_fd_type(int fd); const char *get_fd_type_name(enum bpf_obj_type type); char *get_fdinfo(int fd, const char *key); +int open_obj_pinned(char *path); int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type); int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32));