xref: /linux-6.15/net/openvswitch/flow_table.h (revision 9d2f627b)
1c9422999SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2e6445719SPravin B Shelar /*
3e6445719SPravin B Shelar  * Copyright (c) 2007-2013 Nicira, Inc.
4e6445719SPravin B Shelar  */
5e6445719SPravin B Shelar 
6e6445719SPravin B Shelar #ifndef FLOW_TABLE_H
7e6445719SPravin B Shelar #define FLOW_TABLE_H 1
8e6445719SPravin B Shelar 
9e6445719SPravin B Shelar #include <linux/kernel.h>
10e6445719SPravin B Shelar #include <linux/netlink.h>
11e6445719SPravin B Shelar #include <linux/openvswitch.h>
12e6445719SPravin B Shelar #include <linux/spinlock.h>
13e6445719SPravin B Shelar #include <linux/types.h>
14e6445719SPravin B Shelar #include <linux/rcupdate.h>
15e6445719SPravin B Shelar #include <linux/if_ether.h>
16e6445719SPravin B Shelar #include <linux/in6.h>
17e6445719SPravin B Shelar #include <linux/jiffies.h>
18e6445719SPravin B Shelar #include <linux/time.h>
19e6445719SPravin B Shelar 
20e6445719SPravin B Shelar #include <net/inet_ecn.h>
21e6445719SPravin B Shelar #include <net/ip_tunnels.h>
22e6445719SPravin B Shelar 
23e6445719SPravin B Shelar #include "flow.h"
24e6445719SPravin B Shelar 
2504b7d136STonghao Zhang struct mask_cache_entry {
2604b7d136STonghao Zhang 	u32 skb_hash;
2704b7d136STonghao Zhang 	u32 mask_index;
2804b7d136STonghao Zhang };
2904b7d136STonghao Zhang 
30eac87c41SEelco Chaudron struct mask_count {
31eac87c41SEelco Chaudron 	int index;
32eac87c41SEelco Chaudron 	u64 counter;
33eac87c41SEelco Chaudron };
34eac87c41SEelco Chaudron 
354bc63b1bSTonghao Zhang struct mask_array {
364bc63b1bSTonghao Zhang 	struct rcu_head rcu;
374bc63b1bSTonghao Zhang 	int count, max;
38eac87c41SEelco Chaudron 	u64 __percpu *masks_usage_cntr;
39eac87c41SEelco Chaudron 	u64 *masks_usage_zero_cntr;
40eac87c41SEelco Chaudron 	struct u64_stats_sync syncp;
414bc63b1bSTonghao Zhang 	struct sw_flow_mask __rcu *masks[];
424bc63b1bSTonghao Zhang };
434bc63b1bSTonghao Zhang 
44b637e498SPravin B Shelar struct table_instance {
45ee9c5e67SKent Overstreet 	struct hlist_head *buckets;
46b637e498SPravin B Shelar 	unsigned int n_buckets;
47e6445719SPravin B Shelar 	struct rcu_head rcu;
48e6445719SPravin B Shelar 	int node_ver;
49e6445719SPravin B Shelar 	u32 hash_seed;
50e6445719SPravin B Shelar 	bool keep_flows;
51e6445719SPravin B Shelar };
52e6445719SPravin B Shelar 
53b637e498SPravin B Shelar struct flow_table {
54b637e498SPravin B Shelar 	struct table_instance __rcu *ti;
5574ed7ab9SJoe Stringer 	struct table_instance __rcu *ufid_ti;
5604b7d136STonghao Zhang 	struct mask_cache_entry __percpu *mask_cache;
574bc63b1bSTonghao Zhang 	struct mask_array __rcu *mask_array;
58b637e498SPravin B Shelar 	unsigned long last_rehash;
59b637e498SPravin B Shelar 	unsigned int count;
6074ed7ab9SJoe Stringer 	unsigned int ufid_count;
61b637e498SPravin B Shelar };
62b637e498SPravin B Shelar 
6363e7959cSJarno Rajahalme extern struct kmem_cache *flow_stats_cache;
6463e7959cSJarno Rajahalme 
65e6445719SPravin B Shelar int ovs_flow_init(void);
66e6445719SPravin B Shelar void ovs_flow_exit(void);
67e6445719SPravin B Shelar 
6823dabf88SJarno Rajahalme struct sw_flow *ovs_flow_alloc(void);
69e6445719SPravin B Shelar void ovs_flow_free(struct sw_flow *, bool deferred);
70e6445719SPravin B Shelar 
71b637e498SPravin B Shelar int ovs_flow_tbl_init(struct flow_table *);
7212eb18f7SThomas Graf int ovs_flow_tbl_count(const struct flow_table *table);
739b996e54SPravin B Shelar void ovs_flow_tbl_destroy(struct flow_table *table);
74b637e498SPravin B Shelar int ovs_flow_tbl_flush(struct flow_table *flow_table);
75e6445719SPravin B Shelar 
76618ed0c8SPravin B Shelar int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
7712eb18f7SThomas Graf 			const struct sw_flow_mask *mask);
78e6445719SPravin B Shelar void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
791bd7116fSAndy Zhou int  ovs_flow_tbl_num_masks(const struct flow_table *table);
80b637e498SPravin B Shelar struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
81e6445719SPravin B Shelar 				       u32 *bucket, u32 *idx);
825bb50632SAndy Zhou struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
831bd7116fSAndy Zhou 					  const struct sw_flow_key *,
8404b7d136STonghao Zhang 					  u32 skb_hash,
85*9d2f627bSEelco Chaudron 					  u32 *n_mask_hit,
86*9d2f627bSEelco Chaudron 					  u32 *n_cache_hit);
875bb50632SAndy Zhou struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
885bb50632SAndy Zhou 				    const struct sw_flow_key *);
894a46b24eSAlex Wang struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
9012eb18f7SThomas Graf 					  const struct sw_flow_match *match);
9174ed7ab9SJoe Stringer struct sw_flow *ovs_flow_tbl_lookup_ufid(struct flow_table *,
9274ed7ab9SJoe Stringer 					 const struct sw_flow_id *);
9374ed7ab9SJoe Stringer 
9474ed7ab9SJoe Stringer bool ovs_flow_cmp(const struct sw_flow *, const struct sw_flow_match *);
95e6445719SPravin B Shelar 
96e6445719SPravin B Shelar void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
97ae5f2fb1SJesse Gross 		       bool full, const struct sw_flow_mask *mask);
98eac87c41SEelco Chaudron 
99eac87c41SEelco Chaudron void ovs_flow_masks_rebalance(struct flow_table *table);
100eac87c41SEelco Chaudron 
101e6445719SPravin B Shelar #endif /* flow_table.h */
102