]> git.proxmox.com Git - mirror_ovs.git/blame - lib/odp-execute.c
ovsdb-idl: Fix iteration over tracked rows with no actual data.
[mirror_ovs.git] / lib / odp-execute.c
CommitLineData
f094af7b 1/*
e60e935b 2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
f094af7b
SH
3 * Copyright (c) 2013 Simon Horman
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <config.h>
19#include "odp-execute.h"
b2befd5b 20#include <sys/types.h>
1368af0c 21#include <netinet/in.h>
b2befd5b 22#include <arpa/inet.h>
e60e935b 23#include <netinet/icmp6.h>
6d670e7f 24#include <netinet/ip6.h>
f094af7b
SH
25#include <stdlib.h>
26#include <string.h>
27
a13a0209 28#include "coverage.h"
e14deea0 29#include "dp-packet.h"
758c456d 30#include "dpif.h"
f094af7b 31#include "netlink.h"
837eefc7 32#include "odp-netlink.h"
6c13071b 33#include "odp-util.h"
f094af7b 34#include "packets.h"
c6bf49f3 35#include "flow.h"
f6c8a6b1 36#include "unaligned.h"
f094af7b 37#include "util.h"
fc052306 38#include "csum.h"
1fe178d2 39#include "conntrack.h"
a13a0209
AT
40#include "openvswitch/vlog.h"
41
42VLOG_DEFINE_THIS_MODULE(odp_execute);
43COVERAGE_DEFINE(datapath_drop_sample_error);
44COVERAGE_DEFINE(datapath_drop_nsh_decap_error);
45COVERAGE_DEFINE(drop_action_of_pipeline);
46COVERAGE_DEFINE(drop_action_bridge_not_found);
47COVERAGE_DEFINE(drop_action_recursion_too_deep);
48COVERAGE_DEFINE(drop_action_too_many_resubmit);
49COVERAGE_DEFINE(drop_action_stack_too_deep);
50COVERAGE_DEFINE(drop_action_no_recirculation_context);
51COVERAGE_DEFINE(drop_action_recirculation_conflict);
52COVERAGE_DEFINE(drop_action_too_many_mpls_labels);
53COVERAGE_DEFINE(drop_action_invalid_tunnel_metadata);
54COVERAGE_DEFINE(drop_action_unsupported_packet_type);
55COVERAGE_DEFINE(drop_action_congestion);
56COVERAGE_DEFINE(drop_action_forwarding_disabled);
57
58static void
59dp_update_drop_action_counter(enum xlate_error drop_reason,
60 int delta)
61{
62 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
63
64 switch (drop_reason) {
65 case XLATE_OK:
66 COVERAGE_ADD(drop_action_of_pipeline, delta);
67 break;
68 case XLATE_BRIDGE_NOT_FOUND:
69 COVERAGE_ADD(drop_action_bridge_not_found, delta);
70 break;
71 case XLATE_RECURSION_TOO_DEEP:
72 COVERAGE_ADD(drop_action_recursion_too_deep, delta);
73 break;
74 case XLATE_TOO_MANY_RESUBMITS:
75 COVERAGE_ADD(drop_action_too_many_resubmit, delta);
76 break;
77 case XLATE_STACK_TOO_DEEP:
78 COVERAGE_ADD(drop_action_stack_too_deep, delta);
79 break;
80 case XLATE_NO_RECIRCULATION_CONTEXT:
81 COVERAGE_ADD(drop_action_no_recirculation_context, delta);
82 break;
83 case XLATE_RECIRCULATION_CONFLICT:
84 COVERAGE_ADD(drop_action_recirculation_conflict, delta);
85 break;
86 case XLATE_TOO_MANY_MPLS_LABELS:
87 COVERAGE_ADD(drop_action_too_many_mpls_labels, delta);
88 break;
89 case XLATE_INVALID_TUNNEL_METADATA:
90 COVERAGE_ADD(drop_action_invalid_tunnel_metadata, delta);
91 break;
92 case XLATE_UNSUPPORTED_PACKET_TYPE:
93 COVERAGE_ADD(drop_action_unsupported_packet_type, delta);
94 break;
95 case XLATE_CONGESTION_DROP:
96 COVERAGE_ADD(drop_action_congestion, delta);
97 break;
98 case XLATE_FORWARDING_DISABLED:
99 COVERAGE_ADD(drop_action_forwarding_disabled, delta);
100 break;
101 case XLATE_MAX:
102 default:
103 VLOG_ERR_RL(&rl, "Invalid Drop reason type: %d", drop_reason);
104 }
105}
f094af7b 106
6d670e7f 107/* Masked copy of an ethernet address. 'src' is already properly masked. */
f094af7b 108static void
74ff3298
JR
109ether_addr_copy_masked(struct eth_addr *dst, const struct eth_addr src,
110 const struct eth_addr mask)
6d670e7f
JR
111{
112 int i;
113
74ff3298
JR
114 for (i = 0; i < ARRAY_SIZE(dst->be16); i++) {
115 dst->be16[i] = src.be16[i] | (dst->be16[i] & ~mask.be16[i]);
6d670e7f
JR
116 }
117}
118
119static void
cf62fa4c 120odp_eth_set_addrs(struct dp_packet *packet, const struct ovs_key_ethernet *key,
6d670e7f 121 const struct ovs_key_ethernet *mask)
f094af7b 122{
2482b0b0 123 struct eth_header *eh = dp_packet_eth(packet);
f094af7b 124
cf3b7538 125 if (eh) {
6d670e7f 126 if (!mask) {
74ff3298
JR
127 eh->eth_src = key->eth_src;
128 eh->eth_dst = key->eth_dst;
6d670e7f 129 } else {
74ff3298
JR
130 ether_addr_copy_masked(&eh->eth_src, key->eth_src, mask->eth_src);
131 ether_addr_copy_masked(&eh->eth_dst, key->eth_dst, mask->eth_dst);
6d670e7f 132 }
cf3b7538 133 }
f094af7b
SH
134}
135
6d670e7f 136static void
cf62fa4c 137odp_set_ipv4(struct dp_packet *packet, const struct ovs_key_ipv4 *key,
6d670e7f
JR
138 const struct ovs_key_ipv4 *mask)
139{
cf62fa4c 140 struct ip_header *nh = dp_packet_l3(packet);
fc052306
ZB
141 ovs_be32 ip_src_nh;
142 ovs_be32 ip_dst_nh;
143 ovs_be32 new_ip_src;
144 ovs_be32 new_ip_dst;
145 uint8_t new_tos;
146 uint8_t new_ttl;
6d670e7f 147
fc052306
ZB
148 if (mask->ipv4_src) {
149 ip_src_nh = get_16aligned_be32(&nh->ip_src);
150 new_ip_src = key->ipv4_src | (ip_src_nh & ~mask->ipv4_src);
151
152 if (ip_src_nh != new_ip_src) {
153 packet_set_ipv4_addr(packet, &nh->ip_src, new_ip_src);
154 }
155 }
156
157 if (mask->ipv4_dst) {
158 ip_dst_nh = get_16aligned_be32(&nh->ip_dst);
159 new_ip_dst = key->ipv4_dst | (ip_dst_nh & ~mask->ipv4_dst);
160
161 if (ip_dst_nh != new_ip_dst) {
162 packet_set_ipv4_addr(packet, &nh->ip_dst, new_ip_dst);
163 }
164 }
165
166 if (mask->ipv4_tos) {
167 new_tos = key->ipv4_tos | (nh->ip_tos & ~mask->ipv4_tos);
168
169 if (nh->ip_tos != new_tos) {
170 nh->ip_csum = recalc_csum16(nh->ip_csum,
171 htons((uint16_t) nh->ip_tos),
172 htons((uint16_t) new_tos));
173 nh->ip_tos = new_tos;
174 }
175 }
176
177 if (OVS_LIKELY(mask->ipv4_ttl)) {
178 new_ttl = key->ipv4_ttl | (nh->ip_ttl & ~mask->ipv4_ttl);
179
180 if (OVS_LIKELY(nh->ip_ttl != new_ttl)) {
181 nh->ip_csum = recalc_csum16(nh->ip_csum, htons(nh->ip_ttl << 8),
182 htons(new_ttl << 8));
183 nh->ip_ttl = new_ttl;
184 }
185 }
6d670e7f
JR
186}
187
932c96b7
JR
188static struct in6_addr *
189mask_ipv6_addr(const ovs_16aligned_be32 *old, const struct in6_addr *addr,
190 const struct in6_addr *mask, struct in6_addr *masked)
6d670e7f 191{
932c96b7 192#ifdef s6_addr32
6d670e7f 193 for (int i = 0; i < 4; i++) {
932c96b7
JR
194 masked->s6_addr32[i] = addr->s6_addr32[i]
195 | (get_16aligned_be32(&old[i]) & ~mask->s6_addr32[i]);
6d670e7f 196 }
932c96b7
JR
197#else
198 const uint8_t *old8 = (const uint8_t *)old;
199 for (int i = 0; i < 16; i++) {
200 masked->s6_addr[i] = addr->s6_addr[i] | (old8[i] & ~mask->s6_addr[i]);
201 }
202#endif
6d670e7f
JR
203 return masked;
204}
205
206static void
cf62fa4c 207odp_set_ipv6(struct dp_packet *packet, const struct ovs_key_ipv6 *key,
6d670e7f
JR
208 const struct ovs_key_ipv6 *mask)
209{
cf62fa4c 210 struct ovs_16aligned_ip6_hdr *nh = dp_packet_l3(packet);
932c96b7 211 struct in6_addr sbuf, dbuf;
6d670e7f
JR
212 uint8_t old_tc = ntohl(get_16aligned_be32(&nh->ip6_flow)) >> 20;
213 ovs_be32 old_fl = get_16aligned_be32(&nh->ip6_flow) & htonl(0xfffff);
214
215 packet_set_ipv6(
216 packet,
932c96b7
JR
217 mask_ipv6_addr(nh->ip6_src.be32, &key->ipv6_src, &mask->ipv6_src,
218 &sbuf),
219 mask_ipv6_addr(nh->ip6_dst.be32, &key->ipv6_dst, &mask->ipv6_dst,
220 &dbuf),
6d670e7f
JR
221 key->ipv6_tclass | (old_tc & ~mask->ipv6_tclass),
222 key->ipv6_label | (old_fl & ~mask->ipv6_label),
223 key->ipv6_hlimit | (nh->ip6_hlim & ~mask->ipv6_hlimit));
224}
225
226static void
cf62fa4c 227odp_set_tcp(struct dp_packet *packet, const struct ovs_key_tcp *key,
6d670e7f
JR
228 const struct ovs_key_tcp *mask)
229{
cf62fa4c 230 struct tcp_header *th = dp_packet_l4(packet);
6d670e7f 231
cf62fa4c 232 if (OVS_LIKELY(th && dp_packet_get_tcp_payload(packet))) {
b8778a0d
JR
233 packet_set_tcp_port(packet,
234 key->tcp_src | (th->tcp_src & ~mask->tcp_src),
235 key->tcp_dst | (th->tcp_dst & ~mask->tcp_dst));
236 }
6d670e7f
JR
237}
238
239static void
cf62fa4c 240odp_set_udp(struct dp_packet *packet, const struct ovs_key_udp *key,
6d670e7f
JR
241 const struct ovs_key_udp *mask)
242{
cf62fa4c 243 struct udp_header *uh = dp_packet_l4(packet);
6d670e7f 244
cf62fa4c 245 if (OVS_LIKELY(uh && dp_packet_get_udp_payload(packet))) {
b8778a0d
JR
246 packet_set_udp_port(packet,
247 key->udp_src | (uh->udp_src & ~mask->udp_src),
248 key->udp_dst | (uh->udp_dst & ~mask->udp_dst));
249 }
6d670e7f
JR
250}
251
252static void
cf62fa4c 253odp_set_sctp(struct dp_packet *packet, const struct ovs_key_sctp *key,
6d670e7f
JR
254 const struct ovs_key_sctp *mask)
255{
cf62fa4c 256 struct sctp_header *sh = dp_packet_l4(packet);
6d670e7f 257
cf62fa4c 258 if (OVS_LIKELY(sh && dp_packet_get_sctp_payload(packet))) {
b8778a0d
JR
259 packet_set_sctp_port(packet,
260 key->sctp_src | (sh->sctp_src & ~mask->sctp_src),
261 key->sctp_dst | (sh->sctp_dst & ~mask->sctp_dst));
262 }
6d670e7f
JR
263}
264
f094af7b 265static void
6c13071b
SH
266odp_set_tunnel_action(const struct nlattr *a, struct flow_tnl *tun_key)
267{
d40533fc 268 ovs_assert(odp_tun_key_from_attr(a, tun_key, NULL) != ODP_FIT_ERROR);
6c13071b
SH
269}
270
f6c8a6b1 271static void
cf62fa4c 272set_arp(struct dp_packet *packet, const struct ovs_key_arp *key,
6d670e7f 273 const struct ovs_key_arp *mask)
f6c8a6b1 274{
cf62fa4c 275 struct arp_eth_header *arp = dp_packet_l3(packet);
f6c8a6b1 276
6d670e7f
JR
277 if (!mask) {
278 arp->ar_op = key->arp_op;
74ff3298 279 arp->ar_sha = key->arp_sha;
6d670e7f 280 put_16aligned_be32(&arp->ar_spa, key->arp_sip);
74ff3298 281 arp->ar_tha = key->arp_tha;
6d670e7f
JR
282 put_16aligned_be32(&arp->ar_tpa, key->arp_tip);
283 } else {
284 ovs_be32 ar_spa = get_16aligned_be32(&arp->ar_spa);
285 ovs_be32 ar_tpa = get_16aligned_be32(&arp->ar_tpa);
286
287 arp->ar_op = key->arp_op | (arp->ar_op & ~mask->arp_op);
74ff3298 288 ether_addr_copy_masked(&arp->ar_sha, key->arp_sha, mask->arp_sha);
6d670e7f
JR
289 put_16aligned_be32(&arp->ar_spa,
290 key->arp_sip | (ar_spa & ~mask->arp_sip));
74ff3298 291 ether_addr_copy_masked(&arp->ar_tha, key->arp_tha, mask->arp_tha);
6d670e7f
JR
292 put_16aligned_be32(&arp->ar_tpa,
293 key->arp_tip | (ar_tpa & ~mask->arp_tip));
294 }
f6c8a6b1
BP
295}
296
9b2b8497
VDA
297static void
298odp_set_nd_ext(struct dp_packet *packet, const struct ovs_key_nd_extensions
299 *key, const struct ovs_key_nd_extensions *mask)
300{
301 const struct ovs_nd_msg *ns = dp_packet_l4(packet);
302 ovs_16aligned_be32 reserved = ns->rso_flags;
303 uint8_t opt_type = ns->options[0].type;
304
305 if (mask->nd_reserved) {
306 put_16aligned_be32(&reserved, key->nd_reserved);
307 }
308 if (mask->nd_options_type) {
309 opt_type = key->nd_options_type;
310 }
311 packet_set_nd_ext(packet, reserved, opt_type);
312}
313
e60e935b 314static void
cf62fa4c 315odp_set_nd(struct dp_packet *packet, const struct ovs_key_nd *key,
e60e935b
SRCSA
316 const struct ovs_key_nd *mask)
317{
cf62fa4c 318 const struct ovs_nd_msg *ns = dp_packet_l4(packet);
86d46f3c 319 const struct ovs_nd_lla_opt *lla_opt = dp_packet_get_nd_payload(packet);
e60e935b 320
86d46f3c 321 if (OVS_LIKELY(ns && lla_opt)) {
cf62fa4c 322 int bytes_remain = dp_packet_l4_size(packet) - sizeof(*ns);
932c96b7 323 struct in6_addr tgt_buf;
74ff3298
JR
324 struct eth_addr sll_buf = eth_addr_zero;
325 struct eth_addr tll_buf = eth_addr_zero;
e60e935b 326
86d46f3c
ZKL
327 while (bytes_remain >= ND_LLA_OPT_LEN && lla_opt->len != 0) {
328 if (lla_opt->type == ND_OPT_SOURCE_LINKADDR
329 && lla_opt->len == 1) {
330 sll_buf = lla_opt->mac;
74ff3298 331 ether_addr_copy_masked(&sll_buf, key->nd_sll, mask->nd_sll);
e60e935b
SRCSA
332
333 /* A packet can only contain one SLL or TLL option */
334 break;
86d46f3c
ZKL
335 } else if (lla_opt->type == ND_OPT_TARGET_LINKADDR
336 && lla_opt->len == 1) {
337 tll_buf = lla_opt->mac;
74ff3298 338 ether_addr_copy_masked(&tll_buf, key->nd_tll, mask->nd_tll);
e60e935b
SRCSA
339
340 /* A packet can only contain one SLL or TLL option */
341 break;
342 }
343
86d46f3c
ZKL
344 lla_opt += lla_opt->len;
345 bytes_remain -= lla_opt->len * ND_LLA_OPT_LEN;
e60e935b
SRCSA
346 }
347
348 packet_set_nd(packet,
932c96b7
JR
349 mask_ipv6_addr(ns->target.be32, &key->nd_target,
350 &mask->nd_target, &tgt_buf),
e60e935b
SRCSA
351 sll_buf,
352 tll_buf);
353 }
354}
355
3d2fbd70
JS
356/* Set the NSH header. Assumes the NSH header is present and matches the
357 * MD format of the key. The slow path must take case of that. */
358static void
81fdabb9 359odp_set_nsh(struct dp_packet *packet, const struct nlattr *a, bool has_mask)
3d2fbd70 360{
81fdabb9 361 struct ovs_key_nsh key, mask;
3d2fbd70 362 struct nsh_hdr *nsh = dp_packet_l3(packet);
9a180f2c 363 uint8_t mdtype = nsh_md_type(nsh);
f59cb331 364 ovs_be32 path_hdr;
3d2fbd70 365
81fdabb9 366 if (has_mask) {
d40533fc 367 odp_nsh_key_from_attr(a, &key, &mask, NULL);
81fdabb9 368 } else {
d40533fc 369 odp_nsh_key_from_attr(a, &key, NULL, NULL);
81fdabb9
YY
370 }
371
372 if (!has_mask) {
373 nsh_set_flags_and_ttl(nsh, key.flags, key.ttl);
374 put_16aligned_be32(&nsh->path_hdr, key.path_hdr);
9a180f2c 375 switch (mdtype) {
3d2fbd70
JS
376 case NSH_M_TYPE1:
377 for (int i = 0; i < 4; i++) {
81fdabb9 378 put_16aligned_be32(&nsh->md1.context[i], key.context[i]);
3d2fbd70
JS
379 }
380 break;
381 case NSH_M_TYPE2:
3d2fbd70 382 default:
1fc11c59
JS
383 /* No support for setting any other metadata format yet. */
384 break;
3d2fbd70
JS
385 }
386 } else {
17553f27
YY
387 uint8_t flags = nsh_get_flags(nsh);
388 uint8_t ttl = nsh_get_ttl(nsh);
389
81fdabb9
YY
390 flags = key.flags | (flags & ~mask.flags);
391 ttl = key.ttl | (ttl & ~mask.ttl);
17553f27 392 nsh_set_flags_and_ttl(nsh, flags, ttl);
3d2fbd70 393
17553f27
YY
394 uint32_t spi = ntohl(nsh_get_spi(nsh));
395 uint8_t si = nsh_get_si(nsh);
81fdabb9
YY
396 uint32_t spi_mask = nsh_path_hdr_to_spi_uint32(mask.path_hdr);
397 uint8_t si_mask = nsh_path_hdr_to_si(mask.path_hdr);
f59cb331
YY
398 if (spi_mask == 0x00ffffff) {
399 spi_mask = UINT32_MAX;
400 }
81fdabb9
YY
401 spi = nsh_path_hdr_to_spi_uint32(key.path_hdr) | (spi & ~spi_mask);
402 si = nsh_path_hdr_to_si(key.path_hdr) | (si & ~si_mask);
17553f27
YY
403 path_hdr = nsh_get_path_hdr(nsh);
404 nsh_path_hdr_set_spi(&path_hdr, htonl(spi));
405 nsh_path_hdr_set_si(&path_hdr, si);
3d2fbd70 406 put_16aligned_be32(&nsh->path_hdr, path_hdr);
9a180f2c 407 switch (mdtype) {
3d2fbd70
JS
408 case NSH_M_TYPE1:
409 for (int i = 0; i < 4; i++) {
f59cb331 410 ovs_be32 p = get_16aligned_be32(&nsh->md1.context[i]);
81fdabb9
YY
411 ovs_be32 k = key.context[i];
412 ovs_be32 m = mask.context[i];
f59cb331 413 put_16aligned_be32(&nsh->md1.context[i], k | (p & ~m));
3d2fbd70
JS
414 }
415 break;
416 case NSH_M_TYPE2:
3d2fbd70 417 default:
1fc11c59
JS
418 /* No support for setting any other metadata format yet. */
419 break;
3d2fbd70
JS
420 }
421 }
422}
423
6c13071b 424static void
e14deea0 425odp_execute_set_action(struct dp_packet *packet, const struct nlattr *a)
f094af7b
SH
426{
427 enum ovs_key_attr type = nl_attr_type(a);
428 const struct ovs_key_ipv4 *ipv4_key;
429 const struct ovs_key_ipv6 *ipv6_key;
41ccaa24 430 struct pkt_metadata *md = &packet->md;
f094af7b
SH
431
432 switch (type) {
433 case OVS_KEY_ATTR_PRIORITY:
09f9da0b 434 md->skb_priority = nl_attr_get_u32(a);
6c13071b
SH
435 break;
436
f094af7b 437 case OVS_KEY_ATTR_TUNNEL:
09f9da0b 438 odp_set_tunnel_action(a, &md->tunnel);
6c13071b
SH
439 break;
440
f094af7b 441 case OVS_KEY_ATTR_SKB_MARK:
09f9da0b 442 md->pkt_mark = nl_attr_get_u32(a);
f094af7b
SH
443 break;
444
445 case OVS_KEY_ATTR_ETHERNET:
cf62fa4c 446 odp_eth_set_addrs(packet, nl_attr_get(a), NULL);
f094af7b
SH
447 break;
448
f59cb331 449 case OVS_KEY_ATTR_NSH: {
81fdabb9 450 odp_set_nsh(packet, a, false);
3d2fbd70 451 break;
f59cb331 452 }
3d2fbd70 453
f094af7b
SH
454 case OVS_KEY_ATTR_IPV4:
455 ipv4_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_ipv4));
cf62fa4c 456 packet_set_ipv4(packet, ipv4_key->ipv4_src,
91088554
DDP
457 ipv4_key->ipv4_dst, ipv4_key->ipv4_tos,
458 ipv4_key->ipv4_ttl);
f094af7b
SH
459 break;
460
461 case OVS_KEY_ATTR_IPV6:
462 ipv6_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_ipv6));
932c96b7 463 packet_set_ipv6(packet, &ipv6_key->ipv6_src, &ipv6_key->ipv6_dst,
91088554
DDP
464 ipv6_key->ipv6_tclass, ipv6_key->ipv6_label,
465 ipv6_key->ipv6_hlimit);
f094af7b
SH
466 break;
467
468 case OVS_KEY_ATTR_TCP:
cf62fa4c 469 if (OVS_LIKELY(dp_packet_get_tcp_payload(packet))) {
b8778a0d
JR
470 const struct ovs_key_tcp *tcp_key
471 = nl_attr_get_unspec(a, sizeof(struct ovs_key_tcp));
472
cf62fa4c 473 packet_set_tcp_port(packet, tcp_key->tcp_src,
b8778a0d
JR
474 tcp_key->tcp_dst);
475 }
f094af7b
SH
476 break;
477
2b06df54 478 case OVS_KEY_ATTR_UDP:
cf62fa4c 479 if (OVS_LIKELY(dp_packet_get_udp_payload(packet))) {
b8778a0d
JR
480 const struct ovs_key_udp *udp_key
481 = nl_attr_get_unspec(a, sizeof(struct ovs_key_udp));
482
cf62fa4c 483 packet_set_udp_port(packet, udp_key->udp_src,
b8778a0d
JR
484 udp_key->udp_dst);
485 }
f094af7b
SH
486 break;
487
c6bcb685 488 case OVS_KEY_ATTR_SCTP:
cf62fa4c 489 if (OVS_LIKELY(dp_packet_get_sctp_payload(packet))) {
b8778a0d
JR
490 const struct ovs_key_sctp *sctp_key
491 = nl_attr_get_unspec(a, sizeof(struct ovs_key_sctp));
492
cf62fa4c 493 packet_set_sctp_port(packet, sctp_key->sctp_src,
b8778a0d
JR
494 sctp_key->sctp_dst);
495 }
c6bcb685
JS
496 break;
497
2b06df54 498 case OVS_KEY_ATTR_MPLS:
cf62fa4c 499 set_mpls_lse(packet, nl_attr_get_be32(a));
6d670e7f 500 break;
f094af7b 501
f6c8a6b1 502 case OVS_KEY_ATTR_ARP:
cf62fa4c 503 set_arp(packet, nl_attr_get(a), NULL);
f6c8a6b1
BP
504 break;
505
f6ecf944
JP
506 case OVS_KEY_ATTR_ICMP:
507 case OVS_KEY_ATTR_ICMPV6:
508 if (OVS_LIKELY(dp_packet_get_icmp_payload(packet))) {
509 const struct ovs_key_icmp *icmp_key
510 = nl_attr_get_unspec(a, sizeof(struct ovs_key_icmp));
511
512 packet_set_icmp(packet, icmp_key->icmp_type, icmp_key->icmp_code);
513 }
514 break;
515
e60e935b 516 case OVS_KEY_ATTR_ND:
cf62fa4c 517 if (OVS_LIKELY(dp_packet_get_nd_payload(packet))) {
e60e935b
SRCSA
518 const struct ovs_key_nd *nd_key
519 = nl_attr_get_unspec(a, sizeof(struct ovs_key_nd));
932c96b7 520 packet_set_nd(packet, &nd_key->nd_target, nd_key->nd_sll,
74ff3298 521 nd_key->nd_tll);
e60e935b
SRCSA
522 }
523 break;
524
9b2b8497
VDA
525 case OVS_KEY_ATTR_ND_EXTENSIONS:
526 if (OVS_LIKELY(dp_packet_get_nd_payload(packet))) {
527 const struct ovs_key_nd_extensions *nd_ext_key
528 = nl_attr_get_unspec(a, sizeof(struct ovs_key_nd_extensions));
529 ovs_16aligned_be32 rso_flags;
530 put_16aligned_be32(&rso_flags, nd_ext_key->nd_reserved);
531 packet_set_nd_ext(packet, rso_flags, nd_ext_key->nd_options_type);
532 }
533 break;
534
572f732a 535 case OVS_KEY_ATTR_DP_HASH:
61a2647e 536 md->dp_hash = nl_attr_get_u32(a);
572f732a
AZ
537 break;
538
539 case OVS_KEY_ATTR_RECIRC_ID:
540 md->recirc_id = nl_attr_get_u32(a);
541 break;
542
2b06df54 543 case OVS_KEY_ATTR_UNSPEC:
beb75a40 544 case OVS_KEY_ATTR_PACKET_TYPE:
2b06df54
JS
545 case OVS_KEY_ATTR_ENCAP:
546 case OVS_KEY_ATTR_ETHERTYPE:
547 case OVS_KEY_ATTR_IN_PORT:
548 case OVS_KEY_ATTR_VLAN:
dc235f7f 549 case OVS_KEY_ATTR_TCP_FLAGS:
07659514 550 case OVS_KEY_ATTR_CT_STATE:
c30b4cea
JR
551 case OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4:
552 case OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6:
07659514 553 case OVS_KEY_ATTR_CT_ZONE:
8e53fe8c 554 case OVS_KEY_ATTR_CT_MARK:
9daf2348 555 case OVS_KEY_ATTR_CT_LABELS:
2b06df54
JS
556 case __OVS_KEY_ATTR_MAX:
557 default:
428b2edd 558 OVS_NOT_REACHED();
f094af7b
SH
559 }
560}
561
6d670e7f
JR
562#define get_mask(a, type) ((const type *)(const void *)(a + 1) + 1)
563
564static void
e14deea0 565odp_execute_masked_set_action(struct dp_packet *packet,
41ccaa24 566 const struct nlattr *a)
6d670e7f 567{
41ccaa24 568 struct pkt_metadata *md = &packet->md;
6d670e7f
JR
569 enum ovs_key_attr type = nl_attr_type(a);
570 struct mpls_hdr *mh;
571
572 switch (type) {
573 case OVS_KEY_ATTR_PRIORITY:
574 md->skb_priority = nl_attr_get_u32(a)
575 | (md->skb_priority & ~*get_mask(a, uint32_t));
576 break;
577
578 case OVS_KEY_ATTR_SKB_MARK:
579 md->pkt_mark = nl_attr_get_u32(a)
580 | (md->pkt_mark & ~*get_mask(a, uint32_t));
581 break;
582
583 case OVS_KEY_ATTR_ETHERNET:
cf62fa4c 584 odp_eth_set_addrs(packet, nl_attr_get(a),
6d670e7f
JR
585 get_mask(a, struct ovs_key_ethernet));
586 break;
587
f59cb331 588 case OVS_KEY_ATTR_NSH: {
81fdabb9 589 odp_set_nsh(packet, a, true);
3d2fbd70 590 break;
f59cb331 591 }
3d2fbd70 592
6d670e7f 593 case OVS_KEY_ATTR_IPV4:
cf62fa4c 594 odp_set_ipv4(packet, nl_attr_get(a),
6d670e7f
JR
595 get_mask(a, struct ovs_key_ipv4));
596 break;
597
598 case OVS_KEY_ATTR_IPV6:
cf62fa4c 599 odp_set_ipv6(packet, nl_attr_get(a),
6d670e7f
JR
600 get_mask(a, struct ovs_key_ipv6));
601 break;
602
603 case OVS_KEY_ATTR_TCP:
cf62fa4c 604 odp_set_tcp(packet, nl_attr_get(a),
6d670e7f
JR
605 get_mask(a, struct ovs_key_tcp));
606 break;
607
608 case OVS_KEY_ATTR_UDP:
cf62fa4c 609 odp_set_udp(packet, nl_attr_get(a),
6d670e7f
JR
610 get_mask(a, struct ovs_key_udp));
611 break;
612
613 case OVS_KEY_ATTR_SCTP:
cf62fa4c 614 odp_set_sctp(packet, nl_attr_get(a),
6d670e7f
JR
615 get_mask(a, struct ovs_key_sctp));
616 break;
617
618 case OVS_KEY_ATTR_MPLS:
cf62fa4c 619 mh = dp_packet_l2_5(packet);
6d670e7f
JR
620 if (mh) {
621 put_16aligned_be32(&mh->mpls_lse, nl_attr_get_be32(a)
622 | (get_16aligned_be32(&mh->mpls_lse)
623 & ~*get_mask(a, ovs_be32)));
624 }
625 break;
626
627 case OVS_KEY_ATTR_ARP:
cf62fa4c 628 set_arp(packet, nl_attr_get(a),
6d670e7f
JR
629 get_mask(a, struct ovs_key_arp));
630 break;
631
e60e935b 632 case OVS_KEY_ATTR_ND:
cf62fa4c 633 odp_set_nd(packet, nl_attr_get(a),
e60e935b
SRCSA
634 get_mask(a, struct ovs_key_nd));
635 break;
636
9b2b8497
VDA
637 case OVS_KEY_ATTR_ND_EXTENSIONS:
638 odp_set_nd_ext(packet, nl_attr_get(a),
639 get_mask(a, struct ovs_key_nd_extensions));
640 break;
641
6d670e7f 642 case OVS_KEY_ATTR_DP_HASH:
f7c2f97d 643 md->dp_hash = nl_attr_get_u32(a)
2bc1bbd2 644 | (md->dp_hash & ~*get_mask(a, uint32_t));
6d670e7f
JR
645 break;
646
647 case OVS_KEY_ATTR_RECIRC_ID:
648 md->recirc_id = nl_attr_get_u32(a)
649 | (md->recirc_id & ~*get_mask(a, uint32_t));
650 break;
651
652 case OVS_KEY_ATTR_TUNNEL: /* Masked data not supported for tunnel. */
beb75a40 653 case OVS_KEY_ATTR_PACKET_TYPE:
6d670e7f 654 case OVS_KEY_ATTR_UNSPEC:
07659514
JS
655 case OVS_KEY_ATTR_CT_STATE:
656 case OVS_KEY_ATTR_CT_ZONE:
8e53fe8c 657 case OVS_KEY_ATTR_CT_MARK:
9daf2348 658 case OVS_KEY_ATTR_CT_LABELS:
c30b4cea
JR
659 case OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4:
660 case OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6:
6d670e7f
JR
661 case OVS_KEY_ATTR_ENCAP:
662 case OVS_KEY_ATTR_ETHERTYPE:
663 case OVS_KEY_ATTR_IN_PORT:
664 case OVS_KEY_ATTR_VLAN:
665 case OVS_KEY_ATTR_ICMP:
666 case OVS_KEY_ATTR_ICMPV6:
6d670e7f
JR
667 case OVS_KEY_ATTR_TCP_FLAGS:
668 case __OVS_KEY_ATTR_MAX:
669 default:
670 OVS_NOT_REACHED();
671 }
672}
673
f094af7b 674static void
e14deea0 675odp_execute_sample(void *dp, struct dp_packet *packet, bool steal,
41ccaa24 676 const struct nlattr *action,
1164afb6 677 odp_execute_cb dp_execute_action)
f094af7b
SH
678{
679 const struct nlattr *subactions = NULL;
680 const struct nlattr *a;
1895cc8d 681 struct dp_packet_batch pb;
f094af7b
SH
682 size_t left;
683
684 NL_NESTED_FOR_EACH_UNSAFE (a, left, action) {
685 int type = nl_attr_type(a);
686
687 switch ((enum ovs_sample_attr) type) {
688 case OVS_SAMPLE_ATTR_PROBABILITY:
689 if (random_uint32() >= nl_attr_get_u32(a)) {
1164afb6 690 if (steal) {
a13a0209 691 COVERAGE_INC(datapath_drop_sample_error);
e14deea0 692 dp_packet_delete(packet);
1164afb6 693 }
f094af7b
SH
694 return;
695 }
696 break;
697
698 case OVS_SAMPLE_ATTR_ACTIONS:
699 subactions = a;
700 break;
701
702 case OVS_SAMPLE_ATTR_UNSPEC:
703 case __OVS_SAMPLE_ATTR_MAX:
704 default:
428b2edd 705 OVS_NOT_REACHED();
f094af7b
SH
706 }
707 }
708
70a0573d
AZ
709 if (!steal) {
710 /* The 'subactions' may modify the packet, but the modification
711 * should not propagate beyond this sample action. Make a copy
712 * the packet in case we don't own the packet, so that the
713 * 'subactions' are only applid to the clone. 'odp_execute_actions'
714 * will free the clone. */
715 packet = dp_packet_clone(packet);
716 }
72c84bc2 717 dp_packet_batch_init_packet(&pb, packet);
70a0573d 718 odp_execute_actions(dp, &pb, true, nl_attr_get(subactions),
1164afb6 719 nl_attr_get_size(subactions), dp_execute_action);
f094af7b
SH
720}
721
535e3acf 722static void
911b7e9b 723odp_execute_clone(void *dp, struct dp_packet_batch *batch, bool steal,
535e3acf
AZ
724 const struct nlattr *actions,
725 odp_execute_cb dp_execute_action)
726{
535e3acf
AZ
727 if (!steal) {
728 /* The 'actions' may modify the packet, but the modification
729 * should not propagate beyond this clone action. Make a copy
730 * the packet in case we don't own the packet, so that the
731 * 'actions' are only applied to the clone. 'odp_execute_actions'
732 * will free the clone. */
911b7e9b
SC
733 struct dp_packet_batch clone_pkt_batch;
734 dp_packet_batch_clone(&clone_pkt_batch, batch);
735 dp_packet_batch_reset_cutlen(batch);
736 odp_execute_actions(dp, &clone_pkt_batch, true, nl_attr_get(actions),
535e3acf 737 nl_attr_get_size(actions), dp_execute_action);
911b7e9b
SC
738 }
739 else {
740 odp_execute_actions(dp, batch, true, nl_attr_get(actions),
741 nl_attr_get_size(actions), dp_execute_action);
742 }
535e3acf
AZ
743}
744
5b34f8fc
NS
745static void
746odp_execute_check_pkt_len(void *dp, struct dp_packet *packet, bool steal,
747 const struct nlattr *action,
748 odp_execute_cb dp_execute_action)
749{
750 static const struct nl_policy ovs_cpl_policy[] = {
751 [OVS_CHECK_PKT_LEN_ATTR_PKT_LEN] = { .type = NL_A_U16 },
752 [OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_GREATER] = { .type = NL_A_NESTED },
753 [OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_LESS_EQUAL]
754 = { .type = NL_A_NESTED },
755 };
756 struct nlattr *attrs[ARRAY_SIZE(ovs_cpl_policy)];
757
758 if (!nl_parse_nested(action, ovs_cpl_policy, attrs, ARRAY_SIZE(attrs))) {
759 OVS_NOT_REACHED();
760 }
761
762 const struct nlattr *a;
763 struct dp_packet_batch pb;
32697d4f
IM
764 uint32_t size = dp_packet_get_send_len(packet)
765 - dp_packet_l2_pad_size(packet);
5b34f8fc
NS
766
767 a = attrs[OVS_CHECK_PKT_LEN_ATTR_PKT_LEN];
32697d4f 768 if (size > nl_attr_get_u16(a)) {
5b34f8fc
NS
769 a = attrs[OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_GREATER];
770 } else {
771 a = attrs[OVS_CHECK_PKT_LEN_ATTR_ACTIONS_IF_LESS_EQUAL];
772 }
773
774 if (!steal) {
775 /* The 'subactions' may modify the packet, but the modification
776 * should not propagate beyond this action. Make a copy
777 * the packet in case we don't own the packet, so that the
778 * 'subactions' are only applid to check_pkt_len. 'odp_execute_actions'
779 * will free the clone. */
780 packet = dp_packet_clone(packet);
781 }
782 /* If nl_attr_get(a) is NULL, the packet will be freed by
783 * odp_execute_actions. */
784 dp_packet_batch_init_packet(&pb, packet);
785 odp_execute_actions(dp, &pb, true, nl_attr_get(a), nl_attr_get_size(a),
786 dp_execute_action);
787}
788
db8bb9a5
JS
789static bool
790requires_datapath_assistance(const struct nlattr *a)
791{
792 enum ovs_action_attr type = nl_attr_type(a);
793
794 switch (type) {
795 /* These only make sense in the context of a datapath. */
796 case OVS_ACTION_ATTR_OUTPUT:
9df65060 797 case OVS_ACTION_ATTR_LB_OUTPUT:
db8bb9a5
JS
798 case OVS_ACTION_ATTR_TUNNEL_PUSH:
799 case OVS_ACTION_ATTR_TUNNEL_POP:
800 case OVS_ACTION_ATTR_USERSPACE:
801 case OVS_ACTION_ATTR_RECIRC:
07659514 802 case OVS_ACTION_ATTR_CT:
5dddf960 803 case OVS_ACTION_ATTR_METER:
db8bb9a5
JS
804 return true;
805
806 case OVS_ACTION_ATTR_SET:
807 case OVS_ACTION_ATTR_SET_MASKED:
808 case OVS_ACTION_ATTR_PUSH_VLAN:
809 case OVS_ACTION_ATTR_POP_VLAN:
810 case OVS_ACTION_ATTR_SAMPLE:
811 case OVS_ACTION_ATTR_HASH:
812 case OVS_ACTION_ATTR_PUSH_MPLS:
813 case OVS_ACTION_ATTR_POP_MPLS:
aaca4fe0 814 case OVS_ACTION_ATTR_TRUNC:
6fcecb85
YY
815 case OVS_ACTION_ATTR_PUSH_ETH:
816 case OVS_ACTION_ATTR_POP_ETH:
535e3acf 817 case OVS_ACTION_ATTR_CLONE:
f59cb331
YY
818 case OVS_ACTION_ATTR_PUSH_NSH:
819 case OVS_ACTION_ATTR_POP_NSH:
1fe178d2 820 case OVS_ACTION_ATTR_CT_CLEAR:
5b34f8fc 821 case OVS_ACTION_ATTR_CHECK_PKT_LEN:
a13a0209 822 case OVS_ACTION_ATTR_DROP:
db8bb9a5
JS
823 return false;
824
825 case OVS_ACTION_ATTR_UNSPEC:
826 case __OVS_ACTION_ATTR_MAX:
827 OVS_NOT_REACHED();
828 }
829
830 return false;
831}
832
78b76327
BP
833/* Executes all of the 'actions_len' bytes of datapath actions in 'actions' on
834 * the packets in 'batch'. If 'steal' is true, possibly modifies and
835 * definitely free the packets in 'batch', otherwise leaves 'batch' unchanged.
836 *
837 * Some actions (e.g. output actions) can only be executed by a datapath. This
838 * function implements those actions by passing the action and the packets to
839 * 'dp_execute_action' (along with 'dp'). If 'dp_execute_action' is passed a
a8ab5889
DB
840 * true 'steal' parameter then it must definitely free the packets passed into
841 * it. The packet can be modified whether 'steal' is false or true. If a
842 * packet is removed from the batch, then the fate of the packet is determined
843 * by the code that does this removal, irrespective of the value of 'steal'.
844 * Otherwise, if the packet is not removed from the batch and 'steal' is false
845 * then the packet could either be cloned or not. */
1164afb6 846void
1895cc8d 847odp_execute_actions(void *dp, struct dp_packet_batch *batch, bool steal,
1164afb6
DDP
848 const struct nlattr *actions, size_t actions_len,
849 odp_execute_cb dp_execute_action)
f094af7b 850{
72c84bc2 851 struct dp_packet *packet;
f094af7b
SH
852 const struct nlattr *a;
853 unsigned int left;
8cbf4f47 854
f094af7b
SH
855 NL_ATTR_FOR_EACH_UNSAFE (a, left, actions, actions_len) {
856 int type = nl_attr_type(a);
1164afb6 857 bool last_action = (left <= NLA_ALIGN(a->nla_len));
f094af7b 858
db8bb9a5 859 if (requires_datapath_assistance(a)) {
09f9da0b
JR
860 if (dp_execute_action) {
861 /* Allow 'dp_execute_action' to steal the packet data if we do
862 * not need it any more. */
7d7ded7a 863 bool should_steal = steal && last_action;
1164afb6 864
7d7ded7a 865 dp_execute_action(dp, batch, a, should_steal);
1164afb6 866
1270b6e5 867 if (last_action || dp_packet_batch_is_empty(batch)) {
e5fd79c5
VDA
868 /* We do not need to free the packets.
869 * Either dp_execute_actions() has stolen them
870 * or the batch is freed due to errors. In either
871 * case we do not need to execute further actions.
872 */
1164afb6
DDP
873 return;
874 }
c51876c3 875 }
db8bb9a5
JS
876 continue;
877 }
f094af7b 878
db8bb9a5 879 switch ((enum ovs_action_attr) type) {
6a0b0d3b 880
c6bf49f3
AZ
881 case OVS_ACTION_ATTR_HASH: {
882 const struct ovs_action_hash *hash_act = nl_attr_get(a);
883
6a0b0d3b 884 /* Calculate a hash value directly. This might not match the
c6bf49f3
AZ
885 * value computed by the datapath, but it is much less expensive,
886 * and the current use case (bonding) does not require a strict
887 * match to work properly. */
6a0b0d3b
JS
888 switch (hash_act->hash_alg) {
889 case OVS_HASH_ALG_L4: {
c6bf49f3
AZ
890 struct flow flow;
891 uint32_t hash;
892
e883448e 893 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
95a6cb34
IM
894 /* RSS hash can be used here instead of 5tuple for
895 * performance reasons. */
896 if (dp_packet_rss_valid(packet)) {
897 hash = dp_packet_get_rss_hash(packet);
898 hash = hash_int(hash, hash_act->hash_basis);
899 } else {
900 flow_extract(packet, &flow);
901 hash = flow_hash_5tuple(&flow, hash_act->hash_basis);
902 }
72c84bc2 903 packet->md.dp_hash = hash;
8cbf4f47 904 }
6a0b0d3b
JS
905 break;
906 }
907 case OVS_HASH_ALG_SYM_L4: {
908 struct flow flow;
909 uint32_t hash;
910
911 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
912 flow_extract(packet, &flow);
913 hash = flow_hash_symmetric_l3l4(&flow,
914 hash_act->hash_basis,
915 false);
916 packet->md.dp_hash = hash;
917 }
918 break;
919 }
920 default:
c6bf49f3
AZ
921 /* Assert on unknown hash algorithm. */
922 OVS_NOT_REACHED();
923 }
924 break;
925 }
926
f094af7b
SH
927 case OVS_ACTION_ATTR_PUSH_VLAN: {
928 const struct ovs_action_push_vlan *vlan = nl_attr_get(a);
8cbf4f47 929
e883448e 930 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
72c84bc2 931 eth_push_vlan(packet, vlan->vlan_tpid, vlan->vlan_tci);
8cbf4f47 932 }
f094af7b
SH
933 break;
934 }
935
936 case OVS_ACTION_ATTR_POP_VLAN:
e883448e 937 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
72c84bc2 938 eth_pop_vlan(packet);
8cbf4f47 939 }
f094af7b
SH
940 break;
941
942 case OVS_ACTION_ATTR_PUSH_MPLS: {
943 const struct ovs_action_push_mpls *mpls = nl_attr_get(a);
8cbf4f47 944
e883448e 945 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
72c84bc2 946 push_mpls(packet, mpls->mpls_ethertype, mpls->mpls_lse);
8cbf4f47 947 }
f094af7b
SH
948 break;
949 }
950
951 case OVS_ACTION_ATTR_POP_MPLS:
e883448e 952 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
72c84bc2 953 pop_mpls(packet, nl_attr_get_be16(a));
8cbf4f47 954 }
f094af7b
SH
955 break;
956
957 case OVS_ACTION_ATTR_SET:
e883448e 958 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
72c84bc2 959 odp_execute_set_action(packet, nl_attr_get(a));
6d670e7f
JR
960 }
961 break;
962
963 case OVS_ACTION_ATTR_SET_MASKED:
e883448e 964 DP_PACKET_BATCH_FOR_EACH(i, packet, batch) {
72c84bc2 965 odp_execute_masked_set_action(packet, nl_attr_get(a));
8cbf4f47 966 }
f094af7b
SH
967 break;
968
969 case OVS_ACTION_ATTR_SAMPLE:
e883448e 970 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
72c84bc2 971 odp_execute_sample(dp, packet, steal && last_action, a,
1164afb6
DDP
972 dp_execute_action);
973 }
974
975 if (last_action) {
976 /* We do not need to free the packets. odp_execute_sample() has
977 * stolen them*/
978 return;
8cbf4f47 979 }
f094af7b
SH
980 break;
981
aaca4fe0
WT
982 case OVS_ACTION_ATTR_TRUNC: {
983 const struct ovs_action_trunc *trunc =
984 nl_attr_get_unspec(a, sizeof *trunc);
985
986 batch->trunc = true;
e883448e 987 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
72c84bc2 988 dp_packet_set_cutlen(packet, trunc->max_len);
aaca4fe0
WT
989 }
990 break;
991 }
992
535e3acf 993 case OVS_ACTION_ATTR_CLONE:
911b7e9b
SC
994 odp_execute_clone(dp, batch, steal && last_action, a,
995 dp_execute_action);
535e3acf
AZ
996 if (last_action) {
997 /* We do not need to free the packets. odp_execute_clone() has
998 * stolen them. */
999 return;
1000 }
760ba862 1001 break;
5dddf960
JR
1002 case OVS_ACTION_ATTR_METER:
1003 /* Not implemented yet. */
535e3acf 1004 break;
88fc5281
JS
1005 case OVS_ACTION_ATTR_PUSH_ETH: {
1006 const struct ovs_action_push_eth *eth = nl_attr_get(a);
1007
e883448e 1008 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
88fc5281
JS
1009 push_eth(packet, &eth->addresses.eth_dst,
1010 &eth->addresses.eth_src);
1011 }
1012 break;
1013 }
1014
1015 case OVS_ACTION_ATTR_POP_ETH:
e883448e 1016 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
88fc5281
JS
1017 pop_eth(packet);
1018 }
1019 break;
535e3acf 1020
f59cb331
YY
1021 case OVS_ACTION_ATTR_PUSH_NSH: {
1022 uint32_t buffer[NSH_HDR_MAX_LEN / 4];
1023 struct nsh_hdr *nsh_hdr = ALIGNED_CAST(struct nsh_hdr *, buffer);
1024 nsh_reset_ver_flags_ttl_len(nsh_hdr);
1025 odp_nsh_hdr_from_attr(nl_attr_get(a), nsh_hdr, NSH_HDR_MAX_LEN);
e883448e 1026 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
f59cb331 1027 push_nsh(packet, nsh_hdr);
1fc11c59
JS
1028 }
1029 break;
1030 }
f59cb331 1031 case OVS_ACTION_ATTR_POP_NSH: {
95e620b4
BB
1032 size_t i;
1033 const size_t num = dp_packet_batch_size(batch);
1fc11c59
JS
1034
1035 DP_PACKET_BATCH_REFILL_FOR_EACH (i, num, packet, batch) {
f59cb331 1036 if (pop_nsh(packet)) {
1fc11c59
JS
1037 dp_packet_batch_refill(batch, packet, i);
1038 } else {
a13a0209 1039 COVERAGE_INC(datapath_drop_nsh_decap_error);
1fc11c59
JS
1040 dp_packet_delete(packet);
1041 }
1042 }
1043 break;
1044 }
1fe178d2 1045 case OVS_ACTION_ATTR_CT_CLEAR:
e883448e 1046 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
1fe178d2
EG
1047 conntrack_clear(packet);
1048 }
1049 break;
1fc11c59 1050
5b34f8fc
NS
1051 case OVS_ACTION_ATTR_CHECK_PKT_LEN:
1052 DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
1053 odp_execute_check_pkt_len(dp, packet, steal && last_action, a,
1054 dp_execute_action);
1055 }
1056
1057 if (last_action) {
1058 /* We do not need to free the packets.
1059 * odp_execute_check_pkt_len() has stolen them. */
1060 return;
1061 }
1062 break;
1063
a13a0209
AT
1064 case OVS_ACTION_ATTR_DROP:{
1065 const enum xlate_error *drop_reason = nl_attr_get(a);
1066
1067 dp_update_drop_action_counter(*drop_reason,
1068 dp_packet_batch_size(batch));
1069 dp_packet_delete_batch(batch, steal);
1070 return;
1071 }
db8bb9a5 1072 case OVS_ACTION_ATTR_OUTPUT:
9df65060 1073 case OVS_ACTION_ATTR_LB_OUTPUT:
db8bb9a5
JS
1074 case OVS_ACTION_ATTR_TUNNEL_PUSH:
1075 case OVS_ACTION_ATTR_TUNNEL_POP:
1076 case OVS_ACTION_ATTR_USERSPACE:
1077 case OVS_ACTION_ATTR_RECIRC:
07659514 1078 case OVS_ACTION_ATTR_CT:
f094af7b
SH
1079 case OVS_ACTION_ATTR_UNSPEC:
1080 case __OVS_ACTION_ATTR_MAX:
428b2edd 1081 OVS_NOT_REACHED();
f094af7b
SH
1082 }
1083 }
8cbf4f47 1084
72c84bc2 1085 dp_packet_delete_batch(batch, steal);
da546e07 1086}