xref: /linux-6.15/net/openvswitch/flow_table.h (revision 9b996e54)
1e6445719SPravin B Shelar /*
2e6445719SPravin B Shelar  * Copyright (c) 2007-2013 Nicira, Inc.
3e6445719SPravin B Shelar  *
4e6445719SPravin B Shelar  * This program is free software; you can redistribute it and/or
5e6445719SPravin B Shelar  * modify it under the terms of version 2 of the GNU General Public
6e6445719SPravin B Shelar  * License as published by the Free Software Foundation.
7e6445719SPravin B Shelar  *
8e6445719SPravin B Shelar  * This program is distributed in the hope that it will be useful, but
9e6445719SPravin B Shelar  * WITHOUT ANY WARRANTY; without even the implied warranty of
10e6445719SPravin B Shelar  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11e6445719SPravin B Shelar  * General Public License for more details.
12e6445719SPravin B Shelar  *
13e6445719SPravin B Shelar  * You should have received a copy of the GNU General Public License
14e6445719SPravin B Shelar  * along with this program; if not, write to the Free Software
15e6445719SPravin B Shelar  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16e6445719SPravin B Shelar  * 02110-1301, USA
17e6445719SPravin B Shelar  */
18e6445719SPravin B Shelar 
19e6445719SPravin B Shelar #ifndef FLOW_TABLE_H
20e6445719SPravin B Shelar #define FLOW_TABLE_H 1
21e6445719SPravin B Shelar 
22e6445719SPravin B Shelar #include <linux/kernel.h>
23e6445719SPravin B Shelar #include <linux/netlink.h>
24e6445719SPravin B Shelar #include <linux/openvswitch.h>
25e6445719SPravin B Shelar #include <linux/spinlock.h>
26e6445719SPravin B Shelar #include <linux/types.h>
27e6445719SPravin B Shelar #include <linux/rcupdate.h>
28e6445719SPravin B Shelar #include <linux/if_ether.h>
29e6445719SPravin B Shelar #include <linux/in6.h>
30e6445719SPravin B Shelar #include <linux/jiffies.h>
31e6445719SPravin B Shelar #include <linux/time.h>
32e6445719SPravin B Shelar #include <linux/flex_array.h>
33e6445719SPravin B Shelar 
34e6445719SPravin B Shelar #include <net/inet_ecn.h>
35e6445719SPravin B Shelar #include <net/ip_tunnels.h>
36e6445719SPravin B Shelar 
37e6445719SPravin B Shelar #include "flow.h"
38e6445719SPravin B Shelar 
39b637e498SPravin B Shelar struct table_instance {
40e6445719SPravin B Shelar 	struct flex_array *buckets;
41b637e498SPravin B Shelar 	unsigned int n_buckets;
42e6445719SPravin B Shelar 	struct rcu_head rcu;
43e6445719SPravin B Shelar 	int node_ver;
44e6445719SPravin B Shelar 	u32 hash_seed;
45e6445719SPravin B Shelar 	bool keep_flows;
46e6445719SPravin B Shelar };
47e6445719SPravin B Shelar 
48b637e498SPravin B Shelar struct flow_table {
49b637e498SPravin B Shelar 	struct table_instance __rcu *ti;
50b637e498SPravin B Shelar 	struct list_head mask_list;
51b637e498SPravin B Shelar 	unsigned long last_rehash;
52b637e498SPravin B Shelar 	unsigned int 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 *);
64b637e498SPravin B Shelar int ovs_flow_tbl_count(struct flow_table *table);
65*9b996e54SPravin 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,
69618ed0c8SPravin B Shelar 			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 *,
761bd7116fSAndy Zhou 				    u32 *n_mask_hit);
775bb50632SAndy Zhou struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
785bb50632SAndy Zhou 				    const struct sw_flow_key *);
794a46b24eSAlex Wang struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
804a46b24eSAlex Wang 					  struct sw_flow_match *match);
81e6445719SPravin B Shelar bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
82e6445719SPravin B Shelar 			       struct sw_flow_match *match);
83e6445719SPravin B Shelar 
84e6445719SPravin B Shelar void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
85e6445719SPravin B Shelar 		       const struct sw_flow_mask *mask);
86e6445719SPravin B Shelar #endif /* flow_table.h */
87