Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9833756ybi; Wed, 24 Jul 2019 10:44:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQx+v08wHYWjdSngrSnmtC4gIX0lYJFR+i8lH17PpHoKaCvV7OO/I6k21yuB7msQVzAWa6 X-Received: by 2002:a63:b555:: with SMTP id u21mr83864568pgo.222.1563990286507; Wed, 24 Jul 2019 10:44:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563990286; cv=none; d=google.com; s=arc-20160816; b=OeZt0+Lp82936kEUVw7vRQCEJCIYEWc1bQa+S6NWxkNl32CApx3O+flj6xaXd8TpE6 yexBFm6bP8om2N0UapS7t1j1IP0MAy/Nu47lwndXR1x1MfEzw4yl9270LFlppxv0tfsR Pf5SnmGRhdJWDYvicO3UT0KudnYBR8RoEmq2+5QS6Z6jdkTOgjmW0nA64rHiyzLAPpYa IinOn7mXhE9rsdM2MN8bAG86wuomaQszGIK1txoIiu1QC+UATaYpz6X3XCvP3AdAY1Pn F6H4UFqOmM+Sv5mBp3HXbtQPPuGykpLj87H8m3WCrzUATPiaXO2tkoY19Jp+tNdrNE4+ uS2Q== 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=glKaPZF0kuawPUQxXbpKIp+157oyf0yYPp3UELzJQsg=; b=zAYQv+EtNNY5ARcsGACNH5tCkbXpPqkAXM0kRW8zL7JemhuM1sETeB3Ynf1EP1qRkX hgQ0LF5ES1qbzXBcGhKvtonyMOGABaNXEH4lgIo++wE9XK657g8tqpD7MnUQiVaJVqMr w47yVtvjN30Nfiv+FfhY2L3uELtfd1atVwu3uwBRMCUr8dHKDblYFLf5yL+haex8Wq+j aHhV1Tj3j/vbNoHhKB7cYeJ+GGHceGXAEM5tEiJqozEsBX5xyp8xj/9yFjF/D9v/xsIs T9ErC0mTcgKgNjOZaqK/cuXDHb7wCbu/LA46TKMOr55AyG2ae8gck1wuSDnFiTNggFIT CGIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=rqq9g03P; 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 p44si15571178pjp.0.2019.07.24.10.44.32; Wed, 24 Jul 2019 10:44:46 -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=rqq9g03P; 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 S2387632AbfGXQ6m (ORCPT + 99 others); Wed, 24 Jul 2019 12:58:42 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:55181 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728482AbfGXQ6h (ORCPT ); Wed, 24 Jul 2019 12:58:37 -0400 Received: by mail-qk1-f201.google.com with SMTP id b139so39812301qkc.21 for ; Wed, 24 Jul 2019 09:58:36 -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=glKaPZF0kuawPUQxXbpKIp+157oyf0yYPp3UELzJQsg=; b=rqq9g03PpRhF3ymvIyKsJZzyqpeGHYdT7zGj3bnG5I1MzwqawSR6jYQY47lcFaPh8u AC4HC3jBJ8Q6HPjbVfvzmz4thwjP+kPTjr2j5uQJzkIhru+IeBl/CNrBF8HUEJPBemGj YCZ8sgHUbNal4hCkX93eIDVTkVotYLPT72iFfHt7htZalJIeNAPgZOBv4v1Aggm/iBAF E4vT2Eug6Gz2suAsgF+EumINRAuFJHHIgZphdq8fz7jesmzD+kw6OvLpLQVJ3v4oNRKf 6h7BMZEYGDGnq0Cb8crL9rOnzJd0xO2wfJjOb3bwSjthqNd8+O6dl4tNFBv5bU8iEhTG 811w== 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=glKaPZF0kuawPUQxXbpKIp+157oyf0yYPp3UELzJQsg=; b=Zla3+6VSZKJhVU45hoZ+hStPlKRc7N3ga0GpgZtAB2jLH2mmARbbikrBWN/aFq9d9+ 9DmvAKbB3EF0daAvn9grk25V7DO4WqSpQl/tR9ZUFbj7u4r62HJFeCpeD6HwBqxAdqgv 01k0dgwoM85HTTpmBodPwccqHTgUgecl/BLBSjQpo33RUTvoF55tNtXNQGvElyCM5/Tj so1E6TyD8nt5S9z0MXEQAWthK7hI0yPTPZaBHwj+0KE87VtAwY3sPAKNSBj5KIKv7ai1 ufZO5ZSdao4+R8VmO+gfX+5taI8ZV1I+5WBCc/lDeBrvsIYz8579LV9GPgfoN7QjIyQ2 eCVQ== X-Gm-Message-State: APjAAAXc9xu0Z2ubMLczTPxvgT8kskIZJJZHH2pGBLWip28bp2uhuLcd Y/sdS1L4PrbVgXcrayYhcTiMoI8YdwFb X-Received: by 2002:a0c:8a76:: with SMTP id 51mr60440819qvu.210.1563987516337; Wed, 24 Jul 2019 09:58:36 -0700 (PDT) Date: Wed, 24 Jul 2019 09:58:01 -0700 In-Reply-To: <20190724165803.87470-1-brianvv@google.com> Message-Id: <20190724165803.87470-5-brianvv@google.com> Mime-Version: 1.0 References: <20190724165803.87470-1-brianvv@google.com> X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog Subject: [PATCH bpf-next 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 ++++ 2 files changed, 32 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); -- 2.22.0.657.g960e92d24f-goog