Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:kernel\bpf\lpm_trie.c Create Date:2022-07-28 13:13:19
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:Called from syscall or from eBPF program

Proto:static int trie_update_elem(struct bpf_map *map, void *_key, void *value, u64 flags)

Type:int

Parameter:

TypeParameterName
struct bpf_map *map
void *_key
void *value
u64flags
303  trie = container_of - cast a member of a structure out to the containing structure*@ptr: the pointer to the member.*@type: the type of the container struct this is embedded in.*@member: the name of the member within the struct.(map, structlpm_trie, map)
304  struct lpm_trie_node * node, * im_node = NULL, * new_node = NULL
305  __rcu * slot
306  key = _key
309  matchlen = 0
310  ret = 0
312  If Value for the false possibility is greater at compile time(flags > update existing element ) Then Return -EINVAL
315  If up to 32 for AF_INET, 128 for AF_INET6 > max_prefixlen Then Return -EINVAL
318  raw_spin_lock_irqsave( & lock, irq_flags)
322  If n_entries == max_entries Then
323  ret = -ENOSPC
324  Go to out
327  new_node = lpm_trie_node_alloc(trie, value)
328  If Not new_node Then
329  ret = -ENOMEM
330  Go to out
333  n_entries++
335  prefixlen = up to 32 for AF_INET, 128 for AF_INET6
336  RCU_INIT_POINTER() - initialize an RCU protected pointer*@p: The pointer to be initialized.*@v: The value to initialized the pointer to.* Initialize an RCU-protected pointer in special cases where readers(child[0], NULL)
337  RCU_INIT_POINTER() - initialize an RCU protected pointer*@p: The pointer to be initialized.*@v: The value to initialized the pointer to.* Initialize an RCU-protected pointer in special cases where readers(child[1], NULL)
338  No 3D Now!(data, Arbitrary size , data_size)
345  slot = root
347  When node = cu_dereference_protected() - fetch RCU pointer when updates prevented*@p: The pointer to read, prior to dereferencing*@c: The conditions under which the dereference will take place* Return the value of the specified RCU-protected pointer, but omit( * slot, lockdep_is_held( & lock)) cycle
349  matchlen = longest_prefix_match() - determine the longest prefix*@trie: The trie to get internal sizes from*@node: The node to operate on*@key: The key to compare to @node* Determine the longest prefix of @node that matches the bits in @key.
351  If prefixlen != matchlen || prefixlen == up to 32 for AF_INET, 128 for AF_INET6 || prefixlen == max_prefixlen Then Break
356  next_bit = This trie implements a longest prefix match algorithm that can be used to* match IP addresses to a stored set of ranges.* Data stored in @data of struct bpf_lpm_key and struct lpm_trie_node is
357  slot = child[next_bit]
363  If Not node Then
364  cu_assign_pointer() - assign to RCU-protected pointer*@p: pointer to assign to*@v: value to assign (publish)* Assigns the specified value to the specified RCU-protected* pointer, ensuring that any concurrent RCU readers will see* any prior initialization( * slot, new_node)
365  Go to out
371  If prefixlen == matchlen Then
372  child[0] = child[0]
373  child[1] = child[1]
375  If Not (flags & Intermediate node ) Then n_entries--
378  cu_assign_pointer() - assign to RCU-protected pointer*@p: pointer to assign to*@v: value to assign (publish)* Assigns the specified value to the specified RCU-protected* pointer, ensuring that any concurrent RCU readers will see* any prior initialization( * slot, new_node)
379  kfree_rcu() - kfree an object after a grace period(node, rcu)
381  Go to out
387  If matchlen == up to 32 for AF_INET, 128 for AF_INET6 Then
388  next_bit = This trie implements a longest prefix match algorithm that can be used to* match IP addresses to a stored set of ranges.* Data stored in @data of struct bpf_lpm_key and struct lpm_trie_node is
389  cu_assign_pointer() - assign to RCU-protected pointer*@p: pointer to assign to*@v: value to assign (publish)* Assigns the specified value to the specified RCU-protected* pointer, ensuring that any concurrent RCU readers will see* any prior initialization(child[next_bit], node)
390  cu_assign_pointer() - assign to RCU-protected pointer*@p: pointer to assign to*@v: value to assign (publish)* Assigns the specified value to the specified RCU-protected* pointer, ensuring that any concurrent RCU readers will see* any prior initialization( * slot, new_node)
391  Go to out
394  im_node = lpm_trie_node_alloc(trie, NULL)
395  If Not im_node Then
396  ret = -ENOMEM
397  Go to out
400  prefixlen = matchlen
401  flags |= Intermediate node
402  No 3D Now!(data, data, data_size)
405  If This trie implements a longest prefix match algorithm that can be used to* match IP addresses to a stored set of ranges.* Data stored in @data of struct bpf_lpm_key and struct lpm_trie_node is Then
406  cu_assign_pointer() - assign to RCU-protected pointer*@p: pointer to assign to*@v: value to assign (publish)* Assigns the specified value to the specified RCU-protected* pointer, ensuring that any concurrent RCU readers will see* any prior initialization(child[0], node)
407  cu_assign_pointer() - assign to RCU-protected pointer*@p: pointer to assign to*@v: value to assign (publish)* Assigns the specified value to the specified RCU-protected* pointer, ensuring that any concurrent RCU readers will see* any prior initialization(child[1], new_node)
408  Else
409  cu_assign_pointer() - assign to RCU-protected pointer*@p: pointer to assign to*@v: value to assign (publish)* Assigns the specified value to the specified RCU-protected* pointer, ensuring that any concurrent RCU readers will see* any prior initialization(child[0], new_node)
410  cu_assign_pointer() - assign to RCU-protected pointer*@p: pointer to assign to*@v: value to assign (publish)* Assigns the specified value to the specified RCU-protected* pointer, ensuring that any concurrent RCU readers will see* any prior initialization(child[1], node)
414  cu_assign_pointer() - assign to RCU-protected pointer*@p: pointer to assign to*@v: value to assign (publish)* Assigns the specified value to the specified RCU-protected* pointer, ensuring that any concurrent RCU readers will see* any prior initialization( * slot, im_node)
416  out :
417  If ret Then
418  If new_node Then n_entries--
421  kfree(new_node)
422  kfree(im_node)
425  raw_spin_unlock_irqrestore( & lock, irq_flags)
427  Return ret