2 * Copyright (c) 2009, 2010, 2011 Nicira Networks.
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.
17 #include <arpa/inet.h>
22 #include <netinet/in.h>
23 #include <netinet/icmp6.h>
26 #include "byte-order.h"
28 #include "dynamic-string.h"
32 #include "openvswitch/tunnel.h"
38 VLOG_DEFINE_THIS_MODULE(odp_util);
40 /* The interface between userspace and kernel uses an "OVS_*" prefix.
41 * Since this is fairly non-specific for the OVS userspace components,
42 * "ODP_*" (Open vSwitch Datapath) is used as the prefix for
43 * interactions with the datapath.
46 static void format_odp_key_attr(const struct nlattr *a, struct ds *ds);
48 /* Returns one the following for the action with the given OVS_ACTION_ATTR_*
51 * - For an action whose argument has a fixed length, returned that
52 * nonnegative length in bytes.
54 * - For an action with a variable-length argument, returns -2.
56 * - For an invalid 'type', returns -1. */
58 odp_action_len(uint16_t type)
60 if (type > OVS_ACTION_ATTR_MAX) {
64 switch ((enum ovs_action_attr) type) {
65 case OVS_ACTION_ATTR_OUTPUT: return 4;
66 case OVS_ACTION_ATTR_USERSPACE: return -2;
67 case OVS_ACTION_ATTR_PUSH: return -2;
68 case OVS_ACTION_ATTR_POP: return 2;
69 case OVS_ACTION_ATTR_SET: return -2;
70 case OVS_ACTION_ATTR_SAMPLE: return -2;
72 case OVS_ACTION_ATTR_UNSPEC:
73 case __OVS_ACTION_ATTR_MAX:
81 ovs_key_attr_to_string(enum ovs_key_attr attr)
83 static char unknown_attr[3 + INT_STRLEN(unsigned int) + 1];
86 case OVS_KEY_ATTR_UNSPEC: return "unspec";
87 case OVS_KEY_ATTR_PRIORITY: return "priority";
88 case OVS_KEY_ATTR_TUN_ID: return "tun_id";
89 case OVS_KEY_ATTR_IN_PORT: return "in_port";
90 case OVS_KEY_ATTR_ETHERNET: return "eth";
91 case OVS_KEY_ATTR_8021Q: return "vlan";
92 case OVS_KEY_ATTR_ETHERTYPE: return "eth_type";
93 case OVS_KEY_ATTR_IPV4: return "ipv4";
94 case OVS_KEY_ATTR_IPV6: return "ipv6";
95 case OVS_KEY_ATTR_TCP: return "tcp";
96 case OVS_KEY_ATTR_UDP: return "udp";
97 case OVS_KEY_ATTR_ICMP: return "icmp";
98 case OVS_KEY_ATTR_ICMPV6: return "icmpv6";
99 case OVS_KEY_ATTR_ARP: return "arp";
100 case OVS_KEY_ATTR_ND: return "nd";
102 case __OVS_KEY_ATTR_MAX:
104 snprintf(unknown_attr, sizeof unknown_attr, "key%u",
105 (unsigned int) attr);
111 format_generic_odp_action(struct ds *ds, const struct nlattr *a)
113 size_t len = nl_attr_get_size(a);
115 ds_put_format(ds, "action%"PRId16, nl_attr_type(a));
117 const uint8_t *unspec;
120 unspec = nl_attr_get(a);
121 for (i = 0; i < len; i++) {
122 ds_put_char(ds, i ? ' ': '(');
123 ds_put_format(ds, "%02x", unspec[i]);
125 ds_put_char(ds, ')');
130 format_odp_sample_action(struct ds *ds, const struct nlattr *attr)
132 static const struct nl_policy ovs_sample_policy[] = {
133 [OVS_SAMPLE_ATTR_PROBABILITY] = { .type = NL_A_U32 },
134 [OVS_SAMPLE_ATTR_ACTIONS] = { .type = NL_A_NESTED }
136 struct nlattr *a[ARRAY_SIZE(ovs_sample_policy)];
138 const struct nlattr *nla_acts;
141 ds_put_cstr(ds, "sample");
143 if (!nl_parse_nested(attr, ovs_sample_policy, a, ARRAY_SIZE(a))) {
144 ds_put_cstr(ds, "(error)");
148 percentage = (100.0 * nl_attr_get_u32(a[OVS_SAMPLE_ATTR_PROBABILITY])) /
151 ds_put_format(ds, "(sample=%.1f%%,", percentage);
153 ds_put_cstr(ds, "actions(");
154 nla_acts = nl_attr_get(a[OVS_SAMPLE_ATTR_ACTIONS]);
155 len = nl_attr_get_size(a[OVS_SAMPLE_ATTR_ACTIONS]);
156 format_odp_actions(ds, nla_acts, len);
157 ds_put_format(ds, "))");
161 format_odp_userspace_action(struct ds *ds, const struct nlattr *attr)
163 static const struct nl_policy ovs_userspace_policy[] = {
164 [OVS_USERSPACE_ATTR_PID] = { .type = NL_A_U32 },
165 [OVS_USERSPACE_ATTR_USERDATA] = { .type = NL_A_U64, .optional = true },
167 struct nlattr *a[ARRAY_SIZE(ovs_userspace_policy)];
169 if (!nl_parse_nested(attr, ovs_userspace_policy, a, ARRAY_SIZE(a))) {
170 ds_put_cstr(ds, "userspace(error)");
174 ds_put_format(ds, "userspace(pid=%"PRIu32,
175 nl_attr_get_u32(a[OVS_USERSPACE_ATTR_PID]));
177 if (a[OVS_USERSPACE_ATTR_USERDATA]) {
178 uint64_t userdata = nl_attr_get_u64(a[OVS_USERSPACE_ATTR_USERDATA]);
179 struct user_action_cookie cookie;
181 memcpy(&cookie, &userdata, sizeof cookie);
183 if (cookie.type == USER_ACTION_COOKIE_CONTROLLER) {
184 ds_put_format(ds, ",controller,length=%"PRIu32,
186 } else if (cookie.type == USER_ACTION_COOKIE_SFLOW) {
187 ds_put_format(ds, ",sFlow,n_output=%"PRIu8","
188 "vid=%"PRIu16",pcp=%"PRIu8",ifindex=%"PRIu32,
189 cookie.n_output, vlan_tci_to_vid(cookie.vlan_tci),
190 vlan_tci_to_pcp(cookie.vlan_tci), cookie.data);
192 ds_put_format(ds, ",userdata=0x%"PRIx64, userdata);
196 ds_put_char(ds, ')');
200 format_odp_action(struct ds *ds, const struct nlattr *a)
203 enum ovs_action_attr type = nl_attr_type(a);
205 expected_len = odp_action_len(nl_attr_type(a));
206 if (expected_len != -2 && nl_attr_get_size(a) != expected_len) {
207 ds_put_format(ds, "bad length %zu, expected %d for: ",
208 nl_attr_get_size(a), expected_len);
209 format_generic_odp_action(ds, a);
215 case OVS_ACTION_ATTR_OUTPUT:
216 ds_put_format(ds, "%"PRIu16, nl_attr_get_u32(a));
218 case OVS_ACTION_ATTR_USERSPACE:
219 format_odp_userspace_action(ds, a);
221 case OVS_ACTION_ATTR_SET:
222 ds_put_cstr(ds, "set(");
223 format_odp_key_attr(nl_attr_get(a), ds);
224 ds_put_cstr(ds, ")");
226 case OVS_ACTION_ATTR_PUSH:
227 ds_put_cstr(ds, "push(");
228 format_odp_key_attr(nl_attr_get(a), ds);
229 ds_put_cstr(ds, ")");
231 case OVS_ACTION_ATTR_POP:
232 ds_put_format(ds, "pop(%s)",
233 ovs_key_attr_to_string(nl_attr_get_u16(a)));
235 case OVS_ACTION_ATTR_SAMPLE:
236 format_odp_sample_action(ds, a);
238 case OVS_ACTION_ATTR_UNSPEC:
239 case __OVS_ACTION_ATTR_MAX:
241 format_generic_odp_action(ds, a);
247 format_odp_actions(struct ds *ds, const struct nlattr *actions,
251 const struct nlattr *a;
254 NL_ATTR_FOR_EACH (a, left, actions, actions_len) {
256 ds_put_char(ds, ',');
258 format_odp_action(ds, a);
261 if (left == actions_len) {
262 ds_put_cstr(ds, "<empty>");
264 ds_put_format(ds, ",***%u leftover bytes***", left);
267 ds_put_cstr(ds, "drop");
271 /* Returns the correct length of the payload for a flow key attribute of the
272 * specified 'type', or -1 if 'type' is unknown. */
274 odp_flow_key_attr_len(uint16_t type)
276 if (type > OVS_KEY_ATTR_MAX) {
280 switch ((enum ovs_key_attr) type) {
281 case OVS_KEY_ATTR_PRIORITY: return 4;
282 case OVS_KEY_ATTR_TUN_ID: return 8;
283 case OVS_KEY_ATTR_IN_PORT: return 4;
284 case OVS_KEY_ATTR_ETHERNET: return sizeof(struct ovs_key_ethernet);
285 case OVS_KEY_ATTR_8021Q: return sizeof(struct ovs_key_8021q);
286 case OVS_KEY_ATTR_ETHERTYPE: return 2;
287 case OVS_KEY_ATTR_IPV4: return sizeof(struct ovs_key_ipv4);
288 case OVS_KEY_ATTR_IPV6: return sizeof(struct ovs_key_ipv6);
289 case OVS_KEY_ATTR_TCP: return sizeof(struct ovs_key_tcp);
290 case OVS_KEY_ATTR_UDP: return sizeof(struct ovs_key_udp);
291 case OVS_KEY_ATTR_ICMP: return sizeof(struct ovs_key_icmp);
292 case OVS_KEY_ATTR_ICMPV6: return sizeof(struct ovs_key_icmpv6);
293 case OVS_KEY_ATTR_ARP: return sizeof(struct ovs_key_arp);
294 case OVS_KEY_ATTR_ND: return sizeof(struct ovs_key_nd);
296 case OVS_KEY_ATTR_UNSPEC:
297 case __OVS_KEY_ATTR_MAX:
305 format_generic_odp_key(const struct nlattr *a, struct ds *ds)
307 size_t len = nl_attr_get_size(a);
309 const uint8_t *unspec;
312 unspec = nl_attr_get(a);
313 for (i = 0; i < len; i++) {
314 ds_put_char(ds, i ? ' ': '(');
315 ds_put_format(ds, "%02x", unspec[i]);
317 ds_put_char(ds, ')');
322 ovs_frag_type_to_string(enum ovs_frag_type type)
325 case OVS_FRAG_TYPE_NONE:
327 case OVS_FRAG_TYPE_FIRST:
329 case OVS_FRAG_TYPE_LATER:
331 case __OVS_FRAG_TYPE_MAX:
338 format_odp_key_attr(const struct nlattr *a, struct ds *ds)
340 const struct ovs_key_ethernet *eth_key;
341 const struct ovs_key_8021q *q_key;
342 const struct ovs_key_ipv4 *ipv4_key;
343 const struct ovs_key_ipv6 *ipv6_key;
344 const struct ovs_key_tcp *tcp_key;
345 const struct ovs_key_udp *udp_key;
346 const struct ovs_key_icmp *icmp_key;
347 const struct ovs_key_icmpv6 *icmpv6_key;
348 const struct ovs_key_arp *arp_key;
349 const struct ovs_key_nd *nd_key;
350 enum ovs_key_attr attr = nl_attr_type(a);
352 ds_put_cstr(ds, ovs_key_attr_to_string(attr));
353 if (nl_attr_get_size(a) != odp_flow_key_attr_len(nl_attr_type(a))) {
354 ds_put_format(ds, "(bad length %zu, expected %d)",
356 odp_flow_key_attr_len(nl_attr_type(a)));
357 format_generic_odp_key(a, ds);
362 case OVS_KEY_ATTR_PRIORITY:
363 ds_put_format(ds, "(%"PRIu32")", nl_attr_get_u32(a));
366 case OVS_KEY_ATTR_TUN_ID:
367 ds_put_format(ds, "(%#"PRIx64")", ntohll(nl_attr_get_be64(a)));
370 case OVS_KEY_ATTR_IN_PORT:
371 ds_put_format(ds, "(%"PRIu32")", nl_attr_get_u32(a));
374 case OVS_KEY_ATTR_ETHERNET:
375 eth_key = nl_attr_get(a);
376 ds_put_format(ds, "(src="ETH_ADDR_FMT",dst="ETH_ADDR_FMT")",
377 ETH_ADDR_ARGS(eth_key->eth_src),
378 ETH_ADDR_ARGS(eth_key->eth_dst));
381 case OVS_KEY_ATTR_8021Q:
382 q_key = nl_attr_get(a);
383 ds_put_cstr(ds, "(");
384 if (q_key->q_tpid != htons(ETH_TYPE_VLAN)) {
385 ds_put_format(ds, "tpid=0x%04"PRIx16",", ntohs(q_key->q_tpid));
387 ds_put_format(ds, "vid=%"PRIu16",pcp=%d)",
388 vlan_tci_to_vid(q_key->q_tci),
389 vlan_tci_to_pcp(q_key->q_tci));
392 case OVS_KEY_ATTR_ETHERTYPE:
393 ds_put_format(ds, "(0x%04"PRIx16")",
394 ntohs(nl_attr_get_be16(a)));
397 case OVS_KEY_ATTR_IPV4:
398 ipv4_key = nl_attr_get(a);
399 ds_put_format(ds, "(src="IP_FMT",dst="IP_FMT",proto=%"PRIu8
400 ",tos=%#"PRIx8",ttl=%"PRIu8",frag=%s)",
401 IP_ARGS(&ipv4_key->ipv4_src),
402 IP_ARGS(&ipv4_key->ipv4_dst),
403 ipv4_key->ipv4_proto, ipv4_key->ipv4_tos,
405 ovs_frag_type_to_string(ipv4_key->ipv4_frag));
408 case OVS_KEY_ATTR_IPV6: {
409 char src_str[INET6_ADDRSTRLEN];
410 char dst_str[INET6_ADDRSTRLEN];
412 ipv6_key = nl_attr_get(a);
413 inet_ntop(AF_INET6, ipv6_key->ipv6_src, src_str, sizeof src_str);
414 inet_ntop(AF_INET6, ipv6_key->ipv6_dst, dst_str, sizeof dst_str);
416 ds_put_format(ds, "(src=%s,dst=%s,label=%#"PRIx32",proto=%"PRIu8
417 ",tclass=%#"PRIx8",hlimit=%"PRIu8",frag=%s)",
418 src_str, dst_str, ntohl(ipv6_key->ipv6_label),
419 ipv6_key->ipv6_proto, ipv6_key->ipv6_tclass,
420 ipv6_key->ipv6_hlimit,
421 ovs_frag_type_to_string(ipv6_key->ipv6_frag));
425 case OVS_KEY_ATTR_TCP:
426 tcp_key = nl_attr_get(a);
427 ds_put_format(ds, "(src=%"PRIu16",dst=%"PRIu16")",
428 ntohs(tcp_key->tcp_src), ntohs(tcp_key->tcp_dst));
431 case OVS_KEY_ATTR_UDP:
432 udp_key = nl_attr_get(a);
433 ds_put_format(ds, "(src=%"PRIu16",dst=%"PRIu16")",
434 ntohs(udp_key->udp_src), ntohs(udp_key->udp_dst));
437 case OVS_KEY_ATTR_ICMP:
438 icmp_key = nl_attr_get(a);
439 ds_put_format(ds, "(type=%"PRIu8",code=%"PRIu8")",
440 icmp_key->icmp_type, icmp_key->icmp_code);
443 case OVS_KEY_ATTR_ICMPV6:
444 icmpv6_key = nl_attr_get(a);
445 ds_put_format(ds, "(type=%"PRIu8",code=%"PRIu8")",
446 icmpv6_key->icmpv6_type, icmpv6_key->icmpv6_code);
449 case OVS_KEY_ATTR_ARP:
450 arp_key = nl_attr_get(a);
451 ds_put_format(ds, "(sip="IP_FMT",tip="IP_FMT",op=%"PRIu16","
452 "sha="ETH_ADDR_FMT",tha="ETH_ADDR_FMT")",
453 IP_ARGS(&arp_key->arp_sip), IP_ARGS(&arp_key->arp_tip),
454 ntohs(arp_key->arp_op), ETH_ADDR_ARGS(arp_key->arp_sha),
455 ETH_ADDR_ARGS(arp_key->arp_tha));
458 case OVS_KEY_ATTR_ND: {
459 char target[INET6_ADDRSTRLEN];
461 nd_key = nl_attr_get(a);
462 inet_ntop(AF_INET6, nd_key->nd_target, target, sizeof target);
464 ds_put_format(ds, "(target=%s", target);
465 if (!eth_addr_is_zero(nd_key->nd_sll)) {
466 ds_put_format(ds, ",sll="ETH_ADDR_FMT,
467 ETH_ADDR_ARGS(nd_key->nd_sll));
469 if (!eth_addr_is_zero(nd_key->nd_tll)) {
470 ds_put_format(ds, ",tll="ETH_ADDR_FMT,
471 ETH_ADDR_ARGS(nd_key->nd_tll));
473 ds_put_char(ds, ')');
477 case OVS_KEY_ATTR_UNSPEC:
478 case __OVS_KEY_ATTR_MAX:
480 format_generic_odp_key(a, ds);
485 /* Appends to 'ds' a string representation of the 'key_len' bytes of
486 * OVS_KEY_ATTR_* attributes in 'key'. */
488 odp_flow_key_format(const struct nlattr *key, size_t key_len, struct ds *ds)
491 const struct nlattr *a;
494 NL_ATTR_FOR_EACH (a, left, key, key_len) {
496 ds_put_char(ds, ',');
498 format_odp_key_attr(a, ds);
501 if (left == key_len) {
502 ds_put_cstr(ds, "<empty>");
504 ds_put_format(ds, ",***%u leftover bytes***", left);
507 ds_put_cstr(ds, "<empty>");
512 put_nd_key(int n, const char *nd_target_s,
513 const uint8_t *nd_sll, const uint8_t *nd_tll, struct ofpbuf *key)
515 struct ovs_key_nd nd_key;
517 memset(&nd_key, 0, sizeof nd_key);
518 if (inet_pton(AF_INET6, nd_target_s, nd_key.nd_target) != 1) {
522 memcpy(nd_key.nd_sll, nd_sll, ETH_ADDR_LEN);
525 memcpy(nd_key.nd_tll, nd_tll, ETH_ADDR_LEN);
527 nl_msg_put_unspec(key, OVS_KEY_ATTR_ND, &nd_key, sizeof nd_key);
532 ovs_frag_type_from_string(const char *s, enum ovs_frag_type *type)
534 if (!strcasecmp(s, "no")) {
535 *type = OVS_FRAG_TYPE_NONE;
536 } else if (!strcasecmp(s, "first")) {
537 *type = OVS_FRAG_TYPE_FIRST;
538 } else if (!strcasecmp(s, "later")) {
539 *type = OVS_FRAG_TYPE_LATER;
547 parse_odp_key_attr(const char *s, struct ofpbuf *key)
549 /* Many of the sscanf calls in this function use oversized destination
550 * fields because some sscanf() implementations truncate the range of %i
551 * directives, so that e.g. "%"SCNi16 interprets input of "0xfedc" as a
552 * value of 0x7fff. The other alternatives are to allow only a single
553 * radix (e.g. decimal or hexadecimal) or to write more sophisticated
556 * The tun_id parser has to use an alternative approach because there is no
557 * type larger than 64 bits. */
560 unsigned long long int priority;
563 if (sscanf(s, "priority(%lli)%n", &priority, &n) > 0 && n > 0) {
564 nl_msg_put_u32(key, OVS_KEY_ATTR_PRIORITY, priority);
573 if (sscanf(s, "tun_id(%31[x0123456789abcdefABCDEF])%n",
574 tun_id_s, &n) > 0 && n > 0) {
575 uint64_t tun_id = strtoull(tun_id_s, NULL, 0);
576 nl_msg_put_be64(key, OVS_KEY_ATTR_TUN_ID, htonll(tun_id));
582 unsigned long long int in_port;
585 if (sscanf(s, "in_port(%lli)%n", &in_port, &n) > 0 && n > 0) {
586 nl_msg_put_u32(key, OVS_KEY_ATTR_IN_PORT, in_port);
592 struct ovs_key_ethernet eth_key;
596 "eth(src="ETH_ADDR_SCAN_FMT",dst="ETH_ADDR_SCAN_FMT")%n",
597 ETH_ADDR_SCAN_ARGS(eth_key.eth_src),
598 ETH_ADDR_SCAN_ARGS(eth_key.eth_dst), &n) > 0 && n > 0) {
599 nl_msg_put_unspec(key, OVS_KEY_ATTR_ETHERNET,
600 ð_key, sizeof eth_key);
606 uint16_t tpid = ETH_TYPE_VLAN;
611 if ((sscanf(s, "vlan(vid=%"SCNi16",pcp=%i)%n",
612 &vid, &pcp, &n) > 0 && n > 0) ||
613 (sscanf(s, "vlan(tpid=%"SCNi16",vid=%"SCNi16",pcp=%i)%n",
614 &tpid, &vid, &pcp, &n) > 0 && n > 0)) {
615 struct ovs_key_8021q q_key;
617 q_key.q_tpid = htons(tpid);
618 q_key.q_tci = htons((vid << VLAN_VID_SHIFT) |
619 (pcp << VLAN_PCP_SHIFT));
620 nl_msg_put_unspec(key, OVS_KEY_ATTR_8021Q, &q_key, sizeof q_key);
629 if (sscanf(s, "eth_type(%i)%n", ð_type, &n) > 0 && n > 0) {
630 nl_msg_put_be16(key, OVS_KEY_ATTR_ETHERTYPE, htons(eth_type));
642 enum ovs_frag_type ipv4_frag;
645 if (sscanf(s, "ipv4(src="IP_SCAN_FMT",dst="IP_SCAN_FMT","
646 "proto=%i,tos=%i,ttl=%i,frag=%7[a-z])%n",
647 IP_SCAN_ARGS(&ipv4_src), IP_SCAN_ARGS(&ipv4_dst),
648 &ipv4_proto, &ipv4_tos, &ipv4_ttl, frag, &n) > 0
650 && ovs_frag_type_from_string(frag, &ipv4_frag)) {
651 struct ovs_key_ipv4 ipv4_key;
653 ipv4_key.ipv4_src = ipv4_src;
654 ipv4_key.ipv4_dst = ipv4_dst;
655 ipv4_key.ipv4_proto = ipv4_proto;
656 ipv4_key.ipv4_tos = ipv4_tos;
657 ipv4_key.ipv4_ttl = ipv4_ttl;
658 ipv4_key.ipv4_frag = ipv4_frag;
659 nl_msg_put_unspec(key, OVS_KEY_ATTR_IPV4,
660 &ipv4_key, sizeof ipv4_key);
666 char ipv6_src_s[IPV6_SCAN_LEN + 1];
667 char ipv6_dst_s[IPV6_SCAN_LEN + 1];
673 enum ovs_frag_type ipv6_frag;
676 if (sscanf(s, "ipv6(src="IPV6_SCAN_FMT",dst="IPV6_SCAN_FMT","
677 "label=%i,proto=%i,tclass=%i,hlimit=%i,frag=%7[a-z])%n",
678 ipv6_src_s, ipv6_dst_s, &ipv6_label,
679 &ipv6_proto, &ipv6_tclass, &ipv6_hlimit, frag, &n) > 0
681 && ovs_frag_type_from_string(frag, &ipv6_frag)) {
682 struct ovs_key_ipv6 ipv6_key;
684 if (inet_pton(AF_INET6, ipv6_src_s, &ipv6_key.ipv6_src) != 1 ||
685 inet_pton(AF_INET6, ipv6_dst_s, &ipv6_key.ipv6_dst) != 1) {
688 ipv6_key.ipv6_label = htonl(ipv6_label);
689 ipv6_key.ipv6_proto = ipv6_proto;
690 ipv6_key.ipv6_tclass = ipv6_tclass;
691 ipv6_key.ipv6_hlimit = ipv6_hlimit;
692 ipv6_key.ipv6_frag = ipv6_frag;
693 nl_msg_put_unspec(key, OVS_KEY_ATTR_IPV6,
694 &ipv6_key, sizeof ipv6_key);
704 if (sscanf(s, "tcp(src=%i,dst=%i)%n",&tcp_src, &tcp_dst, &n) > 0
706 struct ovs_key_tcp tcp_key;
708 tcp_key.tcp_src = htons(tcp_src);
709 tcp_key.tcp_dst = htons(tcp_dst);
710 nl_msg_put_unspec(key, OVS_KEY_ATTR_TCP, &tcp_key, sizeof tcp_key);
720 if (sscanf(s, "udp(src=%i,dst=%i)%n", &udp_src, &udp_dst, &n) > 0
722 struct ovs_key_udp udp_key;
724 udp_key.udp_src = htons(udp_src);
725 udp_key.udp_dst = htons(udp_dst);
726 nl_msg_put_unspec(key, OVS_KEY_ATTR_UDP, &udp_key, sizeof udp_key);
736 if (sscanf(s, "icmp(type=%i,code=%i)%n",
737 &icmp_type, &icmp_code, &n) > 0
739 struct ovs_key_icmp icmp_key;
741 icmp_key.icmp_type = icmp_type;
742 icmp_key.icmp_code = icmp_code;
743 nl_msg_put_unspec(key, OVS_KEY_ATTR_ICMP,
744 &icmp_key, sizeof icmp_key);
750 struct ovs_key_icmpv6 icmpv6_key;
753 if (sscanf(s, "icmpv6(type=%"SCNi8",code=%"SCNi8")%n",
754 &icmpv6_key.icmpv6_type, &icmpv6_key.icmpv6_code,&n) > 0
756 nl_msg_put_unspec(key, OVS_KEY_ATTR_ICMPV6,
757 &icmpv6_key, sizeof icmpv6_key);
766 uint8_t arp_sha[ETH_ADDR_LEN];
767 uint8_t arp_tha[ETH_ADDR_LEN];
770 if (sscanf(s, "arp(sip="IP_SCAN_FMT",tip="IP_SCAN_FMT","
771 "op=%i,sha="ETH_ADDR_SCAN_FMT",tha="ETH_ADDR_SCAN_FMT")%n",
772 IP_SCAN_ARGS(&arp_sip),
773 IP_SCAN_ARGS(&arp_tip),
775 ETH_ADDR_SCAN_ARGS(arp_sha),
776 ETH_ADDR_SCAN_ARGS(arp_tha), &n) > 0 && n > 0) {
777 struct ovs_key_arp arp_key;
779 memset(&arp_key, 0, sizeof arp_key);
780 arp_key.arp_sip = arp_sip;
781 arp_key.arp_tip = arp_tip;
782 arp_key.arp_op = htons(arp_op);
783 memcpy(arp_key.arp_sha, arp_sha, ETH_ADDR_LEN);
784 memcpy(arp_key.arp_tha, arp_tha, ETH_ADDR_LEN);
785 nl_msg_put_unspec(key, OVS_KEY_ATTR_ARP, &arp_key, sizeof arp_key);
791 char nd_target_s[IPV6_SCAN_LEN + 1];
792 uint8_t nd_sll[ETH_ADDR_LEN];
793 uint8_t nd_tll[ETH_ADDR_LEN];
796 if (sscanf(s, "nd(target="IPV6_SCAN_FMT")%n",
797 nd_target_s, &n) > 0 && n > 0) {
798 return put_nd_key(n, nd_target_s, NULL, NULL, key);
800 if (sscanf(s, "nd(target="IPV6_SCAN_FMT",sll="ETH_ADDR_SCAN_FMT")%n",
801 nd_target_s, ETH_ADDR_SCAN_ARGS(nd_sll), &n) > 0
803 return put_nd_key(n, nd_target_s, nd_sll, NULL, key);
805 if (sscanf(s, "nd(target="IPV6_SCAN_FMT",tll="ETH_ADDR_SCAN_FMT")%n",
806 nd_target_s, ETH_ADDR_SCAN_ARGS(nd_tll), &n) > 0
808 return put_nd_key(n, nd_target_s, NULL, nd_tll, key);
810 if (sscanf(s, "nd(target="IPV6_SCAN_FMT",sll="ETH_ADDR_SCAN_FMT","
811 "tll="ETH_ADDR_SCAN_FMT")%n",
812 nd_target_s, ETH_ADDR_SCAN_ARGS(nd_sll),
813 ETH_ADDR_SCAN_ARGS(nd_tll), &n) > 0
815 return put_nd_key(n, nd_target_s, nd_sll, nd_tll, key);
822 /* Parses the string representation of a datapath flow key, in the
823 * format output by odp_flow_key_format(). Returns 0 if successful,
824 * otherwise a positive errno value. On success, the flow key is
825 * appended to 'key' as a series of Netlink attributes. On failure, no
826 * data is appended to 'key'. Either way, 'key''s data might be
829 * On success, the attributes appended to 'key' are individually syntactically
830 * valid, but they may not be valid as a sequence. 'key' might, for example,
831 * have duplicated keys. odp_flow_key_to_flow() will detect those errors. */
833 odp_flow_key_from_string(const char *s, struct ofpbuf *key)
835 const size_t old_size = key->size;
839 s += strspn(s, ", \t\r\n");
844 retval = parse_odp_key_attr(s, key);
846 key->size = old_size;
856 ovs_to_odp_frag(uint8_t ovs_frag)
858 return (ovs_frag & FLOW_NW_FRAG_LATER ? OVS_FRAG_TYPE_LATER
859 : ovs_frag & FLOW_NW_FRAG_ANY ? OVS_FRAG_TYPE_FIRST
860 : OVS_FRAG_TYPE_NONE);
863 /* Appends a representation of 'flow' as OVS_KEY_ATTR_* attributes to 'buf'. */
865 odp_flow_key_from_flow(struct ofpbuf *buf, const struct flow *flow)
867 struct ovs_key_ethernet *eth_key;
869 if (flow->priority) {
870 nl_msg_put_u32(buf, OVS_KEY_ATTR_PRIORITY, flow->priority);
873 if (flow->tun_id != htonll(0)) {
874 nl_msg_put_be64(buf, OVS_KEY_ATTR_TUN_ID, flow->tun_id);
877 if (flow->in_port != OFPP_NONE) {
878 nl_msg_put_u32(buf, OVS_KEY_ATTR_IN_PORT,
879 ofp_port_to_odp_port(flow->in_port));
882 eth_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_ETHERNET,
884 memcpy(eth_key->eth_src, flow->dl_src, ETH_ADDR_LEN);
885 memcpy(eth_key->eth_dst, flow->dl_dst, ETH_ADDR_LEN);
887 if (flow->vlan_tci != htons(0)) {
888 struct ovs_key_8021q *q_key;
890 q_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_8021Q,
892 q_key->q_tpid = htons(ETH_TYPE_VLAN);
893 q_key->q_tci = flow->vlan_tci & ~htons(VLAN_CFI);
896 if (ntohs(flow->dl_type) < ETH_TYPE_MIN) {
900 nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, flow->dl_type);
902 if (flow->dl_type == htons(ETH_TYPE_IP)) {
903 struct ovs_key_ipv4 *ipv4_key;
905 ipv4_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_IPV4,
907 ipv4_key->ipv4_src = flow->nw_src;
908 ipv4_key->ipv4_dst = flow->nw_dst;
909 ipv4_key->ipv4_proto = flow->nw_proto;
910 ipv4_key->ipv4_tos = flow->nw_tos;
911 ipv4_key->ipv4_ttl = flow->nw_ttl;
912 ipv4_key->ipv4_frag = ovs_to_odp_frag(flow->nw_frag);
913 } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
914 struct ovs_key_ipv6 *ipv6_key;
916 ipv6_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_IPV6,
918 memcpy(ipv6_key->ipv6_src, &flow->ipv6_src, sizeof ipv6_key->ipv6_src);
919 memcpy(ipv6_key->ipv6_dst, &flow->ipv6_dst, sizeof ipv6_key->ipv6_dst);
920 ipv6_key->ipv6_label = flow->ipv6_label;
921 ipv6_key->ipv6_proto = flow->nw_proto;
922 ipv6_key->ipv6_tclass = flow->nw_tos;
923 ipv6_key->ipv6_hlimit = flow->nw_ttl;
924 ipv6_key->ipv6_frag = ovs_to_odp_frag(flow->nw_frag);
925 } else if (flow->dl_type == htons(ETH_TYPE_ARP)) {
926 struct ovs_key_arp *arp_key;
928 arp_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_ARP,
930 memset(arp_key, 0, sizeof *arp_key);
931 arp_key->arp_sip = flow->nw_src;
932 arp_key->arp_tip = flow->nw_dst;
933 arp_key->arp_op = htons(flow->nw_proto);
934 memcpy(arp_key->arp_sha, flow->arp_sha, ETH_ADDR_LEN);
935 memcpy(arp_key->arp_tha, flow->arp_tha, ETH_ADDR_LEN);
938 if ((flow->dl_type == htons(ETH_TYPE_IP)
939 || flow->dl_type == htons(ETH_TYPE_IPV6))
940 && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
942 if (flow->nw_proto == IPPROTO_TCP) {
943 struct ovs_key_tcp *tcp_key;
945 tcp_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_TCP,
947 tcp_key->tcp_src = flow->tp_src;
948 tcp_key->tcp_dst = flow->tp_dst;
949 } else if (flow->nw_proto == IPPROTO_UDP) {
950 struct ovs_key_udp *udp_key;
952 udp_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_UDP,
954 udp_key->udp_src = flow->tp_src;
955 udp_key->udp_dst = flow->tp_dst;
956 } else if (flow->dl_type == htons(ETH_TYPE_IP)
957 && flow->nw_proto == IPPROTO_ICMP) {
958 struct ovs_key_icmp *icmp_key;
960 icmp_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_ICMP,
962 icmp_key->icmp_type = ntohs(flow->tp_src);
963 icmp_key->icmp_code = ntohs(flow->tp_dst);
964 } else if (flow->dl_type == htons(ETH_TYPE_IPV6)
965 && flow->nw_proto == IPPROTO_ICMPV6) {
966 struct ovs_key_icmpv6 *icmpv6_key;
968 icmpv6_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_ICMPV6,
970 icmpv6_key->icmpv6_type = ntohs(flow->tp_src);
971 icmpv6_key->icmpv6_code = ntohs(flow->tp_dst);
973 if (icmpv6_key->icmpv6_type == ND_NEIGHBOR_SOLICIT
974 || icmpv6_key->icmpv6_type == ND_NEIGHBOR_ADVERT) {
975 struct ovs_key_nd *nd_key;
977 nd_key = nl_msg_put_unspec_uninit(buf, OVS_KEY_ATTR_ND,
979 memcpy(nd_key->nd_target, &flow->nd_target,
980 sizeof nd_key->nd_target);
981 memcpy(nd_key->nd_sll, flow->arp_sha, ETH_ADDR_LEN);
982 memcpy(nd_key->nd_tll, flow->arp_tha, ETH_ADDR_LEN);
989 log_odp_key_attributes(struct vlog_rate_limit *rl, const char *title,
991 const struct nlattr *key, size_t key_len)
996 if (VLOG_DROP_WARN(rl)) {
1001 ds_put_format(&s, "%s:", title);
1002 for (i = 0; i < 32; i++) {
1003 if (attrs & (1u << i)) {
1004 ds_put_format(&s, " %s", ovs_key_attr_to_string(i));
1008 ds_put_cstr(&s, ": ");
1009 odp_flow_key_format(key, key_len, &s);
1011 VLOG_WARN("%s", ds_cstr(&s));
1016 odp_to_ovs_frag(uint8_t odp_frag, struct flow *flow)
1018 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1020 if (odp_frag > OVS_FRAG_TYPE_LATER) {
1021 VLOG_ERR_RL(&rl, "invalid frag %"PRIu8" in flow key",
1026 if (odp_frag != OVS_FRAG_TYPE_NONE) {
1027 flow->nw_frag |= FLOW_NW_FRAG_ANY;
1028 if (odp_frag == OVS_FRAG_TYPE_LATER) {
1029 flow->nw_frag |= FLOW_NW_FRAG_LATER;
1035 /* Converts the 'key_len' bytes of OVS_KEY_ATTR_* attributes in 'key' to a flow
1036 * structure in 'flow'. Returns 0 if successful, otherwise EINVAL. */
1038 odp_flow_key_to_flow(const struct nlattr *key, size_t key_len,
1041 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1042 const struct nlattr *attrs[OVS_KEY_ATTR_MAX + 1];
1043 const struct nlattr *nla;
1044 uint64_t expected_attrs;
1045 uint64_t present_attrs;
1046 uint64_t missing_attrs;
1047 uint64_t extra_attrs;
1050 memset(flow, 0, sizeof *flow);
1052 memset(attrs, 0, sizeof attrs);
1056 NL_ATTR_FOR_EACH (nla, left, key, key_len) {
1057 uint16_t type = nl_attr_type(nla);
1058 size_t len = nl_attr_get_size(nla);
1059 int expected_len = odp_flow_key_attr_len(type);
1061 if (len != expected_len) {
1062 if (expected_len == -1) {
1063 VLOG_ERR_RL(&rl, "unknown attribute %"PRIu16" in flow key",
1066 VLOG_ERR_RL(&rl, "attribute %s has length %zu but should have "
1067 "length %d", ovs_key_attr_to_string(type),
1071 } else if (present_attrs & (UINT64_C(1) << type)) {
1072 VLOG_ERR_RL(&rl, "duplicate %s attribute in flow key",
1073 ovs_key_attr_to_string(type));
1077 present_attrs |= UINT64_C(1) << type;
1081 VLOG_ERR_RL(&rl, "trailing garbage in flow key");
1085 if (attrs[OVS_KEY_ATTR_PRIORITY]) {
1086 flow->priority = nl_attr_get_u32(attrs[OVS_KEY_ATTR_PRIORITY]);
1087 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_PRIORITY;
1090 if (attrs[OVS_KEY_ATTR_TUN_ID]) {
1091 flow->tun_id = nl_attr_get_be64(attrs[OVS_KEY_ATTR_TUN_ID]);
1092 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_TUN_ID;
1095 if (attrs[OVS_KEY_ATTR_IN_PORT]) {
1096 uint32_t in_port = nl_attr_get_u32(attrs[OVS_KEY_ATTR_IN_PORT]);
1097 if (in_port >= UINT16_MAX || in_port >= OFPP_MAX) {
1098 VLOG_ERR_RL(&rl, "in_port %"PRIu32" out of supported range",
1102 flow->in_port = odp_port_to_ofp_port(in_port);
1103 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_IN_PORT;
1105 flow->in_port = OFPP_NONE;
1108 if (attrs[OVS_KEY_ATTR_ETHERNET]) {
1109 const struct ovs_key_ethernet *eth_key;
1111 eth_key = nl_attr_get(attrs[OVS_KEY_ATTR_ETHERNET]);
1112 memcpy(flow->dl_src, eth_key->eth_src, ETH_ADDR_LEN);
1113 memcpy(flow->dl_dst, eth_key->eth_dst, ETH_ADDR_LEN);
1115 VLOG_ERR_RL(&rl, "missing Ethernet attribute in flow key");
1118 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ETHERNET;
1120 if (attrs[OVS_KEY_ATTR_8021Q]) {
1121 const struct ovs_key_8021q *q_key;
1123 q_key = nl_attr_get(attrs[OVS_KEY_ATTR_8021Q]);
1124 if (q_key->q_tpid != htons(ETH_TYPE_VLAN)) {
1125 VLOG_ERR_RL(&rl, "unsupported 802.1Q TPID %"PRIu16" in flow key",
1126 ntohs(q_key->q_tpid));
1129 if (q_key->q_tci & htons(VLAN_CFI)) {
1130 VLOG_ERR_RL(&rl, "invalid 802.1Q TCI %"PRIu16" in flow key",
1131 ntohs(q_key->q_tci));
1134 flow->vlan_tci = q_key->q_tci | htons(VLAN_CFI);
1135 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_8021Q;
1138 if (attrs[OVS_KEY_ATTR_ETHERTYPE]) {
1139 flow->dl_type = nl_attr_get_be16(attrs[OVS_KEY_ATTR_ETHERTYPE]);
1140 if (ntohs(flow->dl_type) < 1536) {
1141 VLOG_ERR_RL(&rl, "invalid Ethertype %"PRIu16" in flow key",
1142 ntohs(flow->dl_type));
1145 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ETHERTYPE;
1147 flow->dl_type = htons(FLOW_DL_TYPE_NONE);
1150 if (flow->dl_type == htons(ETH_TYPE_IP)) {
1151 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_IPV4;
1152 if (attrs[OVS_KEY_ATTR_IPV4]) {
1153 const struct ovs_key_ipv4 *ipv4_key;
1155 ipv4_key = nl_attr_get(attrs[OVS_KEY_ATTR_IPV4]);
1156 flow->nw_src = ipv4_key->ipv4_src;
1157 flow->nw_dst = ipv4_key->ipv4_dst;
1158 flow->nw_proto = ipv4_key->ipv4_proto;
1159 flow->nw_tos = ipv4_key->ipv4_tos;
1160 flow->nw_ttl = ipv4_key->ipv4_ttl;
1161 if (!odp_to_ovs_frag(ipv4_key->ipv4_frag, flow)) {
1165 } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
1166 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_IPV6;
1167 if (attrs[OVS_KEY_ATTR_IPV6]) {
1168 const struct ovs_key_ipv6 *ipv6_key;
1170 ipv6_key = nl_attr_get(attrs[OVS_KEY_ATTR_IPV6]);
1171 memcpy(&flow->ipv6_src, ipv6_key->ipv6_src, sizeof flow->ipv6_src);
1172 memcpy(&flow->ipv6_dst, ipv6_key->ipv6_dst, sizeof flow->ipv6_dst);
1173 flow->ipv6_label = ipv6_key->ipv6_label;
1174 flow->nw_proto = ipv6_key->ipv6_proto;
1175 flow->nw_tos = ipv6_key->ipv6_tclass;
1176 flow->nw_ttl = ipv6_key->ipv6_hlimit;
1177 if (!odp_to_ovs_frag(ipv6_key->ipv6_frag, flow)) {
1181 } else if (flow->dl_type == htons(ETH_TYPE_ARP)) {
1182 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ARP;
1183 if (attrs[OVS_KEY_ATTR_ARP]) {
1184 const struct ovs_key_arp *arp_key;
1186 arp_key = nl_attr_get(attrs[OVS_KEY_ATTR_ARP]);
1187 flow->nw_src = arp_key->arp_sip;
1188 flow->nw_dst = arp_key->arp_tip;
1189 if (arp_key->arp_op & htons(0xff00)) {
1190 VLOG_ERR_RL(&rl, "unsupported ARP opcode %"PRIu16" in flow "
1191 "key", ntohs(arp_key->arp_op));
1194 flow->nw_proto = ntohs(arp_key->arp_op);
1195 memcpy(flow->arp_sha, arp_key->arp_sha, ETH_ADDR_LEN);
1196 memcpy(flow->arp_tha, arp_key->arp_tha, ETH_ADDR_LEN);
1200 if (flow->nw_proto == IPPROTO_TCP
1201 && (flow->dl_type == htons(ETH_TYPE_IP) ||
1202 flow->dl_type == htons(ETH_TYPE_IPV6))
1203 && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
1204 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_TCP;
1205 if (attrs[OVS_KEY_ATTR_TCP]) {
1206 const struct ovs_key_tcp *tcp_key;
1208 tcp_key = nl_attr_get(attrs[OVS_KEY_ATTR_TCP]);
1209 flow->tp_src = tcp_key->tcp_src;
1210 flow->tp_dst = tcp_key->tcp_dst;
1212 } else if (flow->nw_proto == IPPROTO_UDP
1213 && (flow->dl_type == htons(ETH_TYPE_IP) ||
1214 flow->dl_type == htons(ETH_TYPE_IPV6))
1215 && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
1216 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_UDP;
1217 if (attrs[OVS_KEY_ATTR_UDP]) {
1218 const struct ovs_key_udp *udp_key;
1220 udp_key = nl_attr_get(attrs[OVS_KEY_ATTR_UDP]);
1221 flow->tp_src = udp_key->udp_src;
1222 flow->tp_dst = udp_key->udp_dst;
1224 } else if (flow->nw_proto == IPPROTO_ICMP
1225 && flow->dl_type == htons(ETH_TYPE_IP)
1226 && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
1227 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ICMP;
1228 if (attrs[OVS_KEY_ATTR_ICMP]) {
1229 const struct ovs_key_icmp *icmp_key;
1231 icmp_key = nl_attr_get(attrs[OVS_KEY_ATTR_ICMP]);
1232 flow->tp_src = htons(icmp_key->icmp_type);
1233 flow->tp_dst = htons(icmp_key->icmp_code);
1235 } else if (flow->nw_proto == IPPROTO_ICMPV6
1236 && flow->dl_type == htons(ETH_TYPE_IPV6)
1237 && !(flow->nw_frag & FLOW_NW_FRAG_LATER)) {
1238 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ICMPV6;
1239 if (attrs[OVS_KEY_ATTR_ICMPV6]) {
1240 const struct ovs_key_icmpv6 *icmpv6_key;
1242 icmpv6_key = nl_attr_get(attrs[OVS_KEY_ATTR_ICMPV6]);
1243 flow->tp_src = htons(icmpv6_key->icmpv6_type);
1244 flow->tp_dst = htons(icmpv6_key->icmpv6_code);
1246 if (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT) ||
1247 flow->tp_src == htons(ND_NEIGHBOR_ADVERT)) {
1248 expected_attrs |= UINT64_C(1) << OVS_KEY_ATTR_ND;
1249 if (attrs[OVS_KEY_ATTR_ND]) {
1250 const struct ovs_key_nd *nd_key;
1252 nd_key = nl_attr_get(attrs[OVS_KEY_ATTR_ND]);
1253 memcpy(&flow->nd_target, nd_key->nd_target,
1254 sizeof flow->nd_target);
1255 memcpy(flow->arp_sha, nd_key->nd_sll, ETH_ADDR_LEN);
1256 memcpy(flow->arp_tha, nd_key->nd_tll, ETH_ADDR_LEN);
1262 missing_attrs = expected_attrs & ~present_attrs;
1263 if (missing_attrs) {
1264 static struct vlog_rate_limit miss_rl = VLOG_RATE_LIMIT_INIT(10, 10);
1265 log_odp_key_attributes(&miss_rl, "expected but not present",
1266 missing_attrs, key, key_len);
1270 extra_attrs = present_attrs & ~expected_attrs;
1272 static struct vlog_rate_limit extra_rl = VLOG_RATE_LIMIT_INIT(10, 10);
1273 log_odp_key_attributes(&extra_rl, "present but not expected",
1274 extra_attrs, key, key_len);