datapath: Replace "struct odp_action" by Netlink attributes.
[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/if_ether.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         u32 actions_len;
28         struct nlattr 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         atomic_t refcnt;
39         bool dead;
40
41         spinlock_t lock;        /* Lock for values below. */
42         unsigned long used;     /* Last used time (in jiffies). */
43         u64 packet_count;       /* Number of packets matched. */
44         u64 byte_count;         /* Number of bytes matched. */
45         u8 tcp_flags;           /* Union of seen TCP flags. */
46 };
47
48 struct arp_eth_header
49 {
50         __be16      ar_hrd;     /* format of hardware address   */
51         __be16      ar_pro;     /* format of protocol address   */
52         unsigned char   ar_hln; /* length of hardware address   */
53         unsigned char   ar_pln; /* length of protocol address   */
54         __be16      ar_op;      /* ARP opcode (command)     */
55
56         /* Ethernet+IPv4 specific members. */
57         unsigned char       ar_sha[ETH_ALEN];   /* sender hardware address  */
58         unsigned char       ar_sip[4];          /* sender IP address        */
59         unsigned char       ar_tha[ETH_ALEN];   /* target hardware address  */
60         unsigned char       ar_tip[4];          /* target IP address        */
61 } __attribute__((packed));
62
63 int flow_init(void);
64 void flow_exit(void);
65
66 struct sw_flow *flow_alloc(void);
67 void flow_deferred_free(struct sw_flow *);
68 void flow_free_tbl(struct tbl_node *);
69
70 struct sw_flow_actions *flow_actions_alloc(u32 actions_len);
71 void flow_deferred_free_acts(struct sw_flow_actions *);
72
73 void flow_hold(struct sw_flow *);
74 void flow_put(struct sw_flow *);
75
76 int flow_extract(struct sk_buff *, u16 in_port, struct odp_flow_key *, bool *is_frag);
77 void flow_used(struct sw_flow *, struct sk_buff *);
78
79 u32 flow_hash(const struct odp_flow_key *key);
80 int flow_cmp(const struct tbl_node *, void *target);
81
82 static inline struct sw_flow *flow_cast(const struct tbl_node *node)
83 {
84         return container_of(node, struct sw_flow, tbl_node);
85 }
86
87 #endif /* flow.h */