File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -366,6 +366,10 @@ static int trie_update_elem(struct bpf_map *map,
366366 * simply assign the @new_node to that slot and be done.
367367 */
368368 if (!node ) {
369+ if (flags == BPF_EXIST ) {
370+ ret = - ENOENT ;
371+ goto out ;
372+ }
369373 rcu_assign_pointer (* slot , new_node );
370374 goto out ;
371375 }
@@ -374,18 +378,31 @@ static int trie_update_elem(struct bpf_map *map,
374378 * which already has the correct data array set.
375379 */
376380 if (node -> prefixlen == matchlen ) {
381+ if (!(node -> flags & LPM_TREE_NODE_FLAG_IM )) {
382+ if (flags == BPF_NOEXIST ) {
383+ ret = - EEXIST ;
384+ goto out ;
385+ }
386+ trie -> n_entries -- ;
387+ } else if (flags == BPF_EXIST ) {
388+ ret = - ENOENT ;
389+ goto out ;
390+ }
391+
377392 new_node -> child [0 ] = node -> child [0 ];
378393 new_node -> child [1 ] = node -> child [1 ];
379394
380- if (!(node -> flags & LPM_TREE_NODE_FLAG_IM ))
381- trie -> n_entries -- ;
382-
383395 rcu_assign_pointer (* slot , new_node );
384396 kfree_rcu (node , rcu );
385397
386398 goto out ;
387399 }
388400
401+ if (flags == BPF_EXIST ) {
402+ ret = - ENOENT ;
403+ goto out ;
404+ }
405+
389406 /* If the new node matches the prefix completely, it must be inserted
390407 * as an ancestor. Simply insert it between @node and *@slot.
391408 */
You can’t perform that action at this time.
0 commit comments