xref: /linux-6.15/net/openvswitch/flow_table.h (revision 4bc63b1b)
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 
30*4bc63b1bSTonghao Zhang struct mask_array {
31*4bc63b1bSTonghao Zhang 	struct rcu_head rcu;
32*4bc63b1bSTonghao Zhang 	int count, max;
33*4bc63b1bSTonghao Zhang 	struct sw_flow_mask __rcu *masks[];
34*4bc63b1bSTonghao Zhang };
35*4bc63b1bSTonghao Zhang 
36b637e498SPravin B Shelar struct table_instance {
37ee9c5e67SKent Overstreet 	struct hlist_head *buckets;
38b637e498SPravin B Shelar 	unsigned int n_buckets;
39e6445719SPravin B Shelar 	struct rcu_head rcu;
40e6445719SPravin B Shelar 	int node_ver;
41e6445719SPravin B Shelar 	u32 hash_seed;
42e6445719SPravin B Shelar 	bool keep_flows;
43e6445719SPravin B Shelar };
44e6445719SPravin B Shelar 
45b637e498SPravin B Shelar struct flow_table {
46b637e498SPravin B Shelar 	struct table_instance __rcu *ti;
4774ed7ab9SJoe Stringer 	struct table_instance __rcu *ufid_ti;
4804b7d136STonghao Zhang 	struct mask_cache_entry __percpu *mask_cache;
49*4bc63b1bSTonghao Zhang 	struct mask_array __rcu *mask_array;
50b637e498SPravin B Shelar 	unsigned long last_rehash;
51b637e498SPravin B Shelar 	unsigned int count;
5274ed7ab9SJoe Stringer 	unsigned int ufid_count;
53b637e498SPravin B Shelar };
54b637e498SPravin B Shelar 
5563e7959cSJarno Rajahalme extern struct kmem_cache *flow_stats_cache;
5663e7959cSJarno Rajahalme 
57e6445719SPravin B Shelar int ovs_flow_init(void);
58e6445719SPravin B Shelar void ovs_flow_exit(void);
59e6445719SPravin B Shelar 
6023dabf88SJarno Rajahalme struct sw_flow *ovs_flow_alloc(void);
61e6445719SPravin B Shelar void ovs_flow_free(struct sw_flow *, bool deferred);
62e6445719SPravin B Shelar 
63b637e498SPravin B Shelar int ovs_flow_tbl_init(struct flow_table *);
6412eb18f7SThomas Graf int ovs_flow_tbl_count(const struct flow_table *table);
659b996e54SPravin B Shelar void ovs_flow_tbl_destroy(struct flow_table *table);
66b637e498SPravin B Shelar int ovs_flow_tbl_flush(struct flow_table *flow_table);
67e6445719SPravin B Shelar 
68618ed0c8SPravin B Shelar int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
6912eb18f7SThomas Graf 			const struct sw_flow_mask *mask);
70e6445719SPravin B Shelar void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
711bd7116fSAndy Zhou int  ovs_flow_tbl_num_masks(const struct flow_table *table);
72b637e498SPravin B Shelar struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
73e6445719SPravin B Shelar 				       u32 *bucket, u32 *idx);
745bb50632SAndy Zhou struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
751bd7116fSAndy Zhou 					  const struct sw_flow_key *,
7604b7d136STonghao Zhang 					  u32 skb_hash,
771bd7116fSAndy Zhou 					  u32 *n_mask_hit);
785bb50632SAndy Zhou struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
795bb50632SAndy Zhou 				    const struct sw_flow_key *);
804a46b24eSAlex Wang struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
8112eb18f7SThomas Graf 					  const struct sw_flow_match *match);
8274ed7ab9SJoe Stringer struct sw_flow *ovs_flow_tbl_lookup_ufid(struct flow_table *,
8374ed7ab9SJoe Stringer 					 const struct sw_flow_id *);
8474ed7ab9SJoe Stringer 
8574ed7ab9SJoe Stringer bool ovs_flow_cmp(const struct sw_flow *, const struct sw_flow_match *);
86e6445719SPravin B Shelar 
87e6445719SPravin B Shelar void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
88ae5f2fb1SJesse Gross 		       bool full, const struct sw_flow_mask *mask);
89e6445719SPravin B Shelar #endif /* flow_table.h */
90