€•fŒsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ(/translations/zh_CN/bpf/map_bloom_filter”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/zh_TW/bpf/map_bloom_filter”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/it_IT/bpf/map_bloom_filter”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/ja_JP/bpf/map_bloom_filter”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/ko_KR/bpf/map_bloom_filter”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/pt_BR/bpf/map_bloom_filter”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ(/translations/sp_SP/bpf/map_bloom_filter”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒcomment”“”)”}”(hŒ%SPDX-License-Identifier: GPL-2.0-only”h]”hŒ%SPDX-License-Identifier: GPL-2.0-only”…””}”hh·sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1hµhhh²hh³ŒB/var/lib/git/docbuild/linux/Documentation/bpf/map_bloom_filter.rst”h´Kubh¶)”}”(hŒ Copyright (C) 2022 Red Hat, Inc.”h]”hŒ Copyright (C) 2022 Red Hat, Inc.”…””}”hhÈsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1hµhhh²hh³hÇh´KubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒBPF_MAP_TYPE_BLOOM_FILTER”h]”hŒBPF_MAP_TYPE_BLOOM_FILTER”…””}”(hhÝh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhhØh²hh³hÇh´KubhŒnote”“”)”}”(hŒE- ``BPF_MAP_TYPE_BLOOM_FILTER`` was introduced in kernel version 5.16”h]”hŒ bullet_list”“”)”}”(hhh]”hŒ list_item”“”)”}”(hŒC``BPF_MAP_TYPE_BLOOM_FILTER`` was introduced in kernel version 5.16”h]”hŒ paragraph”“”)”}”(hhúh]”(hŒliteral”“”)”}”(hŒ``BPF_MAP_TYPE_BLOOM_FILTER``”h]”hŒBPF_MAP_TYPE_BLOOM_FILTER”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhhþubhŒ& was introduced in kernel version 5.16”…””}”(hhþh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K hhøubah}”(h]”h ]”h"]”h$]”h&]”uh1höhhóubah}”(h]”h ]”h"]”h$]”h&]”Œbullet”Œ-”uh1hñh³hÇh´K hhíubah}”(h]”h ]”h"]”h$]”h&]”uh1hëhhØh²hh³Nh´Nubhý)”}”(hX ``BPF_MAP_TYPE_BLOOM_FILTER`` provides a BPF bloom filter map. Bloom filters are a space-efficient probabilistic data structure used to quickly test whether an element exists in a set. In a bloom filter, false positives are possible whereas false negatives are not.”h]”(j)”}”(hŒ``BPF_MAP_TYPE_BLOOM_FILTER``”h]”hŒBPF_MAP_TYPE_BLOOM_FILTER”…””}”(hj3h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj/ubhŒì provides a BPF bloom filter map. Bloom filters are a space-efficient probabilistic data structure used to quickly test whether an element exists in a set. In a bloom filter, false positives are possible whereas false negatives are not.”…””}”(hj/h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K hhØh²hubhý)”}”(hŒ·The bloom filter map does not have keys, only values. When the bloom filter map is created, it must be created with a ``key_size`` of 0. The bloom filter map supports two operations:”h]”(hŒvThe bloom filter map does not have keys, only values. When the bloom filter map is created, it must be created with a ”…””}”(hjKh²hh³Nh´Nubj)”}”(hŒ ``key_size``”h]”hŒkey_size”…””}”(hjSh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjKubhŒ5 of 0. The bloom filter map supports two operations:”…””}”(hjKh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´KhhØh²hubhò)”}”(hhh]”(h÷)”}”(hŒ"push: adding an element to the map”h]”hý)”}”(hjph]”hŒ"push: adding an element to the map”…””}”(hjrh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´Khjnubah}”(h]”h ]”h"]”h$]”h&]”uh1höhjkh²hh³hÇh´Nubh÷)”}”(hŒ;peek: determining whether an element is present in the map ”h]”hý)”}”(hŒ:peek: determining whether an element is present in the map”h]”hŒ:peek: determining whether an element is present in the map”…””}”(hj‰h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´Khj…ubah}”(h]”h ]”h"]”h$]”h&]”uh1höhjkh²hh³hÇh´Nubeh}”(h]”h ]”h"]”h$]”h&]”j'j(uh1hñh³hÇh´KhhØh²hubhý)”}”(hŒñBPF programs must use ``bpf_map_push_elem`` to add an element to the bloom filter map and ``bpf_map_peek_elem`` to query the map. These operations are exposed to userspace applications using the existing ``bpf`` syscall in the following way:”h]”(hŒBPF programs must use ”…””}”(hj£h²hh³Nh´Nubj)”}”(hŒ``bpf_map_push_elem``”h]”hŒbpf_map_push_elem”…””}”(hj«h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj£ubhŒ/ to add an element to the bloom filter map and ”…””}”(hj£h²hh³Nh´Nubj)”}”(hŒ``bpf_map_peek_elem``”h]”hŒbpf_map_peek_elem”…””}”(hj½h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj£ubhŒ] to query the map. These operations are exposed to userspace applications using the existing ”…””}”(hj£h²hh³Nh´Nubj)”}”(hŒ``bpf``”h]”hŒbpf”…””}”(hjÏh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj£ubhŒ syscall in the following way:”…””}”(hj£h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´KhhØh²hubhò)”}”(hhh]”(h÷)”}”(hŒ``BPF_MAP_UPDATE_ELEM`` -> push”h]”hý)”}”(hjìh]”(j)”}”(hŒ``BPF_MAP_UPDATE_ELEM``”h]”hŒBPF_MAP_UPDATE_ELEM”…””}”(hjñh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjîubhŒ -> push”…””}”(hjîh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´Khjêubah}”(h]”h ]”h"]”h$]”h&]”uh1höhjçh²hh³hÇh´Nubh÷)”}”(hŒ ``BPF_MAP_LOOKUP_ELEM`` -> peek ”h]”hý)”}”(hŒ``BPF_MAP_LOOKUP_ELEM`` -> peek”h]”(j)”}”(hŒ``BPF_MAP_LOOKUP_ELEM``”h]”hŒBPF_MAP_LOOKUP_ELEM”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjubhŒ -> peek”…””}”(hjh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´Khjubah}”(h]”h ]”h"]”h$]”h&]”uh1höhjçh²hh³hÇh´Nubeh}”(h]”h ]”h"]”h$]”h&]”j'j(uh1hñh³hÇh´KhhØh²hubhý)”}”(hX2The ``max_entries`` size that is specified at map creation time is used to approximate a reasonable bitmap size for the bloom filter, and is not otherwise strictly enforced. If the user wishes to insert more entries into the bloom filter than ``max_entries``, this may lead to a higher false positive rate.”h]”(hŒThe ”…””}”(hj;h²hh³Nh´Nubj)”}”(hŒ``max_entries``”h]”hŒ max_entries”…””}”(hjCh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj;ubhŒà size that is specified at map creation time is used to approximate a reasonable bitmap size for the bloom filter, and is not otherwise strictly enforced. If the user wishes to insert more entries into the bloom filter than ”…””}”(hj;h²hh³Nh´Nubj)”}”(hŒ``max_entries``”h]”hŒ max_entries”…””}”(hjUh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj;ubhŒ0, this may lead to a higher false positive rate.”…””}”(hj;h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´KhhØh²hubhý)”}”(hX:The number of hashes to use for the bloom filter is configurable using the lower 4 bits of ``map_extra`` in ``union bpf_attr`` at map creation time. If no number is specified, the default used will be 5 hash functions. In general, using more hashes decreases both the false positive rate and the speed of a lookup.”h]”(hŒ[The number of hashes to use for the bloom filter is configurable using the lower 4 bits of ”…””}”(hjmh²hh³Nh´Nubj)”}”(hŒ ``map_extra``”h]”hŒ map_extra”…””}”(hjuh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjmubhŒ in ”…””}”(hjmh²hh³Nh´Nubj)”}”(hŒ``union bpf_attr``”h]”hŒunion bpf_attr”…””}”(hj‡h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjmubhŒ¼ at map creation time. If no number is specified, the default used will be 5 hash functions. In general, using more hashes decreases both the false positive rate and the speed of a lookup.”…””}”(hjmh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K%hhØh²hubhý)”}”(hŒâIt is not possible to delete elements from a bloom filter map. A bloom filter map may be used as an inner map. The user is responsible for synchronising concurrent updates and lookups to ensure no false negative lookups occur.”h]”hŒâIt is not possible to delete elements from a bloom filter map. A bloom filter map may be used as an inner map. The user is responsible for synchronising concurrent updates and lookups to ensure no false negative lookups occur.”…””}”(hjŸh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K+hhØh²hubh×)”}”(hhh]”(hÜ)”}”(hŒUsage”h]”hŒUsage”…””}”(hj°h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj­h²hh³hÇh´K1ubh×)”}”(hhh]”(hÜ)”}”(hŒ Kernel BPF”h]”hŒ Kernel BPF”…””}”(hjÁh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj¾h²hh³hÇh´K4ubh×)”}”(hhh]”(hÜ)”}”(hŒbpf_map_push_elem()”h]”hŒbpf_map_push_elem()”…””}”(hjÒh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhjÏh²hh³hÇh´K7ubhŒ literal_block”“”)”}”(hŒIlong bpf_map_push_elem(struct bpf_map *map, const void *value, u64 flags)”h]”hŒIlong bpf_map_push_elem(struct bpf_map *map, const void *value, u64 flags)”…””}”hjâsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆŒforce”‰Œlanguage”Œc”Œhighlight_args”}”uh1jàh³hÇh´K9hjÏh²hubhý)”}”(hŒýA ``value`` can be added to a bloom filter using the ``bpf_map_push_elem()`` helper. The ``flags`` parameter must be set to ``BPF_ANY`` when adding an entry to the bloom filter. This helper returns ``0`` on success, or negative error in case of failure.”h]”(hŒA ”…””}”(hjõh²hh³Nh´Nubj)”}”(hŒ ``value``”h]”hŒvalue”…””}”(hjýh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ* can be added to a bloom filter using the ”…””}”(hjõh²hh³Nh´Nubj)”}”(hŒ``bpf_map_push_elem()``”h]”hŒbpf_map_push_elem()”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ helper. The ”…””}”(hjõh²hh³Nh´Nubj)”}”(hŒ ``flags``”h]”hŒflags”…””}”(hj!h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ parameter must be set to ”…””}”(hjõh²hh³Nh´Nubj)”}”(hŒ ``BPF_ANY``”h]”hŒBPF_ANY”…””}”(hj3h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ? when adding an entry to the bloom filter. This helper returns ”…””}”(hjõh²hh³Nh´Nubj)”}”(hŒ``0``”h]”hŒ0”…””}”(hjEh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ2 on success, or negative error in case of failure.”…””}”(hjõh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K=hjÏh²hubeh}”(h]”Œbpf-map-push-elem”ah ]”h"]”Œbpf_map_push_elem()”ah$]”h&]”uh1hÖhj¾h²hh³hÇh´K7ubh×)”}”(hhh]”(hÜ)”}”(hŒbpf_map_peek_elem()”h]”hŒbpf_map_peek_elem()”…””}”(hjhh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhjeh²hh³hÇh´KCubjá)”}”(hŒ8long bpf_map_peek_elem(struct bpf_map *map, void *value)”h]”hŒ8long bpf_map_peek_elem(struct bpf_map *map, void *value)”…””}”hjvsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjð‰jñjòjó}”uh1jàh³hÇh´KEhjeh²hubhý)”}”(hŒöThe ``bpf_map_peek_elem()`` helper is used to determine whether ``value`` is present in the bloom filter map. This helper returns ``0`` if ``value`` is probably present in the map, or ``-ENOENT`` if ``value`` is definitely not present in the map.”h]”(hŒThe ”…””}”(hj…h²hh³Nh´Nubj)”}”(hŒ``bpf_map_peek_elem()``”h]”hŒbpf_map_peek_elem()”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj…ubhŒ% helper is used to determine whether ”…””}”(hj…h²hh³Nh´Nubj)”}”(hŒ ``value``”h]”hŒvalue”…””}”(hjŸh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj…ubhŒ9 is present in the bloom filter map. This helper returns ”…””}”(hj…h²hh³Nh´Nubj)”}”(hŒ``0``”h]”hŒ0”…””}”(hj±h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj…ubhŒ if ”…””}”(hj…h²hh³Nh´Nubj)”}”(hŒ ``value``”h]”hŒvalue”…””}”(hjÃh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj…ubhŒ$ is probably present in the map, or ”…””}”(hj…h²hh³Nh´Nubj)”}”(hŒ ``-ENOENT``”h]”hŒ-ENOENT”…””}”(hjÕh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj…ubhŒ if ”…””}”(hj…h²hh³Nh´Nubj)”}”(hŒ ``value``”h]”hŒvalue”…””}”(hjçh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhj…ubhŒ& is definitely not present in the map.”…””}”(hj…h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´KIhjeh²hubeh}”(h]”Œbpf-map-peek-elem”ah ]”h"]”Œbpf_map_peek_elem()”ah$]”h&]”uh1hÖhj¾h²hh³hÇh´KCubeh}”(h]”Œ kernel-bpf”ah ]”h"]”h$]”Œ kernel bpf”ah&]”uh1hÖhj­h²hh³hÇh´K4Œ referenced”Kubh×)”}”(hhh]”(hÜ)”}”(hŒ Userspace”h]”hŒ Userspace”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhjh²hh³hÇh´KOubh×)”}”(hhh]”(hÜ)”}”(hŒbpf_map_update_elem()”h]”hŒbpf_map_update_elem()”…””}”(hj$h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj!h²hh³hÇh´KRubjá)”}”(hŒQint bpf_map_update_elem (int fd, const void *key, const void *value, __u64 flags)”h]”hŒQint bpf_map_update_elem (int fd, const void *key, const void *value, __u64 flags)”…””}”hj2sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjð‰jñjòjó}”uh1jàh³hÇh´KThj!h²hubhý)”}”(hXA userspace program can add a ``value`` to a bloom filter using libbpf's ``bpf_map_update_elem`` function. The ``key`` parameter must be set to ``NULL`` and ``flags`` must be set to ``BPF_ANY``. Returns ``0`` on success, or negative error in case of failure.”h]”(hŒA userspace program can add a ”…””}”(hjAh²hh³Nh´Nubj)”}”(hŒ ``value``”h]”hŒvalue”…””}”(hjIh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjAubhŒ$ to a bloom filter using libbpf’s ”…””}”(hjAh²hh³Nh´Nubj)”}”(hŒ``bpf_map_update_elem``”h]”hŒbpf_map_update_elem”…””}”(hj[h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjAubhŒ function. The ”…””}”(hjAh²hh³Nh´Nubj)”}”(hŒ``key``”h]”hŒkey”…””}”(hjmh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjAubhŒ parameter must be set to ”…””}”(hjAh²hh³Nh´Nubj)”}”(hŒ``NULL``”h]”hŒNULL”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjAubhŒ and ”…””}”(hjAh²hh³Nh´Nubj)”}”(hŒ ``flags``”h]”hŒflags”…””}”(hj‘h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjAubhŒ must be set to ”…””}”(hjAh²hh³Nh´Nubj)”}”(hŒ ``BPF_ANY``”h]”hŒBPF_ANY”…””}”(hj£h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjAubhŒ . Returns ”…””}”(hjAh²hh³Nh´Nubj)”}”(hŒ``0``”h]”hŒ0”…””}”(hjµh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjAubhŒ2 on success, or negative error in case of failure.”…””}”(hjAh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´KXhj!h²hubeh}”(h]”Œbpf-map-update-elem”ah ]”h"]”Œbpf_map_update_elem()”ah$]”h&]”uh1hÖhjh²hh³hÇh´KRubh×)”}”(hhh]”(hÜ)”}”(hŒbpf_map_lookup_elem()”h]”hŒbpf_map_lookup_elem()”…””}”(hjØh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhjÕh²hh³hÇh´K^ubjá)”}”(hŒ>int bpf_map_lookup_elem (int fd, const void *key, void *value)”h]”hŒ>int bpf_map_lookup_elem (int fd, const void *key, void *value)”…””}”hjæsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjð‰jñjòjó}”uh1jàh³hÇh´K`hjÕh²hubhý)”}”(hX*A userspace program can determine the presence of ``value`` in a bloom filter using libbpf's ``bpf_map_lookup_elem`` function. The ``key`` parameter must be set to ``NULL``. Returns ``0`` if ``value`` is probably present in the map, or ``-ENOENT`` if ``value`` is definitely not present in the map.”h]”(hŒ2A userspace program can determine the presence of ”…””}”(hjõh²hh³Nh´Nubj)”}”(hŒ ``value``”h]”hŒvalue”…””}”(hjýh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ$ in a bloom filter using libbpf’s ”…””}”(hjõh²hh³Nh´Nubj)”}”(hŒ``bpf_map_lookup_elem``”h]”hŒbpf_map_lookup_elem”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ function. The ”…””}”(hjõh²hh³Nh´Nubj)”}”(hŒ``key``”h]”hŒkey”…””}”(hj!h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ parameter must be set to ”…””}”(hjõh²hh³Nh´Nubj)”}”(hŒ``NULL``”h]”hŒNULL”…””}”(hj3h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ . Returns ”…””}”(hjõh²hh³Nh´Nubj)”}”(hŒ``0``”h]”hŒ0”…””}”(hjEh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ if ”…””}”(hjõh²hh³Nh´Nubj)”}”(hŒ ``value``”h]”hŒvalue”…””}”(hjWh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ$ is probably present in the map, or ”…””}”(hjõh²hh³Nh´Nubj)”}”(hŒ ``-ENOENT``”h]”hŒ-ENOENT”…””}”(hjih²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ if ”…””}”hjõsbj)”}”(hŒ ``value``”h]”hŒvalue”…””}”(hj{h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jhjõubhŒ& is definitely not present in the map.”…””}”(hjõh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´KdhjÕh²hubeh}”(h]”Œbpf-map-lookup-elem”ah ]”h"]”Œbpf_map_lookup_elem()”ah$]”h&]”uh1hÖhjh²hh³hÇh´K^ubeh}”(h]”Œ userspace”ah ]”h"]”h$]”Œ userspace”ah&]”uh1hÖhj­h²hh³hÇh´KOjKubeh}”(h]”Œusage”ah ]”h"]”Œusage”ah$]”h&]”uh1hÖhhØh²hh³hÇh´K1ubh×)”}”(hhh]”(hÜ)”}”(hŒExamples”h]”hŒExamples”…””}”(hj®h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj«h²hh³hÇh´Kkubh×)”}”(hhh]”(hÜ)”}”(hŒ Kernel BPF”h]”hŒ Kernel BPF”…””}”(hj¿h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj¼h²hh³hÇh´Knubhý)”}”(hŒBThis snippet shows how to declare a bloom filter in a BPF program:”h]”hŒBThis snippet shows how to declare a bloom filter in a BPF program:”…””}”(hjÍh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´Kphj¼h²hubjá)”}”(hŒµstruct { __uint(type, BPF_MAP_TYPE_BLOOM_FILTER); __type(value, __u32); __uint(max_entries, 1000); __uint(map_extra, 3); } bloom_filter SEC(".maps");”h]”hŒµstruct { __uint(type, BPF_MAP_TYPE_BLOOM_FILTER); __type(value, __u32); __uint(max_entries, 1000); __uint(map_extra, 3); } bloom_filter SEC(".maps");”…””}”hjÛsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjð‰jñjòjó}”uh1jàh³hÇh´Krhj¼h²hubhý)”}”(hŒ[This snippet shows how to determine presence of a value in a bloom filter in a BPF program:”h]”hŒ[This snippet shows how to determine presence of a value in a bloom filter in a BPF program:”…””}”(hjêh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K{hj¼h²hubjá)”}”(hXTvoid *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; }”h]”hXTvoid *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; }”…””}”hjøsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjð‰jñjòjó}”uh1jàh³hÇh´K~hj¼h²hubeh}”(h]”Œid1”ah ]”h"]”h$]”j ah&]”uh1hÖhj«h²hh³hÇh´KnjKubh×)”}”(hhh]”(hÜ)”}”(hŒ Userspace”h]”hŒ Userspace”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhjh²hh³hÇh´KŒubhý)”}”(hŒQThis snippet shows how to use libbpf to create a bloom filter map from userspace:”h]”hŒQThis snippet shows how to use libbpf to create a bloom filter map from userspace:”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´KŽhjh²hubjá)”}”(hXint create_bloom() { LIBBPF_OPTS(bpf_map_create_opts, opts, .map_extra = 3); /* number of hashes */ return bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, "ipv6_bloom", /* name */ 0, /* key size, must be zero */ sizeof(ipv6_addr), /* value size */ 10000, /* max entries */ &opts); /* create options */ }”h]”hXint create_bloom() { LIBBPF_OPTS(bpf_map_create_opts, opts, .map_extra = 3); /* number of hashes */ return bpf_map_create(BPF_MAP_TYPE_BLOOM_FILTER, "ipv6_bloom", /* name */ 0, /* key size, must be zero */ sizeof(ipv6_addr), /* value size */ 10000, /* max entries */ &opts); /* create options */ }”…””}”hj-sbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjð‰jñjòjó}”uh1jàh³hÇh´K‘hjh²hubhý)”}”(hŒJThis snippet shows how to add an element to a bloom filter from userspace:”h]”hŒJThis snippet shows how to add an element to a bloom filter from userspace:”…””}”(hj<h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K hjh²hubjá)”}”(hŒ¯int add_element(struct bpf_map *bloom_map, __u32 value) { int bloom_fd = bpf_map__fd(bloom_map); return bpf_map_update_elem(bloom_fd, NULL, &value, BPF_ANY); }”h]”hŒ¯int add_element(struct bpf_map *bloom_map, __u32 value) { int bloom_fd = bpf_map__fd(bloom_map); return bpf_map_update_elem(bloom_fd, NULL, &value, BPF_ANY); }”…””}”hjJsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆjð‰jñjòjó}”uh1jàh³hÇh´K£hjh²hubeh}”(h]”Œid2”ah ]”h"]”h$]”j¡ah&]”uh1hÖhj«h²hh³hÇh´KŒjKubeh}”(h]”Œexamples”ah ]”h"]”Œexamples”ah$]”h&]”uh1hÖhhØh²hh³hÇh´Kkubh×)”}”(hhh]”(hÜ)”}”(hŒ References”h]”hŒ References”…””}”(hjkh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhjhh²hh³hÇh´K¬ubhý)”}”(hŒChttps://lwn.net/ml/bpf/20210831225005.2762202-1-joannekoong@fb.com/”h]”hŒ reference”“”)”}”(hj{h]”hŒChttps://lwn.net/ml/bpf/20210831225005.2762202-1-joannekoong@fb.com/”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefuri”j{uh1j}hjyubah}”(h]”h ]”h"]”h$]”h&]”uh1hüh³hÇh´K®hjhh²hubeh}”(h]”Œ references”ah ]”h"]”Œ references”ah$]”h&]”uh1hÖhhØh²hh³hÇh´K¬ubeh}”(h]”Œbpf-map-type-bloom-filter”ah ]”h"]”Œbpf_map_type_bloom_filter”ah$]”h&]”uh1hÖhhh²hh³hÇh´Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÇuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(hÛNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jÆŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÇŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(j jj¨j¥Œ kernel bpf”Njbj_jjŒ userspace”NjÒjÏj˜j•jejbj˜j•uŒ nametypes”}”(j ‰j¨‰j ‰jb‰j‰j ‰jÒ‰j˜‰je‰j˜‰uh}”(jhØj¥j­j j¾j_jÏjjejjjÏj!j•jÕjbj«j j¼j[jj•jhuŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”jÔKs…”R”Œparse_messages”]”(hŒsystem_message”“”)”}”(hhh]”hý)”}”(hŒ-Duplicate implicit target name: "kernel bpf".”h]”hŒ1Duplicate implicit target name: “kernel bpfâ€.”…””}”(hj/h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hühj,ubah}”(h]”h ]”h"]”h$]”h&]”j aŒlevel”KŒtype”ŒINFO”Œsource”hÇŒline”Knuh1j*hj¼h²hh³hÇh´Knubj+)”}”(hhh]”hý)”}”(hŒ,Duplicate implicit target name: "userspace".”h]”hŒ0Duplicate implicit target name: “userspaceâ€.”…””}”(hjKh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hühjHubah}”(h]”h ]”h"]”h$]”h&]”j[aŒlevel”KŒtype”jEŒsource”hÇŒline”KŒuh1j*hjh²hh³hÇh´KŒubeŒtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nh²hub.