net/openvswitch/flow_table.c
Source file repositories/reference/linux-study-clean/net/openvswitch/flow_table.c
File Facts
- System
- Linux kernel
- Corpus path
net/openvswitch/flow_table.c- Extension
.c- Size
- 29910 bytes
- Lines
- 1218
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
flow.hdatapath.hflow_netlink.hlinux/uaccess.hlinux/netdevice.hlinux/etherdevice.hlinux/if_ether.hlinux/if_vlan.hnet/llc_pdu.hlinux/kernel.hlinux/jhash.hlinux/jiffies.hlinux/llc.hlinux/module.hlinux/in.hlinux/rcupdate.hlinux/cpumask.hlinux/if_arp.hlinux/ip.hlinux/ipv6.hlinux/sctp.hlinux/tcp.hlinux/udp.hlinux/icmp.hlinux/icmpv6.hlinux/rculist.hlinux/sort.hnet/ip.hnet/ipv6.hnet/ndisc.h
Detected Declarations
function range_n_bytesfunction ovs_flow_mask_keyfunction ovs_flow_tbl_countfunction flow_freefunction for_each_cpufunction rcu_free_flow_callbackfunction ovs_flow_freefunction __table_instance_destroyfunction __mask_array_destroyfunction mask_array_rcu_cbfunction tbl_mask_array_reset_countersfunction for_each_possible_cpufunction tbl_mask_array_reallocfunction tbl_mask_array_add_maskfunction tbl_mask_array_del_maskfunction flow_mask_removefunction __mask_cache_destroyfunction mask_cache_rcu_cbfunction ovs_flow_tbl_masks_cache_resizefunction ovs_flow_tbl_initfunction flow_tbl_destroy_rcu_cbfunction table_instance_flow_freefunction table_instance_flow_flushfunction hlist_for_each_entry_safefunction table_instance_destroyfunction ovs_flow_tbl_destroyfunction hlist_for_each_entry_rcufunction table_instance_insertfunction ufid_table_instance_insertfunction flow_table_copy_flowsfunction ovs_flow_tbl_flushfunction flow_hashfunction flow_key_startfunction cmp_keyfunction flow_cmp_masked_keyfunction ovs_flow_cmp_unmasked_keyfunction hlist_for_each_entry_rcufunction ufid_hashfunction ovs_flow_cmp_ufidfunction ovs_flow_cmpfunction lockdep_ovsl_is_heldfunction ovs_flow_tbl_num_masksfunction ovs_flow_tbl_masks_cache_sizefunction ovs_flow_tbl_removefunction mask_equalfunction flow_mask_insertfunction flow_key_insertfunction flow_ufid_insert
Annotated Snippet
for_each_possible_cpu(cpu) {
struct mask_array_stats *stats;
unsigned int start;
u64 counter;
stats = per_cpu_ptr(ma->masks_usage_stats, cpu);
do {
start = u64_stats_fetch_begin(&stats->syncp);
counter = stats->usage_cntrs[i];
} while (u64_stats_fetch_retry(&stats->syncp, start));
ma->masks_usage_zero_cntr[i] += counter;
}
}
}
static struct mask_array *tbl_mask_array_alloc(int size)
{
struct mask_array *new;
size = max(MASK_ARRAY_SIZE_MIN, size);
new = kzalloc(struct_size(new, masks, size) +
sizeof(u64) * size, GFP_KERNEL);
if (!new)
return NULL;
new->masks_usage_zero_cntr = (u64 *)((u8 *)new +
struct_size(new, masks, size));
new->masks_usage_stats = __alloc_percpu(sizeof(struct mask_array_stats) +
sizeof(u64) * size,
__alignof__(u64));
if (!new->masks_usage_stats) {
kfree(new);
return NULL;
}
new->count = 0;
new->max = size;
return new;
}
static int tbl_mask_array_realloc(struct flow_table *tbl, int size)
{
struct mask_array *old;
struct mask_array *new;
new = tbl_mask_array_alloc(size);
if (!new)
return -ENOMEM;
old = ovsl_dereference(tbl->mask_array);
if (old) {
int i;
for (i = 0; i < old->max; i++) {
if (ovsl_dereference(old->masks[i]))
new->masks[new->count++] = old->masks[i];
}
call_rcu(&old->rcu, mask_array_rcu_cb);
}
rcu_assign_pointer(tbl->mask_array, new);
return 0;
}
static int tbl_mask_array_add_mask(struct flow_table *tbl,
struct sw_flow_mask *new)
{
struct mask_array *ma = ovsl_dereference(tbl->mask_array);
int err, ma_count = READ_ONCE(ma->count);
if (ma_count >= ma->max) {
err = tbl_mask_array_realloc(tbl, ma->max +
MASK_ARRAY_SIZE_MIN);
if (err)
return err;
ma = ovsl_dereference(tbl->mask_array);
} else {
/* On every add or delete we need to reset the counters so
* every new mask gets a fair chance of being prioritized.
*/
tbl_mask_array_reset_counters(ma);
}
BUG_ON(ovsl_dereference(ma->masks[ma_count]));
Annotation
- Immediate include surface: `flow.h`, `datapath.h`, `flow_netlink.h`, `linux/uaccess.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/if_ether.h`, `linux/if_vlan.h`.
- Detected declarations: `function range_n_bytes`, `function ovs_flow_mask_key`, `function ovs_flow_tbl_count`, `function flow_free`, `function for_each_cpu`, `function rcu_free_flow_callback`, `function ovs_flow_free`, `function __table_instance_destroy`, `function __mask_array_destroy`, `function mask_array_rcu_cb`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.