]>
Commit | Line | Data |
---|---|---|
a14bc59f | 1 | /* |
d6569377 | 2 | * Copyright (c) 2009, 2010, 2011 Nicira Networks. |
a14bc59f BP |
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 | ||
064af421 BP |
9 | #ifndef FLOW_H |
10 | #define FLOW_H 1 | |
11 | ||
12 | #include <linux/kernel.h> | |
78d18dbb | 13 | #include <linux/netlink.h> |
077257b8 | 14 | #include <linux/openvswitch.h> |
064af421 BP |
15 | #include <linux/spinlock.h> |
16 | #include <linux/types.h> | |
17 | #include <linux/rcupdate.h> | |
401eeb92 | 18 | #include <linux/if_ether.h> |
bfef4717 | 19 | #include <linux/in6.h> |
6bfafa55 | 20 | #include <linux/jiffies.h> |
5153ef3d | 21 | #include <linux/time.h> |
3544358a | 22 | #include <linux/flex_array.h> |
7257b535 | 23 | #include <net/inet_ecn.h> |
064af421 BP |
24 | |
25 | struct sk_buff; | |
26 | ||
27 | struct sw_flow_actions { | |
28 | struct rcu_head rcu; | |
cdee00fd BP |
29 | u32 actions_len; |
30 | struct nlattr actions[]; | |
064af421 BP |
31 | }; |
32 | ||
36956a7d | 33 | struct sw_flow_key { |
76abe283 | 34 | struct { |
abff858b PS |
35 | __be64 tun_id; /* Encapsulating tunnel ID. */ |
36 | u32 priority; /* Packet QoS priority. */ | |
37 | u16 in_port; /* Input switch port (or USHRT_MAX). */ | |
38 | } phy; | |
39 | struct { | |
76abe283 AE |
40 | u8 src[ETH_ALEN]; /* Ethernet source address. */ |
41 | u8 dst[ETH_ALEN]; /* Ethernet destination address. */ | |
42 | __be16 tci; /* 0 if no VLAN, VLAN_TAG_PRESENT set otherwise. */ | |
43 | __be16 type; /* Ethernet frame type. */ | |
44 | } eth; | |
45 | struct { | |
28bad473 | 46 | u8 proto; /* IP protocol or lower 8 bits of ARP opcode. */ |
530180fd | 47 | u8 tos; /* IP ToS. */ |
b1672b4c JG |
48 | u8 ttl; /* IP TTL/hop limit. */ |
49 | u8 frag; /* One of OVS_FRAG_TYPE_*. */ | |
76abe283 | 50 | } ip; |
d31f1109 JP |
51 | union { |
52 | struct { | |
76abe283 AE |
53 | struct { |
54 | __be32 src; /* IP source address. */ | |
55 | __be32 dst; /* IP destination address. */ | |
56 | } addr; | |
57 | union { | |
58 | struct { | |
59 | __be16 src; /* TCP/UDP source port. */ | |
60 | __be16 dst; /* TCP/UDP destination port. */ | |
61 | } tp; | |
62 | struct { | |
63 | u8 sha[ETH_ALEN]; /* ARP source hardware address. */ | |
64 | u8 tha[ETH_ALEN]; /* ARP target hardware address. */ | |
65 | } arp; | |
66 | }; | |
67 | } ipv4; | |
d31f1109 | 68 | struct { |
76abe283 AE |
69 | struct { |
70 | struct in6_addr src; /* IPv6 source address. */ | |
71 | struct in6_addr dst; /* IPv6 destination address. */ | |
72 | } addr; | |
b1672b4c | 73 | __be32 label; /* IPv6 flow label. */ |
76abe283 AE |
74 | struct { |
75 | __be16 src; /* TCP/UDP source port. */ | |
76 | __be16 dst; /* TCP/UDP destination port. */ | |
77 | } tp; | |
78 | struct { | |
79 | struct in6_addr target; /* ND target address. */ | |
80 | u8 sll[ETH_ALEN]; /* ND source link layer address. */ | |
81 | u8 tll[ETH_ALEN]; /* ND target link layer address. */ | |
82 | } nd; | |
83 | } ipv6; | |
d31f1109 | 84 | }; |
36956a7d BP |
85 | }; |
86 | ||
064af421 BP |
87 | struct sw_flow { |
88 | struct rcu_head rcu; | |
3544358a PS |
89 | struct hlist_node hash_node; |
90 | u32 hash; | |
8d5ebd83 | 91 | |
36956a7d | 92 | struct sw_flow_key key; |
e1040c77 | 93 | struct sw_flow_actions __rcu *sf_acts; |
064af421 | 94 | |
fb8c9347 JG |
95 | atomic_t refcnt; |
96 | bool dead; | |
97 | ||
064af421 | 98 | spinlock_t lock; /* Lock for values below. */ |
6bfafa55 | 99 | unsigned long used; /* Last used time (in jiffies). */ |
064af421 BP |
100 | u64 packet_count; /* Number of packets matched. */ |
101 | u64 byte_count; /* Number of bytes matched. */ | |
102 | u8 tcp_flags; /* Union of seen TCP flags. */ | |
103 | }; | |
104 | ||
6455100f | 105 | struct arp_eth_header { |
401eeb92 BP |
106 | __be16 ar_hrd; /* format of hardware address */ |
107 | __be16 ar_pro; /* format of protocol address */ | |
108 | unsigned char ar_hln; /* length of hardware address */ | |
109 | unsigned char ar_pln; /* length of protocol address */ | |
110 | __be16 ar_op; /* ARP opcode (command) */ | |
111 | ||
112 | /* Ethernet+IPv4 specific members. */ | |
113 | unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */ | |
114 | unsigned char ar_sip[4]; /* sender IP address */ | |
115 | unsigned char ar_tha[ETH_ALEN]; /* target hardware address */ | |
116 | unsigned char ar_tip[4]; /* target IP address */ | |
961703de | 117 | } __packed; |
401eeb92 | 118 | |
560e8022 JG |
119 | int flow_init(void); |
120 | void flow_exit(void); | |
064af421 | 121 | |
560e8022 | 122 | struct sw_flow *flow_alloc(void); |
064af421 | 123 | void flow_deferred_free(struct sw_flow *); |
560e8022 | 124 | |
37a1300c | 125 | struct sw_flow_actions *flow_actions_alloc(const struct nlattr *); |
064af421 | 126 | void flow_deferred_free_acts(struct sw_flow_actions *); |
560e8022 | 127 | |
fb8c9347 JG |
128 | void flow_hold(struct sw_flow *); |
129 | void flow_put(struct sw_flow *); | |
130 | ||
76abe283 | 131 | int flow_extract(struct sk_buff *, u16 in_port, struct sw_flow_key *, |
7257b535 | 132 | int *key_lenp); |
064af421 | 133 | void flow_used(struct sw_flow *, struct sk_buff *); |
ec58547a | 134 | u64 flow_used_time(unsigned long flow_jiffies); |
064af421 | 135 | |
18c43631 JP |
136 | /* Upper bound on the length of a nlattr-formatted flow key. The longest |
137 | * nlattr-formatted flow key would be: | |
138 | * | |
139 | * struct pad nl hdr total | |
140 | * ------ --- ------ ----- | |
abff858b | 141 | * OVS_KEY_ATTR_PRIORITY 4 -- 4 8 |
df2c07f4 JP |
142 | * OVS_KEY_ATTR_TUN_ID 8 -- 4 12 |
143 | * OVS_KEY_ATTR_IN_PORT 4 -- 4 8 | |
144 | * OVS_KEY_ATTR_ETHERNET 12 -- 4 16 | |
145 | * OVS_KEY_ATTR_8021Q 4 -- 4 8 | |
146 | * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 | |
a61680c6 | 147 | * OVS_KEY_ATTR_IPV6 40 -- 4 44 |
df2c07f4 JP |
148 | * OVS_KEY_ATTR_ICMPV6 2 2 4 8 |
149 | * OVS_KEY_ATTR_ND 28 -- 4 32 | |
18c43631 | 150 | * ------------------------------------------------- |
fa8223b7 | 151 | * total 144 |
36956a7d | 152 | */ |
fa8223b7 | 153 | #define FLOW_BUFSIZE 144 |
36956a7d | 154 | |
d6569377 | 155 | int flow_to_nlattrs(const struct sw_flow_key *, struct sk_buff *); |
76abe283 AE |
156 | int flow_from_nlattrs(struct sw_flow_key *swkey, int *key_lenp, |
157 | const struct nlattr *); | |
abff858b | 158 | int flow_metadata_from_nlattrs(u32 *priority, u16 *in_port, __be64 *tun_id, |
80e5eed9 | 159 | const struct nlattr *); |
36956a7d | 160 | |
3544358a PS |
161 | #define TBL_MIN_BUCKETS 1024 |
162 | ||
163 | struct flow_table { | |
6455100f PS |
164 | struct flex_array *buckets; |
165 | unsigned int count, n_buckets; | |
166 | struct rcu_head rcu; | |
3544358a PS |
167 | }; |
168 | ||
169 | static inline int flow_tbl_count(struct flow_table *table) | |
9d209493 | 170 | { |
3544358a | 171 | return table->count; |
9d209493 BP |
172 | } |
173 | ||
3544358a PS |
174 | static inline int flow_tbl_need_to_expand(struct flow_table *table) |
175 | { | |
176 | return (table->count > table->n_buckets); | |
177 | } | |
178 | ||
179 | struct sw_flow *flow_tbl_lookup(struct flow_table *table, | |
180 | struct sw_flow_key *key, int len); | |
181 | void flow_tbl_destroy(struct flow_table *table); | |
182 | void flow_tbl_deferred_destroy(struct flow_table *table); | |
183 | struct flow_table *flow_tbl_alloc(int new_size); | |
184 | struct flow_table *flow_tbl_expand(struct flow_table *table); | |
185 | void flow_tbl_insert(struct flow_table *table, struct sw_flow *flow); | |
186 | void flow_tbl_remove(struct flow_table *table, struct sw_flow *flow); | |
187 | u32 flow_hash(const struct sw_flow_key *key, int key_len); | |
188 | ||
189 | struct sw_flow *flow_tbl_next(struct flow_table *table, u32 *bucket, u32 *idx); | |
4edb9ae9 | 190 | extern const u32 ovs_key_lens[OVS_KEY_ATTR_MAX + 1]; |
3544358a | 191 | |
064af421 | 192 | #endif /* flow.h */ |