Loading...
1/*
2 * Copyright (c) 2007-2013 Nicira, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301, USA
17 */
18
19#ifndef FLOW_TABLE_H
20#define FLOW_TABLE_H 1
21
22#include <linux/kernel.h>
23#include <linux/netlink.h>
24#include <linux/openvswitch.h>
25#include <linux/spinlock.h>
26#include <linux/types.h>
27#include <linux/rcupdate.h>
28#include <linux/if_ether.h>
29#include <linux/in6.h>
30#include <linux/jiffies.h>
31#include <linux/time.h>
32#include <linux/flex_array.h>
33
34#include <net/inet_ecn.h>
35#include <net/ip_tunnels.h>
36
37#include "flow.h"
38
39struct table_instance {
40 struct flex_array *buckets;
41 unsigned int n_buckets;
42 struct rcu_head rcu;
43 int node_ver;
44 u32 hash_seed;
45 bool keep_flows;
46};
47
48struct flow_table {
49 struct table_instance __rcu *ti;
50 struct table_instance __rcu *ufid_ti;
51 struct list_head mask_list;
52 unsigned long last_rehash;
53 unsigned int count;
54 unsigned int ufid_count;
55};
56
57extern struct kmem_cache *flow_stats_cache;
58
59int ovs_flow_init(void);
60void ovs_flow_exit(void);
61
62struct sw_flow *ovs_flow_alloc(void);
63void ovs_flow_free(struct sw_flow *, bool deferred);
64
65int ovs_flow_tbl_init(struct flow_table *);
66int ovs_flow_tbl_count(const struct flow_table *table);
67void ovs_flow_tbl_destroy(struct flow_table *table);
68int ovs_flow_tbl_flush(struct flow_table *flow_table);
69
70int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
71 const struct sw_flow_mask *mask);
72void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
73int ovs_flow_tbl_num_masks(const struct flow_table *table);
74struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
75 u32 *bucket, u32 *idx);
76struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
77 const struct sw_flow_key *,
78 u32 *n_mask_hit);
79struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
80 const struct sw_flow_key *);
81struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
82 const struct sw_flow_match *match);
83struct sw_flow *ovs_flow_tbl_lookup_ufid(struct flow_table *,
84 const struct sw_flow_id *);
85
86bool ovs_flow_cmp(const struct sw_flow *, const struct sw_flow_match *);
87
88void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
89 bool full, const struct sw_flow_mask *mask);
90#endif /* flow_table.h */
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (c) 2007-2013 Nicira, Inc.
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>
19
20#include <net/inet_ecn.h>
21#include <net/ip_tunnels.h>
22
23#include "flow.h"
24
25struct mask_cache_entry {
26 u32 skb_hash;
27 u32 mask_index;
28};
29
30struct 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
36struct mask_count {
37 int index;
38 u64 counter;
39};
40
41struct mask_array {
42 struct rcu_head rcu;
43 int count, max;
44 u64 __percpu *masks_usage_cntr;
45 u64 *masks_usage_zero_cntr;
46 struct u64_stats_sync syncp;
47 struct sw_flow_mask __rcu *masks[];
48};
49
50struct table_instance {
51 struct hlist_head *buckets;
52 unsigned int n_buckets;
53 struct rcu_head rcu;
54 int node_ver;
55 u32 hash_seed;
56 bool keep_flows;
57};
58
59struct flow_table {
60 struct table_instance __rcu *ti;
61 struct table_instance __rcu *ufid_ti;
62 struct mask_cache __rcu *mask_cache;
63 struct mask_array __rcu *mask_array;
64 unsigned long last_rehash;
65 unsigned int count;
66 unsigned int ufid_count;
67};
68
69extern struct kmem_cache *flow_stats_cache;
70
71int ovs_flow_init(void);
72void ovs_flow_exit(void);
73
74struct sw_flow *ovs_flow_alloc(void);
75void ovs_flow_free(struct sw_flow *, bool deferred);
76
77int ovs_flow_tbl_init(struct flow_table *);
78int ovs_flow_tbl_count(const struct flow_table *table);
79void ovs_flow_tbl_destroy(struct flow_table *table);
80int ovs_flow_tbl_flush(struct flow_table *flow_table);
81
82int ovs_flow_tbl_insert(struct flow_table *table, struct sw_flow *flow,
83 const struct sw_flow_mask *mask);
84void ovs_flow_tbl_remove(struct flow_table *table, struct sw_flow *flow);
85int ovs_flow_tbl_num_masks(const struct flow_table *table);
86u32 ovs_flow_tbl_masks_cache_size(const struct flow_table *table);
87int ovs_flow_tbl_masks_cache_resize(struct flow_table *table, u32 size);
88struct sw_flow *ovs_flow_tbl_dump_next(struct table_instance *table,
89 u32 *bucket, u32 *idx);
90struct sw_flow *ovs_flow_tbl_lookup_stats(struct flow_table *,
91 const struct sw_flow_key *,
92 u32 skb_hash,
93 u32 *n_mask_hit,
94 u32 *n_cache_hit);
95struct sw_flow *ovs_flow_tbl_lookup(struct flow_table *,
96 const struct sw_flow_key *);
97struct sw_flow *ovs_flow_tbl_lookup_exact(struct flow_table *tbl,
98 const struct sw_flow_match *match);
99struct sw_flow *ovs_flow_tbl_lookup_ufid(struct flow_table *,
100 const struct sw_flow_id *);
101
102bool ovs_flow_cmp(const struct sw_flow *, const struct sw_flow_match *);
103
104void ovs_flow_mask_key(struct sw_flow_key *dst, const struct sw_flow_key *src,
105 bool full, const struct sw_flow_mask *mask);
106
107void ovs_flow_masks_rebalance(struct flow_table *table);
108void table_instance_flow_flush(struct flow_table *table,
109 struct table_instance *ti,
110 struct table_instance *ufid_ti);
111
112#endif /* flow_table.h */