]> git.proxmox.com Git - mirror_ovs.git/blob - datapath/actions.c
datapath: openvswitch: Optimize sample action for the clone use cases
[mirror_ovs.git] / datapath / actions.c
1 /*
2 * Copyright (c) 2007-2017 Nicira, Inc.
3 *
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>
25 #include <linux/netfilter_ipv6.h>
26 #include <linux/sctp.h>
27 #include <linux/tcp.h>
28 #include <linux/udp.h>
29 #include <linux/in6.h>
30 #include <linux/if_arp.h>
31 #include <linux/if_vlan.h>
32
33 #include <net/dst.h>
34 #include <net/ip.h>
35 #include <net/ipv6.h>
36 #include <net/checksum.h>
37 #include <net/dsfield.h>
38 #include <net/mpls.h>
39 #include <net/sctp/checksum.h>
40
41 #include "datapath.h"
42 #include "conntrack.h"
43 #include "gso.h"
44 #include "vport.h"
45
46 static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
47 struct sw_flow_key *key,
48 const struct nlattr *attr, int len);
49
50 struct deferred_action {
51 struct sk_buff *skb;
52 const struct nlattr *actions;
53 int actions_len;
54
55 /* Store pkt_key clone when creating deferred action. */
56 struct sw_flow_key pkt_key;
57 };
58
59 #define MAX_L2_LEN (VLAN_ETH_HLEN + 3 * MPLS_HLEN)
60 struct ovs_frag_data {
61 unsigned long dst;
62 struct vport *vport;
63 struct ovs_gso_cb cb;
64 __be16 inner_protocol;
65 __u16 vlan_tci;
66 __be16 vlan_proto;
67 unsigned int l2_len;
68 u8 mac_proto;
69 u8 l2_data[MAX_L2_LEN];
70 };
71
72 static DEFINE_PER_CPU(struct ovs_frag_data, ovs_frag_data_storage);
73
74 #define DEFERRED_ACTION_FIFO_SIZE 10
75 #define OVS_RECURSION_LIMIT 4
76 #define OVS_DEFERRED_ACTION_THRESHOLD (OVS_RECURSION_LIMIT - 2)
77 struct action_fifo {
78 int head;
79 int tail;
80 /* Deferred action fifo queue storage. */
81 struct deferred_action fifo[DEFERRED_ACTION_FIFO_SIZE];
82 };
83
84 struct action_flow_keys {
85 struct sw_flow_key key[OVS_DEFERRED_ACTION_THRESHOLD];
86 };
87
88 static struct action_fifo __percpu *action_fifos;
89 static struct action_flow_keys __percpu *flow_keys;
90 static DEFINE_PER_CPU(int, exec_actions_level);
91
92 /* Make a clone of the 'key', using the pre-allocated percpu 'flow_keys'
93 * space. Return NULL if out of key spaces.
94 */
95 static struct sw_flow_key *clone_key(const struct sw_flow_key *key_)
96 {
97 struct action_flow_keys *keys = this_cpu_ptr(flow_keys);
98 int level = this_cpu_read(exec_actions_level);
99 struct sw_flow_key *key = NULL;
100
101 if (level <= OVS_DEFERRED_ACTION_THRESHOLD) {
102 key = &keys->key[level - 1];
103 *key = *key_;
104 }
105
106 return key;
107 }
108
109 static void action_fifo_init(struct action_fifo *fifo)
110 {
111 fifo->head = 0;
112 fifo->tail = 0;
113 }
114
115 static bool action_fifo_is_empty(const struct action_fifo *fifo)
116 {
117 return (fifo->head == fifo->tail);
118 }
119
120 static struct deferred_action *action_fifo_get(struct action_fifo *fifo)
121 {
122 if (action_fifo_is_empty(fifo))
123 return NULL;
124
125 return &fifo->fifo[fifo->tail++];
126 }
127
128 static struct deferred_action *action_fifo_put(struct action_fifo *fifo)
129 {
130 if (fifo->head >= DEFERRED_ACTION_FIFO_SIZE - 1)
131 return NULL;
132
133 return &fifo->fifo[fifo->head++];
134 }
135
136 /* Return queue entry if fifo is not full */
137 static struct deferred_action *add_deferred_actions(struct sk_buff *skb,
138 const struct sw_flow_key *key,
139 const struct nlattr *actions,
140 const int actions_len)
141 {
142 struct action_fifo *fifo;
143 struct deferred_action *da;
144
145 fifo = this_cpu_ptr(action_fifos);
146 da = action_fifo_put(fifo);
147 if (da) {
148 da->skb = skb;
149 da->actions = actions;
150 da->actions_len = actions_len;
151 da->pkt_key = *key;
152 }
153
154 return da;
155 }
156
157 static void invalidate_flow_key(struct sw_flow_key *key)
158 {
159 key->mac_proto |= SW_FLOW_KEY_INVALID;
160 }
161
162 static bool is_flow_key_valid(const struct sw_flow_key *key)
163 {
164 return !(key->mac_proto & SW_FLOW_KEY_INVALID);
165 }
166
167 static void update_ethertype(struct sk_buff *skb, struct ethhdr *hdr,
168 __be16 ethertype)
169 {
170 if (skb->ip_summed == CHECKSUM_COMPLETE) {
171 __be16 diff[] = { ~(hdr->h_proto), ethertype };
172
173 skb->csum = ~csum_partial((char *)diff, sizeof(diff),
174 ~skb->csum);
175 }
176
177 hdr->h_proto = ethertype;
178 }
179
180 static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
181 const struct ovs_action_push_mpls *mpls)
182 {
183 __be32 *new_mpls_lse;
184
185 /* Networking stack do not allow simultaneous Tunnel and MPLS GSO. */
186 if (skb->encapsulation)
187 return -ENOTSUPP;
188
189 if (skb_cow_head(skb, MPLS_HLEN) < 0)
190 return -ENOMEM;
191
192 skb_push(skb, MPLS_HLEN);
193 memmove(skb_mac_header(skb) - MPLS_HLEN, skb_mac_header(skb),
194 skb->mac_len);
195 skb_reset_mac_header(skb);
196
197 new_mpls_lse = (__be32 *)skb_mpls_header(skb);
198 *new_mpls_lse = mpls->mpls_lse;
199
200 skb_postpush_rcsum(skb, new_mpls_lse, MPLS_HLEN);
201
202 if (ovs_key_mac_proto(key) == MAC_PROTO_ETHERNET)
203 update_ethertype(skb, eth_hdr(skb), mpls->mpls_ethertype);
204 if (!ovs_skb_get_inner_protocol(skb))
205 ovs_skb_set_inner_protocol(skb, skb->protocol);
206 skb->protocol = mpls->mpls_ethertype;
207
208 invalidate_flow_key(key);
209 return 0;
210 }
211
212 static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
213 const __be16 ethertype)
214 {
215 int err;
216
217 err = skb_ensure_writable(skb, skb->mac_len + MPLS_HLEN);
218 if (unlikely(err))
219 return err;
220
221 skb_postpull_rcsum(skb, skb_mpls_header(skb), MPLS_HLEN);
222
223 memmove(skb_mac_header(skb) + MPLS_HLEN, skb_mac_header(skb),
224 skb->mac_len);
225
226 __skb_pull(skb, MPLS_HLEN);
227 skb_reset_mac_header(skb);
228
229 if (ovs_key_mac_proto(key) == MAC_PROTO_ETHERNET) {
230 struct ethhdr *hdr;
231
232 /* skb_mpls_header() is used to locate the ethertype
233 * field correctly in the presence of VLAN tags.
234 */
235 hdr = (struct ethhdr *)(skb_mpls_header(skb) - ETH_HLEN);
236 update_ethertype(skb, hdr, ethertype);
237 }
238 if (eth_p_mpls(skb->protocol))
239 skb->protocol = ethertype;
240
241 invalidate_flow_key(key);
242 return 0;
243 }
244
245 static int set_mpls(struct sk_buff *skb, struct sw_flow_key *flow_key,
246 const __be32 *mpls_lse, const __be32 *mask)
247 {
248 __be32 *stack;
249 __be32 lse;
250 int err;
251
252 err = skb_ensure_writable(skb, skb->mac_len + MPLS_HLEN);
253 if (unlikely(err))
254 return err;
255
256 stack = (__be32 *)skb_mpls_header(skb);
257 lse = OVS_MASKED(*stack, *mpls_lse, *mask);
258 if (skb->ip_summed == CHECKSUM_COMPLETE) {
259 __be32 diff[] = { ~(*stack), lse };
260
261 skb->csum = ~csum_partial((char *)diff, sizeof(diff),
262 ~skb->csum);
263 }
264
265 *stack = lse;
266 flow_key->mpls.top_lse = lse;
267 return 0;
268 }
269
270 static int pop_vlan(struct sk_buff *skb, struct sw_flow_key *key)
271 {
272 int err;
273
274 err = skb_vlan_pop(skb);
275 if (skb_vlan_tag_present(skb)) {
276 invalidate_flow_key(key);
277 } else {
278 key->eth.vlan.tci = 0;
279 key->eth.vlan.tpid = 0;
280 }
281 return err;
282 }
283
284 static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key,
285 const struct ovs_action_push_vlan *vlan)
286 {
287 if (skb_vlan_tag_present(skb)) {
288 invalidate_flow_key(key);
289 } else {
290 key->eth.vlan.tci = vlan->vlan_tci;
291 key->eth.vlan.tpid = vlan->vlan_tpid;
292 }
293 return skb_vlan_push(skb, vlan->vlan_tpid,
294 ntohs(vlan->vlan_tci) & ~VLAN_TAG_PRESENT);
295 }
296
297 /* 'src' is already properly masked. */
298 static void ether_addr_copy_masked(u8 *dst_, const u8 *src_, const u8 *mask_)
299 {
300 u16 *dst = (u16 *)dst_;
301 const u16 *src = (const u16 *)src_;
302 const u16 *mask = (const u16 *)mask_;
303
304 OVS_SET_MASKED(dst[0], src[0], mask[0]);
305 OVS_SET_MASKED(dst[1], src[1], mask[1]);
306 OVS_SET_MASKED(dst[2], src[2], mask[2]);
307 }
308
309 static int set_eth_addr(struct sk_buff *skb, struct sw_flow_key *flow_key,
310 const struct ovs_key_ethernet *key,
311 const struct ovs_key_ethernet *mask)
312 {
313 int err;
314
315 err = skb_ensure_writable(skb, ETH_HLEN);
316 if (unlikely(err))
317 return err;
318
319 skb_postpull_rcsum(skb, eth_hdr(skb), ETH_ALEN * 2);
320
321 ether_addr_copy_masked(eth_hdr(skb)->h_source, key->eth_src,
322 mask->eth_src);
323 ether_addr_copy_masked(eth_hdr(skb)->h_dest, key->eth_dst,
324 mask->eth_dst);
325
326 skb_postpush_rcsum(skb, eth_hdr(skb), ETH_ALEN * 2);
327
328 ether_addr_copy(flow_key->eth.src, eth_hdr(skb)->h_source);
329 ether_addr_copy(flow_key->eth.dst, eth_hdr(skb)->h_dest);
330 return 0;
331 }
332
333 /* pop_eth does not support VLAN packets as this action is never called
334 * for them.
335 */
336 static int pop_eth(struct sk_buff *skb, struct sw_flow_key *key)
337 {
338 skb_pull_rcsum(skb, ETH_HLEN);
339 skb_reset_mac_header(skb);
340 skb_reset_mac_len(skb);
341
342 /* safe right before invalidate_flow_key */
343 key->mac_proto = MAC_PROTO_NONE;
344 invalidate_flow_key(key);
345 return 0;
346 }
347
348 static int push_eth(struct sk_buff *skb, struct sw_flow_key *key,
349 const struct ovs_action_push_eth *ethh)
350 {
351 struct ethhdr *hdr;
352
353 /* Add the new Ethernet header */
354 if (skb_cow_head(skb, ETH_HLEN) < 0)
355 return -ENOMEM;
356
357 skb_push(skb, ETH_HLEN);
358 skb_reset_mac_header(skb);
359 skb_reset_mac_len(skb);
360
361 hdr = eth_hdr(skb);
362 ether_addr_copy(hdr->h_source, ethh->addresses.eth_src);
363 ether_addr_copy(hdr->h_dest, ethh->addresses.eth_dst);
364 hdr->h_proto = skb->protocol;
365
366 skb_postpush_rcsum(skb, hdr, ETH_HLEN);
367
368 /* safe right before invalidate_flow_key */
369 key->mac_proto = MAC_PROTO_ETHERNET;
370 invalidate_flow_key(key);
371 return 0;
372 }
373
374 static void update_ip_l4_checksum(struct sk_buff *skb, struct iphdr *nh,
375 __be32 addr, __be32 new_addr)
376 {
377 int transport_len = skb->len - skb_transport_offset(skb);
378
379 if (nh->frag_off & htons(IP_OFFSET))
380 return;
381
382 if (nh->protocol == IPPROTO_TCP) {
383 if (likely(transport_len >= sizeof(struct tcphdr)))
384 inet_proto_csum_replace4(&tcp_hdr(skb)->check, skb,
385 addr, new_addr, true);
386 } else if (nh->protocol == IPPROTO_UDP) {
387 if (likely(transport_len >= sizeof(struct udphdr))) {
388 struct udphdr *uh = udp_hdr(skb);
389
390 if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
391 inet_proto_csum_replace4(&uh->check, skb,
392 addr, new_addr, true);
393 if (!uh->check)
394 uh->check = CSUM_MANGLED_0;
395 }
396 }
397 }
398
399 }
400
401 static void set_ip_addr(struct sk_buff *skb, struct iphdr *nh,
402 __be32 *addr, __be32 new_addr)
403 {
404 update_ip_l4_checksum(skb, nh, *addr, new_addr);
405 csum_replace4(&nh->check, *addr, new_addr);
406 skb_clear_hash(skb);
407 *addr = new_addr;
408 }
409
410 static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
411 __be32 addr[4], const __be32 new_addr[4])
412 {
413 int transport_len = skb->len - skb_transport_offset(skb);
414
415 if (l4_proto == NEXTHDR_TCP) {
416 if (likely(transport_len >= sizeof(struct tcphdr)))
417 inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb,
418 addr, new_addr, true);
419 } else if (l4_proto == NEXTHDR_UDP) {
420 if (likely(transport_len >= sizeof(struct udphdr))) {
421 struct udphdr *uh = udp_hdr(skb);
422
423 if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
424 inet_proto_csum_replace16(&uh->check, skb,
425 addr, new_addr, true);
426 if (!uh->check)
427 uh->check = CSUM_MANGLED_0;
428 }
429 }
430 } else if (l4_proto == NEXTHDR_ICMP) {
431 if (likely(transport_len >= sizeof(struct icmp6hdr)))
432 inet_proto_csum_replace16(&icmp6_hdr(skb)->icmp6_cksum,
433 skb, addr, new_addr, true);
434 }
435 }
436
437 static void mask_ipv6_addr(const __be32 old[4], const __be32 addr[4],
438 const __be32 mask[4], __be32 masked[4])
439 {
440 masked[0] = OVS_MASKED(old[0], addr[0], mask[0]);
441 masked[1] = OVS_MASKED(old[1], addr[1], mask[1]);
442 masked[2] = OVS_MASKED(old[2], addr[2], mask[2]);
443 masked[3] = OVS_MASKED(old[3], addr[3], mask[3]);
444 }
445
446 static void set_ipv6_addr(struct sk_buff *skb, u8 l4_proto,
447 __be32 addr[4], const __be32 new_addr[4],
448 bool recalculate_csum)
449 {
450 if (likely(recalculate_csum))
451 update_ipv6_checksum(skb, l4_proto, addr, new_addr);
452
453 skb_clear_hash(skb);
454 memcpy(addr, new_addr, sizeof(__be32[4]));
455 }
456
457 static void set_ipv6_fl(struct ipv6hdr *nh, u32 fl, u32 mask)
458 {
459 /* Bits 21-24 are always unmasked, so this retains their values. */
460 OVS_SET_MASKED(nh->flow_lbl[0], (u8)(fl >> 16), (u8)(mask >> 16));
461 OVS_SET_MASKED(nh->flow_lbl[1], (u8)(fl >> 8), (u8)(mask >> 8));
462 OVS_SET_MASKED(nh->flow_lbl[2], (u8)fl, (u8)mask);
463 }
464
465 static void set_ip_ttl(struct sk_buff *skb, struct iphdr *nh, u8 new_ttl,
466 u8 mask)
467 {
468 new_ttl = OVS_MASKED(nh->ttl, new_ttl, mask);
469
470 csum_replace2(&nh->check, htons(nh->ttl << 8), htons(new_ttl << 8));
471 nh->ttl = new_ttl;
472 }
473
474 static int set_ipv4(struct sk_buff *skb, struct sw_flow_key *flow_key,
475 const struct ovs_key_ipv4 *key,
476 const struct ovs_key_ipv4 *mask)
477 {
478 struct iphdr *nh;
479 __be32 new_addr;
480 int err;
481
482 err = skb_ensure_writable(skb, skb_network_offset(skb) +
483 sizeof(struct iphdr));
484 if (unlikely(err))
485 return err;
486
487 nh = ip_hdr(skb);
488
489 /* Setting an IP addresses is typically only a side effect of
490 * matching on them in the current userspace implementation, so it
491 * makes sense to check if the value actually changed.
492 */
493 if (mask->ipv4_src) {
494 new_addr = OVS_MASKED(nh->saddr, key->ipv4_src, mask->ipv4_src);
495
496 if (unlikely(new_addr != nh->saddr)) {
497 set_ip_addr(skb, nh, &nh->saddr, new_addr);
498 flow_key->ipv4.addr.src = new_addr;
499 }
500 }
501 if (mask->ipv4_dst) {
502 new_addr = OVS_MASKED(nh->daddr, key->ipv4_dst, mask->ipv4_dst);
503
504 if (unlikely(new_addr != nh->daddr)) {
505 set_ip_addr(skb, nh, &nh->daddr, new_addr);
506 flow_key->ipv4.addr.dst = new_addr;
507 }
508 }
509 if (mask->ipv4_tos) {
510 ipv4_change_dsfield(nh, ~mask->ipv4_tos, key->ipv4_tos);
511 flow_key->ip.tos = nh->tos;
512 }
513 if (mask->ipv4_ttl) {
514 set_ip_ttl(skb, nh, key->ipv4_ttl, mask->ipv4_ttl);
515 flow_key->ip.ttl = nh->ttl;
516 }
517
518 return 0;
519 }
520
521 static bool is_ipv6_mask_nonzero(const __be32 addr[4])
522 {
523 return !!(addr[0] | addr[1] | addr[2] | addr[3]);
524 }
525
526 static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *flow_key,
527 const struct ovs_key_ipv6 *key,
528 const struct ovs_key_ipv6 *mask)
529 {
530 struct ipv6hdr *nh;
531 int err;
532
533 err = skb_ensure_writable(skb, skb_network_offset(skb) +
534 sizeof(struct ipv6hdr));
535 if (unlikely(err))
536 return err;
537
538 nh = ipv6_hdr(skb);
539
540 /* Setting an IP addresses is typically only a side effect of
541 * matching on them in the current userspace implementation, so it
542 * makes sense to check if the value actually changed.
543 */
544 if (is_ipv6_mask_nonzero(mask->ipv6_src)) {
545 __be32 *saddr = (__be32 *)&nh->saddr;
546 __be32 masked[4];
547
548 mask_ipv6_addr(saddr, key->ipv6_src, mask->ipv6_src, masked);
549
550 if (unlikely(memcmp(saddr, masked, sizeof(masked)))) {
551 set_ipv6_addr(skb, flow_key->ip.proto, saddr, masked,
552 true);
553 memcpy(&flow_key->ipv6.addr.src, masked,
554 sizeof(flow_key->ipv6.addr.src));
555 }
556 }
557 if (is_ipv6_mask_nonzero(mask->ipv6_dst)) {
558 unsigned int offset = 0;
559 int flags = IP6_FH_F_SKIP_RH;
560 bool recalc_csum = true;
561 __be32 *daddr = (__be32 *)&nh->daddr;
562 __be32 masked[4];
563
564 mask_ipv6_addr(daddr, key->ipv6_dst, mask->ipv6_dst, masked);
565
566 if (unlikely(memcmp(daddr, masked, sizeof(masked)))) {
567 if (ipv6_ext_hdr(nh->nexthdr))
568 recalc_csum = (ipv6_find_hdr(skb, &offset,
569 NEXTHDR_ROUTING,
570 NULL, &flags)
571 != NEXTHDR_ROUTING);
572
573 set_ipv6_addr(skb, flow_key->ip.proto, daddr, masked,
574 recalc_csum);
575 memcpy(&flow_key->ipv6.addr.dst, masked,
576 sizeof(flow_key->ipv6.addr.dst));
577 }
578 }
579 if (mask->ipv6_tclass) {
580 ipv6_change_dsfield(nh, ~mask->ipv6_tclass, key->ipv6_tclass);
581 flow_key->ip.tos = ipv6_get_dsfield(nh);
582 }
583 if (mask->ipv6_label) {
584 set_ipv6_fl(nh, ntohl(key->ipv6_label),
585 ntohl(mask->ipv6_label));
586 flow_key->ipv6.label =
587 *(__be32 *)nh & htonl(IPV6_FLOWINFO_FLOWLABEL);
588 }
589 if (mask->ipv6_hlimit) {
590 OVS_SET_MASKED(nh->hop_limit, key->ipv6_hlimit,
591 mask->ipv6_hlimit);
592 flow_key->ip.ttl = nh->hop_limit;
593 }
594 return 0;
595 }
596
597 /* Must follow skb_ensure_writable() since that can move the skb data. */
598 static void set_tp_port(struct sk_buff *skb, __be16 *port,
599 __be16 new_port, __sum16 *check)
600 {
601 inet_proto_csum_replace2(check, skb, *port, new_port, false);
602 *port = new_port;
603 }
604
605 static int set_udp(struct sk_buff *skb, struct sw_flow_key *flow_key,
606 const struct ovs_key_udp *key,
607 const struct ovs_key_udp *mask)
608 {
609 struct udphdr *uh;
610 __be16 src, dst;
611 int err;
612
613 err = skb_ensure_writable(skb, skb_transport_offset(skb) +
614 sizeof(struct udphdr));
615 if (unlikely(err))
616 return err;
617
618 uh = udp_hdr(skb);
619 /* Either of the masks is non-zero, so do not bother checking them. */
620 src = OVS_MASKED(uh->source, key->udp_src, mask->udp_src);
621 dst = OVS_MASKED(uh->dest, key->udp_dst, mask->udp_dst);
622
623 if (uh->check && skb->ip_summed != CHECKSUM_PARTIAL) {
624 if (likely(src != uh->source)) {
625 set_tp_port(skb, &uh->source, src, &uh->check);
626 flow_key->tp.src = src;
627 }
628 if (likely(dst != uh->dest)) {
629 set_tp_port(skb, &uh->dest, dst, &uh->check);
630 flow_key->tp.dst = dst;
631 }
632
633 if (unlikely(!uh->check))
634 uh->check = CSUM_MANGLED_0;
635 } else {
636 uh->source = src;
637 uh->dest = dst;
638 flow_key->tp.src = src;
639 flow_key->tp.dst = dst;
640 }
641
642 skb_clear_hash(skb);
643
644 return 0;
645 }
646
647 static int set_tcp(struct sk_buff *skb, struct sw_flow_key *flow_key,
648 const struct ovs_key_tcp *key,
649 const struct ovs_key_tcp *mask)
650 {
651 struct tcphdr *th;
652 __be16 src, dst;
653 int err;
654
655 err = skb_ensure_writable(skb, skb_transport_offset(skb) +
656 sizeof(struct tcphdr));
657 if (unlikely(err))
658 return err;
659
660 th = tcp_hdr(skb);
661 src = OVS_MASKED(th->source, key->tcp_src, mask->tcp_src);
662 if (likely(src != th->source)) {
663 set_tp_port(skb, &th->source, src, &th->check);
664 flow_key->tp.src = src;
665 }
666 dst = OVS_MASKED(th->dest, key->tcp_dst, mask->tcp_dst);
667 if (likely(dst != th->dest)) {
668 set_tp_port(skb, &th->dest, dst, &th->check);
669 flow_key->tp.dst = dst;
670 }
671 skb_clear_hash(skb);
672
673 return 0;
674 }
675
676 static int set_sctp(struct sk_buff *skb, struct sw_flow_key *flow_key,
677 const struct ovs_key_sctp *key,
678 const struct ovs_key_sctp *mask)
679 {
680 unsigned int sctphoff = skb_transport_offset(skb);
681 struct sctphdr *sh;
682 __le32 old_correct_csum, new_csum, old_csum;
683 int err;
684
685 err = skb_ensure_writable(skb, sctphoff + sizeof(struct sctphdr));
686 if (unlikely(err))
687 return err;
688
689 sh = sctp_hdr(skb);
690 old_csum = sh->checksum;
691 old_correct_csum = sctp_compute_cksum(skb, sctphoff);
692
693 sh->source = OVS_MASKED(sh->source, key->sctp_src, mask->sctp_src);
694 sh->dest = OVS_MASKED(sh->dest, key->sctp_dst, mask->sctp_dst);
695
696 new_csum = sctp_compute_cksum(skb, sctphoff);
697
698 /* Carry any checksum errors through. */
699 sh->checksum = old_csum ^ old_correct_csum ^ new_csum;
700
701 skb_clear_hash(skb);
702 flow_key->tp.src = sh->source;
703 flow_key->tp.dst = sh->dest;
704
705 return 0;
706 }
707
708 static int ovs_vport_output(OVS_VPORT_OUTPUT_PARAMS)
709 {
710 struct ovs_frag_data *data = this_cpu_ptr(&ovs_frag_data_storage);
711 struct vport *vport = data->vport;
712
713 if (skb_cow_head(skb, data->l2_len) < 0) {
714 kfree_skb(skb);
715 return -ENOMEM;
716 }
717
718 __skb_dst_copy(skb, data->dst);
719 *OVS_GSO_CB(skb) = data->cb;
720 ovs_skb_set_inner_protocol(skb, data->inner_protocol);
721 skb->vlan_tci = data->vlan_tci;
722 skb->vlan_proto = data->vlan_proto;
723
724 /* Reconstruct the MAC header. */
725 skb_push(skb, data->l2_len);
726 memcpy(skb->data, &data->l2_data, data->l2_len);
727 skb_postpush_rcsum(skb, skb->data, data->l2_len);
728 skb_reset_mac_header(skb);
729
730 ovs_vport_send(vport, skb, data->mac_proto);
731 return 0;
732 }
733
734 static unsigned int
735 ovs_dst_get_mtu(const struct dst_entry *dst)
736 {
737 return dst->dev->mtu;
738 }
739
740 static struct dst_ops ovs_dst_ops = {
741 .family = AF_UNSPEC,
742 .mtu = ovs_dst_get_mtu,
743 };
744
745 /* prepare_frag() is called once per (larger-than-MTU) frame; its inverse is
746 * ovs_vport_output(), which is called once per fragmented packet.
747 */
748 static void prepare_frag(struct vport *vport, struct sk_buff *skb,
749 u8 mac_proto)
750 {
751 unsigned int hlen = skb_network_offset(skb);
752 struct ovs_frag_data *data;
753
754 data = this_cpu_ptr(&ovs_frag_data_storage);
755 data->dst = (unsigned long) skb_dst(skb);
756 data->vport = vport;
757 data->cb = *OVS_GSO_CB(skb);
758 data->inner_protocol = ovs_skb_get_inner_protocol(skb);
759 data->vlan_tci = skb->vlan_tci;
760 data->vlan_proto = skb->vlan_proto;
761 data->mac_proto = mac_proto;
762 data->l2_len = hlen;
763 memcpy(&data->l2_data, skb->data, hlen);
764
765 memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
766 skb_pull(skb, hlen);
767 }
768
769 static void ovs_fragment(struct net *net, struct vport *vport,
770 struct sk_buff *skb, u16 mru,
771 struct sw_flow_key *key)
772 {
773 if (skb_network_offset(skb) > MAX_L2_LEN) {
774 OVS_NLERR(1, "L2 header too long to fragment");
775 goto err;
776 }
777
778 if (key->eth.type == htons(ETH_P_IP)) {
779 struct dst_entry ovs_dst;
780 unsigned long orig_dst;
781
782 prepare_frag(vport, skb, ovs_key_mac_proto(key));
783 dst_init(&ovs_dst, &ovs_dst_ops, NULL, 1,
784 DST_OBSOLETE_NONE, DST_NOCOUNT);
785 ovs_dst.dev = vport->dev;
786
787 orig_dst = (unsigned long) skb_dst(skb);
788 skb_dst_set_noref(skb, &ovs_dst);
789 IPCB(skb)->frag_max_size = mru;
790
791 ip_do_fragment(net, skb->sk, skb, ovs_vport_output);
792 refdst_drop(orig_dst);
793 } else if (key->eth.type == htons(ETH_P_IPV6)) {
794 const struct nf_ipv6_ops *v6ops = nf_get_ipv6_ops();
795 unsigned long orig_dst;
796 struct rt6_info ovs_rt;
797
798 if (!v6ops)
799 goto err;
800
801 prepare_frag(vport, skb,
802 ovs_key_mac_proto(key));
803 memset(&ovs_rt, 0, sizeof(ovs_rt));
804 dst_init(&ovs_rt.dst, &ovs_dst_ops, NULL, 1,
805 DST_OBSOLETE_NONE, DST_NOCOUNT);
806 ovs_rt.dst.dev = vport->dev;
807
808 orig_dst = (unsigned long) skb_dst(skb);
809 skb_dst_set_noref(skb, &ovs_rt.dst);
810 IP6CB(skb)->frag_max_size = mru;
811 #ifdef HAVE_IP_LOCAL_OUT_TAKES_NET
812 v6ops->fragment(net, skb->sk, skb, ovs_vport_output);
813 #else
814 v6ops->fragment(skb->sk, skb, ovs_vport_output);
815 #endif
816 refdst_drop(orig_dst);
817 } else {
818 WARN_ONCE(1, "Failed fragment ->%s: eth=%04x, MRU=%d, MTU=%d.",
819 ovs_vport_name(vport), ntohs(key->eth.type), mru,
820 vport->dev->mtu);
821 goto err;
822 }
823
824 return;
825 err:
826 kfree_skb(skb);
827 }
828
829 static void do_output(struct datapath *dp, struct sk_buff *skb, int out_port,
830 struct sw_flow_key *key)
831 {
832 struct vport *vport = ovs_vport_rcu(dp, out_port);
833
834 if (likely(vport)) {
835 u16 mru = OVS_CB(skb)->mru;
836 u32 cutlen = OVS_CB(skb)->cutlen;
837
838 if (unlikely(cutlen > 0)) {
839 if (skb->len - cutlen > ovs_mac_header_len(key))
840 pskb_trim(skb, skb->len - cutlen);
841 else
842 pskb_trim(skb, ovs_mac_header_len(key));
843 }
844
845 if (likely(!mru ||
846 (skb->len <= mru + vport->dev->hard_header_len))) {
847 ovs_vport_send(vport, skb, ovs_key_mac_proto(key));
848 } else if (mru <= vport->dev->mtu) {
849 struct net *net = ovs_dp_get_net(dp);
850
851 ovs_fragment(net, vport, skb, mru, key);
852 } else {
853 OVS_NLERR(true, "Cannot fragment IP frames");
854 kfree_skb(skb);
855 }
856 } else {
857 kfree_skb(skb);
858 }
859 }
860
861 static int output_userspace(struct datapath *dp, struct sk_buff *skb,
862 struct sw_flow_key *key, const struct nlattr *attr,
863 const struct nlattr *actions, int actions_len,
864 uint32_t cutlen)
865 {
866 struct dp_upcall_info upcall;
867 const struct nlattr *a;
868 int rem, err;
869
870 memset(&upcall, 0, sizeof(upcall));
871 upcall.cmd = OVS_PACKET_CMD_ACTION;
872 upcall.mru = OVS_CB(skb)->mru;
873
874 SKB_INIT_FILL_METADATA_DST(skb);
875 for (a = nla_data(attr), rem = nla_len(attr); rem > 0;
876 a = nla_next(a, &rem)) {
877 switch (nla_type(a)) {
878 case OVS_USERSPACE_ATTR_USERDATA:
879 upcall.userdata = a;
880 break;
881
882 case OVS_USERSPACE_ATTR_PID:
883 upcall.portid = nla_get_u32(a);
884 break;
885
886 case OVS_USERSPACE_ATTR_EGRESS_TUN_PORT: {
887 /* Get out tunnel info. */
888 struct vport *vport;
889
890 vport = ovs_vport_rcu(dp, nla_get_u32(a));
891 if (vport) {
892 err = dev_fill_metadata_dst(vport->dev, skb);
893 if (!err)
894 upcall.egress_tun_info = skb_tunnel_info(skb);
895 }
896
897 break;
898 }
899
900 case OVS_USERSPACE_ATTR_ACTIONS: {
901 /* Include actions. */
902 upcall.actions = actions;
903 upcall.actions_len = actions_len;
904 break;
905 }
906
907 } /* End of switch. */
908 }
909
910 err = ovs_dp_upcall(dp, skb, key, &upcall, cutlen);
911 SKB_RESTORE_FILL_METADATA_DST(skb);
912 return err;
913 }
914
915 /* When 'last' is true, sample() should always consume the 'skb'.
916 * Otherwise, sample() should keep 'skb' intact regardless what
917 * actions are executed within sample().
918 */
919 static int sample(struct datapath *dp, struct sk_buff *skb,
920 struct sw_flow_key *key, const struct nlattr *attr,
921 bool last)
922 {
923 struct nlattr *actions;
924 struct nlattr *sample_arg;
925 struct sw_flow_key *orig_key = key;
926 int rem = nla_len(attr);
927 int err = 0;
928 const struct sample_arg *arg;
929
930 /* The first action is always 'OVS_SAMPLE_ATTR_ARG'. */
931 sample_arg = nla_data(attr);
932 arg = nla_data(sample_arg);
933 actions = nla_next(sample_arg, &rem);
934
935 if ((arg->probability != U32_MAX) &&
936 (!arg->probability || prandom_u32() > arg->probability)) {
937 if (last)
938 consume_skb(skb);
939 return 0;
940 }
941
942 /* Unless the last action, sample works on the clone of SKB. */
943 skb = last ? skb : skb_clone(skb, GFP_ATOMIC);
944 if (!skb) {
945 /* Out of memory, skip this sample action.
946 */
947 return 0;
948 }
949
950 /* In case the sample actions won't change 'key',
951 * it can be used directly to execute sample actions.
952 * Otherwise, allocate a new key from the
953 * next recursion level of 'flow_keys'. If
954 * successful, execute the sample actions without
955 * deferring.
956 *
957 * Defer the sample actions if the recursion
958 * limit has been reached.
959 */
960 if (!arg->exec) {
961 __this_cpu_inc(exec_actions_level);
962 key = clone_key(key);
963 }
964
965 if (key) {
966 err = do_execute_actions(dp, skb, key, actions, rem);
967 } else if (!add_deferred_actions(skb, orig_key, actions, rem)) {
968
969 if (net_ratelimit())
970 pr_warn("%s: deferred action limit reached, drop sample action\n",
971 ovs_dp_name(dp));
972 kfree_skb(skb);
973 }
974
975 if (!arg->exec)
976 __this_cpu_dec(exec_actions_level);
977
978 return err;
979 }
980
981 static void execute_hash(struct sk_buff *skb, struct sw_flow_key *key,
982 const struct nlattr *attr)
983 {
984 struct ovs_action_hash *hash_act = nla_data(attr);
985 u32 hash = 0;
986
987 /* OVS_HASH_ALG_L4 is the only possible hash algorithm. */
988 hash = skb_get_hash(skb);
989 hash = jhash_1word(hash, hash_act->hash_basis);
990 if (!hash)
991 hash = 0x1;
992
993 key->ovs_flow_hash = hash;
994 }
995
996 static int execute_set_action(struct sk_buff *skb,
997 struct sw_flow_key *flow_key,
998 const struct nlattr *a)
999 {
1000 /* Only tunnel set execution is supported without a mask. */
1001 if (nla_type(a) == OVS_KEY_ATTR_TUNNEL_INFO) {
1002 struct ovs_tunnel_info *tun = nla_data(a);
1003
1004 ovs_skb_dst_drop(skb);
1005 ovs_dst_hold((struct dst_entry *)tun->tun_dst);
1006 ovs_skb_dst_set(skb, (struct dst_entry *)tun->tun_dst);
1007 return 0;
1008 }
1009
1010 return -EINVAL;
1011 }
1012
1013 /* Mask is at the midpoint of the data. */
1014 #define get_mask(a, type) ((const type)nla_data(a) + 1)
1015
1016 static int execute_masked_set_action(struct sk_buff *skb,
1017 struct sw_flow_key *flow_key,
1018 const struct nlattr *a)
1019 {
1020 int err = 0;
1021
1022 switch (nla_type(a)) {
1023 case OVS_KEY_ATTR_PRIORITY:
1024 OVS_SET_MASKED(skb->priority, nla_get_u32(a),
1025 *get_mask(a, u32 *));
1026 flow_key->phy.priority = skb->priority;
1027 break;
1028
1029 case OVS_KEY_ATTR_SKB_MARK:
1030 OVS_SET_MASKED(skb->mark, nla_get_u32(a), *get_mask(a, u32 *));
1031 flow_key->phy.skb_mark = skb->mark;
1032 break;
1033
1034 case OVS_KEY_ATTR_TUNNEL_INFO:
1035 /* Masked data not supported for tunnel. */
1036 err = -EINVAL;
1037 break;
1038
1039 case OVS_KEY_ATTR_ETHERNET:
1040 err = set_eth_addr(skb, flow_key, nla_data(a),
1041 get_mask(a, struct ovs_key_ethernet *));
1042 break;
1043
1044 case OVS_KEY_ATTR_IPV4:
1045 err = set_ipv4(skb, flow_key, nla_data(a),
1046 get_mask(a, struct ovs_key_ipv4 *));
1047 break;
1048
1049 case OVS_KEY_ATTR_IPV6:
1050 err = set_ipv6(skb, flow_key, nla_data(a),
1051 get_mask(a, struct ovs_key_ipv6 *));
1052 break;
1053
1054 case OVS_KEY_ATTR_TCP:
1055 err = set_tcp(skb, flow_key, nla_data(a),
1056 get_mask(a, struct ovs_key_tcp *));
1057 break;
1058
1059 case OVS_KEY_ATTR_UDP:
1060 err = set_udp(skb, flow_key, nla_data(a),
1061 get_mask(a, struct ovs_key_udp *));
1062 break;
1063
1064 case OVS_KEY_ATTR_SCTP:
1065 err = set_sctp(skb, flow_key, nla_data(a),
1066 get_mask(a, struct ovs_key_sctp *));
1067 break;
1068
1069 case OVS_KEY_ATTR_MPLS:
1070 err = set_mpls(skb, flow_key, nla_data(a), get_mask(a,
1071 __be32 *));
1072 break;
1073
1074 case OVS_KEY_ATTR_CT_STATE:
1075 case OVS_KEY_ATTR_CT_ZONE:
1076 case OVS_KEY_ATTR_CT_MARK:
1077 case OVS_KEY_ATTR_CT_LABELS:
1078 case OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4:
1079 case OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6:
1080 err = -EINVAL;
1081 break;
1082 }
1083
1084 return err;
1085 }
1086
1087 static int execute_recirc(struct datapath *dp, struct sk_buff *skb,
1088 struct sw_flow_key *key,
1089 const struct nlattr *a, int rem)
1090 {
1091 struct sw_flow_key *recirc_key;
1092 struct deferred_action *da;
1093
1094 if (!is_flow_key_valid(key)) {
1095 int err;
1096
1097 err = ovs_flow_key_update(skb, key);
1098 if (err)
1099 return err;
1100 }
1101 BUG_ON(!is_flow_key_valid(key));
1102
1103 if (!nla_is_last(a, rem)) {
1104 /* Recirc action is the not the last action
1105 * of the action list, need to clone the skb.
1106 */
1107 skb = skb_clone(skb, GFP_ATOMIC);
1108
1109 /* Skip the recirc action when out of memory, but
1110 * continue on with the rest of the action list.
1111 */
1112 if (!skb)
1113 return 0;
1114 }
1115
1116 /* If within the limit of 'OVS_DEFERRED_ACTION_THRESHOLD',
1117 * recirc immediately, otherwise, defer it for later execution.
1118 */
1119 recirc_key = clone_key(key);
1120 if (recirc_key) {
1121 recirc_key->recirc_id = nla_get_u32(a);
1122 ovs_dp_process_packet(skb, recirc_key);
1123 } else {
1124 da = add_deferred_actions(skb, key, NULL, 0);
1125 if (da) {
1126 recirc_key = &da->pkt_key;
1127 recirc_key->recirc_id = nla_get_u32(a);
1128 } else {
1129 /* Log an error in case action fifo is full. */
1130 kfree_skb(skb);
1131 if (net_ratelimit())
1132 pr_warn("%s: deferred action limit reached, drop recirc action\n",
1133 ovs_dp_name(dp));
1134 }
1135 }
1136 return 0;
1137 }
1138
1139 /* Execute a list of actions against 'skb'. */
1140 static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
1141 struct sw_flow_key *key,
1142 const struct nlattr *attr, int len)
1143 {
1144 const struct nlattr *a;
1145 int rem;
1146
1147 for (a = attr, rem = len; rem > 0;
1148 a = nla_next(a, &rem)) {
1149 int err = 0;
1150
1151 switch (nla_type(a)) {
1152 case OVS_ACTION_ATTR_OUTPUT: {
1153 int port = nla_get_u32(a);
1154 struct sk_buff *clone;
1155
1156 /* Every output action needs a separate clone
1157 * of 'skb', In case the output action is the
1158 * last action, cloning can be avoided.
1159 */
1160 if (nla_is_last(a, rem)) {
1161 do_output(dp, skb, port, key);
1162 /* 'skb' has been used for output.
1163 */
1164 return 0;
1165 }
1166
1167 clone = skb_clone(skb, GFP_ATOMIC);
1168 if (clone)
1169 do_output(dp, clone, port, key);
1170 OVS_CB(skb)->cutlen = 0;
1171 break;
1172 }
1173
1174 case OVS_ACTION_ATTR_TRUNC: {
1175 struct ovs_action_trunc *trunc = nla_data(a);
1176
1177 if (skb->len > trunc->max_len)
1178 OVS_CB(skb)->cutlen = skb->len - trunc->max_len;
1179 break;
1180 }
1181
1182 case OVS_ACTION_ATTR_USERSPACE:
1183 output_userspace(dp, skb, key, a, attr,
1184 len, OVS_CB(skb)->cutlen);
1185 OVS_CB(skb)->cutlen = 0;
1186 break;
1187
1188 case OVS_ACTION_ATTR_HASH:
1189 execute_hash(skb, key, a);
1190 break;
1191
1192 case OVS_ACTION_ATTR_PUSH_MPLS:
1193 err = push_mpls(skb, key, nla_data(a));
1194 break;
1195
1196 case OVS_ACTION_ATTR_POP_MPLS:
1197 err = pop_mpls(skb, key, nla_get_be16(a));
1198 break;
1199
1200 case OVS_ACTION_ATTR_PUSH_VLAN:
1201 err = push_vlan(skb, key, nla_data(a));
1202 break;
1203
1204 case OVS_ACTION_ATTR_POP_VLAN:
1205 err = pop_vlan(skb, key);
1206 break;
1207
1208 case OVS_ACTION_ATTR_RECIRC:
1209 err = execute_recirc(dp, skb, key, a, rem);
1210 if (nla_is_last(a, rem)) {
1211 /* If this is the last action, the skb has
1212 * been consumed or freed.
1213 * Return immediately.
1214 */
1215 return err;
1216 }
1217 break;
1218
1219 case OVS_ACTION_ATTR_SET:
1220 err = execute_set_action(skb, key, nla_data(a));
1221 break;
1222
1223 case OVS_ACTION_ATTR_SET_MASKED:
1224 case OVS_ACTION_ATTR_SET_TO_MASKED:
1225 err = execute_masked_set_action(skb, key, nla_data(a));
1226 break;
1227
1228 case OVS_ACTION_ATTR_SAMPLE: {
1229 bool last = nla_is_last(a, rem);
1230
1231 err = sample(dp, skb, key, a, last);
1232 if (last)
1233 return err;
1234
1235 break;
1236 }
1237
1238 case OVS_ACTION_ATTR_CT:
1239 if (!is_flow_key_valid(key)) {
1240 err = ovs_flow_key_update(skb, key);
1241 if (err)
1242 return err;
1243 }
1244
1245 err = ovs_ct_execute(ovs_dp_get_net(dp), skb, key,
1246 nla_data(a));
1247
1248 /* Hide stolen IP fragments from user space. */
1249 if (err)
1250 return err == -EINPROGRESS ? 0 : err;
1251 break;
1252
1253 case OVS_ACTION_ATTR_PUSH_ETH:
1254 err = push_eth(skb, key, nla_data(a));
1255 break;
1256
1257 case OVS_ACTION_ATTR_POP_ETH:
1258 err = pop_eth(skb, key);
1259 break;
1260 }
1261
1262 if (unlikely(err)) {
1263 kfree_skb(skb);
1264 return err;
1265 }
1266 }
1267
1268 consume_skb(skb);
1269 return 0;
1270 }
1271
1272 static void process_deferred_actions(struct datapath *dp)
1273 {
1274 struct action_fifo *fifo = this_cpu_ptr(action_fifos);
1275
1276 /* Do not touch the FIFO in case there is no deferred actions. */
1277 if (action_fifo_is_empty(fifo))
1278 return;
1279
1280 /* Finishing executing all deferred actions. */
1281 do {
1282 struct deferred_action *da = action_fifo_get(fifo);
1283 struct sk_buff *skb = da->skb;
1284 struct sw_flow_key *key = &da->pkt_key;
1285 const struct nlattr *actions = da->actions;
1286 int actions_len = da->actions_len;
1287
1288 if (actions)
1289 do_execute_actions(dp, skb, key, actions, actions_len);
1290 else
1291 ovs_dp_process_packet(skb, key);
1292 } while (!action_fifo_is_empty(fifo));
1293
1294 /* Reset FIFO for the next packet. */
1295 action_fifo_init(fifo);
1296 }
1297
1298 /* Execute a list of actions against 'skb'. */
1299 int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
1300 const struct sw_flow_actions *acts,
1301 struct sw_flow_key *key)
1302 {
1303 int err, level;
1304
1305 level = __this_cpu_inc_return(exec_actions_level);
1306 if (unlikely(level > OVS_RECURSION_LIMIT)) {
1307 net_crit_ratelimited("ovs: recursion limit reached on datapath %s, probable configuration error\n",
1308 ovs_dp_name(dp));
1309 kfree_skb(skb);
1310 err = -ENETDOWN;
1311 goto out;
1312 }
1313
1314 err = do_execute_actions(dp, skb, key,
1315 acts->actions, acts->actions_len);
1316
1317 if (level == 1)
1318 process_deferred_actions(dp);
1319
1320 out:
1321 __this_cpu_dec(exec_actions_level);
1322 return err;
1323 }
1324
1325 int action_fifos_init(void)
1326 {
1327 action_fifos = alloc_percpu(struct action_fifo);
1328 if (!action_fifos)
1329 return -ENOMEM;
1330
1331 flow_keys = alloc_percpu(struct action_flow_keys);
1332 if (!flow_keys) {
1333 free_percpu(action_fifos);
1334 return -ENOMEM;
1335 }
1336
1337 return 0;
1338 }
1339
1340 void action_fifos_exit(void)
1341 {
1342 free_percpu(action_fifos);
1343 free_percpu(flow_keys);
1344 }