datapath: Inline flow_cast().
[sliver-openvswitch.git] / datapath / flow.h
1 /*
2  * Copyright (c) 2009, 2010 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 #include <linux/jiffies.h>
18 #include <linux/time.h>
19
20 #include "openvswitch/datapath-protocol.h"
21 #include "table.h"
22
23 struct sk_buff;
24
25 struct sw_flow_actions {
26         struct rcu_head rcu;
27         unsigned int n_actions;
28         union odp_action actions[];
29 };
30
31 struct sw_flow {
32         struct rcu_head rcu;
33         struct tbl_node tbl_node;
34
35         struct odp_flow_key key;
36         struct sw_flow_actions *sf_acts;
37
38         spinlock_t lock;        /* Lock for values below. */
39         unsigned long used;     /* Last used time (in jiffies). */
40         u64 packet_count;       /* Number of packets matched. */
41         u64 byte_count;         /* Number of bytes matched. */
42         u8 tcp_flags;           /* Union of seen TCP flags. */
43 };
44
45 extern struct kmem_cache *flow_cache;
46
47 struct sw_flow_actions *flow_actions_alloc(size_t n_actions);
48 void flow_deferred_free(struct sw_flow *);
49 void flow_deferred_free_acts(struct sw_flow_actions *);
50 int flow_extract(struct sk_buff *, u16 in_port, struct odp_flow_key *);
51 void flow_used(struct sw_flow *, struct sk_buff *);
52
53 u32 flow_hash(const struct odp_flow_key *key);
54 int flow_cmp(const struct tbl_node *, void *target);
55 void flow_free_tbl(struct tbl_node *);
56
57 int flow_init(void);
58 void flow_exit(void);
59
60 static inline struct sw_flow *flow_cast(const struct tbl_node *node)
61 {
62         return container_of(node, struct sw_flow, tbl_node);
63 }
64
65 #endif /* flow.h */