This trie implements a longest prefix match algorithm that can be used to match IP addresses to a stored set of ranges. Internally, data is stored in an unbalanced trie of nodes that has a maximum height of n, where n is the prefixlen the trie was created with. Tries may be created with prefix lengths that are multiples of 8, in the range from 8 to 2048. The key used for lookup and update operations is a struct bpf_lpm_trie_key, and the value is a uint64_t. The code carries more information about the internal implementation.
Showing the changes to include/uapi/linux (1 of 3 files). Show all
Unified · Split
| @@ -63,6 +63,12 @@ struct bpf_insn { · 62 unmodified lines | ||
| 63 | 63 | __s32 imm; /* signed immediate constant */ |
| 64 | 64 | }; |
| 65 | 65 | |
| 66 | +/* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */ | |
| 67 | +struct bpf_lpm_trie_key { | |
| 68 | + __u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */ | |
| 69 | + __u8 data[0]; /* Arbitrary size */ | |
| 70 | +}; | |
| 71 | + | |
| 66 | 72 | /* BPF syscall commands, see bpf(2) man-page for details. */ |
| 67 | 73 | enum bpf_cmd { |
| 68 | 74 | BPF_MAP_CREATE, |
| @@ -89,6 +95,7 @@ enum bpf_map_type { · 20 unmodified lines | ||
| 89 | 95 | BPF_MAP_TYPE_CGROUP_ARRAY, |
| 90 | 96 | BPF_MAP_TYPE_LRU_HASH, |
| 91 | 97 | BPF_MAP_TYPE_LRU_PERCPU_HASH, |
| 98 | + BPF_MAP_TYPE_LPM_TRIE, | |
| 92 | 99 | }; |
| 93 | 100 | |
| 94 | 101 | enum bpf_prog_type { |