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