bpf

file: /proc/sys/kernel/bpf
variable: kernel.bpf
Official reference

This snippet shows how to declare a bloom filter in a BPF program:

.. code-block:: c

struct {
        __uint(type, BPF_MAP_TYPE_BLOOM_FILTER);
        __type(value, __u32);
        __uint(max_entries, 1000);
        __uint(map_extra, 3);
} bloom_filter SEC(".maps");

This snippet shows how to determine presence of a value in a bloom filter in a BPF program:

.. code-block:: c

void *lookup(__u32 key)
{
        if (bpf_map_peek_elem(&bloom_filter, &key) == 0) {
                /* Verify not a false positive and fetch an associated
                 * value using a secondary lookup, e.g. in a hash table
                 */
                return bpf_map_lookup_elem(&hash_table, &key);
        }
        return 0;
}