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_mask_attr(const char *, const struct simap *port_names,
52 struct ofpbuf *, struct ofpbuf *);
53 static void format_odp_key_attr(const struct nlattr *a,
54 const struct nlattr *ma,
55 const struct hmap *portno_names, struct ds *ds,
58 /* Returns one the following for the action with the given OVS_ACTION_ATTR_*
61 * - For an action whose argument has a fixed length, returned that
62 * nonnegative length in bytes.
64 * - For an action with a variable-length argument, returns -2.
66 * - For an invalid 'type', returns -1. */
68 odp_action_len(uint16_t type)
70 if (type > OVS_ACTION_ATTR_MAX) {
74 switch ((enum ovs_action_attr) type) {
75 case OVS_ACTION_ATTR_OUTPUT: return sizeof(uint32_t);
76 case OVS_ACTION_ATTR_USERSPACE: return -2;
77 case OVS_ACTION_ATTR_PUSH_VLAN: return sizeof(struct ovs_action_push_vlan);
78 case OVS_ACTION_ATTR_POP_VLAN: return 0;
79 case OVS_ACTION_ATTR_PUSH_MPLS: return sizeof(struct ovs_action_push_mpls);
80 case OVS_ACTION_ATTR_POP_MPLS: return sizeof(ovs_be16);
81 case OVS_ACTION_ATTR_SET: return -2;
82 case OVS_ACTION_ATTR_SAMPLE: return -2;
84 case OVS_ACTION_ATTR_UNSPEC:
85 case __OVS_ACTION_ATTR_MAX:
92 /* Returns a string form of 'attr'. The return value is either a statically
93 * allocated constant string or the 'bufsize'-byte buffer 'namebuf'. 'bufsize'
94 * should be at least OVS_KEY_ATTR_BUFSIZE. */
95 enum { OVS_KEY_ATTR_BUFSIZE = 3 + INT_STRLEN(unsigned int) + 1 };
97 ovs_key_attr_to_string(enum ovs_key_attr attr, char *namebuf, size_t bufsize)
100 case OVS_KEY_ATTR_UNSPEC: return "unspec";
101 case OVS_KEY_ATTR_ENCAP: return "encap";
102 case OVS_KEY_ATTR_PRIORITY: return "skb_priority";
103 case OVS_KEY_ATTR_SKB_MARK: return "skb_mark";
104 case OVS_KEY_ATTR_TUNNEL: return "tunnel";
105 case OVS_KEY_ATTR_IN_PORT: return "in_port";
106 case OVS_KEY_ATTR_ETHERNET: return "eth";
107 case OVS_KEY_ATTR_VLAN: return "vlan";
108 case OVS_KEY_ATTR_ETHERTYPE: return "eth_type";
109 case OVS_KEY_ATTR_IPV4: return "ipv4";
110 case OVS_KEY_ATTR_IPV6: return "ipv6";
111 case OVS_KEY_ATTR_TCP: return "tcp";
112 case OVS_KEY_ATTR_UDP: return "udp";
113 case OVS_KEY_ATTR_SCTP: return "sctp";
114 case OVS_KEY_ATTR_ICMP: return "icmp";
115 case OVS_KEY_ATTR_ICMPV6: return "icmpv6";
116 case OVS_KEY_ATTR_ARP: return "arp";
117 case OVS_KEY_ATTR_ND: return "nd";
118 case OVS_KEY_ATTR_MPLS: return "mpls";
120 case __OVS_KEY_ATTR_MAX:
122 snprintf(namebuf, bufsize, "key%u", (unsigned int) attr);
128 format_generic_odp_action(struct ds *ds, const struct nlattr *a)
130 size_t len = nl_attr_get_size(a);
132 ds_put_format(ds, "action%"PRId16, nl_attr_type(a));
134 const uint8_t *unspec;
137 unspec = nl_attr_get(a);
138 for (i = 0; i < len; i++) {
139 ds_put_char(ds, i ? ' ': '(');
140 ds_put_format(ds, "%02x", unspec[i]);
142 ds_put_char(ds, ')');
147 format_odp_sample_action(struct ds *ds, const struct nlattr *attr)
149 static const struct nl_policy ovs_sample_policy[] = {
150 { NL_A_NO_ATTR, 0, 0, false }, /* OVS_SAMPLE_ATTR_UNSPEC */
151 { NL_A_U32, 0, 0, false }, /* OVS_SAMPLE_ATTR_PROBABILITY */
152 { NL_A_NESTED, 0, 0, false }, /* OVS_SAMPLE_ATTR_ACTIONS */
154 struct nlattr *a[ARRAY_SIZE(ovs_sample_policy)];
156 const struct nlattr *nla_acts;
159 ds_put_cstr(ds, "sample");
161 if (!nl_parse_nested(attr, ovs_sample_policy, a, ARRAY_SIZE(a))) {
162 ds_put_cstr(ds, "(error)");
166 percentage = (100.0 * nl_attr_get_u32(a[OVS_SAMPLE_ATTR_PROBABILITY])) /
169 ds_put_format(ds, "(sample=%.1f%%,", percentage);
171 ds_put_cstr(ds, "actions(");
172 nla_acts = nl_attr_get(a[OVS_SAMPLE_ATTR_ACTIONS]);
173 len = nl_attr_get_size(a[OVS_SAMPLE_ATTR_ACTIONS]);
174 format_odp_actions(ds, nla_acts, len);
175 ds_put_format(ds, "))");
179 slow_path_reason_to_string(uint32_t reason)
181 switch ((enum slow_path_reason) reason) {
182 #define SPR(ENUM, STRING, EXPLANATION) case ENUM: return STRING;
191 slow_path_reason_to_explanation(enum slow_path_reason reason)
194 #define SPR(ENUM, STRING, EXPLANATION) case ENUM: return EXPLANATION;
203 parse_flags(const char *s, const char *(*bit_to_string)(uint32_t),
214 while (s[n] != ')') {
215 unsigned long long int flags;
219 if (sscanf(&s[n], "%lli%n", &flags, &n0) > 0 && n0 > 0) {
220 n += n0 + (s[n + n0] == ',');
225 for (bit = 1; bit; bit <<= 1) {
226 const char *name = bit_to_string(bit);
234 if (!strncmp(s + n, name, len) &&
235 (s[n + len] == ',' || s[n + len] == ')')) {
237 n += len + (s[n + len] == ',');
253 format_odp_userspace_action(struct ds *ds, const struct nlattr *attr)
255 static const struct nl_policy ovs_userspace_policy[] = {
256 { NL_A_NO_ATTR, 0, 0, false }, /* OVS_USERSPACE_ATTR_UNSPEC */
257 { NL_A_U32, 0, 0, false }, /* OVS_USERSPACE_ATTR_PID */
258 { NL_A_UNSPEC, 0, 0, true }, /* OVS_USERSPACE_ATTR_USERDATA */
260 struct nlattr *a[ARRAY_SIZE(ovs_userspace_policy)];
261 const struct nlattr *userdata_attr;
263 if (!nl_parse_nested(attr, ovs_userspace_policy, a, ARRAY_SIZE(a))) {
264 ds_put_cstr(ds, "userspace(error)");
268 ds_put_format(ds, "userspace(pid=%"PRIu32,
269 nl_attr_get_u32(a[OVS_USERSPACE_ATTR_PID]));
271 userdata_attr = a[OVS_USERSPACE_ATTR_USERDATA];
274 const uint8_t *userdata = nl_attr_get(userdata_attr);
275 size_t userdata_len = nl_attr_get_size(userdata_attr);
276 bool userdata_unspec = true;
277 union user_action_cookie cookie;
279 if (userdata_len >= sizeof cookie.type
280 && userdata_len <= sizeof cookie) {
282 memset(&cookie, 0, sizeof cookie);
283 memcpy(&cookie, userdata, userdata_len);
285 userdata_unspec = false;
287 if (userdata_len == sizeof cookie.sflow
288 && cookie.type == USER_ACTION_COOKIE_SFLOW) {
289 ds_put_format(ds, ",sFlow("
290 "vid=%"PRIu16",pcp=%"PRIu8",output=%"PRIu32")",
291 vlan_tci_to_vid(cookie.sflow.vlan_tci),
292 vlan_tci_to_pcp(cookie.sflow.vlan_tci),
293 cookie.sflow.output);
294 } else if (userdata_len == sizeof cookie.slow_path
295 && cookie.type == USER_ACTION_COOKIE_SLOW_PATH) {
296 ds_put_cstr(ds, ",slow_path(");
297 format_flags(ds, slow_path_reason_to_string,
298 cookie.slow_path.reason, ',');
299 ds_put_format(ds, ")");
300 } else if (userdata_len == sizeof cookie.flow_sample
301 && cookie.type == USER_ACTION_COOKIE_FLOW_SAMPLE) {
302 ds_put_format(ds, ",flow_sample(probability=%"PRIu16
303 ",collector_set_id=%"PRIu32
304 ",obs_domain_id=%"PRIu32
305 ",obs_point_id=%"PRIu32")",
306 cookie.flow_sample.probability,
307 cookie.flow_sample.collector_set_id,
308 cookie.flow_sample.obs_domain_id,
309 cookie.flow_sample.obs_point_id);
310 } else if (userdata_len == sizeof cookie.ipfix
311 && cookie.type == USER_ACTION_COOKIE_IPFIX) {
312 ds_put_format(ds, ",ipfix");
314 userdata_unspec = true;
318 if (userdata_unspec) {
320 ds_put_format(ds, ",userdata(");
321 for (i = 0; i < userdata_len; i++) {
322 ds_put_format(ds, "%02x", userdata[i]);
324 ds_put_char(ds, ')');
328 ds_put_char(ds, ')');
332 format_vlan_tci(struct ds *ds, ovs_be16 vlan_tci)
334 ds_put_format(ds, "vid=%"PRIu16",pcp=%d",
335 vlan_tci_to_vid(vlan_tci),
336 vlan_tci_to_pcp(vlan_tci));
337 if (!(vlan_tci & htons(VLAN_CFI))) {
338 ds_put_cstr(ds, ",cfi=0");
343 format_mpls_lse(struct ds *ds, ovs_be32 mpls_lse)
345 ds_put_format(ds, "label=%"PRIu32",tc=%d,ttl=%d,bos=%d",
346 mpls_lse_to_label(mpls_lse),
347 mpls_lse_to_tc(mpls_lse),
348 mpls_lse_to_ttl(mpls_lse),
349 mpls_lse_to_bos(mpls_lse));
353 format_mpls(struct ds *ds, const struct ovs_key_mpls *mpls_key,
354 const struct ovs_key_mpls *mpls_mask)
356 ovs_be32 key = mpls_key->mpls_lse;
358 if (mpls_mask == NULL) {
359 format_mpls_lse(ds, key);
361 ovs_be32 mask = mpls_mask->mpls_lse;
363 ds_put_format(ds, "label=%"PRIu32"/0x%x,tc=%d/%x,ttl=%d/0x%x,bos=%d/%x",
364 mpls_lse_to_label(key), mpls_lse_to_label(mask),
365 mpls_lse_to_tc(key), mpls_lse_to_tc(mask),
366 mpls_lse_to_ttl(key), mpls_lse_to_ttl(mask),
367 mpls_lse_to_bos(key), mpls_lse_to_bos(mask));
372 format_odp_action(struct ds *ds, const struct nlattr *a)
375 enum ovs_action_attr type = nl_attr_type(a);
376 const struct ovs_action_push_vlan *vlan;
378 expected_len = odp_action_len(nl_attr_type(a));
379 if (expected_len != -2 && nl_attr_get_size(a) != expected_len) {
380 ds_put_format(ds, "bad length %zu, expected %d for: ",
381 nl_attr_get_size(a), expected_len);
382 format_generic_odp_action(ds, a);
387 case OVS_ACTION_ATTR_OUTPUT:
388 ds_put_format(ds, "%"PRIu32, nl_attr_get_u32(a));
390 case OVS_ACTION_ATTR_USERSPACE:
391 format_odp_userspace_action(ds, a);
393 case OVS_ACTION_ATTR_SET:
394 ds_put_cstr(ds, "set(");
395 format_odp_key_attr(nl_attr_get(a), NULL, NULL, ds, true);
396 ds_put_cstr(ds, ")");
398 case OVS_ACTION_ATTR_PUSH_VLAN:
399 vlan = nl_attr_get(a);
400 ds_put_cstr(ds, "push_vlan(");
401 if (vlan->vlan_tpid != htons(ETH_TYPE_VLAN)) {
402 ds_put_format(ds, "tpid=0x%04"PRIx16",", ntohs(vlan->vlan_tpid));
404 format_vlan_tci(ds, vlan->vlan_tci);
405 ds_put_char(ds, ')');
407 case OVS_ACTION_ATTR_POP_VLAN:
408 ds_put_cstr(ds, "pop_vlan");
410 case OVS_ACTION_ATTR_PUSH_MPLS: {
411 const struct ovs_action_push_mpls *mpls = nl_attr_get(a);
412 ds_put_cstr(ds, "push_mpls(");
413 format_mpls_lse(ds, mpls->mpls_lse);
414 ds_put_format(ds, ",eth_type=0x%"PRIx16")", ntohs(mpls->mpls_ethertype));
417 case OVS_ACTION_ATTR_POP_MPLS: {
418 ovs_be16 ethertype = nl_attr_get_be16(a);
419 ds_put_format(ds, "pop_mpls(eth_type=0x%"PRIx16")", ntohs(ethertype));
422 case OVS_ACTION_ATTR_SAMPLE:
423 format_odp_sample_action(ds, a);
425 case OVS_ACTION_ATTR_UNSPEC:
426 case __OVS_ACTION_ATTR_MAX:
428 format_generic_odp_action(ds, a);
434 format_odp_actions(struct ds *ds, const struct nlattr *actions,
438 const struct nlattr *a;
441 NL_ATTR_FOR_EACH (a, left, actions, actions_len) {
443 ds_put_char(ds, ',');
445 format_odp_action(ds, a);
450 if (left == actions_len) {
451 ds_put_cstr(ds, "<empty>");
453 ds_put_format(ds, ",***%u leftover bytes*** (", left);
454 for (i = 0; i < left; i++) {
455 ds_put_format(ds, "%02x", ((const uint8_t *) a)[i]);
457 ds_put_char(ds, ')');
460 ds_put_cstr(ds, "drop");
465 parse_odp_action(const char *s, const struct simap *port_names,
466 struct ofpbuf *actions)
468 /* Many of the sscanf calls in this function use oversized destination
469 * fields because some sscanf() implementations truncate the range of %i
470 * directives, so that e.g. "%"SCNi16 interprets input of "0xfedc" as a
471 * value of 0x7fff. The other alternatives are to allow only a single
472 * radix (e.g. decimal or hexadecimal) or to write more sophisticated
475 * The tun_id parser has to use an alternative approach because there is no
476 * type larger than 64 bits. */
479 unsigned long long int port;
482 if (sscanf(s, "%lli%n", &port, &n) > 0 && n > 0) {
483 nl_msg_put_u32(actions, OVS_ACTION_ATTR_OUTPUT, port);
489 int len = strcspn(s, delimiters);
490 struct simap_node *node;
492 node = simap_find_len(port_names, s, len);
494 nl_msg_put_u32(actions, OVS_ACTION_ATTR_OUTPUT, node->data);
500 unsigned long long int pid;
501 unsigned long long int output;
502 unsigned long long int probability;
503 unsigned long long int collector_set_id;
504 unsigned long long int obs_domain_id;
505 unsigned long long int obs_point_id;
509 if (sscanf(s, "userspace(pid=%lli)%n", &pid, &n) > 0 && n > 0) {
510 odp_put_userspace_action(pid, NULL, 0, actions);
512 } else if (sscanf(s, "userspace(pid=%lli,sFlow(vid=%i,"
513 "pcp=%i,output=%lli))%n",
514 &pid, &vid, &pcp, &output, &n) > 0 && n > 0) {
515 union user_action_cookie cookie;
518 tci = vid | (pcp << VLAN_PCP_SHIFT);
523 cookie.type = USER_ACTION_COOKIE_SFLOW;
524 cookie.sflow.vlan_tci = htons(tci);
525 cookie.sflow.output = output;
526 odp_put_userspace_action(pid, &cookie, sizeof cookie.sflow,
529 } else if (sscanf(s, "userspace(pid=%lli,slow_path%n", &pid, &n) > 0
531 union user_action_cookie cookie;
534 cookie.type = USER_ACTION_COOKIE_SLOW_PATH;
535 cookie.slow_path.unused = 0;
536 cookie.slow_path.reason = 0;
538 res = parse_flags(&s[n], slow_path_reason_to_string,
539 &cookie.slow_path.reason);
549 odp_put_userspace_action(pid, &cookie, sizeof cookie.slow_path,
552 } else if (sscanf(s, "userspace(pid=%lli,flow_sample(probability=%lli,"
553 "collector_set_id=%lli,obs_domain_id=%lli,"
554 "obs_point_id=%lli))%n",
555 &pid, &probability, &collector_set_id,
556 &obs_domain_id, &obs_point_id, &n) > 0 && n > 0) {
557 union user_action_cookie cookie;
559 cookie.type = USER_ACTION_COOKIE_FLOW_SAMPLE;
560 cookie.flow_sample.probability = probability;
561 cookie.flow_sample.collector_set_id = collector_set_id;
562 cookie.flow_sample.obs_domain_id = obs_domain_id;
563 cookie.flow_sample.obs_point_id = obs_point_id;
564 odp_put_userspace_action(pid, &cookie, sizeof cookie.flow_sample,
567 } else if (sscanf(s, "userspace(pid=%lli,ipfix)%n", &pid, &n) > 0
569 union user_action_cookie cookie;
571 cookie.type = USER_ACTION_COOKIE_IPFIX;
572 odp_put_userspace_action(pid, &cookie, sizeof cookie.ipfix,
575 } else if (sscanf(s, "userspace(pid=%lli,userdata(%n", &pid, &n) > 0
580 ofpbuf_init(&buf, 16);
581 end = ofpbuf_put_hex(&buf, &s[n], NULL);
582 if (end[0] == ')' && end[1] == ')') {
583 odp_put_userspace_action(pid, buf.data, buf.size, actions);
585 return (end + 2) - s;
590 if (!strncmp(s, "set(", 4)) {
594 start_ofs = nl_msg_start_nested(actions, OVS_ACTION_ATTR_SET);
595 retval = parse_odp_key_mask_attr(s + 4, port_names, actions, NULL);
599 if (s[retval + 4] != ')') {
602 nl_msg_end_nested(actions, start_ofs);
607 struct ovs_action_push_vlan push;
608 int tpid = ETH_TYPE_VLAN;
613 if ((sscanf(s, "push_vlan(vid=%i,pcp=%i)%n", &vid, &pcp, &n) > 0
615 || (sscanf(s, "push_vlan(vid=%i,pcp=%i,cfi=%i)%n",
616 &vid, &pcp, &cfi, &n) > 0 && n > 0)
617 || (sscanf(s, "push_vlan(tpid=%i,vid=%i,pcp=%i)%n",
618 &tpid, &vid, &pcp, &n) > 0 && n > 0)
619 || (sscanf(s, "push_vlan(tpid=%i,vid=%i,pcp=%i,cfi=%i)%n",
620 &tpid, &vid, &pcp, &cfi, &n) > 0 && n > 0)) {
621 push.vlan_tpid = htons(tpid);
622 push.vlan_tci = htons((vid << VLAN_VID_SHIFT)
623 | (pcp << VLAN_PCP_SHIFT)
624 | (cfi ? VLAN_CFI : 0));
625 nl_msg_put_unspec(actions, OVS_ACTION_ATTR_PUSH_VLAN,
632 if (!strncmp(s, "pop_vlan", 8)) {
633 nl_msg_put_flag(actions, OVS_ACTION_ATTR_POP_VLAN);
641 if (sscanf(s, "sample(sample=%lf%%,actions(%n", &percentage, &n) > 0
642 && percentage >= 0. && percentage <= 100.0
644 size_t sample_ofs, actions_ofs;
647 probability = floor(UINT32_MAX * (percentage / 100.0) + .5);
648 sample_ofs = nl_msg_start_nested(actions, OVS_ACTION_ATTR_SAMPLE);
649 nl_msg_put_u32(actions, OVS_SAMPLE_ATTR_PROBABILITY,
650 (probability <= 0 ? 0
651 : probability >= UINT32_MAX ? UINT32_MAX
654 actions_ofs = nl_msg_start_nested(actions,
655 OVS_SAMPLE_ATTR_ACTIONS);
659 n += strspn(s + n, delimiters);
664 retval = parse_odp_action(s + n, port_names, actions);
670 nl_msg_end_nested(actions, actions_ofs);
671 nl_msg_end_nested(actions, sample_ofs);
673 return s[n + 1] == ')' ? n + 2 : -EINVAL;
680 /* Parses the string representation of datapath actions, in the format output
681 * by format_odp_action(). Returns 0 if successful, otherwise a positive errno
682 * value. On success, the ODP actions are appended to 'actions' as a series of
683 * Netlink attributes. On failure, no data is appended to 'actions'. Either
684 * way, 'actions''s data might be reallocated. */
686 odp_actions_from_string(const char *s, const struct simap *port_names,
687 struct ofpbuf *actions)
691 if (!strcasecmp(s, "drop")) {
695 old_size = actions->size;
699 s += strspn(s, delimiters);
704 retval = parse_odp_action(s, port_names, actions);
705 if (retval < 0 || !strchr(delimiters, s[retval])) {
706 actions->size = old_size;
715 /* Returns the correct length of the payload for a flow key attribute of the
716 * specified 'type', -1 if 'type' is unknown, or -2 if the attribute's payload
717 * is variable length. */
719 odp_flow_key_attr_len(uint16_t type)
721 if (type > OVS_KEY_ATTR_MAX) {
725 switch ((enum ovs_key_attr) type) {
726 case OVS_KEY_ATTR_ENCAP: return -2;
727 case OVS_KEY_ATTR_PRIORITY: return 4;
728 case OVS_KEY_ATTR_SKB_MARK: return 4;
729 case OVS_KEY_ATTR_TUNNEL: return -2;
730 case OVS_KEY_ATTR_IN_PORT: return 4;
731 case OVS_KEY_ATTR_ETHERNET: return sizeof(struct ovs_key_ethernet);
732 case OVS_KEY_ATTR_VLAN: return sizeof(ovs_be16);
733 case OVS_KEY_ATTR_ETHERTYPE: return 2;
734 case OVS_KEY_ATTR_MPLS: return sizeof(struct ovs_key_mpls);
735 case OVS_KEY_ATTR_IPV4: return sizeof(struct ovs_key_ipv4);
736 case OVS_KEY_ATTR_IPV6: return sizeof(struct ovs_key_ipv6);
737 case OVS_KEY_ATTR_TCP: return sizeof(struct ovs_key_tcp);
738 case OVS_KEY_ATTR_UDP: return sizeof(struct ovs_key_udp);
739 case OVS_KEY_ATTR_SCTP: return sizeof(struct ovs_key_sctp);
740 case OVS_KEY_ATTR_ICMP: return sizeof(struct ovs_key_icmp);
741 case OVS_KEY_ATTR_ICMPV6: return sizeof(struct ovs_key_icmpv6);
742 case OVS_KEY_ATTR_ARP: return sizeof(struct ovs_key_arp);
743 case OVS_KEY_ATTR_ND: return sizeof(struct ovs_key_nd);
745 case OVS_KEY_ATTR_UNSPEC:
746 case __OVS_KEY_ATTR_MAX:
754 format_generic_odp_key(const struct nlattr *a, struct ds *ds)
756 size_t len = nl_attr_get_size(a);
758 const uint8_t *unspec;
761 unspec = nl_attr_get(a);
762 for (i = 0; i < len; i++) {
764 ds_put_char(ds, ' ');
766 ds_put_format(ds, "%02x", unspec[i]);
772 ovs_frag_type_to_string(enum ovs_frag_type type)
775 case OVS_FRAG_TYPE_NONE:
777 case OVS_FRAG_TYPE_FIRST:
779 case OVS_FRAG_TYPE_LATER:
781 case __OVS_FRAG_TYPE_MAX:
788 tunnel_key_attr_len(int type)
791 case OVS_TUNNEL_KEY_ATTR_ID: return 8;
792 case OVS_TUNNEL_KEY_ATTR_IPV4_SRC: return 4;
793 case OVS_TUNNEL_KEY_ATTR_IPV4_DST: return 4;
794 case OVS_TUNNEL_KEY_ATTR_TOS: return 1;
795 case OVS_TUNNEL_KEY_ATTR_TTL: return 1;
796 case OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT: return 0;
797 case OVS_TUNNEL_KEY_ATTR_CSUM: return 0;
798 case __OVS_TUNNEL_KEY_ATTR_MAX:
805 odp_tun_key_from_attr(const struct nlattr *attr, struct flow_tnl *tun)
808 const struct nlattr *a;
810 bool unknown = false;
812 NL_NESTED_FOR_EACH(a, left, attr) {
813 uint16_t type = nl_attr_type(a);
814 size_t len = nl_attr_get_size(a);
815 int expected_len = tunnel_key_attr_len(type);
817 if (len != expected_len && expected_len >= 0) {
818 return ODP_FIT_ERROR;
822 case OVS_TUNNEL_KEY_ATTR_ID:
823 tun->tun_id = nl_attr_get_be64(a);
824 tun->flags |= FLOW_TNL_F_KEY;
826 case OVS_TUNNEL_KEY_ATTR_IPV4_SRC:
827 tun->ip_src = nl_attr_get_be32(a);
829 case OVS_TUNNEL_KEY_ATTR_IPV4_DST:
830 tun->ip_dst = nl_attr_get_be32(a);
832 case OVS_TUNNEL_KEY_ATTR_TOS:
833 tun->ip_tos = nl_attr_get_u8(a);
835 case OVS_TUNNEL_KEY_ATTR_TTL:
836 tun->ip_ttl = nl_attr_get_u8(a);
839 case OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT:
840 tun->flags |= FLOW_TNL_F_DONT_FRAGMENT;
842 case OVS_TUNNEL_KEY_ATTR_CSUM:
843 tun->flags |= FLOW_TNL_F_CSUM;
846 /* Allow this to show up as unexpected, if there are unknown
847 * tunnel attribute, eventually resulting in ODP_FIT_TOO_MUCH. */
854 return ODP_FIT_ERROR;
857 return ODP_FIT_TOO_MUCH;
859 return ODP_FIT_PERFECT;
863 tun_key_to_attr(struct ofpbuf *a, const struct flow_tnl *tun_key)
867 tun_key_ofs = nl_msg_start_nested(a, OVS_KEY_ATTR_TUNNEL);
869 if (tun_key->flags & FLOW_TNL_F_KEY) {
870 nl_msg_put_be64(a, OVS_TUNNEL_KEY_ATTR_ID, tun_key->tun_id);
872 if (tun_key->ip_src) {
873 nl_msg_put_be32(a, OVS_TUNNEL_KEY_ATTR_IPV4_SRC, tun_key->ip_src);
875 if (tun_key->ip_dst) {
876 nl_msg_put_be32(a, OVS_TUNNEL_KEY_ATTR_IPV4_DST, tun_key->ip_dst);
878 if (tun_key->ip_tos) {
879 nl_msg_put_u8(a, OVS_TUNNEL_KEY_ATTR_TOS, tun_key->ip_tos);
881 nl_msg_put_u8(a, OVS_TUNNEL_KEY_ATTR_TTL, tun_key->ip_ttl);
882 if (tun_key->flags & FLOW_TNL_F_DONT_FRAGMENT) {
883 nl_msg_put_flag(a, OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT);
885 if (tun_key->flags & FLOW_TNL_F_CSUM) {
886 nl_msg_put_flag(a, OVS_TUNNEL_KEY_ATTR_CSUM);
889 nl_msg_end_nested(a, tun_key_ofs);
893 odp_mask_attr_is_wildcard(const struct nlattr *ma)
895 return is_all_zeros(nl_attr_get(ma), nl_attr_get_size(ma));
899 odp_mask_attr_is_exact(const struct nlattr *ma)
901 bool is_exact = false;
902 enum ovs_key_attr attr = nl_attr_type(ma);
904 if (attr == OVS_KEY_ATTR_TUNNEL) {
905 /* XXX this is a hack for now. Should change
906 * the exact match dection to per field
907 * instead of per attribute.
909 struct flow_tnl tun_mask;
910 memset(&tun_mask, 0, sizeof tun_mask);
911 odp_tun_key_from_attr(ma, &tun_mask);
912 if (tun_mask.flags == (FLOW_TNL_F_KEY
913 | FLOW_TNL_F_DONT_FRAGMENT
914 | FLOW_TNL_F_CSUM)) {
915 /* The flags are exact match, check the remaining fields. */
916 tun_mask.flags = 0xffff;
917 is_exact = is_all_ones((uint8_t *)&tun_mask,
918 offsetof(struct flow_tnl, ip_ttl));
921 is_exact = is_all_ones(nl_attr_get(ma), nl_attr_get_size(ma));
928 odp_portno_names_set(struct hmap *portno_names, odp_port_t port_no,
931 struct odp_portno_names *odp_portno_names;
933 odp_portno_names = xmalloc(sizeof *odp_portno_names);
934 odp_portno_names->port_no = port_no;
935 odp_portno_names->name = xstrdup(port_name);
936 hmap_insert(portno_names, &odp_portno_names->hmap_node,
937 hash_odp_port(port_no));
941 odp_portno_names_get(const struct hmap *portno_names, odp_port_t port_no)
943 struct odp_portno_names *odp_portno_names;
945 HMAP_FOR_EACH_IN_BUCKET (odp_portno_names, hmap_node,
946 hash_odp_port(port_no), portno_names) {
947 if (odp_portno_names->port_no == port_no) {
948 return odp_portno_names->name;
955 odp_portno_names_destroy(struct hmap *portno_names)
957 struct odp_portno_names *odp_portno_names, *odp_portno_names_next;
958 HMAP_FOR_EACH_SAFE (odp_portno_names, odp_portno_names_next,
959 hmap_node, portno_names) {
960 hmap_remove(portno_names, &odp_portno_names->hmap_node);
961 free(odp_portno_names->name);
962 free(odp_portno_names);
967 format_odp_key_attr(const struct nlattr *a, const struct nlattr *ma,
968 const struct hmap *portno_names, struct ds *ds,
971 struct flow_tnl tun_key;
972 enum ovs_key_attr attr = nl_attr_type(a);
973 char namebuf[OVS_KEY_ATTR_BUFSIZE];
977 is_exact = ma ? odp_mask_attr_is_exact(ma) : true;
979 ds_put_cstr(ds, ovs_key_attr_to_string(attr, namebuf, sizeof namebuf));
982 expected_len = odp_flow_key_attr_len(nl_attr_type(a));
983 if (expected_len != -2) {
984 bool bad_key_len = nl_attr_get_size(a) != expected_len;
985 bool bad_mask_len = ma && nl_attr_get_size(a) != expected_len;
987 if (bad_key_len || bad_mask_len) {
989 ds_put_format(ds, "(bad key length %zu, expected %d)(",
991 odp_flow_key_attr_len(nl_attr_type(a)));
993 format_generic_odp_key(a, ds);
995 ds_put_char(ds, '/');
996 ds_put_format(ds, "(bad mask length %zu, expected %d)(",
997 nl_attr_get_size(ma),
998 odp_flow_key_attr_len(nl_attr_type(ma)));
1000 format_generic_odp_key(ma, ds);
1001 ds_put_char(ds, ')');
1007 ds_put_char(ds, '(');
1009 case OVS_KEY_ATTR_ENCAP:
1010 if (ma && nl_attr_get_size(ma) && nl_attr_get_size(a)) {
1011 odp_flow_format(nl_attr_get(a), nl_attr_get_size(a),
1012 nl_attr_get(ma), nl_attr_get_size(ma), NULL, ds,
1014 } else if (nl_attr_get_size(a)) {
1015 odp_flow_format(nl_attr_get(a), nl_attr_get_size(a), NULL, 0, NULL,
1020 case OVS_KEY_ATTR_PRIORITY:
1021 case OVS_KEY_ATTR_SKB_MARK:
1022 ds_put_format(ds, "%#"PRIx32, nl_attr_get_u32(a));
1024 ds_put_format(ds, "/%#"PRIx32, nl_attr_get_u32(ma));
1028 case OVS_KEY_ATTR_TUNNEL:
1029 memset(&tun_key, 0, sizeof tun_key);
1030 if (odp_tun_key_from_attr(a, &tun_key) == ODP_FIT_ERROR) {
1031 ds_put_format(ds, "error");
1032 } else if (!is_exact) {
1033 struct flow_tnl tun_mask;
1035 memset(&tun_mask, 0, sizeof tun_mask);
1036 odp_tun_key_from_attr(ma, &tun_mask);
1037 ds_put_format(ds, "tun_id=%#"PRIx64"/%#"PRIx64
1038 ",src="IP_FMT"/"IP_FMT",dst="IP_FMT"/"IP_FMT
1039 ",tos=%#"PRIx8"/%#"PRIx8",ttl=%"PRIu8"/%#"PRIx8
1041 ntohll(tun_key.tun_id), ntohll(tun_mask.tun_id),
1042 IP_ARGS(tun_key.ip_src), IP_ARGS(tun_mask.ip_src),
1043 IP_ARGS(tun_key.ip_dst), IP_ARGS(tun_mask.ip_dst),
1044 tun_key.ip_tos, tun_mask.ip_tos,
1045 tun_key.ip_ttl, tun_mask.ip_ttl);
1047 format_flags(ds, flow_tun_flag_to_string, tun_key.flags, ',');
1049 /* XXX This code is correct, but enabling it would break the unit
1050 test. Disable it for now until the input parser is fixed.
1052 ds_put_char(ds, '/');
1053 format_flags(ds, flow_tun_flag_to_string, tun_mask.flags, ',');
1055 ds_put_char(ds, ')');
1057 ds_put_format(ds, "tun_id=0x%"PRIx64",src="IP_FMT",dst="IP_FMT","
1058 "tos=0x%"PRIx8",ttl=%"PRIu8",flags(",
1059 ntohll(tun_key.tun_id),
1060 IP_ARGS(tun_key.ip_src),
1061 IP_ARGS(tun_key.ip_dst),
1062 tun_key.ip_tos, tun_key.ip_ttl);
1064 format_flags(ds, flow_tun_flag_to_string, tun_key.flags, ',');
1065 ds_put_char(ds, ')');
1069 case OVS_KEY_ATTR_IN_PORT:
1070 if (portno_names && verbose && is_exact) {
1071 char *name = odp_portno_names_get(portno_names,
1072 u32_to_odp(nl_attr_get_u32(a)));
1074 ds_put_format(ds, "%s", name);
1076 ds_put_format(ds, "%"PRIu32, nl_attr_get_u32(a));
1079 ds_put_format(ds, "%"PRIu32, nl_attr_get_u32(a));
1081 ds_put_format(ds, "/%#"PRIx32, nl_attr_get_u32(ma));
1086 case OVS_KEY_ATTR_ETHERNET:
1088 const struct ovs_key_ethernet *eth_mask = nl_attr_get(ma);
1089 const struct ovs_key_ethernet *eth_key = nl_attr_get(a);
1091 ds_put_format(ds, "src="ETH_ADDR_FMT"/"ETH_ADDR_FMT
1092 ",dst="ETH_ADDR_FMT"/"ETH_ADDR_FMT,
1093 ETH_ADDR_ARGS(eth_key->eth_src),
1094 ETH_ADDR_ARGS(eth_mask->eth_src),
1095 ETH_ADDR_ARGS(eth_key->eth_dst),
1096 ETH_ADDR_ARGS(eth_mask->eth_dst));
1098 const struct ovs_key_ethernet *eth_key = nl_attr_get(a);
1100 ds_put_format(ds, "src="ETH_ADDR_FMT",dst="ETH_ADDR_FMT,
1101 ETH_ADDR_ARGS(eth_key->eth_src),
1102 ETH_ADDR_ARGS(eth_key->eth_dst));
1106 case OVS_KEY_ATTR_VLAN:
1108 ovs_be16 vlan_tci = nl_attr_get_be16(a);
1110 ovs_be16 mask = nl_attr_get_be16(ma);
1111 ds_put_format(ds, "vid=%"PRIu16"/0x%"PRIx16",pcp=%d/0x%x,cfi=%d/%d",
1112 vlan_tci_to_vid(vlan_tci),
1113 vlan_tci_to_vid(mask),
1114 vlan_tci_to_pcp(vlan_tci),
1115 vlan_tci_to_pcp(mask),
1116 vlan_tci_to_cfi(vlan_tci),
1117 vlan_tci_to_cfi(mask));
1119 format_vlan_tci(ds, vlan_tci);
1124 case OVS_KEY_ATTR_MPLS: {
1125 const struct ovs_key_mpls *mpls_key = nl_attr_get(a);
1126 const struct ovs_key_mpls *mpls_mask = NULL;
1128 mpls_mask = nl_attr_get(ma);
1130 format_mpls(ds, mpls_key, mpls_mask);
1134 case OVS_KEY_ATTR_ETHERTYPE:
1135 ds_put_format(ds, "0x%04"PRIx16, ntohs(nl_attr_get_be16(a)));
1137 ds_put_format(ds, "/0x%04"PRIx16, ntohs(nl_attr_get_be16(ma)));
1141 case OVS_KEY_ATTR_IPV4:
1143 const struct ovs_key_ipv4 *ipv4_key = nl_attr_get(a);
1144 const struct ovs_key_ipv4 *ipv4_mask = nl_attr_get(ma);
1146 ds_put_format(ds, "src="IP_FMT"/"IP_FMT",dst="IP_FMT"/"IP_FMT
1147 ",proto=%"PRIu8"/%#"PRIx8",tos=%#"PRIx8"/%#"PRIx8
1148 ",ttl=%"PRIu8"/%#"PRIx8",frag=%s/%#"PRIx8,
1149 IP_ARGS(ipv4_key->ipv4_src),
1150 IP_ARGS(ipv4_mask->ipv4_src),
1151 IP_ARGS(ipv4_key->ipv4_dst),
1152 IP_ARGS(ipv4_mask->ipv4_dst),
1153 ipv4_key->ipv4_proto, ipv4_mask->ipv4_proto,
1154 ipv4_key->ipv4_tos, ipv4_mask->ipv4_tos,
1155 ipv4_key->ipv4_ttl, ipv4_mask->ipv4_ttl,
1156 ovs_frag_type_to_string(ipv4_key->ipv4_frag),
1157 ipv4_mask->ipv4_frag);
1159 const struct ovs_key_ipv4 *ipv4_key = nl_attr_get(a);
1161 ds_put_format(ds, "src="IP_FMT",dst="IP_FMT",proto=%"PRIu8
1162 ",tos=%#"PRIx8",ttl=%"PRIu8",frag=%s",
1163 IP_ARGS(ipv4_key->ipv4_src),
1164 IP_ARGS(ipv4_key->ipv4_dst),
1165 ipv4_key->ipv4_proto, ipv4_key->ipv4_tos,
1167 ovs_frag_type_to_string(ipv4_key->ipv4_frag));
1171 case OVS_KEY_ATTR_IPV6:
1173 const struct ovs_key_ipv6 *ipv6_key, *ipv6_mask;
1174 char src_str[INET6_ADDRSTRLEN];
1175 char dst_str[INET6_ADDRSTRLEN];
1176 char src_mask[INET6_ADDRSTRLEN];
1177 char dst_mask[INET6_ADDRSTRLEN];
1179 ipv6_key = nl_attr_get(a);
1180 inet_ntop(AF_INET6, ipv6_key->ipv6_src, src_str, sizeof src_str);
1181 inet_ntop(AF_INET6, ipv6_key->ipv6_dst, dst_str, sizeof dst_str);
1183 ipv6_mask = nl_attr_get(ma);
1184 inet_ntop(AF_INET6, ipv6_mask->ipv6_src, src_mask, sizeof src_mask);
1185 inet_ntop(AF_INET6, ipv6_mask->ipv6_dst, dst_mask, sizeof dst_mask);
1187 ds_put_format(ds, "src=%s/%s,dst=%s/%s,label=%#"PRIx32"/%#"PRIx32
1188 ",proto=%"PRIu8"/%#"PRIx8",tclass=%#"PRIx8"/%#"PRIx8
1189 ",hlimit=%"PRIu8"/%#"PRIx8",frag=%s/%#"PRIx8,
1190 src_str, src_mask, dst_str, dst_mask,
1191 ntohl(ipv6_key->ipv6_label),
1192 ntohl(ipv6_mask->ipv6_label),
1193 ipv6_key->ipv6_proto, ipv6_mask->ipv6_proto,
1194 ipv6_key->ipv6_tclass, ipv6_mask->ipv6_tclass,
1195 ipv6_key->ipv6_hlimit, ipv6_mask->ipv6_hlimit,
1196 ovs_frag_type_to_string(ipv6_key->ipv6_frag),
1197 ipv6_mask->ipv6_frag);
1199 const struct ovs_key_ipv6 *ipv6_key;
1200 char src_str[INET6_ADDRSTRLEN];
1201 char dst_str[INET6_ADDRSTRLEN];
1203 ipv6_key = nl_attr_get(a);
1204 inet_ntop(AF_INET6, ipv6_key->ipv6_src, src_str, sizeof src_str);
1205 inet_ntop(AF_INET6, ipv6_key->ipv6_dst, dst_str, sizeof dst_str);
1207 ds_put_format(ds, "src=%s,dst=%s,label=%#"PRIx32",proto=%"PRIu8
1208 ",tclass=%#"PRIx8",hlimit=%"PRIu8",frag=%s",
1209 src_str, dst_str, ntohl(ipv6_key->ipv6_label),
1210 ipv6_key->ipv6_proto, ipv6_key->ipv6_tclass,
1211 ipv6_key->ipv6_hlimit,
1212 ovs_frag_type_to_string(ipv6_key->ipv6_frag));
1216 case OVS_KEY_ATTR_TCP:
1218 const struct ovs_key_tcp *tcp_mask = nl_attr_get(ma);
1219 const struct ovs_key_tcp *tcp_key = nl_attr_get(a);
1221 ds_put_format(ds, "src=%"PRIu16"/%#"PRIx16
1222 ",dst=%"PRIu16"/%#"PRIx16,
1223 ntohs(tcp_key->tcp_src), ntohs(tcp_mask->tcp_src),
1224 ntohs(tcp_key->tcp_dst), ntohs(tcp_mask->tcp_dst));
1226 const struct ovs_key_tcp *tcp_key = nl_attr_get(a);
1228 ds_put_format(ds, "src=%"PRIu16",dst=%"PRIu16,
1229 ntohs(tcp_key->tcp_src), ntohs(tcp_key->tcp_dst));
1233 case OVS_KEY_ATTR_UDP:
1235 const struct ovs_key_udp *udp_mask = nl_attr_get(ma);
1236 const struct ovs_key_udp *udp_key = nl_attr_get(a);
1238 ds_put_format(ds, "src=%"PRIu16"/%#"PRIx16
1239 ",dst=%"PRIu16"/%#"PRIx16,
1240 ntohs(udp_key->udp_src), ntohs(udp_mask->udp_src),
1241 ntohs(udp_key->udp_dst), ntohs(udp_mask->udp_dst));
1243 const struct ovs_key_udp *udp_key = nl_attr_get(a);
1245 ds_put_format(ds, "src=%"PRIu16",dst=%"PRIu16,
1246 ntohs(udp_key->udp_src), ntohs(udp_key->udp_dst));
1250 case OVS_KEY_ATTR_SCTP:
1252 const struct ovs_key_sctp *sctp_mask = nl_attr_get(ma);
1253 const struct ovs_key_sctp *sctp_key = nl_attr_get(a);
1255 ds_put_format(ds, "src=%"PRIu16"/%#"PRIx16
1256 ",dst=%"PRIu16"/%#"PRIx16,
1257 ntohs(sctp_key->sctp_src), ntohs(sctp_mask->sctp_src),
1258 ntohs(sctp_key->sctp_dst), ntohs(sctp_mask->sctp_dst));
1260 const struct ovs_key_sctp *sctp_key = nl_attr_get(a);
1262 ds_put_format(ds, "(src=%"PRIu16",dst=%"PRIu16")",
1263 ntohs(sctp_key->sctp_src), ntohs(sctp_key->sctp_dst));
1267 case OVS_KEY_ATTR_ICMP:
1269 const struct ovs_key_icmp *icmp_mask = nl_attr_get(ma);
1270 const struct ovs_key_icmp *icmp_key = nl_attr_get(a);
1272 ds_put_format(ds, "type=%"PRIu8"/%#"PRIx8",code=%"PRIu8"/%#"PRIx8,
1273 icmp_key->icmp_type, icmp_mask->icmp_type,
1274 icmp_key->icmp_code, icmp_mask->icmp_code);
1276 const struct ovs_key_icmp *icmp_key = nl_attr_get(a);
1278 ds_put_format(ds, "type=%"PRIu8",code=%"PRIu8,
1279 icmp_key->icmp_type, icmp_key->icmp_code);
1283 case OVS_KEY_ATTR_ICMPV6:
1285 const struct ovs_key_icmpv6 *icmpv6_mask = nl_attr_get(ma);
1286 const struct ovs_key_icmpv6 *icmpv6_key = nl_attr_get(a);
1288 ds_put_format(ds, "type=%"PRIu8"/%#"PRIx8",code=%"PRIu8"/%#"PRIx8,
1289 icmpv6_key->icmpv6_type, icmpv6_mask->icmpv6_type,
1290 icmpv6_key->icmpv6_code, icmpv6_mask->icmpv6_code);
1292 const struct ovs_key_icmpv6 *icmpv6_key = nl_attr_get(a);
1294 ds_put_format(ds, "type=%"PRIu8",code=%"PRIu8,
1295 icmpv6_key->icmpv6_type, icmpv6_key->icmpv6_code);
1299 case OVS_KEY_ATTR_ARP:
1301 const struct ovs_key_arp *arp_mask = nl_attr_get(ma);
1302 const struct ovs_key_arp *arp_key = nl_attr_get(a);
1304 ds_put_format(ds, "sip="IP_FMT"/"IP_FMT",tip="IP_FMT"/"IP_FMT
1305 ",op=%"PRIu16"/%#"PRIx16
1306 ",sha="ETH_ADDR_FMT"/"ETH_ADDR_FMT
1307 ",tha="ETH_ADDR_FMT"/"ETH_ADDR_FMT,
1308 IP_ARGS(arp_key->arp_sip),
1309 IP_ARGS(arp_mask->arp_sip),
1310 IP_ARGS(arp_key->arp_tip),
1311 IP_ARGS(arp_mask->arp_tip),
1312 ntohs(arp_key->arp_op), ntohs(arp_mask->arp_op),
1313 ETH_ADDR_ARGS(arp_key->arp_sha),
1314 ETH_ADDR_ARGS(arp_mask->arp_sha),
1315 ETH_ADDR_ARGS(arp_key->arp_tha),
1316 ETH_ADDR_ARGS(arp_mask->arp_tha));
1318 const struct ovs_key_arp *arp_key = nl_attr_get(a);
1320 ds_put_format(ds, "sip="IP_FMT",tip="IP_FMT",op=%"PRIu16","
1321 "sha="ETH_ADDR_FMT",tha="ETH_ADDR_FMT,
1322 IP_ARGS(arp_key->arp_sip), IP_ARGS(arp_key->arp_tip),
1323 ntohs(arp_key->arp_op),
1324 ETH_ADDR_ARGS(arp_key->arp_sha),
1325 ETH_ADDR_ARGS(arp_key->arp_tha));
1329 case OVS_KEY_ATTR_ND: {
1330 const struct ovs_key_nd *nd_key, *nd_mask = NULL;
1331 char target[INET6_ADDRSTRLEN];
1333 nd_key = nl_attr_get(a);
1335 nd_mask = nl_attr_get(ma);
1338 inet_ntop(AF_INET6, nd_key->nd_target, target, sizeof target);
1339 ds_put_format(ds, "target=%s", target);
1341 inet_ntop(AF_INET6, nd_mask->nd_target, target, sizeof target);
1342 ds_put_format(ds, "/%s", target);
1345 if (!eth_addr_is_zero(nd_key->nd_sll)) {
1346 ds_put_format(ds, ",sll="ETH_ADDR_FMT,
1347 ETH_ADDR_ARGS(nd_key->nd_sll));
1349 ds_put_format(ds, "/"ETH_ADDR_FMT,
1350 ETH_ADDR_ARGS(nd_mask->nd_sll));
1353 if (!eth_addr_is_zero(nd_key->nd_tll)) {
1354 ds_put_format(ds, ",tll="ETH_ADDR_FMT,
1355 ETH_ADDR_ARGS(nd_key->nd_tll));
1357 ds_put_format(ds, "/"ETH_ADDR_FMT,
1358 ETH_ADDR_ARGS(nd_mask->nd_tll));
1364 case OVS_KEY_ATTR_UNSPEC:
1365 case __OVS_KEY_ATTR_MAX:
1367 format_generic_odp_key(a, ds);
1369 ds_put_char(ds, '/');
1370 format_generic_odp_key(ma, ds);
1374 ds_put_char(ds, ')');
1377 static struct nlattr *
1378 generate_all_wildcard_mask(struct ofpbuf *ofp, const struct nlattr *key)
1380 const struct nlattr *a;
1382 int type = nl_attr_type(key);
1383 int size = nl_attr_get_size(key);
1385 if (odp_flow_key_attr_len(type) >=0) {
1386 memset(nl_msg_put_unspec_uninit(ofp, type, size), 0, size);
1390 nested_mask = nl_msg_start_nested(ofp, type);
1391 NL_ATTR_FOR_EACH(a, left, key, nl_attr_get_size(key)) {
1392 generate_all_wildcard_mask(ofp, nl_attr_get(a));
1394 nl_msg_end_nested(ofp, nested_mask);
1400 /* Appends to 'ds' a string representation of the 'key_len' bytes of
1401 * OVS_KEY_ATTR_* attributes in 'key'. If non-null, additionally formats the
1402 * 'mask_len' bytes of 'mask' which apply to 'key'. If 'portno_names' is
1403 * non-null and 'verbose' is true, translates odp port number to its name. */
1405 odp_flow_format(const struct nlattr *key, size_t key_len,
1406 const struct nlattr *mask, size_t mask_len,
1407 const struct hmap *portno_names, struct ds *ds, bool verbose)
1410 const struct nlattr *a;
1412 bool has_ethtype_key = false;
1413 const struct nlattr *ma = NULL;
1415 bool first_field = true;
1417 ofpbuf_init(&ofp, 100);
1418 NL_ATTR_FOR_EACH (a, left, key, key_len) {
1419 bool is_nested_attr;
1420 bool is_wildcard = false;
1421 int attr_type = nl_attr_type(a);
1423 if (attr_type == OVS_KEY_ATTR_ETHERTYPE) {
1424 has_ethtype_key = true;
1427 is_nested_attr = (odp_flow_key_attr_len(attr_type) == -2);
1429 if (mask && mask_len) {
1430 ma = nl_attr_find__(mask, mask_len, nl_attr_type(a));
1431 is_wildcard = ma ? odp_mask_attr_is_wildcard(ma) : true;
1434 if (verbose || !is_wildcard || is_nested_attr) {
1435 if (is_wildcard && !ma) {
1436 ma = generate_all_wildcard_mask(&ofp, a);
1439 ds_put_char(ds, ',');
1441 format_odp_key_attr(a, ma, portno_names, ds, verbose);
1442 first_field = false;
1446 ofpbuf_uninit(&ofp);
1451 if (left == key_len) {
1452 ds_put_cstr(ds, "<empty>");
1454 ds_put_format(ds, ",***%u leftover bytes*** (", left);
1455 for (i = 0; i < left; i++) {
1456 ds_put_format(ds, "%02x", ((const uint8_t *) a)[i]);
1458 ds_put_char(ds, ')');
1460 if (!has_ethtype_key) {
1461 ma = nl_attr_find__(mask, mask_len, OVS_KEY_ATTR_ETHERTYPE);
1463 ds_put_format(ds, ",eth_type(0/0x%04"PRIx16")",
1464 ntohs(nl_attr_get_be16(ma)));
1468 ds_put_cstr(ds, "<empty>");
1472 /* Appends to 'ds' a string representation of the 'key_len' bytes of
1473 * OVS_KEY_ATTR_* attributes in 'key'. */
1475 odp_flow_key_format(const struct nlattr *key,
1476 size_t key_len, struct ds *ds)
1478 odp_flow_format(key, key_len, NULL, 0, NULL, ds, true);
1482 put_nd(struct ovs_key_nd* nd_key, const uint8_t *nd_sll,
1483 const uint8_t *nd_tll, struct ofpbuf *key)
1486 memcpy(nd_key->nd_sll, nd_sll, ETH_ADDR_LEN);
1490 memcpy(nd_key->nd_tll, nd_tll, ETH_ADDR_LEN);
1493 nl_msg_put_unspec(key, OVS_KEY_ATTR_ND, nd_key, sizeof *nd_key);
1497 put_nd_key(int n, const char *nd_target_s, const uint8_t *nd_sll,
1498 const uint8_t *nd_tll, struct ofpbuf *key)
1500 struct ovs_key_nd nd_key;
1502 memset(&nd_key, 0, sizeof nd_key);
1504 if (inet_pton(AF_INET6, nd_target_s, nd_key.nd_target) != 1) {
1508 put_nd(&nd_key, nd_sll, nd_tll, key);
1513 put_nd_mask(int n, const char *nd_target_s,
1514 const uint8_t *nd_sll, const uint8_t *nd_tll, struct ofpbuf *mask)
1516 struct ovs_key_nd nd_mask;
1518 memset(&nd_mask, 0xff, sizeof nd_mask);
1520 if (strlen(nd_target_s) != 0 &&
1521 inet_pton(AF_INET6, nd_target_s, nd_mask.nd_target) != 1) {
1525 put_nd(&nd_mask, nd_sll, nd_tll, mask);
1530 ovs_frag_type_from_string(const char *s, enum ovs_frag_type *type)
1532 if (!strcasecmp(s, "no")) {
1533 *type = OVS_FRAG_TYPE_NONE;
1534 } else if (!strcasecmp(s, "first")) {
1535 *type = OVS_FRAG_TYPE_FIRST;
1536 } else if (!strcasecmp(s, "later")) {
1537 *type = OVS_FRAG_TYPE_LATER;
1545 mpls_lse_from_components(int mpls_label, int mpls_tc, int mpls_ttl, int mpls_bos)
1547 return (htonl((mpls_label << MPLS_LABEL_SHIFT) |
1548 (mpls_tc << MPLS_TC_SHIFT) |
1549 (mpls_ttl << MPLS_TTL_SHIFT) |
1550 (mpls_bos << MPLS_BOS_SHIFT)));
1554 parse_odp_key_mask_attr(const char *s, const struct simap *port_names,
1555 struct ofpbuf *key, struct ofpbuf *mask)
1557 /* Many of the sscanf calls in this function use oversized destination
1558 * fields because some sscanf() implementations truncate the range of %i
1559 * directives, so that e.g. "%"SCNi16 interprets input of "0xfedc" as a
1560 * value of 0x7fff. The other alternatives are to allow only a single
1561 * radix (e.g. decimal or hexadecimal) or to write more sophisticated
1564 * The tun_id parser has to use an alternative approach because there is no
1565 * type larger than 64 bits. */
1568 unsigned long long int priority;
1569 unsigned long long int priority_mask;
1572 if (mask && sscanf(s, "skb_priority(%lli/%lli)%n", &priority,
1573 &priority_mask, &n) > 0 && n > 0) {
1574 nl_msg_put_u32(key, OVS_KEY_ATTR_PRIORITY, priority);
1575 nl_msg_put_u32(mask, OVS_KEY_ATTR_PRIORITY, priority_mask);
1577 } else if (sscanf(s, "skb_priority(%lli)%n",
1578 &priority, &n) > 0 && n > 0) {
1579 nl_msg_put_u32(key, OVS_KEY_ATTR_PRIORITY, priority);
1581 nl_msg_put_u32(mask, OVS_KEY_ATTR_PRIORITY, UINT32_MAX);
1588 unsigned long long int mark;
1589 unsigned long long int mark_mask;
1592 if (mask && sscanf(s, "skb_mark(%lli/%lli)%n", &mark,
1593 &mark_mask, &n) > 0 && n > 0) {
1594 nl_msg_put_u32(key, OVS_KEY_ATTR_SKB_MARK, mark);
1595 nl_msg_put_u32(mask, OVS_KEY_ATTR_SKB_MARK, mark_mask);
1597 } else if (sscanf(s, "skb_mark(%lli)%n", &mark, &n) > 0 && n > 0) {
1598 nl_msg_put_u32(key, OVS_KEY_ATTR_SKB_MARK, mark);
1600 nl_msg_put_u32(mask, OVS_KEY_ATTR_SKB_MARK, UINT32_MAX);
1608 int tos, tos_mask, ttl, ttl_mask;
1609 struct flow_tnl tun_key, tun_key_mask;
1610 unsigned long long tun_id_mask;
1613 if (mask && sscanf(s, "tunnel(tun_id=%31[x0123456789abcdefABCDEF]/%llx,"
1614 "src="IP_SCAN_FMT"/"IP_SCAN_FMT",dst="IP_SCAN_FMT
1615 "/"IP_SCAN_FMT",tos=%i/%i,ttl=%i/%i,flags%n",
1616 tun_id_s, &tun_id_mask,
1617 IP_SCAN_ARGS(&tun_key.ip_src),
1618 IP_SCAN_ARGS(&tun_key_mask.ip_src),
1619 IP_SCAN_ARGS(&tun_key.ip_dst),
1620 IP_SCAN_ARGS(&tun_key_mask.ip_dst),
1621 &tos, &tos_mask, &ttl, &ttl_mask,
1626 tun_key.tun_id = htonll(strtoull(tun_id_s, NULL, 0));
1627 tun_key_mask.tun_id = htonll(tun_id_mask);
1628 tun_key.ip_tos = tos;
1629 tun_key_mask.ip_tos = tos_mask;
1630 tun_key.ip_ttl = ttl;
1631 tun_key_mask.ip_ttl = ttl_mask;
1632 res = parse_flags(&s[n], flow_tun_flag_to_string, &flags);
1633 tun_key.flags = flags;
1634 tun_key_mask.flags = UINT16_MAX;
1644 tun_key_to_attr(key, &tun_key);
1646 tun_key_to_attr(mask, &tun_key_mask);
1649 } else if (sscanf(s, "tunnel(tun_id=%31[x0123456789abcdefABCDEF],"
1650 "src="IP_SCAN_FMT",dst="IP_SCAN_FMT
1651 ",tos=%i,ttl=%i,flags%n", tun_id_s,
1652 IP_SCAN_ARGS(&tun_key.ip_src),
1653 IP_SCAN_ARGS(&tun_key.ip_dst), &tos, &ttl,
1658 tun_key.tun_id = htonll(strtoull(tun_id_s, NULL, 0));
1659 tun_key.ip_tos = tos;
1660 tun_key.ip_ttl = ttl;
1661 res = parse_flags(&s[n], flow_tun_flag_to_string, &flags);
1662 tun_key.flags = flags;
1672 tun_key_to_attr(key, &tun_key);
1675 memset(&tun_key, 0xff, sizeof tun_key);
1676 tun_key_to_attr(mask, &tun_key);
1683 unsigned long long int in_port;
1684 unsigned long long int in_port_mask;
1687 if (mask && sscanf(s, "in_port(%lli/%lli)%n", &in_port,
1688 &in_port_mask, &n) > 0 && n > 0) {
1689 nl_msg_put_u32(key, OVS_KEY_ATTR_IN_PORT, in_port);
1690 nl_msg_put_u32(mask, OVS_KEY_ATTR_IN_PORT, in_port_mask);
1692 } else if (sscanf(s, "in_port(%lli)%n", &in_port, &n) > 0 && n > 0) {
1693 nl_msg_put_u32(key, OVS_KEY_ATTR_IN_PORT, in_port);
1695 nl_msg_put_u32(mask, OVS_KEY_ATTR_IN_PORT, UINT32_MAX);
1702 if (port_names && !strncmp(s, "in_port(", 8)) {
1704 const struct simap_node *node;
1708 name_len = strcspn(name, ")");
1709 node = simap_find_len(port_names, name, name_len);
1711 nl_msg_put_u32(key, OVS_KEY_ATTR_IN_PORT, node->data);
1714 nl_msg_put_u32(mask, OVS_KEY_ATTR_IN_PORT, UINT32_MAX);
1716 return 8 + name_len + 1;
1721 struct ovs_key_ethernet eth_key;
1722 struct ovs_key_ethernet eth_key_mask;
1725 if (mask && sscanf(s,
1726 "eth(src="ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT","
1727 "dst="ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT")%n",
1728 ETH_ADDR_SCAN_ARGS(eth_key.eth_src),
1729 ETH_ADDR_SCAN_ARGS(eth_key_mask.eth_src),
1730 ETH_ADDR_SCAN_ARGS(eth_key.eth_dst),
1731 ETH_ADDR_SCAN_ARGS(eth_key_mask.eth_dst), &n) > 0 && n > 0) {
1733 nl_msg_put_unspec(key, OVS_KEY_ATTR_ETHERNET,
1734 ð_key, sizeof eth_key);
1735 nl_msg_put_unspec(mask, OVS_KEY_ATTR_ETHERNET,
1736 ð_key_mask, sizeof eth_key_mask);
1738 } else if (sscanf(s,
1739 "eth(src="ETH_ADDR_SCAN_FMT",dst="ETH_ADDR_SCAN_FMT")%n",
1740 ETH_ADDR_SCAN_ARGS(eth_key.eth_src),
1741 ETH_ADDR_SCAN_ARGS(eth_key.eth_dst), &n) > 0 && n > 0) {
1742 nl_msg_put_unspec(key, OVS_KEY_ATTR_ETHERNET,
1743 ð_key, sizeof eth_key);
1746 memset(ð_key, 0xff, sizeof eth_key);
1747 nl_msg_put_unspec(mask, OVS_KEY_ATTR_ETHERNET,
1748 ð_key, sizeof eth_key);
1755 uint16_t vid, vid_mask;
1760 if (mask && (sscanf(s, "vlan(vid=%"SCNi16"/%"SCNi16",pcp=%i/%i)%n",
1761 &vid, &vid_mask, &pcp, &pcp_mask, &n) > 0 && n > 0)) {
1762 nl_msg_put_be16(key, OVS_KEY_ATTR_VLAN,
1763 htons((vid << VLAN_VID_SHIFT) |
1764 (pcp << VLAN_PCP_SHIFT) |
1766 nl_msg_put_be16(mask, OVS_KEY_ATTR_VLAN,
1767 htons((vid_mask << VLAN_VID_SHIFT) |
1768 (pcp_mask << VLAN_PCP_SHIFT) |
1769 (1 << VLAN_CFI_SHIFT)));
1771 } else if ((sscanf(s, "vlan(vid=%"SCNi16",pcp=%i)%n",
1772 &vid, &pcp, &n) > 0 && n > 0)) {
1773 nl_msg_put_be16(key, OVS_KEY_ATTR_VLAN,
1774 htons((vid << VLAN_VID_SHIFT) |
1775 (pcp << VLAN_PCP_SHIFT) |
1778 nl_msg_put_be16(mask, OVS_KEY_ATTR_VLAN, OVS_BE16_MAX);
1781 } else if (mask && (sscanf(s, "vlan(vid=%"SCNi16"/%"SCNi16",pcp=%i/%i,cfi=%i/%i)%n",
1782 &vid, &vid_mask, &pcp, &pcp_mask, &cfi, &cfi_mask, &n) > 0 && n > 0)) {
1783 nl_msg_put_be16(key, OVS_KEY_ATTR_VLAN,
1784 htons((vid << VLAN_VID_SHIFT) |
1785 (pcp << VLAN_PCP_SHIFT) |
1786 (cfi ? VLAN_CFI : 0)));
1787 nl_msg_put_be16(mask, OVS_KEY_ATTR_VLAN,
1788 htons((vid_mask << VLAN_VID_SHIFT) |
1789 (pcp_mask << VLAN_PCP_SHIFT) |
1790 (cfi_mask << VLAN_CFI_SHIFT)));
1792 } else if ((sscanf(s, "vlan(vid=%"SCNi16",pcp=%i,cfi=%i)%n",
1793 &vid, &pcp, &cfi, &n) > 0 && n > 0)) {
1794 nl_msg_put_be16(key, OVS_KEY_ATTR_VLAN,
1795 htons((vid << VLAN_VID_SHIFT) |
1796 (pcp << VLAN_PCP_SHIFT) |
1797 (cfi ? VLAN_CFI : 0)));
1799 nl_msg_put_be16(mask, OVS_KEY_ATTR_VLAN, OVS_BE16_MAX);
1810 if (mask && sscanf(s, "eth_type(%i/%i)%n",
1811 ð_type, ð_type_mask, &n) > 0 && n > 0) {
1812 if (eth_type != 0) {
1813 nl_msg_put_be16(key, OVS_KEY_ATTR_ETHERTYPE, htons(eth_type));
1815 nl_msg_put_be16(mask, OVS_KEY_ATTR_ETHERTYPE, htons(eth_type_mask));
1817 } else if (sscanf(s, "eth_type(%i)%n", ð_type, &n) > 0 && n > 0) {
1818 nl_msg_put_be16(key, OVS_KEY_ATTR_ETHERTYPE, htons(eth_type));
1820 nl_msg_put_be16(mask, OVS_KEY_ATTR_ETHERTYPE, OVS_BE16_MAX);
1827 int label, tc, ttl, bos;
1828 int label_mask, tc_mask, ttl_mask, bos_mask;
1831 if (mask && sscanf(s, "mpls(label=%"SCNi32"/%"SCNi32",tc=%i/%i,ttl=%i/%i,bos=%i/%i)%n",
1832 &label, &label_mask, &tc, &tc_mask, &ttl, &ttl_mask, &bos, &bos_mask, &n) > 0 && n > 0) {
1833 struct ovs_key_mpls *mpls, *mpls_mask;
1835 mpls = nl_msg_put_unspec_uninit(key, OVS_KEY_ATTR_MPLS,
1837 mpls->mpls_lse = mpls_lse_from_components(label, tc, ttl, bos);
1839 mpls_mask = nl_msg_put_unspec_uninit(mask, OVS_KEY_ATTR_MPLS,
1841 mpls_mask->mpls_lse = mpls_lse_from_components(
1842 label_mask, tc_mask, ttl_mask, bos_mask);
1844 } else if (sscanf(s, "mpls(label=%"SCNi32",tc=%i,ttl=%i,bos=%i)%n",
1845 &label, &tc, &ttl, &bos, &n) > 0 &&
1847 struct ovs_key_mpls *mpls;
1849 mpls = nl_msg_put_unspec_uninit(key, OVS_KEY_ATTR_MPLS,
1851 mpls->mpls_lse = mpls_lse_from_components(label, tc, ttl, bos);
1853 mpls = nl_msg_put_unspec_uninit(mask, OVS_KEY_ATTR_MPLS,
1855 mpls->mpls_lse = OVS_BE32_MAX;
1863 ovs_be32 ipv4_src, ipv4_src_mask;
1864 ovs_be32 ipv4_dst, ipv4_dst_mask;
1865 int ipv4_proto, ipv4_proto_mask;
1866 int ipv4_tos, ipv4_tos_mask;
1867 int ipv4_ttl, ipv4_ttl_mask;
1870 enum ovs_frag_type ipv4_frag;
1873 if (mask && sscanf(s, "ipv4(src="IP_SCAN_FMT"/"IP_SCAN_FMT","
1874 "dst="IP_SCAN_FMT"/"IP_SCAN_FMT","
1875 "proto=%i/%i,tos=%i/%i,ttl=%i/%i,"
1876 "frag=%7[a-z]/%i)%n",
1877 IP_SCAN_ARGS(&ipv4_src), IP_SCAN_ARGS(&ipv4_src_mask),
1878 IP_SCAN_ARGS(&ipv4_dst), IP_SCAN_ARGS(&ipv4_dst_mask),
1879 &ipv4_proto, &ipv4_proto_mask,
1880 &ipv4_tos, &ipv4_tos_mask, &ipv4_ttl, &ipv4_ttl_mask,
1881 frag, &ipv4_frag_mask, &n) > 0
1883 && ovs_frag_type_from_string(frag, &ipv4_frag)) {
1884 struct ovs_key_ipv4 ipv4_key;
1885 struct ovs_key_ipv4 ipv4_mask;
1887 ipv4_key.ipv4_src = ipv4_src;
1888 ipv4_key.ipv4_dst = ipv4_dst;
1889 ipv4_key.ipv4_proto = ipv4_proto;
1890 ipv4_key.ipv4_tos = ipv4_tos;
1891 ipv4_key.ipv4_ttl = ipv4_ttl;
1892 ipv4_key.ipv4_frag = ipv4_frag;
1893 nl_msg_put_unspec(key, OVS_KEY_ATTR_IPV4,
1894 &ipv4_key, sizeof ipv4_key);
1896 ipv4_mask.ipv4_src = ipv4_src_mask;
1897 ipv4_mask.ipv4_dst = ipv4_dst_mask;
1898 ipv4_mask.ipv4_proto = ipv4_proto_mask;
1899 ipv4_mask.ipv4_tos = ipv4_tos_mask;
1900 ipv4_mask.ipv4_ttl = ipv4_ttl_mask;
1901 ipv4_mask.ipv4_frag = ipv4_frag_mask;
1902 nl_msg_put_unspec(mask, OVS_KEY_ATTR_IPV4,
1903 &ipv4_mask, sizeof ipv4_mask);
1905 } else if (sscanf(s, "ipv4(src="IP_SCAN_FMT",dst="IP_SCAN_FMT","
1906 "proto=%i,tos=%i,ttl=%i,frag=%7[a-z])%n",
1907 IP_SCAN_ARGS(&ipv4_src), IP_SCAN_ARGS(&ipv4_dst),
1908 &ipv4_proto, &ipv4_tos, &ipv4_ttl, frag, &n) > 0
1910 && ovs_frag_type_from_string(frag, &ipv4_frag)) {
1911 struct ovs_key_ipv4 ipv4_key;
1913 ipv4_key.ipv4_src = ipv4_src;
1914 ipv4_key.ipv4_dst = ipv4_dst;
1915 ipv4_key.ipv4_proto = ipv4_proto;
1916 ipv4_key.ipv4_tos = ipv4_tos;
1917 ipv4_key.ipv4_ttl = ipv4_ttl;
1918 ipv4_key.ipv4_frag = ipv4_frag;
1919 nl_msg_put_unspec(key, OVS_KEY_ATTR_IPV4,
1920 &ipv4_key, sizeof ipv4_key);
1923 memset(&ipv4_key, 0xff, sizeof ipv4_key);
1924 nl_msg_put_unspec(mask, OVS_KEY_ATTR_IPV4,
1925 &ipv4_key, sizeof ipv4_key);
1932 char ipv6_src_s[IPV6_SCAN_LEN + 1];
1933 char ipv6_src_mask_s[IPV6_SCAN_LEN + 1];
1934 char ipv6_dst_s[IPV6_SCAN_LEN + 1];
1935 char ipv6_dst_mask_s[IPV6_SCAN_LEN + 1];
1936 int ipv6_label, ipv6_label_mask;
1937 int ipv6_proto, ipv6_proto_mask;
1938 int ipv6_tclass, ipv6_tclass_mask;
1939 int ipv6_hlimit, ipv6_hlimit_mask;
1941 enum ovs_frag_type ipv6_frag;
1945 if (mask && sscanf(s, "ipv6(src="IPV6_SCAN_FMT"/"IPV6_SCAN_FMT",dst="
1946 IPV6_SCAN_FMT"/"IPV6_SCAN_FMT","
1947 "label=%i/%i,proto=%i/%i,tclass=%i/%i,"
1948 "hlimit=%i/%i,frag=%7[a-z]/%i)%n",
1949 ipv6_src_s, ipv6_src_mask_s, ipv6_dst_s, ipv6_dst_mask_s,
1950 &ipv6_label, &ipv6_label_mask, &ipv6_proto,
1951 &ipv6_proto_mask, &ipv6_tclass, &ipv6_tclass_mask,
1952 &ipv6_hlimit, &ipv6_hlimit_mask, frag,
1953 &ipv6_frag_mask, &n) > 0
1955 && ovs_frag_type_from_string(frag, &ipv6_frag)) {
1956 struct ovs_key_ipv6 ipv6_key;
1957 struct ovs_key_ipv6 ipv6_mask;
1959 if (inet_pton(AF_INET6, ipv6_src_s, &ipv6_key.ipv6_src) != 1 ||
1960 inet_pton(AF_INET6, ipv6_dst_s, &ipv6_key.ipv6_dst) != 1 ||
1961 inet_pton(AF_INET6, ipv6_src_mask_s, &ipv6_mask.ipv6_src) != 1 ||
1962 inet_pton(AF_INET6, ipv6_dst_mask_s, &ipv6_mask.ipv6_dst) != 1) {
1966 ipv6_key.ipv6_label = htonl(ipv6_label);
1967 ipv6_key.ipv6_proto = ipv6_proto;
1968 ipv6_key.ipv6_tclass = ipv6_tclass;
1969 ipv6_key.ipv6_hlimit = ipv6_hlimit;
1970 ipv6_key.ipv6_frag = ipv6_frag;
1971 nl_msg_put_unspec(key, OVS_KEY_ATTR_IPV6,
1972 &ipv6_key, sizeof ipv6_key);
1974 ipv6_mask.ipv6_label = htonl(ipv6_label_mask);
1975 ipv6_mask.ipv6_proto = ipv6_proto_mask;
1976 ipv6_mask.ipv6_tclass = ipv6_tclass_mask;
1977 ipv6_mask.ipv6_hlimit = ipv6_hlimit_mask;
1978 ipv6_mask.ipv6_frag = ipv6_frag_mask;
1979 nl_msg_put_unspec(mask, OVS_KEY_ATTR_IPV6,
1980 &ipv6_mask, sizeof ipv6_mask);
1982 } else if (sscanf(s, "ipv6(src="IPV6_SCAN_FMT",dst="IPV6_SCAN_FMT","
1983 "label=%i,proto=%i,tclass=%i,hlimit=%i,frag=%7[a-z])%n",
1984 ipv6_src_s, ipv6_dst_s, &ipv6_label,
1985 &ipv6_proto, &ipv6_tclass, &ipv6_hlimit, frag, &n) > 0
1987 && ovs_frag_type_from_string(frag, &ipv6_frag)) {
1988 struct ovs_key_ipv6 ipv6_key;
1990 if (inet_pton(AF_INET6, ipv6_src_s, &ipv6_key.ipv6_src) != 1 ||
1991 inet_pton(AF_INET6, ipv6_dst_s, &ipv6_key.ipv6_dst) != 1) {
1994 ipv6_key.ipv6_label = htonl(ipv6_label);
1995 ipv6_key.ipv6_proto = ipv6_proto;
1996 ipv6_key.ipv6_tclass = ipv6_tclass;
1997 ipv6_key.ipv6_hlimit = ipv6_hlimit;
1998 ipv6_key.ipv6_frag = ipv6_frag;
1999 nl_msg_put_unspec(key, OVS_KEY_ATTR_IPV6,
2000 &ipv6_key, sizeof ipv6_key);
2003 memset(&ipv6_key, 0xff, sizeof ipv6_key);
2004 nl_msg_put_unspec(mask, OVS_KEY_ATTR_IPV6,
2005 &ipv6_key, sizeof ipv6_key);
2018 if (mask && sscanf(s, "tcp(src=%i/%i,dst=%i/%i)%n",
2019 &tcp_src, &tcp_src_mask, &tcp_dst, &tcp_dst_mask, &n) > 0
2021 struct ovs_key_tcp tcp_key;
2022 struct ovs_key_tcp tcp_mask;
2024 tcp_key.tcp_src = htons(tcp_src);
2025 tcp_key.tcp_dst = htons(tcp_dst);
2026 nl_msg_put_unspec(key, OVS_KEY_ATTR_TCP, &tcp_key, sizeof tcp_key);
2028 tcp_mask.tcp_src = htons(tcp_src_mask);
2029 tcp_mask.tcp_dst = htons(tcp_dst_mask);
2030 nl_msg_put_unspec(mask, OVS_KEY_ATTR_TCP,
2031 &tcp_mask, sizeof tcp_mask);
2033 } else if (sscanf(s, "tcp(src=%i,dst=%i)%n",&tcp_src, &tcp_dst, &n) > 0
2035 struct ovs_key_tcp tcp_key;
2037 tcp_key.tcp_src = htons(tcp_src);
2038 tcp_key.tcp_dst = htons(tcp_dst);
2039 nl_msg_put_unspec(key, OVS_KEY_ATTR_TCP, &tcp_key, sizeof tcp_key);
2042 memset(&tcp_key, 0xff, sizeof tcp_key);
2043 nl_msg_put_unspec(mask, OVS_KEY_ATTR_TCP,
2044 &tcp_key, sizeof tcp_key);
2057 if (mask && sscanf(s, "udp(src=%i/%i,dst=%i/%i)%n",
2058 &udp_src, &udp_src_mask,
2059 &udp_dst, &udp_dst_mask, &n) > 0 && n > 0) {
2060 struct ovs_key_udp udp_key;
2061 struct ovs_key_udp udp_mask;
2063 udp_key.udp_src = htons(udp_src);
2064 udp_key.udp_dst = htons(udp_dst);
2065 nl_msg_put_unspec(key, OVS_KEY_ATTR_UDP, &udp_key, sizeof udp_key);
2067 udp_mask.udp_src = htons(udp_src_mask);
2068 udp_mask.udp_dst = htons(udp_dst_mask);
2069 nl_msg_put_unspec(mask, OVS_KEY_ATTR_UDP,
2070 &udp_mask, sizeof udp_mask);
2073 if (sscanf(s, "udp(src=%i,dst=%i)%n", &udp_src, &udp_dst, &n) > 0
2075 struct ovs_key_udp udp_key;
2077 udp_key.udp_src = htons(udp_src);
2078 udp_key.udp_dst = htons(udp_dst);
2079 nl_msg_put_unspec(key, OVS_KEY_ATTR_UDP, &udp_key, sizeof udp_key);
2082 memset(&udp_key, 0xff, sizeof udp_key);
2083 nl_msg_put_unspec(mask, OVS_KEY_ATTR_UDP, &udp_key, sizeof udp_key);
2096 if (mask && sscanf(s, "sctp(src=%i/%i,dst=%i/%i)%n",
2097 &sctp_src, &sctp_src_mask,
2098 &sctp_dst, &sctp_dst_mask, &n) > 0 && n > 0) {
2099 struct ovs_key_sctp sctp_key;
2100 struct ovs_key_sctp sctp_mask;
2102 sctp_key.sctp_src = htons(sctp_src);
2103 sctp_key.sctp_dst = htons(sctp_dst);
2104 nl_msg_put_unspec(key, OVS_KEY_ATTR_SCTP, &sctp_key, sizeof sctp_key);
2106 sctp_mask.sctp_src = htons(sctp_src_mask);
2107 sctp_mask.sctp_dst = htons(sctp_dst_mask);
2108 nl_msg_put_unspec(mask, OVS_KEY_ATTR_SCTP,
2109 &sctp_mask, sizeof sctp_mask);
2112 if (sscanf(s, "sctp(src=%i,dst=%i)%n", &sctp_src, &sctp_dst, &n) > 0
2114 struct ovs_key_sctp sctp_key;
2116 sctp_key.sctp_src = htons(sctp_src);
2117 sctp_key.sctp_dst = htons(sctp_dst);
2118 nl_msg_put_unspec(key, OVS_KEY_ATTR_SCTP, &sctp_key, sizeof sctp_key);
2121 memset(&sctp_key, 0xff, sizeof sctp_key);
2122 nl_msg_put_unspec(mask, OVS_KEY_ATTR_SCTP, &sctp_key, sizeof sctp_key);
2135 if (mask && sscanf(s, "icmp(type=%i/%i,code=%i/%i)%n",
2136 &icmp_type, &icmp_type_mask,
2137 &icmp_code, &icmp_code_mask, &n) > 0 && n > 0) {
2138 struct ovs_key_icmp icmp_key;
2139 struct ovs_key_icmp icmp_mask;
2141 icmp_key.icmp_type = icmp_type;
2142 icmp_key.icmp_code = icmp_code;
2143 nl_msg_put_unspec(key, OVS_KEY_ATTR_ICMP,
2144 &icmp_key, sizeof icmp_key);
2146 icmp_mask.icmp_type = icmp_type_mask;
2147 icmp_mask.icmp_code = icmp_code_mask;
2148 nl_msg_put_unspec(mask, OVS_KEY_ATTR_ICMP,
2149 &icmp_mask, sizeof icmp_mask);
2151 } else if (sscanf(s, "icmp(type=%i,code=%i)%n",
2152 &icmp_type, &icmp_code, &n) > 0
2154 struct ovs_key_icmp icmp_key;
2156 icmp_key.icmp_type = icmp_type;
2157 icmp_key.icmp_code = icmp_code;
2158 nl_msg_put_unspec(key, OVS_KEY_ATTR_ICMP,
2159 &icmp_key, sizeof icmp_key);
2161 memset(&icmp_key, 0xff, sizeof icmp_key);
2162 nl_msg_put_unspec(mask, OVS_KEY_ATTR_ICMP, &icmp_key,
2170 struct ovs_key_icmpv6 icmpv6_key;
2171 struct ovs_key_icmpv6 icmpv6_mask;
2172 int icmpv6_type_mask;
2173 int icmpv6_code_mask;
2176 if (mask && sscanf(s, "icmpv6(type=%"SCNi8"/%i,code=%"SCNi8"/%i)%n",
2177 &icmpv6_key.icmpv6_type, &icmpv6_type_mask,
2178 &icmpv6_key.icmpv6_code, &icmpv6_code_mask, &n) > 0
2180 nl_msg_put_unspec(key, OVS_KEY_ATTR_ICMPV6,
2181 &icmpv6_key, sizeof icmpv6_key);
2183 icmpv6_mask.icmpv6_type = icmpv6_type_mask;
2184 icmpv6_mask.icmpv6_code = icmpv6_code_mask;
2185 nl_msg_put_unspec(mask, OVS_KEY_ATTR_ICMPV6, &icmpv6_mask,
2186 sizeof icmpv6_mask);
2188 } else if (sscanf(s, "icmpv6(type=%"SCNi8",code=%"SCNi8")%n",
2189 &icmpv6_key.icmpv6_type, &icmpv6_key.icmpv6_code,&n) > 0
2191 nl_msg_put_unspec(key, OVS_KEY_ATTR_ICMPV6,
2192 &icmpv6_key, sizeof icmpv6_key);
2195 memset(&icmpv6_key, 0xff, sizeof icmpv6_key);
2196 nl_msg_put_unspec(mask, OVS_KEY_ATTR_ICMPV6, &icmpv6_key,
2204 ovs_be32 arp_sip, arp_sip_mask;
2205 ovs_be32 arp_tip, arp_tip_mask;
2206 int arp_op, arp_op_mask;
2207 uint8_t arp_sha[ETH_ADDR_LEN];
2208 uint8_t arp_sha_mask[ETH_ADDR_LEN];
2209 uint8_t arp_tha[ETH_ADDR_LEN];
2210 uint8_t arp_tha_mask[ETH_ADDR_LEN];
2213 if (mask && sscanf(s, "arp(sip="IP_SCAN_FMT"/"IP_SCAN_FMT","
2214 "tip="IP_SCAN_FMT"/"IP_SCAN_FMT","
2215 "op=%i/%i,sha="ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT","
2216 "tha="ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT")%n",
2217 IP_SCAN_ARGS(&arp_sip), IP_SCAN_ARGS(&arp_sip_mask),
2218 IP_SCAN_ARGS(&arp_tip), IP_SCAN_ARGS(&arp_tip_mask),
2219 &arp_op, &arp_op_mask,
2220 ETH_ADDR_SCAN_ARGS(arp_sha),
2221 ETH_ADDR_SCAN_ARGS(arp_sha_mask),
2222 ETH_ADDR_SCAN_ARGS(arp_tha),
2223 ETH_ADDR_SCAN_ARGS(arp_tha_mask), &n) > 0 && n > 0) {
2224 struct ovs_key_arp arp_key;
2225 struct ovs_key_arp arp_mask;
2227 memset(&arp_key, 0, sizeof arp_key);
2228 arp_key.arp_sip = arp_sip;
2229 arp_key.arp_tip = arp_tip;
2230 arp_key.arp_op = htons(arp_op);
2231 memcpy(arp_key.arp_sha, arp_sha, ETH_ADDR_LEN);
2232 memcpy(arp_key.arp_tha, arp_tha, ETH_ADDR_LEN);
2233 nl_msg_put_unspec(key, OVS_KEY_ATTR_ARP, &arp_key, sizeof arp_key);
2235 arp_mask.arp_sip = arp_sip_mask;
2236 arp_mask.arp_tip = arp_tip_mask;
2237 arp_mask.arp_op = htons(arp_op_mask);
2238 memcpy(arp_mask.arp_sha, arp_sha_mask, ETH_ADDR_LEN);
2239 memcpy(arp_mask.arp_tha, arp_tha_mask, ETH_ADDR_LEN);
2240 nl_msg_put_unspec(mask, OVS_KEY_ATTR_ARP,
2241 &arp_mask, sizeof arp_mask);
2243 } else if (sscanf(s, "arp(sip="IP_SCAN_FMT",tip="IP_SCAN_FMT","
2244 "op=%i,sha="ETH_ADDR_SCAN_FMT",tha="ETH_ADDR_SCAN_FMT")%n",
2245 IP_SCAN_ARGS(&arp_sip),
2246 IP_SCAN_ARGS(&arp_tip),
2248 ETH_ADDR_SCAN_ARGS(arp_sha),
2249 ETH_ADDR_SCAN_ARGS(arp_tha), &n) > 0 && n > 0) {
2250 struct ovs_key_arp arp_key;
2252 memset(&arp_key, 0, sizeof arp_key);
2253 arp_key.arp_sip = arp_sip;
2254 arp_key.arp_tip = arp_tip;
2255 arp_key.arp_op = htons(arp_op);
2256 memcpy(arp_key.arp_sha, arp_sha, ETH_ADDR_LEN);
2257 memcpy(arp_key.arp_tha, arp_tha, ETH_ADDR_LEN);
2258 nl_msg_put_unspec(key, OVS_KEY_ATTR_ARP, &arp_key, sizeof arp_key);
2261 memset(&arp_key, 0xff, sizeof arp_key);
2262 nl_msg_put_unspec(mask, OVS_KEY_ATTR_ARP,
2263 &arp_key, sizeof arp_key);
2270 char nd_target_s[IPV6_SCAN_LEN + 1];
2271 char nd_target_mask_s[IPV6_SCAN_LEN + 1];
2272 uint8_t nd_sll[ETH_ADDR_LEN];
2273 uint8_t nd_sll_mask[ETH_ADDR_LEN];
2274 uint8_t nd_tll[ETH_ADDR_LEN];
2275 uint8_t nd_tll_mask[ETH_ADDR_LEN];
2278 nd_target_mask_s[0] = 0;
2279 memset(nd_sll_mask, 0xff, sizeof nd_sll_mask);
2280 memset(nd_tll_mask, 0xff, sizeof nd_tll_mask);
2282 if (mask && sscanf(s, "nd(target="IPV6_SCAN_FMT"/"IPV6_SCAN_FMT")%n",
2283 nd_target_s, nd_target_mask_s, &n) > 0 && n > 0) {
2284 put_nd_key(n, nd_target_s, NULL, NULL, key);
2285 put_nd_mask(n, nd_target_mask_s, NULL, NULL, mask);
2286 } else if (sscanf(s, "nd(target="IPV6_SCAN_FMT")%n",
2287 nd_target_s, &n) > 0 && n > 0) {
2288 put_nd_key(n, nd_target_s, NULL, NULL, key);
2290 put_nd_mask(n, nd_target_mask_s, NULL, NULL, mask);
2292 } else if (mask && sscanf(s, "nd(target="IPV6_SCAN_FMT"/"IPV6_SCAN_FMT
2293 ",sll="ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT")%n",
2294 nd_target_s, nd_target_mask_s,
2295 ETH_ADDR_SCAN_ARGS(nd_sll),
2296 ETH_ADDR_SCAN_ARGS(nd_sll_mask), &n) > 0 && n > 0) {
2297 put_nd_key(n, nd_target_s, nd_sll, NULL, key);
2298 put_nd_mask(n, nd_target_mask_s, nd_sll_mask, NULL, mask);
2299 } else if (sscanf(s, "nd(target="IPV6_SCAN_FMT",sll="ETH_ADDR_SCAN_FMT")%n",
2300 nd_target_s, ETH_ADDR_SCAN_ARGS(nd_sll), &n) > 0
2302 put_nd_key(n, nd_target_s, nd_sll, NULL, key);
2304 put_nd_mask(n, nd_target_mask_s, nd_sll_mask, NULL, mask);
2306 } else if (mask && sscanf(s, "nd(target="IPV6_SCAN_FMT"/"IPV6_SCAN_FMT
2307 ",tll="ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT")%n",
2308 nd_target_s, nd_target_mask_s,
2309 ETH_ADDR_SCAN_ARGS(nd_tll),
2310 ETH_ADDR_SCAN_ARGS(nd_tll_mask), &n) > 0 && n > 0) {
2311 put_nd_key(n, nd_target_s, NULL, nd_tll, key);
2312 put_nd_mask(n, nd_target_mask_s, NULL, nd_tll_mask, mask);
2313 } else if (sscanf(s, "nd(target="IPV6_SCAN_FMT",tll="ETH_ADDR_SCAN_FMT")%n",
2314 nd_target_s, ETH_ADDR_SCAN_ARGS(nd_tll), &n) > 0
2316 put_nd_key(n, nd_target_s, NULL, nd_tll, key);
2318 put_nd_mask(n, nd_target_mask_s, NULL, nd_tll_mask, mask);
2320 } else if (mask && sscanf(s, "nd(target="IPV6_SCAN_FMT"/"IPV6_SCAN_FMT
2321 ",sll="ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT","
2322 "tll="ETH_ADDR_SCAN_FMT"/"ETH_ADDR_SCAN_FMT")%n",
2323 nd_target_s, nd_target_mask_s,
2324 ETH_ADDR_SCAN_ARGS(nd_sll), ETH_ADDR_SCAN_ARGS(nd_sll_mask),
2325 ETH_ADDR_SCAN_ARGS(nd_tll), ETH_ADDR_SCAN_ARGS(nd_tll_mask),
2328 put_nd_key(n, nd_target_s, nd_sll, nd_tll, key);
2329 put_nd_mask(n, nd_target_mask_s, nd_sll_mask, nd_tll_mask, mask);
2330 } else if (sscanf(s, "nd(target="IPV6_SCAN_FMT",sll="ETH_ADDR_SCAN_FMT","
2331 "tll="ETH_ADDR_SCAN_FMT")%n",
2332 nd_target_s, ETH_ADDR_SCAN_ARGS(nd_sll),
2333 ETH_ADDR_SCAN_ARGS(nd_tll), &n) > 0
2335 put_nd_key(n, nd_target_s, nd_sll, nd_tll, key);
2337 put_nd_mask(n, nd_target_mask_s,
2338 nd_sll_mask, nd_tll_mask, mask);
2347 if (!strncmp(s, "encap(", 6)) {
2348 const char *start = s;
2349 size_t encap, encap_mask = 0;
2351 encap = nl_msg_start_nested(key, OVS_KEY_ATTR_ENCAP);
2353 encap_mask = nl_msg_start_nested(mask, OVS_KEY_ATTR_ENCAP);
2360 s += strspn(s, ", \t\r\n");
2363 } else if (*s == ')') {
2367 retval = parse_odp_key_mask_attr(s, port_names, key, mask);
2375 nl_msg_end_nested(key, encap);
2377 nl_msg_end_nested(mask, encap_mask);
2386 /* Parses the string representation of a datapath flow key, in the
2387 * format output by odp_flow_key_format(). Returns 0 if successful,
2388 * otherwise a positive errno value. On success, the flow key is
2389 * appended to 'key' as a series of Netlink attributes. On failure, no
2390 * data is appended to 'key'. Either way, 'key''s data might be
2393 * If 'port_names' is nonnull, it points to an simap that maps from a port name
2394 * to a port number. (Port names may be used instead of port numbers in
2397 * On success, the attributes appended to 'key' are individually syntactically
2398 * valid, but they may not be valid as a sequence. 'key' might, for example,
2399 * have duplicated keys. odp_flow_key_to_flow() will detect those errors. */
2401 odp_flow_from_string(const char *s, const struct simap *port_names,
2402 struct ofpbuf *key, struct ofpbuf *mask)
2404 const size_t old_size = key->size;
2408 s += strspn(s, delimiters);
2413 retval = parse_odp_key_mask_attr(s, port_names, key, mask);
2415 key->size = old_size;
2425 ovs_to_odp_frag(uint8_t nw_frag)
2427 return (nw_frag == 0 ? OVS_FRAG_TYPE_NONE
2428 : nw_frag == FLOW_NW_FRAG_ANY ? OVS_FRAG_TYPE_FIRST
2429 : OVS_FRAG_TYPE_LATER);
2433 ovs_to_odp_frag_mask(uint8_t nw_frag_mask)
2435 uint8_t frag_mask = ~(OVS_FRAG_TYPE_FIRST | OVS_FRAG_TYPE_LATER);
2437 frag_mask |= (nw_frag_mask & FLOW_NW_FRAG_ANY) ? OVS_FRAG_TYPE_FIRST : 0;
2438 frag_mask |= (nw_frag_mask & FLOW_NW_FRAG_LATER) ? OVS_FRAG_TYPE_LATER : 0;
2444 odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *data,
2445 const struct flow *flow, odp_port_t odp_in_port)
2448 struct ovs_key_ethernet *eth_key;
2451 /* We assume that if 'data' and 'flow' are not the same, we should
2452 * treat 'data' as a mask. */
2453 is_mask = (data != flow);
2455 nl_msg_put_u32(buf, OVS_KEY_ATTR_PRIORITY, data->skb_priority);
2457 if (flow->tunnel.ip_dst || is_mask) {
2458 tun_key_to_attr(buf, &data->tunnel);
2461 nl_msg_put_u32(buf, OVS_KEY_ATTR_SKB_MARK, data->pkt_mark);
2463 /* Add an ingress port attribute if this is a mask or 'odp_in_port'
2464 * is not the magical value "ODPP_NONE". */
2465 if (is_mask || odp_in_port != ODPP_NONE) {
2466 nl_msg_put_odp_port(buf, OVS_KEY_ATTR_IN_PORT, odp_in_port);
2469 eth_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_ETHERNET,
2471 memcpy(eth_key->eth_src, data->dl_src, ETH_ADDR_LEN);
2472 memcpy(eth_key->eth_dst, data->dl_dst, ETH_ADDR_LEN);
2474 if (flow->vlan_tci != htons(0) || flow->dl_type == htons(ETH_TYPE_VLAN)) {
2476 nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, OVS_BE16_MAX);
2478 nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, htons(ETH_TYPE_VLAN));
2480 nl_msg_put_be16(buf, OVS_KEY_ATTR_VLAN, data->vlan_tci);
2481 encap = nl_msg_start_nested(buf, OVS_KEY_ATTR_ENCAP);
2482 if (flow->vlan_tci == htons(0)) {
2489 if (ntohs(flow->dl_type) < ETH_TYPE_MIN) {
2490 /* For backwards compatibility with kernels that don't support
2491 * wildcarding, the following convention is used to encode the
2492 * OVS_KEY_ATTR_ETHERTYPE for key and mask:
2495 * -------- -------- -------
2496 * >0x5ff 0xffff Specified Ethernet II Ethertype.
2497 * >0x5ff 0 Any Ethernet II or non-Ethernet II frame.
2498 * <none> 0xffff Any non-Ethernet II frame (except valid
2499 * 802.3 SNAP packet with valid eth_type).
2502 nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, OVS_BE16_MAX);
2507 nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, data->dl_type);
2509 if (flow->dl_type == htons(ETH_TYPE_IP)) {
2510 struct ovs_key_ipv4 *ipv4_key;
2512 ipv4_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_IPV4,
2514 ipv4_key->ipv4_src = data->nw_src;
2515 ipv4_key->ipv4_dst = data->nw_dst;
2516 ipv4_key->ipv4_proto = data->nw_proto;
2517 ipv4_key->ipv4_tos = data->nw_tos;
2518 ipv4_key->ipv4_ttl = data->nw_ttl;
2519 ipv4_key->ipv4_frag = is_mask ? ovs_to_odp_frag_mask(data->nw_frag)
2520 : ovs_to_odp_frag(data->nw_frag);
2521 } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
2522 struct ovs_key_ipv6 *ipv6_key;
2524 ipv6_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_IPV6,
2526 memcpy(ipv6_key->ipv6_src, &data->ipv6_src, sizeof ipv6_key->ipv6_src);
2527 memcpy(ipv6_key->ipv6_dst, &data->ipv6_dst, sizeof ipv6_key->ipv6_dst);
2528 ipv6_key->ipv6_label = data->ipv6_label;
2529 ipv6_key->ipv6_proto = data->nw_proto;
2530 ipv6_key->ipv6_tclass = data->nw_tos;
2531 ipv6_key->ipv6_hlimit = data->nw_ttl;
2532 ipv6_key->ipv6_frag = is_mask ? ovs_to_odp_frag_mask(data->nw_frag)
2533 : ovs_to_odp_frag(data->nw_frag);
2534 } else if (flow->dl_type == htons(ETH_TYPE_ARP) ||
2535 flow->dl_type == htons(ETH_TYPE_RARP)) {
2536 struct ovs_key_arp *arp_key;
2538 arp_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_ARP,
2540 memset(arp_key, 0, sizeof *arp_key);
2541 arp_key->arp_sip = data->nw_src;
2542 arp_key->arp_tip = data->nw_dst;
2543 arp_key->arp_op = htons(data->nw_proto);
2544 memcpy(arp_key->arp_sha, data->arp_sha, ETH_ADDR_LEN);
2545 memcpy(arp_key->arp_tha, data->arp_tha, ETH_ADDR_LEN);
2546 } else if (eth_type_mpls(flow->dl_type)) {
2547 struct ovs_key_mpls *mpls_key;
2549 mpls_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_MPLS,
2551 mpls_key->mpls_lse = data->mpls_lse;
2554 if (is_ip_any(flow) && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
2555 if (flow->nw_proto == IPPROTO_TCP) {
2556 struct ovs_key_tcp *tcp_key;
2558 tcp_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_TCP,
2560 tcp_key->tcp_src = data->tp_src;
2561 tcp_key->tcp_dst = data->tp_dst;
2562 } else if (flow->nw_proto == IPPROTO_UDP) {
2563 struct ovs_key_udp *udp_key;
2565 udp_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_UDP,
2567 udp_key->udp_src = data->tp_src;
2568 udp_key->udp_dst = data->tp_dst;
2569 } else if (flow->nw_proto == IPPROTO_SCTP) {
2570 struct ovs_key_sctp *sctp_key;
2572 sctp_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_SCTP,
2574 sctp_key->sctp_src = data->tp_src;
2575 sctp_key->sctp_dst = data->tp_dst;
2576 } else if (flow->dl_type == htons(ETH_TYPE_IP)
2577 && flow->nw_proto == IPPROTO_ICMP) {
2578 struct ovs_key_icmp *icmp_key;
2580 icmp_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_ICMP,
2582 icmp_key->icmp_type = ntohs(data->tp_src);
2583 icmp_key->icmp_code = ntohs(data->tp_dst);
2584 } else if (flow->dl_type == htons(ETH_TYPE_IPV6)
2585 && flow->nw_proto == IPPROTO_ICMPV6) {
2586 struct ovs_key_icmpv6 *icmpv6_key;
2588 icmpv6_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_ICMPV6,
2589 sizeof *icmpv6_key);
2590 icmpv6_key->icmpv6_type = ntohs(data->tp_src);
2591 icmpv6_key->icmpv6_code = ntohs(data->tp_dst);
2593 if (flow->tp_dst == htons(0) &&
2594 (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT) ||
2595 flow->tp_src == htons(ND_NEIGHBOR_ADVERT)) &&
2596 (!is_mask || (data->tp_src == htons(0xffff) &&
2597 data->tp_dst == htons(0xffff)))) {
2599 struct ovs_key_nd *nd_key;
2601 nd_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_ND,
2603 memcpy(nd_key->nd_target, &data->nd_target,
2604 sizeof nd_key->nd_target);
2605 memcpy(nd_key->nd_sll, data->arp_sha, ETH_ADDR_LEN);
2606 memcpy(nd_key->nd_tll, data->arp_tha, ETH_ADDR_LEN);
2613 nl_msg_end_nested(buf, encap);
2617 /* Appends a representation of 'flow' as OVS_KEY_ATTR_* attributes to 'buf'.
2618 * 'flow->in_port' is ignored (since it is likely to be an OpenFlow port
2619 * number rather than a datapath port number). Instead, if 'odp_in_port'
2620 * is anything other than ODPP_NONE, it is included in 'buf' as the input
2623 * 'buf' must have at least ODPUTIL_FLOW_KEY_BYTES bytes of space, or be
2624 * capable of being expanded to allow for that much space. */
2626 odp_flow_key_from_flow(struct ofpbuf *buf, const struct flow *flow,
2627 odp_port_t odp_in_port)
2629 odp_flow_key_from_flow__(buf, flow, flow, odp_in_port);
2632 /* Appends a representation of 'mask' as OVS_KEY_ATTR_* attributes to
2633 * 'buf'. 'flow' is used as a template to determine how to interpret
2634 * 'mask'. For example, the 'dl_type' of 'mask' describes the mask, but
2635 * it doesn't indicate whether the other fields should be interpreted as
2636 * ARP, IPv4, IPv6, etc.
2638 * 'buf' must have at least ODPUTIL_FLOW_KEY_BYTES bytes of space, or be
2639 * capable of being expanded to allow for that much space. */
2641 odp_flow_key_from_mask(struct ofpbuf *buf, const struct flow *mask,
2642 const struct flow *flow, uint32_t odp_in_port_mask)
2644 odp_flow_key_from_flow__(buf, mask, flow, u32_to_odp(odp_in_port_mask));
2648 odp_flow_key_hash(const struct nlattr *key, size_t key_len)
2650 BUILD_ASSERT_DECL(!(NLA_ALIGNTO % sizeof(uint32_t)));
2651 return hash_words(ALIGNED_CAST(const uint32_t *, key),
2652 key_len / sizeof(uint32_t), 0);
2656 log_odp_key_attributes(struct vlog_rate_limit *rl, const char *title,
2657 uint64_t attrs, int out_of_range_attr,
2658 const struct nlattr *key, size_t key_len)
2663 if (VLOG_DROP_DBG(rl)) {
2668 for (i = 0; i < 64; i++) {
2669 if (attrs & (UINT64_C(1) << i)) {
2670 char namebuf[OVS_KEY_ATTR_BUFSIZE];
2672 ds_put_format(&s, " %s",
2673 ovs_key_attr_to_string(i, namebuf, sizeof namebuf));
2676 if (out_of_range_attr) {
2677 ds_put_format(&s, " %d (and possibly others)", out_of_range_attr);
2680 ds_put_cstr(&s, ": ");
2681 odp_flow_key_format(key, key_len, &s);
2683 VLOG_DBG("%s:%s", title, ds_cstr(&s));
2688 odp_to_ovs_frag(uint8_t odp_frag, struct flow *flow)
2690 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2692 if (odp_frag > OVS_FRAG_TYPE_LATER) {
2693 VLOG_ERR_RL(&rl, "invalid frag %"PRIu8" in flow key", odp_frag);
2697 if (odp_frag != OVS_FRAG_TYPE_NONE) {
2698 flow->nw_frag |= FLOW_NW_FRAG_ANY;
2699 if (odp_frag == OVS_FRAG_TYPE_LATER) {
2700 flow->nw_frag |= FLOW_NW_FRAG_LATER;
2707 parse_flow_nlattrs(const struct nlattr *key, size_t key_len,
2708 const struct nlattr *attrs[], uint64_t *present_attrsp,
2709 int *out_of_range_attrp)
2711 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(10, 10);
2712 const struct nlattr *nla;
2713 uint64_t present_attrs;
2716 BUILD_ASSERT(OVS_KEY_ATTR_MAX < CHAR_BIT * sizeof present_attrs);
2718 *out_of_range_attrp = 0;
2719 NL_ATTR_FOR_EACH (nla, left, key, key_len) {
2720 uint16_t type = nl_attr_type(nla);
2721 size_t len = nl_attr_get_size(nla);
2722 int expected_len = odp_flow_key_attr_len(type);
2724 if (len != expected_len && expected_len >= 0) {
2725 char namebuf[OVS_KEY_ATTR_BUFSIZE];
2727 VLOG_ERR_RL(&rl, "attribute %s has length %zu but should have "
2728 "length %d", ovs_key_attr_to_string(type, namebuf,
2734 if (type > OVS_KEY_ATTR_MAX) {
2735 *out_of_range_attrp = type;
2737 if (present_attrs & (UINT64_C(1) << type)) {
2738 char namebuf[OVS_KEY_ATTR_BUFSIZE];
2740 VLOG_ERR_RL(&rl, "duplicate %s attribute in flow key",
2741 ovs_key_attr_to_string(type,
2742 namebuf, sizeof namebuf));
2746 present_attrs |= UINT64_C(1) << type;
2751 VLOG_ERR_RL(&rl, "trailing garbage in flow key");
2755 *present_attrsp = present_attrs;
2759 static enum odp_key_fitness
2760 check_expectations(uint64_t present_attrs, int out_of_range_attr,
2761 uint64_t expected_attrs,
2762 const struct nlattr *key, size_t key_len)
2764 uint64_t missing_attrs;
2765 uint64_t extra_attrs;
2767 missing_attrs = expected_attrs & ~present_attrs;
2768 if (missing_attrs) {
2769 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(10, 10);
2770 log_odp_key_attributes(&rl, "expected but not present",
2771 missing_attrs, 0, key, key_len);
2772 return ODP_FIT_TOO_LITTLE;
2775 extra_attrs = present_attrs & ~expected_attrs;
2776 if (extra_attrs || out_of_range_attr) {
2777 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(10, 10);
2778 log_odp_key_attributes(&rl, "present but not expected",
2779 extra_attrs, out_of_range_attr, key, key_len);
2780 return ODP_FIT_TOO_MUCH;
2783 return ODP_FIT_PERFECT;
2787 parse_ethertype(const struct nlattr *attrs[OVS_KEY_ATTR_MAX + 1],
2788 uint64_t present_attrs, uint64_t *expected_attrs,
2789 struct flow *flow, const struct flow *src_flow)
2791 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2792 bool is_mask = flow != src_flow;
2794 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_ETHERTYPE)) {
2795 flow->dl_type = nl_attr_get_be16(attrs[OVS_KEY_ATTR_ETHERTYPE]);
2796 if (!is_mask && ntohs(flow->dl_type) < ETH_TYPE_MIN) {
2797 VLOG_ERR_RL(&rl, "invalid Ethertype %"PRIu16" in flow key",
2798 ntohs(flow->dl_type));
2801 if (is_mask && ntohs(src_flow->dl_type) < ETH_TYPE_MIN &&
2802 flow->dl_type != htons(0xffff)) {
2805 *expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ETHERTYPE;
2808 flow->dl_type = htons(FLOW_DL_TYPE_NONE);
2809 } else if (ntohs(src_flow->dl_type) < ETH_TYPE_MIN) {
2810 /* See comments in odp_flow_key_from_flow__(). */
2811 VLOG_ERR_RL(&rl, "mask expected for non-Ethernet II frame");
2818 static enum odp_key_fitness
2819 parse_l2_5_onward(const struct nlattr *attrs[OVS_KEY_ATTR_MAX + 1],
2820 uint64_t present_attrs, int out_of_range_attr,
2821 uint64_t expected_attrs, struct flow *flow,
2822 const struct nlattr *key, size_t key_len,
2823 const struct flow *src_flow)
2825 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2826 bool is_mask = src_flow != flow;
2827 const void *check_start = NULL;
2828 size_t check_len = 0;
2829 enum ovs_key_attr expected_bit = 0xff;
2831 if (eth_type_mpls(src_flow->dl_type)) {
2833 expected_attrs |= (UINT64_C(1) << OVS_KEY_ATTR_MPLS);
2835 if (!(present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_MPLS))) {
2836 return ODP_FIT_TOO_LITTLE;
2838 flow->mpls_lse = nl_attr_get_be32(attrs[OVS_KEY_ATTR_MPLS]);
2839 } else if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_MPLS)) {
2840 flow->mpls_lse = nl_attr_get_be32(attrs[OVS_KEY_ATTR_MPLS]);
2842 if (flow->mpls_lse != 0 && flow->dl_type != htons(0xffff)) {
2843 return ODP_FIT_ERROR;
2845 expected_attrs |= (UINT64_C(1) << OVS_KEY_ATTR_MPLS);
2848 } else if (src_flow->dl_type == htons(ETH_TYPE_IP)) {
2850 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_IPV4;
2852 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_IPV4)) {
2853 const struct ovs_key_ipv4 *ipv4_key;
2855 ipv4_key = nl_attr_get(attrs[OVS_KEY_ATTR_IPV4]);
2856 flow->nw_src = ipv4_key->ipv4_src;
2857 flow->nw_dst = ipv4_key->ipv4_dst;
2858 flow->nw_proto = ipv4_key->ipv4_proto;
2859 flow->nw_tos = ipv4_key->ipv4_tos;
2860 flow->nw_ttl = ipv4_key->ipv4_ttl;
2862 flow->nw_frag = ipv4_key->ipv4_frag;
2863 check_start = ipv4_key;
2864 check_len = sizeof *ipv4_key;
2865 expected_bit = OVS_KEY_ATTR_IPV4;
2866 } else if (!odp_to_ovs_frag(ipv4_key->ipv4_frag, flow)) {
2867 return ODP_FIT_ERROR;
2870 } else if (src_flow->dl_type == htons(ETH_TYPE_IPV6)) {
2872 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_IPV6;
2874 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_IPV6)) {
2875 const struct ovs_key_ipv6 *ipv6_key;
2877 ipv6_key = nl_attr_get(attrs[OVS_KEY_ATTR_IPV6]);
2878 memcpy(&flow->ipv6_src, ipv6_key->ipv6_src, sizeof flow->ipv6_src);
2879 memcpy(&flow->ipv6_dst, ipv6_key->ipv6_dst, sizeof flow->ipv6_dst);
2880 flow->ipv6_label = ipv6_key->ipv6_label;
2881 flow->nw_proto = ipv6_key->ipv6_proto;
2882 flow->nw_tos = ipv6_key->ipv6_tclass;
2883 flow->nw_ttl = ipv6_key->ipv6_hlimit;
2885 flow->nw_frag = ipv6_key->ipv6_frag;
2886 check_start = ipv6_key;
2887 check_len = sizeof *ipv6_key;
2888 expected_bit = OVS_KEY_ATTR_IPV6;
2889 } else if (!odp_to_ovs_frag(ipv6_key->ipv6_frag, flow)) {
2890 return ODP_FIT_ERROR;
2893 } else if (src_flow->dl_type == htons(ETH_TYPE_ARP) ||
2894 src_flow->dl_type == htons(ETH_TYPE_RARP)) {
2896 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ARP;
2898 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_ARP)) {
2899 const struct ovs_key_arp *arp_key;
2901 arp_key = nl_attr_get(attrs[OVS_KEY_ATTR_ARP]);
2902 flow->nw_src = arp_key->arp_sip;
2903 flow->nw_dst = arp_key->arp_tip;
2904 if (!is_mask && (arp_key->arp_op & htons(0xff00))) {
2905 VLOG_ERR_RL(&rl, "unsupported ARP opcode %"PRIu16" in flow "
2906 "key", ntohs(arp_key->arp_op));
2907 return ODP_FIT_ERROR;
2909 flow->nw_proto = ntohs(arp_key->arp_op);
2910 memcpy(flow->arp_sha, arp_key->arp_sha, ETH_ADDR_LEN);
2911 memcpy(flow->arp_tha, arp_key->arp_tha, ETH_ADDR_LEN);
2914 check_start = arp_key;
2915 check_len = sizeof *arp_key;
2916 expected_bit = OVS_KEY_ATTR_ARP;
2923 if (!is_all_zeros(check_start, check_len) &&
2924 flow->dl_type != htons(0xffff)) {
2925 return ODP_FIT_ERROR;
2927 expected_attrs |= UINT64_C(1) << expected_bit;
2931 expected_bit = OVS_KEY_ATTR_UNSPEC;
2932 if (src_flow->nw_proto == IPPROTO_TCP
2933 && (src_flow->dl_type == htons(ETH_TYPE_IP) ||
2934 src_flow->dl_type == htons(ETH_TYPE_IPV6))
2935 && !(src_flow->nw_frag & FLOW_NW_FRAG_LATER)) {
2937 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_TCP;
2939 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_TCP)) {
2940 const struct ovs_key_tcp *tcp_key;
2942 tcp_key = nl_attr_get(attrs[OVS_KEY_ATTR_TCP]);
2943 flow->tp_src = tcp_key->tcp_src;
2944 flow->tp_dst = tcp_key->tcp_dst;
2945 expected_bit = OVS_KEY_ATTR_TCP;
2947 } else if (src_flow->nw_proto == IPPROTO_UDP
2948 && (src_flow->dl_type == htons(ETH_TYPE_IP) ||
2949 src_flow->dl_type == htons(ETH_TYPE_IPV6))
2950 && !(src_flow->nw_frag & FLOW_NW_FRAG_LATER)) {
2952 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_UDP;
2954 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_UDP)) {
2955 const struct ovs_key_udp *udp_key;
2957 udp_key = nl_attr_get(attrs[OVS_KEY_ATTR_UDP]);
2958 flow->tp_src = udp_key->udp_src;
2959 flow->tp_dst = udp_key->udp_dst;
2960 expected_bit = OVS_KEY_ATTR_UDP;
2962 } else if (flow->nw_proto == IPPROTO_SCTP
2963 && (flow->dl_type == htons(ETH_TYPE_IP) ||
2964 flow->dl_type == htons(ETH_TYPE_IPV6))
2965 && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
2967 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_SCTP;
2969 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_SCTP)) {
2970 const struct ovs_key_sctp *sctp_key;
2972 sctp_key = nl_attr_get(attrs[OVS_KEY_ATTR_SCTP]);
2973 flow->tp_src = sctp_key->sctp_src;
2974 flow->tp_dst = sctp_key->sctp_dst;
2975 expected_bit = OVS_KEY_ATTR_SCTP;
2977 } else if (src_flow->nw_proto == IPPROTO_ICMP
2978 && src_flow->dl_type == htons(ETH_TYPE_IP)
2979 && !(src_flow->nw_frag & FLOW_NW_FRAG_LATER)) {
2981 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ICMP;
2983 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_ICMP)) {
2984 const struct ovs_key_icmp *icmp_key;
2986 icmp_key = nl_attr_get(attrs[OVS_KEY_ATTR_ICMP]);
2987 flow->tp_src = htons(icmp_key->icmp_type);
2988 flow->tp_dst = htons(icmp_key->icmp_code);
2989 expected_bit = OVS_KEY_ATTR_ICMP;
2991 } else if (src_flow->nw_proto == IPPROTO_ICMPV6
2992 && src_flow->dl_type == htons(ETH_TYPE_IPV6)
2993 && !(src_flow->nw_frag & FLOW_NW_FRAG_LATER)) {
2995 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ICMPV6;
2997 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_ICMPV6)) {
2998 const struct ovs_key_icmpv6 *icmpv6_key;
3000 icmpv6_key = nl_attr_get(attrs[OVS_KEY_ATTR_ICMPV6]);
3001 flow->tp_src = htons(icmpv6_key->icmpv6_type);
3002 flow->tp_dst = htons(icmpv6_key->icmpv6_code);
3003 expected_bit = OVS_KEY_ATTR_ICMPV6;
3004 if (src_flow->tp_dst == htons(0) &&
3005 (src_flow->tp_src == htons(ND_NEIGHBOR_SOLICIT) ||
3006 src_flow->tp_src == htons(ND_NEIGHBOR_ADVERT))) {
3008 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ND;
3010 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_ND)) {
3011 const struct ovs_key_nd *nd_key;
3013 nd_key = nl_attr_get(attrs[OVS_KEY_ATTR_ND]);
3014 memcpy(&flow->nd_target, nd_key->nd_target,
3015 sizeof flow->nd_target);
3016 memcpy(flow->arp_sha, nd_key->nd_sll, ETH_ADDR_LEN);
3017 memcpy(flow->arp_tha, nd_key->nd_tll, ETH_ADDR_LEN);
3019 if (!is_all_zeros((const uint8_t *) nd_key,
3021 (flow->tp_src != htons(0xffff) ||
3022 flow->tp_dst != htons(0xffff))) {
3023 return ODP_FIT_ERROR;
3025 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ND;
3032 if (is_mask && expected_bit != OVS_KEY_ATTR_UNSPEC) {
3033 if ((flow->tp_src || flow->tp_dst) && flow->nw_proto != 0xff) {
3034 return ODP_FIT_ERROR;
3036 expected_attrs |= UINT64_C(1) << expected_bit;
3041 return check_expectations(present_attrs, out_of_range_attr, expected_attrs,
3045 /* Parse 802.1Q header then encapsulated L3 attributes. */
3046 static enum odp_key_fitness
3047 parse_8021q_onward(const struct nlattr *attrs[OVS_KEY_ATTR_MAX + 1],
3048 uint64_t present_attrs, int out_of_range_attr,
3049 uint64_t expected_attrs, struct flow *flow,
3050 const struct nlattr *key, size_t key_len,
3051 const struct flow *src_flow)
3053 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
3054 bool is_mask = src_flow != flow;
3056 const struct nlattr *encap
3057 = (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_ENCAP)
3058 ? attrs[OVS_KEY_ATTR_ENCAP] : NULL);
3059 enum odp_key_fitness encap_fitness;
3060 enum odp_key_fitness fitness;
3063 /* Calculate fitness of outer attributes. */
3065 expected_attrs |= ((UINT64_C(1) << OVS_KEY_ATTR_VLAN) |
3066 (UINT64_C(1) << OVS_KEY_ATTR_ENCAP));
3068 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_VLAN)) {
3069 expected_attrs |= (UINT64_C(1) << OVS_KEY_ATTR_VLAN);
3071 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_ENCAP)) {
3072 expected_attrs |= (UINT64_C(1) << OVS_KEY_ATTR_ENCAP);
3075 fitness = check_expectations(present_attrs, out_of_range_attr,
3076 expected_attrs, key, key_len);
3078 /* Get the VLAN TCI value. */
3079 if (!is_mask && !(present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_VLAN))) {
3080 return ODP_FIT_TOO_LITTLE;
3082 tci = nl_attr_get_be16(attrs[OVS_KEY_ATTR_VLAN]);
3084 if (tci == htons(0)) {
3085 /* Corner case for a truncated 802.1Q header. */
3086 if (fitness == ODP_FIT_PERFECT && nl_attr_get_size(encap)) {
3087 return ODP_FIT_TOO_MUCH;
3090 } else if (!(tci & htons(VLAN_CFI))) {
3091 VLOG_ERR_RL(&rl, "OVS_KEY_ATTR_VLAN 0x%04"PRIx16" is nonzero "
3092 "but CFI bit is not set", ntohs(tci));
3093 return ODP_FIT_ERROR;
3097 * Remove the TPID from dl_type since it's not the real Ethertype. */
3098 flow->dl_type = htons(0);
3099 flow->vlan_tci = tci;
3102 if (is_mask && !(present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_ENCAP))) {
3105 /* Now parse the encapsulated attributes. */
3106 if (!parse_flow_nlattrs(nl_attr_get(encap), nl_attr_get_size(encap),
3107 attrs, &present_attrs, &out_of_range_attr)) {
3108 return ODP_FIT_ERROR;
3112 if (!parse_ethertype(attrs, present_attrs, &expected_attrs, flow, src_flow)) {
3113 return ODP_FIT_ERROR;
3115 encap_fitness = parse_l2_5_onward(attrs, present_attrs, out_of_range_attr,
3116 expected_attrs, flow, key, key_len,
3119 /* The overall fitness is the worse of the outer and inner attributes. */
3120 return MAX(fitness, encap_fitness);
3123 static enum odp_key_fitness
3124 odp_flow_key_to_flow__(const struct nlattr *key, size_t key_len,
3125 struct flow *flow, const struct flow *src_flow)
3127 const struct nlattr *attrs[OVS_KEY_ATTR_MAX + 1];
3128 uint64_t expected_attrs;
3129 uint64_t present_attrs;
3130 int out_of_range_attr;
3131 bool is_mask = src_flow != flow;
3133 memset(flow, 0, sizeof *flow);
3135 /* Parse attributes. */
3136 if (!parse_flow_nlattrs(key, key_len, attrs, &present_attrs,
3137 &out_of_range_attr)) {
3138 return ODP_FIT_ERROR;
3143 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_PRIORITY)) {
3144 flow->skb_priority = nl_attr_get_u32(attrs[OVS_KEY_ATTR_PRIORITY]);
3145 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_PRIORITY;
3148 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_SKB_MARK)) {
3149 flow->pkt_mark = nl_attr_get_u32(attrs[OVS_KEY_ATTR_SKB_MARK]);
3150 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_SKB_MARK;
3153 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_TUNNEL)) {
3154 enum odp_key_fitness res;
3156 res = odp_tun_key_from_attr(attrs[OVS_KEY_ATTR_TUNNEL], &flow->tunnel);
3157 if (res == ODP_FIT_ERROR) {
3158 return ODP_FIT_ERROR;
3159 } else if (res == ODP_FIT_PERFECT) {
3160 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_TUNNEL;
3164 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_IN_PORT)) {
3165 flow->in_port.odp_port
3166 = nl_attr_get_odp_port(attrs[OVS_KEY_ATTR_IN_PORT]);
3167 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_IN_PORT;
3168 } else if (!is_mask) {
3169 flow->in_port.odp_port = ODPP_NONE;
3172 /* Ethernet header. */
3173 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_ETHERNET)) {
3174 const struct ovs_key_ethernet *eth_key;
3176 eth_key = nl_attr_get(attrs[OVS_KEY_ATTR_ETHERNET]);
3177 memcpy(flow->dl_src, eth_key->eth_src, ETH_ADDR_LEN);
3178 memcpy(flow->dl_dst, eth_key->eth_dst, ETH_ADDR_LEN);
3180 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ETHERNET;
3184 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ETHERNET;
3187 /* Get Ethertype or 802.1Q TPID or FLOW_DL_TYPE_NONE. */
3188 if (!parse_ethertype(attrs, present_attrs, &expected_attrs, flow,
3190 return ODP_FIT_ERROR;
3193 if ((is_mask && (src_flow->vlan_tci & htons(VLAN_CFI))) ||
3194 (!is_mask && src_flow->dl_type == htons(ETH_TYPE_VLAN))) {
3195 return parse_8021q_onward(attrs, present_attrs, out_of_range_attr,
3196 expected_attrs, flow, key, key_len, src_flow);
3199 flow->vlan_tci = htons(0xffff);
3200 if (present_attrs & (UINT64_C(1) << OVS_KEY_ATTR_VLAN)) {
3201 flow->vlan_tci = nl_attr_get_be16(attrs[OVS_KEY_ATTR_VLAN]);
3202 expected_attrs |= (UINT64_C(1) << OVS_KEY_ATTR_VLAN);
3205 return parse_l2_5_onward(attrs, present_attrs, out_of_range_attr,
3206 expected_attrs, flow, key, key_len, src_flow);
3209 /* Converts the 'key_len' bytes of OVS_KEY_ATTR_* attributes in 'key' to a flow
3210 * structure in 'flow'. Returns an ODP_FIT_* value that indicates how well
3211 * 'key' fits our expectations for what a flow key should contain.
3213 * The 'in_port' will be the datapath's understanding of the port. The
3214 * caller will need to translate with odp_port_to_ofp_port() if the
3215 * OpenFlow port is needed.
3217 * This function doesn't take the packet itself as an argument because none of
3218 * the currently understood OVS_KEY_ATTR_* attributes require it. Currently,
3219 * it is always possible to infer which additional attribute(s) should appear
3220 * by looking at the attributes for lower-level protocols, e.g. if the network
3221 * protocol in OVS_KEY_ATTR_IPV4 or OVS_KEY_ATTR_IPV6 is IPPROTO_TCP then we
3222 * know that a OVS_KEY_ATTR_TCP attribute must appear and that otherwise it
3223 * must be absent. */
3224 enum odp_key_fitness
3225 odp_flow_key_to_flow(const struct nlattr *key, size_t key_len,
3228 return odp_flow_key_to_flow__(key, key_len, flow, flow);
3231 /* Converts the 'key_len' bytes of OVS_KEY_ATTR_* attributes in 'key' to a mask
3232 * structure in 'mask'. 'flow' must be a previously translated flow
3233 * corresponding to 'mask'. Returns an ODP_FIT_* value that indicates how well
3234 * 'key' fits our expectations for what a flow key should contain. */
3235 enum odp_key_fitness
3236 odp_flow_key_to_mask(const struct nlattr *key, size_t key_len,
3237 struct flow *mask, const struct flow *flow)
3239 return odp_flow_key_to_flow__(key, key_len, mask, flow);
3242 /* Returns 'fitness' as a string, for use in debug messages. */
3244 odp_key_fitness_to_string(enum odp_key_fitness fitness)
3247 case ODP_FIT_PERFECT:
3249 case ODP_FIT_TOO_MUCH:
3251 case ODP_FIT_TOO_LITTLE:
3252 return "too_little";
3260 /* Appends an OVS_ACTION_ATTR_USERSPACE action to 'odp_actions' that specifies
3261 * Netlink PID 'pid'. If 'userdata' is nonnull, adds a userdata attribute
3262 * whose contents are the 'userdata_size' bytes at 'userdata' and returns the
3263 * offset within 'odp_actions' of the start of the cookie. (If 'userdata' is
3264 * null, then the return value is not meaningful.) */
3266 odp_put_userspace_action(uint32_t pid,
3267 const void *userdata, size_t userdata_size,
3268 struct ofpbuf *odp_actions)
3270 size_t userdata_ofs;
3273 offset = nl_msg_start_nested(odp_actions, OVS_ACTION_ATTR_USERSPACE);
3274 nl_msg_put_u32(odp_actions, OVS_USERSPACE_ATTR_PID, pid);
3276 userdata_ofs = odp_actions->size + NLA_HDRLEN;
3277 nl_msg_put_unspec(odp_actions, OVS_USERSPACE_ATTR_USERDATA,
3278 userdata, userdata_size);
3282 nl_msg_end_nested(odp_actions, offset);
3284 return userdata_ofs;
3288 odp_put_tunnel_action(const struct flow_tnl *tunnel,
3289 struct ofpbuf *odp_actions)
3291 size_t offset = nl_msg_start_nested(odp_actions, OVS_ACTION_ATTR_SET);
3292 tun_key_to_attr(odp_actions, tunnel);
3293 nl_msg_end_nested(odp_actions, offset);
3296 /* The commit_odp_actions() function and its helpers. */
3299 commit_set_action(struct ofpbuf *odp_actions, enum ovs_key_attr key_type,
3300 const void *key, size_t key_size)
3302 size_t offset = nl_msg_start_nested(odp_actions, OVS_ACTION_ATTR_SET);
3303 nl_msg_put_unspec(odp_actions, key_type, key, key_size);
3304 nl_msg_end_nested(odp_actions, offset);
3308 odp_put_pkt_mark_action(const uint32_t pkt_mark,
3309 struct ofpbuf *odp_actions)
3311 commit_set_action(odp_actions, OVS_KEY_ATTR_SKB_MARK, &pkt_mark,
3315 /* If any of the flow key data that ODP actions can modify are different in
3316 * 'base->tunnel' and 'flow->tunnel', appends a set_tunnel ODP action to
3317 * 'odp_actions' that change the flow tunneling information in key from
3318 * 'base->tunnel' into 'flow->tunnel', and then changes 'base->tunnel' in the
3319 * same way. In other words, operates the same as commit_odp_actions(), but
3320 * only on tunneling information. */
3322 commit_odp_tunnel_action(const struct flow *flow, struct flow *base,
3323 struct ofpbuf *odp_actions)
3325 /* A valid IPV4_TUNNEL must have non-zero ip_dst. */
3326 if (flow->tunnel.ip_dst) {
3327 if (!memcmp(&base->tunnel, &flow->tunnel, sizeof base->tunnel)) {
3330 memcpy(&base->tunnel, &flow->tunnel, sizeof base->tunnel);
3331 odp_put_tunnel_action(&base->tunnel, odp_actions);
3336 commit_set_ether_addr_action(const struct flow *flow, struct flow *base,
3337 struct ofpbuf *odp_actions,
3338 struct flow_wildcards *wc)
3340 struct ovs_key_ethernet eth_key;
3342 if (eth_addr_equals(base->dl_src, flow->dl_src) &&
3343 eth_addr_equals(base->dl_dst, flow->dl_dst)) {
3347 memset(&wc->masks.dl_src, 0xff, sizeof wc->masks.dl_src);
3348 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
3350 memcpy(base->dl_src, flow->dl_src, ETH_ADDR_LEN);
3351 memcpy(base->dl_dst, flow->dl_dst, ETH_ADDR_LEN);
3353 memcpy(eth_key.eth_src, base->dl_src, ETH_ADDR_LEN);
3354 memcpy(eth_key.eth_dst, base->dl_dst, ETH_ADDR_LEN);
3356 commit_set_action(odp_actions, OVS_KEY_ATTR_ETHERNET,
3357 ð_key, sizeof(eth_key));
3361 commit_vlan_action(ovs_be16 vlan_tci, struct flow *base,
3362 struct ofpbuf *odp_actions, struct flow_wildcards *wc)
3364 if (base->vlan_tci == vlan_tci) {
3368 memset(&wc->masks.vlan_tci, 0xff, sizeof wc->masks.vlan_tci);
3370 if (base->vlan_tci & htons(VLAN_CFI)) {
3371 nl_msg_put_flag(odp_actions, OVS_ACTION_ATTR_POP_VLAN);
3374 if (vlan_tci & htons(VLAN_CFI)) {
3375 struct ovs_action_push_vlan vlan;
3377 vlan.vlan_tpid = htons(ETH_TYPE_VLAN);
3378 vlan.vlan_tci = vlan_tci;
3379 nl_msg_put_unspec(odp_actions, OVS_ACTION_ATTR_PUSH_VLAN,
3380 &vlan, sizeof vlan);
3382 base->vlan_tci = vlan_tci;
3386 commit_mpls_action(const struct flow *flow, struct flow *base,
3387 struct ofpbuf *odp_actions, struct flow_wildcards *wc,
3388 int *mpls_depth_delta)
3390 if (flow->mpls_lse == base->mpls_lse && !*mpls_depth_delta) {
3394 memset(&wc->masks.mpls_lse, 0xff, sizeof wc->masks.mpls_lse);
3396 switch (*mpls_depth_delta) {
3398 nl_msg_put_be16(odp_actions, OVS_ACTION_ATTR_POP_MPLS, flow->dl_type);
3401 struct ovs_action_push_mpls *mpls;
3403 mpls = nl_msg_put_unspec_uninit(odp_actions, OVS_ACTION_ATTR_PUSH_MPLS,
3405 memset(mpls, 0, sizeof *mpls);
3406 mpls->mpls_ethertype = flow->dl_type;
3407 mpls->mpls_lse = flow->mpls_lse;
3411 struct ovs_key_mpls mpls_key;
3413 mpls_key.mpls_lse = flow->mpls_lse;
3414 commit_set_action(odp_actions, OVS_KEY_ATTR_MPLS,
3415 &mpls_key, sizeof(mpls_key));
3422 base->dl_type = flow->dl_type;
3423 base->mpls_lse = flow->mpls_lse;
3424 *mpls_depth_delta = 0;
3428 commit_set_ipv4_action(const struct flow *flow, struct flow *base,
3429 struct ofpbuf *odp_actions, struct flow_wildcards *wc)
3431 struct ovs_key_ipv4 ipv4_key;
3433 if (base->nw_src == flow->nw_src &&
3434 base->nw_dst == flow->nw_dst &&
3435 base->nw_tos == flow->nw_tos &&
3436 base->nw_ttl == flow->nw_ttl &&
3437 base->nw_frag == flow->nw_frag) {
3441 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
3442 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
3443 memset(&wc->masks.nw_tos, 0xff, sizeof wc->masks.nw_tos);
3444 memset(&wc->masks.nw_ttl, 0xff, sizeof wc->masks.nw_ttl);
3445 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
3446 memset(&wc->masks.nw_frag, 0xff, sizeof wc->masks.nw_frag);
3448 ipv4_key.ipv4_src = base->nw_src = flow->nw_src;
3449 ipv4_key.ipv4_dst = base->nw_dst = flow->nw_dst;
3450 ipv4_key.ipv4_tos = base->nw_tos = flow->nw_tos;
3451 ipv4_key.ipv4_ttl = base->nw_ttl = flow->nw_ttl;
3452 ipv4_key.ipv4_proto = base->nw_proto;
3453 ipv4_key.ipv4_frag = ovs_to_odp_frag(base->nw_frag);
3455 commit_set_action(odp_actions, OVS_KEY_ATTR_IPV4,
3456 &ipv4_key, sizeof(ipv4_key));
3460 commit_set_ipv6_action(const struct flow *flow, struct flow *base,
3461 struct ofpbuf *odp_actions, struct flow_wildcards *wc)
3463 struct ovs_key_ipv6 ipv6_key;
3465 if (ipv6_addr_equals(&base->ipv6_src, &flow->ipv6_src) &&
3466 ipv6_addr_equals(&base->ipv6_dst, &flow->ipv6_dst) &&
3467 base->ipv6_label == flow->ipv6_label &&
3468 base->nw_tos == flow->nw_tos &&
3469 base->nw_ttl == flow->nw_ttl &&
3470 base->nw_frag == flow->nw_frag) {
3474 memset(&wc->masks.ipv6_src, 0xff, sizeof wc->masks.ipv6_src);
3475 memset(&wc->masks.ipv6_dst, 0xff, sizeof wc->masks.ipv6_dst);
3476 memset(&wc->masks.ipv6_label, 0xff, sizeof wc->masks.ipv6_label);
3477 memset(&wc->masks.nw_tos, 0xff, sizeof wc->masks.nw_tos);
3478 memset(&wc->masks.nw_ttl, 0xff, sizeof wc->masks.nw_ttl);
3479 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
3480 memset(&wc->masks.nw_frag, 0xff, sizeof wc->masks.nw_frag);
3482 base->ipv6_src = flow->ipv6_src;
3483 memcpy(&ipv6_key.ipv6_src, &base->ipv6_src, sizeof(ipv6_key.ipv6_src));
3484 base->ipv6_dst = flow->ipv6_dst;
3485 memcpy(&ipv6_key.ipv6_dst, &base->ipv6_dst, sizeof(ipv6_key.ipv6_dst));
3487 ipv6_key.ipv6_label = base->ipv6_label = flow->ipv6_label;
3488 ipv6_key.ipv6_tclass = base->nw_tos = flow->nw_tos;
3489 ipv6_key.ipv6_hlimit = base->nw_ttl = flow->nw_ttl;
3490 ipv6_key.ipv6_proto = base->nw_proto;
3491 ipv6_key.ipv6_frag = ovs_to_odp_frag(base->nw_frag);
3493 commit_set_action(odp_actions, OVS_KEY_ATTR_IPV6,
3494 &ipv6_key, sizeof(ipv6_key));
3497 static enum slow_path_reason
3498 commit_set_arp_action(const struct flow *flow, struct flow *base,
3499 struct ofpbuf *odp_actions, struct flow_wildcards *wc)
3501 struct ovs_key_arp arp_key;
3503 if (base->nw_src == flow->nw_src &&
3504 base->nw_dst == flow->nw_dst &&
3505 base->nw_proto == flow->nw_proto &&
3506 eth_addr_equals(base->arp_sha, flow->arp_sha) &&
3507 eth_addr_equals(base->arp_tha, flow->arp_tha)) {
3511 memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
3512 memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
3513 memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
3514 memset(&wc->masks.arp_sha, 0xff, sizeof wc->masks.arp_sha);
3515 memset(&wc->masks.arp_tha, 0xff, sizeof wc->masks.arp_tha);
3517 base->nw_src = flow->nw_src;
3518 base->nw_dst = flow->nw_dst;
3519 base->nw_proto = flow->nw_proto;
3520 memcpy(base->arp_sha, flow->arp_sha, ETH_ADDR_LEN);
3521 memcpy(base->arp_tha, flow->arp_tha, ETH_ADDR_LEN);
3523 arp_key.arp_sip = base->nw_src;
3524 arp_key.arp_tip = base->nw_dst;
3525 arp_key.arp_op = htons(base->nw_proto);
3526 memcpy(arp_key.arp_sha, flow->arp_sha, ETH_ADDR_LEN);
3527 memcpy(arp_key.arp_tha, flow->arp_tha, ETH_ADDR_LEN);
3529 commit_set_action(odp_actions, OVS_KEY_ATTR_ARP, &arp_key, sizeof arp_key);
3534 static enum slow_path_reason
3535 commit_set_nw_action(const struct flow *flow, struct flow *base,
3536 struct ofpbuf *odp_actions, struct flow_wildcards *wc)
3538 /* Check if 'flow' really has an L3 header. */
3539 if (!flow->nw_proto) {
3543 switch (ntohs(base->dl_type)) {
3545 commit_set_ipv4_action(flow, base, odp_actions, wc);
3549 commit_set_ipv6_action(flow, base, odp_actions, wc);
3553 return commit_set_arp_action(flow, base, odp_actions, wc);
3560 commit_set_port_action(const struct flow *flow, struct flow *base,
3561 struct ofpbuf *odp_actions, struct flow_wildcards *wc)
3563 if (!is_ip_any(base) || (!base->tp_src && !base->tp_dst)) {
3567 if (base->tp_src == flow->tp_src &&
3568 base->tp_dst == flow->tp_dst) {
3572 memset(&wc->masks.tp_src, 0xff, sizeof wc->masks.tp_src);
3573 memset(&wc->masks.tp_dst, 0xff, sizeof wc->masks.tp_dst);
3575 if (flow->nw_proto == IPPROTO_TCP) {
3576 struct ovs_key_tcp port_key;
3578 port_key.tcp_src = base->tp_src = flow->tp_src;
3579 port_key.tcp_dst = base->tp_dst = flow->tp_dst;
3581 commit_set_action(odp_actions, OVS_KEY_ATTR_TCP,
3582 &port_key, sizeof(port_key));
3584 } else if (flow->nw_proto == IPPROTO_UDP) {
3585 struct ovs_key_udp port_key;
3587 port_key.udp_src = base->tp_src = flow->tp_src;
3588 port_key.udp_dst = base->tp_dst = flow->tp_dst;
3590 commit_set_action(odp_actions, OVS_KEY_ATTR_UDP,
3591 &port_key, sizeof(port_key));
3592 } else if (flow->nw_proto == IPPROTO_SCTP) {
3593 struct ovs_key_sctp port_key;
3595 port_key.sctp_src = base->tp_src = flow->tp_src;
3596 port_key.sctp_dst = base->tp_dst = flow->tp_dst;
3598 commit_set_action(odp_actions, OVS_KEY_ATTR_SCTP,
3599 &port_key, sizeof(port_key));
3604 commit_set_priority_action(const struct flow *flow, struct flow *base,
3605 struct ofpbuf *odp_actions,
3606 struct flow_wildcards *wc)
3608 if (base->skb_priority == flow->skb_priority) {
3612 memset(&wc->masks.skb_priority, 0xff, sizeof wc->masks.skb_priority);
3613 base->skb_priority = flow->skb_priority;
3615 commit_set_action(odp_actions, OVS_KEY_ATTR_PRIORITY,
3616 &base->skb_priority, sizeof(base->skb_priority));
3620 commit_set_pkt_mark_action(const struct flow *flow, struct flow *base,
3621 struct ofpbuf *odp_actions,
3622 struct flow_wildcards *wc)
3624 if (base->pkt_mark == flow->pkt_mark) {
3628 memset(&wc->masks.pkt_mark, 0xff, sizeof wc->masks.pkt_mark);
3629 base->pkt_mark = flow->pkt_mark;
3631 odp_put_pkt_mark_action(base->pkt_mark, odp_actions);
3634 /* If any of the flow key data that ODP actions can modify are different in
3635 * 'base' and 'flow', appends ODP actions to 'odp_actions' that change the flow
3636 * key from 'base' into 'flow', and then changes 'base' the same way. Does not
3637 * commit set_tunnel actions. Users should call commit_odp_tunnel_action()
3638 * in addition to this function if needed. Sets fields in 'wc' that are
3639 * used as part of the action.
3641 * Returns a reason to force processing the flow's packets into the userspace
3642 * slow path, if there is one, otherwise 0. */
3643 enum slow_path_reason
3644 commit_odp_actions(const struct flow *flow, struct flow *base,
3645 struct ofpbuf *odp_actions, struct flow_wildcards *wc,
3646 int *mpls_depth_delta)
3648 enum slow_path_reason slow;
3650 commit_set_ether_addr_action(flow, base, odp_actions, wc);
3651 commit_vlan_action(flow->vlan_tci, base, odp_actions, wc);
3652 slow = commit_set_nw_action(flow, base, odp_actions, wc);
3653 commit_set_port_action(flow, base, odp_actions, wc);
3654 /* Committing MPLS actions should occur after committing nw and port
3655 * actions. This is because committing MPLS actions may alter a packet so
3656 * that it is no longer IP and thus nw and port actions are no longer valid.
3658 commit_mpls_action(flow, base, odp_actions, wc, mpls_depth_delta);
3659 commit_set_priority_action(flow, base, odp_actions, wc);
3660 commit_set_pkt_mark_action(flow, base, odp_actions, wc);