From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933291AbbLQGKU (ORCPT ); Thu, 17 Dec 2015 01:10:20 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:38022 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932239AbbLQGKS (ORCPT ); Thu, 17 Dec 2015 01:10:18 -0500 From: Wang Nan To: , , , , , , , , , , , CC: , , Wang Nan Subject: [PATCH v2 06/10] bpf tools: Support new map operations Date: Thu, 17 Dec 2015 06:09:30 +0000 Message-ID: <1450332570-164744-1-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1450329794-161948-7-git-send-email-wangnan0@huawei.com> References: <1450329794-161948-7-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.567251B4.00E7,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 4a51f0270e5df6e7d545c52a1f316ed8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add bpf_map_lookup_elem(), bpf_map_delete_elem() and bpf_map_get_next_key() to libbpf so it can issue all BPF map operations. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo --- v1 -> v2: Remove tailing whitespaces. --- tools/lib/bpf/bpf.c | 32 ++++++++++++++++++++++++++++++++ tools/lib/bpf/bpf.h | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index e0dccea..b8e7aaa 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -97,3 +97,35 @@ int bpf_map_update_elem(int fd, void *key, void *value, return sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, sizeof(attr)); } + +int bpf_map_lookup_elem(int fd, void *key, void *value) +{ + union bpf_attr attr = { + .map_fd = fd, + .key = ptr_to_u64(key), + .value = ptr_to_u64(value), + }; + + return sys_bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr)); +} + +int bpf_map_delete_elem(int fd, void *key) +{ + union bpf_attr attr = { + .map_fd = fd, + .key = ptr_to_u64(key), + }; + + return sys_bpf(BPF_MAP_DELETE_ELEM, &attr, sizeof(attr)); +} + +int bpf_map_get_next_key(int fd, void *key, void *next_key) +{ + union bpf_attr attr = { + .map_fd = fd, + .key = ptr_to_u64(key), + .next_key = ptr_to_u64(next_key), + }; + + return sys_bpf(BPF_MAP_GET_NEXT_KEY, &attr, sizeof(attr)); +} diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 01a421a..3d22048 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -23,4 +23,8 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, int bpf_map_update_elem(int fd, void *key, void *value, __u64 flags); + +int bpf_map_lookup_elem(int fd, void *key, void *value); +int bpf_map_delete_elem(int fd, void *key); +int bpf_map_get_next_key(int fd, void *key, void *next_key); #endif -- 1.8.3.4