Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2495208ybd; Thu, 27 Jun 2019 13:25:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPlbMCFW1e1aooRWwDAYPJ/sYU5OkL5BffLDVgZRKbNbZR6kptgiF/v6vcu4QdooEYM2K0 X-Received: by 2002:a65:4347:: with SMTP id k7mr5591443pgq.253.1561667120088; Thu, 27 Jun 2019 13:25:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561667120; cv=none; d=google.com; s=arc-20160816; b=aQTcKwk+8w636yW42CwtTgnG2m9Rc32LCymCdfW6JeZ/7qgosxtcj89iKQFLurBVdZ D2qI+S6BoXD0qUAqq3o8lJmJTOuE1LreQelpyiOSqj/BpgCIHEDC9abZJRPQ69qfpB7G hWeeyDtSrq9tulNjBMk7jq13oz9uGVLbYuMyo6Bw5gSbdqSabkaOvY1h1uI9v/jLy9Qi F5CgfgVFcSxQ0ehPnjDuWEP87Nw4AmdcTi5qa7orNWbZ3yttWCUAqCEOvXY+tqdGlqbO 0A8bLGpNJV59yUnPFv+qteSdVdjNA+U53PRbbE6/y4a9gvJugHbabniLU1ODS0lDB2oU 2uuQ== 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=Qx6zTmWl7cnoAmaxAa2U3PPxEaWd7SQs0w5RBVcvKMg=; b=c0tJjcJkB3dcMe0T2oawhmeC/ffZ0kBh3Lg/Jdvq3N8ZrI2/0R1L1p47JykWlcFkNe x5+bfoKxBsrQIXVzM1/WdDjqAMHpKYQ3WY0dxYTzE0O7i0PEQ38czm7UwiTF512b0RmQ 7DF78knEpeiZv9kd+IUzPDoMXskj8mJwWtWA4b5PySENOBuU+0aSRZ/Kqw6J+RnAmglz PXcmCvJo7iAUclh3Q/zyjUT0l0JKc4EBNhlNumKtjgvlXnPDfjePAGOtU6N3AHMe/tBm m7S3oeSOIwVt1K1NF26K+Xz/3VZM0jZJSs2KFVZysyDBaAomOjAd+w0aagJwgwPorVEl tGZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="ZnXGrg/a"; 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 39si3270452pla.73.2019.06.27.13.25.04; Thu, 27 Jun 2019 13:25:20 -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="ZnXGrg/a"; 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 S1726674AbfF0UYs (ORCPT + 99 others); Thu, 27 Jun 2019 16:24:48 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:49602 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbfF0UYn (ORCPT ); Thu, 27 Jun 2019 16:24:43 -0400 Received: by mail-pf1-f202.google.com with SMTP id x9so2264803pfm.16 for ; Thu, 27 Jun 2019 13:24:43 -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=Qx6zTmWl7cnoAmaxAa2U3PPxEaWd7SQs0w5RBVcvKMg=; b=ZnXGrg/aKIIKDp6JCvIE36LhXe8OA/r2R56GEOXCcPwriAo1jlO0FIzmIrwoTxDw76 ra+QLeGO+fg1Wv5c7XdTWn9tnRCQtDvJ42Rz8GNNADc7349KibWK6OiEdRjS1xBtVNfs LCghjBV+8KURbqaWR0yjtXBT1MUJSZW1xLBAvvJcZeyt367gIvDQ2RCd/yNF7FhO3TTP 3utIh4ij4wqpttrTr5zHm4VNkKigjhsqPTyWCHsl/xKIa2sHteRRmGJC23g9rCVdHw20 APJXPEOAlAtyQMeCqidLrog+2jpeD+p9+U2QhaTmnvchzxrDKYMgFtqQMNogs1HzfYU0 EM0g== 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=Qx6zTmWl7cnoAmaxAa2U3PPxEaWd7SQs0w5RBVcvKMg=; b=tiFa+Qmi+A03hw1cLRmo2ZEJPCve8Z4MOJktmh/ZJC1ojIwbaJ+quHYPYTTj5agTKi 4FvpkHNqVMld1mdv+7cvZ3B6mNuLLgCfLbXeSBNk5CMUTDPkHC3brySrUOPsTU6t346f ADGHVvyr5zvPp6cefsZGiETmOHkNQZdT71MX/VjJ6/auxrYkh8al3xaZkGwK3AuS9XUs FXpCs87JwPaYrWVXKTkWqW3p0VcqsQ4lPFO/Jd3NZd+iCIUTabPaRkTBp6efNoC/6iO8 nZbjQm5T8RFPqo03iZ71UuEp/NYfuR70Vqs+v6Y9P6OD9Z6y7IN4L/lMc/xK8bXCp9Jv +Kpw== X-Gm-Message-State: APjAAAVnftNEmzTWaQj8LeEDOxjjWWh7woiG9uyWqBh2XiGDO84XH7Oh h0wKnZcHCpxXlRlMOrgmd/4NGEBADs51 X-Received: by 2002:a63:d354:: with SMTP id u20mr5374534pgi.129.1561667082596; Thu, 27 Jun 2019 13:24:42 -0700 (PDT) Date: Thu, 27 Jun 2019 13:24:15 -0700 In-Reply-To: <20190627202417.33370-1-brianvv@google.com> Message-Id: <20190627202417.33370-5-brianvv@google.com> Mime-Version: 1.0 References: <20190627202417.33370-1-brianvv@google.com> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog Subject: [RFC PATCH bpf-next v2 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 c7d7993c44bb0..c1139b7db756a 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 ff42ca043dc8f..86496443440e9 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 2c6d835620d25..e7641773cfb0f 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