1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
8 #include <rte_common.h>
9 #include <rte_byteorder.h>
10 #include <rte_malloc.h>
11 #include <rte_string_fns.h>
13 #include <rte_flow_driver.h>
14 #include <rte_tailq.h>
16 #include "rte_eth_softnic_internals.h"
17 #include "rte_eth_softnic.h"
19 #define rte_htons rte_cpu_to_be_16
20 #define rte_htonl rte_cpu_to_be_32
22 #define rte_ntohs rte_be_to_cpu_16
23 #define rte_ntohl rte_be_to_cpu_32
25 static struct rte_flow *
26 softnic_flow_find(struct softnic_table *table,
27 struct softnic_table_rule_match *rule_match)
29 struct rte_flow *flow;
31 TAILQ_FOREACH(flow, &table->flows, node)
32 if (memcmp(&flow->match, rule_match, sizeof(*rule_match)) == 0)
39 flow_attr_map_set(struct pmd_internals *softnic,
42 const char *pipeline_name,
45 struct pipeline *pipeline;
46 struct flow_attr_map *map;
48 if (group_id >= SOFTNIC_FLOW_MAX_GROUPS ||
49 pipeline_name == NULL)
52 pipeline = softnic_pipeline_find(softnic, pipeline_name);
53 if (pipeline == NULL ||
54 table_id >= pipeline->n_tables)
57 map = (ingress) ? &softnic->flow.ingress_map[group_id] :
58 &softnic->flow.egress_map[group_id];
59 strlcpy(map->pipeline_name, pipeline_name, sizeof(map->pipeline_name));
60 map->table_id = table_id;
66 struct flow_attr_map *
67 flow_attr_map_get(struct pmd_internals *softnic,
71 if (group_id >= SOFTNIC_FLOW_MAX_GROUPS)
74 return (ingress) ? &softnic->flow.ingress_map[group_id] :
75 &softnic->flow.egress_map[group_id];
79 flow_pipeline_table_get(struct pmd_internals *softnic,
80 const struct rte_flow_attr *attr,
81 const char **pipeline_name,
83 struct rte_flow_error *error)
85 struct flow_attr_map *map;
88 return rte_flow_error_set(error,
90 RTE_FLOW_ERROR_TYPE_ATTR,
94 if (!attr->ingress && !attr->egress)
95 return rte_flow_error_set(error,
97 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
99 "Ingress/egress not specified");
101 if (attr->ingress && attr->egress)
102 return rte_flow_error_set(error,
104 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
106 "Setting both ingress and egress is not allowed");
108 map = flow_attr_map_get(softnic,
113 return rte_flow_error_set(error,
115 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
120 *pipeline_name = map->pipeline_name;
123 *table_id = map->table_id;
129 uint8_t raw[TABLE_RULE_MATCH_SIZE_MAX];
130 struct rte_flow_item_eth eth;
131 struct rte_flow_item_vlan vlan;
132 struct rte_flow_item_ipv4 ipv4;
133 struct rte_flow_item_ipv6 ipv6;
134 struct rte_flow_item_icmp icmp;
135 struct rte_flow_item_udp udp;
136 struct rte_flow_item_tcp tcp;
137 struct rte_flow_item_sctp sctp;
138 struct rte_flow_item_vxlan vxlan;
139 struct rte_flow_item_e_tag e_tag;
140 struct rte_flow_item_nvgre nvgre;
141 struct rte_flow_item_mpls mpls;
142 struct rte_flow_item_gre gre;
143 struct rte_flow_item_gtp gtp;
144 struct rte_flow_item_esp esp;
145 struct rte_flow_item_geneve geneve;
146 struct rte_flow_item_vxlan_gpe vxlan_gpe;
147 struct rte_flow_item_arp_eth_ipv4 arp_eth_ipv4;
148 struct rte_flow_item_ipv6_ext ipv6_ext;
149 struct rte_flow_item_icmp6 icmp6;
150 struct rte_flow_item_icmp6_nd_ns icmp6_nd_ns;
151 struct rte_flow_item_icmp6_nd_na icmp6_nd_na;
152 struct rte_flow_item_icmp6_nd_opt icmp6_nd_opt;
153 struct rte_flow_item_icmp6_nd_opt_sla_eth icmp6_nd_opt_sla_eth;
154 struct rte_flow_item_icmp6_nd_opt_tla_eth icmp6_nd_opt_tla_eth;
157 static const union flow_item flow_item_raw_mask;
160 flow_item_is_proto(enum rte_flow_item_type type,
165 case RTE_FLOW_ITEM_TYPE_RAW:
166 *mask = &flow_item_raw_mask;
167 *size = sizeof(flow_item_raw_mask);
170 case RTE_FLOW_ITEM_TYPE_ETH:
171 *mask = &rte_flow_item_eth_mask;
172 *size = sizeof(struct rte_ether_hdr);
175 case RTE_FLOW_ITEM_TYPE_VLAN:
176 *mask = &rte_flow_item_vlan_mask;
177 *size = sizeof(struct rte_vlan_hdr);
180 case RTE_FLOW_ITEM_TYPE_IPV4:
181 *mask = &rte_flow_item_ipv4_mask;
182 *size = sizeof(struct rte_ipv4_hdr);
185 case RTE_FLOW_ITEM_TYPE_IPV6:
186 *mask = &rte_flow_item_ipv6_mask;
187 *size = sizeof(struct rte_ipv6_hdr);
190 case RTE_FLOW_ITEM_TYPE_ICMP:
191 *mask = &rte_flow_item_icmp_mask;
192 *size = sizeof(struct rte_flow_item_icmp);
195 case RTE_FLOW_ITEM_TYPE_UDP:
196 *mask = &rte_flow_item_udp_mask;
197 *size = sizeof(struct rte_flow_item_udp);
200 case RTE_FLOW_ITEM_TYPE_TCP:
201 *mask = &rte_flow_item_tcp_mask;
202 *size = sizeof(struct rte_flow_item_tcp);
205 case RTE_FLOW_ITEM_TYPE_SCTP:
206 *mask = &rte_flow_item_sctp_mask;
207 *size = sizeof(struct rte_flow_item_sctp);
210 case RTE_FLOW_ITEM_TYPE_VXLAN:
211 *mask = &rte_flow_item_vxlan_mask;
212 *size = sizeof(struct rte_flow_item_vxlan);
215 case RTE_FLOW_ITEM_TYPE_E_TAG:
216 *mask = &rte_flow_item_e_tag_mask;
217 *size = sizeof(struct rte_flow_item_e_tag);
220 case RTE_FLOW_ITEM_TYPE_NVGRE:
221 *mask = &rte_flow_item_nvgre_mask;
222 *size = sizeof(struct rte_flow_item_nvgre);
225 case RTE_FLOW_ITEM_TYPE_MPLS:
226 *mask = &rte_flow_item_mpls_mask;
227 *size = sizeof(struct rte_flow_item_mpls);
230 case RTE_FLOW_ITEM_TYPE_GRE:
231 *mask = &rte_flow_item_gre_mask;
232 *size = sizeof(struct rte_flow_item_gre);
235 case RTE_FLOW_ITEM_TYPE_GTP:
236 case RTE_FLOW_ITEM_TYPE_GTPC:
237 case RTE_FLOW_ITEM_TYPE_GTPU:
238 *mask = &rte_flow_item_gtp_mask;
239 *size = sizeof(struct rte_flow_item_gtp);
242 case RTE_FLOW_ITEM_TYPE_ESP:
243 *mask = &rte_flow_item_esp_mask;
244 *size = sizeof(struct rte_flow_item_esp);
247 case RTE_FLOW_ITEM_TYPE_GENEVE:
248 *mask = &rte_flow_item_geneve_mask;
249 *size = sizeof(struct rte_flow_item_geneve);
252 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
253 *mask = &rte_flow_item_vxlan_gpe_mask;
254 *size = sizeof(struct rte_flow_item_vxlan_gpe);
257 case RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4:
258 *mask = &rte_flow_item_arp_eth_ipv4_mask;
259 *size = sizeof(struct rte_flow_item_arp_eth_ipv4);
262 case RTE_FLOW_ITEM_TYPE_IPV6_EXT:
263 *mask = &rte_flow_item_ipv6_ext_mask;
264 *size = sizeof(struct rte_flow_item_ipv6_ext);
267 case RTE_FLOW_ITEM_TYPE_ICMP6:
268 *mask = &rte_flow_item_icmp6_mask;
269 *size = sizeof(struct rte_flow_item_icmp6);
272 case RTE_FLOW_ITEM_TYPE_ICMP6_ND_NS:
273 *mask = &rte_flow_item_icmp6_nd_ns_mask;
274 *size = sizeof(struct rte_flow_item_icmp6_nd_ns);
277 case RTE_FLOW_ITEM_TYPE_ICMP6_ND_NA:
278 *mask = &rte_flow_item_icmp6_nd_na_mask;
279 *size = sizeof(struct rte_flow_item_icmp6_nd_na);
282 case RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT:
283 *mask = &rte_flow_item_icmp6_nd_opt_mask;
284 *size = sizeof(struct rte_flow_item_icmp6_nd_opt);
287 case RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_SLA_ETH:
288 *mask = &rte_flow_item_icmp6_nd_opt_sla_eth_mask;
289 *size = sizeof(struct rte_flow_item_icmp6_nd_opt_sla_eth);
292 case RTE_FLOW_ITEM_TYPE_ICMP6_ND_OPT_TLA_ETH:
293 *mask = &rte_flow_item_icmp6_nd_opt_tla_eth_mask;
294 *size = sizeof(struct rte_flow_item_icmp6_nd_opt_tla_eth);
297 default: return 0; /* FALSE */
302 flow_item_raw_preprocess(const struct rte_flow_item *item,
303 union flow_item *item_spec,
304 union flow_item *item_mask,
307 struct rte_flow_error *error)
309 const struct rte_flow_item_raw *item_raw_spec = item->spec;
310 const struct rte_flow_item_raw *item_raw_mask = item->mask;
311 const uint8_t *pattern;
312 const uint8_t *pattern_mask;
313 uint8_t *spec = (uint8_t *)item_spec;
314 uint8_t *mask = (uint8_t *)item_mask;
315 size_t pattern_length, pattern_offset, i;
319 return rte_flow_error_set(error,
321 RTE_FLOW_ERROR_TYPE_ITEM,
323 "RAW: Null specification");
326 return rte_flow_error_set(error,
328 RTE_FLOW_ERROR_TYPE_ITEM,
330 "RAW: Range not allowed (last must be NULL)");
332 if (item_raw_spec->relative == 0)
333 return rte_flow_error_set(error,
335 RTE_FLOW_ERROR_TYPE_ITEM,
337 "RAW: Absolute offset not supported");
339 if (item_raw_spec->search)
340 return rte_flow_error_set(error,
342 RTE_FLOW_ERROR_TYPE_ITEM,
344 "RAW: Search not supported");
346 if (item_raw_spec->offset < 0)
347 return rte_flow_error_set(error,
348 ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
350 "RAW: Negative offset not supported");
352 if (item_raw_spec->length == 0)
353 return rte_flow_error_set(error,
355 RTE_FLOW_ERROR_TYPE_ITEM,
357 "RAW: Zero pattern length");
359 if (item_raw_spec->offset + item_raw_spec->length >
360 TABLE_RULE_MATCH_SIZE_MAX)
361 return rte_flow_error_set(error,
363 RTE_FLOW_ERROR_TYPE_ITEM,
365 "RAW: Item too big");
367 if (!item_raw_spec->pattern && item_raw_mask && item_raw_mask->pattern)
368 return rte_flow_error_set(error,
370 RTE_FLOW_ERROR_TYPE_ITEM,
372 "RAW: Non-NULL pattern mask not allowed with NULL pattern");
374 pattern = item_raw_spec->pattern;
375 pattern_mask = (item_raw_mask) ? item_raw_mask->pattern : NULL;
376 pattern_length = (size_t)item_raw_spec->length;
377 pattern_offset = (size_t)item_raw_spec->offset;
380 if (pattern_mask == NULL)
383 for (i = 0; i < pattern_length; i++)
387 memset(spec, 0, TABLE_RULE_MATCH_SIZE_MAX);
389 memcpy(&spec[pattern_offset], pattern, pattern_length);
391 memset(mask, 0, TABLE_RULE_MATCH_SIZE_MAX);
393 memcpy(&mask[pattern_offset], pattern_mask, pattern_length);
395 *item_size = pattern_offset + pattern_length;
396 *item_disabled = disabled;
402 flow_item_proto_preprocess(const struct rte_flow_item *item,
403 union flow_item *item_spec,
404 union flow_item *item_mask,
407 struct rte_flow_error *error)
409 const void *mask_default;
410 uint8_t *spec = (uint8_t *)item_spec;
411 uint8_t *mask = (uint8_t *)item_mask;
414 if (!flow_item_is_proto(item->type, &mask_default, &size))
415 return rte_flow_error_set(error,
417 RTE_FLOW_ERROR_TYPE_ITEM,
419 "Item type not supported");
421 if (item->type == RTE_FLOW_ITEM_TYPE_RAW)
422 return flow_item_raw_preprocess(item,
431 /* If spec is NULL, then last and mask also have to be NULL. */
432 if (item->last || item->mask)
433 return rte_flow_error_set(error,
435 RTE_FLOW_ERROR_TYPE_ITEM,
437 "Invalid item (NULL spec with non-NULL last or mask)");
439 memset(item_spec, 0, size);
440 memset(item_mask, 0, size);
442 *item_disabled = 1; /* TRUE */
446 memcpy(spec, item->spec, size);
451 memcpy(mask, item->mask, size);
453 memcpy(mask, mask_default, size);
456 for (i = 0; i < size; i++)
459 *item_disabled = (i == size) ? 1 : 0;
461 /* Apply mask over spec. */
462 for (i = 0; i < size; i++)
470 memcpy(last, item->last, size);
471 for (i = 0; i < size; i++)
474 /* check for range */
475 for (i = 0; i < size; i++)
476 if (last[i] != spec[i])
477 return rte_flow_error_set(error,
479 RTE_FLOW_ERROR_TYPE_ITEM,
481 "Range not supported");
488 * Skip disabled protocol items and VOID items
489 * until any of the mutually exclusive conditions
490 * from the list below takes place:
491 * (A) A protocol present in the proto_mask
492 * is met (either ENABLED or DISABLED);
493 * (B) A protocol NOT present in the proto_mask is met in ENABLED state;
494 * (C) The END item is met.
497 flow_item_skip_disabled_protos(const struct rte_flow_item **item,
500 struct rte_flow_error *error)
504 for ( ; (*item)->type != RTE_FLOW_ITEM_TYPE_END; (*item)++) {
505 union flow_item spec, mask;
507 int disabled = 0, status;
509 if ((*item)->type == RTE_FLOW_ITEM_TYPE_VOID)
512 status = flow_item_proto_preprocess(*item,
521 if ((proto_mask & (1LLU << (*item)->type)) ||
534 #define FLOW_ITEM_PROTO_IP \
535 ((1LLU << RTE_FLOW_ITEM_TYPE_IPV4) | \
536 (1LLU << RTE_FLOW_ITEM_TYPE_IPV6))
539 flow_item_skip_void(const struct rte_flow_item **item)
542 if ((*item)->type != RTE_FLOW_ITEM_TYPE_VOID)
546 #define IP_PROTOCOL_TCP 0x06
547 #define IP_PROTOCOL_UDP 0x11
548 #define IP_PROTOCOL_SCTP 0x84
551 mask_to_depth(uint64_t mask,
556 if (mask == UINT64_MAX) {
565 if (mask & (mask + 1))
568 n = __builtin_popcountll(mask);
570 *depth = (uint32_t)(64 - n);
576 ipv4_mask_to_depth(uint32_t mask,
582 status = mask_to_depth(mask | (UINT64_MAX << 32), &d);
594 ipv6_mask_to_depth(uint8_t *mask,
597 uint64_t *m = (uint64_t *)mask;
598 uint64_t m0 = rte_be_to_cpu_64(m[0]);
599 uint64_t m1 = rte_be_to_cpu_64(m[1]);
603 status = mask_to_depth(m0, &d0);
607 status = mask_to_depth(m1, &d1);
621 port_mask_to_range(uint16_t port,
629 status = mask_to_depth(port_mask | (UINT64_MAX << 16), NULL);
633 p0 = port & port_mask;
634 p1 = p0 | ~port_mask;
646 flow_rule_match_acl_get(struct pmd_internals *softnic __rte_unused,
647 struct pipeline *pipeline __rte_unused,
648 struct softnic_table *table __rte_unused,
649 const struct rte_flow_attr *attr,
650 const struct rte_flow_item *item,
651 struct softnic_table_rule_match *rule_match,
652 struct rte_flow_error *error)
654 union flow_item spec, mask;
655 size_t size, length = 0;
656 int disabled = 0, status;
657 uint8_t ip_proto, ip_proto_mask;
659 memset(rule_match, 0, sizeof(*rule_match));
660 rule_match->match_type = TABLE_ACL;
661 rule_match->match.acl.priority = attr->priority;
663 /* VOID or disabled protos only, if any. */
664 status = flow_item_skip_disabled_protos(&item,
665 FLOW_ITEM_PROTO_IP, &length, error);
670 status = flow_item_proto_preprocess(item, &spec, &mask,
671 &size, &disabled, error);
675 switch (item->type) {
676 case RTE_FLOW_ITEM_TYPE_IPV4:
678 uint32_t sa_depth, da_depth;
680 status = ipv4_mask_to_depth(rte_ntohl(mask.ipv4.hdr.src_addr),
683 return rte_flow_error_set(error,
685 RTE_FLOW_ERROR_TYPE_ITEM,
687 "ACL: Illegal IPv4 header source address mask");
689 status = ipv4_mask_to_depth(rte_ntohl(mask.ipv4.hdr.dst_addr),
692 return rte_flow_error_set(error,
694 RTE_FLOW_ERROR_TYPE_ITEM,
696 "ACL: Illegal IPv4 header destination address mask");
698 ip_proto = spec.ipv4.hdr.next_proto_id;
699 ip_proto_mask = mask.ipv4.hdr.next_proto_id;
701 rule_match->match.acl.ip_version = 1;
702 rule_match->match.acl.ipv4.sa =
703 rte_ntohl(spec.ipv4.hdr.src_addr);
704 rule_match->match.acl.ipv4.da =
705 rte_ntohl(spec.ipv4.hdr.dst_addr);
706 rule_match->match.acl.sa_depth = sa_depth;
707 rule_match->match.acl.da_depth = da_depth;
708 rule_match->match.acl.proto = ip_proto;
709 rule_match->match.acl.proto_mask = ip_proto_mask;
711 } /* RTE_FLOW_ITEM_TYPE_IPV4 */
713 case RTE_FLOW_ITEM_TYPE_IPV6:
715 uint32_t sa_depth, da_depth;
717 status = ipv6_mask_to_depth(mask.ipv6.hdr.src_addr, &sa_depth);
719 return rte_flow_error_set(error,
721 RTE_FLOW_ERROR_TYPE_ITEM,
723 "ACL: Illegal IPv6 header source address mask");
725 status = ipv6_mask_to_depth(mask.ipv6.hdr.dst_addr, &da_depth);
727 return rte_flow_error_set(error,
729 RTE_FLOW_ERROR_TYPE_ITEM,
731 "ACL: Illegal IPv6 header destination address mask");
733 ip_proto = spec.ipv6.hdr.proto;
734 ip_proto_mask = mask.ipv6.hdr.proto;
736 rule_match->match.acl.ip_version = 0;
737 memcpy(rule_match->match.acl.ipv6.sa,
738 spec.ipv6.hdr.src_addr,
739 sizeof(spec.ipv6.hdr.src_addr));
740 memcpy(rule_match->match.acl.ipv6.da,
741 spec.ipv6.hdr.dst_addr,
742 sizeof(spec.ipv6.hdr.dst_addr));
743 rule_match->match.acl.sa_depth = sa_depth;
744 rule_match->match.acl.da_depth = da_depth;
745 rule_match->match.acl.proto = ip_proto;
746 rule_match->match.acl.proto_mask = ip_proto_mask;
748 } /* RTE_FLOW_ITEM_TYPE_IPV6 */
751 return rte_flow_error_set(error,
753 RTE_FLOW_ERROR_TYPE_ITEM,
755 "ACL: IP protocol required");
758 if (ip_proto_mask != UINT8_MAX)
759 return rte_flow_error_set(error,
761 RTE_FLOW_ERROR_TYPE_ITEM,
763 "ACL: Illegal IP protocol mask");
767 /* VOID only, if any. */
768 flow_item_skip_void(&item);
770 /* TCP/UDP/SCTP only. */
771 status = flow_item_proto_preprocess(item, &spec, &mask,
772 &size, &disabled, error);
776 switch (item->type) {
777 case RTE_FLOW_ITEM_TYPE_TCP:
779 uint16_t sp0, sp1, dp0, dp1;
781 if (ip_proto != IP_PROTOCOL_TCP)
782 return rte_flow_error_set(error,
784 RTE_FLOW_ERROR_TYPE_ITEM,
786 "ACL: Item type is TCP, but IP protocol is not");
788 status = port_mask_to_range(rte_ntohs(spec.tcp.hdr.src_port),
789 rte_ntohs(mask.tcp.hdr.src_port),
794 return rte_flow_error_set(error,
796 RTE_FLOW_ERROR_TYPE_ITEM,
798 "ACL: Illegal TCP source port mask");
800 status = port_mask_to_range(rte_ntohs(spec.tcp.hdr.dst_port),
801 rte_ntohs(mask.tcp.hdr.dst_port),
806 return rte_flow_error_set(error,
808 RTE_FLOW_ERROR_TYPE_ITEM,
810 "ACL: Illegal TCP destination port mask");
812 rule_match->match.acl.sp0 = sp0;
813 rule_match->match.acl.sp1 = sp1;
814 rule_match->match.acl.dp0 = dp0;
815 rule_match->match.acl.dp1 = dp1;
818 } /* RTE_FLOW_ITEM_TYPE_TCP */
820 case RTE_FLOW_ITEM_TYPE_UDP:
822 uint16_t sp0, sp1, dp0, dp1;
824 if (ip_proto != IP_PROTOCOL_UDP)
825 return rte_flow_error_set(error,
827 RTE_FLOW_ERROR_TYPE_ITEM,
829 "ACL: Item type is UDP, but IP protocol is not");
831 status = port_mask_to_range(rte_ntohs(spec.udp.hdr.src_port),
832 rte_ntohs(mask.udp.hdr.src_port),
836 return rte_flow_error_set(error,
838 RTE_FLOW_ERROR_TYPE_ITEM,
840 "ACL: Illegal UDP source port mask");
842 status = port_mask_to_range(rte_ntohs(spec.udp.hdr.dst_port),
843 rte_ntohs(mask.udp.hdr.dst_port),
847 return rte_flow_error_set(error,
849 RTE_FLOW_ERROR_TYPE_ITEM,
851 "ACL: Illegal UDP destination port mask");
853 rule_match->match.acl.sp0 = sp0;
854 rule_match->match.acl.sp1 = sp1;
855 rule_match->match.acl.dp0 = dp0;
856 rule_match->match.acl.dp1 = dp1;
859 } /* RTE_FLOW_ITEM_TYPE_UDP */
861 case RTE_FLOW_ITEM_TYPE_SCTP:
863 uint16_t sp0, sp1, dp0, dp1;
865 if (ip_proto != IP_PROTOCOL_SCTP)
866 return rte_flow_error_set(error,
868 RTE_FLOW_ERROR_TYPE_ITEM,
870 "ACL: Item type is SCTP, but IP protocol is not");
872 status = port_mask_to_range(rte_ntohs(spec.sctp.hdr.src_port),
873 rte_ntohs(mask.sctp.hdr.src_port),
878 return rte_flow_error_set(error,
880 RTE_FLOW_ERROR_TYPE_ITEM,
882 "ACL: Illegal SCTP source port mask");
884 status = port_mask_to_range(rte_ntohs(spec.sctp.hdr.dst_port),
885 rte_ntohs(mask.sctp.hdr.dst_port),
889 return rte_flow_error_set(error,
891 RTE_FLOW_ERROR_TYPE_ITEM,
893 "ACL: Illegal SCTP destination port mask");
895 rule_match->match.acl.sp0 = sp0;
896 rule_match->match.acl.sp1 = sp1;
897 rule_match->match.acl.dp0 = dp0;
898 rule_match->match.acl.dp1 = dp1;
901 } /* RTE_FLOW_ITEM_TYPE_SCTP */
904 return rte_flow_error_set(error,
906 RTE_FLOW_ERROR_TYPE_ITEM,
908 "ACL: TCP/UDP/SCTP required");
913 /* VOID or disabled protos only, if any. */
914 status = flow_item_skip_disabled_protos(&item, 0, NULL, error);
919 if (item->type != RTE_FLOW_ITEM_TYPE_END)
920 return rte_flow_error_set(error,
922 RTE_FLOW_ERROR_TYPE_ITEM,
924 "ACL: Expecting END item");
930 * Both *tmask* and *fmask* are byte arrays of size *tsize* and *fsize*
932 * They are located within a larger buffer at offsets *toffset* and *foffset*
933 * respectivelly. Both *tmask* and *fmask* represent bitmasks for the larger
935 * Question: are the two masks equivalent?
938 * 1. Offset basically indicates that the first offset bytes in the buffer
939 * are "don't care", so offset is equivalent to pre-pending an "all-zeros"
940 * array of *offset* bytes to the *mask*.
941 * 2. Each *mask* might contain a number of zero bytes at the beginning or
943 * 3. Bytes in the larger buffer after the end of the *mask* are also considered
944 * "don't care", so they are equivalent to appending an "all-zeros" array of
945 * bytes to the *mask*.
948 * Buffer = [xx xx xx xx xx xx xx xx], buffer size = 8 bytes
949 * tmask = [00 22 00 33 00], toffset = 2, tsize = 5
950 * => buffer mask = [00 00 00 22 00 33 00 00]
951 * fmask = [22 00 33], foffset = 3, fsize = 3 =>
952 * => buffer mask = [00 00 00 22 00 33 00 00]
953 * Therefore, the tmask and fmask from this example are equivalent.
956 hash_key_mask_is_same(uint8_t *tmask,
962 size_t *toffset_plus,
963 size_t *foffset_plus)
965 size_t tpos; /* Position of first non-zero byte in the tmask buffer. */
966 size_t fpos; /* Position of first non-zero byte in the fmask buffer. */
968 /* Compute tpos and fpos. */
969 for (tpos = 0; tmask[tpos] == 0; tpos++)
971 for (fpos = 0; fmask[fpos] == 0; fpos++)
974 if (toffset + tpos != foffset + fpos)
975 return 0; /* FALSE */
983 for (i = 0; i < tsize; i++)
984 if (tmask[tpos + i] != fmask[fpos + i])
985 return 0; /* FALSE */
987 for ( ; i < fsize; i++)
989 return 0; /* FALSE */
993 for (i = 0; i < fsize; i++)
994 if (tmask[tpos + i] != fmask[fpos + i])
995 return 0; /* FALSE */
997 for ( ; i < tsize; i++)
999 return 0; /* FALSE */
1003 *toffset_plus = tpos;
1006 *foffset_plus = fpos;
1008 return 1; /* TRUE */
1012 flow_rule_match_hash_get(struct pmd_internals *softnic __rte_unused,
1013 struct pipeline *pipeline __rte_unused,
1014 struct softnic_table *table,
1015 const struct rte_flow_attr *attr __rte_unused,
1016 const struct rte_flow_item *item,
1017 struct softnic_table_rule_match *rule_match,
1018 struct rte_flow_error *error)
1020 struct softnic_table_rule_match_hash key, key_mask;
1021 struct softnic_table_hash_params *params = &table->params.match.hash;
1022 size_t offset = 0, length = 0, tpos, fpos;
1025 memset(&key, 0, sizeof(key));
1026 memset(&key_mask, 0, sizeof(key_mask));
1028 /* VOID or disabled protos only, if any. */
1029 status = flow_item_skip_disabled_protos(&item, 0, &offset, error);
1033 if (item->type == RTE_FLOW_ITEM_TYPE_END)
1034 return rte_flow_error_set(error,
1036 RTE_FLOW_ERROR_TYPE_ITEM,
1038 "HASH: END detected too early");
1040 /* VOID or any protocols (enabled or disabled). */
1041 for ( ; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1042 union flow_item spec, mask;
1044 int disabled, status;
1046 if (item->type == RTE_FLOW_ITEM_TYPE_VOID)
1049 status = flow_item_proto_preprocess(item,
1058 if (length + size > sizeof(key)) {
1062 return rte_flow_error_set(error,
1064 RTE_FLOW_ERROR_TYPE_ITEM,
1066 "HASH: Item too big");
1069 memcpy(&key.key[length], &spec, size);
1070 memcpy(&key_mask.key[length], &mask, size);
1074 if (item->type != RTE_FLOW_ITEM_TYPE_END) {
1075 /* VOID or disabled protos only, if any. */
1076 status = flow_item_skip_disabled_protos(&item, 0, NULL, error);
1081 if (item->type != RTE_FLOW_ITEM_TYPE_END)
1082 return rte_flow_error_set(error,
1084 RTE_FLOW_ERROR_TYPE_ITEM,
1086 "HASH: Expecting END item");
1089 /* Compare flow key mask against table key mask. */
1090 offset += sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM;
1092 if (!hash_key_mask_is_same(params->key_mask,
1100 return rte_flow_error_set(error,
1102 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1104 "HASH: Item list is not observing the match format");
1107 memset(rule_match, 0, sizeof(*rule_match));
1108 rule_match->match_type = TABLE_HASH;
1109 memcpy(&rule_match->match.hash.key[tpos],
1111 RTE_MIN(sizeof(rule_match->match.hash.key) - tpos,
1118 flow_rule_match_get(struct pmd_internals *softnic,
1119 struct pipeline *pipeline,
1120 struct softnic_table *table,
1121 const struct rte_flow_attr *attr,
1122 const struct rte_flow_item *item,
1123 struct softnic_table_rule_match *rule_match,
1124 struct rte_flow_error *error)
1126 switch (table->params.match_type) {
1128 return flow_rule_match_acl_get(softnic,
1139 return flow_rule_match_hash_get(softnic,
1150 return rte_flow_error_set(error,
1152 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1154 "Unsupported pipeline table match type");
1159 flow_rule_action_get(struct pmd_internals *softnic,
1160 struct pipeline *pipeline,
1161 struct softnic_table *table,
1162 const struct rte_flow_attr *attr,
1163 const struct rte_flow_action *action,
1164 struct softnic_table_rule_action *rule_action,
1165 struct rte_flow_error *error)
1167 struct softnic_table_action_profile *profile;
1168 struct softnic_table_action_profile_params *params;
1169 struct softnic_mtr_meter_policy *policy;
1170 int n_jump_queue_rss_drop = 0;
1173 int n_vxlan_decap = 0;
1175 profile = softnic_table_action_profile_find(softnic,
1176 table->params.action_profile_name);
1177 if (profile == NULL)
1178 return rte_flow_error_set(error,
1180 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1182 "JUMP: Table action profile");
1184 params = &profile->params;
1186 for ( ; action->type != RTE_FLOW_ACTION_TYPE_END; action++) {
1187 if (action->type == RTE_FLOW_ACTION_TYPE_VOID)
1190 switch (action->type) {
1191 case RTE_FLOW_ACTION_TYPE_JUMP:
1193 const struct rte_flow_action_jump *conf = action->conf;
1194 struct flow_attr_map *map;
1197 return rte_flow_error_set(error,
1199 RTE_FLOW_ERROR_TYPE_ACTION,
1201 "JUMP: Null configuration");
1203 if (n_jump_queue_rss_drop)
1204 return rte_flow_error_set(error,
1206 RTE_FLOW_ERROR_TYPE_ACTION,
1208 "Only one termination action is"
1209 " allowed per flow");
1211 if ((params->action_mask &
1212 (1LLU << RTE_TABLE_ACTION_FWD)) == 0)
1213 return rte_flow_error_set(error,
1215 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1217 "JUMP action not enabled for this table");
1219 n_jump_queue_rss_drop = 1;
1221 map = flow_attr_map_get(softnic,
1224 if (map == NULL || map->valid == 0)
1225 return rte_flow_error_set(error,
1227 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1229 "JUMP: Invalid group mapping");
1231 if (strcmp(pipeline->name, map->pipeline_name) != 0)
1232 return rte_flow_error_set(error,
1234 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1236 "JUMP: Jump to table in different pipeline");
1238 /* RTE_TABLE_ACTION_FWD */
1239 rule_action->fwd.action = RTE_PIPELINE_ACTION_TABLE;
1240 rule_action->fwd.id = map->table_id;
1241 rule_action->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
1243 } /* RTE_FLOW_ACTION_TYPE_JUMP */
1245 case RTE_FLOW_ACTION_TYPE_QUEUE:
1247 char name[NAME_SIZE];
1248 struct rte_eth_dev *dev;
1249 const struct rte_flow_action_queue *conf = action->conf;
1254 return rte_flow_error_set(error,
1256 RTE_FLOW_ERROR_TYPE_ACTION,
1258 "QUEUE: Null configuration");
1260 if (n_jump_queue_rss_drop)
1261 return rte_flow_error_set(error,
1263 RTE_FLOW_ERROR_TYPE_ACTION,
1265 "Only one termination action is allowed"
1268 if ((params->action_mask &
1269 (1LLU << RTE_TABLE_ACTION_FWD)) == 0)
1270 return rte_flow_error_set(error,
1272 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1274 "QUEUE action not enabled for this table");
1276 n_jump_queue_rss_drop = 1;
1278 dev = ETHDEV(softnic);
1280 conf->index >= dev->data->nb_rx_queues)
1281 return rte_flow_error_set(error,
1283 RTE_FLOW_ERROR_TYPE_ACTION,
1285 "QUEUE: Invalid RX queue ID");
1287 snprintf(name, sizeof(name), "RXQ%u",
1288 (uint32_t)conf->index);
1290 status = softnic_pipeline_port_out_find(softnic,
1295 return rte_flow_error_set(error,
1297 RTE_FLOW_ERROR_TYPE_ACTION,
1299 "QUEUE: RX queue not accessible from this pipeline");
1301 /* RTE_TABLE_ACTION_FWD */
1302 rule_action->fwd.action = RTE_PIPELINE_ACTION_PORT;
1303 rule_action->fwd.id = port_id;
1304 rule_action->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
1306 } /*RTE_FLOW_ACTION_TYPE_QUEUE */
1308 case RTE_FLOW_ACTION_TYPE_RSS:
1310 const struct rte_flow_action_rss *conf = action->conf;
1314 return rte_flow_error_set(error,
1316 RTE_FLOW_ERROR_TYPE_ACTION,
1318 "RSS: Null configuration");
1320 if (!rte_is_power_of_2(conf->queue_num))
1321 return rte_flow_error_set(error,
1323 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1325 "RSS: Number of queues must be a power of 2");
1327 if (conf->queue_num > RTE_DIM(rule_action->lb.out))
1328 return rte_flow_error_set(error,
1330 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1332 "RSS: Number of queues too big");
1334 if (n_jump_queue_rss_drop)
1335 return rte_flow_error_set(error,
1337 RTE_FLOW_ERROR_TYPE_ACTION,
1339 "Only one termination action is allowed per flow");
1341 if (((params->action_mask &
1342 (1LLU << RTE_TABLE_ACTION_FWD)) == 0) ||
1343 ((params->action_mask &
1344 (1LLU << RTE_TABLE_ACTION_LB)) == 0))
1345 return rte_flow_error_set(error,
1347 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1349 "RSS action not supported by this table");
1351 if (params->lb.out_offset !=
1352 pipeline->params.offset_port_id)
1353 return rte_flow_error_set(error,
1355 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1357 "RSS action not supported by this pipeline");
1359 n_jump_queue_rss_drop = 1;
1361 /* RTE_TABLE_ACTION_LB */
1362 for (i = 0; i < conf->queue_num; i++) {
1363 char name[NAME_SIZE];
1364 struct rte_eth_dev *dev;
1368 dev = ETHDEV(softnic);
1371 dev->data->nb_rx_queues)
1372 return rte_flow_error_set(error,
1374 RTE_FLOW_ERROR_TYPE_ACTION,
1376 "RSS: Invalid RX queue ID");
1378 snprintf(name, sizeof(name), "RXQ%u",
1379 (uint32_t)conf->queue[i]);
1381 status = softnic_pipeline_port_out_find(softnic,
1386 return rte_flow_error_set(error,
1388 RTE_FLOW_ERROR_TYPE_ACTION,
1390 "RSS: RX queue not accessible from this pipeline");
1392 rule_action->lb.out[i] = port_id;
1395 for ( ; i < RTE_DIM(rule_action->lb.out); i++)
1396 rule_action->lb.out[i] =
1397 rule_action->lb.out[i % conf->queue_num];
1399 rule_action->action_mask |= 1 << RTE_TABLE_ACTION_LB;
1401 /* RTE_TABLE_ACTION_FWD */
1402 rule_action->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
1403 rule_action->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
1405 } /* RTE_FLOW_ACTION_TYPE_RSS */
1407 case RTE_FLOW_ACTION_TYPE_DROP:
1409 const void *conf = action->conf;
1412 return rte_flow_error_set(error,
1414 RTE_FLOW_ERROR_TYPE_ACTION,
1416 "DROP: No configuration required");
1418 if (n_jump_queue_rss_drop)
1419 return rte_flow_error_set(error,
1421 RTE_FLOW_ERROR_TYPE_ACTION,
1423 "Only one termination action is allowed per flow");
1424 if ((params->action_mask &
1425 (1LLU << RTE_TABLE_ACTION_FWD)) == 0)
1426 return rte_flow_error_set(error,
1428 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1430 "DROP action not supported by this table");
1432 n_jump_queue_rss_drop = 1;
1434 /* RTE_TABLE_ACTION_FWD */
1435 rule_action->fwd.action = RTE_PIPELINE_ACTION_DROP;
1436 rule_action->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
1438 } /* RTE_FLOW_ACTION_TYPE_DROP */
1440 case RTE_FLOW_ACTION_TYPE_COUNT:
1442 const struct rte_flow_action_count *conf = action->conf;
1445 return rte_flow_error_set(error,
1447 RTE_FLOW_ERROR_TYPE_ACTION,
1449 "COUNT: Null configuration");
1452 return rte_flow_error_set(error,
1454 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1456 "COUNT: Shared counters not supported");
1459 return rte_flow_error_set(error,
1461 RTE_FLOW_ERROR_TYPE_ACTION,
1463 "Only one COUNT action per flow");
1465 if ((params->action_mask &
1466 (1LLU << RTE_TABLE_ACTION_STATS)) == 0)
1467 return rte_flow_error_set(error,
1469 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1471 "COUNT action not supported by this table");
1475 /* RTE_TABLE_ACTION_STATS */
1476 rule_action->stats.n_packets = 0;
1477 rule_action->stats.n_bytes = 0;
1478 rule_action->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
1480 } /* RTE_FLOW_ACTION_TYPE_COUNT */
1482 case RTE_FLOW_ACTION_TYPE_MARK:
1484 const struct rte_flow_action_mark *conf = action->conf;
1487 return rte_flow_error_set(error,
1489 RTE_FLOW_ERROR_TYPE_ACTION,
1491 "MARK: Null configuration");
1494 return rte_flow_error_set(error,
1496 RTE_FLOW_ERROR_TYPE_ACTION,
1498 "Only one MARK action per flow");
1500 if ((params->action_mask &
1501 (1LLU << RTE_TABLE_ACTION_TAG)) == 0)
1502 return rte_flow_error_set(error,
1504 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1506 "MARK action not supported by this table");
1510 /* RTE_TABLE_ACTION_TAG */
1511 rule_action->tag.tag = conf->id;
1512 rule_action->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
1514 } /* RTE_FLOW_ACTION_TYPE_MARK */
1516 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
1518 const struct rte_flow_action_mark *conf = action->conf;
1521 return rte_flow_error_set(error,
1523 RTE_FLOW_ERROR_TYPE_ACTION,
1525 "VXLAN DECAP: Non-null configuration");
1528 return rte_flow_error_set(error,
1530 RTE_FLOW_ERROR_TYPE_ACTION,
1532 "Only one VXLAN DECAP action per flow");
1534 if ((params->action_mask &
1535 (1LLU << RTE_TABLE_ACTION_DECAP)) == 0)
1536 return rte_flow_error_set(error,
1538 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1540 "VXLAN DECAP action not supported by this table");
1544 /* RTE_TABLE_ACTION_DECAP */
1545 rule_action->decap.n = 50; /* Ether/IPv4/UDP/VXLAN */
1546 rule_action->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
1548 } /* RTE_FLOW_ACTION_TYPE_VXLAN_DECAP */
1550 case RTE_FLOW_ACTION_TYPE_METER:
1552 const struct rte_flow_action_meter *conf = action->conf;
1553 struct softnic_mtr_meter_profile *mp;
1554 struct softnic_mtr *m;
1555 uint32_t table_id = table - pipeline->table;
1556 uint32_t meter_profile_id;
1559 if ((params->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) == 0)
1560 return rte_flow_error_set(error,
1562 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1564 "METER: Table action not supported");
1566 if (params->mtr.n_tc != 1)
1567 return rte_flow_error_set(error,
1569 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1571 "METER: Multiple TCs not supported");
1574 return rte_flow_error_set(error,
1576 RTE_FLOW_ERROR_TYPE_ACTION,
1578 "METER: Null configuration");
1580 m = softnic_mtr_find(softnic, conf->mtr_id);
1583 return rte_flow_error_set(error,
1585 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1587 "METER: Invalid meter ID");
1590 return rte_flow_error_set(error,
1592 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1594 "METER: Meter already attached to a flow");
1596 meter_profile_id = m->params.meter_profile_id;
1597 mp = softnic_mtr_meter_profile_find(softnic, meter_profile_id);
1599 /* Add meter profile to pipeline table */
1600 if (!softnic_pipeline_table_meter_profile_find(table,
1601 meter_profile_id)) {
1602 struct rte_table_action_meter_profile profile;
1604 memset(&profile, 0, sizeof(profile));
1605 profile.alg = RTE_TABLE_ACTION_METER_TRTCM;
1606 profile.trtcm.cir = mp->params.trtcm_rfc2698.cir;
1607 profile.trtcm.pir = mp->params.trtcm_rfc2698.pir;
1608 profile.trtcm.cbs = mp->params.trtcm_rfc2698.cbs;
1609 profile.trtcm.pbs = mp->params.trtcm_rfc2698.pbs;
1611 status = softnic_pipeline_table_mtr_profile_add(softnic,
1617 rte_flow_error_set(error,
1619 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1621 "METER: Table meter profile add failed");
1625 /* Meter policy must exist */
1626 policy = softnic_mtr_meter_policy_find(softnic,
1627 m->params.meter_policy_id);
1628 if (policy == NULL) {
1629 rte_flow_error_set(error,
1631 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1633 "METER: fail to find meter policy");
1636 /* RTE_TABLE_ACTION_METER */
1637 rule_action->mtr.mtr[0].meter_profile_id = meter_profile_id;
1638 rule_action->mtr.mtr[0].policer[RTE_COLOR_GREEN] =
1639 policy->policer[RTE_COLOR_GREEN];
1640 rule_action->mtr.mtr[0].policer[RTE_COLOR_YELLOW] =
1641 policy->policer[RTE_COLOR_YELLOW];
1642 rule_action->mtr.mtr[0].policer[RTE_COLOR_RED] =
1643 policy->policer[RTE_COLOR_RED];
1644 rule_action->mtr.tc_mask = 1;
1645 rule_action->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
1647 } /* RTE_FLOW_ACTION_TYPE_METER */
1649 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
1651 const struct rte_flow_action_vxlan_encap *conf =
1653 const struct rte_flow_item *item;
1654 union flow_item spec, mask;
1655 int disabled = 0, status;
1659 return rte_flow_error_set(error,
1661 RTE_FLOW_ERROR_TYPE_ACTION,
1663 "VXLAN ENCAP: Null configuration");
1665 item = conf->definition;
1667 return rte_flow_error_set(error,
1669 RTE_FLOW_ERROR_TYPE_ACTION,
1671 "VXLAN ENCAP: Null configuration definition");
1673 if (!(params->action_mask &
1674 (1LLU << RTE_TABLE_ACTION_ENCAP)))
1675 return rte_flow_error_set(error,
1677 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1679 "VXLAN ENCAP: Encap action not enabled for this table");
1681 /* Check for Ether. */
1682 flow_item_skip_void(&item);
1683 status = flow_item_proto_preprocess(item, &spec, &mask,
1684 &size, &disabled, error);
1688 if (item->type != RTE_FLOW_ITEM_TYPE_ETH) {
1689 return rte_flow_error_set(error,
1691 RTE_FLOW_ERROR_TYPE_ITEM,
1693 "VXLAN ENCAP: first encap item should be ether");
1695 rte_ether_addr_copy(&spec.eth.dst,
1696 &rule_action->encap.vxlan.ether.da);
1697 rte_ether_addr_copy(&spec.eth.src,
1698 &rule_action->encap.vxlan.ether.sa);
1702 /* Check for VLAN. */
1703 flow_item_skip_void(&item);
1704 status = flow_item_proto_preprocess(item, &spec, &mask,
1705 &size, &disabled, error);
1709 if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
1710 if (!params->encap.vxlan.vlan)
1711 return rte_flow_error_set(error,
1713 RTE_FLOW_ERROR_TYPE_ITEM,
1715 "VXLAN ENCAP: vlan encap not supported by table");
1717 uint16_t tci = rte_ntohs(spec.vlan.tci);
1718 rule_action->encap.vxlan.vlan.pcp =
1720 rule_action->encap.vxlan.vlan.dei =
1722 rule_action->encap.vxlan.vlan.vid =
1727 flow_item_skip_void(&item);
1728 status = flow_item_proto_preprocess(item, &spec,
1729 &mask, &size, &disabled, error);
1733 if (params->encap.vxlan.vlan)
1734 return rte_flow_error_set(error,
1736 RTE_FLOW_ERROR_TYPE_ITEM,
1738 "VXLAN ENCAP: expecting vlan encap item");
1741 /* Check for IPV4/IPV6. */
1742 switch (item->type) {
1743 case RTE_FLOW_ITEM_TYPE_IPV4:
1745 rule_action->encap.vxlan.ipv4.sa =
1746 rte_ntohl(spec.ipv4.hdr.src_addr);
1747 rule_action->encap.vxlan.ipv4.da =
1748 rte_ntohl(spec.ipv4.hdr.dst_addr);
1749 rule_action->encap.vxlan.ipv4.dscp =
1750 spec.ipv4.hdr.type_of_service >> 2;
1751 rule_action->encap.vxlan.ipv4.ttl =
1752 spec.ipv4.hdr.time_to_live;
1755 case RTE_FLOW_ITEM_TYPE_IPV6:
1759 memcpy(&rule_action->encap.vxlan.ipv6.sa,
1760 &spec.ipv6.hdr.src_addr,
1761 sizeof(spec.ipv6.hdr.src_addr));
1762 memcpy(&rule_action->encap.vxlan.ipv6.da,
1763 &spec.ipv6.hdr.dst_addr,
1764 sizeof(spec.ipv6.hdr.dst_addr));
1765 vtc_flow = rte_ntohl(spec.ipv6.hdr.vtc_flow);
1766 rule_action->encap.vxlan.ipv6.flow_label =
1768 rule_action->encap.vxlan.ipv6.dscp =
1769 (vtc_flow >> 22) & 0x3f;
1770 rule_action->encap.vxlan.ipv6.hop_limit =
1771 spec.ipv6.hdr.hop_limits;
1775 return rte_flow_error_set(error,
1777 RTE_FLOW_ERROR_TYPE_ITEM,
1779 "VXLAN ENCAP: encap item after ether should be ipv4/ipv6");
1784 /* Check for UDP. */
1785 flow_item_skip_void(&item);
1786 status = flow_item_proto_preprocess(item, &spec, &mask,
1787 &size, &disabled, error);
1791 if (item->type != RTE_FLOW_ITEM_TYPE_UDP) {
1792 return rte_flow_error_set(error,
1794 RTE_FLOW_ERROR_TYPE_ITEM,
1796 "VXLAN ENCAP: encap item after ipv4/ipv6 should be udp");
1798 rule_action->encap.vxlan.udp.sp =
1799 rte_ntohs(spec.udp.hdr.src_port);
1800 rule_action->encap.vxlan.udp.dp =
1801 rte_ntohs(spec.udp.hdr.dst_port);
1805 /* Check for VXLAN. */
1806 flow_item_skip_void(&item);
1807 status = flow_item_proto_preprocess(item, &spec, &mask,
1808 &size, &disabled, error);
1812 if (item->type != RTE_FLOW_ITEM_TYPE_VXLAN) {
1813 return rte_flow_error_set(error,
1815 RTE_FLOW_ERROR_TYPE_ITEM,
1817 "VXLAN ENCAP: encap item after udp should be vxlan");
1819 rule_action->encap.vxlan.vxlan.vni =
1820 (spec.vxlan.vni[0] << 16U |
1821 spec.vxlan.vni[1] << 8U
1822 | spec.vxlan.vni[2]);
1826 /* Check for END. */
1827 flow_item_skip_void(&item);
1829 if (item->type != RTE_FLOW_ITEM_TYPE_END)
1830 return rte_flow_error_set(error,
1832 RTE_FLOW_ERROR_TYPE_ITEM,
1834 "VXLAN ENCAP: expecting END item");
1836 rule_action->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
1837 rule_action->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
1839 } /* RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP */
1846 if (n_jump_queue_rss_drop == 0)
1847 return rte_flow_error_set(error,
1849 RTE_FLOW_ERROR_TYPE_ACTION,
1851 "Flow does not have any terminating action");
1857 pmd_flow_validate(struct rte_eth_dev *dev,
1858 const struct rte_flow_attr *attr,
1859 const struct rte_flow_item item[],
1860 const struct rte_flow_action action[],
1861 struct rte_flow_error *error)
1863 struct softnic_table_rule_match rule_match;
1864 struct softnic_table_rule_action rule_action;
1866 struct pmd_internals *softnic = dev->data->dev_private;
1867 struct pipeline *pipeline;
1868 struct softnic_table *table;
1869 const char *pipeline_name = NULL;
1870 uint32_t table_id = 0;
1873 /* Check input parameters. */
1875 return rte_flow_error_set(error,
1877 RTE_FLOW_ERROR_TYPE_ATTR,
1881 return rte_flow_error_set(error,
1883 RTE_FLOW_ERROR_TYPE_ITEM,
1888 return rte_flow_error_set(error,
1890 RTE_FLOW_ERROR_TYPE_ACTION,
1894 /* Identify the pipeline table to add this flow to. */
1895 status = flow_pipeline_table_get(softnic, attr, &pipeline_name,
1900 pipeline = softnic_pipeline_find(softnic, pipeline_name);
1901 if (pipeline == NULL)
1902 return rte_flow_error_set(error,
1904 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1906 "Invalid pipeline name");
1908 if (table_id >= pipeline->n_tables)
1909 return rte_flow_error_set(error,
1911 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1913 "Invalid pipeline table ID");
1915 table = &pipeline->table[table_id];
1918 memset(&rule_match, 0, sizeof(rule_match));
1919 status = flow_rule_match_get(softnic,
1930 memset(&rule_action, 0, sizeof(rule_action));
1931 status = flow_rule_action_get(softnic,
1944 static struct softnic_mtr *
1945 flow_action_meter_get(struct pmd_internals *softnic,
1946 const struct rte_flow_action *action)
1948 for ( ; action->type != RTE_FLOW_ACTION_TYPE_END; action++)
1949 if (action->type == RTE_FLOW_ACTION_TYPE_METER) {
1950 const struct rte_flow_action_meter *conf = action->conf;
1955 return softnic_mtr_find(softnic, conf->mtr_id);
1962 flow_meter_owner_reset(struct pmd_internals *softnic,
1963 struct rte_flow *flow)
1965 struct softnic_mtr_list *ml = &softnic->mtr.mtrs;
1966 struct softnic_mtr *m;
1968 TAILQ_FOREACH(m, ml, node)
1969 if (m->flow == flow) {
1976 flow_meter_owner_set(struct pmd_internals *softnic,
1977 struct rte_flow *flow,
1978 struct softnic_mtr *mtr)
1980 /* Reset current flow meter */
1981 flow_meter_owner_reset(softnic, flow);
1983 /* Set new flow meter */
1988 is_meter_action_enable(struct pmd_internals *softnic,
1989 struct softnic_table *table)
1991 struct softnic_table_action_profile *profile =
1992 softnic_table_action_profile_find(softnic,
1993 table->params.action_profile_name);
1994 struct softnic_table_action_profile_params *params = &profile->params;
1996 return (params->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) ? 1 : 0;
1999 static struct rte_flow *
2000 pmd_flow_create(struct rte_eth_dev *dev,
2001 const struct rte_flow_attr *attr,
2002 const struct rte_flow_item item[],
2003 const struct rte_flow_action action[],
2004 struct rte_flow_error *error)
2006 struct softnic_table_rule_match rule_match;
2007 struct softnic_table_rule_action rule_action;
2010 struct pmd_internals *softnic = dev->data->dev_private;
2011 struct pipeline *pipeline;
2012 struct softnic_table *table;
2013 struct rte_flow *flow;
2014 struct softnic_mtr *mtr;
2015 const char *pipeline_name = NULL;
2016 uint32_t table_id = 0;
2017 int new_flow, status;
2019 /* Check input parameters. */
2021 rte_flow_error_set(error,
2023 RTE_FLOW_ERROR_TYPE_ATTR,
2030 rte_flow_error_set(error,
2032 RTE_FLOW_ERROR_TYPE_ITEM,
2038 if (action == NULL) {
2039 rte_flow_error_set(error,
2041 RTE_FLOW_ERROR_TYPE_ACTION,
2047 /* Identify the pipeline table to add this flow to. */
2048 status = flow_pipeline_table_get(softnic, attr, &pipeline_name,
2053 pipeline = softnic_pipeline_find(softnic, pipeline_name);
2054 if (pipeline == NULL) {
2055 rte_flow_error_set(error,
2057 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2059 "Invalid pipeline name");
2063 if (table_id >= pipeline->n_tables) {
2064 rte_flow_error_set(error,
2066 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2068 "Invalid pipeline table ID");
2072 table = &pipeline->table[table_id];
2075 memset(&rule_match, 0, sizeof(rule_match));
2076 status = flow_rule_match_get(softnic,
2087 memset(&rule_action, 0, sizeof(rule_action));
2088 status = flow_rule_action_get(softnic,
2098 /* Flow find/allocate. */
2100 flow = softnic_flow_find(table, &rule_match);
2103 flow = calloc(1, sizeof(struct rte_flow));
2105 rte_flow_error_set(error,
2107 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2109 "Not enough memory for new flow");
2115 status = softnic_pipeline_table_rule_add(softnic,
2125 rte_flow_error_set(error,
2127 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2129 "Pipeline table rule add failed");
2134 memcpy(&flow->match, &rule_match, sizeof(rule_match));
2135 memcpy(&flow->action, &rule_action, sizeof(rule_action));
2136 flow->data = rule_data;
2137 flow->pipeline = pipeline;
2138 flow->table_id = table_id;
2140 mtr = flow_action_meter_get(softnic, action);
2142 flow_meter_owner_set(softnic, flow, mtr);
2144 /* Flow add to list. */
2146 TAILQ_INSERT_TAIL(&table->flows, flow, node);
2152 pmd_flow_destroy(struct rte_eth_dev *dev,
2153 struct rte_flow *flow,
2154 struct rte_flow_error *error)
2156 struct pmd_internals *softnic = dev->data->dev_private;
2157 struct softnic_table *table;
2160 /* Check input parameters. */
2162 return rte_flow_error_set(error,
2164 RTE_FLOW_ERROR_TYPE_HANDLE,
2168 table = &flow->pipeline->table[flow->table_id];
2171 status = softnic_pipeline_table_rule_delete(softnic,
2172 flow->pipeline->name,
2176 return rte_flow_error_set(error,
2178 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2180 "Pipeline table rule delete failed");
2182 /* Update dependencies */
2183 if (is_meter_action_enable(softnic, table))
2184 flow_meter_owner_reset(softnic, flow);
2187 TAILQ_REMOVE(&table->flows, flow, node);
2194 pmd_flow_flush(struct rte_eth_dev *dev,
2195 struct rte_flow_error *error)
2197 struct pmd_internals *softnic = dev->data->dev_private;
2198 struct pipeline *pipeline;
2199 int fail_to_del_rule = 0;
2202 TAILQ_FOREACH(pipeline, &softnic->pipeline_list, node) {
2203 /* Remove all the flows added to the tables. */
2204 for (i = 0; i < pipeline->n_tables; i++) {
2205 struct softnic_table *table = &pipeline->table[i];
2206 struct rte_flow *flow;
2210 TAILQ_FOREACH_SAFE(flow, &table->flows, node, temp) {
2212 status = softnic_pipeline_table_rule_delete
2218 fail_to_del_rule = 1;
2219 /* Update dependencies */
2220 if (is_meter_action_enable(softnic, table))
2221 flow_meter_owner_reset(softnic, flow);
2224 TAILQ_REMOVE(&table->flows, flow, node);
2230 if (fail_to_del_rule)
2231 return rte_flow_error_set(error,
2233 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2235 "Some of the rules could not be deleted");
2241 pmd_flow_query(struct rte_eth_dev *dev __rte_unused,
2242 struct rte_flow *flow,
2243 const struct rte_flow_action *action __rte_unused,
2245 struct rte_flow_error *error)
2247 struct rte_table_action_stats_counters stats;
2248 struct softnic_table *table;
2249 struct rte_flow_query_count *flow_stats = data;
2252 /* Check input parameters. */
2254 return rte_flow_error_set(error,
2256 RTE_FLOW_ERROR_TYPE_HANDLE,
2261 return rte_flow_error_set(error,
2263 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2267 table = &flow->pipeline->table[flow->table_id];
2269 /* Rule stats read. */
2270 status = rte_table_action_stats_read(table->a,
2275 return rte_flow_error_set(error,
2277 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2279 "Pipeline table rule stats read failed");
2281 /* Fill in flow stats. */
2282 flow_stats->hits_set =
2283 (table->ap->params.stats.n_packets_enabled) ? 1 : 0;
2284 flow_stats->bytes_set =
2285 (table->ap->params.stats.n_bytes_enabled) ? 1 : 0;
2286 flow_stats->hits = stats.n_packets;
2287 flow_stats->bytes = stats.n_bytes;
2292 const struct rte_flow_ops pmd_flow_ops = {
2293 .validate = pmd_flow_validate,
2294 .create = pmd_flow_create,
2295 .destroy = pmd_flow_destroy,
2296 .flush = pmd_flow_flush,
2297 .query = pmd_flow_query,