datapath: Genericize hash table.
[sliver-openvswitch.git] / datapath / flow.h
1 /*
2  * Copyright (c) 2009 Nicira Networks.
3  * Distributed under the terms of the GNU GPL version 2.
4  *
5  * Significant portions of this file may be copied from parts of the Linux
6  * kernel, by Linus Torvalds and others.
7  */
8
9 #ifndef FLOW_H
10 #define FLOW_H 1
11
12 #include <linux/kernel.h>
13 #include <linux/spinlock.h>
14 #include <linux/types.h>
15 #include <linux/rcupdate.h>
16 #include <linux/gfp.h>
17
18 #include "openvswitch/datapath-protocol.h"
19 #include "table.h"
20
21 struct sk_buff;
22
23 struct sw_flow_actions {
24         struct rcu_head rcu;
25         unsigned int n_actions;
26         union odp_action actions[];
27 };
28
29 struct sw_flow {
30         struct rcu_head rcu;
31         struct tbl_node tbl_node;
32
33         struct odp_flow_key key;
34         struct sw_flow_actions *sf_acts;
35
36         struct timespec used;   /* Last used time. */
37
38         u8 ip_tos;              /* IP TOS value. */
39
40         spinlock_t lock;        /* Lock for values below. */
41         u64 packet_count;       /* Number of packets matched. */
42         u64 byte_count;         /* Number of bytes matched. */
43         u8 tcp_flags;           /* Union of seen TCP flags. */
44 };
45
46 extern struct kmem_cache *flow_cache;
47
48 struct sw_flow_actions *flow_actions_alloc(size_t n_actions);
49 void flow_deferred_free(struct sw_flow *);
50 void flow_deferred_free_acts(struct sw_flow_actions *);
51 int flow_extract(struct sk_buff *, u16 in_port, struct odp_flow_key *);
52 void flow_used(struct sw_flow *, struct sk_buff *);
53
54 struct sw_flow *flow_cast(const struct tbl_node *);
55 u32 flow_hash(const struct odp_flow_key *key);
56 int flow_cmp(const struct tbl_node *, void *target);
57 void flow_free_tbl(struct tbl_node *);
58
59 int flow_init(void);
60 void flow_exit(void);
61
62 #endif /* flow.h */