Repository navigation
Fix leafref binary search accepting entries excluded by xpath predicates - #700
Open
khromenokroman wants to merge 2 commits into
Open
khromenokroman wants to merge 2 commits into
khromenokroman wants to merge 2 commits into
Conversation
leafref_opt_search_detect() enabled binary search when all xvec entries share the same yang and parent (leaf-list) or grandparent (list key). leafref_opt_search() then searches among ALL siblings of that parent, but xvec may be only a subset of them if the leafref path has a predicate, eg "../iface[enabled='true']/name". A reference to an entry excluded by the predicate was then wrongly accepted. This was the case for a single match before, and for any number of matches after the fix for clicon#669 allowed list entries with different parents. Only use binary search if xvec contains all such siblings, ie the number of siblings with the same yang equals xlen. Predicates above the common parent (eg selecting a context) do not filter siblings and keep the optimization.
…ries Add sender/active-template leafref "/sender[enabled='true']/name" and check that a reference to a disabled sender fails validation while a reference to an enabled one passes.
This was referenced Oct 7, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@olofhagsand Hello
Description:
Related to #669
Problem
leafref_opt_search_detect()enables binary search when all nodes inxvechave the same YANG spec and share the same parent (leaf-list) or grandparent
(list key).
leafref_opt_search()then searches among all siblings underthat parent, but
xvecmay be only a subset of them if the leafref pathcontains a predicate on the list, e.g.:
A reference to an entry that the predicate excluded is then wrongly accepted
instead of failing with
instance-required.This already happened when exactly one entry matched the predicate. Since
ff7dafe (#669), which allows list entries with different parents, it happens
for any number of matches.
Example with
LEAFREF_OPTIMIZE(default):With
LEAFREF_OPTIMIZEundefined (linear search) the same data correctlyfails validation.
Fix
Use binary search only if
xveccontains all siblings with the same YANGspec, i.e. the number of such children of the common parent equals
xlen.If the xpath filtered anything out, fall back to the linear search.
Predicates above the common parent (e.g. selecting a context entry with
/contexts/context[name=current()/...]/...) do not filter the siblings andkeep the optimization. The extra check is a single pass over the parent's
children, the same order as the existing detection loop.
Testing
test/test_leafref.sh: addedsender/active-templateleafref/sender[enabled='true']/name; a reference to a disabled sender must failvalidation, a reference to an enabled one must pass.
Verified with a standalone validation program (
xml_yang_validate_all_top):Performance unchanged for paths without predicates (the List binary search is broken #669 case):
20000 list entries + 20000 leafrefs validate in 0.29s, vs 75s with linear search.