Thomas Gleixner | c942299 | 2019-05-29 07:12:43 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2007-2013 Nicira, Inc. |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 4 | */ |
| 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 Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 19 | |
| 20 | #include <net/inet_ecn.h> |
| 21 | #include <net/ip_tunnels.h> |
| 22 | |
| 23 | #include "flow.h" |
| 24 | |
Tonghao Zhang | 04b7d13 | 2019-11-01 22:23:45 +0800 | [diff] [blame] | 25 | struct mask_cache_entry { |
| 26 | u32 skb_hash; |
| 27 | u32 mask_index; |
| 28 | }; |
| 29 | |
Eelco Chaudron | 9bf24f5 | 2020-07-31 14:21:34 +0200 | [diff] [blame] | 30 | struct 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 Chaudron | eac87c4 | 2020-07-15 14:09:28 +0200 | [diff] [blame] | 36 | struct mask_count { |
| 37 | int index; |
| 38 | u64 counter; |
| 39 | }; |
| 40 | |
Eelco Chaudron | f981fc3 | 2020-10-17 20:24:51 +0200 | [diff] [blame] | 41 | struct mask_array_stats { |
| 42 | struct u64_stats_sync syncp; |
| 43 | u64 usage_cntrs[]; |
| 44 | }; |
| 45 | |
Tonghao Zhang | 4bc63b1 | 2019-11-01 22:23:46 +0800 | [diff] [blame] | 46 | struct mask_array { |
| 47 | struct rcu_head rcu; |
| 48 | int count, max; |
Eelco Chaudron | f981fc3 | 2020-10-17 20:24:51 +0200 | [diff] [blame] | 49 | struct mask_array_stats __percpu *masks_usage_stats; |
Eelco Chaudron | eac87c4 | 2020-07-15 14:09:28 +0200 | [diff] [blame] | 50 | u64 *masks_usage_zero_cntr; |
Tonghao Zhang | 4bc63b1 | 2019-11-01 22:23:46 +0800 | [diff] [blame] | 51 | struct sw_flow_mask __rcu *masks[]; |
| 52 | }; |
| 53 | |
Pravin B Shelar | b637e49 | 2013-10-04 00:14:23 -0700 | [diff] [blame] | 54 | struct table_instance { |
Kent Overstreet | ee9c5e6 | 2019-03-11 23:31:02 -0700 | [diff] [blame] | 55 | struct hlist_head *buckets; |
Pravin B Shelar | b637e49 | 2013-10-04 00:14:23 -0700 | [diff] [blame] | 56 | unsigned int n_buckets; |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 57 | struct rcu_head rcu; |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 58 | int node_ver; |
| 59 | u32 hash_seed; |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Pravin B Shelar | b637e49 | 2013-10-04 00:14:23 -0700 | [diff] [blame] | 62 | struct flow_table { |
| 63 | struct table_instance __rcu *ti; |
Joe Stringer | 74ed7ab | 2015-01-21 16:42:52 -0800 | [diff] [blame] | 64 | struct table_instance __rcu *ufid_ti; |
Eelco Chaudron | 9bf24f5 | 2020-07-31 14:21:34 +0200 | [diff] [blame] | 65 | struct mask_cache __rcu *mask_cache; |
Tonghao Zhang | 4bc63b1 | 2019-11-01 22:23:46 +0800 | [diff] [blame] | 66 | struct mask_array __rcu *mask_array; |
Pravin B Shelar | b637e49 | 2013-10-04 00:14:23 -0700 | [diff] [blame] | 67 | unsigned long last_rehash; |
| 68 | unsigned int count; |
Joe Stringer | 74ed7ab | 2015-01-21 16:42:52 -0800 | [diff] [blame] | 69 | unsigned int ufid_count; |
Pravin B Shelar | b637e49 | 2013-10-04 00:14:23 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Jarno Rajahalme | 63e7959 | 2014-03-27 12:42:54 -0700 | [diff] [blame] | 72 | extern struct kmem_cache *flow_stats_cache; |
| 73 | |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 74 | int ovs_flow_init(void); |
| 75 | void ovs_flow_exit(void); |
| 76 | |
Jarno Rajahalme | 23dabf8 | 2014-03-27 12:35:23 -0700 | [diff] [blame] | 77 | struct sw_flow *ovs_flow_alloc(void); |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 78 | void ovs_flow_free(struct sw_flow *, bool deferred); |
| 79 | |
Pravin B Shelar | b637e49 | 2013-10-04 00:14:23 -0700 | [diff] [blame] | 80 | int ovs_flow_tbl_init(struct flow_table *); |
Thomas Graf | 12eb18f | 2014-11-06 06:58:52 -0800 | [diff] [blame] | 81 | int ovs_flow_tbl_count(const struct flow_table *table); |
Pravin B Shelar | 9b996e5 | 2014-05-06 18:41:20 -0700 | [diff] [blame] | 82 | void ovs_flow_tbl_destroy(struct flow_table *table); |
Pravin B Shelar | b637e49 | 2013-10-04 00:14:23 -0700 | [diff] [blame] | 83 | int ovs_flow_tbl_flush(struct flow_table *flow_table); |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 84 | |
Pravin B Shelar | 618ed0c | 2013-10-04 00:17:42 -0700 | [diff] [blame] | 85 | int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow, |
Thomas Graf | 12eb18f | 2014-11-06 06:58:52 -0800 | [diff] [blame] | 86 | const struct sw_flow_mask *mask); |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 87 | void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow); |
Andy Zhou | 1bd7116 | 2013-10-22 10:42:46 -0700 | [diff] [blame] | 88 | int ovs_flow_tbl_num_masks(const struct flow_table *table); |
Eelco Chaudron | 9bf24f5 | 2020-07-31 14:21:34 +0200 | [diff] [blame] | 89 | u32 ovs_flow_tbl_masks_cache_size(const struct flow_table *table); |
| 90 | int ovs_flow_tbl_masks_cache_resize(struct flow_table *table, u32 size); |
Pravin B Shelar | b637e49 | 2013-10-04 00:14:23 -0700 | [diff] [blame] | 91 | struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table, |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 92 | u32 *bucket, u32 *idx); |
Andy Zhou | 5bb5063 | 2013-11-25 10:42:46 -0800 | [diff] [blame] | 93 | struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *, |
Tonghao Zhang | 04b7d13 | 2019-11-01 22:23:45 +0800 | [diff] [blame] | 94 | const struct sw_flow_key *, |
| 95 | u32 skb_hash, |
Eelco Chaudron | 9d2f627 | 2020-07-31 14:20:56 +0200 | [diff] [blame] | 96 | u32 *n_mask_hit, |
| 97 | u32 *n_cache_hit); |
Andy Zhou | 5bb5063 | 2013-11-25 10:42:46 -0800 | [diff] [blame] | 98 | struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *, |
| 99 | const struct sw_flow_key *); |
Alex Wang | 4a46b24 | 2014-06-30 20:30:29 -0700 | [diff] [blame] | 100 | struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl, |
Thomas Graf | 12eb18f | 2014-11-06 06:58:52 -0800 | [diff] [blame] | 101 | const struct sw_flow_match *match); |
Joe Stringer | 74ed7ab | 2015-01-21 16:42:52 -0800 | [diff] [blame] | 102 | struct sw_flow *ovs_flow_tbl_lookup_ufid(struct flow_table *, |
| 103 | const struct sw_flow_id *); |
| 104 | |
| 105 | bool ovs_flow_cmp(const struct sw_flow *, const struct sw_flow_match *); |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 106 | |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 107 | void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src, |
Jesse Gross | ae5f2fb | 2015-09-21 20:21:20 -0700 | [diff] [blame] | 108 | bool full, const struct sw_flow_mask *mask); |
Eelco Chaudron | eac87c4 | 2020-07-15 14:09:28 +0200 | [diff] [blame] | 109 | |
| 110 | void ovs_flow_masks_rebalance(struct flow_table *table); |
Tonghao Zhang | 1f3a090 | 2020-08-12 17:56:39 +0800 | [diff] [blame] | 111 | void table_instance_flow_flush(struct flow_table *table, |
| 112 | struct table_instance *ti, |
| 113 | struct table_instance *ufid_ti); |
Eelco Chaudron | eac87c4 | 2020-07-15 14:09:28 +0200 | [diff] [blame] | 114 | |
Pravin B Shelar | e644571 | 2013-10-03 18:16:47 -0700 | [diff] [blame] | 115 | #endif /* flow_table.h */ |