Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1133014ybi; Wed, 3 Jul 2019 10:03:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHLCiWsq2L//0g3XrP2b0LNEcGF0Lb0PcK+GzVVe66Hv5Lejg4KJhfxiEbXuUr0jzrJLw/ X-Received: by 2002:a65:5202:: with SMTP id o2mr35344756pgp.199.1562173401879; Wed, 03 Jul 2019 10:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562173401; cv=none; d=google.com; s=arc-20160816; b=qfvfJHBMtgHvpz7EpMC7FXgEcOkq+UXtwogK7CISbUYc6PQC+mJhYq2aVWbWqs/T+h d4kvQzqhFtlMcu5vykpSVOlE8L1k2JoQ9SnNPR1SSyjnL8+BtOg0TU7iKzhWC6bQI0yT tbgZQOfy3nfzUheSlW4GTDXt0SSSLjIJPXRf7jqe5SIGhG2YKuuDDhVnHpI535FfwICG dnj9tkr5OUZGycWAHtXO31Sjt7eN5FFKMQC1yf8hbUBEVqJO+l4qeysSKbnHJhRSFwty QAr1LY2UtmuOHz9oYwWD6p4svfU6ljXjVTHfqQUAy3PognWhxAbYrudnGz1iI/6zr6VJ RT2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=SkPVxPTkLQnSJ+04pOruRJ+oHifbro+qasEP8Q6MwF4=; b=DiDvC/Itle/shSY/ricbriNv5eNqeqUJ1T+Bpf4llTfUZ2ADJFsPes/BE74TxRnW2a 3nGPBDCKnvdD1Nvf063pYOPjTkx9i/w/5NYvsbW2sBISOzyQQD1aPggQxxVMzIjWhJx5 Qwe5rFPCBtLMnfaGztnMUwkwklg3OxYX7jc9NXvHBfuuRaYJ7ADkR9We+nDWnR1ptuMm FZoCMs0wSb7SS/bPUh4o7172oV+TbippCT11lM31IWzLxFnNYD6n8juTvV7yoVdDBF0l 1tD2jq36ttATRlCShRfu/rnV4gdILuXnJ2Jc6vs+Ht528fsDxCoLDW7R8+9V0CCWxgGC PnKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SSaXIUdq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z61si2664409plb.19.2019.07.03.10.03.01; Wed, 03 Jul 2019 10:03:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SSaXIUdq; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727300AbfGCRCN (ORCPT + 99 others); Wed, 3 Jul 2019 13:02:13 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:38895 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727242AbfGCRCM (ORCPT ); Wed, 3 Jul 2019 13:02:12 -0400 Received: by mail-pg1-f201.google.com with SMTP id w5so1962630pgs.5 for ; Wed, 03 Jul 2019 10:02:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=SkPVxPTkLQnSJ+04pOruRJ+oHifbro+qasEP8Q6MwF4=; b=SSaXIUdqZIgZvFHvhwZvfBWgZIsMPL+K6OnKBFCRQjlPLpmeZzVc9rJIfRlNu+KnoX 4ZWEd5V9nO/Q714zf0mRBjIva4Sxy8h04AdI3omElqxwP+BTy58PYe7rLDOj7gs2f1vd 548JoeoIdOKvTeO46tkv7LBny1ufzCOq4q7nrnh7uttNUQVag3QljTBIofOwJfuHXIo6 0pMHl/SNcBCngGWHqT00tRid+cjvSgiPhUrXnn5Hwa8MAjjdXnAqdMGxJ5DpJIF2Ndn9 PWtH4zWlYaq8ICS1BUv6axZ3pkwVaSILw8SNHwsEddJzL/LRgfrLr3Plad7f1wUh9Bob KjiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=SkPVxPTkLQnSJ+04pOruRJ+oHifbro+qasEP8Q6MwF4=; b=uV/HxCtgYEmQkcT/r1wQ5VQtAAnQmRbmgLzPzM+8lUXAGnygoZufOznQCR9ioR41/y /D+FOXhedViXYWVeiJclhNMIkrFEwLn8HwfI1SPAivbIFXy9IZeKg4+KPem/RW3yPW2m pFG1BF247SffxPIMrboUAF/suOmRYtTplvRIymQL5Q73gMwfRUA0FLoPJ+5FSIWMpXyP WYD4VFiAR8h0lxCbysmo1DLqAjB9UUUbE5TKTxI3xZ3MwH+HGI4qjf5CSi8i9RWraqwc Jy3fMGy9AOsLBCeC9ABAfSLVFtYfMQVxNWqGvDAmvFQyR558/5xjBBOc606tJaeN4WFU 8Gdw== X-Gm-Message-State: APjAAAVc0yF3KndSJvTGFOqnLgyZrvI1oTbTTqu96iSF5DM9LRB31MXc l7YkKPy35+0FodmdRLXpvQBBw0wSnYVG X-Received: by 2002:a63:a41:: with SMTP id z1mr37996608pgk.290.1562173331396; Wed, 03 Jul 2019 10:02:11 -0700 (PDT) Date: Wed, 3 Jul 2019 10:01:16 -0700 In-Reply-To: <20190703170118.196552-1-brianvv@google.com> Message-Id: <20190703170118.196552-5-brianvv@google.com> Mime-Version: 1.0 References: <20190703170118.196552-1-brianvv@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [PATCH bpf-next RFC v3 4/6] libbpf: support BPF_MAP_DUMP command From: Brian Vazquez To: Brian Vazquez , Alexei Starovoitov , Daniel Borkmann , "David S . Miller" Cc: Stanislav Fomichev , Willem de Bruijn , Petar Penkov , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Brian Vazquez Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make libbpf aware of new BPF_MAP_DUMP command and add bpf_map_dump and bpf_map_dump_flags to use them from the library. Suggested-by: Stanislav Fomichev Signed-off-by: Brian Vazquez --- tools/lib/bpf/bpf.c | 28 ++++++++++++++++++++++++++++ tools/lib/bpf/bpf.h | 4 ++++ tools/lib/bpf/libbpf.map | 2 ++ 3 files changed, 34 insertions(+) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index c7d7993c44bb..c1139b7db756 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -368,6 +368,34 @@ int bpf_map_update_elem(int fd, const void *key, const void *value, return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); } +int bpf_map_dump(int fd, const void *prev_key, void *buf, void *buf_len) +{ + union bpf_attr attr; + + memset(&attr, 0, sizeof(attr)); + attr.dump.map_fd = fd; + attr.dump.prev_key = ptr_to_u64(prev_key); + attr.dump.buf = ptr_to_u64(buf); + attr.dump.buf_len = ptr_to_u64(buf_len); + + return sys_bpf(BPF_MAP_DUMP, &attr, sizeof(attr)); +} + +int bpf_map_dump_flags(int fd, const void *prev_key, void *buf, void *buf_len, + __u64 flags) +{ + union bpf_attr attr; + + memset(&attr, 0, sizeof(attr)); + attr.dump.map_fd = fd; + attr.dump.prev_key = ptr_to_u64(prev_key); + attr.dump.buf = ptr_to_u64(buf); + attr.dump.buf_len = ptr_to_u64(buf_len); + attr.dump.flags = flags; + + return sys_bpf(BPF_MAP_DUMP, &attr, sizeof(attr)); +} + int bpf_map_lookup_elem(int fd, const void *key, void *value) { union bpf_attr attr; diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index ff42ca043dc8..86496443440e 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -112,6 +112,10 @@ LIBBPF_API int bpf_verify_program(enum bpf_prog_type type, LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value, __u64 flags); +LIBBPF_API int bpf_map_dump(int fd, const void *prev_key, void *buf, + void *buf_len); +LIBBPF_API int bpf_map_dump_flags(int fd, const void *prev_key, void *buf, + void *buf_len, __u64 flags); LIBBPF_API int bpf_map_lookup_elem(int fd, const void *key, void *value); LIBBPF_API int bpf_map_lookup_elem_flags(int fd, const void *key, void *value, __u64 flags); diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 2c6d835620d2..e7641773cfb0 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -173,4 +173,6 @@ LIBBPF_0.0.4 { btf__parse_elf; bpf_object__load_xattr; libbpf_num_possible_cpus; + bpf_map_dump; + bpf_map_dump_flags; } LIBBPF_0.0.3; -- 2.22.0.410.gd8fdbe21b5-goog