2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 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"
30 #include "dynamic-string.h"
40 VLOG_DEFINE_THIS_MODULE(odp_util
);
42 /* The interface between userspace and kernel uses an "OVS_*" prefix.
43 * Since this is fairly non-specific for the OVS userspace components,
44 * "ODP_*" (Open vSwitch Datapath) is used as the prefix for
45 * interactions with the datapath.
48 /* The set of characters that may separate one action or one key attribute
50 static const char *delimiters
= ", \t\r\n";
52 static int parse_odp_key_mask_attr(const char *, const struct simap
*port_names
,
53 struct ofpbuf
*, struct ofpbuf
*);
54 static void format_odp_key_attr(const struct nlattr
*a
,
55 const struct nlattr
*ma
,
56 const struct hmap
*portno_names
, struct ds
*ds
,
59 /* Returns one the following for the action with the given OVS_ACTION_ATTR_*
62 * - For an action whose argument has a fixed length, returned that
63 * nonnegative length in bytes.
65 * - For an action with a variable-length argument, returns -2.
67 * - For an invalid 'type', returns -1. */
69 odp_action_len(uint16_t type
)
71 if (type
> OVS_ACTION_ATTR_MAX
) {
75 switch ((enum ovs_action_attr
) type
) {
76 case OVS_ACTION_ATTR_OUTPUT
: return sizeof(uint32_t);
77 case OVS_ACTION_ATTR_USERSPACE
: return -2;
78 case OVS_ACTION_ATTR_PUSH_VLAN
: return sizeof(struct ovs_action_push_vlan
);
79 case OVS_ACTION_ATTR_POP_VLAN
: return 0;
80 case OVS_ACTION_ATTR_PUSH_MPLS
: return sizeof(struct ovs_action_push_mpls
);
81 case OVS_ACTION_ATTR_POP_MPLS
: return sizeof(ovs_be16
);
82 case OVS_ACTION_ATTR_RECIRC
: return sizeof(uint32_t);
83 case OVS_ACTION_ATTR_HASH
: return sizeof(struct ovs_action_hash
);
84 case OVS_ACTION_ATTR_SET
: return -2;
85 case OVS_ACTION_ATTR_SAMPLE
: return -2;
87 case OVS_ACTION_ATTR_UNSPEC
:
88 case __OVS_ACTION_ATTR_MAX
:
95 /* Returns a string form of 'attr'. The return value is either a statically
96 * allocated constant string or the 'bufsize'-byte buffer 'namebuf'. 'bufsize'
97 * should be at least OVS_KEY_ATTR_BUFSIZE. */
98 enum { OVS_KEY_ATTR_BUFSIZE
= 3 + INT_STRLEN(unsigned int) + 1 };
100 ovs_key_attr_to_string(enum ovs_key_attr attr
, char *namebuf
, size_t bufsize
)
103 case OVS_KEY_ATTR_UNSPEC
: return "unspec";
104 case OVS_KEY_ATTR_ENCAP
: return "encap";
105 case OVS_KEY_ATTR_PRIORITY
: return "skb_priority";
106 case OVS_KEY_ATTR_SKB_MARK
: return "skb_mark";
107 case OVS_KEY_ATTR_TUNNEL
: return "tunnel";
108 case OVS_KEY_ATTR_IN_PORT
: return "in_port";
109 case OVS_KEY_ATTR_ETHERNET
: return "eth";
110 case OVS_KEY_ATTR_VLAN
: return "vlan";
111 case OVS_KEY_ATTR_ETHERTYPE
: return "eth_type";
112 case OVS_KEY_ATTR_IPV4
: return "ipv4";
113 case OVS_KEY_ATTR_IPV6
: return "ipv6";
114 case OVS_KEY_ATTR_TCP
: return "tcp";
115 case OVS_KEY_ATTR_TCP_FLAGS
: return "tcp_flags";
116 case OVS_KEY_ATTR_UDP
: return "udp";
117 case OVS_KEY_ATTR_SCTP
: return "sctp";
118 case OVS_KEY_ATTR_ICMP
: return "icmp";
119 case OVS_KEY_ATTR_ICMPV6
: return "icmpv6";
120 case OVS_KEY_ATTR_ARP
: return "arp";
121 case OVS_KEY_ATTR_ND
: return "nd";
122 case OVS_KEY_ATTR_MPLS
: return "mpls";
123 case OVS_KEY_ATTR_DP_HASH
: return "dp_hash";
124 case OVS_KEY_ATTR_RECIRC_ID
: return "recirc_id";
126 case __OVS_KEY_ATTR_MAX
:
128 snprintf(namebuf
, bufsize
, "key%u", (unsigned int) attr
);
134 format_generic_odp_action(struct ds
*ds
, const struct nlattr
*a
)
136 size_t len
= nl_attr_get_size(a
);
138 ds_put_format(ds
, "action%"PRId16
, nl_attr_type(a
));
140 const uint8_t *unspec
;
143 unspec
= nl_attr_get(a
);
144 for (i
= 0; i
< len
; i
++) {
145 ds_put_char(ds
, i
? ' ': '(');
146 ds_put_format(ds
, "%02x", unspec
[i
]);
148 ds_put_char(ds
, ')');
153 format_odp_sample_action(struct ds
*ds
, const struct nlattr
*attr
)
155 static const struct nl_policy ovs_sample_policy
[] = {
156 [OVS_SAMPLE_ATTR_PROBABILITY
] = { .type
= NL_A_U32
},
157 [OVS_SAMPLE_ATTR_ACTIONS
] = { .type
= NL_A_NESTED
}
159 struct nlattr
*a
[ARRAY_SIZE(ovs_sample_policy
)];
161 const struct nlattr
*nla_acts
;
164 ds_put_cstr(ds
, "sample");
166 if (!nl_parse_nested(attr
, ovs_sample_policy
, a
, ARRAY_SIZE(a
))) {
167 ds_put_cstr(ds
, "(error)");
171 percentage
= (100.0 * nl_attr_get_u32(a
[OVS_SAMPLE_ATTR_PROBABILITY
])) /
174 ds_put_format(ds
, "(sample=%.1f%%,", percentage
);
176 ds_put_cstr(ds
, "actions(");
177 nla_acts
= nl_attr_get(a
[OVS_SAMPLE_ATTR_ACTIONS
]);
178 len
= nl_attr_get_size(a
[OVS_SAMPLE_ATTR_ACTIONS
]);
179 format_odp_actions(ds
, nla_acts
, len
);
180 ds_put_format(ds
, "))");
184 slow_path_reason_to_string(uint32_t reason
)
186 switch ((enum slow_path_reason
) reason
) {
187 #define SPR(ENUM, STRING, EXPLANATION) case ENUM: return STRING;
196 slow_path_reason_to_explanation(enum slow_path_reason reason
)
199 #define SPR(ENUM, STRING, EXPLANATION) case ENUM: return EXPLANATION;
208 parse_flags(const char *s
, const char *(*bit_to_string
)(uint32_t),
219 while (s
[n
] != ')') {
220 unsigned long long int flags
;
224 if (ovs_scan(&s
[n
], "%lli%n", &flags
, &n0
)) {
225 n
+= n0
+ (s
[n
+ n0
] == ',');
230 for (bit
= 1; bit
; bit
<<= 1) {
231 const char *name
= bit_to_string(bit
);
239 if (!strncmp(s
+ n
, name
, len
) &&
240 (s
[n
+ len
] == ',' || s
[n
+ len
] == ')')) {
242 n
+= len
+ (s
[n
+ len
] == ',');
258 format_odp_userspace_action(struct ds
*ds
, const struct nlattr
*attr
)
260 static const struct nl_policy ovs_userspace_policy
[] = {
261 [OVS_USERSPACE_ATTR_PID
] = { .type
= NL_A_U32
},
262 [OVS_USERSPACE_ATTR_USERDATA
] = { .type
= NL_A_UNSPEC
,
264 [OVS_USERSPACE_ATTR_EGRESS_TUN_PORT
] = { .type
= NL_A_U32
,
267 struct nlattr
*a
[ARRAY_SIZE(ovs_userspace_policy
)];
268 const struct nlattr
*userdata_attr
;
269 const struct nlattr
*tunnel_out_port_attr
;
271 if (!nl_parse_nested(attr
, ovs_userspace_policy
, a
, ARRAY_SIZE(a
))) {
272 ds_put_cstr(ds
, "userspace(error)");
276 ds_put_format(ds
, "userspace(pid=%"PRIu32
,
277 nl_attr_get_u32(a
[OVS_USERSPACE_ATTR_PID
]));
279 userdata_attr
= a
[OVS_USERSPACE_ATTR_USERDATA
];
282 const uint8_t *userdata
= nl_attr_get(userdata_attr
);
283 size_t userdata_len
= nl_attr_get_size(userdata_attr
);
284 bool userdata_unspec
= true;
285 union user_action_cookie cookie
;
287 if (userdata_len
>= sizeof cookie
.type
288 && userdata_len
<= sizeof cookie
) {
290 memset(&cookie
, 0, sizeof cookie
);
291 memcpy(&cookie
, userdata
, userdata_len
);
293 userdata_unspec
= false;
295 if (userdata_len
== sizeof cookie
.sflow
296 && cookie
.type
== USER_ACTION_COOKIE_SFLOW
) {
297 ds_put_format(ds
, ",sFlow("
298 "vid=%"PRIu16
",pcp=%"PRIu8
",output=%"PRIu32
")",
299 vlan_tci_to_vid(cookie
.sflow
.vlan_tci
),
300 vlan_tci_to_pcp(cookie
.sflow
.vlan_tci
),
301 cookie
.sflow
.output
);
302 } else if (userdata_len
== sizeof cookie
.slow_path
303 && cookie
.type
== USER_ACTION_COOKIE_SLOW_PATH
) {
304 ds_put_cstr(ds
, ",slow_path(");
305 format_flags(ds
, slow_path_reason_to_string
,
306 cookie
.slow_path
.reason
, ',');
307 ds_put_format(ds
, ")");
308 } else if (userdata_len
== sizeof cookie
.flow_sample
309 && cookie
.type
== USER_ACTION_COOKIE_FLOW_SAMPLE
) {
310 ds_put_format(ds
, ",flow_sample(probability=%"PRIu16
311 ",collector_set_id=%"PRIu32
312 ",obs_domain_id=%"PRIu32
313 ",obs_point_id=%"PRIu32
")",
314 cookie
.flow_sample
.probability
,
315 cookie
.flow_sample
.collector_set_id
,
316 cookie
.flow_sample
.obs_domain_id
,
317 cookie
.flow_sample
.obs_point_id
);
318 } else if (userdata_len
>= sizeof cookie
.ipfix
319 && cookie
.type
== USER_ACTION_COOKIE_IPFIX
) {
320 ds_put_format(ds
, ",ipfix(output_port=%"PRIu32
")",
321 cookie
.ipfix
.output_odp_port
);
323 userdata_unspec
= true;
327 if (userdata_unspec
) {
329 ds_put_format(ds
, ",userdata(");
330 for (i
= 0; i
< userdata_len
; i
++) {
331 ds_put_format(ds
, "%02x", userdata
[i
]);
333 ds_put_char(ds
, ')');
337 tunnel_out_port_attr
= a
[OVS_USERSPACE_ATTR_EGRESS_TUN_PORT
];
338 if (tunnel_out_port_attr
) {
339 ds_put_format(ds
, ",tunnel_out_port=%"PRIu32
,
340 nl_attr_get_u32(tunnel_out_port_attr
));
343 ds_put_char(ds
, ')');
347 format_vlan_tci(struct ds
*ds
, ovs_be16 vlan_tci
)
349 ds_put_format(ds
, "vid=%"PRIu16
",pcp=%d",
350 vlan_tci_to_vid(vlan_tci
),
351 vlan_tci_to_pcp(vlan_tci
));
352 if (!(vlan_tci
& htons(VLAN_CFI
))) {
353 ds_put_cstr(ds
, ",cfi=0");
358 format_mpls_lse(struct ds
*ds
, ovs_be32 mpls_lse
)
360 ds_put_format(ds
, "label=%"PRIu32
",tc=%d,ttl=%d,bos=%d",
361 mpls_lse_to_label(mpls_lse
),
362 mpls_lse_to_tc(mpls_lse
),
363 mpls_lse_to_ttl(mpls_lse
),
364 mpls_lse_to_bos(mpls_lse
));
368 format_mpls(struct ds
*ds
, const struct ovs_key_mpls
*mpls_key
,
369 const struct ovs_key_mpls
*mpls_mask
, int n
)
372 ovs_be32 key
= mpls_key
->mpls_lse
;
374 if (mpls_mask
== NULL
) {
375 format_mpls_lse(ds
, key
);
377 ovs_be32 mask
= mpls_mask
->mpls_lse
;
379 ds_put_format(ds
, "label=%"PRIu32
"/0x%x,tc=%d/%x,ttl=%d/0x%x,bos=%d/%x",
380 mpls_lse_to_label(key
), mpls_lse_to_label(mask
),
381 mpls_lse_to_tc(key
), mpls_lse_to_tc(mask
),
382 mpls_lse_to_ttl(key
), mpls_lse_to_ttl(mask
),
383 mpls_lse_to_bos(key
), mpls_lse_to_bos(mask
));
388 for (i
= 0; i
< n
; i
++) {
389 ds_put_format(ds
, "lse%d=%#"PRIx32
,
390 i
, ntohl(mpls_key
[i
].mpls_lse
));
392 ds_put_format(ds
, "/%#"PRIx32
, ntohl(mpls_mask
[i
].mpls_lse
));
394 ds_put_char(ds
, ',');
401 format_odp_recirc_action(struct ds
*ds
, uint32_t recirc_id
)
403 ds_put_format(ds
, "recirc(%"PRIu32
")", recirc_id
);
407 format_odp_hash_action(struct ds
*ds
, const struct ovs_action_hash
*hash_act
)
409 ds_put_format(ds
, "hash(");
411 if (hash_act
->hash_alg
== OVS_HASH_ALG_L4
) {
412 ds_put_format(ds
, "hash_l4(%"PRIu32
")", hash_act
->hash_basis
);
414 ds_put_format(ds
, "Unknown hash algorithm(%"PRIu32
")",
417 ds_put_format(ds
, ")");
421 format_odp_action(struct ds
*ds
, const struct nlattr
*a
)
424 enum ovs_action_attr type
= nl_attr_type(a
);
425 const struct ovs_action_push_vlan
*vlan
;
427 expected_len
= odp_action_len(nl_attr_type(a
));
428 if (expected_len
!= -2 && nl_attr_get_size(a
) != expected_len
) {
429 ds_put_format(ds
, "bad length %"PRIuSIZE
", expected %d for: ",
430 nl_attr_get_size(a
), expected_len
);
431 format_generic_odp_action(ds
, a
);
436 case OVS_ACTION_ATTR_OUTPUT
:
437 ds_put_format(ds
, "%"PRIu32
, nl_attr_get_u32(a
));
439 case OVS_ACTION_ATTR_USERSPACE
:
440 format_odp_userspace_action(ds
, a
);
442 case OVS_ACTION_ATTR_RECIRC
:
443 format_odp_recirc_action(ds
, nl_attr_get_u32(a
));
445 case OVS_ACTION_ATTR_HASH
:
446 format_odp_hash_action(ds
, nl_attr_get(a
));
448 case OVS_ACTION_ATTR_SET
:
449 ds_put_cstr(ds
, "set(");
450 format_odp_key_attr(nl_attr_get(a
), NULL
, NULL
, ds
, true);
451 ds_put_cstr(ds
, ")");
453 case OVS_ACTION_ATTR_PUSH_VLAN
:
454 vlan
= nl_attr_get(a
);
455 ds_put_cstr(ds
, "push_vlan(");
456 if (vlan
->vlan_tpid
!= htons(ETH_TYPE_VLAN
)) {
457 ds_put_format(ds
, "tpid=0x%04"PRIx16
",", ntohs(vlan
->vlan_tpid
));
459 format_vlan_tci(ds
, vlan
->vlan_tci
);
460 ds_put_char(ds
, ')');
462 case OVS_ACTION_ATTR_POP_VLAN
:
463 ds_put_cstr(ds
, "pop_vlan");
465 case OVS_ACTION_ATTR_PUSH_MPLS
: {
466 const struct ovs_action_push_mpls
*mpls
= nl_attr_get(a
);
467 ds_put_cstr(ds
, "push_mpls(");
468 format_mpls_lse(ds
, mpls
->mpls_lse
);
469 ds_put_format(ds
, ",eth_type=0x%"PRIx16
")", ntohs(mpls
->mpls_ethertype
));
472 case OVS_ACTION_ATTR_POP_MPLS
: {
473 ovs_be16 ethertype
= nl_attr_get_be16(a
);
474 ds_put_format(ds
, "pop_mpls(eth_type=0x%"PRIx16
")", ntohs(ethertype
));
477 case OVS_ACTION_ATTR_SAMPLE
:
478 format_odp_sample_action(ds
, a
);
480 case OVS_ACTION_ATTR_UNSPEC
:
481 case __OVS_ACTION_ATTR_MAX
:
483 format_generic_odp_action(ds
, a
);
489 format_odp_actions(struct ds
*ds
, const struct nlattr
*actions
,
493 const struct nlattr
*a
;
496 NL_ATTR_FOR_EACH (a
, left
, actions
, actions_len
) {
498 ds_put_char(ds
, ',');
500 format_odp_action(ds
, a
);
505 if (left
== actions_len
) {
506 ds_put_cstr(ds
, "<empty>");
508 ds_put_format(ds
, ",***%u leftover bytes*** (", left
);
509 for (i
= 0; i
< left
; i
++) {
510 ds_put_format(ds
, "%02x", ((const uint8_t *) a
)[i
]);
512 ds_put_char(ds
, ')');
515 ds_put_cstr(ds
, "drop");
519 /* Separate out parse_odp_userspace_action() function. */
521 parse_odp_userspace_action(const char *s
, struct ofpbuf
*actions
)
524 union user_action_cookie cookie
;
526 odp_port_t tunnel_out_port
;
528 void *user_data
= NULL
;
529 size_t user_data_size
= 0;
531 if (!ovs_scan(s
, "userspace(pid=%"SCNi32
"%n", &pid
, &n
)) {
537 uint32_t probability
;
538 uint32_t collector_set_id
;
539 uint32_t obs_domain_id
;
540 uint32_t obs_point_id
;
543 if (ovs_scan(&s
[n
], ",sFlow(vid=%i,"
544 "pcp=%i,output=%"SCNi32
")%n",
545 &vid
, &pcp
, &output
, &n1
)) {
549 tci
= vid
| (pcp
<< VLAN_PCP_SHIFT
);
554 cookie
.type
= USER_ACTION_COOKIE_SFLOW
;
555 cookie
.sflow
.vlan_tci
= htons(tci
);
556 cookie
.sflow
.output
= output
;
558 user_data_size
= sizeof cookie
.sflow
;
559 } else if (ovs_scan(&s
[n
], ",slow_path%n",
564 cookie
.type
= USER_ACTION_COOKIE_SLOW_PATH
;
565 cookie
.slow_path
.unused
= 0;
566 cookie
.slow_path
.reason
= 0;
568 res
= parse_flags(&s
[n
], slow_path_reason_to_string
,
569 &cookie
.slow_path
.reason
);
576 user_data_size
= sizeof cookie
.slow_path
;
577 } else if (ovs_scan(&s
[n
], ",flow_sample(probability=%"SCNi32
","
578 "collector_set_id=%"SCNi32
","
579 "obs_domain_id=%"SCNi32
","
580 "obs_point_id=%"SCNi32
")%n",
581 &probability
, &collector_set_id
,
582 &obs_domain_id
, &obs_point_id
, &n1
)) {
585 cookie
.type
= USER_ACTION_COOKIE_FLOW_SAMPLE
;
586 cookie
.flow_sample
.probability
= probability
;
587 cookie
.flow_sample
.collector_set_id
= collector_set_id
;
588 cookie
.flow_sample
.obs_domain_id
= obs_domain_id
;
589 cookie
.flow_sample
.obs_point_id
= obs_point_id
;
591 user_data_size
= sizeof cookie
.flow_sample
;
592 } else if (ovs_scan(&s
[n
], ",ipfix(output_port=%"SCNi32
")%n",
595 cookie
.type
= USER_ACTION_COOKIE_IPFIX
;
596 cookie
.ipfix
.output_odp_port
= u32_to_odp(output
);
598 user_data_size
= sizeof cookie
.ipfix
;
599 } else if (ovs_scan(&s
[n
], ",userdata(%n",
604 ofpbuf_init(&buf
, 16);
605 end
= ofpbuf_put_hex(&buf
, &s
[n
], NULL
);
609 user_data
= ofpbuf_data(&buf
);
610 user_data_size
= ofpbuf_size(&buf
);
617 if (ovs_scan(&s
[n
], ",tunnel_out_port=%"SCNi32
")%n",
618 &tunnel_out_port
, &n1
)) {
619 odp_put_userspace_action(pid
, user_data
, user_data_size
, tunnel_out_port
, actions
);
621 } else if (s
[n
] == ')') {
622 odp_put_userspace_action(pid
, user_data
, user_data_size
, ODPP_NONE
, actions
);
631 parse_odp_action(const char *s
, const struct simap
*port_names
,
632 struct ofpbuf
*actions
)
638 if (ovs_scan(s
, "%"SCNi32
"%n", &port
, &n
)) {
639 nl_msg_put_u32(actions
, OVS_ACTION_ATTR_OUTPUT
, port
);
645 int len
= strcspn(s
, delimiters
);
646 struct simap_node
*node
;
648 node
= simap_find_len(port_names
, s
, len
);
650 nl_msg_put_u32(actions
, OVS_ACTION_ATTR_OUTPUT
, node
->data
);
655 if (!strncmp(s
, "userspace(", 10)) {
656 return parse_odp_userspace_action(s
, actions
);
659 if (!strncmp(s
, "set(", 4)) {
663 start_ofs
= nl_msg_start_nested(actions
, OVS_ACTION_ATTR_SET
);
664 retval
= parse_odp_key_mask_attr(s
+ 4, port_names
, actions
, NULL
);
668 if (s
[retval
+ 4] != ')') {
671 nl_msg_end_nested(actions
, start_ofs
);
676 struct ovs_action_push_vlan push
;
677 int tpid
= ETH_TYPE_VLAN
;
682 if (ovs_scan(s
, "push_vlan(vid=%i,pcp=%i)%n", &vid
, &pcp
, &n
)
683 || ovs_scan(s
, "push_vlan(vid=%i,pcp=%i,cfi=%i)%n",
684 &vid
, &pcp
, &cfi
, &n
)
685 || ovs_scan(s
, "push_vlan(tpid=%i,vid=%i,pcp=%i)%n",
686 &tpid
, &vid
, &pcp
, &n
)
687 || ovs_scan(s
, "push_vlan(tpid=%i,vid=%i,pcp=%i,cfi=%i)%n",
688 &tpid
, &vid
, &pcp
, &cfi
, &n
)) {
689 push
.vlan_tpid
= htons(tpid
);
690 push
.vlan_tci
= htons((vid
<< VLAN_VID_SHIFT
)
691 | (pcp
<< VLAN_PCP_SHIFT
)
692 | (cfi
? VLAN_CFI
: 0));
693 nl_msg_put_unspec(actions
, OVS_ACTION_ATTR_PUSH_VLAN
,
700 if (!strncmp(s
, "pop_vlan", 8)) {
701 nl_msg_put_flag(actions
, OVS_ACTION_ATTR_POP_VLAN
);
709 if (ovs_scan(s
, "sample(sample=%lf%%,actions(%n", &percentage
, &n
)
710 && percentage
>= 0. && percentage
<= 100.0) {
711 size_t sample_ofs
, actions_ofs
;
714 probability
= floor(UINT32_MAX
* (percentage
/ 100.0) + .5);
715 sample_ofs
= nl_msg_start_nested(actions
, OVS_ACTION_ATTR_SAMPLE
);
716 nl_msg_put_u32(actions
, OVS_SAMPLE_ATTR_PROBABILITY
,
717 (probability
<= 0 ? 0
718 : probability
>= UINT32_MAX
? UINT32_MAX
721 actions_ofs
= nl_msg_start_nested(actions
,
722 OVS_SAMPLE_ATTR_ACTIONS
);
726 n
+= strspn(s
+ n
, delimiters
);
731 retval
= parse_odp_action(s
+ n
, port_names
, actions
);
737 nl_msg_end_nested(actions
, actions_ofs
);
738 nl_msg_end_nested(actions
, sample_ofs
);
740 return s
[n
+ 1] == ')' ? n
+ 2 : -EINVAL
;
747 /* Parses the string representation of datapath actions, in the format output
748 * by format_odp_action(). Returns 0 if successful, otherwise a positive errno
749 * value. On success, the ODP actions are appended to 'actions' as a series of
750 * Netlink attributes. On failure, no data is appended to 'actions'. Either
751 * way, 'actions''s data might be reallocated. */
753 odp_actions_from_string(const char *s
, const struct simap
*port_names
,
754 struct ofpbuf
*actions
)
758 if (!strcasecmp(s
, "drop")) {
762 old_size
= ofpbuf_size(actions
);
766 s
+= strspn(s
, delimiters
);
771 retval
= parse_odp_action(s
, port_names
, actions
);
772 if (retval
< 0 || !strchr(delimiters
, s
[retval
])) {
773 ofpbuf_set_size(actions
, old_size
);
782 /* Returns the correct length of the payload for a flow key attribute of the
783 * specified 'type', -1 if 'type' is unknown, or -2 if the attribute's payload
784 * is variable length. */
786 odp_flow_key_attr_len(uint16_t type
)
788 if (type
> OVS_KEY_ATTR_MAX
) {
792 switch ((enum ovs_key_attr
) type
) {
793 case OVS_KEY_ATTR_ENCAP
: return -2;
794 case OVS_KEY_ATTR_PRIORITY
: return 4;
795 case OVS_KEY_ATTR_SKB_MARK
: return 4;
796 case OVS_KEY_ATTR_DP_HASH
: return 4;
797 case OVS_KEY_ATTR_RECIRC_ID
: return 4;
798 case OVS_KEY_ATTR_TUNNEL
: return -2;
799 case OVS_KEY_ATTR_IN_PORT
: return 4;
800 case OVS_KEY_ATTR_ETHERNET
: return sizeof(struct ovs_key_ethernet
);
801 case OVS_KEY_ATTR_VLAN
: return sizeof(ovs_be16
);
802 case OVS_KEY_ATTR_ETHERTYPE
: return 2;
803 case OVS_KEY_ATTR_MPLS
: return -2;
804 case OVS_KEY_ATTR_IPV4
: return sizeof(struct ovs_key_ipv4
);
805 case OVS_KEY_ATTR_IPV6
: return sizeof(struct ovs_key_ipv6
);
806 case OVS_KEY_ATTR_TCP
: return sizeof(struct ovs_key_tcp
);
807 case OVS_KEY_ATTR_TCP_FLAGS
: return 2;
808 case OVS_KEY_ATTR_UDP
: return sizeof(struct ovs_key_udp
);
809 case OVS_KEY_ATTR_SCTP
: return sizeof(struct ovs_key_sctp
);
810 case OVS_KEY_ATTR_ICMP
: return sizeof(struct ovs_key_icmp
);
811 case OVS_KEY_ATTR_ICMPV6
: return sizeof(struct ovs_key_icmpv6
);
812 case OVS_KEY_ATTR_ARP
: return sizeof(struct ovs_key_arp
);
813 case OVS_KEY_ATTR_ND
: return sizeof(struct ovs_key_nd
);
815 case OVS_KEY_ATTR_UNSPEC
:
816 case __OVS_KEY_ATTR_MAX
:
824 format_generic_odp_key(const struct nlattr
*a
, struct ds
*ds
)
826 size_t len
= nl_attr_get_size(a
);
828 const uint8_t *unspec
;
831 unspec
= nl_attr_get(a
);
832 for (i
= 0; i
< len
; i
++) {
834 ds_put_char(ds
, ' ');
836 ds_put_format(ds
, "%02x", unspec
[i
]);
842 ovs_frag_type_to_string(enum ovs_frag_type type
)
845 case OVS_FRAG_TYPE_NONE
:
847 case OVS_FRAG_TYPE_FIRST
:
849 case OVS_FRAG_TYPE_LATER
:
851 case __OVS_FRAG_TYPE_MAX
:
858 tunnel_key_attr_len(int type
)
861 case OVS_TUNNEL_KEY_ATTR_ID
: return 8;
862 case OVS_TUNNEL_KEY_ATTR_IPV4_SRC
: return 4;
863 case OVS_TUNNEL_KEY_ATTR_IPV4_DST
: return 4;
864 case OVS_TUNNEL_KEY_ATTR_TOS
: return 1;
865 case OVS_TUNNEL_KEY_ATTR_TTL
: return 1;
866 case OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT
: return 0;
867 case OVS_TUNNEL_KEY_ATTR_CSUM
: return 0;
868 case OVS_TUNNEL_KEY_ATTR_TP_SRC
: return 2;
869 case OVS_TUNNEL_KEY_ATTR_TP_DST
: return 2;
870 case OVS_TUNNEL_KEY_ATTR_OAM
: return 0;
871 case OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS
: return -2;
872 case __OVS_TUNNEL_KEY_ATTR_MAX
:
878 #define GENEVE_OPT(class, type) ((OVS_FORCE uint32_t)(class) << 8 | (type))
880 parse_geneve_opts(const struct nlattr
*attr
)
882 int opts_len
= nl_attr_get_size(attr
);
883 const struct geneve_opt
*opt
= nl_attr_get(attr
);
885 while (opts_len
> 0) {
888 if (opts_len
< sizeof(*opt
)) {
892 len
= sizeof(*opt
) + opt
->length
* 4;
893 if (len
> opts_len
) {
897 switch (GENEVE_OPT(opt
->opt_class
, opt
->type
)) {
899 if (opt
->type
& GENEVE_CRIT_OPT_TYPE
) {
904 opt
= opt
+ len
/ sizeof(*opt
);
912 odp_tun_key_from_attr(const struct nlattr
*attr
, struct flow_tnl
*tun
)
915 const struct nlattr
*a
;
917 bool unknown
= false;
919 NL_NESTED_FOR_EACH(a
, left
, attr
) {
920 uint16_t type
= nl_attr_type(a
);
921 size_t len
= nl_attr_get_size(a
);
922 int expected_len
= tunnel_key_attr_len(type
);
924 if (len
!= expected_len
&& expected_len
>= 0) {
925 return ODP_FIT_ERROR
;
929 case OVS_TUNNEL_KEY_ATTR_ID
:
930 tun
->tun_id
= nl_attr_get_be64(a
);
931 tun
->flags
|= FLOW_TNL_F_KEY
;
933 case OVS_TUNNEL_KEY_ATTR_IPV4_SRC
:
934 tun
->ip_src
= nl_attr_get_be32(a
);
936 case OVS_TUNNEL_KEY_ATTR_IPV4_DST
:
937 tun
->ip_dst
= nl_attr_get_be32(a
);
939 case OVS_TUNNEL_KEY_ATTR_TOS
:
940 tun
->ip_tos
= nl_attr_get_u8(a
);
942 case OVS_TUNNEL_KEY_ATTR_TTL
:
943 tun
->ip_ttl
= nl_attr_get_u8(a
);
946 case OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT
:
947 tun
->flags
|= FLOW_TNL_F_DONT_FRAGMENT
;
949 case OVS_TUNNEL_KEY_ATTR_CSUM
:
950 tun
->flags
|= FLOW_TNL_F_CSUM
;
952 case OVS_TUNNEL_KEY_ATTR_TP_SRC
:
953 tun
->tp_src
= nl_attr_get_be16(a
);
955 case OVS_TUNNEL_KEY_ATTR_TP_DST
:
956 tun
->tp_dst
= nl_attr_get_be16(a
);
958 case OVS_TUNNEL_KEY_ATTR_OAM
:
959 tun
->flags
|= FLOW_TNL_F_OAM
;
961 case OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS
: {
962 if (parse_geneve_opts(a
)) {
963 return ODP_FIT_ERROR
;
965 /* It is necessary to reproduce options exactly (including order)
966 * so it's easiest to just echo them back. */
971 /* Allow this to show up as unexpected, if there are unknown
972 * tunnel attribute, eventually resulting in ODP_FIT_TOO_MUCH. */
979 return ODP_FIT_ERROR
;
982 return ODP_FIT_TOO_MUCH
;
984 return ODP_FIT_PERFECT
;
988 tun_key_to_attr(struct ofpbuf
*a
, const struct flow_tnl
*tun_key
)
992 tun_key_ofs
= nl_msg_start_nested(a
, OVS_KEY_ATTR_TUNNEL
);
994 /* tun_id != 0 without FLOW_TNL_F_KEY is valid if tun_key is a mask. */
995 if (tun_key
->tun_id
|| tun_key
->flags
& FLOW_TNL_F_KEY
) {
996 nl_msg_put_be64(a
, OVS_TUNNEL_KEY_ATTR_ID
, tun_key
->tun_id
);
998 if (tun_key
->ip_src
) {
999 nl_msg_put_be32(a
, OVS_TUNNEL_KEY_ATTR_IPV4_SRC
, tun_key
->ip_src
);
1001 if (tun_key
->ip_dst
) {
1002 nl_msg_put_be32(a
, OVS_TUNNEL_KEY_ATTR_IPV4_DST
, tun_key
->ip_dst
);
1004 if (tun_key
->ip_tos
) {
1005 nl_msg_put_u8(a
, OVS_TUNNEL_KEY_ATTR_TOS
, tun_key
->ip_tos
);
1007 nl_msg_put_u8(a
, OVS_TUNNEL_KEY_ATTR_TTL
, tun_key
->ip_ttl
);
1008 if (tun_key
->flags
& FLOW_TNL_F_DONT_FRAGMENT
) {
1009 nl_msg_put_flag(a
, OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT
);
1011 if (tun_key
->flags
& FLOW_TNL_F_CSUM
) {
1012 nl_msg_put_flag(a
, OVS_TUNNEL_KEY_ATTR_CSUM
);
1014 if (tun_key
->tp_src
) {
1015 nl_msg_put_be16(a
, OVS_TUNNEL_KEY_ATTR_TP_SRC
, tun_key
->tp_src
);
1017 if (tun_key
->tp_dst
) {
1018 nl_msg_put_be16(a
, OVS_TUNNEL_KEY_ATTR_TP_DST
, tun_key
->tp_dst
);
1020 if (tun_key
->flags
& FLOW_TNL_F_OAM
) {
1021 nl_msg_put_flag(a
, OVS_TUNNEL_KEY_ATTR_OAM
);
1024 nl_msg_end_nested(a
, tun_key_ofs
);
1028 odp_mask_attr_is_wildcard(const struct nlattr
*ma
)
1030 return is_all_zeros(nl_attr_get(ma
), nl_attr_get_size(ma
));
1034 odp_mask_attr_is_exact(const struct nlattr
*ma
)
1036 bool is_exact
= false;
1037 enum ovs_key_attr attr
= nl_attr_type(ma
);
1039 if (attr
== OVS_KEY_ATTR_TUNNEL
) {
1040 /* XXX this is a hack for now. Should change
1041 * the exact match dection to per field
1042 * instead of per attribute.
1044 struct flow_tnl tun_mask
;
1045 memset(&tun_mask
, 0, sizeof tun_mask
);
1046 odp_tun_key_from_attr(ma
, &tun_mask
);
1047 if (tun_mask
.flags
== (FLOW_TNL_F_KEY
1048 | FLOW_TNL_F_DONT_FRAGMENT
1050 | FLOW_TNL_F_OAM
)) {
1051 /* The flags are exact match, check the remaining fields. */
1052 tun_mask
.flags
= 0xffff;
1053 is_exact
= is_all_ones((uint8_t *)&tun_mask
,
1054 offsetof(struct flow_tnl
, ip_ttl
));
1057 is_exact
= is_all_ones(nl_attr_get(ma
), nl_attr_get_size(ma
));
1064 odp_portno_names_set(struct hmap
*portno_names
, odp_port_t port_no
,
1067 struct odp_portno_names
*odp_portno_names
;
1069 odp_portno_names
= xmalloc(sizeof *odp_portno_names
);
1070 odp_portno_names
->port_no
= port_no
;
1071 odp_portno_names
->name
= xstrdup(port_name
);
1072 hmap_insert(portno_names
, &odp_portno_names
->hmap_node
,
1073 hash_odp_port(port_no
));
1077 odp_portno_names_get(const struct hmap
*portno_names
, odp_port_t port_no
)
1079 struct odp_portno_names
*odp_portno_names
;
1081 HMAP_FOR_EACH_IN_BUCKET (odp_portno_names
, hmap_node
,
1082 hash_odp_port(port_no
), portno_names
) {
1083 if (odp_portno_names
->port_no
== port_no
) {
1084 return odp_portno_names
->name
;
1091 odp_portno_names_destroy(struct hmap
*portno_names
)
1093 struct odp_portno_names
*odp_portno_names
, *odp_portno_names_next
;
1094 HMAP_FOR_EACH_SAFE (odp_portno_names
, odp_portno_names_next
,
1095 hmap_node
, portno_names
) {
1096 hmap_remove(portno_names
, &odp_portno_names
->hmap_node
);
1097 free(odp_portno_names
->name
);
1098 free(odp_portno_names
);
1103 format_odp_key_attr(const struct nlattr
*a
, const struct nlattr
*ma
,
1104 const struct hmap
*portno_names
, struct ds
*ds
,
1107 struct flow_tnl tun_key
;
1108 enum ovs_key_attr attr
= nl_attr_type(a
);
1109 char namebuf
[OVS_KEY_ATTR_BUFSIZE
];
1113 is_exact
= ma
? odp_mask_attr_is_exact(ma
) : true;
1115 ds_put_cstr(ds
, ovs_key_attr_to_string(attr
, namebuf
, sizeof namebuf
));
1118 expected_len
= odp_flow_key_attr_len(nl_attr_type(a
));
1119 if (expected_len
!= -2) {
1120 bool bad_key_len
= nl_attr_get_size(a
) != expected_len
;
1121 bool bad_mask_len
= ma
&& nl_attr_get_size(ma
) != expected_len
;
1123 if (bad_key_len
|| bad_mask_len
) {
1125 ds_put_format(ds
, "(bad key length %"PRIuSIZE
", expected %d)(",
1126 nl_attr_get_size(a
), expected_len
);
1128 format_generic_odp_key(a
, ds
);
1130 ds_put_char(ds
, '/');
1132 ds_put_format(ds
, "(bad mask length %"PRIuSIZE
", expected %d)(",
1133 nl_attr_get_size(ma
), expected_len
);
1135 format_generic_odp_key(ma
, ds
);
1137 ds_put_char(ds
, ')');
1143 ds_put_char(ds
, '(');
1145 case OVS_KEY_ATTR_ENCAP
:
1146 if (ma
&& nl_attr_get_size(ma
) && nl_attr_get_size(a
)) {
1147 odp_flow_format(nl_attr_get(a
), nl_attr_get_size(a
),
1148 nl_attr_get(ma
), nl_attr_get_size(ma
), NULL
, ds
,
1150 } else if (nl_attr_get_size(a
)) {
1151 odp_flow_format(nl_attr_get(a
), nl_attr_get_size(a
), NULL
, 0, NULL
,
1156 case OVS_KEY_ATTR_PRIORITY
:
1157 case OVS_KEY_ATTR_SKB_MARK
:
1158 case OVS_KEY_ATTR_DP_HASH
:
1159 case OVS_KEY_ATTR_RECIRC_ID
:
1160 ds_put_format(ds
, "%#"PRIx32
, nl_attr_get_u32(a
));
1162 ds_put_format(ds
, "/%#"PRIx32
, nl_attr_get_u32(ma
));
1166 case OVS_KEY_ATTR_TUNNEL
:
1167 memset(&tun_key
, 0, sizeof tun_key
);
1168 if (odp_tun_key_from_attr(a
, &tun_key
) == ODP_FIT_ERROR
) {
1169 ds_put_format(ds
, "error");
1170 } else if (!is_exact
) {
1171 struct flow_tnl tun_mask
;
1173 memset(&tun_mask
, 0, sizeof tun_mask
);
1174 odp_tun_key_from_attr(ma
, &tun_mask
);
1175 ds_put_format(ds
, "tun_id=%#"PRIx64
"/%#"PRIx64
1176 ",src="IP_FMT
"/"IP_FMT
",dst="IP_FMT
"/"IP_FMT
1177 ",tos=%#"PRIx8
"/%#"PRIx8
",ttl=%"PRIu8
"/%#"PRIx8
1179 ntohll(tun_key
.tun_id
), ntohll(tun_mask
.tun_id
),
1180 IP_ARGS(tun_key
.ip_src
), IP_ARGS(tun_mask
.ip_src
),
1181 IP_ARGS(tun_key
.ip_dst
), IP_ARGS(tun_mask
.ip_dst
),
1182 tun_key
.ip_tos
, tun_mask
.ip_tos
,
1183 tun_key
.ip_ttl
, tun_mask
.ip_ttl
);
1185 format_flags(ds
, flow_tun_flag_to_string
, tun_key
.flags
, ',');
1187 /* XXX This code is correct, but enabling it would break the unit
1188 test. Disable it for now until the input parser is fixed.
1190 ds_put_char(ds, '/');
1191 format_flags(ds, flow_tun_flag_to_string, tun_mask.flags, ',');
1193 ds_put_char(ds
, ')');
1195 ds_put_format(ds
, "tun_id=0x%"PRIx64
",src="IP_FMT
",dst="IP_FMT
","
1196 "tos=0x%"PRIx8
",ttl=%"PRIu8
",flags(",
1197 ntohll(tun_key
.tun_id
),
1198 IP_ARGS(tun_key
.ip_src
),
1199 IP_ARGS(tun_key
.ip_dst
),
1200 tun_key
.ip_tos
, tun_key
.ip_ttl
);
1202 format_flags(ds
, flow_tun_flag_to_string
, tun_key
.flags
, ',');
1203 ds_put_char(ds
, ')');
1207 case OVS_KEY_ATTR_IN_PORT
:
1208 if (portno_names
&& verbose
&& is_exact
) {
1209 char *name
= odp_portno_names_get(portno_names
,
1210 u32_to_odp(nl_attr_get_u32(a
)));
1212 ds_put_format(ds
, "%s", name
);
1214 ds_put_format(ds
, "%"PRIu32
, nl_attr_get_u32(a
));
1217 ds_put_format(ds
, "%"PRIu32
, nl_attr_get_u32(a
));
1219 ds_put_format(ds
, "/%#"PRIx32
, nl_attr_get_u32(ma
));
1224 case OVS_KEY_ATTR_ETHERNET
:
1226 const struct ovs_key_ethernet
*eth_mask
= nl_attr_get(ma
);
1227 const struct ovs_key_ethernet
*eth_key
= nl_attr_get(a
);
1229 ds_put_format(ds
, "src="ETH_ADDR_FMT
"/"ETH_ADDR_FMT
1230 ",dst="ETH_ADDR_FMT
"/"ETH_ADDR_FMT
,
1231 ETH_ADDR_ARGS(eth_key
->eth_src
),
1232 ETH_ADDR_ARGS(eth_mask
->eth_src
),
1233 ETH_ADDR_ARGS(eth_key
->eth_dst
),
1234 ETH_ADDR_ARGS(eth_mask
->eth_dst
));
1236 const struct ovs_key_ethernet
*eth_key
= nl_attr_get(a
);
1238 ds_put_format(ds
, "src="ETH_ADDR_FMT
",dst="ETH_ADDR_FMT
,
1239 ETH_ADDR_ARGS(eth_key
->eth_src
),
1240 ETH_ADDR_ARGS(eth_key
->eth_dst
));
1244 case OVS_KEY_ATTR_VLAN
:
1246 ovs_be16 vlan_tci
= nl_attr_get_be16(a
);
1248 ovs_be16 mask
= nl_attr_get_be16(ma
);
1249 ds_put_format(ds
, "vid=%"PRIu16
"/0x%"PRIx16
",pcp=%d/0x%x,cfi=%d/%d",
1250 vlan_tci_to_vid(vlan_tci
),
1251 vlan_tci_to_vid(mask
),
1252 vlan_tci_to_pcp(vlan_tci
),
1253 vlan_tci_to_pcp(mask
),
1254 vlan_tci_to_cfi(vlan_tci
),
1255 vlan_tci_to_cfi(mask
));
1257 format_vlan_tci(ds
, vlan_tci
);
1262 case OVS_KEY_ATTR_MPLS
: {
1263 const struct ovs_key_mpls
*mpls_key
= nl_attr_get(a
);
1264 const struct ovs_key_mpls
*mpls_mask
= NULL
;
1265 size_t size
= nl_attr_get_size(a
);
1267 if (!size
|| size
% sizeof *mpls_key
) {
1268 ds_put_format(ds
, "(bad key length %"PRIuSIZE
")",
1269 nl_attr_get_size(a
));
1273 mpls_mask
= nl_attr_get(ma
);
1274 if (nl_attr_get_size(a
) != nl_attr_get_size(ma
)) {
1275 ds_put_format(ds
, "(key length %"PRIuSIZE
" != "
1276 "mask length %"PRIuSIZE
")",
1277 nl_attr_get_size(a
), nl_attr_get_size(ma
));
1281 format_mpls(ds
, mpls_key
, mpls_mask
, size
/ sizeof *mpls_key
);
1285 case OVS_KEY_ATTR_ETHERTYPE
:
1286 ds_put_format(ds
, "0x%04"PRIx16
, ntohs(nl_attr_get_be16(a
)));
1288 ds_put_format(ds
, "/0x%04"PRIx16
, ntohs(nl_attr_get_be16(ma
)));
1292 case OVS_KEY_ATTR_IPV4
:
1294 const struct ovs_key_ipv4
*ipv4_key
= nl_attr_get(a
);
1295 const struct ovs_key_ipv4
*ipv4_mask
= nl_attr_get(ma
);
1297 ds_put_format(ds
, "src="IP_FMT
"/"IP_FMT
",dst="IP_FMT
"/"IP_FMT
1298 ",proto=%"PRIu8
"/%#"PRIx8
",tos=%#"PRIx8
"/%#"PRIx8
1299 ",ttl=%"PRIu8
"/%#"PRIx8
",frag=%s/%#"PRIx8
,
1300 IP_ARGS(ipv4_key
->ipv4_src
),
1301 IP_ARGS(ipv4_mask
->ipv4_src
),
1302 IP_ARGS(ipv4_key
->ipv4_dst
),
1303 IP_ARGS(ipv4_mask
->ipv4_dst
),
1304 ipv4_key
->ipv4_proto
, ipv4_mask
->ipv4_proto
,
1305 ipv4_key
->ipv4_tos
, ipv4_mask
->ipv4_tos
,
1306 ipv4_key
->ipv4_ttl
, ipv4_mask
->ipv4_ttl
,
1307 ovs_frag_type_to_string(ipv4_key
->ipv4_frag
),
1308 ipv4_mask
->ipv4_frag
);
1310 const struct ovs_key_ipv4
*ipv4_key
= nl_attr_get(a
);
1312 ds_put_format(ds
, "src="IP_FMT
",dst="IP_FMT
",proto=%"PRIu8
1313 ",tos=%#"PRIx8
",ttl=%"PRIu8
",frag=%s",
1314 IP_ARGS(ipv4_key
->ipv4_src
),
1315 IP_ARGS(ipv4_key
->ipv4_dst
),
1316 ipv4_key
->ipv4_proto
, ipv4_key
->ipv4_tos
,
1318 ovs_frag_type_to_string(ipv4_key
->ipv4_frag
));
1322 case OVS_KEY_ATTR_IPV6
:
1324 const struct ovs_key_ipv6
*ipv6_key
, *ipv6_mask
;
1325 char src_str
[INET6_ADDRSTRLEN
];
1326 char dst_str
[INET6_ADDRSTRLEN
];
1327 char src_mask
[INET6_ADDRSTRLEN
];
1328 char dst_mask
[INET6_ADDRSTRLEN
];
1330 ipv6_key
= nl_attr_get(a
);
1331 inet_ntop(AF_INET6
, ipv6_key
->ipv6_src
, src_str
, sizeof src_str
);
1332 inet_ntop(AF_INET6
, ipv6_key
->ipv6_dst
, dst_str
, sizeof dst_str
);
1334 ipv6_mask
= nl_attr_get(ma
);
1335 inet_ntop(AF_INET6
, ipv6_mask
->ipv6_src
, src_mask
, sizeof src_mask
);
1336 inet_ntop(AF_INET6
, ipv6_mask
->ipv6_dst
, dst_mask
, sizeof dst_mask
);
1338 ds_put_format(ds
, "src=%s/%s,dst=%s/%s,label=%#"PRIx32
"/%#"PRIx32
1339 ",proto=%"PRIu8
"/%#"PRIx8
",tclass=%#"PRIx8
"/%#"PRIx8
1340 ",hlimit=%"PRIu8
"/%#"PRIx8
",frag=%s/%#"PRIx8
,
1341 src_str
, src_mask
, dst_str
, dst_mask
,
1342 ntohl(ipv6_key
->ipv6_label
),
1343 ntohl(ipv6_mask
->ipv6_label
),
1344 ipv6_key
->ipv6_proto
, ipv6_mask
->ipv6_proto
,
1345 ipv6_key
->ipv6_tclass
, ipv6_mask
->ipv6_tclass
,
1346 ipv6_key
->ipv6_hlimit
, ipv6_mask
->ipv6_hlimit
,
1347 ovs_frag_type_to_string(ipv6_key
->ipv6_frag
),
1348 ipv6_mask
->ipv6_frag
);
1350 const struct ovs_key_ipv6
*ipv6_key
;
1351 char src_str
[INET6_ADDRSTRLEN
];
1352 char dst_str
[INET6_ADDRSTRLEN
];
1354 ipv6_key
= nl_attr_get(a
);
1355 inet_ntop(AF_INET6
, ipv6_key
->ipv6_src
, src_str
, sizeof src_str
);
1356 inet_ntop(AF_INET6
, ipv6_key
->ipv6_dst
, dst_str
, sizeof dst_str
);
1358 ds_put_format(ds
, "src=%s,dst=%s,label=%#"PRIx32
",proto=%"PRIu8
1359 ",tclass=%#"PRIx8
",hlimit=%"PRIu8
",frag=%s",
1360 src_str
, dst_str
, ntohl(ipv6_key
->ipv6_label
),
1361 ipv6_key
->ipv6_proto
, ipv6_key
->ipv6_tclass
,
1362 ipv6_key
->ipv6_hlimit
,
1363 ovs_frag_type_to_string(ipv6_key
->ipv6_frag
));
1367 case OVS_KEY_ATTR_TCP
:
1369 const struct ovs_key_tcp
*tcp_mask
= nl_attr_get(ma
);
1370 const struct ovs_key_tcp
*tcp_key
= nl_attr_get(a
);
1372 ds_put_format(ds
, "src=%"PRIu16
"/%#"PRIx16
1373 ",dst=%"PRIu16
"/%#"PRIx16
,
1374 ntohs(tcp_key
->tcp_src
), ntohs(tcp_mask
->tcp_src
),
1375 ntohs(tcp_key
->tcp_dst
), ntohs(tcp_mask
->tcp_dst
));
1377 const struct ovs_key_tcp
*tcp_key
= nl_attr_get(a
);
1379 ds_put_format(ds
, "src=%"PRIu16
",dst=%"PRIu16
,
1380 ntohs(tcp_key
->tcp_src
), ntohs(tcp_key
->tcp_dst
));
1384 case OVS_KEY_ATTR_TCP_FLAGS
:
1385 ds_put_format(ds
, "0x%03"PRIx16
, ntohs(nl_attr_get_be16(a
)));
1387 ds_put_format(ds
, "/0x%03"PRIx16
, ntohs(nl_attr_get_be16(ma
)));
1391 case OVS_KEY_ATTR_UDP
:
1393 const struct ovs_key_udp
*udp_mask
= nl_attr_get(ma
);
1394 const struct ovs_key_udp
*udp_key
= nl_attr_get(a
);
1396 ds_put_format(ds
, "src=%"PRIu16
"/%#"PRIx16
1397 ",dst=%"PRIu16
"/%#"PRIx16
,
1398 ntohs(udp_key
->udp_src
), ntohs(udp_mask
->udp_src
),
1399 ntohs(udp_key
->udp_dst
), ntohs(udp_mask
->udp_dst
));
1401 const struct ovs_key_udp
*udp_key
= nl_attr_get(a
);
1403 ds_put_format(ds
, "src=%"PRIu16
",dst=%"PRIu16
,
1404 ntohs(udp_key
->udp_src
), ntohs(udp_key
->udp_dst
));
1408 case OVS_KEY_ATTR_SCTP
:
1410 const struct ovs_key_sctp
*sctp_mask
= nl_attr_get(ma
);
1411 const struct ovs_key_sctp
*sctp_key
= nl_attr_get(a
);
1413 ds_put_format(ds
, "src=%"PRIu16
"/%#"PRIx16
1414 ",dst=%"PRIu16
"/%#"PRIx16
,
1415 ntohs(sctp_key
->sctp_src
), ntohs(sctp_mask
->sctp_src
),
1416 ntohs(sctp_key
->sctp_dst
), ntohs(sctp_mask
->sctp_dst
));
1418 const struct ovs_key_sctp
*sctp_key
= nl_attr_get(a
);
1420 ds_put_format(ds
, "src=%"PRIu16
",dst=%"PRIu16
,
1421 ntohs(sctp_key
->sctp_src
), ntohs(sctp_key
->sctp_dst
));
1425 case OVS_KEY_ATTR_ICMP
:
1427 const struct ovs_key_icmp
*icmp_mask
= nl_attr_get(ma
);
1428 const struct ovs_key_icmp
*icmp_key
= nl_attr_get(a
);
1430 ds_put_format(ds
, "type=%"PRIu8
"/%#"PRIx8
",code=%"PRIu8
"/%#"PRIx8
,
1431 icmp_key
->icmp_type
, icmp_mask
->icmp_type
,
1432 icmp_key
->icmp_code
, icmp_mask
->icmp_code
);
1434 const struct ovs_key_icmp
*icmp_key
= nl_attr_get(a
);
1436 ds_put_format(ds
, "type=%"PRIu8
",code=%"PRIu8
,
1437 icmp_key
->icmp_type
, icmp_key
->icmp_code
);
1441 case OVS_KEY_ATTR_ICMPV6
:
1443 const struct ovs_key_icmpv6
*icmpv6_mask
= nl_attr_get(ma
);
1444 const struct ovs_key_icmpv6
*icmpv6_key
= nl_attr_get(a
);
1446 ds_put_format(ds
, "type=%"PRIu8
"/%#"PRIx8
",code=%"PRIu8
"/%#"PRIx8
,
1447 icmpv6_key
->icmpv6_type
, icmpv6_mask
->icmpv6_type
,
1448 icmpv6_key
->icmpv6_code
, icmpv6_mask
->icmpv6_code
);
1450 const struct ovs_key_icmpv6
*icmpv6_key
= nl_attr_get(a
);
1452 ds_put_format(ds
, "type=%"PRIu8
",code=%"PRIu8
,
1453 icmpv6_key
->icmpv6_type
, icmpv6_key
->icmpv6_code
);
1457 case OVS_KEY_ATTR_ARP
:
1459 const struct ovs_key_arp
*arp_mask
= nl_attr_get(ma
);
1460 const struct ovs_key_arp
*arp_key
= nl_attr_get(a
);
1462 ds_put_format(ds
, "sip="IP_FMT
"/"IP_FMT
",tip="IP_FMT
"/"IP_FMT
1463 ",op=%"PRIu16
"/%#"PRIx16
1464 ",sha="ETH_ADDR_FMT
"/"ETH_ADDR_FMT
1465 ",tha="ETH_ADDR_FMT
"/"ETH_ADDR_FMT
,
1466 IP_ARGS(arp_key
->arp_sip
),
1467 IP_ARGS(arp_mask
->arp_sip
),
1468 IP_ARGS(arp_key
->arp_tip
),
1469 IP_ARGS(arp_mask
->arp_tip
),
1470 ntohs(arp_key
->arp_op
), ntohs(arp_mask
->arp_op
),
1471 ETH_ADDR_ARGS(arp_key
->arp_sha
),
1472 ETH_ADDR_ARGS(arp_mask
->arp_sha
),
1473 ETH_ADDR_ARGS(arp_key
->arp_tha
),
1474 ETH_ADDR_ARGS(arp_mask
->arp_tha
));
1476 const struct ovs_key_arp
*arp_key
= nl_attr_get(a
);
1478 ds_put_format(ds
, "sip="IP_FMT
",tip="IP_FMT
",op=%"PRIu16
","
1479 "sha="ETH_ADDR_FMT
",tha="ETH_ADDR_FMT
,
1480 IP_ARGS(arp_key
->arp_sip
), IP_ARGS(arp_key
->arp_tip
),
1481 ntohs(arp_key
->arp_op
),
1482 ETH_ADDR_ARGS(arp_key
->arp_sha
),
1483 ETH_ADDR_ARGS(arp_key
->arp_tha
));
1487 case OVS_KEY_ATTR_ND
: {
1488 const struct ovs_key_nd
*nd_key
, *nd_mask
= NULL
;
1489 char target
[INET6_ADDRSTRLEN
];
1491 nd_key
= nl_attr_get(a
);
1493 nd_mask
= nl_attr_get(ma
);
1496 inet_ntop(AF_INET6
, nd_key
->nd_target
, target
, sizeof target
);
1497 ds_put_format(ds
, "target=%s", target
);
1499 inet_ntop(AF_INET6
, nd_mask
->nd_target
, target
, sizeof target
);
1500 ds_put_format(ds
, "/%s", target
);
1503 if (!eth_addr_is_zero(nd_key
->nd_sll
)) {
1504 ds_put_format(ds
, ",sll="ETH_ADDR_FMT
,
1505 ETH_ADDR_ARGS(nd_key
->nd_sll
));
1507 ds_put_format(ds
, "/"ETH_ADDR_FMT
,
1508 ETH_ADDR_ARGS(nd_mask
->nd_sll
));
1511 if (!eth_addr_is_zero(nd_key
->nd_tll
)) {
1512 ds_put_format(ds
, ",tll="ETH_ADDR_FMT
,
1513 ETH_ADDR_ARGS(nd_key
->nd_tll
));
1515 ds_put_format(ds
, "/"ETH_ADDR_FMT
,
1516 ETH_ADDR_ARGS(nd_mask
->nd_tll
));
1521 case OVS_KEY_ATTR_UNSPEC
:
1522 case __OVS_KEY_ATTR_MAX
:
1524 format_generic_odp_key(a
, ds
);
1526 ds_put_char(ds
, '/');
1527 format_generic_odp_key(ma
, ds
);
1531 ds_put_char(ds
, ')');
1534 static struct nlattr
*
1535 generate_all_wildcard_mask(struct ofpbuf
*ofp
, const struct nlattr
*key
)
1537 const struct nlattr
*a
;
1539 int type
= nl_attr_type(key
);
1540 int size
= nl_attr_get_size(key
);
1542 if (odp_flow_key_attr_len(type
) >=0) {
1543 nl_msg_put_unspec_zero(ofp
, type
, size
);
1547 nested_mask
= nl_msg_start_nested(ofp
, type
);
1548 NL_ATTR_FOR_EACH(a
, left
, key
, nl_attr_get_size(key
)) {
1549 generate_all_wildcard_mask(ofp
, nl_attr_get(a
));
1551 nl_msg_end_nested(ofp
, nested_mask
);
1554 return ofpbuf_base(ofp
);
1557 /* Appends to 'ds' a string representation of the 'key_len' bytes of
1558 * OVS_KEY_ATTR_* attributes in 'key'. If non-null, additionally formats the
1559 * 'mask_len' bytes of 'mask' which apply to 'key'. If 'portno_names' is
1560 * non-null and 'verbose' is true, translates odp port number to its name. */
1562 odp_flow_format(const struct nlattr
*key
, size_t key_len
,
1563 const struct nlattr
*mask
, size_t mask_len
,
1564 const struct hmap
*portno_names
, struct ds
*ds
, bool verbose
)
1567 const struct nlattr
*a
;
1569 bool has_ethtype_key
= false;
1570 const struct nlattr
*ma
= NULL
;
1572 bool first_field
= true;
1574 ofpbuf_init(&ofp
, 100);
1575 NL_ATTR_FOR_EACH (a
, left
, key
, key_len
) {
1576 bool is_nested_attr
;
1577 bool is_wildcard
= false;
1578 int attr_type
= nl_attr_type(a
);
1580 if (attr_type
== OVS_KEY_ATTR_ETHERTYPE
) {
1581 has_ethtype_key
= true;
1584 is_nested_attr
= (odp_flow_key_attr_len(attr_type
) == -2);
1586 if (mask
&& mask_len
) {
1587 ma
= nl_attr_find__(mask
, mask_len
, nl_attr_type(a
));
1588 is_wildcard
= ma
? odp_mask_attr_is_wildcard(ma
) : true;
1591 if (verbose
|| !is_wildcard
|| is_nested_attr
) {
1592 if (is_wildcard
&& !ma
) {
1593 ma
= generate_all_wildcard_mask(&ofp
, a
);
1596 ds_put_char(ds
, ',');
1598 format_odp_key_attr(a
, ma
, portno_names
, ds
, verbose
);
1599 first_field
= false;
1603 ofpbuf_uninit(&ofp
);
1608 if (left
== key_len
) {
1609 ds_put_cstr(ds
, "<empty>");
1611 ds_put_format(ds
, ",***%u leftover bytes*** (", left
);
1612 for (i
= 0; i
< left
; i
++) {
1613 ds_put_format(ds
, "%02x", ((const uint8_t *) a
)[i
]);
1615 ds_put_char(ds
, ')');
1617 if (!has_ethtype_key
) {
1618 ma
= nl_attr_find__(mask
, mask_len
, OVS_KEY_ATTR_ETHERTYPE
);
1620 ds_put_format(ds
, ",eth_type(0/0x%04"PRIx16
")",
1621 ntohs(nl_attr_get_be16(ma
)));
1625 ds_put_cstr(ds
, "<empty>");
1629 /* Appends to 'ds' a string representation of the 'key_len' bytes of
1630 * OVS_KEY_ATTR_* attributes in 'key'. */
1632 odp_flow_key_format(const struct nlattr
*key
,
1633 size_t key_len
, struct ds
*ds
)
1635 odp_flow_format(key
, key_len
, NULL
, 0, NULL
, ds
, true);
1639 put_nd(struct ovs_key_nd
* nd_key
, const uint8_t *nd_sll
,
1640 const uint8_t *nd_tll
, struct ofpbuf
*key
)
1643 memcpy(nd_key
->nd_sll
, nd_sll
, ETH_ADDR_LEN
);
1647 memcpy(nd_key
->nd_tll
, nd_tll
, ETH_ADDR_LEN
);
1650 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ND
, nd_key
, sizeof *nd_key
);
1654 put_nd_key(int n
, const char *nd_target_s
, const uint8_t *nd_sll
,
1655 const uint8_t *nd_tll
, struct ofpbuf
*key
)
1657 struct ovs_key_nd nd_key
;
1659 memset(&nd_key
, 0, sizeof nd_key
);
1661 if (inet_pton(AF_INET6
, nd_target_s
, nd_key
.nd_target
) != 1) {
1665 put_nd(&nd_key
, nd_sll
, nd_tll
, key
);
1670 put_nd_mask(int n
, const char *nd_target_s
,
1671 const uint8_t *nd_sll
, const uint8_t *nd_tll
, struct ofpbuf
*mask
)
1673 struct ovs_key_nd nd_mask
;
1675 memset(&nd_mask
, 0xff, sizeof nd_mask
);
1677 if (strlen(nd_target_s
) != 0 &&
1678 inet_pton(AF_INET6
, nd_target_s
, nd_mask
.nd_target
) != 1) {
1682 put_nd(&nd_mask
, nd_sll
, nd_tll
, mask
);
1687 ovs_frag_type_from_string(const char *s
, enum ovs_frag_type
*type
)
1689 if (!strcasecmp(s
, "no")) {
1690 *type
= OVS_FRAG_TYPE_NONE
;
1691 } else if (!strcasecmp(s
, "first")) {
1692 *type
= OVS_FRAG_TYPE_FIRST
;
1693 } else if (!strcasecmp(s
, "later")) {
1694 *type
= OVS_FRAG_TYPE_LATER
;
1702 mpls_lse_from_components(int mpls_label
, int mpls_tc
, int mpls_ttl
, int mpls_bos
)
1704 return (htonl((mpls_label
<< MPLS_LABEL_SHIFT
) |
1705 (mpls_tc
<< MPLS_TC_SHIFT
) |
1706 (mpls_ttl
<< MPLS_TTL_SHIFT
) |
1707 (mpls_bos
<< MPLS_BOS_SHIFT
)));
1711 parse_odp_key_mask_attr(const char *s
, const struct simap
*port_names
,
1712 struct ofpbuf
*key
, struct ofpbuf
*mask
)
1716 uint32_t priority_mask
;
1719 if (mask
&& ovs_scan(s
, "skb_priority(%"SCNi32
"/%"SCNi32
")%n",
1720 &priority
, &priority_mask
, &n
)) {
1721 nl_msg_put_u32(key
, OVS_KEY_ATTR_PRIORITY
, priority
);
1722 nl_msg_put_u32(mask
, OVS_KEY_ATTR_PRIORITY
, priority_mask
);
1724 } else if (ovs_scan(s
, "skb_priority(%"SCNi32
")%n", &priority
, &n
)) {
1725 nl_msg_put_u32(key
, OVS_KEY_ATTR_PRIORITY
, priority
);
1727 nl_msg_put_u32(mask
, OVS_KEY_ATTR_PRIORITY
, UINT32_MAX
);
1738 if (mask
&& ovs_scan(s
, "skb_mark(%"SCNi32
"/%"SCNi32
")%n", &mark
,
1740 nl_msg_put_u32(key
, OVS_KEY_ATTR_SKB_MARK
, mark
);
1741 nl_msg_put_u32(mask
, OVS_KEY_ATTR_SKB_MARK
, mark_mask
);
1743 } else if (ovs_scan(s
, "skb_mark(%"SCNi32
")%n", &mark
, &n
)) {
1744 nl_msg_put_u32(key
, OVS_KEY_ATTR_SKB_MARK
, mark
);
1746 nl_msg_put_u32(mask
, OVS_KEY_ATTR_SKB_MARK
, UINT32_MAX
);
1756 if (ovs_scan(s
, "recirc_id(%"SCNi32
")%n", &recirc_id
, &n
)) {
1757 nl_msg_put_u32(key
, OVS_KEY_ATTR_RECIRC_ID
, recirc_id
);
1758 nl_msg_put_u32(mask
, OVS_KEY_ATTR_RECIRC_ID
, UINT32_MAX
);
1765 uint32_t dp_hash_mask
;
1768 if (mask
&& ovs_scan(s
, "dp_hash(%"SCNi32
"/%"SCNi32
")%n", &dp_hash
,
1769 &dp_hash_mask
, &n
)) {
1770 nl_msg_put_u32(key
, OVS_KEY_ATTR_DP_HASH
, dp_hash
);
1771 nl_msg_put_u32(mask
, OVS_KEY_ATTR_DP_HASH
, dp_hash_mask
);
1773 } else if (ovs_scan(s
, "dp_hash(%"SCNi32
")%n", &dp_hash
, &n
)) {
1774 nl_msg_put_u32(key
, OVS_KEY_ATTR_DP_HASH
, dp_hash
);
1776 nl_msg_put_u32(mask
, OVS_KEY_ATTR_DP_HASH
, UINT32_MAX
);
1783 uint64_t tun_id
, tun_id_mask
;
1784 struct flow_tnl tun_key
, tun_key_mask
;
1787 if (mask
&& ovs_scan(s
, "tunnel(tun_id=%"SCNi64
"/%"SCNi64
","
1788 "src="IP_SCAN_FMT
"/"IP_SCAN_FMT
",dst="IP_SCAN_FMT
1789 "/"IP_SCAN_FMT
",tos=%"SCNi8
"/%"SCNi8
","
1790 "ttl=%"SCNi8
"/%"SCNi8
",flags%n",
1791 &tun_id
, &tun_id_mask
,
1792 IP_SCAN_ARGS(&tun_key
.ip_src
),
1793 IP_SCAN_ARGS(&tun_key_mask
.ip_src
),
1794 IP_SCAN_ARGS(&tun_key
.ip_dst
),
1795 IP_SCAN_ARGS(&tun_key_mask
.ip_dst
),
1796 &tun_key
.ip_tos
, &tun_key_mask
.ip_tos
,
1797 &tun_key
.ip_ttl
, &tun_key_mask
.ip_ttl
, &n
)) {
1801 tun_key
.tun_id
= htonll(tun_id
);
1802 tun_key_mask
.tun_id
= htonll(tun_id_mask
);
1803 res
= parse_flags(&s
[n
], flow_tun_flag_to_string
, &flags
);
1804 tun_key
.flags
= flags
;
1805 tun_key_mask
.flags
= UINT16_MAX
;
1815 tun_key_to_attr(key
, &tun_key
);
1817 tun_key_to_attr(mask
, &tun_key_mask
);
1820 } else if (ovs_scan(s
, "tunnel(tun_id=%"SCNi64
","
1821 "src="IP_SCAN_FMT
",dst="IP_SCAN_FMT
1822 ",tos=%"SCNi8
",ttl=%"SCNi8
",flags%n", &tun_id
,
1823 IP_SCAN_ARGS(&tun_key
.ip_src
),
1824 IP_SCAN_ARGS(&tun_key
.ip_dst
),
1825 &tun_key
.ip_tos
, &tun_key
.ip_ttl
, &n
)) {
1829 tun_key
.tun_id
= htonll(tun_id
);
1830 res
= parse_flags(&s
[n
], flow_tun_flag_to_string
, &flags
);
1831 tun_key
.flags
= flags
;
1841 tun_key_to_attr(key
, &tun_key
);
1844 memset(&tun_key
, 0xff, sizeof tun_key
);
1845 tun_key_to_attr(mask
, &tun_key
);
1853 uint32_t in_port_mask
;
1856 if (mask
&& ovs_scan(s
, "in_port(%"SCNi32
"/%"SCNi32
")%n",
1857 &in_port
, &in_port_mask
, &n
)) {
1858 nl_msg_put_u32(key
, OVS_KEY_ATTR_IN_PORT
, in_port
);
1859 nl_msg_put_u32(mask
, OVS_KEY_ATTR_IN_PORT
, in_port_mask
);
1861 } else if (ovs_scan(s
, "in_port(%"SCNi32
")%n", &in_port
, &n
)) {
1862 nl_msg_put_u32(key
, OVS_KEY_ATTR_IN_PORT
, in_port
);
1864 nl_msg_put_u32(mask
, OVS_KEY_ATTR_IN_PORT
, UINT32_MAX
);
1871 if (port_names
&& !strncmp(s
, "in_port(", 8)) {
1873 const struct simap_node
*node
;
1877 name_len
= strcspn(name
, ")");
1878 node
= simap_find_len(port_names
, name
, name_len
);
1880 nl_msg_put_u32(key
, OVS_KEY_ATTR_IN_PORT
, node
->data
);
1883 nl_msg_put_u32(mask
, OVS_KEY_ATTR_IN_PORT
, UINT32_MAX
);
1885 return 8 + name_len
+ 1;
1890 struct ovs_key_ethernet eth_key
;
1891 struct ovs_key_ethernet eth_key_mask
;
1894 if (mask
&& ovs_scan(s
,
1895 "eth(src="ETH_ADDR_SCAN_FMT
"/"ETH_ADDR_SCAN_FMT
","
1896 "dst="ETH_ADDR_SCAN_FMT
"/"ETH_ADDR_SCAN_FMT
")%n",
1897 ETH_ADDR_SCAN_ARGS(eth_key
.eth_src
),
1898 ETH_ADDR_SCAN_ARGS(eth_key_mask
.eth_src
),
1899 ETH_ADDR_SCAN_ARGS(eth_key
.eth_dst
),
1900 ETH_ADDR_SCAN_ARGS(eth_key_mask
.eth_dst
), &n
)) {
1901 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ETHERNET
,
1902 ð_key
, sizeof eth_key
);
1903 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_ETHERNET
,
1904 ð_key_mask
, sizeof eth_key_mask
);
1906 } else if (ovs_scan(s
, "eth(src="ETH_ADDR_SCAN_FMT
","
1907 "dst="ETH_ADDR_SCAN_FMT
")%n",
1908 ETH_ADDR_SCAN_ARGS(eth_key
.eth_src
),
1909 ETH_ADDR_SCAN_ARGS(eth_key
.eth_dst
), &n
)) {
1910 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ETHERNET
,
1911 ð_key
, sizeof eth_key
);
1914 memset(ð_key
, 0xff, sizeof eth_key
);
1915 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_ETHERNET
,
1916 ð_key
, sizeof eth_key
);
1928 if (mask
&& ovs_scan(s
, "vlan(vid=%i/%i,pcp=%i/%i)%n",
1929 &vid
, &vid_mask
, &pcp
, &pcp_mask
, &n
)) {
1930 nl_msg_put_be16(key
, OVS_KEY_ATTR_VLAN
,
1931 htons((vid
<< VLAN_VID_SHIFT
) |
1932 (pcp
<< VLAN_PCP_SHIFT
) |
1934 nl_msg_put_be16(mask
, OVS_KEY_ATTR_VLAN
,
1935 htons((vid_mask
<< VLAN_VID_SHIFT
) |
1936 (pcp_mask
<< VLAN_PCP_SHIFT
) |
1937 (1 << VLAN_CFI_SHIFT
)));
1939 } else if (ovs_scan(s
, "vlan(vid=%i,pcp=%i)%n", &vid
, &pcp
, &n
)) {
1940 nl_msg_put_be16(key
, OVS_KEY_ATTR_VLAN
,
1941 htons((vid
<< VLAN_VID_SHIFT
) |
1942 (pcp
<< VLAN_PCP_SHIFT
) |
1945 nl_msg_put_be16(mask
, OVS_KEY_ATTR_VLAN
, OVS_BE16_MAX
);
1949 && ovs_scan(s
, "vlan(vid=%i/%i,pcp=%i/%i,cfi=%i/%i)%n",
1950 &vid
, &vid_mask
, &pcp
, &pcp_mask
,
1951 &cfi
, &cfi_mask
, &n
)) {
1952 nl_msg_put_be16(key
, OVS_KEY_ATTR_VLAN
,
1953 htons((vid
<< VLAN_VID_SHIFT
) |
1954 (pcp
<< VLAN_PCP_SHIFT
) |
1955 (cfi
? VLAN_CFI
: 0)));
1956 nl_msg_put_be16(mask
, OVS_KEY_ATTR_VLAN
,
1957 htons((vid_mask
<< VLAN_VID_SHIFT
) |
1958 (pcp_mask
<< VLAN_PCP_SHIFT
) |
1959 (cfi_mask
<< VLAN_CFI_SHIFT
)));
1961 } else if (ovs_scan(s
, "vlan(vid=%i,pcp=%i,cfi=%i)%n",
1962 &vid
, &pcp
, &cfi
, &n
)) {
1963 nl_msg_put_be16(key
, OVS_KEY_ATTR_VLAN
,
1964 htons((vid
<< VLAN_VID_SHIFT
) |
1965 (pcp
<< VLAN_PCP_SHIFT
) |
1966 (cfi
? VLAN_CFI
: 0)));
1968 nl_msg_put_be16(mask
, OVS_KEY_ATTR_VLAN
, OVS_BE16_MAX
);
1979 if (mask
&& ovs_scan(s
, "eth_type(%i/%i)%n",
1980 ð_type
, ð_type_mask
, &n
)) {
1981 if (eth_type
!= 0) {
1982 nl_msg_put_be16(key
, OVS_KEY_ATTR_ETHERTYPE
, htons(eth_type
));
1984 nl_msg_put_be16(mask
, OVS_KEY_ATTR_ETHERTYPE
, htons(eth_type_mask
));
1986 } else if (ovs_scan(s
, "eth_type(%i)%n", ð_type
, &n
)) {
1987 nl_msg_put_be16(key
, OVS_KEY_ATTR_ETHERTYPE
, htons(eth_type
));
1989 nl_msg_put_be16(mask
, OVS_KEY_ATTR_ETHERTYPE
, OVS_BE16_MAX
);
1996 int label
, tc
, ttl
, bos
;
1997 int label_mask
, tc_mask
, ttl_mask
, bos_mask
;
2000 if (mask
&& ovs_scan(s
, "mpls(label=%i/%i,tc=%i/%i,"
2001 "ttl=%i/%i,bos=%i/%i)%n",
2002 &label
, &label_mask
, &tc
, &tc_mask
,
2003 &ttl
, &ttl_mask
, &bos
, &bos_mask
, &n
)) {
2004 struct ovs_key_mpls
*mpls
, *mpls_mask
;
2006 mpls
= nl_msg_put_unspec_uninit(key
, OVS_KEY_ATTR_MPLS
,
2008 mpls
->mpls_lse
= mpls_lse_from_components(label
, tc
, ttl
, bos
);
2010 mpls_mask
= nl_msg_put_unspec_uninit(mask
, OVS_KEY_ATTR_MPLS
,
2012 mpls_mask
->mpls_lse
= mpls_lse_from_components(
2013 label_mask
, tc_mask
, ttl_mask
, bos_mask
);
2015 } else if (ovs_scan(s
, "mpls(label=%i,tc=%i,ttl=%i,bos=%i)%n",
2016 &label
, &tc
, &ttl
, &bos
, &n
)) {
2017 struct ovs_key_mpls
*mpls
;
2019 mpls
= nl_msg_put_unspec_uninit(key
, OVS_KEY_ATTR_MPLS
,
2021 mpls
->mpls_lse
= mpls_lse_from_components(label
, tc
, ttl
, bos
);
2023 mpls
= nl_msg_put_unspec_uninit(mask
, OVS_KEY_ATTR_MPLS
,
2025 mpls
->mpls_lse
= OVS_BE32_MAX
;
2033 struct ovs_key_ipv4 ipv4_key
;
2034 struct ovs_key_ipv4 ipv4_mask
;
2037 enum ovs_frag_type ipv4_frag
;
2041 && ovs_scan(s
, "ipv4(src="IP_SCAN_FMT
"/"IP_SCAN_FMT
","
2042 "dst="IP_SCAN_FMT
"/"IP_SCAN_FMT
","
2043 "proto=%"SCNi8
"/%"SCNi8
","
2044 "tos=%"SCNi8
"/%"SCNi8
","
2045 "ttl=%"SCNi8
"/%"SCNi8
","
2046 "frag=%7[a-z]/%"SCNi8
")%n",
2047 IP_SCAN_ARGS(&ipv4_key
.ipv4_src
),
2048 IP_SCAN_ARGS(&ipv4_mask
.ipv4_src
),
2049 IP_SCAN_ARGS(&ipv4_key
.ipv4_dst
),
2050 IP_SCAN_ARGS(&ipv4_mask
.ipv4_dst
),
2051 &ipv4_key
.ipv4_proto
, &ipv4_mask
.ipv4_proto
,
2052 &ipv4_key
.ipv4_tos
, &ipv4_mask
.ipv4_tos
,
2053 &ipv4_key
.ipv4_ttl
, &ipv4_mask
.ipv4_ttl
,
2054 frag
, &ipv4_mask
.ipv4_frag
, &n
)
2055 && ovs_frag_type_from_string(frag
, &ipv4_frag
)) {
2056 ipv4_key
.ipv4_frag
= ipv4_frag
;
2057 nl_msg_put_unspec(key
, OVS_KEY_ATTR_IPV4
,
2058 &ipv4_key
, sizeof ipv4_key
);
2060 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_IPV4
,
2061 &ipv4_mask
, sizeof ipv4_mask
);
2063 } else if (ovs_scan(s
, "ipv4(src="IP_SCAN_FMT
",dst="IP_SCAN_FMT
","
2064 "proto=%"SCNi8
",tos=%"SCNi8
",ttl=%"SCNi8
","
2066 IP_SCAN_ARGS(&ipv4_key
.ipv4_src
),
2067 IP_SCAN_ARGS(&ipv4_key
.ipv4_dst
),
2068 &ipv4_key
.ipv4_proto
,
2072 && ovs_frag_type_from_string(frag
, &ipv4_frag
)) {
2073 ipv4_key
.ipv4_frag
= ipv4_frag
;
2074 nl_msg_put_unspec(key
, OVS_KEY_ATTR_IPV4
,
2075 &ipv4_key
, sizeof ipv4_key
);
2078 memset(&ipv4_key
, 0xff, sizeof ipv4_key
);
2079 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_IPV4
,
2080 &ipv4_key
, sizeof ipv4_key
);
2087 char ipv6_src_s
[IPV6_SCAN_LEN
+ 1];
2088 char ipv6_src_mask_s
[IPV6_SCAN_LEN
+ 1];
2089 char ipv6_dst_s
[IPV6_SCAN_LEN
+ 1];
2090 char ipv6_dst_mask_s
[IPV6_SCAN_LEN
+ 1];
2091 int ipv6_label
, ipv6_label_mask
;
2092 int ipv6_proto
, ipv6_proto_mask
;
2093 int ipv6_tclass
, ipv6_tclass_mask
;
2094 int ipv6_hlimit
, ipv6_hlimit_mask
;
2096 enum ovs_frag_type ipv6_frag
;
2100 if (mask
&& ovs_scan(s
, "ipv6(src="IPV6_SCAN_FMT
"/"IPV6_SCAN_FMT
",dst="
2101 IPV6_SCAN_FMT
"/"IPV6_SCAN_FMT
","
2102 "label=%i/%i,proto=%i/%i,tclass=%i/%i,"
2103 "hlimit=%i/%i,frag=%7[a-z]/%i)%n",
2104 ipv6_src_s
, ipv6_src_mask_s
,
2105 ipv6_dst_s
, ipv6_dst_mask_s
,
2106 &ipv6_label
, &ipv6_label_mask
, &ipv6_proto
,
2107 &ipv6_proto_mask
, &ipv6_tclass
, &ipv6_tclass_mask
,
2108 &ipv6_hlimit
, &ipv6_hlimit_mask
, frag
,
2109 &ipv6_frag_mask
, &n
)
2110 && ovs_frag_type_from_string(frag
, &ipv6_frag
)) {
2111 struct ovs_key_ipv6 ipv6_key
;
2112 struct ovs_key_ipv6 ipv6_mask
;
2114 if (inet_pton(AF_INET6
, ipv6_src_s
, &ipv6_key
.ipv6_src
) != 1 ||
2115 inet_pton(AF_INET6
, ipv6_dst_s
, &ipv6_key
.ipv6_dst
) != 1 ||
2116 inet_pton(AF_INET6
, ipv6_src_mask_s
, &ipv6_mask
.ipv6_src
) != 1 ||
2117 inet_pton(AF_INET6
, ipv6_dst_mask_s
, &ipv6_mask
.ipv6_dst
) != 1) {
2121 ipv6_key
.ipv6_label
= htonl(ipv6_label
);
2122 ipv6_key
.ipv6_proto
= ipv6_proto
;
2123 ipv6_key
.ipv6_tclass
= ipv6_tclass
;
2124 ipv6_key
.ipv6_hlimit
= ipv6_hlimit
;
2125 ipv6_key
.ipv6_frag
= ipv6_frag
;
2126 nl_msg_put_unspec(key
, OVS_KEY_ATTR_IPV6
,
2127 &ipv6_key
, sizeof ipv6_key
);
2129 ipv6_mask
.ipv6_label
= htonl(ipv6_label_mask
);
2130 ipv6_mask
.ipv6_proto
= ipv6_proto_mask
;
2131 ipv6_mask
.ipv6_tclass
= ipv6_tclass_mask
;
2132 ipv6_mask
.ipv6_hlimit
= ipv6_hlimit_mask
;
2133 ipv6_mask
.ipv6_frag
= ipv6_frag_mask
;
2134 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_IPV6
,
2135 &ipv6_mask
, sizeof ipv6_mask
);
2137 } else if (ovs_scan(s
, "ipv6(src="IPV6_SCAN_FMT
",dst="IPV6_SCAN_FMT
","
2138 "label=%i,proto=%i,tclass=%i,hlimit=%i,"
2140 ipv6_src_s
, ipv6_dst_s
, &ipv6_label
,
2141 &ipv6_proto
, &ipv6_tclass
, &ipv6_hlimit
, frag
, &n
)
2142 && ovs_frag_type_from_string(frag
, &ipv6_frag
)) {
2143 struct ovs_key_ipv6 ipv6_key
;
2145 if (inet_pton(AF_INET6
, ipv6_src_s
, &ipv6_key
.ipv6_src
) != 1 ||
2146 inet_pton(AF_INET6
, ipv6_dst_s
, &ipv6_key
.ipv6_dst
) != 1) {
2149 ipv6_key
.ipv6_label
= htonl(ipv6_label
);
2150 ipv6_key
.ipv6_proto
= ipv6_proto
;
2151 ipv6_key
.ipv6_tclass
= ipv6_tclass
;
2152 ipv6_key
.ipv6_hlimit
= ipv6_hlimit
;
2153 ipv6_key
.ipv6_frag
= ipv6_frag
;
2154 nl_msg_put_unspec(key
, OVS_KEY_ATTR_IPV6
,
2155 &ipv6_key
, sizeof ipv6_key
);
2158 memset(&ipv6_key
, 0xff, sizeof ipv6_key
);
2159 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_IPV6
,
2160 &ipv6_key
, sizeof ipv6_key
);
2173 if (mask
&& ovs_scan(s
, "tcp(src=%i/%i,dst=%i/%i)%n",
2174 &tcp_src
, &tcp_src_mask
, &tcp_dst
,
2175 &tcp_dst_mask
, &n
)) {
2176 struct ovs_key_tcp tcp_key
;
2177 struct ovs_key_tcp tcp_mask
;
2179 tcp_key
.tcp_src
= htons(tcp_src
);
2180 tcp_key
.tcp_dst
= htons(tcp_dst
);
2181 nl_msg_put_unspec(key
, OVS_KEY_ATTR_TCP
, &tcp_key
, sizeof tcp_key
);
2183 tcp_mask
.tcp_src
= htons(tcp_src_mask
);
2184 tcp_mask
.tcp_dst
= htons(tcp_dst_mask
);
2185 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_TCP
,
2186 &tcp_mask
, sizeof tcp_mask
);
2188 } else if (ovs_scan(s
, "tcp(src=%i,dst=%i)%n",
2189 &tcp_src
, &tcp_dst
, &n
)) {
2190 struct ovs_key_tcp tcp_key
;
2192 tcp_key
.tcp_src
= htons(tcp_src
);
2193 tcp_key
.tcp_dst
= htons(tcp_dst
);
2194 nl_msg_put_unspec(key
, OVS_KEY_ATTR_TCP
, &tcp_key
, sizeof tcp_key
);
2197 memset(&tcp_key
, 0xff, sizeof tcp_key
);
2198 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_TCP
,
2199 &tcp_key
, sizeof tcp_key
);
2206 uint16_t tcp_flags
, tcp_flags_mask
;
2209 if (mask
&& ovs_scan(s
, "tcp_flags(%"SCNi16
"/%"SCNi16
")%n",
2210 &tcp_flags
, &tcp_flags_mask
, &n
) > 0 && n
> 0) {
2211 nl_msg_put_be16(key
, OVS_KEY_ATTR_TCP_FLAGS
, htons(tcp_flags
));
2212 nl_msg_put_be16(mask
, OVS_KEY_ATTR_TCP_FLAGS
, htons(tcp_flags_mask
));
2214 } else if (ovs_scan(s
, "tcp_flags(%"SCNi16
")%n", &tcp_flags
, &n
)) {
2215 nl_msg_put_be16(key
, OVS_KEY_ATTR_TCP_FLAGS
, htons(tcp_flags
));
2217 nl_msg_put_be16(mask
, OVS_KEY_ATTR_TCP_FLAGS
,
2231 if (mask
&& ovs_scan(s
, "udp(src=%i/%i,dst=%i/%i)%n",
2232 &udp_src
, &udp_src_mask
,
2233 &udp_dst
, &udp_dst_mask
, &n
)) {
2234 struct ovs_key_udp udp_key
;
2235 struct ovs_key_udp udp_mask
;
2237 udp_key
.udp_src
= htons(udp_src
);
2238 udp_key
.udp_dst
= htons(udp_dst
);
2239 nl_msg_put_unspec(key
, OVS_KEY_ATTR_UDP
, &udp_key
, sizeof udp_key
);
2241 udp_mask
.udp_src
= htons(udp_src_mask
);
2242 udp_mask
.udp_dst
= htons(udp_dst_mask
);
2243 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_UDP
,
2244 &udp_mask
, sizeof udp_mask
);
2247 if (ovs_scan(s
, "udp(src=%i,dst=%i)%n", &udp_src
, &udp_dst
, &n
)) {
2248 struct ovs_key_udp udp_key
;
2250 udp_key
.udp_src
= htons(udp_src
);
2251 udp_key
.udp_dst
= htons(udp_dst
);
2252 nl_msg_put_unspec(key
, OVS_KEY_ATTR_UDP
, &udp_key
, sizeof udp_key
);
2255 memset(&udp_key
, 0xff, sizeof udp_key
);
2256 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_UDP
, &udp_key
, sizeof udp_key
);
2269 if (mask
&& ovs_scan(s
, "sctp(src=%i/%i,dst=%i/%i)%n",
2270 &sctp_src
, &sctp_src_mask
,
2271 &sctp_dst
, &sctp_dst_mask
, &n
)) {
2272 struct ovs_key_sctp sctp_key
;
2273 struct ovs_key_sctp sctp_mask
;
2275 sctp_key
.sctp_src
= htons(sctp_src
);
2276 sctp_key
.sctp_dst
= htons(sctp_dst
);
2277 nl_msg_put_unspec(key
, OVS_KEY_ATTR_SCTP
, &sctp_key
, sizeof sctp_key
);
2279 sctp_mask
.sctp_src
= htons(sctp_src_mask
);
2280 sctp_mask
.sctp_dst
= htons(sctp_dst_mask
);
2281 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_SCTP
,
2282 &sctp_mask
, sizeof sctp_mask
);
2285 if (ovs_scan(s
, "sctp(src=%i,dst=%i)%n", &sctp_src
, &sctp_dst
, &n
)) {
2286 struct ovs_key_sctp sctp_key
;
2288 sctp_key
.sctp_src
= htons(sctp_src
);
2289 sctp_key
.sctp_dst
= htons(sctp_dst
);
2290 nl_msg_put_unspec(key
, OVS_KEY_ATTR_SCTP
, &sctp_key
, sizeof sctp_key
);
2293 memset(&sctp_key
, 0xff, sizeof sctp_key
);
2294 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_SCTP
, &sctp_key
, sizeof sctp_key
);
2301 struct ovs_key_icmp icmp_key
;
2302 struct ovs_key_icmp icmp_mask
;
2305 if (mask
&& ovs_scan(s
, "icmp(type=%"SCNi8
"/%"SCNi8
","
2306 "code=%"SCNi8
"/%"SCNi8
")%n",
2307 &icmp_key
.icmp_type
, &icmp_mask
.icmp_type
,
2308 &icmp_key
.icmp_code
, &icmp_mask
.icmp_code
, &n
)) {
2309 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ICMP
,
2310 &icmp_key
, sizeof icmp_key
);
2311 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_ICMP
,
2312 &icmp_mask
, sizeof icmp_mask
);
2314 } else if (ovs_scan(s
, "icmp(type=%"SCNi8
",code=%"SCNi8
")%n",
2315 &icmp_key
.icmp_type
, &icmp_key
.icmp_code
, &n
)) {
2316 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ICMP
,
2317 &icmp_key
, sizeof icmp_key
);
2319 memset(&icmp_key
, 0xff, sizeof icmp_key
);
2320 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_ICMP
, &icmp_key
,
2328 struct ovs_key_icmpv6 icmpv6_key
;
2329 struct ovs_key_icmpv6 icmpv6_mask
;
2332 if (mask
&& ovs_scan(s
, "icmpv6(type=%"SCNi8
"/%"SCNi8
","
2333 "code=%"SCNi8
"/%"SCNi8
")%n",
2334 &icmpv6_key
.icmpv6_type
, &icmpv6_mask
.icmpv6_type
,
2335 &icmpv6_key
.icmpv6_code
, &icmpv6_mask
.icmpv6_code
,
2337 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ICMPV6
,
2338 &icmpv6_key
, sizeof icmpv6_key
);
2339 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_ICMPV6
, &icmpv6_mask
,
2340 sizeof icmpv6_mask
);
2342 } else if (ovs_scan(s
, "icmpv6(type=%"SCNi8
",code=%"SCNi8
")%n",
2343 &icmpv6_key
.icmpv6_type
, &icmpv6_key
.icmpv6_code
,
2345 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ICMPV6
,
2346 &icmpv6_key
, sizeof icmpv6_key
);
2349 memset(&icmpv6_key
, 0xff, sizeof icmpv6_key
);
2350 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_ICMPV6
, &icmpv6_key
,
2358 struct ovs_key_arp arp_key
;
2359 struct ovs_key_arp arp_mask
;
2360 uint16_t arp_op
, arp_op_mask
;
2363 if (mask
&& ovs_scan(s
, "arp(sip="IP_SCAN_FMT
"/"IP_SCAN_FMT
","
2364 "tip="IP_SCAN_FMT
"/"IP_SCAN_FMT
","
2365 "op=%"SCNi16
"/%"SCNi16
","
2366 "sha="ETH_ADDR_SCAN_FMT
"/"ETH_ADDR_SCAN_FMT
","
2367 "tha="ETH_ADDR_SCAN_FMT
"/"ETH_ADDR_SCAN_FMT
")%n",
2368 IP_SCAN_ARGS(&arp_key
.arp_sip
),
2369 IP_SCAN_ARGS(&arp_mask
.arp_sip
),
2370 IP_SCAN_ARGS(&arp_key
.arp_tip
),
2371 IP_SCAN_ARGS(&arp_mask
.arp_tip
),
2372 &arp_op
, &arp_op_mask
,
2373 ETH_ADDR_SCAN_ARGS(arp_key
.arp_sha
),
2374 ETH_ADDR_SCAN_ARGS(arp_mask
.arp_sha
),
2375 ETH_ADDR_SCAN_ARGS(arp_key
.arp_tha
),
2376 ETH_ADDR_SCAN_ARGS(arp_mask
.arp_tha
), &n
)) {
2377 arp_key
.arp_op
= htons(arp_op
);
2378 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ARP
, &arp_key
, sizeof arp_key
);
2379 arp_mask
.arp_op
= htons(arp_op_mask
);
2380 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_ARP
,
2381 &arp_mask
, sizeof arp_mask
);
2383 } else if (ovs_scan(s
, "arp(sip="IP_SCAN_FMT
",tip="IP_SCAN_FMT
","
2384 "op=%"SCNi16
",sha="ETH_ADDR_SCAN_FMT
","
2385 "tha="ETH_ADDR_SCAN_FMT
")%n",
2386 IP_SCAN_ARGS(&arp_key
.arp_sip
),
2387 IP_SCAN_ARGS(&arp_key
.arp_tip
),
2389 ETH_ADDR_SCAN_ARGS(arp_key
.arp_sha
),
2390 ETH_ADDR_SCAN_ARGS(arp_key
.arp_tha
), &n
)) {
2391 arp_key
.arp_op
= htons(arp_op
);
2392 nl_msg_put_unspec(key
, OVS_KEY_ATTR_ARP
, &arp_key
, sizeof arp_key
);
2395 memset(&arp_key
, 0xff, sizeof arp_key
);
2396 nl_msg_put_unspec(mask
, OVS_KEY_ATTR_ARP
,
2397 &arp_key
, sizeof arp_key
);
2404 char nd_target_s
[IPV6_SCAN_LEN
+ 1];
2405 char nd_target_mask_s
[IPV6_SCAN_LEN
+ 1];
2406 uint8_t nd_sll
[ETH_ADDR_LEN
];
2407 uint8_t nd_sll_mask
[ETH_ADDR_LEN
];
2408 uint8_t nd_tll
[ETH_ADDR_LEN
];
2409 uint8_t nd_tll_mask
[ETH_ADDR_LEN
];
2412 nd_target_mask_s
[0] = 0;
2413 memset(nd_sll_mask
, 0xff, sizeof nd_sll_mask
);
2414 memset(nd_tll_mask
, 0xff, sizeof nd_tll_mask
);
2416 if (mask
&& ovs_scan(s
, "nd(target="IPV6_SCAN_FMT
"/"IPV6_SCAN_FMT
")%n",
2417 nd_target_s
, nd_target_mask_s
, &n
)) {
2418 put_nd_key(n
, nd_target_s
, NULL
, NULL
, key
);
2419 put_nd_mask(n
, nd_target_mask_s
, NULL
, NULL
, mask
);
2420 } else if (ovs_scan(s
, "nd(target="IPV6_SCAN_FMT
")%n",
2422 put_nd_key(n
, nd_target_s
, NULL
, NULL
, key
);
2424 put_nd_mask(n
, nd_target_mask_s
, NULL
, NULL
, mask
);
2427 ovs_scan(s
, "nd(target="IPV6_SCAN_FMT
"/"IPV6_SCAN_FMT
2428 ",sll="ETH_ADDR_SCAN_FMT
"/"ETH_ADDR_SCAN_FMT
")%n",
2429 nd_target_s
, nd_target_mask_s
,
2430 ETH_ADDR_SCAN_ARGS(nd_sll
),
2431 ETH_ADDR_SCAN_ARGS(nd_sll_mask
), &n
)) {
2432 put_nd_key(n
, nd_target_s
, nd_sll
, NULL
, key
);
2433 put_nd_mask(n
, nd_target_mask_s
, nd_sll_mask
, NULL
, mask
);
2434 } else if (ovs_scan(s
, "nd(target="IPV6_SCAN_FMT
","
2435 "sll="ETH_ADDR_SCAN_FMT
")%n",
2436 nd_target_s
, ETH_ADDR_SCAN_ARGS(nd_sll
), &n
)) {
2437 put_nd_key(n
, nd_target_s
, nd_sll
, NULL
, key
);
2439 put_nd_mask(n
, nd_target_mask_s
, nd_sll_mask
, NULL
, mask
);
2442 ovs_scan(s
, "nd(target="IPV6_SCAN_FMT
"/"IPV6_SCAN_FMT
2443 ",tll="ETH_ADDR_SCAN_FMT
"/"ETH_ADDR_SCAN_FMT
")%n",
2444 nd_target_s
, nd_target_mask_s
,
2445 ETH_ADDR_SCAN_ARGS(nd_tll
),
2446 ETH_ADDR_SCAN_ARGS(nd_tll_mask
), &n
)) {
2447 put_nd_key(n
, nd_target_s
, NULL
, nd_tll
, key
);
2448 put_nd_mask(n
, nd_target_mask_s
, NULL
, nd_tll_mask
, mask
);
2449 } else if (ovs_scan(s
, "nd(target="IPV6_SCAN_FMT
","
2450 "tll="ETH_ADDR_SCAN_FMT
")%n",
2451 nd_target_s
, ETH_ADDR_SCAN_ARGS(nd_tll
), &n
)) {
2452 put_nd_key(n
, nd_target_s
, NULL
, nd_tll
, key
);
2454 put_nd_mask(n
, nd_target_mask_s
, NULL
, nd_tll_mask
, mask
);
2457 ovs_scan(s
, "nd(target="IPV6_SCAN_FMT
"/"IPV6_SCAN_FMT
2458 ",sll="ETH_ADDR_SCAN_FMT
"/"ETH_ADDR_SCAN_FMT
","
2459 "tll="ETH_ADDR_SCAN_FMT
"/"ETH_ADDR_SCAN_FMT
")%n",
2460 nd_target_s
, nd_target_mask_s
,
2461 ETH_ADDR_SCAN_ARGS(nd_sll
),
2462 ETH_ADDR_SCAN_ARGS(nd_sll_mask
),
2463 ETH_ADDR_SCAN_ARGS(nd_tll
),
2464 ETH_ADDR_SCAN_ARGS(nd_tll_mask
),
2466 put_nd_key(n
, nd_target_s
, nd_sll
, nd_tll
, key
);
2467 put_nd_mask(n
, nd_target_mask_s
, nd_sll_mask
, nd_tll_mask
, mask
);
2468 } else if (ovs_scan(s
, "nd(target="IPV6_SCAN_FMT
","
2469 "sll="ETH_ADDR_SCAN_FMT
","
2470 "tll="ETH_ADDR_SCAN_FMT
")%n",
2471 nd_target_s
, ETH_ADDR_SCAN_ARGS(nd_sll
),
2472 ETH_ADDR_SCAN_ARGS(nd_tll
), &n
)) {
2473 put_nd_key(n
, nd_target_s
, nd_sll
, nd_tll
, key
);
2475 put_nd_mask(n
, nd_target_mask_s
,
2476 nd_sll_mask
, nd_tll_mask
, mask
);
2485 if (!strncmp(s
, "encap(", 6)) {
2486 const char *start
= s
;
2487 size_t encap
, encap_mask
= 0;
2489 encap
= nl_msg_start_nested(key
, OVS_KEY_ATTR_ENCAP
);
2491 encap_mask
= nl_msg_start_nested(mask
, OVS_KEY_ATTR_ENCAP
);
2498 s
+= strspn(s
, ", \t\r\n");
2501 } else if (*s
== ')') {
2505 retval
= parse_odp_key_mask_attr(s
, port_names
, key
, mask
);
2513 nl_msg_end_nested(key
, encap
);
2515 nl_msg_end_nested(mask
, encap_mask
);
2524 /* Parses the string representation of a datapath flow key, in the
2525 * format output by odp_flow_key_format(). Returns 0 if successful,
2526 * otherwise a positive errno value. On success, the flow key is
2527 * appended to 'key' as a series of Netlink attributes. On failure, no
2528 * data is appended to 'key'. Either way, 'key''s data might be
2531 * If 'port_names' is nonnull, it points to an simap that maps from a port name
2532 * to a port number. (Port names may be used instead of port numbers in
2535 * On success, the attributes appended to 'key' are individually syntactically
2536 * valid, but they may not be valid as a sequence. 'key' might, for example,
2537 * have duplicated keys. odp_flow_key_to_flow() will detect those errors. */
2539 odp_flow_from_string(const char *s
, const struct simap
*port_names
,
2540 struct ofpbuf
*key
, struct ofpbuf
*mask
)
2542 const size_t old_size
= ofpbuf_size(key
);
2546 s
+= strspn(s
, delimiters
);
2551 retval
= parse_odp_key_mask_attr(s
, port_names
, key
, mask
);
2553 ofpbuf_set_size(key
, old_size
);
2563 ovs_to_odp_frag(uint8_t nw_frag
)
2565 return (nw_frag
== 0 ? OVS_FRAG_TYPE_NONE
2566 : nw_frag
== FLOW_NW_FRAG_ANY
? OVS_FRAG_TYPE_FIRST
2567 : OVS_FRAG_TYPE_LATER
);
2571 ovs_to_odp_frag_mask(uint8_t nw_frag_mask
)
2573 uint8_t frag_mask
= ~(OVS_FRAG_TYPE_FIRST
| OVS_FRAG_TYPE_LATER
);
2575 frag_mask
|= (nw_frag_mask
& FLOW_NW_FRAG_ANY
) ? OVS_FRAG_TYPE_FIRST
: 0;
2576 frag_mask
|= (nw_frag_mask
& FLOW_NW_FRAG_LATER
) ? OVS_FRAG_TYPE_LATER
: 0;
2582 odp_flow_key_from_flow__(struct ofpbuf
*buf
, const struct flow
*flow
,
2583 const struct flow
*mask
, odp_port_t odp_in_port
,
2584 size_t max_mpls_depth
, bool recirc
, bool export_mask
)
2586 struct ovs_key_ethernet
*eth_key
;
2588 const struct flow
*data
= export_mask
? mask
: flow
;
2590 nl_msg_put_u32(buf
, OVS_KEY_ATTR_PRIORITY
, data
->skb_priority
);
2592 if (flow
->tunnel
.ip_dst
|| export_mask
) {
2593 tun_key_to_attr(buf
, &data
->tunnel
);
2596 nl_msg_put_u32(buf
, OVS_KEY_ATTR_SKB_MARK
, data
->pkt_mark
);
2599 nl_msg_put_u32(buf
, OVS_KEY_ATTR_RECIRC_ID
, data
->recirc_id
);
2600 nl_msg_put_u32(buf
, OVS_KEY_ATTR_DP_HASH
, data
->dp_hash
);
2603 /* Add an ingress port attribute if this is a mask or 'odp_in_port'
2604 * is not the magical value "ODPP_NONE". */
2605 if (export_mask
|| odp_in_port
!= ODPP_NONE
) {
2606 nl_msg_put_odp_port(buf
, OVS_KEY_ATTR_IN_PORT
, odp_in_port
);
2609 eth_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_ETHERNET
,
2611 memcpy(eth_key
->eth_src
, data
->dl_src
, ETH_ADDR_LEN
);
2612 memcpy(eth_key
->eth_dst
, data
->dl_dst
, ETH_ADDR_LEN
);
2614 if (flow
->vlan_tci
!= htons(0) || flow
->dl_type
== htons(ETH_TYPE_VLAN
)) {
2616 nl_msg_put_be16(buf
, OVS_KEY_ATTR_ETHERTYPE
, OVS_BE16_MAX
);
2618 nl_msg_put_be16(buf
, OVS_KEY_ATTR_ETHERTYPE
, htons(ETH_TYPE_VLAN
));
2620 nl_msg_put_be16(buf
, OVS_KEY_ATTR_VLAN
, data
->vlan_tci
);
2621 encap
= nl_msg_start_nested(buf
, OVS_KEY_ATTR_ENCAP
);
2622 if (flow
->vlan_tci
== htons(0)) {
2629 if (ntohs(flow
->dl_type
) < ETH_TYPE_MIN
) {
2630 /* For backwards compatibility with kernels that don't support
2631 * wildcarding, the following convention is used to encode the
2632 * OVS_KEY_ATTR_ETHERTYPE for key and mask:
2635 * -------- -------- -------
2636 * >0x5ff 0xffff Specified Ethernet II Ethertype.
2637 * >0x5ff 0 Any Ethernet II or non-Ethernet II frame.
2638 * <none> 0xffff Any non-Ethernet II frame (except valid
2639 * 802.3 SNAP packet with valid eth_type).
2642 nl_msg_put_be16(buf
, OVS_KEY_ATTR_ETHERTYPE
, OVS_BE16_MAX
);
2647 nl_msg_put_be16(buf
, OVS_KEY_ATTR_ETHERTYPE
, data
->dl_type
);
2649 if (flow
->dl_type
== htons(ETH_TYPE_IP
)) {
2650 struct ovs_key_ipv4
*ipv4_key
;
2652 ipv4_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_IPV4
,
2654 ipv4_key
->ipv4_src
= data
->nw_src
;
2655 ipv4_key
->ipv4_dst
= data
->nw_dst
;
2656 ipv4_key
->ipv4_proto
= data
->nw_proto
;
2657 ipv4_key
->ipv4_tos
= data
->nw_tos
;
2658 ipv4_key
->ipv4_ttl
= data
->nw_ttl
;
2659 ipv4_key
->ipv4_frag
= export_mask
? ovs_to_odp_frag_mask(data
->nw_frag
)
2660 : ovs_to_odp_frag(data
->nw_frag
);
2661 } else if (flow
->dl_type
== htons(ETH_TYPE_IPV6
)) {
2662 struct ovs_key_ipv6
*ipv6_key
;
2664 ipv6_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_IPV6
,
2666 memcpy(ipv6_key
->ipv6_src
, &data
->ipv6_src
, sizeof ipv6_key
->ipv6_src
);
2667 memcpy(ipv6_key
->ipv6_dst
, &data
->ipv6_dst
, sizeof ipv6_key
->ipv6_dst
);
2668 ipv6_key
->ipv6_label
= data
->ipv6_label
;
2669 ipv6_key
->ipv6_proto
= data
->nw_proto
;
2670 ipv6_key
->ipv6_tclass
= data
->nw_tos
;
2671 ipv6_key
->ipv6_hlimit
= data
->nw_ttl
;
2672 ipv6_key
->ipv6_frag
= export_mask
? ovs_to_odp_frag_mask(data
->nw_frag
)
2673 : ovs_to_odp_frag(data
->nw_frag
);
2674 } else if (flow
->dl_type
== htons(ETH_TYPE_ARP
) ||
2675 flow
->dl_type
== htons(ETH_TYPE_RARP
)) {
2676 struct ovs_key_arp
*arp_key
;
2678 arp_key
= nl_msg_put_unspec_zero(buf
, OVS_KEY_ATTR_ARP
,
2680 arp_key
->arp_sip
= data
->nw_src
;
2681 arp_key
->arp_tip
= data
->nw_dst
;
2682 arp_key
->arp_op
= htons(data
->nw_proto
);
2683 memcpy(arp_key
->arp_sha
, data
->arp_sha
, ETH_ADDR_LEN
);
2684 memcpy(arp_key
->arp_tha
, data
->arp_tha
, ETH_ADDR_LEN
);
2685 } else if (eth_type_mpls(flow
->dl_type
)) {
2686 struct ovs_key_mpls
*mpls_key
;
2689 n
= flow_count_mpls_labels(flow
, NULL
);
2690 n
= MIN(n
, max_mpls_depth
);
2691 mpls_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_MPLS
,
2692 n
* sizeof *mpls_key
);
2693 for (i
= 0; i
< n
; i
++) {
2694 mpls_key
[i
].mpls_lse
= data
->mpls_lse
[i
];
2698 if (is_ip_any(flow
) && !(flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
2699 if (flow
->nw_proto
== IPPROTO_TCP
) {
2700 struct ovs_key_tcp
*tcp_key
;
2702 tcp_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_TCP
,
2704 tcp_key
->tcp_src
= data
->tp_src
;
2705 tcp_key
->tcp_dst
= data
->tp_dst
;
2707 if (data
->tcp_flags
) {
2708 nl_msg_put_be16(buf
, OVS_KEY_ATTR_TCP_FLAGS
, data
->tcp_flags
);
2710 } else if (flow
->nw_proto
== IPPROTO_UDP
) {
2711 struct ovs_key_udp
*udp_key
;
2713 udp_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_UDP
,
2715 udp_key
->udp_src
= data
->tp_src
;
2716 udp_key
->udp_dst
= data
->tp_dst
;
2717 } else if (flow
->nw_proto
== IPPROTO_SCTP
) {
2718 struct ovs_key_sctp
*sctp_key
;
2720 sctp_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_SCTP
,
2722 sctp_key
->sctp_src
= data
->tp_src
;
2723 sctp_key
->sctp_dst
= data
->tp_dst
;
2724 } else if (flow
->dl_type
== htons(ETH_TYPE_IP
)
2725 && flow
->nw_proto
== IPPROTO_ICMP
) {
2726 struct ovs_key_icmp
*icmp_key
;
2728 icmp_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_ICMP
,
2730 icmp_key
->icmp_type
= ntohs(data
->tp_src
);
2731 icmp_key
->icmp_code
= ntohs(data
->tp_dst
);
2732 } else if (flow
->dl_type
== htons(ETH_TYPE_IPV6
)
2733 && flow
->nw_proto
== IPPROTO_ICMPV6
) {
2734 struct ovs_key_icmpv6
*icmpv6_key
;
2736 icmpv6_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_ICMPV6
,
2737 sizeof *icmpv6_key
);
2738 icmpv6_key
->icmpv6_type
= ntohs(data
->tp_src
);
2739 icmpv6_key
->icmpv6_code
= ntohs(data
->tp_dst
);
2741 if (flow
->tp_dst
== htons(0)
2742 && (flow
->tp_src
== htons(ND_NEIGHBOR_SOLICIT
)
2743 || flow
->tp_src
== htons(ND_NEIGHBOR_ADVERT
))
2744 && (!export_mask
|| (data
->tp_src
== htons(0xffff)
2745 && data
->tp_dst
== htons(0xffff)))) {
2747 struct ovs_key_nd
*nd_key
;
2749 nd_key
= nl_msg_put_unspec_uninit(buf
, OVS_KEY_ATTR_ND
,
2751 memcpy(nd_key
->nd_target
, &data
->nd_target
,
2752 sizeof nd_key
->nd_target
);
2753 memcpy(nd_key
->nd_sll
, data
->arp_sha
, ETH_ADDR_LEN
);
2754 memcpy(nd_key
->nd_tll
, data
->arp_tha
, ETH_ADDR_LEN
);
2761 nl_msg_end_nested(buf
, encap
);
2765 /* Appends a representation of 'flow' as OVS_KEY_ATTR_* attributes to 'buf'.
2766 * 'flow->in_port' is ignored (since it is likely to be an OpenFlow port
2767 * number rather than a datapath port number). Instead, if 'odp_in_port'
2768 * is anything other than ODPP_NONE, it is included in 'buf' as the input
2771 * 'buf' must have at least ODPUTIL_FLOW_KEY_BYTES bytes of space, or be
2772 * capable of being expanded to allow for that much space.
2774 * 'recirc' indicates support for recirculation fields. If this is true, then
2775 * these fields will always be serialised. */
2777 odp_flow_key_from_flow(struct ofpbuf
*buf
, const struct flow
*flow
,
2778 const struct flow
*mask
, odp_port_t odp_in_port
,
2781 odp_flow_key_from_flow__(buf
, flow
, mask
, odp_in_port
, SIZE_MAX
, recirc
,
2785 /* Appends a representation of 'mask' as OVS_KEY_ATTR_* attributes to
2786 * 'buf'. 'flow' is used as a template to determine how to interpret
2787 * 'mask'. For example, the 'dl_type' of 'mask' describes the mask, but
2788 * it doesn't indicate whether the other fields should be interpreted as
2789 * ARP, IPv4, IPv6, etc.
2791 * 'buf' must have at least ODPUTIL_FLOW_KEY_BYTES bytes of space, or be
2792 * capable of being expanded to allow for that much space.
2794 * 'recirc' indicates support for recirculation fields. If this is true, then
2795 * these fields will always be serialised. */
2797 odp_flow_key_from_mask(struct ofpbuf
*buf
, const struct flow
*mask
,
2798 const struct flow
*flow
, uint32_t odp_in_port_mask
,
2799 size_t max_mpls_depth
, bool recirc
)
2801 odp_flow_key_from_flow__(buf
, flow
, mask
, u32_to_odp(odp_in_port_mask
),
2802 max_mpls_depth
, recirc
, true);
2805 /* Generate ODP flow key from the given packet metadata */
2807 odp_key_from_pkt_metadata(struct ofpbuf
*buf
, const struct pkt_metadata
*md
)
2809 nl_msg_put_u32(buf
, OVS_KEY_ATTR_PRIORITY
, md
->skb_priority
);
2811 if (md
->tunnel
.ip_dst
) {
2812 tun_key_to_attr(buf
, &md
->tunnel
);
2815 nl_msg_put_u32(buf
, OVS_KEY_ATTR_SKB_MARK
, md
->pkt_mark
);
2817 /* Add an ingress port attribute if 'odp_in_port' is not the magical
2818 * value "ODPP_NONE". */
2819 if (md
->in_port
.odp_port
!= ODPP_NONE
) {
2820 nl_msg_put_odp_port(buf
, OVS_KEY_ATTR_IN_PORT
, md
->in_port
.odp_port
);
2824 /* Generate packet metadata from the given ODP flow key. */
2826 odp_key_to_pkt_metadata(const struct nlattr
*key
, size_t key_len
,
2827 struct pkt_metadata
*md
)
2829 const struct nlattr
*nla
;
2831 uint32_t wanted_attrs
= 1u << OVS_KEY_ATTR_PRIORITY
|
2832 1u << OVS_KEY_ATTR_SKB_MARK
| 1u << OVS_KEY_ATTR_TUNNEL
|
2833 1u << OVS_KEY_ATTR_IN_PORT
;
2835 *md
= PKT_METADATA_INITIALIZER(ODPP_NONE
);
2837 NL_ATTR_FOR_EACH (nla
, left
, key
, key_len
) {
2838 uint16_t type
= nl_attr_type(nla
);
2839 size_t len
= nl_attr_get_size(nla
);
2840 int expected_len
= odp_flow_key_attr_len(type
);
2842 if (len
!= expected_len
&& expected_len
>= 0) {
2847 case OVS_KEY_ATTR_RECIRC_ID
:
2848 md
->recirc_id
= nl_attr_get_u32(nla
);
2849 wanted_attrs
&= ~(1u << OVS_KEY_ATTR_RECIRC_ID
);
2851 case OVS_KEY_ATTR_DP_HASH
:
2852 md
->dp_hash
= nl_attr_get_u32(nla
);
2853 wanted_attrs
&= ~(1u << OVS_KEY_ATTR_DP_HASH
);
2855 case OVS_KEY_ATTR_PRIORITY
:
2856 md
->skb_priority
= nl_attr_get_u32(nla
);
2857 wanted_attrs
&= ~(1u << OVS_KEY_ATTR_PRIORITY
);
2859 case OVS_KEY_ATTR_SKB_MARK
:
2860 md
->pkt_mark
= nl_attr_get_u32(nla
);
2861 wanted_attrs
&= ~(1u << OVS_KEY_ATTR_SKB_MARK
);
2863 case OVS_KEY_ATTR_TUNNEL
: {
2864 enum odp_key_fitness res
;
2866 res
= odp_tun_key_from_attr(nla
, &md
->tunnel
);
2867 if (res
== ODP_FIT_ERROR
) {
2868 memset(&md
->tunnel
, 0, sizeof md
->tunnel
);
2869 } else if (res
== ODP_FIT_PERFECT
) {
2870 wanted_attrs
&= ~(1u << OVS_KEY_ATTR_TUNNEL
);
2874 case OVS_KEY_ATTR_IN_PORT
:
2875 md
->in_port
.odp_port
= nl_attr_get_odp_port(nla
);
2876 wanted_attrs
&= ~(1u << OVS_KEY_ATTR_IN_PORT
);
2882 if (!wanted_attrs
) {
2883 return; /* Have everything. */
2889 odp_flow_key_hash(const struct nlattr
*key
, size_t key_len
)
2891 BUILD_ASSERT_DECL(!(NLA_ALIGNTO
% sizeof(uint32_t)));
2892 return hash_words(ALIGNED_CAST(const uint32_t *, key
),
2893 key_len
/ sizeof(uint32_t), 0);
2897 log_odp_key_attributes(struct vlog_rate_limit
*rl
, const char *title
,
2898 uint64_t attrs
, int out_of_range_attr
,
2899 const struct nlattr
*key
, size_t key_len
)
2904 if (VLOG_DROP_DBG(rl
)) {
2909 for (i
= 0; i
< 64; i
++) {
2910 if (attrs
& (UINT64_C(1) << i
)) {
2911 char namebuf
[OVS_KEY_ATTR_BUFSIZE
];
2913 ds_put_format(&s
, " %s",
2914 ovs_key_attr_to_string(i
, namebuf
, sizeof namebuf
));
2917 if (out_of_range_attr
) {
2918 ds_put_format(&s
, " %d (and possibly others)", out_of_range_attr
);
2921 ds_put_cstr(&s
, ": ");
2922 odp_flow_key_format(key
, key_len
, &s
);
2924 VLOG_DBG("%s:%s", title
, ds_cstr(&s
));
2929 odp_to_ovs_frag(uint8_t odp_frag
, struct flow
*flow
)
2931 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
2933 if (odp_frag
> OVS_FRAG_TYPE_LATER
) {
2934 VLOG_ERR_RL(&rl
, "invalid frag %"PRIu8
" in flow key", odp_frag
);
2938 if (odp_frag
!= OVS_FRAG_TYPE_NONE
) {
2939 flow
->nw_frag
|= FLOW_NW_FRAG_ANY
;
2940 if (odp_frag
== OVS_FRAG_TYPE_LATER
) {
2941 flow
->nw_frag
|= FLOW_NW_FRAG_LATER
;
2948 parse_flow_nlattrs(const struct nlattr
*key
, size_t key_len
,
2949 const struct nlattr
*attrs
[], uint64_t *present_attrsp
,
2950 int *out_of_range_attrp
)
2952 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(10, 10);
2953 const struct nlattr
*nla
;
2954 uint64_t present_attrs
;
2957 BUILD_ASSERT(OVS_KEY_ATTR_MAX
< CHAR_BIT
* sizeof present_attrs
);
2959 *out_of_range_attrp
= 0;
2960 NL_ATTR_FOR_EACH (nla
, left
, key
, key_len
) {
2961 uint16_t type
= nl_attr_type(nla
);
2962 size_t len
= nl_attr_get_size(nla
);
2963 int expected_len
= odp_flow_key_attr_len(type
);
2965 if (len
!= expected_len
&& expected_len
>= 0) {
2966 char namebuf
[OVS_KEY_ATTR_BUFSIZE
];
2968 VLOG_ERR_RL(&rl
, "attribute %s has length %"PRIuSIZE
" but should have "
2969 "length %d", ovs_key_attr_to_string(type
, namebuf
,
2975 if (type
> OVS_KEY_ATTR_MAX
) {
2976 *out_of_range_attrp
= type
;
2978 if (present_attrs
& (UINT64_C(1) << type
)) {
2979 char namebuf
[OVS_KEY_ATTR_BUFSIZE
];
2981 VLOG_ERR_RL(&rl
, "duplicate %s attribute in flow key",
2982 ovs_key_attr_to_string(type
,
2983 namebuf
, sizeof namebuf
));
2987 present_attrs
|= UINT64_C(1) << type
;
2992 VLOG_ERR_RL(&rl
, "trailing garbage in flow key");
2996 *present_attrsp
= present_attrs
;
3000 static enum odp_key_fitness
3001 check_expectations(uint64_t present_attrs
, int out_of_range_attr
,
3002 uint64_t expected_attrs
,
3003 const struct nlattr
*key
, size_t key_len
)
3005 uint64_t missing_attrs
;
3006 uint64_t extra_attrs
;
3008 missing_attrs
= expected_attrs
& ~present_attrs
;
3009 if (missing_attrs
) {
3010 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(10, 10);
3011 log_odp_key_attributes(&rl
, "expected but not present",
3012 missing_attrs
, 0, key
, key_len
);
3013 return ODP_FIT_TOO_LITTLE
;
3016 extra_attrs
= present_attrs
& ~expected_attrs
;
3017 if (extra_attrs
|| out_of_range_attr
) {
3018 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(10, 10);
3019 log_odp_key_attributes(&rl
, "present but not expected",
3020 extra_attrs
, out_of_range_attr
, key
, key_len
);
3021 return ODP_FIT_TOO_MUCH
;
3024 return ODP_FIT_PERFECT
;
3028 parse_ethertype(const struct nlattr
*attrs
[OVS_KEY_ATTR_MAX
+ 1],
3029 uint64_t present_attrs
, uint64_t *expected_attrs
,
3030 struct flow
*flow
, const struct flow
*src_flow
)
3032 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
3033 bool is_mask
= flow
!= src_flow
;
3035 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ETHERTYPE
)) {
3036 flow
->dl_type
= nl_attr_get_be16(attrs
[OVS_KEY_ATTR_ETHERTYPE
]);
3037 if (!is_mask
&& ntohs(flow
->dl_type
) < ETH_TYPE_MIN
) {
3038 VLOG_ERR_RL(&rl
, "invalid Ethertype %"PRIu16
" in flow key",
3039 ntohs(flow
->dl_type
));
3042 if (is_mask
&& ntohs(src_flow
->dl_type
) < ETH_TYPE_MIN
&&
3043 flow
->dl_type
!= htons(0xffff)) {
3046 *expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ETHERTYPE
;
3049 flow
->dl_type
= htons(FLOW_DL_TYPE_NONE
);
3050 } else if (ntohs(src_flow
->dl_type
) < ETH_TYPE_MIN
) {
3051 /* See comments in odp_flow_key_from_flow__(). */
3052 VLOG_ERR_RL(&rl
, "mask expected for non-Ethernet II frame");
3059 static enum odp_key_fitness
3060 parse_l2_5_onward(const struct nlattr
*attrs
[OVS_KEY_ATTR_MAX
+ 1],
3061 uint64_t present_attrs
, int out_of_range_attr
,
3062 uint64_t expected_attrs
, struct flow
*flow
,
3063 const struct nlattr
*key
, size_t key_len
,
3064 const struct flow
*src_flow
)
3066 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
3067 bool is_mask
= src_flow
!= flow
;
3068 const void *check_start
= NULL
;
3069 size_t check_len
= 0;
3070 enum ovs_key_attr expected_bit
= 0xff;
3072 if (eth_type_mpls(src_flow
->dl_type
)) {
3073 size_t size
= nl_attr_get_size(attrs
[OVS_KEY_ATTR_MPLS
]);
3074 const ovs_be32
*mpls_lse
= nl_attr_get(attrs
[OVS_KEY_ATTR_MPLS
]);
3075 int n
= size
/ sizeof(ovs_be32
);
3078 if (!size
|| size
% sizeof(ovs_be32
)) {
3079 return ODP_FIT_ERROR
;
3083 expected_attrs
|= (UINT64_C(1) << OVS_KEY_ATTR_MPLS
);
3085 if (!(present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_MPLS
))) {
3086 return ODP_FIT_TOO_LITTLE
;
3088 } else if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_MPLS
)) {
3089 if (flow
->mpls_lse
[0] && flow
->dl_type
!= htons(0xffff)) {
3090 return ODP_FIT_ERROR
;
3092 expected_attrs
|= (UINT64_C(1) << OVS_KEY_ATTR_MPLS
);
3095 for (i
= 0; i
< n
&& i
< FLOW_MAX_MPLS_LABELS
; i
++) {
3096 flow
->mpls_lse
[i
] = mpls_lse
[i
];
3098 if (n
> FLOW_MAX_MPLS_LABELS
) {
3099 return ODP_FIT_TOO_MUCH
;
3103 /* BOS may be set only in the innermost label. */
3104 for (i
= 0; i
< n
- 1; i
++) {
3105 if (flow
->mpls_lse
[i
] & htonl(MPLS_BOS_MASK
)) {
3106 return ODP_FIT_ERROR
;
3110 /* BOS must be set in the innermost label. */
3111 if (n
< FLOW_MAX_MPLS_LABELS
3112 && !(flow
->mpls_lse
[n
- 1] & htonl(MPLS_BOS_MASK
))) {
3113 return ODP_FIT_TOO_LITTLE
;
3118 } else if (src_flow
->dl_type
== htons(ETH_TYPE_IP
)) {
3120 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_IPV4
;
3122 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_IPV4
)) {
3123 const struct ovs_key_ipv4
*ipv4_key
;
3125 ipv4_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_IPV4
]);
3126 flow
->nw_src
= ipv4_key
->ipv4_src
;
3127 flow
->nw_dst
= ipv4_key
->ipv4_dst
;
3128 flow
->nw_proto
= ipv4_key
->ipv4_proto
;
3129 flow
->nw_tos
= ipv4_key
->ipv4_tos
;
3130 flow
->nw_ttl
= ipv4_key
->ipv4_ttl
;
3132 flow
->nw_frag
= ipv4_key
->ipv4_frag
;
3133 check_start
= ipv4_key
;
3134 check_len
= sizeof *ipv4_key
;
3135 expected_bit
= OVS_KEY_ATTR_IPV4
;
3136 } else if (!odp_to_ovs_frag(ipv4_key
->ipv4_frag
, flow
)) {
3137 return ODP_FIT_ERROR
;
3140 } else if (src_flow
->dl_type
== htons(ETH_TYPE_IPV6
)) {
3142 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_IPV6
;
3144 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_IPV6
)) {
3145 const struct ovs_key_ipv6
*ipv6_key
;
3147 ipv6_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_IPV6
]);
3148 memcpy(&flow
->ipv6_src
, ipv6_key
->ipv6_src
, sizeof flow
->ipv6_src
);
3149 memcpy(&flow
->ipv6_dst
, ipv6_key
->ipv6_dst
, sizeof flow
->ipv6_dst
);
3150 flow
->ipv6_label
= ipv6_key
->ipv6_label
;
3151 flow
->nw_proto
= ipv6_key
->ipv6_proto
;
3152 flow
->nw_tos
= ipv6_key
->ipv6_tclass
;
3153 flow
->nw_ttl
= ipv6_key
->ipv6_hlimit
;
3155 flow
->nw_frag
= ipv6_key
->ipv6_frag
;
3156 check_start
= ipv6_key
;
3157 check_len
= sizeof *ipv6_key
;
3158 expected_bit
= OVS_KEY_ATTR_IPV6
;
3159 } else if (!odp_to_ovs_frag(ipv6_key
->ipv6_frag
, flow
)) {
3160 return ODP_FIT_ERROR
;
3163 } else if (src_flow
->dl_type
== htons(ETH_TYPE_ARP
) ||
3164 src_flow
->dl_type
== htons(ETH_TYPE_RARP
)) {
3166 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ARP
;
3168 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ARP
)) {
3169 const struct ovs_key_arp
*arp_key
;
3171 arp_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_ARP
]);
3172 flow
->nw_src
= arp_key
->arp_sip
;
3173 flow
->nw_dst
= arp_key
->arp_tip
;
3174 if (!is_mask
&& (arp_key
->arp_op
& htons(0xff00))) {
3175 VLOG_ERR_RL(&rl
, "unsupported ARP opcode %"PRIu16
" in flow "
3176 "key", ntohs(arp_key
->arp_op
));
3177 return ODP_FIT_ERROR
;
3179 flow
->nw_proto
= ntohs(arp_key
->arp_op
);
3180 memcpy(flow
->arp_sha
, arp_key
->arp_sha
, ETH_ADDR_LEN
);
3181 memcpy(flow
->arp_tha
, arp_key
->arp_tha
, ETH_ADDR_LEN
);
3184 check_start
= arp_key
;
3185 check_len
= sizeof *arp_key
;
3186 expected_bit
= OVS_KEY_ATTR_ARP
;
3192 if (check_len
> 0) { /* Happens only when 'is_mask'. */
3193 if (!is_all_zeros(check_start
, check_len
) &&
3194 flow
->dl_type
!= htons(0xffff)) {
3195 return ODP_FIT_ERROR
;
3197 expected_attrs
|= UINT64_C(1) << expected_bit
;
3201 expected_bit
= OVS_KEY_ATTR_UNSPEC
;
3202 if (src_flow
->nw_proto
== IPPROTO_TCP
3203 && (src_flow
->dl_type
== htons(ETH_TYPE_IP
) ||
3204 src_flow
->dl_type
== htons(ETH_TYPE_IPV6
))
3205 && !(src_flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
3207 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_TCP
;
3209 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_TCP
)) {
3210 const struct ovs_key_tcp
*tcp_key
;
3212 tcp_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_TCP
]);
3213 flow
->tp_src
= tcp_key
->tcp_src
;
3214 flow
->tp_dst
= tcp_key
->tcp_dst
;
3215 expected_bit
= OVS_KEY_ATTR_TCP
;
3217 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_TCP_FLAGS
)) {
3218 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_TCP_FLAGS
;
3219 flow
->tcp_flags
= nl_attr_get_be16(attrs
[OVS_KEY_ATTR_TCP_FLAGS
]);
3221 } else if (src_flow
->nw_proto
== IPPROTO_UDP
3222 && (src_flow
->dl_type
== htons(ETH_TYPE_IP
) ||
3223 src_flow
->dl_type
== htons(ETH_TYPE_IPV6
))
3224 && !(src_flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
3226 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_UDP
;
3228 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_UDP
)) {
3229 const struct ovs_key_udp
*udp_key
;
3231 udp_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_UDP
]);
3232 flow
->tp_src
= udp_key
->udp_src
;
3233 flow
->tp_dst
= udp_key
->udp_dst
;
3234 expected_bit
= OVS_KEY_ATTR_UDP
;
3236 } else if (src_flow
->nw_proto
== IPPROTO_SCTP
3237 && (src_flow
->dl_type
== htons(ETH_TYPE_IP
) ||
3238 src_flow
->dl_type
== htons(ETH_TYPE_IPV6
))
3239 && !(src_flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
3241 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_SCTP
;
3243 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_SCTP
)) {
3244 const struct ovs_key_sctp
*sctp_key
;
3246 sctp_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_SCTP
]);
3247 flow
->tp_src
= sctp_key
->sctp_src
;
3248 flow
->tp_dst
= sctp_key
->sctp_dst
;
3249 expected_bit
= OVS_KEY_ATTR_SCTP
;
3251 } else if (src_flow
->nw_proto
== IPPROTO_ICMP
3252 && src_flow
->dl_type
== htons(ETH_TYPE_IP
)
3253 && !(src_flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
3255 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ICMP
;
3257 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ICMP
)) {
3258 const struct ovs_key_icmp
*icmp_key
;
3260 icmp_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_ICMP
]);
3261 flow
->tp_src
= htons(icmp_key
->icmp_type
);
3262 flow
->tp_dst
= htons(icmp_key
->icmp_code
);
3263 expected_bit
= OVS_KEY_ATTR_ICMP
;
3265 } else if (src_flow
->nw_proto
== IPPROTO_ICMPV6
3266 && src_flow
->dl_type
== htons(ETH_TYPE_IPV6
)
3267 && !(src_flow
->nw_frag
& FLOW_NW_FRAG_LATER
)) {
3269 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ICMPV6
;
3271 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ICMPV6
)) {
3272 const struct ovs_key_icmpv6
*icmpv6_key
;
3274 icmpv6_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_ICMPV6
]);
3275 flow
->tp_src
= htons(icmpv6_key
->icmpv6_type
);
3276 flow
->tp_dst
= htons(icmpv6_key
->icmpv6_code
);
3277 expected_bit
= OVS_KEY_ATTR_ICMPV6
;
3278 if (src_flow
->tp_dst
== htons(0) &&
3279 (src_flow
->tp_src
== htons(ND_NEIGHBOR_SOLICIT
) ||
3280 src_flow
->tp_src
== htons(ND_NEIGHBOR_ADVERT
))) {
3282 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ND
;
3284 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ND
)) {
3285 const struct ovs_key_nd
*nd_key
;
3287 nd_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_ND
]);
3288 memcpy(&flow
->nd_target
, nd_key
->nd_target
,
3289 sizeof flow
->nd_target
);
3290 memcpy(flow
->arp_sha
, nd_key
->nd_sll
, ETH_ADDR_LEN
);
3291 memcpy(flow
->arp_tha
, nd_key
->nd_tll
, ETH_ADDR_LEN
);
3293 if (!is_all_zeros((const uint8_t *) nd_key
,
3295 (flow
->tp_src
!= htons(0xffff) ||
3296 flow
->tp_dst
!= htons(0xffff))) {
3297 return ODP_FIT_ERROR
;
3299 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ND
;
3306 if (is_mask
&& expected_bit
!= OVS_KEY_ATTR_UNSPEC
) {
3307 if ((flow
->tp_src
|| flow
->tp_dst
) && flow
->nw_proto
!= 0xff) {
3308 return ODP_FIT_ERROR
;
3310 expected_attrs
|= UINT64_C(1) << expected_bit
;
3315 return check_expectations(present_attrs
, out_of_range_attr
, expected_attrs
,
3319 /* Parse 802.1Q header then encapsulated L3 attributes. */
3320 static enum odp_key_fitness
3321 parse_8021q_onward(const struct nlattr
*attrs
[OVS_KEY_ATTR_MAX
+ 1],
3322 uint64_t present_attrs
, int out_of_range_attr
,
3323 uint64_t expected_attrs
, struct flow
*flow
,
3324 const struct nlattr
*key
, size_t key_len
,
3325 const struct flow
*src_flow
)
3327 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
3328 bool is_mask
= src_flow
!= flow
;
3330 const struct nlattr
*encap
3331 = (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ENCAP
)
3332 ? attrs
[OVS_KEY_ATTR_ENCAP
] : NULL
);
3333 enum odp_key_fitness encap_fitness
;
3334 enum odp_key_fitness fitness
;
3336 /* Calculate fitness of outer attributes. */
3338 expected_attrs
|= ((UINT64_C(1) << OVS_KEY_ATTR_VLAN
) |
3339 (UINT64_C(1) << OVS_KEY_ATTR_ENCAP
));
3341 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_VLAN
)) {
3342 expected_attrs
|= (UINT64_C(1) << OVS_KEY_ATTR_VLAN
);
3344 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ENCAP
)) {
3345 expected_attrs
|= (UINT64_C(1) << OVS_KEY_ATTR_ENCAP
);
3348 fitness
= check_expectations(present_attrs
, out_of_range_attr
,
3349 expected_attrs
, key
, key_len
);
3352 * Remove the TPID from dl_type since it's not the real Ethertype. */
3353 flow
->dl_type
= htons(0);
3354 flow
->vlan_tci
= (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_VLAN
)
3355 ? nl_attr_get_be16(attrs
[OVS_KEY_ATTR_VLAN
])
3358 if (!(present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_VLAN
))) {
3359 return ODP_FIT_TOO_LITTLE
;
3360 } else if (flow
->vlan_tci
== htons(0)) {
3361 /* Corner case for a truncated 802.1Q header. */
3362 if (fitness
== ODP_FIT_PERFECT
&& nl_attr_get_size(encap
)) {
3363 return ODP_FIT_TOO_MUCH
;
3366 } else if (!(flow
->vlan_tci
& htons(VLAN_CFI
))) {
3367 VLOG_ERR_RL(&rl
, "OVS_KEY_ATTR_VLAN 0x%04"PRIx16
" is nonzero "
3368 "but CFI bit is not set", ntohs(flow
->vlan_tci
));
3369 return ODP_FIT_ERROR
;
3372 if (!(present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ENCAP
))) {
3377 /* Now parse the encapsulated attributes. */
3378 if (!parse_flow_nlattrs(nl_attr_get(encap
), nl_attr_get_size(encap
),
3379 attrs
, &present_attrs
, &out_of_range_attr
)) {
3380 return ODP_FIT_ERROR
;
3384 if (!parse_ethertype(attrs
, present_attrs
, &expected_attrs
, flow
, src_flow
)) {
3385 return ODP_FIT_ERROR
;
3387 encap_fitness
= parse_l2_5_onward(attrs
, present_attrs
, out_of_range_attr
,
3388 expected_attrs
, flow
, key
, key_len
,
3391 /* The overall fitness is the worse of the outer and inner attributes. */
3392 return MAX(fitness
, encap_fitness
);
3395 static enum odp_key_fitness
3396 odp_flow_key_to_flow__(const struct nlattr
*key
, size_t key_len
,
3397 struct flow
*flow
, const struct flow
*src_flow
)
3399 const struct nlattr
*attrs
[OVS_KEY_ATTR_MAX
+ 1];
3400 uint64_t expected_attrs
;
3401 uint64_t present_attrs
;
3402 int out_of_range_attr
;
3403 bool is_mask
= src_flow
!= flow
;
3405 memset(flow
, 0, sizeof *flow
);
3407 /* Parse attributes. */
3408 if (!parse_flow_nlattrs(key
, key_len
, attrs
, &present_attrs
,
3409 &out_of_range_attr
)) {
3410 return ODP_FIT_ERROR
;
3415 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_RECIRC_ID
)) {
3416 flow
->recirc_id
= nl_attr_get_u32(attrs
[OVS_KEY_ATTR_RECIRC_ID
]);
3417 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_RECIRC_ID
;
3418 } else if (is_mask
) {
3419 /* Always exact match recirc_id if it is not specified. */
3420 flow
->recirc_id
= UINT32_MAX
;
3423 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_DP_HASH
)) {
3424 flow
->dp_hash
= nl_attr_get_u32(attrs
[OVS_KEY_ATTR_DP_HASH
]);
3425 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_DP_HASH
;
3427 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_PRIORITY
)) {
3428 flow
->skb_priority
= nl_attr_get_u32(attrs
[OVS_KEY_ATTR_PRIORITY
]);
3429 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_PRIORITY
;
3432 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_SKB_MARK
)) {
3433 flow
->pkt_mark
= nl_attr_get_u32(attrs
[OVS_KEY_ATTR_SKB_MARK
]);
3434 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_SKB_MARK
;
3437 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_TUNNEL
)) {
3438 enum odp_key_fitness res
;
3440 res
= odp_tun_key_from_attr(attrs
[OVS_KEY_ATTR_TUNNEL
], &flow
->tunnel
);
3441 if (res
== ODP_FIT_ERROR
) {
3442 return ODP_FIT_ERROR
;
3443 } else if (res
== ODP_FIT_PERFECT
) {
3444 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_TUNNEL
;
3448 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_IN_PORT
)) {
3449 flow
->in_port
.odp_port
3450 = nl_attr_get_odp_port(attrs
[OVS_KEY_ATTR_IN_PORT
]);
3451 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_IN_PORT
;
3452 } else if (!is_mask
) {
3453 flow
->in_port
.odp_port
= ODPP_NONE
;
3456 /* Ethernet header. */
3457 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_ETHERNET
)) {
3458 const struct ovs_key_ethernet
*eth_key
;
3460 eth_key
= nl_attr_get(attrs
[OVS_KEY_ATTR_ETHERNET
]);
3461 memcpy(flow
->dl_src
, eth_key
->eth_src
, ETH_ADDR_LEN
);
3462 memcpy(flow
->dl_dst
, eth_key
->eth_dst
, ETH_ADDR_LEN
);
3464 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ETHERNET
;
3468 expected_attrs
|= UINT64_C(1) << OVS_KEY_ATTR_ETHERNET
;
3471 /* Get Ethertype or 802.1Q TPID or FLOW_DL_TYPE_NONE. */
3472 if (!parse_ethertype(attrs
, present_attrs
, &expected_attrs
, flow
,
3474 return ODP_FIT_ERROR
;
3478 ? (src_flow
->vlan_tci
& htons(VLAN_CFI
)) != 0
3479 : src_flow
->dl_type
== htons(ETH_TYPE_VLAN
)) {
3480 return parse_8021q_onward(attrs
, present_attrs
, out_of_range_attr
,
3481 expected_attrs
, flow
, key
, key_len
, src_flow
);
3484 flow
->vlan_tci
= htons(0xffff);
3485 if (present_attrs
& (UINT64_C(1) << OVS_KEY_ATTR_VLAN
)) {
3486 flow
->vlan_tci
= nl_attr_get_be16(attrs
[OVS_KEY_ATTR_VLAN
]);
3487 expected_attrs
|= (UINT64_C(1) << OVS_KEY_ATTR_VLAN
);
3490 return parse_l2_5_onward(attrs
, present_attrs
, out_of_range_attr
,
3491 expected_attrs
, flow
, key
, key_len
, src_flow
);
3494 /* Converts the 'key_len' bytes of OVS_KEY_ATTR_* attributes in 'key' to a flow
3495 * structure in 'flow'. Returns an ODP_FIT_* value that indicates how well
3496 * 'key' fits our expectations for what a flow key should contain.
3498 * The 'in_port' will be the datapath's understanding of the port. The
3499 * caller will need to translate with odp_port_to_ofp_port() if the
3500 * OpenFlow port is needed.
3502 * This function doesn't take the packet itself as an argument because none of
3503 * the currently understood OVS_KEY_ATTR_* attributes require it. Currently,
3504 * it is always possible to infer which additional attribute(s) should appear
3505 * by looking at the attributes for lower-level protocols, e.g. if the network
3506 * protocol in OVS_KEY_ATTR_IPV4 or OVS_KEY_ATTR_IPV6 is IPPROTO_TCP then we
3507 * know that a OVS_KEY_ATTR_TCP attribute must appear and that otherwise it
3508 * must be absent. */
3509 enum odp_key_fitness
3510 odp_flow_key_to_flow(const struct nlattr
*key
, size_t key_len
,
3513 return odp_flow_key_to_flow__(key
, key_len
, flow
, flow
);
3516 /* Converts the 'key_len' bytes of OVS_KEY_ATTR_* attributes in 'key' to a mask
3517 * structure in 'mask'. 'flow' must be a previously translated flow
3518 * corresponding to 'mask'. Returns an ODP_FIT_* value that indicates how well
3519 * 'key' fits our expectations for what a flow key should contain. */
3520 enum odp_key_fitness
3521 odp_flow_key_to_mask(const struct nlattr
*key
, size_t key_len
,
3522 struct flow
*mask
, const struct flow
*flow
)
3524 return odp_flow_key_to_flow__(key
, key_len
, mask
, flow
);
3527 /* Returns 'fitness' as a string, for use in debug messages. */
3529 odp_key_fitness_to_string(enum odp_key_fitness fitness
)
3532 case ODP_FIT_PERFECT
:
3534 case ODP_FIT_TOO_MUCH
:
3536 case ODP_FIT_TOO_LITTLE
:
3537 return "too_little";
3545 /* Appends an OVS_ACTION_ATTR_USERSPACE action to 'odp_actions' that specifies
3546 * Netlink PID 'pid'. If 'userdata' is nonnull, adds a userdata attribute
3547 * whose contents are the 'userdata_size' bytes at 'userdata' and returns the
3548 * offset within 'odp_actions' of the start of the cookie. (If 'userdata' is
3549 * null, then the return value is not meaningful.) */
3551 odp_put_userspace_action(uint32_t pid
,
3552 const void *userdata
, size_t userdata_size
,
3553 odp_port_t tunnel_out_port
,
3554 struct ofpbuf
*odp_actions
)
3556 size_t userdata_ofs
;
3559 offset
= nl_msg_start_nested(odp_actions
, OVS_ACTION_ATTR_USERSPACE
);
3560 nl_msg_put_u32(odp_actions
, OVS_USERSPACE_ATTR_PID
, pid
);
3562 userdata_ofs
= ofpbuf_size(odp_actions
) + NLA_HDRLEN
;
3564 /* The OVS kernel module before OVS 1.11 and the upstream Linux kernel
3565 * module before Linux 3.10 required the userdata to be exactly 8 bytes
3568 * - The kernel rejected shorter userdata with -ERANGE.
3570 * - The kernel silently dropped userdata beyond the first 8 bytes.
3572 * Thus, for maximum compatibility, always put at least 8 bytes. (We
3573 * separately disable features that required more than 8 bytes.) */
3574 memcpy(nl_msg_put_unspec_zero(odp_actions
, OVS_USERSPACE_ATTR_USERDATA
,
3575 MAX(8, userdata_size
)),
3576 userdata
, userdata_size
);
3580 if (tunnel_out_port
!= ODPP_NONE
) {
3581 nl_msg_put_odp_port(odp_actions
, OVS_USERSPACE_ATTR_EGRESS_TUN_PORT
,
3584 nl_msg_end_nested(odp_actions
, offset
);
3586 return userdata_ofs
;
3590 odp_put_tunnel_action(const struct flow_tnl
*tunnel
,
3591 struct ofpbuf
*odp_actions
)
3593 size_t offset
= nl_msg_start_nested(odp_actions
, OVS_ACTION_ATTR_SET
);
3594 tun_key_to_attr(odp_actions
, tunnel
);
3595 nl_msg_end_nested(odp_actions
, offset
);
3598 /* The commit_odp_actions() function and its helpers. */
3601 commit_set_action(struct ofpbuf
*odp_actions
, enum ovs_key_attr key_type
,
3602 const void *key
, size_t key_size
)
3604 size_t offset
= nl_msg_start_nested(odp_actions
, OVS_ACTION_ATTR_SET
);
3605 nl_msg_put_unspec(odp_actions
, key_type
, key
, key_size
);
3606 nl_msg_end_nested(odp_actions
, offset
);
3610 odp_put_pkt_mark_action(const uint32_t pkt_mark
,
3611 struct ofpbuf
*odp_actions
)
3613 commit_set_action(odp_actions
, OVS_KEY_ATTR_SKB_MARK
, &pkt_mark
,
3617 /* If any of the flow key data that ODP actions can modify are different in
3618 * 'base->tunnel' and 'flow->tunnel', appends a set_tunnel ODP action to
3619 * 'odp_actions' that change the flow tunneling information in key from
3620 * 'base->tunnel' into 'flow->tunnel', and then changes 'base->tunnel' in the
3621 * same way. In other words, operates the same as commit_odp_actions(), but
3622 * only on tunneling information. */
3624 commit_odp_tunnel_action(const struct flow
*flow
, struct flow
*base
,
3625 struct ofpbuf
*odp_actions
)
3627 /* A valid IPV4_TUNNEL must have non-zero ip_dst. */
3628 if (flow
->tunnel
.ip_dst
) {
3629 if (!memcmp(&base
->tunnel
, &flow
->tunnel
, sizeof base
->tunnel
)) {
3632 memcpy(&base
->tunnel
, &flow
->tunnel
, sizeof base
->tunnel
);
3633 odp_put_tunnel_action(&base
->tunnel
, odp_actions
);
3638 commit_set_ether_addr_action(const struct flow
*flow
, struct flow
*base
,
3639 struct ofpbuf
*odp_actions
,
3640 struct flow_wildcards
*wc
)
3642 struct ovs_key_ethernet eth_key
;
3644 if (eth_addr_equals(base
->dl_src
, flow
->dl_src
) &&
3645 eth_addr_equals(base
->dl_dst
, flow
->dl_dst
)) {
3649 memset(&wc
->masks
.dl_src
, 0xff, sizeof wc
->masks
.dl_src
);
3650 memset(&wc
->masks
.dl_dst
, 0xff, sizeof wc
->masks
.dl_dst
);
3652 memcpy(base
->dl_src
, flow
->dl_src
, ETH_ADDR_LEN
);
3653 memcpy(base
->dl_dst
, flow
->dl_dst
, ETH_ADDR_LEN
);
3655 memcpy(eth_key
.eth_src
, base
->dl_src
, ETH_ADDR_LEN
);
3656 memcpy(eth_key
.eth_dst
, base
->dl_dst
, ETH_ADDR_LEN
);
3658 commit_set_action(odp_actions
, OVS_KEY_ATTR_ETHERNET
,
3659 ð_key
, sizeof(eth_key
));
3663 pop_vlan(struct flow
*base
,
3664 struct ofpbuf
*odp_actions
, struct flow_wildcards
*wc
)
3666 memset(&wc
->masks
.vlan_tci
, 0xff, sizeof wc
->masks
.vlan_tci
);
3668 if (base
->vlan_tci
& htons(VLAN_CFI
)) {
3669 nl_msg_put_flag(odp_actions
, OVS_ACTION_ATTR_POP_VLAN
);
3675 commit_vlan_action(ovs_be16 vlan_tci
, struct flow
*base
,
3676 struct ofpbuf
*odp_actions
, struct flow_wildcards
*wc
)
3678 if (base
->vlan_tci
== vlan_tci
) {
3682 pop_vlan(base
, odp_actions
, wc
);
3683 if (vlan_tci
& htons(VLAN_CFI
)) {
3684 struct ovs_action_push_vlan vlan
;
3686 vlan
.vlan_tpid
= htons(ETH_TYPE_VLAN
);
3687 vlan
.vlan_tci
= vlan_tci
;
3688 nl_msg_put_unspec(odp_actions
, OVS_ACTION_ATTR_PUSH_VLAN
,
3689 &vlan
, sizeof vlan
);
3691 base
->vlan_tci
= vlan_tci
;
3695 commit_mpls_action(const struct flow
*flow
, struct flow
*base
,
3696 struct ofpbuf
*odp_actions
, struct flow_wildcards
*wc
)
3698 int base_n
= flow_count_mpls_labels(base
, wc
);
3699 int flow_n
= flow_count_mpls_labels(flow
, wc
);
3700 int common_n
= flow_count_common_mpls_labels(flow
, flow_n
, base
, base_n
,
3703 while (base_n
> common_n
) {
3704 if (base_n
- 1 == common_n
&& flow_n
> common_n
) {
3705 /* If there is only one more LSE in base than there are common
3706 * between base and flow; and flow has at least one more LSE than
3707 * is common then the topmost LSE of base may be updated using
3709 struct ovs_key_mpls mpls_key
;
3711 mpls_key
.mpls_lse
= flow
->mpls_lse
[flow_n
- base_n
];
3712 commit_set_action(odp_actions
, OVS_KEY_ATTR_MPLS
,
3713 &mpls_key
, sizeof mpls_key
);
3714 flow_set_mpls_lse(base
, 0, mpls_key
.mpls_lse
);
3717 /* Otherwise, if there more LSEs in base than are common between
3718 * base and flow then pop the topmost one. */
3722 /* If all the LSEs are to be popped and this is not the outermost
3723 * LSE then use ETH_TYPE_MPLS as the ethertype parameter of the
3724 * POP_MPLS action instead of flow->dl_type.
3726 * This is because the POP_MPLS action requires its ethertype
3727 * argument to be an MPLS ethernet type but in this case
3728 * flow->dl_type will be a non-MPLS ethernet type.
3730 * When the final POP_MPLS action occurs it use flow->dl_type and
3731 * the and the resulting packet will have the desired dl_type. */
3732 if ((!eth_type_mpls(flow
->dl_type
)) && base_n
> 1) {
3733 dl_type
= htons(ETH_TYPE_MPLS
);
3735 dl_type
= flow
->dl_type
;
3737 nl_msg_put_be16(odp_actions
, OVS_ACTION_ATTR_POP_MPLS
, dl_type
);
3738 popped
= flow_pop_mpls(base
, base_n
, flow
->dl_type
, wc
);
3744 /* If, after the above popping and setting, there are more LSEs in flow
3745 * than base then some LSEs need to be pushed. */
3746 while (base_n
< flow_n
) {
3747 struct ovs_action_push_mpls
*mpls
;
3749 mpls
= nl_msg_put_unspec_zero(odp_actions
,
3750 OVS_ACTION_ATTR_PUSH_MPLS
,
3752 mpls
->mpls_ethertype
= flow
->dl_type
;
3753 mpls
->mpls_lse
= flow
->mpls_lse
[flow_n
- base_n
- 1];
3754 flow_push_mpls(base
, base_n
, mpls
->mpls_ethertype
, wc
);
3755 flow_set_mpls_lse(base
, 0, mpls
->mpls_lse
);
3761 commit_set_ipv4_action(const struct flow
*flow
, struct flow
*base
,
3762 struct ofpbuf
*odp_actions
, struct flow_wildcards
*wc
)
3764 struct ovs_key_ipv4 ipv4_key
;
3766 if (base
->nw_src
== flow
->nw_src
&&
3767 base
->nw_dst
== flow
->nw_dst
&&
3768 base
->nw_tos
== flow
->nw_tos
&&
3769 base
->nw_ttl
== flow
->nw_ttl
&&
3770 base
->nw_frag
== flow
->nw_frag
) {
3774 memset(&wc
->masks
.nw_src
, 0xff, sizeof wc
->masks
.nw_src
);
3775 memset(&wc
->masks
.nw_dst
, 0xff, sizeof wc
->masks
.nw_dst
);
3776 memset(&wc
->masks
.nw_tos
, 0xff, sizeof wc
->masks
.nw_tos
);
3777 memset(&wc
->masks
.nw_ttl
, 0xff, sizeof wc
->masks
.nw_ttl
);
3778 memset(&wc
->masks
.nw_proto
, 0xff, sizeof wc
->masks
.nw_proto
);
3779 memset(&wc
->masks
.nw_frag
, 0xff, sizeof wc
->masks
.nw_frag
);
3781 ipv4_key
.ipv4_src
= base
->nw_src
= flow
->nw_src
;
3782 ipv4_key
.ipv4_dst
= base
->nw_dst
= flow
->nw_dst
;
3783 ipv4_key
.ipv4_tos
= base
->nw_tos
= flow
->nw_tos
;
3784 ipv4_key
.ipv4_ttl
= base
->nw_ttl
= flow
->nw_ttl
;
3785 ipv4_key
.ipv4_proto
= base
->nw_proto
;
3786 ipv4_key
.ipv4_frag
= ovs_to_odp_frag(base
->nw_frag
);
3788 commit_set_action(odp_actions
, OVS_KEY_ATTR_IPV4
,
3789 &ipv4_key
, sizeof(ipv4_key
));
3793 commit_set_ipv6_action(const struct flow
*flow
, struct flow
*base
,
3794 struct ofpbuf
*odp_actions
, struct flow_wildcards
*wc
)
3796 struct ovs_key_ipv6 ipv6_key
;
3798 if (ipv6_addr_equals(&base
->ipv6_src
, &flow
->ipv6_src
) &&
3799 ipv6_addr_equals(&base
->ipv6_dst
, &flow
->ipv6_dst
) &&
3800 base
->ipv6_label
== flow
->ipv6_label
&&
3801 base
->nw_tos
== flow
->nw_tos
&&
3802 base
->nw_ttl
== flow
->nw_ttl
&&
3803 base
->nw_frag
== flow
->nw_frag
) {
3807 memset(&wc
->masks
.ipv6_src
, 0xff, sizeof wc
->masks
.ipv6_src
);
3808 memset(&wc
->masks
.ipv6_dst
, 0xff, sizeof wc
->masks
.ipv6_dst
);
3809 memset(&wc
->masks
.ipv6_label
, 0xff, sizeof wc
->masks
.ipv6_label
);
3810 memset(&wc
->masks
.nw_tos
, 0xff, sizeof wc
->masks
.nw_tos
);
3811 memset(&wc
->masks
.nw_ttl
, 0xff, sizeof wc
->masks
.nw_ttl
);
3812 memset(&wc
->masks
.nw_proto
, 0xff, sizeof wc
->masks
.nw_proto
);
3813 memset(&wc
->masks
.nw_frag
, 0xff, sizeof wc
->masks
.nw_frag
);
3815 base
->ipv6_src
= flow
->ipv6_src
;
3816 memcpy(&ipv6_key
.ipv6_src
, &base
->ipv6_src
, sizeof(ipv6_key
.ipv6_src
));
3817 base
->ipv6_dst
= flow
->ipv6_dst
;
3818 memcpy(&ipv6_key
.ipv6_dst
, &base
->ipv6_dst
, sizeof(ipv6_key
.ipv6_dst
));
3820 ipv6_key
.ipv6_label
= base
->ipv6_label
= flow
->ipv6_label
;
3821 ipv6_key
.ipv6_tclass
= base
->nw_tos
= flow
->nw_tos
;
3822 ipv6_key
.ipv6_hlimit
= base
->nw_ttl
= flow
->nw_ttl
;
3823 ipv6_key
.ipv6_proto
= base
->nw_proto
;
3824 ipv6_key
.ipv6_frag
= ovs_to_odp_frag(base
->nw_frag
);
3826 commit_set_action(odp_actions
, OVS_KEY_ATTR_IPV6
,
3827 &ipv6_key
, sizeof(ipv6_key
));
3830 static enum slow_path_reason
3831 commit_set_arp_action(const struct flow
*flow
, struct flow
*base
,
3832 struct ofpbuf
*odp_actions
, struct flow_wildcards
*wc
)
3834 struct ovs_key_arp arp_key
;
3836 if (base
->nw_src
== flow
->nw_src
&&
3837 base
->nw_dst
== flow
->nw_dst
&&
3838 base
->nw_proto
== flow
->nw_proto
&&
3839 eth_addr_equals(base
->arp_sha
, flow
->arp_sha
) &&
3840 eth_addr_equals(base
->arp_tha
, flow
->arp_tha
)) {
3844 memset(&wc
->masks
.nw_src
, 0xff, sizeof wc
->masks
.nw_src
);
3845 memset(&wc
->masks
.nw_dst
, 0xff, sizeof wc
->masks
.nw_dst
);
3846 memset(&wc
->masks
.nw_proto
, 0xff, sizeof wc
->masks
.nw_proto
);
3847 memset(&wc
->masks
.arp_sha
, 0xff, sizeof wc
->masks
.arp_sha
);
3848 memset(&wc
->masks
.arp_tha
, 0xff, sizeof wc
->masks
.arp_tha
);
3850 base
->nw_src
= flow
->nw_src
;
3851 base
->nw_dst
= flow
->nw_dst
;
3852 base
->nw_proto
= flow
->nw_proto
;
3853 memcpy(base
->arp_sha
, flow
->arp_sha
, ETH_ADDR_LEN
);
3854 memcpy(base
->arp_tha
, flow
->arp_tha
, ETH_ADDR_LEN
);
3856 arp_key
.arp_sip
= base
->nw_src
;
3857 arp_key
.arp_tip
= base
->nw_dst
;
3858 arp_key
.arp_op
= htons(base
->nw_proto
);
3859 memcpy(arp_key
.arp_sha
, flow
->arp_sha
, ETH_ADDR_LEN
);
3860 memcpy(arp_key
.arp_tha
, flow
->arp_tha
, ETH_ADDR_LEN
);
3862 commit_set_action(odp_actions
, OVS_KEY_ATTR_ARP
, &arp_key
, sizeof arp_key
);
3867 static enum slow_path_reason
3868 commit_set_nw_action(const struct flow
*flow
, struct flow
*base
,
3869 struct ofpbuf
*odp_actions
, struct flow_wildcards
*wc
)
3871 /* Check if 'flow' really has an L3 header. */
3872 if (!flow
->nw_proto
) {
3876 switch (ntohs(base
->dl_type
)) {
3878 commit_set_ipv4_action(flow
, base
, odp_actions
, wc
);
3882 commit_set_ipv6_action(flow
, base
, odp_actions
, wc
);
3886 return commit_set_arp_action(flow
, base
, odp_actions
, wc
);
3893 commit_set_port_action(const struct flow
*flow
, struct flow
*base
,
3894 struct ofpbuf
*odp_actions
, struct flow_wildcards
*wc
)
3896 /* Check if 'flow' really has an L3 header. */
3897 if (!flow
->nw_proto
) {
3901 if (!is_ip_any(base
) || (!base
->tp_src
&& !base
->tp_dst
)) {
3905 if (base
->tp_src
== flow
->tp_src
&&
3906 base
->tp_dst
== flow
->tp_dst
) {
3910 memset(&wc
->masks
.tp_src
, 0xff, sizeof wc
->masks
.tp_src
);
3911 memset(&wc
->masks
.tp_dst
, 0xff, sizeof wc
->masks
.tp_dst
);
3913 if (flow
->nw_proto
== IPPROTO_TCP
) {
3914 struct ovs_key_tcp port_key
;
3916 port_key
.tcp_src
= base
->tp_src
= flow
->tp_src
;
3917 port_key
.tcp_dst
= base
->tp_dst
= flow
->tp_dst
;
3919 commit_set_action(odp_actions
, OVS_KEY_ATTR_TCP
,
3920 &port_key
, sizeof(port_key
));
3922 } else if (flow
->nw_proto
== IPPROTO_UDP
) {
3923 struct ovs_key_udp port_key
;
3925 port_key
.udp_src
= base
->tp_src
= flow
->tp_src
;
3926 port_key
.udp_dst
= base
->tp_dst
= flow
->tp_dst
;
3928 commit_set_action(odp_actions
, OVS_KEY_ATTR_UDP
,
3929 &port_key
, sizeof(port_key
));
3930 } else if (flow
->nw_proto
== IPPROTO_SCTP
) {
3931 struct ovs_key_sctp port_key
;
3933 port_key
.sctp_src
= base
->tp_src
= flow
->tp_src
;
3934 port_key
.sctp_dst
= base
->tp_dst
= flow
->tp_dst
;
3936 commit_set_action(odp_actions
, OVS_KEY_ATTR_SCTP
,
3937 &port_key
, sizeof(port_key
));
3942 commit_set_priority_action(const struct flow
*flow
, struct flow
*base
,
3943 struct ofpbuf
*odp_actions
,
3944 struct flow_wildcards
*wc
)
3946 if (base
->skb_priority
== flow
->skb_priority
) {
3950 memset(&wc
->masks
.skb_priority
, 0xff, sizeof wc
->masks
.skb_priority
);
3951 base
->skb_priority
= flow
->skb_priority
;
3953 commit_set_action(odp_actions
, OVS_KEY_ATTR_PRIORITY
,
3954 &base
->skb_priority
, sizeof(base
->skb_priority
));
3958 commit_set_pkt_mark_action(const struct flow
*flow
, struct flow
*base
,
3959 struct ofpbuf
*odp_actions
,
3960 struct flow_wildcards
*wc
)
3962 if (base
->pkt_mark
== flow
->pkt_mark
) {
3966 memset(&wc
->masks
.pkt_mark
, 0xff, sizeof wc
->masks
.pkt_mark
);
3967 base
->pkt_mark
= flow
->pkt_mark
;
3969 odp_put_pkt_mark_action(base
->pkt_mark
, odp_actions
);
3972 /* If any of the flow key data that ODP actions can modify are different in
3973 * 'base' and 'flow', appends ODP actions to 'odp_actions' that change the flow
3974 * key from 'base' into 'flow', and then changes 'base' the same way. Does not
3975 * commit set_tunnel actions. Users should call commit_odp_tunnel_action()
3976 * in addition to this function if needed. Sets fields in 'wc' that are
3977 * used as part of the action.
3979 * Returns a reason to force processing the flow's packets into the userspace
3980 * slow path, if there is one, otherwise 0. */
3981 enum slow_path_reason
3982 commit_odp_actions(const struct flow
*flow
, struct flow
*base
,
3983 struct ofpbuf
*odp_actions
, struct flow_wildcards
*wc
)
3985 enum slow_path_reason slow
;
3987 commit_set_ether_addr_action(flow
, base
, odp_actions
, wc
);
3988 slow
= commit_set_nw_action(flow
, base
, odp_actions
, wc
);
3989 commit_set_port_action(flow
, base
, odp_actions
, wc
);
3990 commit_mpls_action(flow
, base
, odp_actions
, wc
);
3991 commit_vlan_action(flow
->vlan_tci
, base
, odp_actions
, wc
);
3992 commit_set_priority_action(flow
, base
, odp_actions
, wc
);
3993 commit_set_pkt_mark_action(flow
, base
, odp_actions
, wc
);