blob: 9e659db78c05ab1e09aa6d041418542d9123f91e [file] [log] [blame]
Thomas Gleixnerc9422992019-05-29 07:12:43 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Pravin B Shelare6445712013-10-03 18:16:47 -07002/*
3 * Copyright (c) 2007-2013 Nicira, Inc.
Pravin B Shelare6445712013-10-03 18:16:47 -07004 */
5
6#ifndef FLOW_TABLE_H
7#define FLOW_TABLE_H 1
8
9#include <linux/kernel.h>
10#include <linux/netlink.h>
11#include <linux/openvswitch.h>
12#include <linux/spinlock.h>
13#include <linux/types.h>
14#include <linux/rcupdate.h>
15#include <linux/if_ether.h>
16#include <linux/in6.h>
17#include <linux/jiffies.h>
18#include <linux/time.h>
Pravin B Shelare6445712013-10-03 18:16:47 -070019
20#include <net/inet_ecn.h>
21#include <net/ip_tunnels.h>
22
23#include "flow.h"
24
Tonghao Zhang04b7d132019-11-01 22:23:45 +080025struct mask_cache_entry {
26 u32 skb_hash;
27 u32 mask_index;
28};
29
Eelco Chaudron9bf24f52020-07-31 14:21:34 +020030struct mask_cache {
31 struct rcu_head rcu;
32 u32 cache_size; /* Must be ^2 value. */
33 struct mask_cache_entry __percpu *mask_cache;
34};
35
Eelco Chaudroneac87c42020-07-15 14:09:28 +020036struct mask_count {
37 int index;
38 u64 counter;
39};
40
Eelco Chaudronf981fc32020-10-17 20:24:51 +020041struct mask_array_stats {
42 struct u64_stats_sync syncp;
43 u64 usage_cntrs[];
44};
45
Tonghao Zhang4bc63b12019-11-01 22:23:46 +080046struct mask_array {
47 struct rcu_head rcu;
48 int count, max;
Eelco Chaudronf981fc32020-10-17 20:24:51 +020049 struct mask_array_stats __percpu *masks_usage_stats;
Eelco Chaudroneac87c42020-07-15 14:09:28 +020050 u64 *masks_usage_zero_cntr;
Tonghao Zhang4bc63b12019-11-01 22:23:46 +080051 struct sw_flow_mask __rcu *masks[];
52};
53
Pravin B Shelarb637e492013-10-04 00:14:23 -070054struct table_instance {
Kent Overstreetee9c5e62019-03-11 23:31:02 -070055 struct hlist_head *buckets;
Pravin B Shelarb637e492013-10-04 00:14:23 -070056 unsigned int n_buckets;
Pravin B Shelare6445712013-10-03 18:16:47 -070057 struct rcu_head rcu;
Pravin B Shelare6445712013-10-03 18:16:47 -070058 int node_ver;
59 u32 hash_seed;
Pravin B Shelare6445712013-10-03 18:16:47 -070060};
61
Pravin B Shelarb637e492013-10-04 00:14:23 -070062struct flow_table {
63 struct table_instance __rcu *ti;
Joe Stringer74ed7ab2015-01-21 16:42:52 -080064 struct table_instance __rcu *ufid_ti;
Eelco Chaudron9bf24f52020-07-31 14:21:34 +020065 struct mask_cache __rcu *mask_cache;
Tonghao Zhang4bc63b12019-11-01 22:23:46 +080066 struct mask_array __rcu *mask_array;
Pravin B Shelarb637e492013-10-04 00:14:23 -070067 unsigned long last_rehash;
68 unsigned int count;
Joe Stringer74ed7ab2015-01-21 16:42:52 -080069 unsigned int ufid_count;
Pravin B Shelarb637e492013-10-04 00:14:23 -070070};
71
Jarno Rajahalme63e79592014-03-27 12:42:54 -070072extern struct kmem_cache *flow_stats_cache;
73
Pravin B Shelare6445712013-10-03 18:16:47 -070074int ovs_flow_init(void);
75void ovs_flow_exit(void);
76
Jarno Rajahalme23dabf82014-03-27 12:35:23 -070077struct sw_flow *ovs_flow_alloc(void);
Pravin B Shelare6445712013-10-03 18:16:47 -070078void ovs_flow_free(struct sw_flow *, bool deferred);
79
Pravin B Shelarb637e492013-10-04 00:14:23 -070080int ovs_flow_tbl_init(struct flow_table *);
Thomas Graf12eb18f2014-11-06 06:58:52 -080081int ovs_flow_tbl_count(const struct flow_table *table);
Pravin B Shelar9b996e52014-05-06 18:41:20 -070082void ovs_flow_tbl_destroy(struct flow_table *table);
Pravin B Shelarb637e492013-10-04 00:14:23 -070083int ovs_flow_tbl_flush(struct flow_table *flow_table);
Pravin B Shelare6445712013-10-03 18:16:47 -070084
Pravin B Shelar618ed0c2013-10-04 00:17:42 -070085int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
Thomas Graf12eb18f2014-11-06 06:58:52 -080086 const struct sw_flow_mask *mask);
Pravin B Shelare6445712013-10-03 18:16:47 -070087void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
Andy Zhou1bd71162013-10-22 10:42:46 -070088int ovs_flow_tbl_num_masks(const struct flow_table *table);
Eelco Chaudron9bf24f52020-07-31 14:21:34 +020089u32 ovs_flow_tbl_masks_cache_size(const struct flow_table *table);
90int ovs_flow_tbl_masks_cache_resize(struct flow_table *table, u32 size);
Pravin B Shelarb637e492013-10-04 00:14:23 -070091struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
Pravin B Shelare6445712013-10-03 18:16:47 -070092 u32 *bucket, u32 *idx);
Andy Zhou5bb50632013-11-25 10:42:46 -080093struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
Tonghao Zhang04b7d132019-11-01 22:23:45 +080094 const struct sw_flow_key *,
95 u32 skb_hash,
Eelco Chaudron9d2f6272020-07-31 14:20:56 +020096 u32 *n_mask_hit,
97 u32 *n_cache_hit);
Andy Zhou5bb50632013-11-25 10:42:46 -080098struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
99 const struct sw_flow_key *);
Alex Wang4a46b242014-06-30 20:30:29 -0700100struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
Thomas Graf12eb18f2014-11-06 06:58:52 -0800101 const struct sw_flow_match *match);
Joe Stringer74ed7ab2015-01-21 16:42:52 -0800102struct sw_flow *ovs_flow_tbl_lookup_ufid(struct flow_table *,
103 const struct sw_flow_id *);
104
105bool ovs_flow_cmp(const struct sw_flow *, const struct sw_flow_match *);
Pravin B Shelare6445712013-10-03 18:16:47 -0700106
Pravin B Shelare6445712013-10-03 18:16:47 -0700107void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
Jesse Grossae5f2fb2015-09-21 20:21:20 -0700108 bool full, const struct sw_flow_mask *mask);
Eelco Chaudroneac87c42020-07-15 14:09:28 +0200109
110void ovs_flow_masks_rebalance(struct flow_table *table);
Tonghao Zhang1f3a0902020-08-12 17:56:39 +0800111void table_instance_flow_flush(struct flow_table *table,
112 struct table_instance *ti,
113 struct table_instance *ufid_ti);
Eelco Chaudroneac87c42020-07-15 14:09:28 +0200114
Pravin B Shelare6445712013-10-03 18:16:47 -0700115#endif /* flow_table.h */