rsphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget"/translations/zh_CN/bpf/map_xskmapmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/zh_TW/bpf/map_xskmapmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/it_IT/bpf/map_xskmapmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/ja_JP/bpf/map_xskmapmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/ko_KR/bpf/map_xskmapmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hPortuguese (Brazilian)}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/pt_BR/bpf/map_xskmapmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget"/translations/sp_SP/bpf/map_xskmapmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h%SPDX-License-Identifier: GPL-2.0-onlyh]h%SPDX-License-Identifier: GPL-2.0-only}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhh+-------------+-------------+ | | prog | | 2 | xsk C | | | | | +-------------+ | | | | | | | | | | +---------+ | | | +---------------------------------------------------+h]hX+---------------------------------------------------+ | xsk A | xsk B | xsk C |<---+ User space =========================================================|========== | Queue 0 | Queue 1 | Queue 2 | | Kernel +---------------------------------------------------+ | | Netdev eth0 | | +---------------------------------------------------+ | | +=============+ | | | | key | xsk | | | | +---------+ +=============+ | | | | | | 0 | xsk A | | | | | | +-------------+ | | | | | | 1 | xsk B | | | | | BPF |-- redirect -->+-------------+-------------+ | | prog | | 2 | xsk C | | | | | +-------------+ | | | | | | | | | | +---------+ | | | +---------------------------------------------------+}hjsbah}(h]h ]h"]h$]h&]hhƌforcelanguagenonehighlight_args}uh1jhhhKhhhhubh)}(hX An AF_XDP socket that is bound to a certain will *only* accept XDP frames from that . If an XDP program tries to redirect from a other than what the socket is bound to, the frame will not be received on the socket.h]h)}(hX An AF_XDP socket that is bound to a certain will *only* accept XDP frames from that . If an XDP program tries to redirect from a other than what the socket is bound to, the frame will not be received on the socket.h](hCAn AF_XDP socket that is bound to a certain will }(hjhhhNhNubhemphasis)}(h*only*h]honly}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh accept XDP frames from that . If an XDP program tries to redirect from a other than what the socket is bound to, the frame will not be received on the socket.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK+hjubah}(h]h ]h"]h$]h&]uh1hhhhhhhhNubh)}(hXTypically an XSKMAP is created per netdev. This map contains an array of XSK File Descriptors (FDs). The number of array elements is typically set or adjusted using the ``max_entries`` map parameter. For AF_XDP ``max_entries`` is equal to the number of queues supported by the netdev.h](hTypically an XSKMAP is created per netdev. This map contains an array of XSK File Descriptors (FDs). The number of array elements is typically set or adjusted using the }(hjhhhNhNubj)}(h``max_entries``h]h max_entries}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh map parameter. For AF_XDP }(hjhhhNhNubj)}(h``max_entries``h]h max_entries}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh: is equal to the number of queues supported by the netdev.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK0hhhhubh)}(h4Both the map key and map value size must be 4 bytes.h]h)}(hjh]h4Both the map key and map value size must be 4 bytes.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK6hjubah}(h]h ]h"]h$]h&]uh1hhhhhhhhNubh)}(hhh](h)}(hUsageh]hUsage}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK9ubh)}(hhh](h)}(h Kernel BPFh]h Kernel BPF}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj'hhhhhKubj)}(h>long bpf_redirect_map(struct bpf_map *map, u32 key, u64 flags)h]h>long bpf_redirect_map(struct bpf_map *map, u32 key, u64 flags)}hjIsbah}(h]h ]h"]h$]h&]hhjjcj}uh1jhhhK?hj8hhubh)}(hRedirect the packet to the endpoint referenced by ``map`` at index ``key``. For ``BPF_MAP_TYPE_XSKMAP`` this map contains references to XSK FDs for sockets attached to a netdev's queues.h](h2Redirect the packet to the endpoint referenced by }(hjYhhhNhNubj)}(h``map``h]hmap}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1jhjYubh at index }(hjYhhhNhNubj)}(h``key``h]hkey}(hjshhhNhNubah}(h]h ]h"]h$]h&]uh1jhjYubh. For }(hjYhhhNhNubj)}(h``BPF_MAP_TYPE_XSKMAP``h]hBPF_MAP_TYPE_XSKMAP}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjYubhU this map contains references to XSK FDs for sockets attached to a netdev’s queues.}(hjYhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKChj8hhubh)}(hIf the map is empty at an index, the packet is dropped. This means that it is necessary to have an XDP program loaded with at least one XSK in the XSKMAP to be able to get any traffic to user space through the socket.h]h)}(hIf the map is empty at an index, the packet is dropped. This means that it is necessary to have an XDP program loaded with at least one XSK in the XSKMAP to be able to get any traffic to user space through the socket.h]hIf the map is empty at an index, the packet is dropped. This means that it is necessary to have an XDP program loaded with at least one XSK in the XSKMAP to be able to get any traffic to user space through the socket.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKHhjubah}(h]h ]h"]h$]h&]uh1hhj8hhhhhNubeh}(h]bpf-redirect-mapah ]h"]bpf_redirect_map()ah$]h&]uh1hhj'hhhhhK>ubh)}(hhh](h)}(hbpf_map_lookup_elem()h]hbpf_map_lookup_elem()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKMubj)}(h?void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)h]h?void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)}hjsbah}(h]h ]h"]h$]h&]hhjjjWj}uh1jhhhKNhjhhubh)}(hoXSK entry references of type ``struct xdp_sock *`` can be retrieved using the ``bpf_map_lookup_elem()`` helper.h](hXSK entry references of type }(hjhhhNhNubj)}(h``struct xdp_sock *``h]hstruct xdp_sock *}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh can be retrieved using the }(hjhhhNhNubj)}(h``bpf_map_lookup_elem()``h]hbpf_map_lookup_elem()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh helper.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKRhjhhubeh}(h]bpf-map-lookup-elemah ]h"]h$]bpf_map_lookup_elem()ah&]uh1hhj'hhhhhKM referencedKubeh}(h] kernel-bpfah ]h"] kernel bpfah$]h&]uh1hhjhhhhhKrx_queue_index; if (bpf_map_lookup_elem(&xsks_map, &index)) return bpf_redirect_map(&xsks_map, index, 0); return XDP_PASS; }h]hXstruct { __uint(type, BPF_MAP_TYPE_XSKMAP); __type(key, __u32); __type(value, __u32); __uint(max_entries, 64); } xsks_map SEC(".maps"); SEC("xdp") int xsk_redir_prog(struct xdp_md *ctx) { __u32 index = ctx->rx_queue_index; if (bpf_map_lookup_elem(&xsks_map, &index)) return bpf_redirect_map(&xsks_map, index, 0); return XDP_PASS; }}hjRsbah}(h]h ]h"]h$]h&]hhjjjWj}uh1jhhhKhjhhubeh}(h]kernelah ]h"]kernelah$]h&]uh1hhjhhhhhKubh)}(hhh](h)}(h User spaceh]h User space}(hjlhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjihhhhhKubh)}(hKThe following code snippet shows how to update an XSKMAP with an XSK entry.h]hKThe following code snippet shows how to update an XSKMAP with an XSK entry.}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjihhubj)}(hX-int update_xsks_map(struct bpf_map *xsks_map, int queue_id, int xsk_fd) { int ret; ret = bpf_map_update_elem(bpf_map__fd(xsks_map), &queue_id, &xsk_fd, 0); if (ret < 0) fprintf(stderr, "Failed to update xsks_map: %s\n", strerror(errno)); return ret; }h]hX-int update_xsks_map(struct bpf_map *xsks_map, int queue_id, int xsk_fd) { int ret; ret = bpf_map_update_elem(bpf_map__fd(xsks_map), &queue_id, &xsk_fd, 0); if (ret < 0) fprintf(stderr, "Failed to update xsks_map: %s\n", strerror(errno)); return ret; }}hjsbah}(h]h ]h"]h$]h&]hhjjjWj}uh1jhhhKhjihhubh)}(hFor an example on how create AF_XDP sockets, please see the AF_XDP-example and AF_XDP-forwarding programs in the `bpf-examples`_ directory in the `libxdp`_ repository. For a detailed explanation of the AF_XDP interface please see:h](hqFor an example on how create AF_XDP sockets, please see the AF_XDP-example and AF_XDP-forwarding programs in the }(hjhhhNhNubjn)}(h`bpf-examples`_h]h bpf-examples}(hjhhhNhNubah}(h]h ]h"]h$]h&]name bpf-examplesj+https://github.com/xdp-project/bpf-examplesuh1jmhjjKubh directory in the }(hjhhhNhNubjn)}(h `libxdp`_h]hlibxdp}(hjhhhNhNubah}(h]h ]h"]h$]h&]namelibxdpjjuh1jmhjjKubhK repository. For a detailed explanation of the AF_XDP interface please see:}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjihhubh)}(hhh](h)}(h`libxdp-readme`_.h]h)}(hjh](jn)}(h`libxdp-readme`_h]h libxdp-readme}(hjhhhNhNubah}(h]h ]h"]h$]h&]name libxdp-readmejThttps://github.com/xdp-project/xdp-tools/tree/master/lib/libxdp#using-af_xdp-socketsuh1jmhjjKubh.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubh)}(h `AF_XDP`_ kernel documentation. h]h)}(h`AF_XDP`_ kernel documentation.h](jn)}(h `AF_XDP`_h]hAF_XDP}(hjhhhNhNubah}(h]h ]h"]h$]h&]nameAF_XDPjjuh1jmhjjKubh kernel documentation.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjhhhhhNubeh}(h]h ]h"]h$]h&]j'j(uh1hhhhKhjihhubh)}(hJThe most comprehensive resource for using XSKMAPs and AF_XDP is `libxdp`_.h]h)}(hj)h](h@The most comprehensive resource for using XSKMAPs and AF_XDP is }(hj+hhhNhNubjn)}(h `libxdp`_h]hlibxdp}(hj2hhhNhNubah}(h]h ]h"]h$]h&]namelibxdpjjuh1jmhj+jKubh.}(hj+hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhj'ubah}(h]h ]h"]h$]h&]uh1hhjihhhhhNubhtarget)}(hK.. _libxdp: https://github.com/xdp-project/xdp-tools/tree/master/lib/libxdph]h}(h]libxdpah ]h"]libxdpah$]h&]jjuh1jRhKhjihhhhjKubjS)}(hI.. _AF_XDP: https://www.kernel.org/doc/html/latest/networking/af_xdp.htmlh]h}(h]af-xdpah ]h"]af_xdpah$]h&]jjuh1jRhKhjihhhhjKubjS)}(h=.. _bpf-examples: https://github.com/xdp-project/bpf-examplesh]h}(h] bpf-examplesah ]h"] bpf-examplesah$]h&]jjuh1jRhKhjihhhhjKubjS)}(hg.. _libxdp-readme: https://github.com/xdp-project/xdp-tools/tree/master/lib/libxdp#using-af_xdp-socketsh]h}(h] libxdp-readmeah ]h"] libxdp-readmeah$]h&]jjuh1jRhKhjihhhhjKubeh}(h]id2ah ]h"]h$]jah&]uh1hhjhhhhhKjKubeh}(h]examplesah ]h"]examplesah$]h&]uh1hhhhhhhhKubeh}(h]bpf-map-type-xskmapah ]h"]bpf_map_type_xskmapah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourcehnj _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}(af_xdp](jojelibxdp](jjj2e bpf-examples]ja libxdp-readme]jaurefids}nameids}(jjjjjjjjbpf_map_lookup_elem()N user spaceNj/j,jjjjjfjcj]jZjijfjujrjj~u nametypes}(jjjjj j j/jjjfj]jijujuh}(jhjjjj'jj8jjjj j,jIjtj2jjyjjjcjjjijZjTjfj`jrjlj~jxu footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}jKsRparse_messages](hsystem_message)}(hhh]h)}(h8Duplicate implicit target name: "bpf_map_lookup_elem()".h]h