Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9972591ybi; Wed, 24 Jul 2019 13:18:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxEQ0OtWRO7bQNdKLCxnUnzdT3B34lW6KofshIcxrTutZNmnxDS4+7l4ci9MV/3NAVeXKp0 X-Received: by 2002:a65:5882:: with SMTP id d2mr57063132pgu.134.1563999529248; Wed, 24 Jul 2019 13:18:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563999529; cv=none; d=google.com; s=arc-20160816; b=eQnE0merZWKUur4blIjiEVeOi3iWm5VKfamELOeMMypz4pk8loaIsL98bTY+3Jgf4q TiXvtrOvUNP6u1oreLlAf7ZsAZ0Ro65z8WyzktZNWfIYfGSdzcd+AeJjWBn8yTIGJGk2 K1kjBoLRfAMtervtRprYNeWur2H/zc/vBNDsBx+l4qI1PUV3W7+CBDkH3Rl2hTalsK+R kQaSiZ6MaZWk5+ZlZqJ0EkNcM3AAw6Z3h682LMDyRKatjyfig0rLQrzPAF0xQhJeEjpB lTEBAb7xsj37GTREYZYxny12+ofhchjuA8S5kdgkHEzze6wkAEsAXa29wyriM8wW1MVz nxRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=2p2ZfklHVEaOI9/2iCtD+yerzjFCKwVXOTunjKilUyg=; b=pXDr1zktlsUSH1PCcQO+zdbYUFRySqEEMBCj3GABrqwuFtBXoNGJyKHJyDlcIpMw1Q APCZsc9PEpoQFIdJzgvu7A0oE9uaT7AzgYE1OE7DBlPmmRD9yvng9pcATEonoysaWh2S /+8CNrVO+aAKBYioejiJHIAq6oQEtLidv2EtSSUXMflSqOKYRKO9mL1CpVgXP/qDmFaW hHZ5767xBDU0E/KiK6BN22vURVcS11apeYCQyVzkB+4x+Oa3CTFtaldR3bUN+RUfzMX9 8k5ueSXIMvtdGZw9JOcndRR/ou6qIeunTov+DIGKcboRP1WFdfyRK5vGDKAW6DTVeGy6 7NNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bFoeW529; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j12si13609578plk.272.2019.07.24.13.18.34; Wed, 24 Jul 2019 13:18:49 -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=@gmail.com header.s=20161025 header.b=bFoeW529; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391301AbfGXTv4 (ORCPT + 99 others); Wed, 24 Jul 2019 15:51:56 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:47037 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391707AbfGXTvw (ORCPT ); Wed, 24 Jul 2019 15:51:52 -0400 Received: by mail-ed1-f65.google.com with SMTP id d4so48167940edr.13; Wed, 24 Jul 2019 12:51:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2p2ZfklHVEaOI9/2iCtD+yerzjFCKwVXOTunjKilUyg=; b=bFoeW529ejuAL1azYCFXDwwZiIKojlT53AEBYIQE493V9F2hmIMpWNNMYMyuedouB6 Sfs0q/fXYDTeMHxjBC9GbtUNpcM4en6eXqDvF4577koXwZhd2X7v9WrYl5LrP83rTQxF a0jgfQxns67iKj6MkzBaqU4xi+tKgBQmYCFx/Tqx+cRGcA2h5LJzwhUMurzbBeqtryIq dyruxHxkK6fIJBZP8GQ8JLrVMKKv/TGpGloP8VPiYz3eQAyx/qlFaFkGqL3L9y2i/9D5 MbrIySIPL4sGxM9qz07W9sBGzrSQCUc7sT+3+6FBbv/JRJfFjYIPrwa8x1b8vmo5aT/W fz+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2p2ZfklHVEaOI9/2iCtD+yerzjFCKwVXOTunjKilUyg=; b=smN3qBO1sdjsXT7HUfFydkIDbkuAr6/02YufkbaXdu+3XWAzI25KL0vwwtzJr3fTAU k/7uSSMFCKb0zt8o5n+LX9J3IKixEoJ50YvRc6E/l4F/VVz/dNv+ahYI8E6D0wvjPglC lv+VWADLbm82iqoVcZTq2LEeM2guFrX4oS84MJE0VLQvbBhREvl/gObTzbO7HsnWNZNU 1fW3ZvPK+GilkEK9oI3Ohb/x/SH1RtYzI/mkZvsAL9tKJjRNcFqev8oH12W6SDN9wrN6 LWyksY2hV6Vkk9HZP4wAUT8u3HUzEUpgn63n6TqV2EpsNbU3EolUkk1AL8zcRX+6NZl/ hCPw== X-Gm-Message-State: APjAAAUOSnUZ40MS/2RdlhswDRNHBSfO4AAyPuUcr2OsTWoyJOx5I81U WnYqgxF2rA+NTIarUEan3H3raaJsNdOaMciVAVs= X-Received: by 2002:a50:eb8f:: with SMTP id y15mr73599212edr.31.1563997910491; Wed, 24 Jul 2019 12:51:50 -0700 (PDT) MIME-Version: 1.0 References: <20190724165803.87470-1-brianvv@google.com> <20190724165803.87470-5-brianvv@google.com> In-Reply-To: <20190724165803.87470-5-brianvv@google.com> From: Willem de Bruijn Date: Wed, 24 Jul 2019 15:51:14 -0400 Message-ID: Subject: Re: [PATCH bpf-next 4/6] libbpf: support BPF_MAP_DUMP command To: Brian Vazquez Cc: Brian Vazquez , Alexei Starovoitov , Daniel Borkmann , "David S . Miller" , Stanislav Fomichev , Willem de Bruijn , Petar Penkov , LKML , Network Development , bpf 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 On Wed, Jul 24, 2019 at 1:10 PM Brian Vazquez wrote: > > 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)); > +} This can call bpf_map_dump_flags internally to avoid code duplication? > + > +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)); > +} > +