xref: /linux-6.15/net/openvswitch/flow_table.h (revision e6445719)
1*e6445719SPravin B Shelar /*
2*e6445719SPravin B Shelar  * Copyright (c) 2007-2013 Nicira, Inc.
3*e6445719SPravin B Shelar  *
4*e6445719SPravin B Shelar  * This program is free software; you can redistribute it and/or
5*e6445719SPravin B Shelar  * modify it under the terms of version 2 of the GNU General Public
6*e6445719SPravin B Shelar  * License as published by the Free Software Foundation.
7*e6445719SPravin B Shelar  *
8*e6445719SPravin B Shelar  * This program is distributed in the hope that it will be useful, but
9*e6445719SPravin B Shelar  * WITHOUT ANY WARRANTY; without even the implied warranty of
10*e6445719SPravin B Shelar  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11*e6445719SPravin B Shelar  * General Public License for more details.
12*e6445719SPravin B Shelar  *
13*e6445719SPravin B Shelar  * You should have received a copy of the GNU General Public License
14*e6445719SPravin B Shelar  * along with this program; if not, write to the Free Software
15*e6445719SPravin B Shelar  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16*e6445719SPravin B Shelar  * 02110-1301, USA
17*e6445719SPravin B Shelar  */
18*e6445719SPravin B Shelar 
19*e6445719SPravin B Shelar #ifndef FLOW_TABLE_H
20*e6445719SPravin B Shelar #define FLOW_TABLE_H 1
21*e6445719SPravin B Shelar 
22*e6445719SPravin B Shelar #include <linux/kernel.h>
23*e6445719SPravin B Shelar #include <linux/netlink.h>
24*e6445719SPravin B Shelar #include <linux/openvswitch.h>
25*e6445719SPravin B Shelar #include <linux/spinlock.h>
26*e6445719SPravin B Shelar #include <linux/types.h>
27*e6445719SPravin B Shelar #include <linux/rcupdate.h>
28*e6445719SPravin B Shelar #include <linux/if_ether.h>
29*e6445719SPravin B Shelar #include <linux/in6.h>
30*e6445719SPravin B Shelar #include <linux/jiffies.h>
31*e6445719SPravin B Shelar #include <linux/time.h>
32*e6445719SPravin B Shelar #include <linux/flex_array.h>
33*e6445719SPravin B Shelar 
34*e6445719SPravin B Shelar #include <net/inet_ecn.h>
35*e6445719SPravin B Shelar #include <net/ip_tunnels.h>
36*e6445719SPravin B Shelar 
37*e6445719SPravin B Shelar #include "flow.h"
38*e6445719SPravin B Shelar 
39*e6445719SPravin B Shelar #define TBL_MIN_BUCKETS		1024
40*e6445719SPravin B Shelar 
41*e6445719SPravin B Shelar struct flow_table {
42*e6445719SPravin B Shelar 	struct flex_array *buckets;
43*e6445719SPravin B Shelar 	unsigned int count, n_buckets;
44*e6445719SPravin B Shelar 	struct rcu_head rcu;
45*e6445719SPravin B Shelar 	struct list_head *mask_list;
46*e6445719SPravin B Shelar 	int node_ver;
47*e6445719SPravin B Shelar 	u32 hash_seed;
48*e6445719SPravin B Shelar 	bool keep_flows;
49*e6445719SPravin B Shelar };
50*e6445719SPravin B Shelar 
51*e6445719SPravin B Shelar int ovs_flow_init(void);
52*e6445719SPravin B Shelar void ovs_flow_exit(void);
53*e6445719SPravin B Shelar 
54*e6445719SPravin B Shelar struct sw_flow *ovs_flow_alloc(void);
55*e6445719SPravin B Shelar void ovs_flow_free(struct sw_flow *, bool deferred);
56*e6445719SPravin B Shelar 
57*e6445719SPravin B Shelar static inline int ovs_flow_tbl_count(struct flow_table *table)
58*e6445719SPravin B Shelar {
59*e6445719SPravin B Shelar 	return table->count;
60*e6445719SPravin B Shelar }
61*e6445719SPravin B Shelar 
62*e6445719SPravin B Shelar static inline int ovs_flow_tbl_need_to_expand(struct flow_table *table)
63*e6445719SPravin B Shelar {
64*e6445719SPravin B Shelar 	return (table->count > table->n_buckets);
65*e6445719SPravin B Shelar }
66*e6445719SPravin B Shelar 
67*e6445719SPravin B Shelar struct flow_table *ovs_flow_tbl_alloc(int new_size);
68*e6445719SPravin B Shelar struct flow_table *ovs_flow_tbl_expand(struct flow_table *table);
69*e6445719SPravin B Shelar struct flow_table *ovs_flow_tbl_rehash(struct flow_table *table);
70*e6445719SPravin B Shelar void ovs_flow_tbl_destroy(struct flow_table *table, bool deferred);
71*e6445719SPravin B Shelar 
72*e6445719SPravin B Shelar void ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow);
73*e6445719SPravin B Shelar void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
74*e6445719SPravin B Shelar struct sw_flow *ovs_flow_tbl_dump_next(struct flow_table *table,
75*e6445719SPravin B Shelar 				       u32 *bucket, u32 *idx);
76*e6445719SPravin B Shelar struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
77*e6445719SPravin B Shelar 				    const struct sw_flow_key *);
78*e6445719SPravin B Shelar 
79*e6445719SPravin B Shelar bool ovs_flow_cmp_unmasked_key(const struct sw_flow *flow,
80*e6445719SPravin B Shelar 			       struct sw_flow_match *match);
81*e6445719SPravin B Shelar 
82*e6445719SPravin B Shelar struct sw_flow_mask *ovs_sw_flow_mask_alloc(void);
83*e6445719SPravin B Shelar void ovs_sw_flow_mask_add_ref(struct sw_flow_mask *);
84*e6445719SPravin B Shelar void ovs_sw_flow_mask_del_ref(struct sw_flow_mask *, bool deferred);
85*e6445719SPravin B Shelar void ovs_sw_flow_mask_insert(struct flow_table *, struct sw_flow_mask *);
86*e6445719SPravin B Shelar struct sw_flow_mask *ovs_sw_flow_mask_find(const struct flow_table *,
87*e6445719SPravin B Shelar 					   const struct sw_flow_mask *);
88*e6445719SPravin B Shelar void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
89*e6445719SPravin B Shelar 		       const struct sw_flow_mask *mask);
90*e6445719SPravin B Shelar 
91*e6445719SPravin B Shelar #endif /* flow_table.h */
92