blob: d4c2f735d9992ecf1613a9536b8bc16c52cceb05 [file] [log] [blame]
Jesse Grossccb13522011-10-25 19:26:31 -07001/*
Andy Zhou971427f32014-09-15 19:37:25 -07002 * Copyright (c) 2007-2014 Nicira, Inc.
Jesse Grossccb13522011-10-25 19:26:31 -07003 *
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#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
21#include <linux/skbuff.h>
22#include <linux/in.h>
23#include <linux/ip.h>
24#include <linux/openvswitch.h>
Joe Stringera175a722013-08-22 12:30:48 -070025#include <linux/sctp.h>
Jesse Grossccb13522011-10-25 19:26:31 -070026#include <linux/tcp.h>
27#include <linux/udp.h>
28#include <linux/in6.h>
29#include <linux/if_arp.h>
30#include <linux/if_vlan.h>
Simon Horman25cd9ba2014-10-06 05:05:13 -070031
Jesse Grossccb13522011-10-25 19:26:31 -070032#include <net/ip.h>
Ansis Atteka3fdbd1c2012-11-13 15:44:14 -080033#include <net/ipv6.h>
Jesse Grossccb13522011-10-25 19:26:31 -070034#include <net/checksum.h>
35#include <net/dsfield.h>
Simon Horman25cd9ba2014-10-06 05:05:13 -070036#include <net/mpls.h>
Joe Stringera175a722013-08-22 12:30:48 -070037#include <net/sctp/checksum.h>
Jesse Grossccb13522011-10-25 19:26:31 -070038
39#include "datapath.h"
Andy Zhou971427f32014-09-15 19:37:25 -070040#include "flow.h"
Jesse Grossccb13522011-10-25 19:26:31 -070041#include "vport.h"
42
43static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
Pravin B Shelar2ff3e4e2014-09-15 19:15:28 -070044 struct sw_flow_key *key,
Simon Horman651887b2014-07-21 15:12:34 -070045 const struct nlattr *attr, int len);
Jesse Grossccb13522011-10-25 19:26:31 -070046
Andy Zhou971427f32014-09-15 19:37:25 -070047struct deferred_action {
48 struct sk_buff *skb;
49 const struct nlattr *actions;
50
51 /* Store pkt_key clone when creating deferred action. */
52 struct sw_flow_key pkt_key;
53};
54
55#define DEFERRED_ACTION_FIFO_SIZE 10
56struct action_fifo {
57 int head;
58 int tail;
59 /* Deferred action fifo queue storage. */
60 struct deferred_action fifo[DEFERRED_ACTION_FIFO_SIZE];
61};
62
63static struct action_fifo __percpu *action_fifos;
64static DEFINE_PER_CPU(int, exec_actions_level);
65
66static void action_fifo_init(struct action_fifo *fifo)
67{
68 fifo->head = 0;
69 fifo->tail = 0;
70}
71
72static bool action_fifo_is_empty(struct action_fifo *fifo)
73{
74 return (fifo->head == fifo->tail);
75}
76
77static struct deferred_action *action_fifo_get(struct action_fifo *fifo)
78{
79 if (action_fifo_is_empty(fifo))
80 return NULL;
81
82 return &fifo->fifo[fifo->tail++];
83}
84
85static struct deferred_action *action_fifo_put(struct action_fifo *fifo)
86{
87 if (fifo->head >= DEFERRED_ACTION_FIFO_SIZE - 1)
88 return NULL;
89
90 return &fifo->fifo[fifo->head++];
91}
92
93/* Return true if fifo is not full */
94static struct deferred_action *add_deferred_actions(struct sk_buff *skb,
95 struct sw_flow_key *key,
96 const struct nlattr *attr)
97{
98 struct action_fifo *fifo;
99 struct deferred_action *da;
100
101 fifo = this_cpu_ptr(action_fifos);
102 da = action_fifo_put(fifo);
103 if (da) {
104 da->skb = skb;
105 da->actions = attr;
106 da->pkt_key = *key;
107 }
108
109 return da;
110}
111
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800112static void invalidate_flow_key(struct sw_flow_key *key)
113{
114 key->eth.type = htons(0);
115}
116
117static bool is_flow_key_valid(const struct sw_flow_key *key)
118{
119 return !!key->eth.type;
120}
121
Jesse Grossccb13522011-10-25 19:26:31 -0700122static int make_writable(struct sk_buff *skb, int write_len)
123{
Jiri Benc2ba5af42014-08-21 21:33:44 +0200124 if (!pskb_may_pull(skb, write_len))
125 return -ENOMEM;
126
Jesse Grossccb13522011-10-25 19:26:31 -0700127 if (!skb_cloned(skb) || skb_clone_writable(skb, write_len))
128 return 0;
129
130 return pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
131}
132
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800133static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
Simon Horman25cd9ba2014-10-06 05:05:13 -0700134 const struct ovs_action_push_mpls *mpls)
135{
136 __be32 *new_mpls_lse;
137 struct ethhdr *hdr;
138
139 /* Networking stack do not allow simultaneous Tunnel and MPLS GSO. */
140 if (skb->encapsulation)
141 return -ENOTSUPP;
142
143 if (skb_cow_head(skb, MPLS_HLEN) < 0)
144 return -ENOMEM;
145
146 skb_push(skb, MPLS_HLEN);
147 memmove(skb_mac_header(skb) - MPLS_HLEN, skb_mac_header(skb),
148 skb->mac_len);
149 skb_reset_mac_header(skb);
150
151 new_mpls_lse = (__be32 *)skb_mpls_header(skb);
152 *new_mpls_lse = mpls->mpls_lse;
153
154 if (skb->ip_summed == CHECKSUM_COMPLETE)
155 skb->csum = csum_add(skb->csum, csum_partial(new_mpls_lse,
156 MPLS_HLEN, 0));
157
158 hdr = eth_hdr(skb);
159 hdr->h_proto = mpls->mpls_ethertype;
160
161 skb_set_inner_protocol(skb, skb->protocol);
162 skb->protocol = mpls->mpls_ethertype;
163
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800164 invalidate_flow_key(key);
Simon Horman25cd9ba2014-10-06 05:05:13 -0700165 return 0;
166}
167
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800168static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
169 const __be16 ethertype)
Simon Horman25cd9ba2014-10-06 05:05:13 -0700170{
171 struct ethhdr *hdr;
172 int err;
173
174 err = make_writable(skb, skb->mac_len + MPLS_HLEN);
175 if (unlikely(err))
176 return err;
177
178 if (skb->ip_summed == CHECKSUM_COMPLETE)
179 skb->csum = csum_sub(skb->csum,
180 csum_partial(skb_mpls_header(skb),
181 MPLS_HLEN, 0));
182
183 memmove(skb_mac_header(skb) + MPLS_HLEN, skb_mac_header(skb),
184 skb->mac_len);
185
186 __skb_pull(skb, MPLS_HLEN);
187 skb_reset_mac_header(skb);
188
189 /* skb_mpls_header() is used to locate the ethertype
190 * field correctly in the presence of VLAN tags.
191 */
192 hdr = (struct ethhdr *)(skb_mpls_header(skb) - ETH_HLEN);
193 hdr->h_proto = ethertype;
194 if (eth_p_mpls(skb->protocol))
195 skb->protocol = ethertype;
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800196
197 invalidate_flow_key(key);
Simon Horman25cd9ba2014-10-06 05:05:13 -0700198 return 0;
199}
200
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800201static int set_mpls(struct sk_buff *skb, struct sw_flow_key *key,
202 const __be32 *mpls_lse)
Simon Horman25cd9ba2014-10-06 05:05:13 -0700203{
204 __be32 *stack;
205 int err;
206
207 err = make_writable(skb, skb->mac_len + MPLS_HLEN);
208 if (unlikely(err))
209 return err;
210
211 stack = (__be32 *)skb_mpls_header(skb);
212 if (skb->ip_summed == CHECKSUM_COMPLETE) {
213 __be32 diff[] = { ~(*stack), *mpls_lse };
Simon Horman25cd9ba2014-10-06 05:05:13 -0700214 skb->csum = ~csum_partial((char *)diff, sizeof(diff),
215 ~skb->csum);
216 }
217
218 *stack = *mpls_lse;
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800219 key->mpls.top_lse = *mpls_lse;
Simon Horman25cd9ba2014-10-06 05:05:13 -0700220 return 0;
221}
222
Joe Stringer39855b52012-08-31 15:28:28 -0700223/* remove VLAN header from packet and update csum accordingly. */
Jesse Grossccb13522011-10-25 19:26:31 -0700224static int __pop_vlan_tci(struct sk_buff *skb, __be16 *current_tci)
225{
226 struct vlan_hdr *vhdr;
227 int err;
228
229 err = make_writable(skb, VLAN_ETH_HLEN);
230 if (unlikely(err))
231 return err;
232
233 if (skb->ip_summed == CHECKSUM_COMPLETE)
234 skb->csum = csum_sub(skb->csum, csum_partial(skb->data
Cong Wang7b024082013-02-22 17:32:26 +0800235 + (2 * ETH_ALEN), VLAN_HLEN, 0));
Jesse Grossccb13522011-10-25 19:26:31 -0700236
237 vhdr = (struct vlan_hdr *)(skb->data + ETH_HLEN);
238 *current_tci = vhdr->h_vlan_TCI;
239
240 memmove(skb->data + VLAN_HLEN, skb->data, 2 * ETH_ALEN);
241 __skb_pull(skb, VLAN_HLEN);
242
243 vlan_set_encap_proto(skb, vhdr);
244 skb->mac_header += VLAN_HLEN;
Simon Horman25cd9ba2014-10-06 05:05:13 -0700245
Jiri Benc2ba5af42014-08-21 21:33:44 +0200246 if (skb_network_offset(skb) < ETH_HLEN)
247 skb_set_network_header(skb, ETH_HLEN);
Jesse Grossccb13522011-10-25 19:26:31 -0700248
Simon Horman25cd9ba2014-10-06 05:05:13 -0700249 /* Update mac_len for subsequent MPLS actions */
250 skb_reset_mac_len(skb);
Jesse Grossccb13522011-10-25 19:26:31 -0700251 return 0;
252}
253
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800254static int pop_vlan(struct sk_buff *skb, struct sw_flow_key *key)
Jesse Grossccb13522011-10-25 19:26:31 -0700255{
256 __be16 tci;
257 int err;
258
259 if (likely(vlan_tx_tag_present(skb))) {
260 skb->vlan_tci = 0;
261 } else {
262 if (unlikely(skb->protocol != htons(ETH_P_8021Q) ||
263 skb->len < VLAN_ETH_HLEN))
264 return 0;
265
266 err = __pop_vlan_tci(skb, &tci);
267 if (err)
268 return err;
269 }
270 /* move next vlan tag to hw accel tag */
271 if (likely(skb->protocol != htons(ETH_P_8021Q) ||
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800272 skb->len < VLAN_ETH_HLEN)) {
273 key->eth.tci = 0;
Jesse Grossccb13522011-10-25 19:26:31 -0700274 return 0;
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800275 }
Jesse Grossccb13522011-10-25 19:26:31 -0700276
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800277 invalidate_flow_key(key);
Jesse Grossccb13522011-10-25 19:26:31 -0700278 err = __pop_vlan_tci(skb, &tci);
279 if (unlikely(err))
280 return err;
281
Patrick McHardy86a9bad2013-04-19 02:04:30 +0000282 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ntohs(tci));
Jesse Grossccb13522011-10-25 19:26:31 -0700283 return 0;
284}
285
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800286static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key,
287 const struct ovs_action_push_vlan *vlan)
Jesse Grossccb13522011-10-25 19:26:31 -0700288{
289 if (unlikely(vlan_tx_tag_present(skb))) {
290 u16 current_tag;
291
292 /* push down current VLAN tag */
293 current_tag = vlan_tx_tag_get(skb);
294
Patrick McHardy86a9bad2013-04-19 02:04:30 +0000295 if (!__vlan_put_tag(skb, skb->vlan_proto, current_tag))
Jesse Grossccb13522011-10-25 19:26:31 -0700296 return -ENOMEM;
Simon Horman25cd9ba2014-10-06 05:05:13 -0700297 /* Update mac_len for subsequent MPLS actions */
298 skb->mac_len += VLAN_HLEN;
Jesse Grossccb13522011-10-25 19:26:31 -0700299
300 if (skb->ip_summed == CHECKSUM_COMPLETE)
301 skb->csum = csum_add(skb->csum, csum_partial(skb->data
Cong Wang7b024082013-02-22 17:32:26 +0800302 + (2 * ETH_ALEN), VLAN_HLEN, 0));
Jesse Grossccb13522011-10-25 19:26:31 -0700303
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800304 invalidate_flow_key(key);
305 } else {
306 key->eth.tci = vlan->vlan_tci;
Jesse Grossccb13522011-10-25 19:26:31 -0700307 }
Patrick McHardy86a9bad2013-04-19 02:04:30 +0000308 __vlan_hwaccel_put_tag(skb, vlan->vlan_tpid, ntohs(vlan->vlan_tci) & ~VLAN_TAG_PRESENT);
Jesse Grossccb13522011-10-25 19:26:31 -0700309 return 0;
310}
311
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800312static int set_eth_addr(struct sk_buff *skb, struct sw_flow_key *key,
Jesse Grossccb13522011-10-25 19:26:31 -0700313 const struct ovs_key_ethernet *eth_key)
314{
315 int err;
316 err = make_writable(skb, ETH_HLEN);
317 if (unlikely(err))
318 return err;
319
Pravin B Shelarb34df5e2013-06-13 11:11:44 -0700320 skb_postpull_rcsum(skb, eth_hdr(skb), ETH_ALEN * 2);
321
Joe Perches8c63ff02014-02-18 11:15:45 -0800322 ether_addr_copy(eth_hdr(skb)->h_source, eth_key->eth_src);
323 ether_addr_copy(eth_hdr(skb)->h_dest, eth_key->eth_dst);
Jesse Grossccb13522011-10-25 19:26:31 -0700324
Pravin B Shelarb34df5e2013-06-13 11:11:44 -0700325 ovs_skb_postpush_rcsum(skb, eth_hdr(skb), ETH_ALEN * 2);
326
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800327 ether_addr_copy(key->eth.src, eth_key->eth_src);
328 ether_addr_copy(key->eth.dst, eth_key->eth_dst);
Jesse Grossccb13522011-10-25 19:26:31 -0700329 return 0;
330}
331
332static void set_ip_addr(struct sk_buff *skb, struct iphdr *nh,
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800333 __be32 *addr, __be32 new_addr)
Jesse Grossccb13522011-10-25 19:26:31 -0700334{
335 int transport_len = skb->len - skb_transport_offset(skb);
336
337 if (nh->protocol == IPPROTO_TCP) {
338 if (likely(transport_len >= sizeof(struct tcphdr)))
339 inet_proto_csum_replace4(&tcp_hdr(skb)->check, skb,
340 *addr, new_addr, 1);
341 } else if (nh->protocol == IPPROTO_UDP) {
Jesse Gross81e5d412012-03-06 15:05:46 -0800342 if (likely(transport_len >= sizeof(struct udphdr))) {
343 struct udphdr *uh = udp_hdr(skb);
344
345 if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
346 inet_proto_csum_replace4(&uh->check, skb,
347 *addr, new_addr, 1);
348 if (!uh->check)
349 uh->check = CSUM_MANGLED_0;
350 }
351 }
Jesse Grossccb13522011-10-25 19:26:31 -0700352 }
353
354 csum_replace4(&nh->check, *addr, new_addr);
Tom Herbert7539fad2013-12-15 22:12:18 -0800355 skb_clear_hash(skb);
Jesse Grossccb13522011-10-25 19:26:31 -0700356 *addr = new_addr;
357}
358
Ansis Atteka3fdbd1c2012-11-13 15:44:14 -0800359static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
360 __be32 addr[4], const __be32 new_addr[4])
361{
362 int transport_len = skb->len - skb_transport_offset(skb);
363
364 if (l4_proto == IPPROTO_TCP) {
365 if (likely(transport_len >= sizeof(struct tcphdr)))
366 inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb,
367 addr, new_addr, 1);
368 } else if (l4_proto == IPPROTO_UDP) {
369 if (likely(transport_len >= sizeof(struct udphdr))) {
370 struct udphdr *uh = udp_hdr(skb);
371
372 if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
373 inet_proto_csum_replace16(&uh->check, skb,
374 addr, new_addr, 1);
375 if (!uh->check)
376 uh->check = CSUM_MANGLED_0;
377 }
378 }
379 }
380}
381
382static void set_ipv6_addr(struct sk_buff *skb, u8 l4_proto,
383 __be32 addr[4], const __be32 new_addr[4],
384 bool recalculate_csum)
385{
386 if (recalculate_csum)
387 update_ipv6_checksum(skb, l4_proto, addr, new_addr);
388
Tom Herbert7539fad2013-12-15 22:12:18 -0800389 skb_clear_hash(skb);
Ansis Atteka3fdbd1c2012-11-13 15:44:14 -0800390 memcpy(addr, new_addr, sizeof(__be32[4]));
391}
392
393static void set_ipv6_tc(struct ipv6hdr *nh, u8 tc)
394{
395 nh->priority = tc >> 4;
396 nh->flow_lbl[0] = (nh->flow_lbl[0] & 0x0F) | ((tc & 0x0F) << 4);
397}
398
399static void set_ipv6_fl(struct ipv6hdr *nh, u32 fl)
400{
401 nh->flow_lbl[0] = (nh->flow_lbl[0] & 0xF0) | (fl & 0x000F0000) >> 16;
402 nh->flow_lbl[1] = (fl & 0x0000FF00) >> 8;
403 nh->flow_lbl[2] = fl & 0x000000FF;
404}
405
Jesse Grossccb13522011-10-25 19:26:31 -0700406static void set_ip_ttl(struct sk_buff *skb, struct iphdr *nh, u8 new_ttl)
407{
408 csum_replace2(&nh->check, htons(nh->ttl << 8), htons(new_ttl << 8));
409 nh->ttl = new_ttl;
410}
411
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800412static int set_ipv4(struct sk_buff *skb, struct sw_flow_key *key,
413 const struct ovs_key_ipv4 *ipv4_key)
Jesse Grossccb13522011-10-25 19:26:31 -0700414{
415 struct iphdr *nh;
416 int err;
417
418 err = make_writable(skb, skb_network_offset(skb) +
419 sizeof(struct iphdr));
420 if (unlikely(err))
421 return err;
422
423 nh = ip_hdr(skb);
424
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800425 if (ipv4_key->ipv4_src != nh->saddr) {
Jesse Grossccb13522011-10-25 19:26:31 -0700426 set_ip_addr(skb, nh, &nh->saddr, ipv4_key->ipv4_src);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800427 key->ipv4.addr.src = ipv4_key->ipv4_src;
428 }
Jesse Grossccb13522011-10-25 19:26:31 -0700429
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800430 if (ipv4_key->ipv4_dst != nh->daddr) {
Jesse Grossccb13522011-10-25 19:26:31 -0700431 set_ip_addr(skb, nh, &nh->daddr, ipv4_key->ipv4_dst);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800432 key->ipv4.addr.dst = ipv4_key->ipv4_dst;
433 }
Jesse Grossccb13522011-10-25 19:26:31 -0700434
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800435 if (ipv4_key->ipv4_tos != nh->tos) {
Jesse Grossccb13522011-10-25 19:26:31 -0700436 ipv4_change_dsfield(nh, 0, ipv4_key->ipv4_tos);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800437 key->ip.tos = nh->tos;
438 }
Jesse Grossccb13522011-10-25 19:26:31 -0700439
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800440 if (ipv4_key->ipv4_ttl != nh->ttl) {
Jesse Grossccb13522011-10-25 19:26:31 -0700441 set_ip_ttl(skb, nh, ipv4_key->ipv4_ttl);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800442 key->ip.ttl = ipv4_key->ipv4_ttl;
443 }
Jesse Grossccb13522011-10-25 19:26:31 -0700444
445 return 0;
446}
447
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800448static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *key,
449 const struct ovs_key_ipv6 *ipv6_key)
Ansis Atteka3fdbd1c2012-11-13 15:44:14 -0800450{
451 struct ipv6hdr *nh;
452 int err;
453 __be32 *saddr;
454 __be32 *daddr;
455
456 err = make_writable(skb, skb_network_offset(skb) +
457 sizeof(struct ipv6hdr));
458 if (unlikely(err))
459 return err;
460
461 nh = ipv6_hdr(skb);
462 saddr = (__be32 *)&nh->saddr;
463 daddr = (__be32 *)&nh->daddr;
464
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800465 if (memcmp(ipv6_key->ipv6_src, saddr, sizeof(ipv6_key->ipv6_src))) {
Ansis Atteka3fdbd1c2012-11-13 15:44:14 -0800466 set_ipv6_addr(skb, ipv6_key->ipv6_proto, saddr,
467 ipv6_key->ipv6_src, true);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800468 memcpy(&key->ipv6.addr.src, ipv6_key->ipv6_src,
469 sizeof(ipv6_key->ipv6_src));
470 }
Ansis Atteka3fdbd1c2012-11-13 15:44:14 -0800471
472 if (memcmp(ipv6_key->ipv6_dst, daddr, sizeof(ipv6_key->ipv6_dst))) {
473 unsigned int offset = 0;
474 int flags = IP6_FH_F_SKIP_RH;
475 bool recalc_csum = true;
476
477 if (ipv6_ext_hdr(nh->nexthdr))
478 recalc_csum = ipv6_find_hdr(skb, &offset,
479 NEXTHDR_ROUTING, NULL,
480 &flags) != NEXTHDR_ROUTING;
481
482 set_ipv6_addr(skb, ipv6_key->ipv6_proto, daddr,
483 ipv6_key->ipv6_dst, recalc_csum);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800484 memcpy(&key->ipv6.addr.dst, ipv6_key->ipv6_dst,
485 sizeof(ipv6_key->ipv6_dst));
Ansis Atteka3fdbd1c2012-11-13 15:44:14 -0800486 }
487
488 set_ipv6_tc(nh, ipv6_key->ipv6_tclass);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800489 key->ip.tos = ipv6_get_dsfield(nh);
Ansis Atteka3fdbd1c2012-11-13 15:44:14 -0800490
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800491 set_ipv6_fl(nh, ntohl(ipv6_key->ipv6_label));
492 key->ipv6.label = *(__be32 *)nh & htonl(IPV6_FLOWINFO_FLOWLABEL);
493
494 nh->hop_limit = ipv6_key->ipv6_hlimit;
495 key->ip.ttl = ipv6_key->ipv6_hlimit;
Ansis Atteka3fdbd1c2012-11-13 15:44:14 -0800496 return 0;
497}
498
Jesse Grossccb13522011-10-25 19:26:31 -0700499/* Must follow make_writable() since that can move the skb data. */
500static void set_tp_port(struct sk_buff *skb, __be16 *port,
501 __be16 new_port, __sum16 *check)
502{
503 inet_proto_csum_replace2(check, skb, *port, new_port, 0);
504 *port = new_port;
Tom Herbert7539fad2013-12-15 22:12:18 -0800505 skb_clear_hash(skb);
Jesse Grossccb13522011-10-25 19:26:31 -0700506}
507
Jesse Gross81e5d412012-03-06 15:05:46 -0800508static void set_udp_port(struct sk_buff *skb, __be16 *port, __be16 new_port)
509{
510 struct udphdr *uh = udp_hdr(skb);
511
512 if (uh->check && skb->ip_summed != CHECKSUM_PARTIAL) {
513 set_tp_port(skb, port, new_port, &uh->check);
514
515 if (!uh->check)
516 uh->check = CSUM_MANGLED_0;
517 } else {
518 *port = new_port;
Tom Herbert7539fad2013-12-15 22:12:18 -0800519 skb_clear_hash(skb);
Jesse Gross81e5d412012-03-06 15:05:46 -0800520 }
521}
522
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800523static int set_udp(struct sk_buff *skb, struct sw_flow_key *key,
524 const struct ovs_key_udp *udp_port_key)
Jesse Grossccb13522011-10-25 19:26:31 -0700525{
526 struct udphdr *uh;
527 int err;
528
529 err = make_writable(skb, skb_transport_offset(skb) +
530 sizeof(struct udphdr));
531 if (unlikely(err))
532 return err;
533
534 uh = udp_hdr(skb);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800535 if (udp_port_key->udp_src != uh->source) {
Jesse Gross81e5d412012-03-06 15:05:46 -0800536 set_udp_port(skb, &uh->source, udp_port_key->udp_src);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800537 key->tp.src = udp_port_key->udp_src;
538 }
Jesse Grossccb13522011-10-25 19:26:31 -0700539
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800540 if (udp_port_key->udp_dst != uh->dest) {
Jesse Gross81e5d412012-03-06 15:05:46 -0800541 set_udp_port(skb, &uh->dest, udp_port_key->udp_dst);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800542 key->tp.dst = udp_port_key->udp_dst;
543 }
Jesse Grossccb13522011-10-25 19:26:31 -0700544
545 return 0;
546}
547
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800548static int set_tcp(struct sk_buff *skb, struct sw_flow_key *key,
549 const struct ovs_key_tcp *tcp_port_key)
Jesse Grossccb13522011-10-25 19:26:31 -0700550{
551 struct tcphdr *th;
552 int err;
553
554 err = make_writable(skb, skb_transport_offset(skb) +
555 sizeof(struct tcphdr));
556 if (unlikely(err))
557 return err;
558
559 th = tcp_hdr(skb);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800560 if (tcp_port_key->tcp_src != th->source) {
Jesse Grossccb13522011-10-25 19:26:31 -0700561 set_tp_port(skb, &th->source, tcp_port_key->tcp_src, &th->check);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800562 key->tp.src = tcp_port_key->tcp_src;
563 }
Jesse Grossccb13522011-10-25 19:26:31 -0700564
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800565 if (tcp_port_key->tcp_dst != th->dest) {
Jesse Grossccb13522011-10-25 19:26:31 -0700566 set_tp_port(skb, &th->dest, tcp_port_key->tcp_dst, &th->check);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800567 key->tp.dst = tcp_port_key->tcp_dst;
568 }
Jesse Grossccb13522011-10-25 19:26:31 -0700569
570 return 0;
571}
572
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800573static int set_sctp(struct sk_buff *skb, struct sw_flow_key *key,
574 const struct ovs_key_sctp *sctp_port_key)
Joe Stringera175a722013-08-22 12:30:48 -0700575{
576 struct sctphdr *sh;
577 int err;
578 unsigned int sctphoff = skb_transport_offset(skb);
579
580 err = make_writable(skb, sctphoff + sizeof(struct sctphdr));
581 if (unlikely(err))
582 return err;
583
584 sh = sctp_hdr(skb);
585 if (sctp_port_key->sctp_src != sh->source ||
586 sctp_port_key->sctp_dst != sh->dest) {
587 __le32 old_correct_csum, new_csum, old_csum;
588
589 old_csum = sh->checksum;
590 old_correct_csum = sctp_compute_cksum(skb, sctphoff);
591
592 sh->source = sctp_port_key->sctp_src;
593 sh->dest = sctp_port_key->sctp_dst;
594
595 new_csum = sctp_compute_cksum(skb, sctphoff);
596
597 /* Carry any checksum errors through. */
598 sh->checksum = old_csum ^ old_correct_csum ^ new_csum;
599
Tom Herbert7539fad2013-12-15 22:12:18 -0800600 skb_clear_hash(skb);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800601 key->tp.src = sctp_port_key->sctp_src;
602 key->tp.dst = sctp_port_key->sctp_dst;
Joe Stringera175a722013-08-22 12:30:48 -0700603 }
604
605 return 0;
606}
607
Andy Zhou738967b2014-09-08 00:35:02 -0700608static void do_output(struct datapath *dp, struct sk_buff *skb, int out_port)
Jesse Grossccb13522011-10-25 19:26:31 -0700609{
Andy Zhou738967b2014-09-08 00:35:02 -0700610 struct vport *vport = ovs_vport_rcu(dp, out_port);
Jesse Grossccb13522011-10-25 19:26:31 -0700611
Andy Zhou738967b2014-09-08 00:35:02 -0700612 if (likely(vport))
613 ovs_vport_send(vport, skb);
614 else
Jesse Grossccb13522011-10-25 19:26:31 -0700615 kfree_skb(skb);
Jesse Grossccb13522011-10-25 19:26:31 -0700616}
617
618static int output_userspace(struct datapath *dp, struct sk_buff *skb,
Pravin B Shelar2ff3e4e2014-09-15 19:15:28 -0700619 struct sw_flow_key *key, const struct nlattr *attr)
Jesse Grossccb13522011-10-25 19:26:31 -0700620{
Wenyu Zhang8f0aad62014-11-06 06:51:24 -0800621 struct ovs_tunnel_info info;
Jesse Grossccb13522011-10-25 19:26:31 -0700622 struct dp_upcall_info upcall;
623 const struct nlattr *a;
624 int rem;
625
626 upcall.cmd = OVS_PACKET_CMD_ACTION;
Pravin B Shelar2ff3e4e2014-09-15 19:15:28 -0700627 upcall.key = key;
Jesse Grossccb13522011-10-25 19:26:31 -0700628 upcall.userdata = NULL;
Eric W. Biederman15e47302012-09-07 20:12:54 +0000629 upcall.portid = 0;
Wenyu Zhang8f0aad62014-11-06 06:51:24 -0800630 upcall.egress_tun_info = NULL;
Jesse Grossccb13522011-10-25 19:26:31 -0700631
632 for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
633 a = nla_next(a, &rem)) {
634 switch (nla_type(a)) {
635 case OVS_USERSPACE_ATTR_USERDATA:
636 upcall.userdata = a;
637 break;
638
639 case OVS_USERSPACE_ATTR_PID:
Eric W. Biederman15e47302012-09-07 20:12:54 +0000640 upcall.portid = nla_get_u32(a);
Jesse Grossccb13522011-10-25 19:26:31 -0700641 break;
Wenyu Zhang8f0aad62014-11-06 06:51:24 -0800642
643 case OVS_USERSPACE_ATTR_EGRESS_TUN_PORT: {
644 /* Get out tunnel info. */
645 struct vport *vport;
646
647 vport = ovs_vport_rcu(dp, nla_get_u32(a));
648 if (vport) {
649 int err;
650
651 err = ovs_vport_get_egress_tun_info(vport, skb,
652 &info);
653 if (!err)
654 upcall.egress_tun_info = &info;
655 }
656 break;
Jesse Grossccb13522011-10-25 19:26:31 -0700657 }
Wenyu Zhang8f0aad62014-11-06 06:51:24 -0800658
659 } /* End of switch. */
Jesse Grossccb13522011-10-25 19:26:31 -0700660 }
661
662 return ovs_dp_upcall(dp, skb, &upcall);
663}
664
665static int sample(struct datapath *dp, struct sk_buff *skb,
Pravin B Shelar2ff3e4e2014-09-15 19:15:28 -0700666 struct sw_flow_key *key, const struct nlattr *attr)
Jesse Grossccb13522011-10-25 19:26:31 -0700667{
668 const struct nlattr *acts_list = NULL;
669 const struct nlattr *a;
670 int rem;
671
672 for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
673 a = nla_next(a, &rem)) {
674 switch (nla_type(a)) {
675 case OVS_SAMPLE_ATTR_PROBABILITY:
Aruna-Hewapathirane63862b52014-01-11 07:15:59 -0500676 if (prandom_u32() >= nla_get_u32(a))
Jesse Grossccb13522011-10-25 19:26:31 -0700677 return 0;
678 break;
679
680 case OVS_SAMPLE_ATTR_ACTIONS:
681 acts_list = a;
682 break;
683 }
684 }
685
Simon Horman651887b2014-07-21 15:12:34 -0700686 rem = nla_len(acts_list);
687 a = nla_data(acts_list);
688
Andy Zhou32ae87f2014-09-15 19:33:50 -0700689 /* Actions list is empty, do nothing */
690 if (unlikely(!rem))
691 return 0;
Simon Horman651887b2014-07-21 15:12:34 -0700692
Andy Zhou32ae87f2014-09-15 19:33:50 -0700693 /* The only known usage of sample action is having a single user-space
694 * action. Treat this usage as a special case.
695 * The output_userspace() should clone the skb to be sent to the
696 * user space. This skb will be consumed by its caller.
Simon Horman651887b2014-07-21 15:12:34 -0700697 */
Andy Zhou32ae87f2014-09-15 19:33:50 -0700698 if (likely(nla_type(a) == OVS_ACTION_ATTR_USERSPACE &&
Simon Horman941d8eb2014-10-27 16:12:16 +0900699 nla_is_last(a, rem)))
Andy Zhou32ae87f2014-09-15 19:33:50 -0700700 return output_userspace(dp, skb, key, a);
701
702 skb = skb_clone(skb, GFP_ATOMIC);
703 if (!skb)
704 /* Skip the sample action when out of memory. */
705 return 0;
706
Andy Zhou971427f32014-09-15 19:37:25 -0700707 if (!add_deferred_actions(skb, key, a)) {
708 if (net_ratelimit())
709 pr_warn("%s: deferred actions limit reached, dropping sample action\n",
710 ovs_dp_name(dp));
711
712 kfree_skb(skb);
713 }
714 return 0;
715}
716
717static void execute_hash(struct sk_buff *skb, struct sw_flow_key *key,
718 const struct nlattr *attr)
719{
720 struct ovs_action_hash *hash_act = nla_data(attr);
721 u32 hash = 0;
722
723 /* OVS_HASH_ALG_L4 is the only possible hash algorithm. */
724 hash = skb_get_hash(skb);
725 hash = jhash_1word(hash, hash_act->hash_basis);
726 if (!hash)
727 hash = 0x1;
728
729 key->ovs_flow_hash = hash;
Jesse Grossccb13522011-10-25 19:26:31 -0700730}
731
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800732static int execute_set_action(struct sk_buff *skb, struct sw_flow_key *key,
733 const struct nlattr *nested_attr)
Jesse Grossccb13522011-10-25 19:26:31 -0700734{
735 int err = 0;
736
737 switch (nla_type(nested_attr)) {
738 case OVS_KEY_ATTR_PRIORITY:
739 skb->priority = nla_get_u32(nested_attr);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800740 key->phy.priority = skb->priority;
Jesse Grossccb13522011-10-25 19:26:31 -0700741 break;
742
Ansis Atteka39c7caeb2012-11-26 11:24:11 -0800743 case OVS_KEY_ATTR_SKB_MARK:
744 skb->mark = nla_get_u32(nested_attr);
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800745 key->phy.skb_mark = skb->mark;
Ansis Atteka39c7caeb2012-11-26 11:24:11 -0800746 break;
747
Jesse Grossf0b128c2014-10-03 15:35:31 -0700748 case OVS_KEY_ATTR_TUNNEL_INFO:
749 OVS_CB(skb)->egress_tun_info = nla_data(nested_attr);
Pravin B Shelar7d5437c2013-06-17 17:50:18 -0700750 break;
751
Jesse Grossccb13522011-10-25 19:26:31 -0700752 case OVS_KEY_ATTR_ETHERNET:
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800753 err = set_eth_addr(skb, key, nla_data(nested_attr));
Jesse Grossccb13522011-10-25 19:26:31 -0700754 break;
755
756 case OVS_KEY_ATTR_IPV4:
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800757 err = set_ipv4(skb, key, nla_data(nested_attr));
Jesse Grossccb13522011-10-25 19:26:31 -0700758 break;
759
Ansis Atteka3fdbd1c2012-11-13 15:44:14 -0800760 case OVS_KEY_ATTR_IPV6:
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800761 err = set_ipv6(skb, key, nla_data(nested_attr));
Ansis Atteka3fdbd1c2012-11-13 15:44:14 -0800762 break;
763
Jesse Grossccb13522011-10-25 19:26:31 -0700764 case OVS_KEY_ATTR_TCP:
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800765 err = set_tcp(skb, key, nla_data(nested_attr));
Jesse Grossccb13522011-10-25 19:26:31 -0700766 break;
767
768 case OVS_KEY_ATTR_UDP:
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800769 err = set_udp(skb, key, nla_data(nested_attr));
Jesse Grossccb13522011-10-25 19:26:31 -0700770 break;
Joe Stringera175a722013-08-22 12:30:48 -0700771
772 case OVS_KEY_ATTR_SCTP:
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800773 err = set_sctp(skb, key, nla_data(nested_attr));
Joe Stringera175a722013-08-22 12:30:48 -0700774 break;
Simon Horman25cd9ba2014-10-06 05:05:13 -0700775
776 case OVS_KEY_ATTR_MPLS:
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800777 err = set_mpls(skb, key, nla_data(nested_attr));
Simon Horman25cd9ba2014-10-06 05:05:13 -0700778 break;
Jesse Grossccb13522011-10-25 19:26:31 -0700779 }
780
781 return err;
782}
783
Andy Zhou971427f32014-09-15 19:37:25 -0700784static int execute_recirc(struct datapath *dp, struct sk_buff *skb,
785 struct sw_flow_key *key,
786 const struct nlattr *a, int rem)
787{
788 struct deferred_action *da;
Andy Zhou971427f32014-09-15 19:37:25 -0700789
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800790 if (!is_flow_key_valid(key)) {
791 int err;
792
793 err = ovs_flow_key_update(skb, key);
794 if (err)
795 return err;
796 }
797 BUG_ON(!is_flow_key_valid(key));
Andy Zhou971427f32014-09-15 19:37:25 -0700798
Simon Horman941d8eb2014-10-27 16:12:16 +0900799 if (!nla_is_last(a, rem)) {
Andy Zhou971427f32014-09-15 19:37:25 -0700800 /* Recirc action is the not the last action
801 * of the action list, need to clone the skb.
802 */
803 skb = skb_clone(skb, GFP_ATOMIC);
804
805 /* Skip the recirc action when out of memory, but
806 * continue on with the rest of the action list.
807 */
808 if (!skb)
809 return 0;
810 }
811
812 da = add_deferred_actions(skb, key, NULL);
813 if (da) {
814 da->pkt_key.recirc_id = nla_get_u32(a);
815 } else {
816 kfree_skb(skb);
817
818 if (net_ratelimit())
819 pr_warn("%s: deferred action limit reached, drop recirc action\n",
820 ovs_dp_name(dp));
821 }
822
823 return 0;
824}
825
Jesse Grossccb13522011-10-25 19:26:31 -0700826/* Execute a list of actions against 'skb'. */
827static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
Pravin B Shelar2ff3e4e2014-09-15 19:15:28 -0700828 struct sw_flow_key *key,
Simon Horman651887b2014-07-21 15:12:34 -0700829 const struct nlattr *attr, int len)
Jesse Grossccb13522011-10-25 19:26:31 -0700830{
831 /* Every output action needs a separate clone of 'skb', but the common
832 * case is just a single output action, so that doing a clone and
833 * then freeing the original skbuff is wasteful. So the following code
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800834 * is slightly obscure just to avoid that.
835 */
Jesse Grossccb13522011-10-25 19:26:31 -0700836 int prev_port = -1;
837 const struct nlattr *a;
838 int rem;
839
840 for (a = attr, rem = len; rem > 0;
841 a = nla_next(a, &rem)) {
842 int err = 0;
843
Andy Zhou738967b2014-09-08 00:35:02 -0700844 if (unlikely(prev_port != -1)) {
845 struct sk_buff *out_skb = skb_clone(skb, GFP_ATOMIC);
846
847 if (out_skb)
848 do_output(dp, out_skb, prev_port);
849
Jesse Grossccb13522011-10-25 19:26:31 -0700850 prev_port = -1;
851 }
852
853 switch (nla_type(a)) {
854 case OVS_ACTION_ATTR_OUTPUT:
855 prev_port = nla_get_u32(a);
856 break;
857
858 case OVS_ACTION_ATTR_USERSPACE:
Pravin B Shelar2ff3e4e2014-09-15 19:15:28 -0700859 output_userspace(dp, skb, key, a);
Jesse Grossccb13522011-10-25 19:26:31 -0700860 break;
861
Andy Zhou971427f32014-09-15 19:37:25 -0700862 case OVS_ACTION_ATTR_HASH:
863 execute_hash(skb, key, a);
864 break;
865
Simon Horman25cd9ba2014-10-06 05:05:13 -0700866 case OVS_ACTION_ATTR_PUSH_MPLS:
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800867 err = push_mpls(skb, key, nla_data(a));
Simon Horman25cd9ba2014-10-06 05:05:13 -0700868 break;
869
870 case OVS_ACTION_ATTR_POP_MPLS:
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800871 err = pop_mpls(skb, key, nla_get_be16(a));
Simon Horman25cd9ba2014-10-06 05:05:13 -0700872 break;
873
Jesse Grossccb13522011-10-25 19:26:31 -0700874 case OVS_ACTION_ATTR_PUSH_VLAN:
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800875 err = push_vlan(skb, key, nla_data(a));
Jesse Grossccb13522011-10-25 19:26:31 -0700876 if (unlikely(err)) /* skb already freed. */
877 return err;
878 break;
879
880 case OVS_ACTION_ATTR_POP_VLAN:
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800881 err = pop_vlan(skb, key);
Jesse Grossccb13522011-10-25 19:26:31 -0700882 break;
883
Andy Zhou971427f32014-09-15 19:37:25 -0700884 case OVS_ACTION_ATTR_RECIRC:
885 err = execute_recirc(dp, skb, key, a, rem);
Simon Horman941d8eb2014-10-27 16:12:16 +0900886 if (nla_is_last(a, rem)) {
Andy Zhou971427f32014-09-15 19:37:25 -0700887 /* If this is the last action, the skb has
888 * been consumed or freed.
889 * Return immediately.
890 */
891 return err;
892 }
893 break;
894
Jesse Grossccb13522011-10-25 19:26:31 -0700895 case OVS_ACTION_ATTR_SET:
Pravin B Shelarfff06c32014-11-06 06:55:14 -0800896 err = execute_set_action(skb, key, nla_data(a));
Jesse Grossccb13522011-10-25 19:26:31 -0700897 break;
898
899 case OVS_ACTION_ATTR_SAMPLE:
Pravin B Shelar2ff3e4e2014-09-15 19:15:28 -0700900 err = sample(dp, skb, key, a);
Andy Zhoufe984c02014-05-06 17:23:48 -0700901 if (unlikely(err)) /* skb already freed. */
902 return err;
Jesse Grossccb13522011-10-25 19:26:31 -0700903 break;
904 }
905
906 if (unlikely(err)) {
907 kfree_skb(skb);
908 return err;
909 }
910 }
911
Simon Horman651887b2014-07-21 15:12:34 -0700912 if (prev_port != -1)
Jesse Grossccb13522011-10-25 19:26:31 -0700913 do_output(dp, skb, prev_port);
Simon Horman651887b2014-07-21 15:12:34 -0700914 else
Jesse Grossccb13522011-10-25 19:26:31 -0700915 consume_skb(skb);
916
917 return 0;
918}
919
Andy Zhou971427f32014-09-15 19:37:25 -0700920static void process_deferred_actions(struct datapath *dp)
921{
922 struct action_fifo *fifo = this_cpu_ptr(action_fifos);
923
924 /* Do not touch the FIFO in case there is no deferred actions. */
925 if (action_fifo_is_empty(fifo))
926 return;
927
928 /* Finishing executing all deferred actions. */
929 do {
930 struct deferred_action *da = action_fifo_get(fifo);
931 struct sk_buff *skb = da->skb;
932 struct sw_flow_key *key = &da->pkt_key;
933 const struct nlattr *actions = da->actions;
934
935 if (actions)
936 do_execute_actions(dp, skb, key, actions,
937 nla_len(actions));
938 else
939 ovs_dp_process_packet(skb, key);
940 } while (!action_fifo_is_empty(fifo));
941
942 /* Reset FIFO for the next packet. */
943 action_fifo_init(fifo);
944}
945
Jesse Grossccb13522011-10-25 19:26:31 -0700946/* Execute a list of actions against 'skb'. */
Pravin B Shelar2ff3e4e2014-09-15 19:15:28 -0700947int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
Lorand Jakabd98612b2014-10-06 05:45:32 -0700948 struct sw_flow_actions *acts, struct sw_flow_key *key)
Jesse Grossccb13522011-10-25 19:26:31 -0700949{
Andy Zhou971427f32014-09-15 19:37:25 -0700950 int level = this_cpu_read(exec_actions_level);
Andy Zhou971427f32014-09-15 19:37:25 -0700951 int err;
Jesse Grossccb13522011-10-25 19:26:31 -0700952
Andy Zhou971427f32014-09-15 19:37:25 -0700953 this_cpu_inc(exec_actions_level);
Jesse Grossf0b128c2014-10-03 15:35:31 -0700954 OVS_CB(skb)->egress_tun_info = NULL;
Andy Zhou971427f32014-09-15 19:37:25 -0700955 err = do_execute_actions(dp, skb, key,
956 acts->actions, acts->actions_len);
957
958 if (!level)
959 process_deferred_actions(dp);
960
961 this_cpu_dec(exec_actions_level);
962 return err;
963}
964
965int action_fifos_init(void)
966{
967 action_fifos = alloc_percpu(struct action_fifo);
968 if (!action_fifos)
969 return -ENOMEM;
970
971 return 0;
972}
973
974void action_fifos_exit(void)
975{
976 free_percpu(action_fifos);
Jesse Grossccb13522011-10-25 19:26:31 -0700977}