Helper function bpf_map_delete_elem
The delete map element helper call is used to delete values from maps.
Note
This helper function is only callable from eBPF, but has the same name as the bpf_map_delete_elem userspace library function, which can only be used from userspace programs.
Definition
Copyright (c) 2015 The Libbpf Authors. All rights reserved.
Delete entry with key from map.
Returns
0 on success, or a negative error in case of failure.
static long (* const bpf_map_delete_elem)(void *map, const void *key) = (void *) 3;
Usage
The map argument must be a pointer to a map definition and key must be a pointer to the key you
wish to delete.
The return value will be 0 on success or a negative valued error number indicating a failure.
Program types
This helper call can be used in the following program types:
BPF_PROG_TYPE_CGROUP_DEVICEBPF_PROG_TYPE_CGROUP_SKBBPF_PROG_TYPE_CGROUP_SOCKBPF_PROG_TYPE_CGROUP_SOCKOPTBPF_PROG_TYPE_CGROUP_SOCK_ADDRBPF_PROG_TYPE_CGROUP_SYSCTLBPF_PROG_TYPE_FLOW_DISSECTORBPF_PROG_TYPE_KPROBEBPF_PROG_TYPE_LIRC_MODE2BPF_PROG_TYPE_LSMBPF_PROG_TYPE_LWT_INBPF_PROG_TYPE_LWT_OUTBPF_PROG_TYPE_LWT_SEG6LOCALBPF_PROG_TYPE_LWT_XMITBPF_PROG_TYPE_NETFILTERBPF_PROG_TYPE_PERF_EVENTBPF_PROG_TYPE_RAW_TRACEPOINTBPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLEBPF_PROG_TYPE_SCHED_ACTBPF_PROG_TYPE_SCHED_CLSBPF_PROG_TYPE_SK_LOOKUPBPF_PROG_TYPE_SK_MSGBPF_PROG_TYPE_SK_REUSEPORTBPF_PROG_TYPE_SK_SKBBPF_PROG_TYPE_SOCKET_FILTERBPF_PROG_TYPE_SOCK_OPSBPF_PROG_TYPE_STRUCT_OPSBPF_PROG_TYPE_SYSCALLBPF_PROG_TYPE_TRACEPOINTBPF_PROG_TYPE_TRACINGBPF_PROG_TYPE_XDP
Map types
This helper call can be used with the following map types:
Example
#include "vmlinux.sh"
#include <bpf/bpf_helpers.h>
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, u32);
__type(value, u32);
__uint(max_entries, 10240);
} cnt_map SEC(".maps");
SEC("tracepoints/syscalls/sys_enter_openat")
int bpf_prog1(void *ctx)
{
u32 pid = bpf_get_current_pid_tgid();
u32 init_val=0;
u32 *cnt = bpf_map_lookup_elem(&cnt_map, &pid);
if(cnt){
__sync_fetch_and_add(cnt, 1);
}else{
bpf_map_update_elem(&cnt_map, &pid, &init_val, BPF_ANY);
return 0;
}
if(*cnt == 42)
bpf_map_delete_elem(&cnt_map, &pid);
return 0;
}
char LICENSE[] SEC("license") = "GPL"