From 3a1c3cd01b8bce9203e96520f2715b7fd8d93f02 Mon Sep 17 00:00:00 2001 From: Hyong Youb Kim Date: Sat, 2 Mar 2019 02:42:41 -0800 Subject: [PATCH] net/enic: fix SCTP match for flow API The driver needs to explicitly set the protocol number (132) in the IP header pattern, as the current firmware filter API lacks "match SCTP packet" flag. Otherwise, the resulting NIC filter may lead to false positives (i.e. NIC reporting non-SCTP packets as SCTP packets). The flow director handler does the same (enic_clsf.c). Fixes: 6ced137607d0 ("net/enic: flow API for NICs with advanced filters enabled") Cc: stable@dpdk.org Signed-off-by: Hyong Youb Kim Reviewed-by: John Daley --- drivers/net/enic/enic_flow.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/net/enic/enic_flow.c b/drivers/net/enic/enic_flow.c index bb9ed037a5..55d8d50a11 100644 --- a/drivers/net/enic/enic_flow.c +++ b/drivers/net/enic/enic_flow.c @@ -70,7 +70,6 @@ static enic_copy_item_fn enic_copy_item_ipv6_v2; static enic_copy_item_fn enic_copy_item_udp_v2; static enic_copy_item_fn enic_copy_item_tcp_v2; static enic_copy_item_fn enic_copy_item_sctp_v2; -static enic_copy_item_fn enic_copy_item_sctp_v2; static enic_copy_item_fn enic_copy_item_vxlan_v2; static copy_action_fn enic_copy_action_v1; static copy_action_fn enic_copy_action_v2; @@ -237,7 +236,7 @@ static const struct enic_items enic_items_v3[] = { }, [RTE_FLOW_ITEM_TYPE_SCTP] = { .copy_item = enic_copy_item_sctp_v2, - .valid_start_item = 1, + .valid_start_item = 0, .prev_items = (const enum rte_flow_item_type[]) { RTE_FLOW_ITEM_TYPE_IPV4, RTE_FLOW_ITEM_TYPE_IPV6, @@ -819,12 +818,37 @@ enic_copy_item_sctp_v2(const struct rte_flow_item *item, const struct rte_flow_item_sctp *spec = item->spec; const struct rte_flow_item_sctp *mask = item->mask; struct filter_generic_1 *gp = &enic_filter->u.generic_1; + uint8_t *ip_proto_mask = NULL; + uint8_t *ip_proto = NULL; FLOW_TRACE(); if (*inner_ofst) return ENOTSUP; + /* + * The NIC filter API has no flags for "match sctp", so explicitly set + * the protocol number in the IP pattern. + */ + if (gp->val_flags & FILTER_GENERIC_1_IPV4) { + struct ipv4_hdr *ip; + ip = (struct ipv4_hdr *)gp->layer[FILTER_GENERIC_1_L3].mask; + ip_proto_mask = &ip->next_proto_id; + ip = (struct ipv4_hdr *)gp->layer[FILTER_GENERIC_1_L3].val; + ip_proto = &ip->next_proto_id; + } else if (gp->val_flags & FILTER_GENERIC_1_IPV6) { + struct ipv6_hdr *ip; + ip = (struct ipv6_hdr *)gp->layer[FILTER_GENERIC_1_L3].mask; + ip_proto_mask = &ip->proto; + ip = (struct ipv6_hdr *)gp->layer[FILTER_GENERIC_1_L3].val; + ip_proto = &ip->proto; + } else { + /* Need IPv4/IPv6 pattern first */ + return EINVAL; + } + *ip_proto = IPPROTO_SCTP; + *ip_proto_mask = 0xff; + /* Match all if no spec */ if (!spec) return 0; -- 2.20.1