2 * Copyright (c) 2007-2014 Nicira, Inc.
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.
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.
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
19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/skbuff.h>
24 #include <linux/openvswitch.h>
25 #include <linux/sctp.h>
26 #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>
33 #include <net/checksum.h>
34 #include <net/dsfield.h>
35 #include <net/sctp/checksum.h>
43 static int do_execute_actions(struct datapath
*dp
, struct sk_buff
*skb
,
44 const struct nlattr
*attr
, int len
);
46 static int make_writable(struct sk_buff
*skb
, int write_len
)
48 if (!skb_cloned(skb
) || skb_clone_writable(skb
, write_len
))
51 return pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
);
54 /* The end of the mac header.
56 * For non-MPLS skbs this will correspond to the network header.
57 * For MPLS skbs it will be before the network_header as the MPLS
58 * label stack lies between the end of the mac header and the network
59 * header. That is, for MPLS skbs the end of the mac header
60 * is the top of the MPLS label stack.
62 static unsigned char *mac_header_end(const struct sk_buff
*skb
)
64 return skb_mac_header(skb
) + skb
->mac_len
;
67 static int push_mpls(struct sk_buff
*skb
,
68 const struct ovs_action_push_mpls
*mpls
)
73 if (skb_cow_head(skb
, MPLS_HLEN
) < 0)
76 skb_push(skb
, MPLS_HLEN
);
77 memmove(skb_mac_header(skb
) - MPLS_HLEN
, skb_mac_header(skb
),
79 skb_reset_mac_header(skb
);
81 new_mpls_lse
= (__be32
*)mac_header_end(skb
);
82 *new_mpls_lse
= mpls
->mpls_lse
;
84 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
85 skb
->csum
= csum_add(skb
->csum
, csum_partial(new_mpls_lse
,
89 hdr
->h_proto
= mpls
->mpls_ethertype
;
90 if (!ovs_skb_get_inner_protocol(skb
))
91 ovs_skb_set_inner_protocol(skb
, skb
->protocol
);
92 skb
->protocol
= mpls
->mpls_ethertype
;
96 static int pop_mpls(struct sk_buff
*skb
, const __be16 ethertype
)
101 err
= make_writable(skb
, skb
->mac_len
+ MPLS_HLEN
);
105 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
106 skb
->csum
= csum_sub(skb
->csum
,
107 csum_partial(mac_header_end(skb
),
110 memmove(skb_mac_header(skb
) + MPLS_HLEN
, skb_mac_header(skb
),
113 __skb_pull(skb
, MPLS_HLEN
);
114 skb_reset_mac_header(skb
);
116 /* mac_header_end() is used to locate the ethertype
117 * field correctly in the presence of VLAN tags.
119 hdr
= (struct ethhdr
*)(mac_header_end(skb
) - ETH_HLEN
);
120 hdr
->h_proto
= ethertype
;
121 if (eth_p_mpls(skb
->protocol
))
122 skb
->protocol
= ethertype
;
126 static int set_mpls(struct sk_buff
*skb
, const __be32
*mpls_lse
)
128 __be32
*stack
= (__be32
*)mac_header_end(skb
);
131 err
= make_writable(skb
, skb
->mac_len
+ MPLS_HLEN
);
135 if (skb
->ip_summed
== CHECKSUM_COMPLETE
) {
136 __be32 diff
[] = { ~(*stack
), *mpls_lse
};
137 skb
->csum
= ~csum_partial((char *)diff
, sizeof(diff
),
146 /* remove VLAN header from packet and update csum accordingly. */
147 static int __pop_vlan_tci(struct sk_buff
*skb
, __be16
*current_tci
)
149 struct vlan_hdr
*vhdr
;
152 err
= make_writable(skb
, VLAN_ETH_HLEN
);
156 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
157 skb
->csum
= csum_sub(skb
->csum
, csum_partial(skb
->data
158 + (2 * ETH_ALEN
), VLAN_HLEN
, 0));
160 vhdr
= (struct vlan_hdr
*)(skb
->data
+ ETH_HLEN
);
161 *current_tci
= vhdr
->h_vlan_TCI
;
163 memmove(skb
->data
+ VLAN_HLEN
, skb
->data
, 2 * ETH_ALEN
);
164 __skb_pull(skb
, VLAN_HLEN
);
166 vlan_set_encap_proto(skb
, vhdr
);
167 skb
->mac_header
+= VLAN_HLEN
;
168 /* Update mac_len for subsequent MPLS actions */
169 skb
->mac_len
-= VLAN_HLEN
;
174 static int pop_vlan(struct sk_buff
*skb
)
179 if (likely(vlan_tx_tag_present(skb
))) {
180 vlan_set_tci(skb
, 0);
182 if (unlikely(skb
->protocol
!= htons(ETH_P_8021Q
) ||
183 skb
->len
< VLAN_ETH_HLEN
))
186 err
= __pop_vlan_tci(skb
, &tci
);
190 /* move next vlan tag to hw accel tag */
191 if (likely(skb
->protocol
!= htons(ETH_P_8021Q
) ||
192 skb
->len
< VLAN_ETH_HLEN
))
195 err
= __pop_vlan_tci(skb
, &tci
);
199 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), ntohs(tci
));
203 static int push_vlan(struct sk_buff
*skb
, const struct ovs_action_push_vlan
*vlan
)
205 if (unlikely(vlan_tx_tag_present(skb
))) {
208 /* push down current VLAN tag */
209 current_tag
= vlan_tx_tag_get(skb
);
211 if (!__vlan_put_tag(skb
, skb
->vlan_proto
, current_tag
))
214 /* Update mac_len for subsequent MPLS actions */
215 skb
->mac_len
+= VLAN_HLEN
;
217 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
218 skb
->csum
= csum_add(skb
->csum
, csum_partial(skb
->data
219 + (2 * ETH_ALEN
), VLAN_HLEN
, 0));
222 __vlan_hwaccel_put_tag(skb
, vlan
->vlan_tpid
, ntohs(vlan
->vlan_tci
) & ~VLAN_TAG_PRESENT
);
226 static int set_eth_addr(struct sk_buff
*skb
,
227 const struct ovs_key_ethernet
*eth_key
)
230 err
= make_writable(skb
, ETH_HLEN
);
234 skb_postpull_rcsum(skb
, eth_hdr(skb
), ETH_ALEN
* 2);
236 ether_addr_copy(eth_hdr(skb
)->h_source
, eth_key
->eth_src
);
237 ether_addr_copy(eth_hdr(skb
)->h_dest
, eth_key
->eth_dst
);
239 ovs_skb_postpush_rcsum(skb
, eth_hdr(skb
), ETH_ALEN
* 2);
244 static void set_ip_addr(struct sk_buff
*skb
, struct iphdr
*nh
,
245 __be32
*addr
, __be32 new_addr
)
247 int transport_len
= skb
->len
- skb_transport_offset(skb
);
249 if (nh
->protocol
== IPPROTO_TCP
) {
250 if (likely(transport_len
>= sizeof(struct tcphdr
)))
251 inet_proto_csum_replace4(&tcp_hdr(skb
)->check
, skb
,
253 } else if (nh
->protocol
== IPPROTO_UDP
) {
254 if (likely(transport_len
>= sizeof(struct udphdr
))) {
255 struct udphdr
*uh
= udp_hdr(skb
);
257 if (uh
->check
|| skb
->ip_summed
== CHECKSUM_PARTIAL
) {
258 inet_proto_csum_replace4(&uh
->check
, skb
,
261 uh
->check
= CSUM_MANGLED_0
;
266 csum_replace4(&nh
->check
, *addr
, new_addr
);
271 static void update_ipv6_checksum(struct sk_buff
*skb
, u8 l4_proto
,
272 __be32 addr
[4], const __be32 new_addr
[4])
274 int transport_len
= skb
->len
- skb_transport_offset(skb
);
276 if (l4_proto
== IPPROTO_TCP
) {
277 if (likely(transport_len
>= sizeof(struct tcphdr
)))
278 inet_proto_csum_replace16(&tcp_hdr(skb
)->check
, skb
,
280 } else if (l4_proto
== IPPROTO_UDP
) {
281 if (likely(transport_len
>= sizeof(struct udphdr
))) {
282 struct udphdr
*uh
= udp_hdr(skb
);
284 if (uh
->check
|| skb
->ip_summed
== CHECKSUM_PARTIAL
) {
285 inet_proto_csum_replace16(&uh
->check
, skb
,
288 uh
->check
= CSUM_MANGLED_0
;
294 static void set_ipv6_addr(struct sk_buff
*skb
, u8 l4_proto
,
295 __be32 addr
[4], const __be32 new_addr
[4],
296 bool recalculate_csum
)
298 if (recalculate_csum
)
299 update_ipv6_checksum(skb
, l4_proto
, addr
, new_addr
);
302 memcpy(addr
, new_addr
, sizeof(__be32
[4]));
305 static void set_ipv6_tc(struct ipv6hdr
*nh
, u8 tc
)
307 nh
->priority
= tc
>> 4;
308 nh
->flow_lbl
[0] = (nh
->flow_lbl
[0] & 0x0F) | ((tc
& 0x0F) << 4);
311 static void set_ipv6_fl(struct ipv6hdr
*nh
, u32 fl
)
313 nh
->flow_lbl
[0] = (nh
->flow_lbl
[0] & 0xF0) | (fl
& 0x000F0000) >> 16;
314 nh
->flow_lbl
[1] = (fl
& 0x0000FF00) >> 8;
315 nh
->flow_lbl
[2] = fl
& 0x000000FF;
318 static void set_ip_ttl(struct sk_buff
*skb
, struct iphdr
*nh
, u8 new_ttl
)
320 csum_replace2(&nh
->check
, htons(nh
->ttl
<< 8), htons(new_ttl
<< 8));
324 static int set_ipv4(struct sk_buff
*skb
, const struct ovs_key_ipv4
*ipv4_key
)
329 err
= make_writable(skb
, skb_network_offset(skb
) +
330 sizeof(struct iphdr
));
336 if (ipv4_key
->ipv4_src
!= nh
->saddr
)
337 set_ip_addr(skb
, nh
, &nh
->saddr
, ipv4_key
->ipv4_src
);
339 if (ipv4_key
->ipv4_dst
!= nh
->daddr
)
340 set_ip_addr(skb
, nh
, &nh
->daddr
, ipv4_key
->ipv4_dst
);
342 if (ipv4_key
->ipv4_tos
!= nh
->tos
)
343 ipv4_change_dsfield(nh
, 0, ipv4_key
->ipv4_tos
);
345 if (ipv4_key
->ipv4_ttl
!= nh
->ttl
)
346 set_ip_ttl(skb
, nh
, ipv4_key
->ipv4_ttl
);
351 static int set_ipv6(struct sk_buff
*skb
, const struct ovs_key_ipv6
*ipv6_key
)
358 err
= make_writable(skb
, skb_network_offset(skb
) +
359 sizeof(struct ipv6hdr
));
364 saddr
= (__be32
*)&nh
->saddr
;
365 daddr
= (__be32
*)&nh
->daddr
;
367 if (memcmp(ipv6_key
->ipv6_src
, saddr
, sizeof(ipv6_key
->ipv6_src
)))
368 set_ipv6_addr(skb
, ipv6_key
->ipv6_proto
, saddr
,
369 ipv6_key
->ipv6_src
, true);
371 if (memcmp(ipv6_key
->ipv6_dst
, daddr
, sizeof(ipv6_key
->ipv6_dst
))) {
372 unsigned int offset
= 0;
373 int flags
= OVS_IP6T_FH_F_SKIP_RH
;
374 bool recalc_csum
= true;
376 if (ipv6_ext_hdr(nh
->nexthdr
))
377 recalc_csum
= ipv6_find_hdr(skb
, &offset
,
378 NEXTHDR_ROUTING
, NULL
,
379 &flags
) != NEXTHDR_ROUTING
;
381 set_ipv6_addr(skb
, ipv6_key
->ipv6_proto
, daddr
,
382 ipv6_key
->ipv6_dst
, recalc_csum
);
385 set_ipv6_tc(nh
, ipv6_key
->ipv6_tclass
);
386 set_ipv6_fl(nh
, ntohl(ipv6_key
->ipv6_label
));
387 nh
->hop_limit
= ipv6_key
->ipv6_hlimit
;
392 /* Must follow make_writable() since that can move the skb data. */
393 static void set_tp_port(struct sk_buff
*skb
, __be16
*port
,
394 __be16 new_port
, __sum16
*check
)
396 inet_proto_csum_replace2(check
, skb
, *port
, new_port
, 0);
401 static void set_udp_port(struct sk_buff
*skb
, __be16
*port
, __be16 new_port
)
403 struct udphdr
*uh
= udp_hdr(skb
);
405 if (uh
->check
&& skb
->ip_summed
!= CHECKSUM_PARTIAL
) {
406 set_tp_port(skb
, port
, new_port
, &uh
->check
);
409 uh
->check
= CSUM_MANGLED_0
;
416 static int set_udp(struct sk_buff
*skb
, const struct ovs_key_udp
*udp_port_key
)
421 err
= make_writable(skb
, skb_transport_offset(skb
) +
422 sizeof(struct udphdr
));
427 if (udp_port_key
->udp_src
!= uh
->source
)
428 set_udp_port(skb
, &uh
->source
, udp_port_key
->udp_src
);
430 if (udp_port_key
->udp_dst
!= uh
->dest
)
431 set_udp_port(skb
, &uh
->dest
, udp_port_key
->udp_dst
);
436 static int set_tcp(struct sk_buff
*skb
, const struct ovs_key_tcp
*tcp_port_key
)
441 err
= make_writable(skb
, skb_transport_offset(skb
) +
442 sizeof(struct tcphdr
));
447 if (tcp_port_key
->tcp_src
!= th
->source
)
448 set_tp_port(skb
, &th
->source
, tcp_port_key
->tcp_src
, &th
->check
);
450 if (tcp_port_key
->tcp_dst
!= th
->dest
)
451 set_tp_port(skb
, &th
->dest
, tcp_port_key
->tcp_dst
, &th
->check
);
456 static int set_sctp(struct sk_buff
*skb
,
457 const struct ovs_key_sctp
*sctp_port_key
)
461 unsigned int sctphoff
= skb_transport_offset(skb
);
463 err
= make_writable(skb
, sctphoff
+ sizeof(struct sctphdr
));
468 if (sctp_port_key
->sctp_src
!= sh
->source
||
469 sctp_port_key
->sctp_dst
!= sh
->dest
) {
470 __le32 old_correct_csum
, new_csum
, old_csum
;
472 old_csum
= sh
->checksum
;
473 old_correct_csum
= sctp_compute_cksum(skb
, sctphoff
);
475 sh
->source
= sctp_port_key
->sctp_src
;
476 sh
->dest
= sctp_port_key
->sctp_dst
;
478 new_csum
= sctp_compute_cksum(skb
, sctphoff
);
480 /* Carry any checksum errors through. */
481 sh
->checksum
= old_csum
^ old_correct_csum
^ new_csum
;
489 static int do_output(struct datapath
*dp
, struct sk_buff
*skb
, int out_port
)
496 vport
= ovs_vport_rcu(dp
, out_port
);
497 if (unlikely(!vport
)) {
502 ovs_vport_send(vport
, skb
);
506 static int output_userspace(struct datapath
*dp
, struct sk_buff
*skb
,
507 const struct nlattr
*attr
)
509 struct dp_upcall_info upcall
;
510 const struct nlattr
*a
;
513 BUG_ON(!OVS_CB(skb
)->pkt_key
);
515 upcall
.cmd
= OVS_PACKET_CMD_ACTION
;
516 upcall
.key
= OVS_CB(skb
)->pkt_key
;
517 upcall
.userdata
= NULL
;
520 for (a
= nla_data(attr
), rem
= nla_len(attr
); rem
> 0;
521 a
= nla_next(a
, &rem
)) {
522 switch (nla_type(a
)) {
523 case OVS_USERSPACE_ATTR_USERDATA
:
527 case OVS_USERSPACE_ATTR_PID
:
528 upcall
.portid
= nla_get_u32(a
);
533 return ovs_dp_upcall(dp
, skb
, &upcall
);
536 static bool last_action(const struct nlattr
*a
, int rem
)
538 return a
->nla_len
== rem
;
541 static int sample(struct datapath
*dp
, struct sk_buff
*skb
,
542 const struct nlattr
*attr
)
544 const struct nlattr
*acts_list
= NULL
;
545 const struct nlattr
*a
;
546 struct sk_buff
*sample_skb
;
549 for (a
= nla_data(attr
), rem
= nla_len(attr
); rem
> 0;
550 a
= nla_next(a
, &rem
)) {
551 switch (nla_type(a
)) {
552 case OVS_SAMPLE_ATTR_PROBABILITY
:
553 if (prandom_u32() >= nla_get_u32(a
))
557 case OVS_SAMPLE_ATTR_ACTIONS
:
563 rem
= nla_len(acts_list
);
564 a
= nla_data(acts_list
);
566 /* Actions list is either empty or only contains a single user-space
567 * action, the latter being a special case as it is the only known
568 * usage of the sample action.
569 * In these special cases don't clone the skb as there are no
570 * side-effects in the nested actions.
571 * Otherwise, clone in case the nested actions have side effects. */
572 if (likely(rem
== 0 ||
573 (nla_type(a
) == OVS_ACTION_ATTR_USERSPACE
&&
574 last_action(a
, rem
)))) {
578 sample_skb
= skb_clone(skb
, GFP_ATOMIC
);
581 /* Note that do_execute_actions() never consumes skb.
582 * In the case where skb has been cloned above it is the clone that
583 * is consumed. Otherwise the skb_get(skb) call prevents
584 * consumption by do_execute_actions(). Thus, it is safe to simply
585 * return the error code and let the caller (also
586 * do_execute_actions()) free skb on error. */
587 return do_execute_actions(dp
, sample_skb
, a
, rem
);
590 static void execute_hash(struct sk_buff
*skb
, const struct nlattr
*attr
)
592 struct sw_flow_key
*key
= OVS_CB(skb
)->pkt_key
;
593 struct ovs_action_hash
*hash_act
= nla_data(attr
);
596 /* OVS_HASH_ALG_L4 is the only possible hash algorithm. */
597 hash
= skb_get_hash(skb
);
598 hash
= jhash_1word(hash
, hash_act
->hash_basis
);
602 key
->ovs_flow_hash
= hash
;
605 static int execute_set_action(struct sk_buff
*skb
,
606 const struct nlattr
*nested_attr
)
610 switch (nla_type(nested_attr
)) {
611 case OVS_KEY_ATTR_PRIORITY
:
612 skb
->priority
= nla_get_u32(nested_attr
);
615 case OVS_KEY_ATTR_SKB_MARK
:
616 skb
->mark
= nla_get_u32(nested_attr
);
619 case OVS_KEY_ATTR_TUNNEL_INFO
:
620 OVS_CB(skb
)->tun_info
= nla_data(nested_attr
);
623 case OVS_KEY_ATTR_ETHERNET
:
624 err
= set_eth_addr(skb
, nla_data(nested_attr
));
627 case OVS_KEY_ATTR_IPV4
:
628 err
= set_ipv4(skb
, nla_data(nested_attr
));
631 case OVS_KEY_ATTR_IPV6
:
632 err
= set_ipv6(skb
, nla_data(nested_attr
));
635 case OVS_KEY_ATTR_TCP
:
636 err
= set_tcp(skb
, nla_data(nested_attr
));
639 case OVS_KEY_ATTR_UDP
:
640 err
= set_udp(skb
, nla_data(nested_attr
));
643 case OVS_KEY_ATTR_SCTP
:
644 err
= set_sctp(skb
, nla_data(nested_attr
));
647 case OVS_KEY_ATTR_MPLS
:
648 err
= set_mpls(skb
, nla_data(nested_attr
));
655 static int execute_recirc(struct datapath
*dp
, struct sk_buff
*skb
,
656 const struct nlattr
*a
)
658 struct sw_flow_key recirc_key
;
659 const struct vport
*p
= OVS_CB(skb
)->input_vport
;
660 uint32_t hash
= OVS_CB(skb
)->pkt_key
->ovs_flow_hash
;
663 err
= ovs_flow_extract(skb
, p
->port_no
, &recirc_key
);
669 recirc_key
.ovs_flow_hash
= hash
;
670 recirc_key
.recirc_id
= nla_get_u32(a
);
672 ovs_dp_process_packet_with_key(skb
, &recirc_key
, true);
677 /* Execute a list of actions against 'skb'. */
678 static int do_execute_actions(struct datapath
*dp
, struct sk_buff
*skb
,
679 const struct nlattr
*attr
, int len
)
681 /* Every output action needs a separate clone of 'skb', but the common
682 * case is just a single output action, so that doing a clone and
683 * then freeing the original skbuff is wasteful. So the following code
684 * is slightly obscure just to avoid that. */
686 const struct nlattr
*a
;
689 for (a
= attr
, rem
= len
; rem
> 0;
690 a
= nla_next(a
, &rem
)) {
693 if (prev_port
!= -1) {
694 do_output(dp
, skb_clone(skb
, GFP_ATOMIC
), prev_port
);
698 switch (nla_type(a
)) {
699 case OVS_ACTION_ATTR_OUTPUT
:
700 prev_port
= nla_get_u32(a
);
703 case OVS_ACTION_ATTR_USERSPACE
:
704 output_userspace(dp
, skb
, a
);
707 case OVS_ACTION_ATTR_HASH
:
708 execute_hash(skb
, a
);
711 case OVS_ACTION_ATTR_PUSH_MPLS
:
712 err
= push_mpls(skb
, nla_data(a
));
715 case OVS_ACTION_ATTR_POP_MPLS
:
716 err
= pop_mpls(skb
, nla_get_be16(a
));
719 case OVS_ACTION_ATTR_PUSH_VLAN
:
720 err
= push_vlan(skb
, nla_data(a
));
721 if (unlikely(err
)) /* skb already freed. */
725 case OVS_ACTION_ATTR_POP_VLAN
:
729 case OVS_ACTION_ATTR_RECIRC
: {
730 struct sk_buff
*recirc_skb
;
732 if (!last_action(a
, rem
))
733 recirc_skb
= skb_clone(skb
, GFP_ATOMIC
);
737 err
= execute_recirc(dp
, recirc_skb
, a
);
739 if (recirc_skb
== skb
)
745 case OVS_ACTION_ATTR_SET
:
746 err
= execute_set_action(skb
, nla_data(a
));
749 case OVS_ACTION_ATTR_SAMPLE
:
750 err
= sample(dp
, skb
, a
);
761 do_output(dp
, skb
, prev_port
);
768 /* We limit the number of times that we pass into execute_actions()
769 * to avoid blowing out the stack in the event that we have a loop.
771 * Each loop adds some (estimated) cost to the kernel stack.
772 * The loop terminates when the max cost is exceeded.
774 #define RECIRC_STACK_COST 1
775 #define DEFAULT_STACK_COST 4
776 /* Allow up to 4 regular services, and up to 3 recirculations */
777 #define MAX_STACK_COST (DEFAULT_STACK_COST * 4 + RECIRC_STACK_COST * 3)
779 struct loop_counter
{
780 u8 stack_cost
; /* loop stack cost. */
781 bool looping
; /* Loop detected? */
784 static DEFINE_PER_CPU(struct loop_counter
, loop_counters
);
786 static int loop_suppress(struct datapath
*dp
, struct sw_flow_actions
*actions
)
789 pr_warn("%s: flow loop detected, dropping\n",
791 actions
->actions_len
= 0;
795 /* Execute a list of actions against 'skb'. */
796 int ovs_execute_actions(struct datapath
*dp
, struct sk_buff
*skb
, bool recirc
)
798 struct sw_flow_actions
*acts
= rcu_dereference(OVS_CB(skb
)->flow
->sf_acts
);
799 const u8 stack_cost
= recirc
? RECIRC_STACK_COST
: DEFAULT_STACK_COST
;
800 struct loop_counter
*loop
;
803 /* Check whether we've looped too much. */
804 loop
= &__get_cpu_var(loop_counters
);
805 loop
->stack_cost
+= stack_cost
;
806 if (unlikely(loop
->stack_cost
> MAX_STACK_COST
))
807 loop
->looping
= true;
808 if (unlikely(loop
->looping
)) {
809 error
= loop_suppress(dp
, acts
);
814 OVS_CB(skb
)->tun_info
= NULL
;
815 error
= do_execute_actions(dp
, skb
, acts
->actions
, acts
->actions_len
);
817 /* Check whether sub-actions looped too much. */
818 if (unlikely(loop
->looping
))
819 error
= loop_suppress(dp
, acts
);
822 /* Decrement loop stack cost. */
823 loop
->stack_cost
-= stack_cost
;
824 if (!loop
->stack_cost
)
825 loop
->looping
= false;