ksphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget'/translations/zh_CN/networking/fib_triemodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget'/translations/zh_TW/networking/fib_triemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget'/translations/it_IT/networking/fib_triemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget'/translations/ja_JP/networking/fib_triemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget'/translations/ko_KR/networking/fib_triemodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget'/translations/sp_SP/networking/fib_triemodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhhA/var/lib/git/docbuild/linux/Documentation/networking/fib_trie.rsthKubhsection)}(hhh](htitle)}(hLC-trie implementation notesh]hLC-trie implementation notes}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Node typesh]h Node types}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubhdefinition_list)}(hhh](hdefinition_list_item)}(hleaf An end node with data. This has a copy of the relevant key, along with 'hlist' with routing table entries sorted by prefix length. See struct leaf and struct leaf_info. h](hterm)}(hleafh]hleaf}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhubh definition)}(hhh]h paragraph)}(hAn end node with data. This has a copy of the relevant key, along with 'hlist' with routing table entries sorted by prefix length. See struct leaf and struct leaf_info.h]hAn end node with data. This has a copy of the relevant key, along with ‘hlist’ with routing table entries sorted by prefix length. See struct leaf and struct leaf_info.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhubah}(h]h ]h"]h$]h&]uh1hhhubeh}(h]h ]h"]h$]h&]uh1hhhhK hhubh)}(htrie node or tnode An internal node, holding an array of child (leaf or tnode) pointers, indexed through a subset of the key. See Level Compression. h](h)}(htrie node or tnodeh]htrie node or tnode}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hhh]h)}(hAn internal node, holding an array of child (leaf or tnode) pointers, indexed through a subset of the key. See Level Compression.h]hAn internal node, holding an array of child (leaf or tnode) pointers, indexed through a subset of the key. See Level Compression.}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj(ubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubeh}(h]h ]h"]h$]h&]uh1hhhhhhhhNubeh}(h] node-typesah ]h"] node typesah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hA few concepts explainedh]hA few concepts explained}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjShhhhhKubh)}(hhh](h)}(hBits (tnode) The number of bits in the key segment used for indexing into the child array - the "child index". See Level Compression. h](h)}(h Bits (tnode)h]h Bits (tnode)}(hjkhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjgubh)}(hhh]h)}(hxThe number of bits in the key segment used for indexing into the child array - the "child index". See Level Compression.h]h|The number of bits in the key segment used for indexing into the child array - the “child index”. See Level Compression.}(hj|hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjyubah}(h]h ]h"]h$]h&]uh1hhjgubeh}(h]h ]h"]h$]h&]uh1hhhhKhjdubh)}(hwPos (tnode) The position (in the key) of the key segment used for indexing into the child array. See Path Compression. h](h)}(h Pos (tnode)h]h Pos (tnode)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hhh]h)}(hjThe position (in the key) of the key segment used for indexing into the child array. See Path Compression.h]hjThe position (in the key) of the key segment used for indexing into the child array. See Path Compression.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhhhKhjdhhubh)}(hXqPath Compression / skipped bits Any given tnode is linked to from the child array of its parent, using a segment of the key specified by the parent's "pos" and "bits" In certain cases, this tnode's own "pos" will not be immediately adjacent to the parent (pos+bits), but there will be some bits in the key skipped over because they represent a single path with no deviations. These "skipped bits" constitute Path Compression. Note that the search algorithm will simply skip over these bits when searching, making it necessary to save the keys in the leaves to verify that they actually do match the key we are searching for. h](h)}(hPath Compression / skipped bitsh]hPath Compression / skipped bits}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK%hjubh)}(hhh]h)}(hXPAny given tnode is linked to from the child array of its parent, using a segment of the key specified by the parent's "pos" and "bits" In certain cases, this tnode's own "pos" will not be immediately adjacent to the parent (pos+bits), but there will be some bits in the key skipped over because they represent a single path with no deviations. These "skipped bits" constitute Path Compression. Note that the search algorithm will simply skip over these bits when searching, making it necessary to save the keys in the leaves to verify that they actually do match the key we are searching for.h]hXdAny given tnode is linked to from the child array of its parent, using a segment of the key specified by the parent’s “pos” and “bits” In certain cases, this tnode’s own “pos” will not be immediately adjacent to the parent (pos+bits), but there will be some bits in the key skipped over because they represent a single path with no deviations. These “skipped bits” constitute Path Compression. Note that the search algorithm will simply skip over these bits when searching, making it necessary to save the keys in the leaves to verify that they actually do match the key we are searching for.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhhhK%hjdhhubh)}(hXLevel Compression / child arrays the trie is kept level balanced moving, under certain conditions, the children of a full child (see "full_children") up one level, so that instead of a pure binary tree, each internal node ("tnode") may contain an arbitrarily large array of links to several children. Conversely, a tnode with a mostly empty child array (see empty_children) may be "halved", having some of its children moved downwards one level, in order to avoid ever-increasing child arrays. h](h)}(h Level Compression / child arraysh]h Level Compression / child arrays}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK.hjubh)}(hhh]h)}(hXthe trie is kept level balanced moving, under certain conditions, the children of a full child (see "full_children") up one level, so that instead of a pure binary tree, each internal node ("tnode") may contain an arbitrarily large array of links to several children. Conversely, a tnode with a mostly empty child array (see empty_children) may be "halved", having some of its children moved downwards one level, in order to avoid ever-increasing child arrays.h]hXthe trie is kept level balanced moving, under certain conditions, the children of a full child (see “full_children”) up one level, so that instead of a pure binary tree, each internal node (“tnode”) may contain an arbitrarily large array of links to several children. Conversely, a tnode with a mostly empty child array (see empty_children) may be “halved”, having some of its children moved downwards one level, in order to avoid ever-increasing child arrays.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK(hjubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhhhK.hjdhhubh)}(hZempty_children the number of positions in the child array of a given tnode that are NULL. h](h)}(hempty_childrenh]hempty_children}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK2hj#ubh)}(hhh]h)}(hJthe number of positions in the child array of a given tnode that are NULL.h]hJthe number of positions in the child array of a given tnode that are NULL.}(hj8hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK1hj5ubah}(h]h ]h"]h$]h&]uh1hhj#ubeh}(h]h ]h"]h$]h&]uh1hhhhK2hjdhhubh)}(hX8full_children the number of children of a given tnode that aren't path compressed. (in other words, they aren't NULL or leaves and their "pos" is equal to this tnode's "pos"+"bits"). (The word "full" here is used more in the sense of "complete" than as the opposite of "empty", which might be a tad confusing.) h](h)}(h full_childrenh]h full_children}(hjVhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK:hjRubh)}(hhh](h)}(hthe number of children of a given tnode that aren't path compressed. (in other words, they aren't NULL or leaves and their "pos" is equal to this tnode's "pos"+"bits").h]hthe number of children of a given tnode that aren’t path compressed. (in other words, they aren’t NULL or leaves and their “pos” is equal to this tnode’s “pos”+”bits”).}(hjghhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK5hjdubh)}(h(The word "full" here is used more in the sense of "complete" than as the opposite of "empty", which might be a tad confusing.)h]h(The word “full” here is used more in the sense of “complete” than as the opposite of “empty”, which might be a tad confusing.)}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK9hjdubeh}(h]h ]h"]h$]h&]uh1hhjRubeh}(h]h ]h"]h$]h&]uh1hhhhK:hjdhhubeh}(h]h ]h"]h$]h&]uh1hhjShhhhhNubeh}(h]a-few-concepts-explainedah ]h"]a few concepts explainedah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hCommentsh]hComments}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK=ubh)}(h}We have tried to keep the structure of the code as close to fib_hash as possible to allow verification and help up reviewing.h]h}We have tried to keep the structure of the code as close to fib_hash as possible to allow verification and help up reviewing.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK?hjhhubh)}(hhh](h)}(hrfib_find_node() A good start for understanding this code. This function implements a straightforward trie lookup. h](h)}(hfib_find_node()h]hfib_find_node()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKDhjubh)}(hhh]h)}(haA good start for understanding this code. This function implements a straightforward trie lookup.h]haA good start for understanding this code. This function implements a straightforward trie lookup.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKChjubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhhhKDhjubh)}(hfib_insert_node() Inserts a new leaf node in the trie. This is bit more complicated than fib_find_node(). Inserting a new node means we might have to run the level compression algorithm on part of the trie. h](h)}(hfib_insert_node()h]hfib_insert_node()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKIhjubh)}(hhh]h)}(hInserts a new leaf node in the trie. This is bit more complicated than fib_find_node(). Inserting a new node means we might have to run the level compression algorithm on part of the trie.h]hInserts a new leaf node in the trie. This is bit more complicated than fib_find_node(). Inserting a new node means we might have to run the level compression algorithm on part of the trie.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKGhjubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhhhKIhjhhubh)}(hXtrie_leaf_remove() Looks up a key, deletes it and runs the level compression algorithm. h](h)}(htrie_leaf_remove()h]htrie_leaf_remove()}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKLhjubh)}(hhh]h)}(hDLooks up a key, deletes it and runs the level compression algorithm.h]hDLooks up a key, deletes it and runs the level compression algorithm.}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKLhj/ubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhhhKLhjhhubh)}(htrie_rebalance() The key function for the dynamic trie after any change in the trie it is run to optimize and reorganize. It will walk the trie upwards towards the root from a given tnode, doing a resize() at each step to implement level compression. h](h)}(htrie_rebalance()h]htrie_rebalance()}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKRhjLubh)}(hhh]h)}(hThe key function for the dynamic trie after any change in the trie it is run to optimize and reorganize. It will walk the trie upwards towards the root from a given tnode, doing a resize() at each step to implement level compression.h]hThe key function for the dynamic trie after any change in the trie it is run to optimize and reorganize. It will walk the trie upwards towards the root from a given tnode, doing a resize() at each step to implement level compression.}(hjahhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKOhj^ubah}(h]h ]h"]h$]h&]uh1hhjLubeh}(h]h ]h"]h$]h&]uh1hhhhKRhjhhubh)}(hXresize() Analyzes a tnode and optimizes the child array size by either inflating or shrinking it repeatedly until it fulfills the criteria for optimal level compression. This part follows the original paper pretty closely and there may be some room for experimentation here. h](h)}(hresize()h]hresize()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKXhj{ubh)}(hhh]h)}(hX Analyzes a tnode and optimizes the child array size by either inflating or shrinking it repeatedly until it fulfills the criteria for optimal level compression. This part follows the original paper pretty closely and there may be some room for experimentation here.h]hX Analyzes a tnode and optimizes the child array size by either inflating or shrinking it repeatedly until it fulfills the criteria for optimal level compression. This part follows the original paper pretty closely and there may be some room for experimentation here.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKUhjubah}(h]h ]h"]h$]h&]uh1hhj{ubeh}(h]h ]h"]h$]h&]uh1hhhhKXhjhhubh)}(hPinflate() Doubles the size of the child array within a tnode. Used by resize(). h](h)}(h inflate()h]h inflate()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK[hjubh)}(hhh]h)}(hEDoubles the size of the child array within a tnode. Used by resize().h]hEDoubles the size of the child array within a tnode. Used by resize().}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK[hjubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhhhK[hjhhubh)}(hhhalve() Halves the size of the child array within a tnode - the inverse of inflate(). Used by resize(); h](h)}(hhalve()h]hhalve()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK_hjubh)}(hhh]h)}(h_Halves the size of the child array within a tnode - the inverse of inflate(). Used by resize();h]h_Halves the size of the child array within a tnode - the inverse of inflate(). Used by resize();}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK^hjubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhhhK_hjhhubh)}(hfn_trie_insert(), fn_trie_delete(), fn_trie_select_default() The route manipulation functions. Should conform pretty closely to the corresponding functions in fib_hash. h](h)}(hstats.backtrack++) up the trie, continuing to chop off part of the key in order to find the longest matching prefix.h]hAt this point we backtrack (t->stats.backtrack++) up the trie, continuing to chop off part of the key in order to find the longest matching prefix.}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hAt this point we will repeatedly descend subtries to look for a match, and there are some optimizations available that can provide us with "shortcuts" to avoid descending into dead ends. Look for "HL_OPTIMIZE" sections in the code.h]hAt this point we will repeatedly descend subtries to look for a match, and there are some optimizations available that can provide us with “shortcuts” to avoid descending into dead ends. Look for “HL_OPTIMIZE” sections in the code.}(hj/hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hTo alleviate any doubts about the correctness of the route selection process, a new netlink operation has been added. Look for NETLINK_FIB_LOOKUP, which gives userland access to fib_lookup().h]hTo alleviate any doubts about the correctness of the route selection process, a new netlink operation has been added. Look for NETLINK_FIB_LOOKUP, which gives userland access to fib_lookup().}(hj=hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]main-lookup-mechanismah ]h"]main lookup mechanismah$]h&]uh1hhhhhhhhKxubeh}(h]lc-trie-implementation-notesah ]h"]lc-trie implementation notesah$]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_handlerj~error_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _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}refids}nameids}(jXjUjPjMjjjjjjjPjMu nametypes}(jXjPjjjjPuh}(jUhjMhjjSjjjjjMju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.