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/icmp6.h>
25 #include "byte-order.h"
27 #include "dynamic-string.h"
30 #include "openvswitch/tunnel.h"
36 odp_action_len(uint16_t type)
38 if (type > ODP_ACTION_ATTR_MAX) {
42 switch ((enum odp_action_type) type) {
43 case ODP_ACTION_ATTR_OUTPUT: return 4;
44 case ODP_ACTION_ATTR_USERSPACE: return 8;
45 case ODP_ACTION_ATTR_SET_DL_TCI: return 2;
46 case ODP_ACTION_ATTR_STRIP_VLAN: return 0;
47 case ODP_ACTION_ATTR_SET_DL_SRC: return ETH_ADDR_LEN;
48 case ODP_ACTION_ATTR_SET_DL_DST: return ETH_ADDR_LEN;
49 case ODP_ACTION_ATTR_SET_NW_SRC: return 4;
50 case ODP_ACTION_ATTR_SET_NW_DST: return 4;
51 case ODP_ACTION_ATTR_SET_NW_TOS: return 1;
52 case ODP_ACTION_ATTR_SET_TP_SRC: return 2;
53 case ODP_ACTION_ATTR_SET_TP_DST: return 2;
54 case ODP_ACTION_ATTR_SET_TUNNEL: return 8;
55 case ODP_ACTION_ATTR_SET_PRIORITY: return 4;
56 case ODP_ACTION_ATTR_POP_PRIORITY: return 0;
58 case ODP_ACTION_ATTR_UNSPEC:
59 case __ODP_ACTION_ATTR_MAX:
67 format_generic_odp_action(struct ds *ds, const struct nlattr *a)
69 size_t len = nl_attr_get_size(a);
71 ds_put_format(ds, "action%"PRId16, nl_attr_type(a));
73 const uint8_t *unspec;
76 unspec = nl_attr_get(a);
77 for (i = 0; i < len; i++) {
78 ds_put_char(ds, i ? ' ': '(');
79 ds_put_format(ds, "%02x", unspec[i]);
86 format_odp_action(struct ds *ds, const struct nlattr *a)
91 if (nl_attr_get_size(a) != odp_action_len(nl_attr_type(a))) {
92 ds_put_format(ds, "bad length %zu, expected %d for: ",
93 nl_attr_get_size(a), odp_action_len(nl_attr_type(a)));
94 format_generic_odp_action(ds, a);
98 switch (nl_attr_type(a)) {
99 case ODP_ACTION_ATTR_OUTPUT:
100 ds_put_format(ds, "%"PRIu16, nl_attr_get_u32(a));
102 case ODP_ACTION_ATTR_USERSPACE:
103 ds_put_format(ds, "userspace(%"PRIu64")", nl_attr_get_u64(a));
105 case ODP_ACTION_ATTR_SET_TUNNEL:
106 ds_put_format(ds, "set_tunnel(%#"PRIx64")",
107 ntohll(nl_attr_get_be64(a)));
109 case ODP_ACTION_ATTR_SET_DL_TCI:
110 ds_put_format(ds, "set_tci(vid=%"PRIu16",pcp=%d)",
111 vlan_tci_to_vid(nl_attr_get_be16(a)),
112 vlan_tci_to_pcp(nl_attr_get_be16(a)));
114 case ODP_ACTION_ATTR_STRIP_VLAN:
115 ds_put_format(ds, "strip_vlan");
117 case ODP_ACTION_ATTR_SET_DL_SRC:
118 eth = nl_attr_get_unspec(a, ETH_ADDR_LEN);
119 ds_put_format(ds, "set_dl_src("ETH_ADDR_FMT")", ETH_ADDR_ARGS(eth));
121 case ODP_ACTION_ATTR_SET_DL_DST:
122 eth = nl_attr_get_unspec(a, ETH_ADDR_LEN);
123 ds_put_format(ds, "set_dl_dst("ETH_ADDR_FMT")", ETH_ADDR_ARGS(eth));
125 case ODP_ACTION_ATTR_SET_NW_SRC:
126 ip = nl_attr_get_be32(a);
127 ds_put_format(ds, "set_nw_src("IP_FMT")", IP_ARGS(&ip));
129 case ODP_ACTION_ATTR_SET_NW_DST:
130 ip = nl_attr_get_be32(a);
131 ds_put_format(ds, "set_nw_dst("IP_FMT")", IP_ARGS(&ip));
133 case ODP_ACTION_ATTR_SET_NW_TOS:
134 ds_put_format(ds, "set_nw_tos(%"PRIu8")", nl_attr_get_u8(a));
136 case ODP_ACTION_ATTR_SET_TP_SRC:
137 ds_put_format(ds, "set_tp_src(%"PRIu16")", ntohs(nl_attr_get_be16(a)));
139 case ODP_ACTION_ATTR_SET_TP_DST:
140 ds_put_format(ds, "set_tp_dst(%"PRIu16")", ntohs(nl_attr_get_be16(a)));
142 case ODP_ACTION_ATTR_SET_PRIORITY:
143 ds_put_format(ds, "set_priority(%#"PRIx32")", nl_attr_get_u32(a));
145 case ODP_ACTION_ATTR_POP_PRIORITY:
146 ds_put_cstr(ds, "pop_priority");
149 format_generic_odp_action(ds, a);
155 format_odp_actions(struct ds *ds, const struct nlattr *actions,
159 const struct nlattr *a;
162 NL_ATTR_FOR_EACH (a, left, actions, actions_len) {
164 ds_put_char(ds, ',');
166 format_odp_action(ds, a);
169 if (left == actions_len) {
170 ds_put_cstr(ds, "<empty>");
172 ds_put_format(ds, ",***%u leftover bytes***", left);
175 ds_put_cstr(ds, "drop");
179 /* Returns the correct length of the payload for a flow key attribute of the
180 * specified 'type', or -1 if 'type' is unknown. */
182 odp_flow_key_attr_len(uint16_t type)
184 if (type > ODP_KEY_ATTR_MAX) {
188 switch ((enum odp_key_type) type) {
189 case ODP_KEY_ATTR_TUN_ID: return 8;
190 case ODP_KEY_ATTR_IN_PORT: return 4;
191 case ODP_KEY_ATTR_ETHERNET: return sizeof(struct odp_key_ethernet);
192 case ODP_KEY_ATTR_8021Q: return sizeof(struct odp_key_8021q);
193 case ODP_KEY_ATTR_ETHERTYPE: return 2;
194 case ODP_KEY_ATTR_IPV4: return sizeof(struct odp_key_ipv4);
195 case ODP_KEY_ATTR_IPV6: return sizeof(struct odp_key_ipv6);
196 case ODP_KEY_ATTR_TCP: return sizeof(struct odp_key_tcp);
197 case ODP_KEY_ATTR_UDP: return sizeof(struct odp_key_udp);
198 case ODP_KEY_ATTR_ICMP: return sizeof(struct odp_key_icmp);
199 case ODP_KEY_ATTR_ICMPV6: return sizeof(struct odp_key_icmpv6);
200 case ODP_KEY_ATTR_ARP: return sizeof(struct odp_key_arp);
201 case ODP_KEY_ATTR_ND: return sizeof(struct odp_key_nd);
203 case ODP_KEY_ATTR_UNSPEC:
204 case __ODP_KEY_ATTR_MAX:
213 format_generic_odp_key(const struct nlattr *a, struct ds *ds)
215 size_t len = nl_attr_get_size(a);
217 ds_put_format(ds, "key%"PRId16, nl_attr_type(a));
219 const uint8_t *unspec;
222 unspec = nl_attr_get(a);
223 for (i = 0; i < len; i++) {
224 ds_put_char(ds, i ? ' ': '(');
225 ds_put_format(ds, "%02x", unspec[i]);
227 ds_put_char(ds, ')');
232 format_odp_key_attr(const struct nlattr *a, struct ds *ds)
234 const struct odp_key_ethernet *eth_key;
235 const struct odp_key_8021q *q_key;
236 const struct odp_key_ipv4 *ipv4_key;
237 const struct odp_key_ipv6 *ipv6_key;
238 const struct odp_key_tcp *tcp_key;
239 const struct odp_key_udp *udp_key;
240 const struct odp_key_icmp *icmp_key;
241 const struct odp_key_icmpv6 *icmpv6_key;
242 const struct odp_key_arp *arp_key;
243 const struct odp_key_nd *nd_key;
245 if (nl_attr_get_size(a) != odp_flow_key_attr_len(nl_attr_type(a))) {
246 ds_put_format(ds, "bad length %zu, expected %d for: ",
248 odp_flow_key_attr_len(nl_attr_type(a)));
249 format_generic_odp_key(a, ds);
253 switch (nl_attr_type(a)) {
254 case ODP_KEY_ATTR_TUN_ID:
255 ds_put_format(ds, "tun_id(%#"PRIx64")", ntohll(nl_attr_get_be64(a)));
258 case ODP_KEY_ATTR_IN_PORT:
259 ds_put_format(ds, "in_port(%"PRIu32")", nl_attr_get_u32(a));
262 case ODP_KEY_ATTR_ETHERNET:
263 eth_key = nl_attr_get(a);
264 ds_put_format(ds, "eth(src="ETH_ADDR_FMT",dst="ETH_ADDR_FMT")",
265 ETH_ADDR_ARGS(eth_key->eth_src),
266 ETH_ADDR_ARGS(eth_key->eth_dst));
269 case ODP_KEY_ATTR_8021Q:
270 q_key = nl_attr_get(a);
271 ds_put_cstr(ds, "vlan(");
272 if (q_key->q_tpid != htons(ETH_TYPE_VLAN)) {
273 ds_put_format(ds, "tpid=0x%04"PRIx16",", ntohs(q_key->q_tpid));
275 ds_put_format(ds, "vid%"PRIu16",pcp%d)",
276 vlan_tci_to_vid(q_key->q_tci),
277 vlan_tci_to_pcp(q_key->q_tci));
280 case ODP_KEY_ATTR_ETHERTYPE:
281 ds_put_format(ds, "eth_type(0x%04"PRIx16")",
282 ntohs(nl_attr_get_be16(a)));
285 case ODP_KEY_ATTR_IPV4:
286 ipv4_key = nl_attr_get(a);
287 ds_put_format(ds, "ipv4(src="IP_FMT",dst="IP_FMT","
288 "proto=%"PRId8",tos=%"PRIu8")",
289 IP_ARGS(&ipv4_key->ipv4_src),
290 IP_ARGS(&ipv4_key->ipv4_dst),
291 ipv4_key->ipv4_proto, ipv4_key->ipv4_tos);
294 case ODP_KEY_ATTR_IPV6: {
295 char src_str[INET6_ADDRSTRLEN];
296 char dst_str[INET6_ADDRSTRLEN];
298 ipv6_key = nl_attr_get(a);
299 inet_ntop(AF_INET6, ipv6_key->ipv6_src, src_str, sizeof src_str);
300 inet_ntop(AF_INET6, ipv6_key->ipv6_dst, dst_str, sizeof dst_str);
302 ds_put_format(ds, "ipv6(src=%s,dst=%s,proto=%"PRId8",tos=%"PRIu8")",
303 src_str, dst_str, ipv6_key->ipv6_proto,
308 case ODP_KEY_ATTR_TCP:
309 tcp_key = nl_attr_get(a);
310 ds_put_format(ds, "tcp(src=%"PRIu16",dst=%"PRIu16")",
311 ntohs(tcp_key->tcp_src), ntohs(tcp_key->tcp_dst));
314 case ODP_KEY_ATTR_UDP:
315 udp_key = nl_attr_get(a);
316 ds_put_format(ds, "udp(src=%"PRIu16",dst=%"PRIu16")",
317 ntohs(udp_key->udp_src), ntohs(udp_key->udp_dst));
320 case ODP_KEY_ATTR_ICMP:
321 icmp_key = nl_attr_get(a);
322 ds_put_format(ds, "icmp(type=%"PRIu8",code=%"PRIu8")",
323 icmp_key->icmp_type, icmp_key->icmp_code);
326 case ODP_KEY_ATTR_ICMPV6:
327 icmpv6_key = nl_attr_get(a);
328 ds_put_format(ds, "icmpv6(type=%"PRIu8",code=%"PRIu8")",
329 icmpv6_key->icmpv6_type, icmpv6_key->icmpv6_code);
332 case ODP_KEY_ATTR_ARP:
333 arp_key = nl_attr_get(a);
334 ds_put_format(ds, "arp(sip="IP_FMT",tip="IP_FMT",op=%"PRIu16","
335 "sha="ETH_ADDR_FMT",tha="ETH_ADDR_FMT")",
336 IP_ARGS(&arp_key->arp_sip), IP_ARGS(&arp_key->arp_tip),
337 ntohs(arp_key->arp_op), ETH_ADDR_ARGS(arp_key->arp_sha),
338 ETH_ADDR_ARGS(arp_key->arp_tha));
341 case ODP_KEY_ATTR_ND: {
342 char target[INET6_ADDRSTRLEN];
344 nd_key = nl_attr_get(a);
345 inet_ntop(AF_INET6, nd_key->nd_target, target, sizeof target);
347 ds_put_format(ds, "nd(target=%s", target);
348 if (!eth_addr_is_zero(nd_key->nd_sll)) {
349 ds_put_format(ds, ",sll="ETH_ADDR_FMT,
350 ETH_ADDR_ARGS(nd_key->nd_sll));
352 if (!eth_addr_is_zero(nd_key->nd_tll)) {
353 ds_put_format(ds, ",tll="ETH_ADDR_FMT,
354 ETH_ADDR_ARGS(nd_key->nd_tll));
356 ds_put_char(ds, ')');
361 format_generic_odp_key(a, ds);
366 /* Appends to 'ds' a string representation of the 'key_len' bytes of
367 * ODP_KEY_ATTR_* attributes in 'key'. */
369 odp_flow_key_format(const struct nlattr *key, size_t key_len, struct ds *ds)
372 const struct nlattr *a;
375 NL_ATTR_FOR_EACH (a, left, key, key_len) {
377 ds_put_char(ds, ',');
379 format_odp_key_attr(a, ds);
382 if (left == key_len) {
383 ds_put_cstr(ds, "<empty>");
385 ds_put_format(ds, ",***%u leftover bytes***", left);
388 ds_put_cstr(ds, "<empty>");
392 /* Appends a representation of 'flow' as ODP_KEY_ATTR_* attributes to 'buf'. */
394 odp_flow_key_from_flow(struct ofpbuf *buf, const struct flow *flow)
396 struct odp_key_ethernet *eth_key;
398 if (flow->tun_id != htonll(0)) {
399 nl_msg_put_be64(buf, ODP_KEY_ATTR_TUN_ID, flow->tun_id);
402 nl_msg_put_u32(buf, ODP_KEY_ATTR_IN_PORT,
403 ofp_port_to_odp_port(flow->in_port));
405 eth_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_ETHERNET,
407 memcpy(eth_key->eth_src, flow->dl_src, ETH_ADDR_LEN);
408 memcpy(eth_key->eth_dst, flow->dl_dst, ETH_ADDR_LEN);
410 if (flow->vlan_tci != htons(0)) {
411 struct odp_key_8021q *q_key;
413 q_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_8021Q,
415 q_key->q_tpid = htons(ETH_TYPE_VLAN);
416 q_key->q_tci = flow->vlan_tci & ~htons(VLAN_CFI);
419 if (ntohs(flow->dl_type) < ETH_TYPE_MIN) {
423 nl_msg_put_be16(buf, ODP_KEY_ATTR_ETHERTYPE, flow->dl_type);
425 if (flow->dl_type == htons(ETH_TYPE_IP)) {
426 struct odp_key_ipv4 *ipv4_key;
428 ipv4_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_IPV4,
430 memset(ipv4_key, 0, sizeof *ipv4_key);
431 ipv4_key->ipv4_src = flow->nw_src;
432 ipv4_key->ipv4_dst = flow->nw_dst;
433 ipv4_key->ipv4_proto = flow->nw_proto;
434 ipv4_key->ipv4_tos = flow->nw_tos;
435 } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
436 struct odp_key_ipv6 *ipv6_key;
438 ipv6_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_IPV6,
440 memset(ipv6_key, 0, sizeof *ipv6_key);
441 memcpy(ipv6_key->ipv6_src, &flow->ipv6_src, sizeof ipv6_key->ipv6_src);
442 memcpy(ipv6_key->ipv6_dst, &flow->ipv6_dst, sizeof ipv6_key->ipv6_dst);
443 ipv6_key->ipv6_proto = flow->nw_proto;
444 ipv6_key->ipv6_tos = flow->nw_tos;
445 } else if (flow->dl_type == htons(ETH_TYPE_ARP)) {
446 struct odp_key_arp *arp_key;
448 arp_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_ARP,
450 memset(arp_key, 0, sizeof *arp_key);
451 arp_key->arp_sip = flow->nw_src;
452 arp_key->arp_tip = flow->nw_dst;
453 arp_key->arp_op = htons(flow->nw_proto);
454 memcpy(arp_key->arp_sha, flow->arp_sha, ETH_ADDR_LEN);
455 memcpy(arp_key->arp_tha, flow->arp_tha, ETH_ADDR_LEN);
458 if (flow->dl_type == htons(ETH_TYPE_IP)
459 || flow->dl_type == htons(ETH_TYPE_IPV6)) {
461 if (flow->nw_proto == IPPROTO_TCP) {
462 struct odp_key_tcp *tcp_key;
464 tcp_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_TCP,
466 tcp_key->tcp_src = flow->tp_src;
467 tcp_key->tcp_dst = flow->tp_dst;
468 } else if (flow->nw_proto == IPPROTO_UDP) {
469 struct odp_key_udp *udp_key;
471 udp_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_UDP,
473 udp_key->udp_src = flow->tp_src;
474 udp_key->udp_dst = flow->tp_dst;
475 } else if (flow->dl_type == htons(ETH_TYPE_IP)
476 && flow->nw_proto == IPPROTO_ICMP) {
477 struct odp_key_icmp *icmp_key;
479 icmp_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_ICMP,
481 icmp_key->icmp_type = ntohs(flow->tp_src);
482 icmp_key->icmp_code = ntohs(flow->tp_dst);
483 } else if (flow->dl_type == htons(ETH_TYPE_IPV6)
484 && flow->nw_proto == IPPROTO_ICMPV6) {
485 struct odp_key_icmpv6 *icmpv6_key;
487 icmpv6_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_ICMPV6,
489 icmpv6_key->icmpv6_type = ntohs(flow->tp_src);
490 icmpv6_key->icmpv6_code = ntohs(flow->tp_dst);
492 if (icmpv6_key->icmpv6_type == ND_NEIGHBOR_SOLICIT
493 || icmpv6_key->icmpv6_type == ND_NEIGHBOR_ADVERT) {
494 struct odp_key_nd *nd_key;
496 nd_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_ND,
498 memcpy(nd_key->nd_target, &flow->nd_target,
499 sizeof nd_key->nd_target);
500 memcpy(nd_key->nd_sll, flow->arp_sha, ETH_ADDR_LEN);
501 memcpy(nd_key->nd_tll, flow->arp_tha, ETH_ADDR_LEN);
507 /* Converts the 'key_len' bytes of ODP_KEY_ATTR_* attributes in 'key' to a flow
508 * structure in 'flow'. Returns 0 if successful, otherwise EINVAL. */
510 odp_flow_key_to_flow(const struct nlattr *key, size_t key_len,
513 const struct nlattr *nla;
514 enum odp_key_type prev_type;
517 memset(flow, 0, sizeof *flow);
518 flow->dl_type = htons(FLOW_DL_TYPE_NONE);
520 prev_type = ODP_KEY_ATTR_UNSPEC;
521 NL_ATTR_FOR_EACH (nla, left, key, key_len) {
522 const struct odp_key_ethernet *eth_key;
523 const struct odp_key_8021q *q_key;
524 const struct odp_key_ipv4 *ipv4_key;
525 const struct odp_key_ipv6 *ipv6_key;
526 const struct odp_key_tcp *tcp_key;
527 const struct odp_key_udp *udp_key;
528 const struct odp_key_icmp *icmp_key;
529 const struct odp_key_icmpv6 *icmpv6_key;
530 const struct odp_key_arp *arp_key;
531 const struct odp_key_nd *nd_key;
533 uint16_t type = nl_attr_type(nla);
534 int len = odp_flow_key_attr_len(type);
536 if (nl_attr_get_size(nla) != len && len != -1) {
540 #define TRANSITION(PREV_TYPE, TYPE) (((PREV_TYPE) << 16) | (TYPE))
541 switch (TRANSITION(prev_type, type)) {
542 case TRANSITION(ODP_KEY_ATTR_UNSPEC, ODP_KEY_ATTR_TUN_ID):
543 flow->tun_id = nl_attr_get_be64(nla);
546 case TRANSITION(ODP_KEY_ATTR_UNSPEC, ODP_KEY_ATTR_IN_PORT):
547 case TRANSITION(ODP_KEY_ATTR_TUN_ID, ODP_KEY_ATTR_IN_PORT):
548 if (nl_attr_get_u32(nla) >= UINT16_MAX) {
551 flow->in_port = odp_port_to_ofp_port(nl_attr_get_u32(nla));
554 case TRANSITION(ODP_KEY_ATTR_IN_PORT, ODP_KEY_ATTR_ETHERNET):
555 eth_key = nl_attr_get(nla);
556 memcpy(flow->dl_src, eth_key->eth_src, ETH_ADDR_LEN);
557 memcpy(flow->dl_dst, eth_key->eth_dst, ETH_ADDR_LEN);
560 case TRANSITION(ODP_KEY_ATTR_ETHERNET, ODP_KEY_ATTR_8021Q):
561 q_key = nl_attr_get(nla);
562 if (q_key->q_tpid != htons(ETH_TYPE_VLAN)) {
563 /* Only standard 0x8100 VLANs currently supported. */
566 if (q_key->q_tci & htons(VLAN_CFI)) {
569 flow->vlan_tci = q_key->q_tci | htons(VLAN_CFI);
572 case TRANSITION(ODP_KEY_ATTR_8021Q, ODP_KEY_ATTR_ETHERTYPE):
573 case TRANSITION(ODP_KEY_ATTR_ETHERNET, ODP_KEY_ATTR_ETHERTYPE):
574 flow->dl_type = nl_attr_get_be16(nla);
575 if (ntohs(flow->dl_type) < 1536) {
580 case TRANSITION(ODP_KEY_ATTR_ETHERTYPE, ODP_KEY_ATTR_IPV4):
581 if (flow->dl_type != htons(ETH_TYPE_IP)) {
584 ipv4_key = nl_attr_get(nla);
585 flow->nw_src = ipv4_key->ipv4_src;
586 flow->nw_dst = ipv4_key->ipv4_dst;
587 flow->nw_proto = ipv4_key->ipv4_proto;
588 flow->nw_tos = ipv4_key->ipv4_tos;
589 if (flow->nw_tos & IP_ECN_MASK) {
594 case TRANSITION(ODP_KEY_ATTR_ETHERTYPE, ODP_KEY_ATTR_IPV6):
595 if (flow->dl_type != htons(ETH_TYPE_IPV6)) {
598 ipv6_key = nl_attr_get(nla);
599 memcpy(&flow->ipv6_src, ipv6_key->ipv6_src, sizeof flow->ipv6_src);
600 memcpy(&flow->ipv6_dst, ipv6_key->ipv6_dst, sizeof flow->ipv6_dst);
601 flow->nw_proto = ipv6_key->ipv6_proto;
602 flow->nw_tos = ipv6_key->ipv6_tos;
603 if (flow->nw_tos & IP_ECN_MASK) {
608 case TRANSITION(ODP_KEY_ATTR_IPV4, ODP_KEY_ATTR_TCP):
609 case TRANSITION(ODP_KEY_ATTR_IPV6, ODP_KEY_ATTR_TCP):
610 if (flow->nw_proto != IPPROTO_TCP) {
613 tcp_key = nl_attr_get(nla);
614 flow->tp_src = tcp_key->tcp_src;
615 flow->tp_dst = tcp_key->tcp_dst;
618 case TRANSITION(ODP_KEY_ATTR_IPV4, ODP_KEY_ATTR_UDP):
619 case TRANSITION(ODP_KEY_ATTR_IPV6, ODP_KEY_ATTR_UDP):
620 if (flow->nw_proto != IPPROTO_UDP) {
623 udp_key = nl_attr_get(nla);
624 flow->tp_src = udp_key->udp_src;
625 flow->tp_dst = udp_key->udp_dst;
628 case TRANSITION(ODP_KEY_ATTR_IPV4, ODP_KEY_ATTR_ICMP):
629 if (flow->nw_proto != IPPROTO_ICMP) {
632 icmp_key = nl_attr_get(nla);
633 flow->tp_src = htons(icmp_key->icmp_type);
634 flow->tp_dst = htons(icmp_key->icmp_code);
637 case TRANSITION(ODP_KEY_ATTR_IPV6, ODP_KEY_ATTR_ICMPV6):
638 if (flow->nw_proto != IPPROTO_ICMPV6) {
641 icmpv6_key = nl_attr_get(nla);
642 flow->tp_src = htons(icmpv6_key->icmpv6_type);
643 flow->tp_dst = htons(icmpv6_key->icmpv6_code);
646 case TRANSITION(ODP_KEY_ATTR_ETHERTYPE, ODP_KEY_ATTR_ARP):
647 if (flow->dl_type != htons(ETH_TYPE_ARP)) {
650 arp_key = nl_attr_get(nla);
651 flow->nw_src = arp_key->arp_sip;
652 flow->nw_dst = arp_key->arp_tip;
653 if (arp_key->arp_op & htons(0xff00)) {
656 flow->nw_proto = ntohs(arp_key->arp_op);
657 memcpy(flow->arp_sha, arp_key->arp_sha, ETH_ADDR_LEN);
658 memcpy(flow->arp_tha, arp_key->arp_tha, ETH_ADDR_LEN);
661 case TRANSITION(ODP_KEY_ATTR_ICMPV6, ODP_KEY_ATTR_ND):
662 if (flow->tp_src != htons(ND_NEIGHBOR_SOLICIT)
663 && flow->tp_src != htons(ND_NEIGHBOR_ADVERT)) {
666 nd_key = nl_attr_get(nla);
667 memcpy(&flow->nd_target, nd_key->nd_target, sizeof flow->nd_target);
668 memcpy(flow->arp_sha, nd_key->nd_sll, ETH_ADDR_LEN);
669 memcpy(flow->arp_tha, nd_key->nd_tll, ETH_ADDR_LEN);
673 if (type == ODP_KEY_ATTR_UNSPEC
674 || prev_type == ODP_KEY_ATTR_UNSPEC) {
687 case ODP_KEY_ATTR_UNSPEC:
690 case ODP_KEY_ATTR_TUN_ID:
691 case ODP_KEY_ATTR_IN_PORT:
694 case ODP_KEY_ATTR_ETHERNET:
695 case ODP_KEY_ATTR_8021Q:
698 case ODP_KEY_ATTR_ETHERTYPE:
699 if (flow->dl_type == htons(ETH_TYPE_IP)
700 || flow->dl_type == htons(ETH_TYPE_IPV6)
701 || flow->dl_type == htons(ETH_TYPE_ARP)) {
706 case ODP_KEY_ATTR_IPV4:
707 if (flow->nw_proto == IPPROTO_TCP
708 || flow->nw_proto == IPPROTO_UDP
709 || flow->nw_proto == IPPROTO_ICMP) {
714 case ODP_KEY_ATTR_IPV6:
715 if (flow->nw_proto == IPPROTO_TCP
716 || flow->nw_proto == IPPROTO_UDP
717 || flow->nw_proto == IPPROTO_ICMPV6) {
722 case ODP_KEY_ATTR_ICMPV6:
723 if (flow->icmp_type == htons(ND_NEIGHBOR_SOLICIT)
724 || flow->icmp_type == htons(ND_NEIGHBOR_ADVERT)) {
729 case ODP_KEY_ATTR_TCP:
730 case ODP_KEY_ATTR_UDP:
731 case ODP_KEY_ATTR_ICMP:
732 case ODP_KEY_ATTR_ARP:
733 case ODP_KEY_ATTR_ND:
736 case __ODP_KEY_ATTR_MAX: