xref: /linux-6.15/net/openvswitch/flow_table.h (revision b637e498)
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 
39*b637e498SPravin B Shelar struct table_instance {
40e6445719SPravin B Shelar 	struct flex_array *buckets;
41*b637e498SPravin 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 
48*b637e498SPravin B Shelar struct flow_table {
49*b637e498SPravin B Shelar 	struct table_instance __rcu *ti;
50*b637e498SPravin B Shelar 	struct list_head mask_list;
51*b637e498SPravin B Shelar 	unsigned long last_rehash;
52*b637e498SPravin B Shelar 	unsigned int count;
53*b637e498SPravin B Shelar };
54*b637e498SPravin B Shelar 
55e6445719SPravin B Shelar int ovs_flow_init(void);
56e6445719SPravin B Shelar void ovs_flow_exit(void);
57e6445719SPravin B Shelar 
58e6445719SPravin B Shelar struct sw_flow *ovs_flow_alloc(void);
59e6445719SPravin B Shelar void ovs_flow_free(struct sw_flow *, bool deferred);
60e6445719SPravin B Shelar 
61*b637e498SPravin B Shelar int ovs_flow_tbl_init(struct flow_table *);
62*b637e498SPravin B Shelar int ovs_flow_tbl_count(struct flow_table *table);
63e6445719SPravin B Shelar void ovs_flow_tbl_destroy(struct flow_table *table, bool deferred);
64*b637e498SPravin B Shelar int ovs_flow_tbl_flush(struct flow_table *flow_table);
65e6445719SPravin B Shelar 
66e6445719SPravin B Shelar void ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow);
67e6445719SPravin B Shelar void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
68*b637e498SPravin B Shelar struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
69e6445719SPravin B Shelar 				       u32 *bucket, u32 *idx);
70e6445719SPravin B Shelar struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
71e6445719SPravin B Shelar 				    const struct sw_flow_key *);
72e6445719SPravin B Shelar 
73e6445719SPravin B Shelar bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
74e6445719SPravin B Shelar 			       struct sw_flow_match *match);
75e6445719SPravin B Shelar 
76e6445719SPravin B Shelar struct sw_flow_mask *ovs_sw_flow_mask_alloc(void);
77e6445719SPravin B Shelar void ovs_sw_flow_mask_add_ref(struct sw_flow_mask *);
78e6445719SPravin B Shelar void ovs_sw_flow_mask_del_ref(struct sw_flow_mask *, bool deferred);
79e6445719SPravin B Shelar void ovs_sw_flow_mask_insert(struct flow_table *, struct sw_flow_mask *);
80e6445719SPravin B Shelar struct sw_flow_mask *ovs_sw_flow_mask_find(const struct flow_table *,
81e6445719SPravin B Shelar 					   const struct sw_flow_mask *);
82e6445719SPravin B Shelar void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
83e6445719SPravin B Shelar 		       const struct sw_flow_mask *mask);
84e6445719SPravin B Shelar 
85e6445719SPravin B Shelar #endif /* flow_table.h */
86