2 * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <arpa/inet.h>
23 #include <netinet/in.h>
24 #include <netinet/icmp6.h>
27 #include "byte-order.h"
29 #include "dynamic-string.h"
39 VLOG_DEFINE_THIS_MODULE(odp_util
);
41 /* The interface between userspace and kernel uses an "OVS_*" prefix.
42 * Since this is fairly non-specific for the OVS userspace components,
43 * "ODP_*" (Open vSwitch Datapath) is used as the prefix for
44 * interactions with the datapath.
47 /* The set of characters that may separate one action or one key attribute
49 static const char *delimiters
= ", \t\r\n";
51 static int parse_odp_key_attr(const char *, const struct simap
*port_names
,
53 static void format_odp_key_attr(const struct nlattr
*a
, struct ds
*ds
);
55 /* Returns one the following for the action with the given OVS_ACTION_ATTR_*
58 * - For an action whose argument has a fixed length, returned that
59 * nonnegative length in bytes.
61 * - For an action with a variable-length argument, returns -2.
63 * - For an invalid 'type', returns -1. */
65 odp_action_len(uint16_t type
)
67 if (type
> OVS_ACTION_ATTR_MAX
) {
71 switch ((enum ovs_action_attr
) type
) {
72 case OVS_ACTION_ATTR_OUTPUT
: return sizeof(uint32_t);
73 case OVS_ACTION_ATTR_USERSPACE
: return -2;
74 case OVS_ACTION_ATTR_PUSH_VLAN
: return sizeof(struct ovs_action_push_vlan
);
75 case OVS_ACTION_ATTR_POP_VLAN
: return 0;
76 case OVS_ACTION_ATTR_PUSH_MPLS
: return sizeof(struct ovs_action_push_mpls
);
77 case OVS_ACTION_ATTR_POP_MPLS
: return sizeof(ovs_be16
);
78 case OVS_ACTION_ATTR_SET
: return -2;
79 case OVS_ACTION_ATTR_SAMPLE
: return -2;
81 case OVS_ACTION_ATTR_UNSPEC
:
82 case __OVS_ACTION_ATTR_MAX
:
89 /* Returns a string form of 'attr'. The return value is either a statically
90 * allocated constant string or the 'bufsize'-byte buffer 'namebuf'. 'bufsize'
91 * should be at least OVS_KEY_ATTR_BUFSIZE. */
92 enum { OVS_KEY_ATTR_BUFSIZE
= 3 + INT_STRLEN(unsigned int) + 1 };
94 ovs_key_attr_to_string(enum ovs_key_attr attr
, char *namebuf
, size_t bufsize
)
97 case OVS_KEY_ATTR_UNSPEC
: return "unspec";
98 case OVS_KEY_ATTR_ENCAP
: return "encap";
99 case OVS_KEY_ATTR_PRIORITY
: return "skb_priority";
100 case OVS_KEY_ATTR_SKB_MARK
: return "skb_mark";
101 case OVS_KEY_ATTR_TUNNEL
: return "tunnel";
102 case OVS_KEY_ATTR_IN_PORT
: return "in_port";
103 case OVS_KEY_ATTR_ETHERNET
: return "eth";
104 case OVS_KEY_ATTR_VLAN
: return "vlan";
105 case OVS_KEY_ATTR_ETHERTYPE
: return "eth_type";
106 case OVS_KEY_ATTR_IPV4
: return "ipv4";
107 case OVS_KEY_ATTR_IPV6
: return "ipv6";
108 case OVS_KEY_ATTR_TCP
: return "tcp";
109 case OVS_KEY_ATTR_UDP
: return "udp";
110 case OVS_KEY_ATTR_ICMP
: return "icmp";
111 case OVS_KEY_ATTR_ICMPV6
: return "icmpv6";
112 case OVS_KEY_ATTR_ARP
: return "arp";
113 case OVS_KEY_ATTR_ND
: return "nd";
114 case OVS_KEY_ATTR_MPLS
: return "mpls";
116 case __OVS_KEY_ATTR_MAX
:
118 snprintf(namebuf
, bufsize
, "key%u", (unsigned int) attr
);
124 format_generic_odp_action(struct ds
*ds
, const struct nlattr
*a
)
126 size_t len
= nl_attr_get_size(a
);
128 ds_put_format(ds
, "action%"PRId16
, nl_attr_type(a
));
130 const uint8_t *unspec
;
133 unspec
= nl_attr_get(a
);
134 for (i
= 0; i
< len
; i
++) {
135 ds_put_char(ds
, i
? ' ': '(');
136 ds_put_format(ds
, "%02x", unspec
[i
]);
138 ds_put_char(ds
, ')');
143 format_odp_sample_action(struct ds
*ds
, const struct nlattr
*attr
)
145 static const struct nl_policy ovs_sample_policy
[] = {
146 [OVS_SAMPLE_ATTR_PROBABILITY
] = { .type
= NL_A_U32
},
147 [OVS_SAMPLE_ATTR_ACTIONS
] = { .type
= NL_A_NESTED
}
149 struct nlattr
*a
[ARRAY_SIZE(ovs_sample_policy
)];
151 const struct nlattr
*nla_acts
;
154 ds_put_cstr(ds
, "sample");
156 if (!nl_parse_nested(attr
, ovs_sample_policy
, a
, ARRAY_SIZE(a
))) {
157 ds_put_cstr(ds
, "(error)");
161 percentage
= (100.0 * nl_attr_get_u32(a
[OVS_SAMPLE_ATTR_PROBABILITY
])) /
164 ds_put_format(ds
, "(sample=%.1f%%,", percentage
);
166 ds_put_cstr(ds
, "actions(");
167 nla_acts
= nl_attr_get(a
[OVS_SAMPLE_ATTR_ACTIONS
]);
168 len
= nl_attr_get_size(a
[OVS_SAMPLE_ATTR_ACTIONS
]);
169 format_odp_actions(ds
, nla_acts
, len
);
170 ds_put_format(ds
, "))");
174 slow_path_reason_to_string(enum slow_path_reason reason
)
185 case SLOW_CONTROLLER
:
193 static enum slow_path_reason
194 string_to_slow_path_reason(const char *string
)
196 enum slow_path_reason i
;
198 for (i
= 1; i
< __SLOW_MAX
; i
++) {
199 if (!strcmp(string
, slow_path_reason_to_string(i
))) {
208 parse_flags(const char *s
, const char *(*bit_to_string
)(uint32_t),
219 while (s
[n
] != ')') {
220 unsigned long long int flags
;
224 if (sscanf(&s
[n
], "%lli%n", &flags
, &n0
) > 0 && n0
> 0) {
225 n
+= n0
+ (s
[n
+ n0
] == ',');
230 for (bit
= 1; bit
; bit
<<= 1) {
231 const char *name
= bit_to_string(bit
);
239 if (!strncmp(s
+ n
, name
, len
) &&
240 (s
[n
+ len
] == ',' || s
[n
+ len
] == ')')) {
242 n
+= len
+ (s
[n
+ len
] == ',');
258 format_odp_userspace_action(struct ds
*ds
, const struct nlattr
*attr
)
260 static const struct nl_policy ovs_userspace_policy
[] = {
261 [OVS_USERSPACE_ATTR_PID
] = { .type
= NL_A_U32
},
262 [OVS_USERSPACE_ATTR_USERDATA
] = { .type
= NL_A_UNSPEC
,
265 struct nlattr
*a
[ARRAY_SIZE(ovs_userspace_policy
)];
266 const struct nlattr
*userdata_attr
;
268 if (!nl_parse_nested(attr
, ovs_userspace_policy
, a
, ARRAY_SIZE(a
))) {
269 ds_put_cstr(ds
, "userspace(error)");
273 ds_put_format(ds
, "userspace(pid=%"PRIu32
,
274 nl_attr_get_u32(a
[OVS_USERSPACE_ATTR_PID
]));
276 userdata_attr
= a
[OVS_USERSPACE_ATTR_USERDATA
];
279 const uint8_t *userdata
= nl_attr_get(userdata_attr
);
280 size_t userdata_len
= nl_attr_get_size(userdata_attr
);
281 bool userdata_unspec
= true;
282 union user_action_cookie cookie
;
284 if (userdata_len
>= sizeof cookie
.type
285 && userdata_len
<= sizeof cookie
) {
287 memset(&cookie
, 0, sizeof cookie
);
288 memcpy(&cookie
, userdata
, userdata_len
);
290 userdata_unspec
= false;
292 if (userdata_len
== sizeof cookie
.sflow
293 && cookie
.type
== USER_ACTION_COOKIE_SFLOW
) {
294 ds_put_format(ds
, ",sFlow("
295 "vid=%"PRIu16
",pcp=%"PRIu8
",output=%"PRIu32
")",
296 vlan_tci_to_vid(cookie
.sflow
.vlan_tci
),
297 vlan_tci_to_pcp(cookie
.sflow
.vlan_tci
),
298 cookie
.sflow
.output
);
299 } else if (userdata_len
== sizeof cookie
.slow_path
300 && cookie
.type
== USER_ACTION_COOKIE_SLOW_PATH
) {
302 reason
= slow_path_reason_to_string(cookie
.slow_path
.reason
);
303 reason
= reason
? reason
: "";
304 ds_put_format(ds
, ",slow_path(%s)", reason
);
305 } else if (userdata_len
== sizeof cookie
.flow_sample
306 && cookie
.type
== USER_ACTION_COOKIE_FLOW_SAMPLE
) {
307 ds_put_format(ds
, ",flow_sample(probability=%"PRIu16
308 ",collector_set_id=%"PRIu32
309 ",obs_domain_id=%"PRIu32
310 ",obs_point_id=%"PRIu32
")",
311 cookie
.flow_sample
.probability
,
312 cookie
.flow_sample
.collector_set_id
,
313 cookie
.flow_sample
.obs_domain_id
,
314 cookie
.flow_sample
.obs_point_id
);
315 } else if (userdata_len
== sizeof cookie
.ipfix
316 && cookie
.type
== USER_ACTION_COOKIE_IPFIX
) {
317 ds_put_format(ds
, ",ipfix");
319 userdata_unspec
= true;
323 if (userdata_unspec
) {
325 ds_put_format(ds
, ",userdata(");
326 for (i
= 0; i
< userdata_len
; i
++) {
327 ds_put_format(ds
, "%02x", userdata
[i
]);
329 ds_put_char(ds
, ')');
333 ds_put_char(ds
, ')');
337 format_vlan_tci(struct ds
*ds
, ovs_be16 vlan_tci
)
339 ds_put_format(ds
, "vid=%"PRIu16
",pcp=%d",
340 vlan_tci_to_vid(vlan_tci
),
341 vlan_tci_to_pcp(vlan_tci
));
342 if (!(vlan_tci
& htons(VLAN_CFI
))) {
343 ds_put_cstr(ds
, ",cfi=0");
348 format_mpls_lse(struct ds
*ds
, ovs_be32 mpls_lse
)
350 ds_put_format(ds
, "label=%"PRIu32
",tc=%d,ttl=%d,bos=%d",
351 mpls_lse_to_label(mpls_lse
),
352 mpls_lse_to_tc(mpls_lse
),
353 mpls_lse_to_ttl(mpls_lse
),
354 mpls_lse_to_bos(mpls_lse
));
358 format_odp_action(struct ds
*ds
, const struct nlattr
*a
)
361 enum ovs_action_attr type
= nl_attr_type(a
);
362 const struct ovs_action_push_vlan
*vlan
;
364 expected_len
= odp_action_len(nl_attr_type(a
));
365 if (expected_len
!= -2 && nl_attr_get_size(a
) != expected_len
) {
366 ds_put_format(ds
, "bad length %zu, expected %d for: ",
367 nl_attr_get_size(a
), expected_len
);
368 format_generic_odp_action(ds
, a
);
373 case OVS_ACTION_ATTR_OUTPUT
:
374 ds_put_format(ds
, "%"PRIu32
, nl_attr_get_u32(a
));
376 case OVS_ACTION_ATTR_USERSPACE
:
377 format_odp_userspace_action(ds
, a
);
379 case OVS_ACTION_ATTR_SET
:
380 ds_put_cstr(ds
, "set(");
381 format_odp_key_attr(nl_attr_get(a
), ds
);
382 ds_put_cstr(ds
, ")");
384 case OVS_ACTION_ATTR_PUSH_VLAN
:
385 vlan
= nl_attr_get(a
);
386 ds_put_cstr(ds
, "push_vlan(");
387 if (vlan
->vlan_tpid
!= htons(ETH_TYPE_VLAN
)) {
388 ds_put_format(ds
, "tpid=0x%04"PRIx16
",", ntohs(vlan
->vlan_tpid
));
390 format_vlan_tci(ds
, vlan
->vlan_tci
);
391 ds_put_char(ds
, ')');
393 case OVS_ACTION_ATTR_POP_VLAN
:
394 ds_put_cstr(ds
, "pop_vlan");
396 case OVS_ACTION_ATTR_PUSH_MPLS
: {
397 const struct ovs_action_push_mpls
*mpls
= nl_attr_get(a
);
398 ds_put_cstr(ds
, "push_mpls(");
399 format_mpls_lse(ds
, mpls
->mpls_lse
);
400 ds_put_format(ds
, ",eth_type=0x%"PRIx16
")", ntohs(mpls
->mpls_ethertype
));
403 case OVS_ACTION_ATTR_POP_MPLS
: {
404 ovs_be16 ethertype
= nl_attr_get_be16(a
);
405 ds_put_format(ds
, "pop_mpls(eth_type=0x%"PRIx16
")", ntohs(ethertype
));
408 case OVS_ACTION_ATTR_SAMPLE
:
409 format_odp_sample_action(ds
, a
);
411 case OVS_ACTION_ATTR_UNSPEC
:
412 case __OVS_ACTION_ATTR_MAX
:
414 format_generic_odp_action(ds
, a
);
420 format_odp_actions(struct ds
*ds
, const struct nlattr
*actions
,
424 const struct nlattr
*a
;
427 NL_ATTR_FOR_EACH (a
, left
, actions
, actions_len
) {
429 ds_put_char(ds
, ',');
431 format_odp_action(ds
, a
);
436 if (left
== actions_len
) {
437 ds_put_cstr(ds
, "<empty>");
439 ds_put_format(ds
, ",***%u leftover bytes*** (", left
);
440 for (i
= 0; i
< left
; i
++) {
441 ds_put_format(ds
, "%02x", ((const uint8_t *) a
)[i
]);
443 ds_put_char(ds
, ')');
446 ds_put_cstr(ds
, "drop");
451 parse_odp_action(const char *s
, const struct simap
*port_names
,
452 struct ofpbuf
*actions
)
454 /* Many of the sscanf calls in this function use oversized destination
455 * fields because some sscanf() implementations truncate the range of %i
456 * directives, so that e.g. "%"SCNi16 interprets input of "0xfedc" as a
457 * value of 0x7fff. The other alternatives are to allow only a single
458 * radix (e.g. decimal or hexadecimal) or to write more sophisticated
461 * The tun_id parser has to use an alternative approach because there is no
462 * type larger than 64 bits. */
465 unsigned long long int port
;
468 if (sscanf(s
, "%lli%n", &port
, &n
) > 0 && n
> 0) {
469 nl_msg_put_u32(actions
, OVS_ACTION_ATTR_OUTPUT
, port
);
475 int len
= strcspn(s
, delimiters
);
476 struct simap_node
*node
;
478 node
= simap_find_len(port_names
, s
, len
);
480 nl_msg_put_u32(actions
, OVS_ACTION_ATTR_OUTPUT
, node
->data
);
486 unsigned long long int pid
;
487 unsigned long long int output
;
488 unsigned long long int probability
;
489 unsigned long long int collector_set_id
;
490 unsigned long long int obs_domain_id
;
491 unsigned long long int obs_point_id
;
495 if (sscanf(s
, "userspace(pid=%lli)%n", &pid
, &n
) > 0 && n
> 0) {
496 odp_put_userspace_action(pid
, NULL
, 0, actions
);
498 } else if (sscanf(s
, "userspace(pid=%lli,sFlow(vid=%i,"
499 "pcp=%i,output=%lli))%n",
500 &pid
, &vid
, &pcp
, &output
, &n
) > 0 && n
> 0) {
501 union user_action_cookie cookie
;
504 tci
= vid
| (pcp
<< VLAN_PCP_SHIFT
);
509 cookie
.type
= USER_ACTION_COOKIE_SFLOW
;
510 cookie
.sflow
.vlan_tci
= htons(tci
);
511 cookie
.sflow
.output
= output
;
512 odp_put_userspace_action(pid
, &cookie
, sizeof cookie
.sflow
,
515 } else if (sscanf(s
, "userspace(pid=%lli,slow_path(%n", &pid
, &n
) > 0
517 union user_action_cookie cookie
;
520 if (s
[n
] == ')' && s
[n
+ 1] == ')') {
523 } else if (sscanf(s
+ n
, "%31[^)]))", reason
) > 0) {
524 n
+= strlen(reason
) + 2;
529 cookie
.type
= USER_ACTION_COOKIE_SLOW_PATH
;
530 cookie
.slow_path
.unused
= 0;
531 cookie
.slow_path
.reason
= string_to_slow_path_reason(reason
);
533 if (reason
[0] && !cookie
.slow_path
.reason
) {
537 odp_put_userspace_action(pid
, &cookie
, sizeof cookie
.slow_path
,
540 } else if (sscanf(s
, "userspace(pid=%lli,flow_sample(probability=%lli,"
541 "collector_set_id=%lli,obs_domain_id=%lli,"
542 "obs_point_id=%lli))%n",
543 &pid
, &probability
, &collector_set_id
,
544 &obs_domain_id
, &obs_point_id
, &n
) > 0 && n
> 0) {
545 union user_action_cookie cookie
;
547 cookie
.type
= USER_ACTION_COOKIE_FLOW_SAMPLE
;
548 cookie
.flow_sample
.probability
= probability
;
549 cookie
.flow_sample
.collector_set_id
= collector_set_id
;
550 cookie
.flow_sample
.obs_domain_id
= obs_domain_id
;
551 cookie
.flow_sample
.obs_point_id
= obs_point_id
;
552 odp_put_userspace_action(pid
, &cookie
, sizeof cookie
.flow_sample
,
555 } else if (sscanf(s
, "userspace(pid=%lli,ipfix)%n", &pid
, &n
) > 0
557 union user_action_cookie cookie
;
559 cookie
.type
= USER_ACTION_COOKIE_IPFIX
;
560 odp_put_userspace_action(pid
, &cookie
, sizeof cookie
.ipfix
,
563 } else if (sscanf(s
, "userspace(pid=%lli,userdata(%n", &pid
, &n
) > 0
568 ofpbuf_init(&buf
, 16);
569 end
= ofpbuf_put_hex(&buf
, &s
[n
], NULL
);
570 if (end
[0] == ')' && end
[1] == ')') {
571 odp_put_userspace_action(pid
, buf
.data
, buf
.size
, actions
);
573 return (end
+ 2) - s
;
578 if (!strncmp(s
, "set(", 4)) {
582 start_ofs
= nl_msg_start_nested(actions
, OVS_ACTION_ATTR_SET
);
583 retval
= parse_odp_key_attr(s
+ 4, port_names
, actions
);
587 if (s
[retval
+ 4] != ')') {
590 nl_msg_end_nested(actions
, start_ofs
);
595 struct ovs_action_push_vlan push
;
596 int tpid
= ETH_TYPE_VLAN
;
601 if ((sscanf(s
, "push_vlan(vid=%i,pcp=%i)%n", &vid
, &pcp
, &n
) > 0
603 || (sscanf(s
, "push_vlan(vid=%i,pcp=%i,cfi=%i)%n",
604 &vid
, &pcp
, &cfi
, &n
) > 0 && n
> 0)
605 || (sscanf(s
, "push_vlan(tpid=%i,vid=%i,pcp=%i)%n",
606 &tpid
, &vid
, &pcp
, &n
) > 0 && n
> 0)
607 || (sscanf(s
, "push_vlan(tpid=%i,vid=%i,pcp=%i,cfi=%i)%n",
608 &tpid
, &vid
, &pcp
, &cfi
, &n
) > 0 && n
> 0)) {
609 push
.vlan_tpid
= htons(tpid
);
610 push
.vlan_tci
= htons((vid
<< VLAN_VID_SHIFT
)
611 | (pcp
<< VLAN_PCP_SHIFT
)
612 | (cfi
? VLAN_CFI
: 0));
613 nl_msg_put_unspec(actions
, OVS_ACTION_ATTR_PUSH_VLAN
,
620 if (!strncmp(s
, "pop_vlan", 8)) {
621 nl_msg_put_flag(actions
, OVS_ACTION_ATTR_POP_VLAN
);
629 if (sscanf(s
, "sample(sample=%lf%%,actions(%n", &percentage
, &n
) > 0
630 && percentage
>= 0. && percentage
<= 100.0
632 size_t sample_ofs
, actions_ofs
;
635 probability
= floor(UINT32_MAX
* (percentage
/ 100.0) + .5);
636 sample_ofs
= nl_msg_start_nested(actions
, OVS_ACTION_ATTR_SAMPLE
);
637 nl_msg_put_u32(actions
, OVS_SAMPLE_ATTR_PROBABILITY
,
638 (probability
<= 0 ? 0
639 : probability
>= UINT32_MAX
? UINT32_MAX
642 actions_ofs
= nl_msg_start_nested(actions
,
643 OVS_SAMPLE_ATTR_ACTIONS
);
647 n
+= strspn(s
+ n
, delimiters
);
652 retval
= parse_odp_action(s
+ n
, port_names
, actions
);
658 nl_msg_end_nested(actions
, actions_ofs
);
659 nl_msg_end_nested(actions
, sample_ofs
);
661 return s
[n
+ 1] == ')' ? n
+ 2 : -EINVAL
;
668 /* Parses the string representation of datapath actions, in the format output
669 * by format_odp_action(). Returns 0 if successful, otherwise a positive errno
670 * value. On success, the ODP actions are appended to 'actions' as a series of
671 * Netlink attributes. On failure, no data is appended to 'actions'. Either
672 * way, 'actions''s data might be reallocated. */
674 odp_actions_from_string(const char *s
, const struct simap
*port_names
,
675 struct ofpbuf
*actions
)
679 if (!strcasecmp(s
, "drop")) {
683 old_size
= actions
->size
;
687 s
+= strspn(s
, delimiters
);
692 retval
= parse_odp_action(s
, port_names
, actions
);
693 if (retval
< 0 || !strchr(delimiters
, s
[retval
])) {
694 actions
->size
= old_size
;
703 /* Returns the correct length of the payload for a flow key attribute of the
704 * specified 'type', -1 if 'type' is unknown, or -2 if the attribute's payload
705 * is variable length. */
707 odp_flow_key_attr_len(uint16_t type
)
709 if (type
> OVS_KEY_ATTR_MAX
) {
713 switch ((enum ovs_key_attr
) type
) {
714 case OVS_KEY_ATTR_ENCAP
: return -2;
715 case OVS_KEY_ATTR_PRIORITY
: return 4;
716 case OVS_KEY_ATTR_SKB_MARK
: return 4;
717 case OVS_KEY_ATTR_TUNNEL
: return -2;
718 case OVS_KEY_ATTR_IN_PORT
: return 4;
719 case OVS_KEY_ATTR_ETHERNET
: return sizeof(struct ovs_key_ethernet
);
720 case OVS_KEY_ATTR_VLAN
: return sizeof(ovs_be16
);
721 case OVS_KEY_ATTR_ETHERTYPE
: return 2;
722 case OVS_KEY_ATTR_MPLS
: return sizeof(struct ovs_key_mpls
);
723 case OVS_KEY_ATTR_IPV4
: return sizeof(struct ovs_key_ipv4
);
724 case OVS_KEY_ATTR_IPV6
: return sizeof(struct ovs_key_ipv6
);
725 case OVS_KEY_ATTR_TCP
: return sizeof(struct ovs_key_tcp
);
726 case OVS_KEY_ATTR_UDP
: return sizeof(struct ovs_key_udp
);
727 case OVS_KEY_ATTR_ICMP
: return sizeof(struct ovs_key_icmp
);
728 case OVS_KEY_ATTR_ICMPV6
: return sizeof(struct ovs_key_icmpv6
);
729 case OVS_KEY_ATTR_ARP
: return sizeof(struct ovs_key_arp
);
730 case OVS_KEY_ATTR_ND
: return sizeof(struct ovs_key_nd
);
732 case OVS_KEY_ATTR_UNSPEC
:
733 case __OVS_KEY_ATTR_MAX
:
741 format_generic_odp_key(const struct nlattr
*a
, struct ds
*ds
)
743 size_t len
= nl_attr_get_size(a
);
745 const uint8_t *unspec
;
748 unspec
= nl_attr_get(a
);
749 for (i
= 0; i
< len
; i
++) {
750 ds_put_char(ds
, i
? ' ': '(');
751 ds_put_format(ds
, "%02x", unspec
[i
]);
753 ds_put_char(ds
, ')');
758 ovs_frag_type_to_string(enum ovs_frag_type type
)
761 case OVS_FRAG_TYPE_NONE
:
763 case OVS_FRAG_TYPE_FIRST
:
765 case OVS_FRAG_TYPE_LATER
:
767 case __OVS_FRAG_TYPE_MAX
:
774 tunnel_key_attr_len(int type
)
777 case OVS_TUNNEL_KEY_ATTR_ID
: return 8;
778 case OVS_TUNNEL_KEY_ATTR_IPV4_SRC
: return 4;
779 case OVS_TUNNEL_KEY_ATTR_IPV4_DST
: return 4;
780 case OVS_TUNNEL_KEY_ATTR_TOS
: return 1;
781 case OVS_TUNNEL_KEY_ATTR_TTL
: return 1;
782 case OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT
: return 0;
783 case OVS_TUNNEL_KEY_ATTR_CSUM
: return 0;
784 case __OVS_TUNNEL_KEY_ATTR_MAX
:
791 odp_tun_key_from_attr(const struct nlattr
*attr
, struct flow_tnl
*tun
)
794 const struct nlattr
*a
;
796 bool unknown
= false;
798 NL_NESTED_FOR_EACH(a
, left
, attr
) {
799 uint16_t type
= nl_attr_type(a
);
800 size_t len
= nl_attr_get_size(a
);
801 int expected_len
= tunnel_key_attr_len(type
);
803 if (len
!= expected_len
&& expected_len
>= 0) {
804 return ODP_FIT_ERROR
;
808 case OVS_TUNNEL_KEY_ATTR_ID
:
809 tun
->tun_id
= nl_attr_get_be64(a
);
810 tun
->flags
|= FLOW_TNL_F_KEY
;
812 case OVS_TUNNEL_KEY_ATTR_IPV4_SRC
:
813 tun
->ip_src
= nl_attr_get_be32(a
);
815 case OVS_TUNNEL_KEY_ATTR_IPV4_DST
:
816 tun
->ip_dst
= nl_attr_get_be32(a
);
818 case OVS_TUNNEL_KEY_ATTR_TOS
:
819 tun
->ip_tos
= nl_attr_get_u8(a
);
821 case OVS_TUNNEL_KEY_ATTR_TTL
:
822 tun
->ip_ttl
= nl_attr_get_u8(a
);
825 case OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT
:
826 tun
->flags
|= FLOW_TNL_F_DONT_FRAGMENT
;
828 case OVS_TUNNEL_KEY_ATTR_CSUM
:
829 tun
->flags
|= FLOW_TNL_F_CSUM
;
832 /* Allow this to show up as unexpected, if there are unknown
833 * tunnel attribute, eventually resulting in ODP_FIT_TOO_MUCH. */
840 return ODP_FIT_ERROR
;
843 return ODP_FIT_TOO_MUCH
;
845 return ODP_FIT_PERFECT
;
849 tun_key_to_attr(struct ofpbuf
*a
, const struct flow_tnl
*tun_key
)
853 tun_key_ofs
= nl_msg_start_nested(a
, OVS_KEY_ATTR_TUNNEL
);
855 if (tun_key
->flags
& FLOW_TNL_F_KEY
) {
856 nl_msg_put_be64(a
, OVS_TUNNEL_KEY_ATTR_ID
, tun_key
->tun_id
);
858 if (tun_key
->ip_src
) {
859 nl_msg_put_be32(a
, OVS_TUNNEL_KEY_ATTR_IPV4_SRC
, tun_key
->ip_src
);
861 if (tun_key
->ip_dst
) {
862 nl_msg_put_be32(a
, OVS_TUNNEL_KEY_ATTR_IPV4_DST
, tun_key
->ip_dst
);
864 if (tun_key
->ip_tos
) {
865 nl_msg_put_u8(a
, OVS_TUNNEL_KEY_ATTR_TOS
, tun_key
->ip_tos
);
867 nl_msg_put_u8(a
, OVS_TUNNEL_KEY_ATTR_TTL
, tun_key
->ip_ttl
);
868 if (tun_key
->flags
& FLOW_TNL_F_DONT_FRAGMENT
) {
869 nl_msg_put_flag(a
, OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT
);
871 if (tun_key
->flags
& FLOW_TNL_F_CSUM
) {
872 nl_msg_put_flag(a
, OVS_TUNNEL_KEY_ATTR_CSUM
);
875 nl_msg_end_nested(a
, tun_key_ofs
);
879 format_odp_key_attr(const struct nlattr
*a
, struct ds
*ds
)
881 const struct ovs_key_ethernet
*eth_key
;
882 const struct ovs_key_ipv4
*ipv4_key
;
883 const struct ovs_key_ipv6
*ipv6_key
;
884 const struct ovs_key_tcp
*tcp_key
;
885 const struct ovs_key_udp
*udp_key
;
886 const struct ovs_key_icmp
*icmp_key
;
887 const struct ovs_key_icmpv6
*icmpv6_key
;
888 const struct ovs_key_arp
*arp_key
;
889 const struct ovs_key_nd
*nd_key
;
890 struct flow_tnl tun_key
;
891 enum ovs_key_attr attr
= nl_attr_type(a
);
892 char namebuf
[OVS_KEY_ATTR_BUFSIZE
];
895 ds_put_cstr(ds
, ovs_key_attr_to_string(attr
, namebuf
, sizeof namebuf
));
896 expected_len
= odp_flow_key_attr_len(nl_attr_type(a
));
897 if (expected_len
!= -2 && nl_attr_get_size(a
) != expected_len
) {
898 ds_put_format(ds
, "(bad length %zu, expected %d)",
900 odp_flow_key_attr_len(nl_attr_type(a
)));
901 format_generic_odp_key(a
, ds
);
906 case OVS_KEY_ATTR_ENCAP
:
907 ds_put_cstr(ds
, "(");
908 if (nl_attr_get_size(a
)) {
909 odp_flow_key_format(nl_attr_get(a
), nl_attr_get_size(a
), ds
);
911 ds_put_char(ds
, ')');
914 case OVS_KEY_ATTR_PRIORITY
:
915 ds_put_format(ds
, "(%#"PRIx32
")", nl_attr_get_u32(a
));
918 case OVS_KEY_ATTR_SKB_MARK
:
919 ds_put_format(ds
, "(%#"PRIx32
")", nl_attr_get_u32(a
));
922 case OVS_KEY_ATTR_TUNNEL
:
923 memset(&tun_key
, 0, sizeof tun_key
);
924 if (odp_tun_key_from_attr(a
, &tun_key
) == ODP_FIT_ERROR
) {
925 ds_put_format(ds
, "(error)");
927 ds_put_format(ds
, "(tun_id=0x%"PRIx64
",src="IP_FMT
",dst="IP_FMT
","
928 "tos=0x%"PRIx8
",ttl=%"PRIu8
",flags(",
929 ntohll(tun_key
.tun_id
),
930 IP_ARGS(tun_key
.ip_src
),
931 IP_ARGS(tun_key
.ip_dst
),
932 tun_key
.ip_tos
, tun_key
.ip_ttl
);
934 format_flags(ds
, flow_tun_flag_to_string
,
935 (uint32_t) tun_key
.flags
, ',');
936 ds_put_format(ds
, "))");
940 case OVS_KEY_ATTR_IN_PORT
:
941 ds_put_format(ds
, "(%"PRIu32
")", nl_attr_get_u32(a
));
944 case OVS_KEY_ATTR_ETHERNET
:
945 eth_key
= nl_attr_get(a
);
946 ds_put_format(ds
, "(src="ETH_ADDR_FMT
",dst="ETH_ADDR_FMT
")",
947 ETH_ADDR_ARGS(eth_key
->eth_src
),
948 ETH_ADDR_ARGS(eth_key
->eth_dst
));
951 case OVS_KEY_ATTR_VLAN
:
952 ds_put_char(ds
, '(');
953 format_vlan_tci(ds
, nl_attr_get_be16(a
));
954 ds_put_char(ds
, ')');
957 case OVS_KEY_ATTR_MPLS
: {
958 const struct ovs_key_mpls
*mpls_key
= nl_attr_get(a
);
959 ds_put_char(ds
, '(');
960 format_mpls_lse(ds
, mpls_key
->mpls_lse
);
961 ds_put_char(ds
, ')');
965 case OVS_KEY_ATTR_ETHERTYPE
:
966 ds_put_format(ds
, "(0x%04"PRIx16
")",
967 ntohs(nl_attr_get_be16(a
)));
970 case OVS_KEY_ATTR_IPV4
:
971 ipv4_key
= nl_attr_get(a
);
972 ds_put_format(ds
, "(src="IP_FMT
",dst="IP_FMT
",proto=%"PRIu8
973 ",tos=%#"PRIx8
",ttl=%"PRIu8
",frag=%s)",
974 IP_ARGS(ipv4_key
->ipv4_src
),
975 IP_ARGS(ipv4_key
->ipv4_dst
),
976 ipv4_key
->ipv4_proto
, ipv4_key
->ipv4_tos
,
978 ovs_frag_type_to_string(ipv4_key
->ipv4_frag
));
981 case OVS_KEY_ATTR_IPV6
: {
982 char src_str
[INET6_ADDRSTRLEN
];
983 char dst_str
[INET6_ADDRSTRLEN
];
985 ipv6_key
= nl_attr_get(a
);
986 inet_ntop(AF_INET6
, ipv6_key
->ipv6_src
, src_str
, sizeof src_str
);
987 inet_ntop(AF_INET6
, ipv6_key
->ipv6_dst
, dst_str
, sizeof dst_str
);
989 ds_put_format(ds
, "(src=%s,dst=%s,label=%#"PRIx32
",proto=%"PRIu8
990 ",tclass=%#"PRIx8
",hlimit=%"PRIu8
",frag=%s)",
991 src_str
, dst_str
, ntohl(ipv6_key
->ipv6_label
),
992 ipv6_key
->ipv6_proto
, ipv6_key
->ipv6_tclass
,
993 ipv6_key
->ipv6_hlimit
,
994 ovs_frag_type_to_string(ipv6_key
->ipv6_frag
));
998 case OVS_KEY_ATTR_TCP
:
999 tcp_key
= nl_attr_get(a
);
1000 ds_put_format(ds
, "(src=%"PRIu16
",dst=%"PRIu16
")",
1001 ntohs(tcp_key
->tcp_src
), ntohs(tcp_key
->tcp_dst
));
1004 case OVS_KEY_ATTR_UDP
:
1005 udp_key
= nl_attr_get(a
);
1006 ds_put_format(ds
, "(src=%"PRIu16
",dst=%"PRIu16
")",
1007 ntohs(udp_key
->udp_src
), ntohs(udp_key
->udp_dst
));
1010 case OVS_KEY_ATTR_ICMP
:
1011 icmp_key
= nl_attr_get(a
);
1012 ds_put_format(ds
, "(type=%"PRIu8
",code=%"PRIu8
")",
1013 icmp_key
->icmp_type
, icmp_key
->icmp_code
);
1016 case OVS_KEY_ATTR_ICMPV6
:
1017 icmpv6_key
= nl_attr_get(a
);
1018 ds_put_format(ds
, "(type=%"PRIu8
",code=%"PRIu8
")",
1019 icmpv6_key
->icmpv6_type
, icmpv6_key
->icmpv6_code
);
1022 case OVS_KEY_ATTR_ARP
:
1023 arp_key
= nl_attr_get(a
);
1024 ds_put_format(ds
, "(sip="IP_FMT
",tip="IP_FMT
",op=%"PRIu16
","
1025 "sha="ETH_ADDR_FMT
",tha="ETH_ADDR_FMT
")",
1026 IP_ARGS(arp_key
->arp_sip
), IP_ARGS(arp_key
->arp_tip
),
1027 ntohs(arp_key
->arp_op
), ETH_ADDR_ARGS(arp_key
->arp_sha
),
1028 ETH_ADDR_ARGS(arp_key
->arp_tha
));
1031 case OVS_KEY_ATTR_ND
: {
1032 char target
[INET6_ADDRSTRLEN
];
1034 nd_key
= nl_attr_get(a
);
1035 inet_ntop(AF_INET6
, nd_key
->nd_target
, target
, sizeof target
);
1037 ds_put_format(ds
, "(target=%s", target
);
1038 if (!eth_addr_is_zero(nd_key
->nd_sll
)) {
1039 ds_put_format(ds
, ",sll="ETH_ADDR_FMT
,
1040 ETH_ADDR_ARGS(nd_key
->nd_sll
));
1042 if (!eth_addr_is_zero(nd_key
->nd_tll
)) {
1043 ds_put_format(ds
, ",tll="ETH_ADDR_FMT
,
1044 ETH_ADDR_ARGS(nd_key
->nd_tll
));
1046 ds_put_char(ds
, ')');
1050 case OVS_KEY_ATTR_UNSPEC
:
1051 case __OVS_KEY_ATTR_MAX
:
1053 format_generic_odp_key(a
, ds
);
1058 /* Appends to 'ds' a string representation of the 'key_len' bytes of
1059 * OVS_KEY_ATTR_* attributes in 'key'. */
1061 odp_flow_key_format(const struct nlattr
*key
, size_t key_len
, struct ds
*ds
)
1064 const struct nlattr
*a
;
1067 NL_ATTR_FOR_EACH (a
, left
, key
, key_len
) {
1069 ds_put_char(ds
, ',');
1071 format_odp_key_attr(a
, ds
);
1076 if (left
== key_len
) {
1077 ds_put_cstr(ds
, "<empty>");
1079 ds_put_format(ds
, ",***%u leftover bytes*** (", left
);
1080 for (i
= 0; i
< left
; i
++) {
1081 ds_put_format(ds
, "%02x", ((const uint8_t *) a
)[i
]);
1083 ds_put_char(ds
, ')');
1086 ds_put_cstr(ds
, "<empty>");
1091 put_nd_key(int n
, const char *nd_target_s
,
1092 const uint8_t *nd_sll
, const uint8_t *nd_tll
, struct ofpbuf
*key
)
1094 struct ovs_key_nd nd_key
;
1096 memset(&nd_key
, 0, sizeof nd_key
);
1097 if (inet_pton(AF_INET6
, nd_target_s
, nd_key
.nd_target
) != 1) {
1101 memcpy(nd_key
.nd_sll
, nd_sll
, ETH_ADDR_LEN
);
1104 memcpy(nd_key
.nd_tll
, nd_tll
, ETH_ADDR_LEN
);
1106 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ND
, &nd_key
, sizeof nd_key
);
1111 ovs_frag_type_from_string(const char *s
, enum ovs_frag_type
*type
)
1113 if (!strcasecmp(s
, "no")) {
1114 *type
= OVS_FRAG_TYPE_NONE
;
1115 } else if (!strcasecmp(s
, "first")) {
1116 *type
= OVS_FRAG_TYPE_FIRST
;
1117 } else if (!strcasecmp(s
, "later")) {
1118 *type
= OVS_FRAG_TYPE_LATER
;
1126 mpls_lse_from_components(int mpls_label
, int mpls_tc
, int mpls_ttl
, int mpls_bos
)
1128 return (htonl((mpls_label
<< MPLS_LABEL_SHIFT
) |
1129 (mpls_tc
<< MPLS_TC_SHIFT
) |
1130 (mpls_ttl
<< MPLS_TTL_SHIFT
) |
1131 (mpls_bos
<< MPLS_BOS_SHIFT
)));
1135 parse_odp_key_attr(const char *s
, const struct simap
*port_names
,
1138 /* Many of the sscanf calls in this function use oversized destination
1139 * fields because some sscanf() implementations truncate the range of %i
1140 * directives, so that e.g. "%"SCNi16 interprets input of "0xfedc" as a
1141 * value of 0x7fff. The other alternatives are to allow only a single
1142 * radix (e.g. decimal or hexadecimal) or to write more sophisticated
1145 * The tun_id parser has to use an alternative approach because there is no
1146 * type larger than 64 bits. */
1149 unsigned long long int priority
;
1152 if (sscanf(s
, "skb_priority(%llx)%n", &priority
, &n
) > 0 && n
> 0) {
1153 nl_msg_put_u32(key
, OVS_KEY_ATTR_PRIORITY
, priority
);
1159 unsigned long long int mark
;
1162 if (sscanf(s
, "skb_mark(%llx)%n", &mark
, &n
) > 0 && n
> 0) {
1163 nl_msg_put_u32(key
, OVS_KEY_ATTR_SKB_MARK
, mark
);
1171 struct flow_tnl tun_key
;
1174 if (sscanf(s
, "tunnel(tun_id=%31[x0123456789abcdefABCDEF],"
1175 "src="IP_SCAN_FMT
",dst="IP_SCAN_FMT
1176 ",tos=%i,ttl=%i,flags%n", tun_id_s
,
1177 IP_SCAN_ARGS(&tun_key
.ip_src
),
1178 IP_SCAN_ARGS(&tun_key
.ip_dst
), &tos
, &ttl
,
1183 tun_key
.tun_id
= htonll(strtoull(tun_id_s
, NULL
, 0));
1184 tun_key
.ip_tos
= tos
;
1185 tun_key
.ip_ttl
= ttl
;
1186 res
= parse_flags(&s
[n
], flow_tun_flag_to_string
, &flags
);
1187 tun_key
.flags
= (uint16_t) flags
;
1197 tun_key_to_attr(key
, &tun_key
);
1203 unsigned long long int in_port
;
1206 if (sscanf(s
, "in_port(%lli)%n", &in_port
, &n
) > 0 && n
> 0) {
1207 nl_msg_put_u32(key
, OVS_KEY_ATTR_IN_PORT
, in_port
);
1212 if (port_names
&& !strncmp(s
, "in_port(", 8)) {
1214 const struct simap_node
*node
;
1218 name_len
= strcspn(s
, ")");
1219 node
= simap_find_len(port_names
, name
, name_len
);
1221 nl_msg_put_u32(key
, OVS_KEY_ATTR_IN_PORT
, node
->data
);
1222 return 8 + name_len
+ 1;
1227 struct ovs_key_ethernet eth_key
;
1231 "eth(src="ETH_ADDR_SCAN_FMT
",dst="ETH_ADDR_SCAN_FMT
")%n",
1232 ETH_ADDR_SCAN_ARGS(eth_key
.eth_src
),
1233 ETH_ADDR_SCAN_ARGS(eth_key
.eth_dst
), &n
) > 0 && n
> 0) {
1234 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ETHERNET
,
1235 ð_key
, sizeof eth_key
);
1246 if ((sscanf(s
, "vlan(vid=%"SCNi16
",pcp=%i)%n", &vid
, &pcp
, &n
) > 0
1248 nl_msg_put_be16(key
, OVS_KEY_ATTR_VLAN
,
1249 htons((vid
<< VLAN_VID_SHIFT
) |
1250 (pcp
<< VLAN_PCP_SHIFT
) |
1253 } else if ((sscanf(s
, "vlan(vid=%"SCNi16
",pcp=%i,cfi=%i)%n",
1254 &vid
, &pcp
, &cfi
, &n
) > 0
1256 nl_msg_put_be16(key
, OVS_KEY_ATTR_VLAN
,
1257 htons((vid
<< VLAN_VID_SHIFT
) |
1258 (pcp
<< VLAN_PCP_SHIFT
) |
1259 (cfi
? VLAN_CFI
: 0)));
1268 if (sscanf(s
, "eth_type(%i)%n", ð_type
, &n
) > 0 && n
> 0) {
1269 nl_msg_put_be16(key
, OVS_KEY_ATTR_ETHERTYPE
, htons(eth_type
));
1275 int label
, tc
, ttl
, bos
;
1278 if (sscanf(s
, "mpls(label=%"SCNi32
",tc=%i,ttl=%i,bos=%i)%n",
1279 &label
, &tc
, &ttl
, &bos
, &n
) > 0 &&
1281 struct ovs_key_mpls
*mpls
;
1283 mpls
= nl_msg_put_unspec_uninit(key
, OVS_KEY_ATTR_MPLS
,
1285 mpls
->mpls_lse
= mpls_lse_from_components(label
, tc
, ttl
, bos
);
1297 enum ovs_frag_type ipv4_frag
;
1300 if (sscanf(s
, "ipv4(src="IP_SCAN_FMT
",dst="IP_SCAN_FMT
","
1301 "proto=%i,tos=%i,ttl=%i,frag=%7[a-z])%n",
1302 IP_SCAN_ARGS(&ipv4_src
), IP_SCAN_ARGS(&ipv4_dst
),
1303 &ipv4_proto
, &ipv4_tos
, &ipv4_ttl
, frag
, &n
) > 0
1305 && ovs_frag_type_from_string(frag
, &ipv4_frag
)) {
1306 struct ovs_key_ipv4 ipv4_key
;
1308 ipv4_key
.ipv4_src
= ipv4_src
;
1309 ipv4_key
.ipv4_dst
= ipv4_dst
;
1310 ipv4_key
.ipv4_proto
= ipv4_proto
;
1311 ipv4_key
.ipv4_tos
= ipv4_tos
;
1312 ipv4_key
.ipv4_ttl
= ipv4_ttl
;
1313 ipv4_key
.ipv4_frag
= ipv4_frag
;
1314 nl_msg_put_unspec(key
, OVS_KEY_ATTR_IPV4
,
1315 &ipv4_key
, sizeof ipv4_key
);
1321 char ipv6_src_s
[IPV6_SCAN_LEN
+ 1];
1322 char ipv6_dst_s
[IPV6_SCAN_LEN
+ 1];
1328 enum ovs_frag_type ipv6_frag
;
1331 if (sscanf(s
, "ipv6(src="IPV6_SCAN_FMT
",dst="IPV6_SCAN_FMT
","
1332 "label=%i,proto=%i,tclass=%i,hlimit=%i,frag=%7[a-z])%n",
1333 ipv6_src_s
, ipv6_dst_s
, &ipv6_label
,
1334 &ipv6_proto
, &ipv6_tclass
, &ipv6_hlimit
, frag
, &n
) > 0
1336 && ovs_frag_type_from_string(frag
, &ipv6_frag
)) {
1337 struct ovs_key_ipv6 ipv6_key
;
1339 if (inet_pton(AF_INET6
, ipv6_src_s
, &ipv6_key
.ipv6_src
) != 1 ||
1340 inet_pton(AF_INET6
, ipv6_dst_s
, &ipv6_key
.ipv6_dst
) != 1) {
1343 ipv6_key
.ipv6_label
= htonl(ipv6_label
);
1344 ipv6_key
.ipv6_proto
= ipv6_proto
;
1345 ipv6_key
.ipv6_tclass
= ipv6_tclass
;
1346 ipv6_key
.ipv6_hlimit
= ipv6_hlimit
;
1347 ipv6_key
.ipv6_frag
= ipv6_frag
;
1348 nl_msg_put_unspec(key
, OVS_KEY_ATTR_IPV6
,
1349 &ipv6_key
, sizeof ipv6_key
);
1359 if (sscanf(s
, "tcp(src=%i,dst=%i)%n",&tcp_src
, &tcp_dst
, &n
) > 0
1361 struct ovs_key_tcp tcp_key
;
1363 tcp_key
.tcp_src
= htons(tcp_src
);
1364 tcp_key
.tcp_dst
= htons(tcp_dst
);
1365 nl_msg_put_unspec(key
, OVS_KEY_ATTR_TCP
, &tcp_key
, sizeof tcp_key
);
1375 if (sscanf(s
, "udp(src=%i,dst=%i)%n", &udp_src
, &udp_dst
, &n
) > 0
1377 struct ovs_key_udp udp_key
;
1379 udp_key
.udp_src
= htons(udp_src
);
1380 udp_key
.udp_dst
= htons(udp_dst
);
1381 nl_msg_put_unspec(key
, OVS_KEY_ATTR_UDP
, &udp_key
, sizeof udp_key
);
1391 if (sscanf(s
, "icmp(type=%i,code=%i)%n",
1392 &icmp_type
, &icmp_code
, &n
) > 0
1394 struct ovs_key_icmp icmp_key
;
1396 icmp_key
.icmp_type
= icmp_type
;
1397 icmp_key
.icmp_code
= icmp_code
;
1398 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ICMP
,
1399 &icmp_key
, sizeof icmp_key
);
1405 struct ovs_key_icmpv6 icmpv6_key
;
1408 if (sscanf(s
, "icmpv6(type=%"SCNi8
",code=%"SCNi8
")%n",
1409 &icmpv6_key
.icmpv6_type
, &icmpv6_key
.icmpv6_code
,&n
) > 0
1411 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ICMPV6
,
1412 &icmpv6_key
, sizeof icmpv6_key
);
1421 uint8_t arp_sha
[ETH_ADDR_LEN
];
1422 uint8_t arp_tha
[ETH_ADDR_LEN
];
1425 if (sscanf(s
, "arp(sip="IP_SCAN_FMT
",tip="IP_SCAN_FMT
","
1426 "op=%i,sha="ETH_ADDR_SCAN_FMT
",tha="ETH_ADDR_SCAN_FMT
")%n",
1427 IP_SCAN_ARGS(&arp_sip
),
1428 IP_SCAN_ARGS(&arp_tip
),
1430 ETH_ADDR_SCAN_ARGS(arp_sha
),
1431 ETH_ADDR_SCAN_ARGS(arp_tha
), &n
) > 0 && n
> 0) {
1432 struct ovs_key_arp arp_key
;
1434 memset(&arp_key
, 0, sizeof arp_key
);
1435 arp_key
.arp_sip
= arp_sip
;
1436 arp_key
.arp_tip
= arp_tip
;
1437 arp_key
.arp_op
= htons(arp_op
);
1438 memcpy(arp_key
.arp_sha
, arp_sha
, ETH_ADDR_LEN
);
1439 memcpy(arp_key
.arp_tha
, arp_tha
, ETH_ADDR_LEN
);
1440 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ARP
, &arp_key
, sizeof arp_key
);
1446 char nd_target_s
[IPV6_SCAN_LEN
+ 1];
1447 uint8_t nd_sll
[ETH_ADDR_LEN
];
1448 uint8_t nd_tll
[ETH_ADDR_LEN
];
1451 if (sscanf(s
, "nd(target="IPV6_SCAN_FMT
")%n",
1452 nd_target_s
, &n
) > 0 && n
> 0) {
1453 return put_nd_key(n
, nd_target_s
, NULL
, NULL
, key
);
1455 if (sscanf(s
, "nd(target="IPV6_SCAN_FMT
",sll="ETH_ADDR_SCAN_FMT
")%n",
1456 nd_target_s
, ETH_ADDR_SCAN_ARGS(nd_sll
), &n
) > 0
1458 return put_nd_key(n
, nd_target_s
, nd_sll
, NULL
, key
);
1460 if (sscanf(s
, "nd(target="IPV6_SCAN_FMT
",tll="ETH_ADDR_SCAN_FMT
")%n",
1461 nd_target_s
, ETH_ADDR_SCAN_ARGS(nd_tll
), &n
) > 0
1463 return put_nd_key(n
, nd_target_s
, NULL
, nd_tll
, key
);
1465 if (sscanf(s
, "nd(target="IPV6_SCAN_FMT
",sll="ETH_ADDR_SCAN_FMT
","
1466 "tll="ETH_ADDR_SCAN_FMT
")%n",
1467 nd_target_s
, ETH_ADDR_SCAN_ARGS(nd_sll
),
1468 ETH_ADDR_SCAN_ARGS(nd_tll
), &n
) > 0
1470 return put_nd_key(n
, nd_target_s
, nd_sll
, nd_tll
, key
);
1474 if (!strncmp(s
, "encap(", 6)) {
1475 const char *start
= s
;
1478 encap
= nl_msg_start_nested(key
, OVS_KEY_ATTR_ENCAP
);
1484 s
+= strspn(s
, ", \t\r\n");
1487 } else if (*s
== ')') {
1491 retval
= parse_odp_key_attr(s
, port_names
, key
);
1499 nl_msg_end_nested(key
, encap
);
1507 /* Parses the string representation of a datapath flow key, in the
1508 * format output by odp_flow_key_format(). Returns 0 if successful,
1509 * otherwise a positive errno value. On success, the flow key is
1510 * appended to 'key' as a series of Netlink attributes. On failure, no
1511 * data is appended to 'key'. Either way, 'key''s data might be
1514 * If 'port_names' is nonnull, it points to an simap that maps from a port name
1515 * to a port number. (Port names may be used instead of port numbers in
1518 * On success, the attributes appended to 'key' are individually syntactically
1519 * valid, but they may not be valid as a sequence. 'key' might, for example,
1520 * have duplicated keys. odp_flow_key_to_flow() will detect those errors. */
1522 odp_flow_key_from_string(const char *s
, const struct simap
*port_names
,
1525 const size_t old_size
= key
->size
;
1529 s
+= strspn(s
, delimiters
);
1534 retval
= parse_odp_key_attr(s
, port_names
, key
);
1536 key
->size
= old_size
;
1546 ovs_to_odp_frag(uint8_t nw_frag
)
1548 return (nw_frag
== 0 ? OVS_FRAG_TYPE_NONE
1549 : nw_frag
== FLOW_NW_FRAG_ANY
? OVS_FRAG_TYPE_FIRST
1550 : OVS_FRAG_TYPE_LATER
);
1553 /* Appends a representation of 'flow' as OVS_KEY_ATTR_* attributes to 'buf'.
1554 * 'flow->in_port' is ignored (since it is likely to be an OpenFlow port
1555 * number rather than a datapath port number). Instead, if 'odp_in_port'
1556 * is anything other than OVSP_NONE, it is included in 'buf' as the input
1559 * 'buf' must have at least ODPUTIL_FLOW_KEY_BYTES bytes of space, or be
1560 * capable of being expanded to allow for that much space. */
1562 odp_flow_key_from_flow(struct ofpbuf
*buf
, const struct flow
*flow
,
1563 uint32_t odp_in_port
)
1565 struct ovs_key_ethernet
*eth_key
;
1568 if (flow
->skb_priority
) {
1569 nl_msg_put_u32(buf
, OVS_KEY_ATTR_PRIORITY
, flow
->skb_priority
);
1572 if (flow
->tunnel
.ip_dst
) {
1573 tun_key_to_attr(buf
, &flow
->tunnel
);
1576 if (flow
->skb_mark
) {
1577 nl_msg_put_u32(buf
, OVS_KEY_ATTR_SKB_MARK
, flow
->skb_mark
);
1580 if (odp_in_port
!= OVSP_NONE
) {
1581 nl_msg_put_u32(buf
, OVS_KEY_ATTR_IN_PORT
, odp_in_port
);
1584 eth_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_ETHERNET
,
1586 memcpy(eth_key
->eth_src
, flow
->dl_src
, ETH_ADDR_LEN
);
1587 memcpy(eth_key
->eth_dst
, flow
->dl_dst
, ETH_ADDR_LEN
);
1589 if (flow
->vlan_tci
!= htons(0) || flow
->dl_type
== htons(ETH_TYPE_VLAN
)) {
1590 nl_msg_put_be16(buf
, OVS_KEY_ATTR_ETHERTYPE
, htons(ETH_TYPE_VLAN
));
1591 nl_msg_put_be16(buf
, OVS_KEY_ATTR_VLAN
, flow
->vlan_tci
);
1592 encap
= nl_msg_start_nested(buf
, OVS_KEY_ATTR_ENCAP
);
1593 if (flow
->vlan_tci
== htons(0)) {
1600 if (ntohs(flow
->dl_type
) < ETH_TYPE_MIN
) {
1604 nl_msg_put_be16(buf
, OVS_KEY_ATTR_ETHERTYPE
, flow
->dl_type
);
1606 if (flow
->dl_type
== htons(ETH_TYPE_IP
)) {
1607 struct ovs_key_ipv4
*ipv4_key
;
1609 ipv4_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_IPV4
,
1611 ipv4_key
->ipv4_src
= flow
->nw_src
;
1612 ipv4_key
->ipv4_dst
= flow
->nw_dst
;
1613 ipv4_key
->ipv4_proto
= flow
->nw_proto
;
1614 ipv4_key
->ipv4_tos
= flow
->nw_tos
;
1615 ipv4_key
->ipv4_ttl
= flow
->nw_ttl
;
1616 ipv4_key
->ipv4_frag
= ovs_to_odp_frag(flow
->nw_frag
);
1617 } else if (flow
->dl_type
== htons(ETH_TYPE_IPV6
)) {
1618 struct ovs_key_ipv6
*ipv6_key
;
1620 ipv6_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_IPV6
,
1622 memcpy(ipv6_key
->ipv6_src
, &flow
->ipv6_src
, sizeof ipv6_key
->ipv6_src
);
1623 memcpy(ipv6_key
->ipv6_dst
, &flow
->ipv6_dst
, sizeof ipv6_key
->ipv6_dst
);
1624 ipv6_key
->ipv6_label
= flow
->ipv6_label
;
1625 ipv6_key
->ipv6_proto
= flow
->nw_proto
;
1626 ipv6_key
->ipv6_tclass
= flow
->nw_tos
;
1627 ipv6_key
->ipv6_hlimit
= flow
->nw_ttl
;
1628 ipv6_key
->ipv6_frag
= ovs_to_odp_frag(flow
->nw_frag
);
1629 } else if (flow
->dl_type
== htons(ETH_TYPE_ARP
) ||
1630 flow
->dl_type
== htons(ETH_TYPE_RARP
)) {
1631 struct ovs_key_arp
*arp_key
;
1633 arp_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_ARP
,
1635 memset(arp_key
, 0, sizeof *arp_key
);
1636 arp_key
->arp_sip
= flow
->nw_src
;
1637 arp_key
->arp_tip
= flow
->nw_dst
;
1638 arp_key
->arp_op
= htons(flow
->nw_proto
);
1639 memcpy(arp_key
->arp_sha
, flow
->arp_sha
, ETH_ADDR_LEN
);
1640 memcpy(arp_key
->arp_tha
, flow
->arp_tha
, ETH_ADDR_LEN
);
1643 if (flow
->mpls_depth
) {
1644 struct ovs_key_mpls
*mpls_key
;
1646 mpls_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_MPLS
,
1648 mpls_key
->mpls_lse
= flow
->mpls_lse
;
1651 if (is_ip_any(flow
) && !(flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
1652 if (flow
->nw_proto
== IPPROTO_TCP
) {
1653 struct ovs_key_tcp
*tcp_key
;
1655 tcp_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_TCP
,
1657 tcp_key
->tcp_src
= flow
->tp_src
;
1658 tcp_key
->tcp_dst
= flow
->tp_dst
;
1659 } else if (flow
->nw_proto
== IPPROTO_UDP
) {
1660 struct ovs_key_udp
*udp_key
;
1662 udp_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_UDP
,
1664 udp_key
->udp_src
= flow
->tp_src
;
1665 udp_key
->udp_dst
= flow
->tp_dst
;
1666 } else if (flow
->dl_type
== htons(ETH_TYPE_IP
)
1667 && flow
->nw_proto
== IPPROTO_ICMP
) {
1668 struct ovs_key_icmp
*icmp_key
;
1670 icmp_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_ICMP
,
1672 icmp_key
->icmp_type
= ntohs(flow
->tp_src
);
1673 icmp_key
->icmp_code
= ntohs(flow
->tp_dst
);
1674 } else if (flow
->dl_type
== htons(ETH_TYPE_IPV6
)
1675 && flow
->nw_proto
== IPPROTO_ICMPV6
) {
1676 struct ovs_key_icmpv6
*icmpv6_key
;
1678 icmpv6_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_ICMPV6
,
1679 sizeof *icmpv6_key
);
1680 icmpv6_key
->icmpv6_type
= ntohs(flow
->tp_src
);
1681 icmpv6_key
->icmpv6_code
= ntohs(flow
->tp_dst
);
1683 if (icmpv6_key
->icmpv6_type
== ND_NEIGHBOR_SOLICIT
1684 || icmpv6_key
->icmpv6_type
== ND_NEIGHBOR_ADVERT
) {
1685 struct ovs_key_nd
*nd_key
;
1687 nd_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_ND
,
1689 memcpy(nd_key
->nd_target
, &flow
->nd_target
,
1690 sizeof nd_key
->nd_target
);
1691 memcpy(nd_key
->nd_sll
, flow
->arp_sha
, ETH_ADDR_LEN
);
1692 memcpy(nd_key
->nd_tll
, flow
->arp_tha
, ETH_ADDR_LEN
);
1699 nl_msg_end_nested(buf
, encap
);
1704 odp_flow_key_hash(const struct nlattr
*key
, size_t key_len
)
1706 BUILD_ASSERT_DECL(!(NLA_ALIGNTO
% sizeof(uint32_t)));
1707 return hash_words((const uint32_t *) key
, key_len
/ sizeof(uint32_t), 0);
1711 log_odp_key_attributes(struct vlog_rate_limit
*rl
, const char *title
,
1712 uint64_t attrs
, int out_of_range_attr
,
1713 const struct nlattr
*key
, size_t key_len
)
1718 if (VLOG_DROP_DBG(rl
)) {
1723 for (i
= 0; i
< 64; i
++) {
1724 if (attrs
& (UINT64_C(1) << i
)) {
1725 char namebuf
[OVS_KEY_ATTR_BUFSIZE
];
1727 ds_put_format(&s
, " %s",
1728 ovs_key_attr_to_string(i
, namebuf
, sizeof namebuf
));
1731 if (out_of_range_attr
) {
1732 ds_put_format(&s
, " %d (and possibly others)", out_of_range_attr
);
1735 ds_put_cstr(&s
, ": ");
1736 odp_flow_key_format(key
, key_len
, &s
);
1738 VLOG_DBG("%s:%s", title
, ds_cstr(&s
));
1743 odp_to_ovs_frag(uint8_t odp_frag
, struct flow
*flow
)
1745 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
1747 if (odp_frag
> OVS_FRAG_TYPE_LATER
) {
1748 VLOG_ERR_RL(&rl
, "invalid frag %"PRIu8
" in flow key", odp_frag
);
1752 if (odp_frag
!= OVS_FRAG_TYPE_NONE
) {
1753 flow
->nw_frag
|= FLOW_NW_FRAG_ANY
;
1754 if (odp_frag
== OVS_FRAG_TYPE_LATER
) {
1755 flow
->nw_frag
|= FLOW_NW_FRAG_LATER
;
1762 parse_flow_nlattrs(const struct nlattr
*key
, size_t key_len
,
1763 const struct nlattr
*attrs
[], uint64_t *present_attrsp
,
1764 int *out_of_range_attrp
)
1766 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(10, 10);
1767 const struct nlattr
*nla
;
1768 uint64_t present_attrs
;
1771 BUILD_ASSERT(OVS_KEY_ATTR_MAX
< CHAR_BIT
* sizeof present_attrs
);
1773 *out_of_range_attrp
= 0;
1774 NL_ATTR_FOR_EACH (nla
, left
, key
, key_len
) {
1775 uint16_t type
= nl_attr_type(nla
);
1776 size_t len
= nl_attr_get_size(nla
);
1777 int expected_len
= odp_flow_key_attr_len(type
);
1779 if (len
!= expected_len
&& expected_len
>= 0) {
1780 char namebuf
[OVS_KEY_ATTR_BUFSIZE
];
1782 VLOG_ERR_RL(&rl
, "attribute %s has length %zu but should have "
1783 "length %d", ovs_key_attr_to_string(type
, namebuf
,
1789 if (type
> OVS_KEY_ATTR_MAX
) {
1790 *out_of_range_attrp
= type
;
1792 if (present_attrs
& (UINT64_C(1) << type
)) {
1793 char namebuf
[OVS_KEY_ATTR_BUFSIZE
];
1795 VLOG_ERR_RL(&rl
, "duplicate %s attribute in flow key",
1796 ovs_key_attr_to_string(type
,
1797 namebuf
, sizeof namebuf
));
1801 present_attrs
|= UINT64_C(1) << type
;
1806 VLOG_ERR_RL(&rl
, "trailing garbage in flow key");
1810 *present_attrsp
= present_attrs
;
1814 static enum odp_key_fitness
1815 check_expectations(uint64_t present_attrs
, int out_of_range_attr
,
1816 uint64_t expected_attrs
,
1817 const struct nlattr
*key
, size_t key_len
)
1819 uint64_t missing_attrs
;
1820 uint64_t extra_attrs
;
1822 missing_attrs
= expected_attrs
& ~present_attrs
;
1823 if (missing_attrs
) {
1824 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(10, 10);
1825 log_odp_key_attributes(&rl
, "expected but not present",
1826 missing_attrs
, 0, key
, key_len
);
1827 return ODP_FIT_TOO_LITTLE
;
1830 extra_attrs
= present_attrs
& ~expected_attrs
;
1831 if (extra_attrs
|| out_of_range_attr
) {
1832 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(10, 10);
1833 log_odp_key_attributes(&rl
, "present but not expected",
1834 extra_attrs
, out_of_range_attr
, key
, key_len
);
1835 return ODP_FIT_TOO_MUCH
;
1838 return ODP_FIT_PERFECT
;
1842 parse_ethertype(const struct nlattr
*attrs
[OVS_KEY_ATTR_MAX
+ 1],
1843 uint64_t present_attrs
, uint64_t *expected_attrs
,
1846 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
1848 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ETHERTYPE
)) {
1849 flow
->dl_type
= nl_attr_get_be16(attrs
[OVS_KEY_ATTR_ETHERTYPE
]);
1850 if (ntohs(flow
->dl_type
) < 1536) {
1851 VLOG_ERR_RL(&rl
, "invalid Ethertype %"PRIu16
" in flow key",
1852 ntohs(flow
->dl_type
));
1855 *expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ETHERTYPE
;
1857 flow
->dl_type
= htons(FLOW_DL_TYPE_NONE
);
1862 static enum odp_key_fitness
1863 parse_l2_5_onward(const struct nlattr
*attrs
[OVS_KEY_ATTR_MAX
+ 1],
1864 uint64_t present_attrs
, int out_of_range_attr
,
1865 uint64_t expected_attrs
, struct flow
*flow
,
1866 const struct nlattr
*key
, size_t key_len
)
1868 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
1870 if (eth_type_mpls(flow
->dl_type
)) {
1871 expected_attrs
|= (UINT64_C(1) << OVS_KEY_ATTR_MPLS
);
1873 if (!(present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_MPLS
))) {
1874 return ODP_FIT_TOO_LITTLE
;
1876 flow
->mpls_lse
= nl_attr_get_be32(attrs
[OVS_KEY_ATTR_MPLS
]);
1878 } else if (flow
->dl_type
== htons(ETH_TYPE_IP
)) {
1879 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_IPV4
;
1880 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_IPV4
)) {
1881 const struct ovs_key_ipv4
*ipv4_key
;
1883 ipv4_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_IPV4
]);
1884 flow
->nw_src
= ipv4_key
->ipv4_src
;
1885 flow
->nw_dst
= ipv4_key
->ipv4_dst
;
1886 flow
->nw_proto
= ipv4_key
->ipv4_proto
;
1887 flow
->nw_tos
= ipv4_key
->ipv4_tos
;
1888 flow
->nw_ttl
= ipv4_key
->ipv4_ttl
;
1889 if (!odp_to_ovs_frag(ipv4_key
->ipv4_frag
, flow
)) {
1890 return ODP_FIT_ERROR
;
1893 } else if (flow
->dl_type
== htons(ETH_TYPE_IPV6
)) {
1894 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_IPV6
;
1895 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_IPV6
)) {
1896 const struct ovs_key_ipv6
*ipv6_key
;
1898 ipv6_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_IPV6
]);
1899 memcpy(&flow
->ipv6_src
, ipv6_key
->ipv6_src
, sizeof flow
->ipv6_src
);
1900 memcpy(&flow
->ipv6_dst
, ipv6_key
->ipv6_dst
, sizeof flow
->ipv6_dst
);
1901 flow
->ipv6_label
= ipv6_key
->ipv6_label
;
1902 flow
->nw_proto
= ipv6_key
->ipv6_proto
;
1903 flow
->nw_tos
= ipv6_key
->ipv6_tclass
;
1904 flow
->nw_ttl
= ipv6_key
->ipv6_hlimit
;
1905 if (!odp_to_ovs_frag(ipv6_key
->ipv6_frag
, flow
)) {
1906 return ODP_FIT_ERROR
;
1909 } else if (flow
->dl_type
== htons(ETH_TYPE_ARP
) ||
1910 flow
->dl_type
== htons(ETH_TYPE_RARP
)) {
1911 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ARP
;
1912 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ARP
)) {
1913 const struct ovs_key_arp
*arp_key
;
1915 arp_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_ARP
]);
1916 flow
->nw_src
= arp_key
->arp_sip
;
1917 flow
->nw_dst
= arp_key
->arp_tip
;
1918 if (arp_key
->arp_op
& htons(0xff00)) {
1919 VLOG_ERR_RL(&rl
, "unsupported ARP opcode %"PRIu16
" in flow "
1920 "key", ntohs(arp_key
->arp_op
));
1921 return ODP_FIT_ERROR
;
1923 flow
->nw_proto
= ntohs(arp_key
->arp_op
);
1924 memcpy(flow
->arp_sha
, arp_key
->arp_sha
, ETH_ADDR_LEN
);
1925 memcpy(flow
->arp_tha
, arp_key
->arp_tha
, ETH_ADDR_LEN
);
1929 if (flow
->nw_proto
== IPPROTO_TCP
1930 && (flow
->dl_type
== htons(ETH_TYPE_IP
) ||
1931 flow
->dl_type
== htons(ETH_TYPE_IPV6
))
1932 && !(flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
1933 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_TCP
;
1934 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_TCP
)) {
1935 const struct ovs_key_tcp
*tcp_key
;
1937 tcp_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_TCP
]);
1938 flow
->tp_src
= tcp_key
->tcp_src
;
1939 flow
->tp_dst
= tcp_key
->tcp_dst
;
1941 } else if (flow
->nw_proto
== IPPROTO_UDP
1942 && (flow
->dl_type
== htons(ETH_TYPE_IP
) ||
1943 flow
->dl_type
== htons(ETH_TYPE_IPV6
))
1944 && !(flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
1945 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_UDP
;
1946 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_UDP
)) {
1947 const struct ovs_key_udp
*udp_key
;
1949 udp_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_UDP
]);
1950 flow
->tp_src
= udp_key
->udp_src
;
1951 flow
->tp_dst
= udp_key
->udp_dst
;
1953 } else if (flow
->nw_proto
== IPPROTO_ICMP
1954 && flow
->dl_type
== htons(ETH_TYPE_IP
)
1955 && !(flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
1956 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ICMP
;
1957 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ICMP
)) {
1958 const struct ovs_key_icmp
*icmp_key
;
1960 icmp_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_ICMP
]);
1961 flow
->tp_src
= htons(icmp_key
->icmp_type
);
1962 flow
->tp_dst
= htons(icmp_key
->icmp_code
);
1964 } else if (flow
->nw_proto
== IPPROTO_ICMPV6
1965 && flow
->dl_type
== htons(ETH_TYPE_IPV6
)
1966 && !(flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
1967 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ICMPV6
;
1968 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ICMPV6
)) {
1969 const struct ovs_key_icmpv6
*icmpv6_key
;
1971 icmpv6_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_ICMPV6
]);
1972 flow
->tp_src
= htons(icmpv6_key
->icmpv6_type
);
1973 flow
->tp_dst
= htons(icmpv6_key
->icmpv6_code
);
1975 if (flow
->tp_src
== htons(ND_NEIGHBOR_SOLICIT
) ||
1976 flow
->tp_src
== htons(ND_NEIGHBOR_ADVERT
)) {
1977 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ND
;
1978 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ND
)) {
1979 const struct ovs_key_nd
*nd_key
;
1981 nd_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_ND
]);
1982 memcpy(&flow
->nd_target
, nd_key
->nd_target
,
1983 sizeof flow
->nd_target
);
1984 memcpy(flow
->arp_sha
, nd_key
->nd_sll
, ETH_ADDR_LEN
);
1985 memcpy(flow
->arp_tha
, nd_key
->nd_tll
, ETH_ADDR_LEN
);
1991 return check_expectations(present_attrs
, out_of_range_attr
, expected_attrs
,
1995 /* Parse 802.1Q header then encapsulated L3 attributes. */
1996 static enum odp_key_fitness
1997 parse_8021q_onward(const struct nlattr
*attrs
[OVS_KEY_ATTR_MAX
+ 1],
1998 uint64_t present_attrs
, int out_of_range_attr
,
1999 uint64_t expected_attrs
, struct flow
*flow
,
2000 const struct nlattr
*key
, size_t key_len
)
2002 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
2004 const struct nlattr
*encap
2005 = (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ENCAP
)
2006 ? attrs
[OVS_KEY_ATTR_ENCAP
] : NULL
);
2007 enum odp_key_fitness encap_fitness
;
2008 enum odp_key_fitness fitness
;
2011 /* Calculate fitness of outer attributes. */
2012 expected_attrs
|= ((UINT64_C(1) << OVS_KEY_ATTR_VLAN
) |
2013 (UINT64_C(1) << OVS_KEY_ATTR_ENCAP
));
2014 fitness
= check_expectations(present_attrs
, out_of_range_attr
,
2015 expected_attrs
, key
, key_len
);
2017 /* Get the VLAN TCI value. */
2018 if (!(present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_VLAN
))) {
2019 return ODP_FIT_TOO_LITTLE
;
2021 tci
= nl_attr_get_be16(attrs
[OVS_KEY_ATTR_VLAN
]);
2022 if (tci
== htons(0)) {
2023 /* Corner case for a truncated 802.1Q header. */
2024 if (fitness
== ODP_FIT_PERFECT
&& nl_attr_get_size(encap
)) {
2025 return ODP_FIT_TOO_MUCH
;
2028 } else if (!(tci
& htons(VLAN_CFI
))) {
2029 VLOG_ERR_RL(&rl
, "OVS_KEY_ATTR_VLAN 0x%04"PRIx16
" is nonzero "
2030 "but CFI bit is not set", ntohs(tci
));
2031 return ODP_FIT_ERROR
;
2035 * Remove the TPID from dl_type since it's not the real Ethertype. */
2036 flow
->vlan_tci
= tci
;
2037 flow
->dl_type
= htons(0);
2039 /* Now parse the encapsulated attributes. */
2040 if (!parse_flow_nlattrs(nl_attr_get(encap
), nl_attr_get_size(encap
),
2041 attrs
, &present_attrs
, &out_of_range_attr
)) {
2042 return ODP_FIT_ERROR
;
2046 if (!parse_ethertype(attrs
, present_attrs
, &expected_attrs
, flow
)) {
2047 return ODP_FIT_ERROR
;
2049 encap_fitness
= parse_l2_5_onward(attrs
, present_attrs
, out_of_range_attr
,
2050 expected_attrs
, flow
, key
, key_len
);
2052 /* The overall fitness is the worse of the outer and inner attributes. */
2053 return MAX(fitness
, encap_fitness
);
2056 /* Converts the 'key_len' bytes of OVS_KEY_ATTR_* attributes in 'key' to a flow
2057 * structure in 'flow'. Returns an ODP_FIT_* value that indicates how well
2058 * 'key' fits our expectations for what a flow key should contain.
2060 * The 'in_port' will be the datapath's understanding of the port. The
2061 * caller will need to translate with odp_port_to_ofp_port() if the
2062 * OpenFlow port is needed.
2064 * This function doesn't take the packet itself as an argument because none of
2065 * the currently understood OVS_KEY_ATTR_* attributes require it. Currently,
2066 * it is always possible to infer which additional attribute(s) should appear
2067 * by looking at the attributes for lower-level protocols, e.g. if the network
2068 * protocol in OVS_KEY_ATTR_IPV4 or OVS_KEY_ATTR_IPV6 is IPPROTO_TCP then we
2069 * know that a OVS_KEY_ATTR_TCP attribute must appear and that otherwise it
2070 * must be absent. */
2071 enum odp_key_fitness
2072 odp_flow_key_to_flow(const struct nlattr
*key
, size_t key_len
,
2075 const struct nlattr
*attrs
[OVS_KEY_ATTR_MAX
+ 1];
2076 uint64_t expected_attrs
;
2077 uint64_t present_attrs
;
2078 int out_of_range_attr
;
2080 memset(flow
, 0, sizeof *flow
);
2082 /* Parse attributes. */
2083 if (!parse_flow_nlattrs(key
, key_len
, attrs
, &present_attrs
,
2084 &out_of_range_attr
)) {
2085 return ODP_FIT_ERROR
;
2090 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_PRIORITY
)) {
2091 flow
->skb_priority
= nl_attr_get_u32(attrs
[OVS_KEY_ATTR_PRIORITY
]);
2092 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_PRIORITY
;
2095 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_SKB_MARK
)) {
2096 flow
->skb_mark
= nl_attr_get_u32(attrs
[OVS_KEY_ATTR_SKB_MARK
]);
2097 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_SKB_MARK
;
2100 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_TUNNEL
)) {
2101 enum odp_key_fitness res
;
2103 res
= odp_tun_key_from_attr(attrs
[OVS_KEY_ATTR_TUNNEL
], &flow
->tunnel
);
2104 if (res
== ODP_FIT_ERROR
) {
2105 return ODP_FIT_ERROR
;
2106 } else if (res
== ODP_FIT_PERFECT
) {
2107 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_TUNNEL
;
2111 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_IN_PORT
)) {
2112 flow
->in_port
= nl_attr_get_u32(attrs
[OVS_KEY_ATTR_IN_PORT
]);
2113 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_IN_PORT
;
2115 flow
->in_port
= OVSP_NONE
;
2118 /* Ethernet header. */
2119 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ETHERNET
)) {
2120 const struct ovs_key_ethernet
*eth_key
;
2122 eth_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_ETHERNET
]);
2123 memcpy(flow
->dl_src
, eth_key
->eth_src
, ETH_ADDR_LEN
);
2124 memcpy(flow
->dl_dst
, eth_key
->eth_dst
, ETH_ADDR_LEN
);
2126 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ETHERNET
;
2128 /* Get Ethertype or 802.1Q TPID or FLOW_DL_TYPE_NONE. */
2129 if (!parse_ethertype(attrs
, present_attrs
, &expected_attrs
, flow
)) {
2130 return ODP_FIT_ERROR
;
2133 if (flow
->dl_type
== htons(ETH_TYPE_VLAN
)) {
2134 return parse_8021q_onward(attrs
, present_attrs
, out_of_range_attr
,
2135 expected_attrs
, flow
, key
, key_len
);
2137 return parse_l2_5_onward(attrs
, present_attrs
, out_of_range_attr
,
2138 expected_attrs
, flow
, key
, key_len
);
2141 /* Returns 'fitness' as a string, for use in debug messages. */
2143 odp_key_fitness_to_string(enum odp_key_fitness fitness
)
2146 case ODP_FIT_PERFECT
:
2148 case ODP_FIT_TOO_MUCH
:
2150 case ODP_FIT_TOO_LITTLE
:
2151 return "too_little";
2159 /* Appends an OVS_ACTION_ATTR_USERSPACE action to 'odp_actions' that specifies
2160 * Netlink PID 'pid'. If 'userdata' is nonnull, adds a userdata attribute
2161 * whose contents are the 'userdata_size' bytes at 'userdata' and returns the
2162 * offset within 'odp_actions' of the start of the cookie. (If 'userdata' is
2163 * null, then the return value is not meaningful.) */
2165 odp_put_userspace_action(uint32_t pid
,
2166 const void *userdata
, size_t userdata_size
,
2167 struct ofpbuf
*odp_actions
)
2169 size_t userdata_ofs
;
2172 offset
= nl_msg_start_nested(odp_actions
, OVS_ACTION_ATTR_USERSPACE
);
2173 nl_msg_put_u32(odp_actions
, OVS_USERSPACE_ATTR_PID
, pid
);
2175 userdata_ofs
= odp_actions
->size
+ NLA_HDRLEN
;
2176 nl_msg_put_unspec(odp_actions
, OVS_USERSPACE_ATTR_USERDATA
,
2177 userdata
, userdata_size
);
2181 nl_msg_end_nested(odp_actions
, offset
);
2183 return userdata_ofs
;
2187 odp_put_tunnel_action(const struct flow_tnl
*tunnel
,
2188 struct ofpbuf
*odp_actions
)
2190 size_t offset
= nl_msg_start_nested(odp_actions
, OVS_ACTION_ATTR_SET
);
2191 tun_key_to_attr(odp_actions
, tunnel
);
2192 nl_msg_end_nested(odp_actions
, offset
);
2195 /* The commit_odp_actions() function and its helpers. */
2198 commit_set_action(struct ofpbuf
*odp_actions
, enum ovs_key_attr key_type
,
2199 const void *key
, size_t key_size
)
2201 size_t offset
= nl_msg_start_nested(odp_actions
, OVS_ACTION_ATTR_SET
);
2202 nl_msg_put_unspec(odp_actions
, key_type
, key
, key_size
);
2203 nl_msg_end_nested(odp_actions
, offset
);
2207 odp_put_skb_mark_action(const uint32_t skb_mark
,
2208 struct ofpbuf
*odp_actions
)
2210 commit_set_action(odp_actions
, OVS_KEY_ATTR_SKB_MARK
, &skb_mark
,
2214 /* If any of the flow key data that ODP actions can modify are different in
2215 * 'base->tunnel' and 'flow->tunnel', appends a set_tunnel ODP action to
2216 * 'odp_actions' that change the flow tunneling information in key from
2217 * 'base->tunnel' into 'flow->tunnel', and then changes 'base->tunnel' in the
2218 * same way. In other words, operates the same as commit_odp_actions(), but
2219 * only on tunneling information. */
2221 commit_odp_tunnel_action(const struct flow
*flow
, struct flow
*base
,
2222 struct ofpbuf
*odp_actions
)
2224 /* A valid IPV4_TUNNEL must have non-zero ip_dst. */
2225 if (flow
->tunnel
.ip_dst
) {
2226 if (!memcmp(&base
->tunnel
, &flow
->tunnel
, sizeof base
->tunnel
)) {
2229 memcpy(&base
->tunnel
, &flow
->tunnel
, sizeof base
->tunnel
);
2230 odp_put_tunnel_action(&base
->tunnel
, odp_actions
);
2235 commit_set_ether_addr_action(const struct flow
*flow
, struct flow
*base
,
2236 struct ofpbuf
*odp_actions
)
2238 struct ovs_key_ethernet eth_key
;
2240 if (eth_addr_equals(base
->dl_src
, flow
->dl_src
) &&
2241 eth_addr_equals(base
->dl_dst
, flow
->dl_dst
)) {
2245 memcpy(base
->dl_src
, flow
->dl_src
, ETH_ADDR_LEN
);
2246 memcpy(base
->dl_dst
, flow
->dl_dst
, ETH_ADDR_LEN
);
2248 memcpy(eth_key
.eth_src
, base
->dl_src
, ETH_ADDR_LEN
);
2249 memcpy(eth_key
.eth_dst
, base
->dl_dst
, ETH_ADDR_LEN
);
2251 commit_set_action(odp_actions
, OVS_KEY_ATTR_ETHERNET
,
2252 ð_key
, sizeof(eth_key
));
2256 commit_vlan_action(const struct flow
*flow
, struct flow
*base
,
2257 struct ofpbuf
*odp_actions
)
2259 if (base
->vlan_tci
== flow
->vlan_tci
) {
2263 if (base
->vlan_tci
& htons(VLAN_CFI
)) {
2264 nl_msg_put_flag(odp_actions
, OVS_ACTION_ATTR_POP_VLAN
);
2267 if (flow
->vlan_tci
& htons(VLAN_CFI
)) {
2268 struct ovs_action_push_vlan vlan
;
2270 vlan
.vlan_tpid
= htons(ETH_TYPE_VLAN
);
2271 vlan
.vlan_tci
= flow
->vlan_tci
;
2272 nl_msg_put_unspec(odp_actions
, OVS_ACTION_ATTR_PUSH_VLAN
,
2273 &vlan
, sizeof vlan
);
2275 base
->vlan_tci
= flow
->vlan_tci
;
2279 commit_mpls_action(const struct flow
*flow
, struct flow
*base
,
2280 struct ofpbuf
*odp_actions
)
2282 if (flow
->mpls_lse
== base
->mpls_lse
&&
2283 flow
->mpls_depth
== base
->mpls_depth
) {
2287 if (flow
->mpls_depth
< base
->mpls_depth
) {
2288 if (base
->mpls_depth
- flow
->mpls_depth
> 1) {
2289 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(10, 10);
2290 VLOG_WARN_RL(&rl
, "Multiple mpls_pop actions reduced to "
2291 " a single mpls_pop action");
2294 nl_msg_put_be16(odp_actions
, OVS_ACTION_ATTR_POP_MPLS
, flow
->dl_type
);
2295 } else if (flow
->mpls_depth
> base
->mpls_depth
) {
2296 struct ovs_action_push_mpls
*mpls
;
2298 if (flow
->mpls_depth
- base
->mpls_depth
> 1) {
2299 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(10, 10);
2300 VLOG_WARN_RL(&rl
, "Multiple mpls_push actions reduced to "
2301 " a single mpls_push action");
2304 mpls
= nl_msg_put_unspec_uninit(odp_actions
, OVS_ACTION_ATTR_PUSH_MPLS
,
2306 memset(mpls
, 0, sizeof *mpls
);
2307 mpls
->mpls_ethertype
= flow
->dl_type
;
2308 mpls
->mpls_lse
= flow
->mpls_lse
;
2310 struct ovs_key_mpls mpls_key
;
2312 mpls_key
.mpls_lse
= flow
->mpls_lse
;
2313 commit_set_action(odp_actions
, OVS_KEY_ATTR_MPLS
,
2314 &mpls_key
, sizeof(mpls_key
));
2317 base
->dl_type
= flow
->dl_type
;
2318 base
->mpls_lse
= flow
->mpls_lse
;
2319 base
->mpls_depth
= flow
->mpls_depth
;
2323 commit_set_ipv4_action(const struct flow
*flow
, struct flow
*base
,
2324 struct ofpbuf
*odp_actions
)
2326 struct ovs_key_ipv4 ipv4_key
;
2328 if (base
->nw_src
== flow
->nw_src
&&
2329 base
->nw_dst
== flow
->nw_dst
&&
2330 base
->nw_tos
== flow
->nw_tos
&&
2331 base
->nw_ttl
== flow
->nw_ttl
&&
2332 base
->nw_frag
== flow
->nw_frag
) {
2336 ipv4_key
.ipv4_src
= base
->nw_src
= flow
->nw_src
;
2337 ipv4_key
.ipv4_dst
= base
->nw_dst
= flow
->nw_dst
;
2338 ipv4_key
.ipv4_tos
= base
->nw_tos
= flow
->nw_tos
;
2339 ipv4_key
.ipv4_ttl
= base
->nw_ttl
= flow
->nw_ttl
;
2340 ipv4_key
.ipv4_proto
= base
->nw_proto
;
2341 ipv4_key
.ipv4_frag
= ovs_to_odp_frag(base
->nw_frag
);
2343 commit_set_action(odp_actions
, OVS_KEY_ATTR_IPV4
,
2344 &ipv4_key
, sizeof(ipv4_key
));
2348 commit_set_ipv6_action(const struct flow
*flow
, struct flow
*base
,
2349 struct ofpbuf
*odp_actions
)
2351 struct ovs_key_ipv6 ipv6_key
;
2353 if (ipv6_addr_equals(&base
->ipv6_src
, &flow
->ipv6_src
) &&
2354 ipv6_addr_equals(&base
->ipv6_dst
, &flow
->ipv6_dst
) &&
2355 base
->ipv6_label
== flow
->ipv6_label
&&
2356 base
->nw_tos
== flow
->nw_tos
&&
2357 base
->nw_ttl
== flow
->nw_ttl
&&
2358 base
->nw_frag
== flow
->nw_frag
) {
2362 base
->ipv6_src
= flow
->ipv6_src
;
2363 memcpy(&ipv6_key
.ipv6_src
, &base
->ipv6_src
, sizeof(ipv6_key
.ipv6_src
));
2364 base
->ipv6_dst
= flow
->ipv6_dst
;
2365 memcpy(&ipv6_key
.ipv6_dst
, &base
->ipv6_dst
, sizeof(ipv6_key
.ipv6_dst
));
2367 ipv6_key
.ipv6_label
= base
->ipv6_label
= flow
->ipv6_label
;
2368 ipv6_key
.ipv6_tclass
= base
->nw_tos
= flow
->nw_tos
;
2369 ipv6_key
.ipv6_hlimit
= base
->nw_ttl
= flow
->nw_ttl
;
2370 ipv6_key
.ipv6_proto
= base
->nw_proto
;
2371 ipv6_key
.ipv6_frag
= ovs_to_odp_frag(base
->nw_frag
);
2373 commit_set_action(odp_actions
, OVS_KEY_ATTR_IPV6
,
2374 &ipv6_key
, sizeof(ipv6_key
));
2378 commit_set_nw_action(const struct flow
*flow
, struct flow
*base
,
2379 struct ofpbuf
*odp_actions
)
2381 /* Check if flow really have an IP header. */
2382 if (!flow
->nw_proto
) {
2386 if (base
->dl_type
== htons(ETH_TYPE_IP
)) {
2387 commit_set_ipv4_action(flow
, base
, odp_actions
);
2388 } else if (base
->dl_type
== htons(ETH_TYPE_IPV6
)) {
2389 commit_set_ipv6_action(flow
, base
, odp_actions
);
2394 commit_set_port_action(const struct flow
*flow
, struct flow
*base
,
2395 struct ofpbuf
*odp_actions
)
2397 if (!is_ip_any(base
) || (!base
->tp_src
&& !base
->tp_dst
)) {
2401 if (base
->tp_src
== flow
->tp_src
&&
2402 base
->tp_dst
== flow
->tp_dst
) {
2406 if (flow
->nw_proto
== IPPROTO_TCP
) {
2407 struct ovs_key_tcp port_key
;
2409 port_key
.tcp_src
= base
->tp_src
= flow
->tp_src
;
2410 port_key
.tcp_dst
= base
->tp_dst
= flow
->tp_dst
;
2412 commit_set_action(odp_actions
, OVS_KEY_ATTR_TCP
,
2413 &port_key
, sizeof(port_key
));
2415 } else if (flow
->nw_proto
== IPPROTO_UDP
) {
2416 struct ovs_key_udp port_key
;
2418 port_key
.udp_src
= base
->tp_src
= flow
->tp_src
;
2419 port_key
.udp_dst
= base
->tp_dst
= flow
->tp_dst
;
2421 commit_set_action(odp_actions
, OVS_KEY_ATTR_UDP
,
2422 &port_key
, sizeof(port_key
));
2427 commit_set_priority_action(const struct flow
*flow
, struct flow
*base
,
2428 struct ofpbuf
*odp_actions
)
2430 if (base
->skb_priority
== flow
->skb_priority
) {
2433 base
->skb_priority
= flow
->skb_priority
;
2435 commit_set_action(odp_actions
, OVS_KEY_ATTR_PRIORITY
,
2436 &base
->skb_priority
, sizeof(base
->skb_priority
));
2440 commit_set_skb_mark_action(const struct flow
*flow
, struct flow
*base
,
2441 struct ofpbuf
*odp_actions
)
2443 if (base
->skb_mark
== flow
->skb_mark
) {
2446 base
->skb_mark
= flow
->skb_mark
;
2448 odp_put_skb_mark_action(base
->skb_mark
, odp_actions
);
2450 /* If any of the flow key data that ODP actions can modify are different in
2451 * 'base' and 'flow', appends ODP actions to 'odp_actions' that change the flow
2452 * key from 'base' into 'flow', and then changes 'base' the same way. Does not
2453 * commit set_tunnel actions. Users should call commit_odp_tunnel_action()
2454 * in addition to this function if needed. */
2456 commit_odp_actions(const struct flow
*flow
, struct flow
*base
,
2457 struct ofpbuf
*odp_actions
)
2459 commit_set_ether_addr_action(flow
, base
, odp_actions
);
2460 commit_vlan_action(flow
, base
, odp_actions
);
2461 commit_set_nw_action(flow
, base
, odp_actions
);
2462 commit_set_port_action(flow
, base
, odp_actions
);
2463 /* Committing MPLS actions should occur after committing nw and port
2464 * actions. This is because committing MPLS actions may alter a packet so
2465 * that it is no longer IP and thus nw and port actions are no longer valid.
2467 commit_mpls_action(flow
, base
, odp_actions
);
2468 commit_set_priority_action(flow
, base
, odp_actions
);
2469 commit_set_skb_mark_action(flow
, base
, odp_actions
);