History

bpf: lpm_trie: check left child of last leftmost node for NULL

If the leftmost parent node of the tree has does not have a child on the left side, then trie_get_next_key (and bpftool map dump) will not look at the child on the right. This leads to the traversal missing elements. Lookup is not affected. Update selftest to handle this case. Reproducer: bpftool map create /sys/fs/bpf/lpm type lpm_trie key 6 \ value 1 entries 256 name test_lpm flags 1 bpftool map update pinned /sys/fs/bpf/lpm key 8 0 0 0 0 0 value 1 bpftool map update pinned /sys/fs/bpf/lpm key 16 0 0 0 0 128 value 2 bpftool map dump pinned /sys/fs/bpf/lpm Returns only 1 element. (2 expected)

Jonathan Lemon committed 7 years ago

Commit da2577f1 parent dce5ccc2 files · +45 −5Browse files

Showing the changes to kernel (1 of 2 files). Show all

Unified · Split

kernel/bpf/lpm_trie.c+7−2
@@ -716,9 +716,14 @@ find_leftmost: · 715 unmodified lines
716716 * have exact two children, so this function will never return NULL.
717717 */
718718 for (node = search_root; node;) {
719− if (!(node->flags & LPM_TREE_NODE_FLAG_IM))
719+ if (node->flags & LPM_TREE_NODE_FLAG_IM) {
720+ node = rcu_dereference(node->child[0]);
721+ } else {
720722 next_node = node;
721− node = rcu_dereference(node->child[0]);
723+ node = rcu_dereference(node->child[0]);
724+ if (!node)
725+ node = rcu_dereference(next_node->child[1]);
726+ }
722727 }
723728 do_copy:
724729 next_key->prefixlen = next_node->prefixlen;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t