From patchwork Thu Feb 8 01:00:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 127235 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1004333ljc; Wed, 7 Feb 2018 17:03:27 -0800 (PST) X-Google-Smtp-Source: AH8x2273EY5/Z/f4GlrQ9KJ8PdeaYiIUuS5uVquy2tn+teMhB0b8ovkMxeNC4SwLdTSo2gA6oJwX X-Received: by 10.55.56.84 with SMTP id f81mr5241377qka.25.1518051807153; Wed, 07 Feb 2018 17:03:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518051807; cv=none; d=google.com; s=arc-20160816; b=nAS9anbP8E31W4vtj1OeYgRxdF+HbDG11kbe1RG3psb2Xi7qxmuiJiUbCGlVI64jNQ CN/gcM9vDD+8DZnmZHO15U350QAezNYTvXg+LzPCgtxtMFjn9NS7yWFBpZCBebNV4iaK 7DnQsfv9gX6GW+/KUvlRipZ/YGpZ3sHn/U9wjvmbxLe4EFBOW3B9eztXUdn9M34uPFDb /u7534kjZlpPDR9XnpWtdRo3kOkFqg9NTuAHHS9YPKiqbZfOeCaFJNVZU4yeqfri3u7j MQb+o7fB97q0B57BdzvjXtFOv3a8fRjXfXfn6hSffyFQN+kM3Wz0C7UvuSpGHgfly6FC wlDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=Q1yNNPhR8NBWgtw0NHQN74/arobPKAbCD8XdeMFssjA=; b=RnCMBXbWAwr6DxeJ01O3LeBizKNdk60PWsxNW9HceHhJ+enkQl36XIk///SSwTF/Cn syntKFdNoioZWFcAq+dtCkaAnxsB/fFawkykTvq9YIPH2vISulW5rOGFfsa57ZMz9h+M NdqFdvntfDg3EF/6mG3BEhH/nDcsmf0dLqaHFJ5+C3h8gpWeyCPckbovFz/+ZSeBUnCe bLwoNc/HdOJDFz9+zqlSG7Xrjgp4SfMBpbMlRlj6sj845YVQfOglSWmhc0lR6gus4bH8 rQGTTzNUMvdB9fz+yoHniaDvL7Dq4xyRojDeZFxxlE+XZ5FL9mqb8lcvcj9Mzc0TNGMZ 8f5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id x4si983485qkl.113.2018.02.07.17.03.26; Wed, 07 Feb 2018 17:03:27 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 8C4BB60953; Thu, 8 Feb 2018 01:03:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2 autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 1C36D61791; Thu, 8 Feb 2018 01:00:35 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 9532A60928; Thu, 8 Feb 2018 01:00:21 +0000 (UTC) Received: from forward100j.mail.yandex.net (forward100j.mail.yandex.net [5.45.198.240]) by lists.linaro.org (Postfix) with ESMTPS id 75E4661769 for ; Thu, 8 Feb 2018 01:00:12 +0000 (UTC) Received: from mxback7j.mail.yandex.net (mxback7j.mail.yandex.net [IPv6:2a02:6b8:0:1619::110]) by forward100j.mail.yandex.net (Yandex) with ESMTP id 7D4005D85EDA for ; Thu, 8 Feb 2018 04:00:11 +0300 (MSK) Received: from smtp2o.mail.yandex.net (smtp2o.mail.yandex.net [2a02:6b8:0:1a2d::26]) by mxback7j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id BHzpcRN3Co-0BjSwQSq; Thu, 08 Feb 2018 04:00:11 +0300 Received: by smtp2o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id dozPKnGPpm-0A1WAvjE; Thu, 08 Feb 2018 04:00:10 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 8 Feb 2018 04:00:07 +0300 Message-Id: <1518051607-20804-5-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518051607-20804-1-git-send-email-odpbot@yandex.ru> References: <1518051607-20804-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 459 Subject: [lng-odp] [PATCH API-NEXT v1 4/4] linux-gen: use packet l4 type rather than individual input flags X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Dmitry Eremin-Solenikov Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 459 (lumag:packet-types-2) ** https://github.com/Linaro/odp/pull/459 ** Patch: https://github.com/Linaro/odp/pull/459.patch ** Base sha: af7be638ef9ac98bdb1f2e4917f152889eb1850f ** Merge commit sha: 714954eb283fbb69b44b8dc12b02f5cfbcf17577 **/ .../include/odp/api/plat/packet_inline_types.h | 7 --- .../include/odp_classification_inlines.h | 15 +++--- .../linux-generic/include/odp_packet_internal.h | 10 ++++ platform/linux-generic/odp_classification.c | 8 +-- platform/linux-generic/odp_packet.c | 11 ++-- platform/linux-generic/odp_packet_flags.c | 60 +++++++++++++++++++--- 6 files changed, 79 insertions(+), 32 deletions(-) diff --git a/platform/linux-generic/include/odp/api/plat/packet_inline_types.h b/platform/linux-generic/include/odp/api/plat/packet_inline_types.h index fb54e6402..008a06bff 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_inline_types.h +++ b/platform/linux-generic/include/odp/api/plat/packet_inline_types.h @@ -80,14 +80,7 @@ typedef union { uint64_t ipsec:1; /* IPSec packet. Required by the odp_packet_has_ipsec_set() func. */ - uint64_t ipsec_ah:1; /* IPSec authentication header */ - uint64_t ipsec_esp:1; /* IPSec encapsulating security - payload */ - uint64_t udp:1; /* UDP */ - uint64_t tcp:1; /* TCP */ uint64_t tcpopt:1; /* TCP options present */ - uint64_t sctp:1; /* SCTP */ - uint64_t icmp:1; /* ICMP */ uint64_t color:2; /* Packet color for traffic mgmt */ uint64_t nodrop:1; /* Drop eligibility status */ diff --git a/platform/linux-generic/include/odp_classification_inlines.h b/platform/linux-generic/include/odp_classification_inlines.h index f9462e976..4d6472355 100644 --- a/platform/linux-generic/include/odp_classification_inlines.h +++ b/platform/linux-generic/include/odp_classification_inlines.h @@ -102,7 +102,8 @@ static inline int verify_pmr_tcp_sport(const uint8_t *pkt_addr, { uint16_t sport; const _odp_tcphdr_t *tcp; - if (!pkt_hdr->p.input_flags.tcp) + + if (!packet_hdr_has_tcp(pkt_hdr)) return 0; tcp = (const _odp_tcphdr_t *)(pkt_addr + pkt_hdr->p.l4_offset); sport = _odp_be_to_cpu_16(tcp->src_port); @@ -118,7 +119,8 @@ static inline int verify_pmr_tcp_dport(const uint8_t *pkt_addr, { uint16_t dport; const _odp_tcphdr_t *tcp; - if (!pkt_hdr->p.input_flags.tcp) + + if (!packet_hdr_has_tcp(pkt_hdr)) return 0; tcp = (const _odp_tcphdr_t *)(pkt_addr + pkt_hdr->p.l4_offset); dport = _odp_be_to_cpu_16(tcp->dst_port); @@ -134,7 +136,8 @@ static inline int verify_pmr_udp_dport(const uint8_t *pkt_addr, { uint16_t dport; const _odp_udphdr_t *udp; - if (!pkt_hdr->p.input_flags.udp) + + if (!packet_hdr_has_udp(pkt_hdr)) return 0; udp = (const _odp_udphdr_t *)(pkt_addr + pkt_hdr->p.l4_offset); dport = _odp_be_to_cpu_16(udp->dst_port); @@ -151,7 +154,7 @@ static inline int verify_pmr_udp_sport(const uint8_t *pkt_addr, uint16_t sport; const _odp_udphdr_t *udp; - if (!pkt_hdr->p.input_flags.udp) + if (!packet_hdr_has_udp(pkt_hdr)) return 0; udp = (const _odp_udphdr_t *)(pkt_addr + pkt_hdr->p.l4_offset); sport = _odp_be_to_cpu_16(udp->src_port); @@ -291,11 +294,11 @@ static inline int verify_pmr_ipsec_spi(const uint8_t *pkt_addr, pkt_addr += pkt_hdr->p.l4_offset; - if (pkt_hdr->p.input_flags.ipsec_ah) { + if (pkt_hdr->p.input_flags.l4_type == ODP_PROTO_L4_TYPE_AH) { const _odp_ahhdr_t *ahhdr = (const _odp_ahhdr_t *)pkt_addr; spi = _odp_be_to_cpu_32(ahhdr->spi); - } else if (pkt_hdr->p.input_flags.ipsec_esp) { + } else if (pkt_hdr->p.input_flags.l4_type == ODP_PROTO_L4_TYPE_ESP) { const _odp_esphdr_t *esphdr = (const _odp_esphdr_t *)pkt_addr; spi = _odp_be_to_cpu_32(esphdr->spi); diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 59cb9ded9..9ef11c677 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -291,6 +291,16 @@ static inline int packet_hdr_has_ipv6(odp_packet_hdr_t *pkt_hdr) return pkt_hdr->p.input_flags.l3_type == ODP_PROTO_L3_TYPE_IPV6; } +static inline int packet_hdr_has_tcp(odp_packet_hdr_t *pkt_hdr) +{ + return pkt_hdr->p.input_flags.l4_type == ODP_PROTO_L4_TYPE_TCP; +} + +static inline int packet_hdr_has_udp(odp_packet_hdr_t *pkt_hdr) +{ + return pkt_hdr->p.input_flags.l4_type == ODP_PROTO_L4_TYPE_UDP; +} + static inline void packet_set_ts(odp_packet_hdr_t *pkt_hdr, odp_time_t *ts) { if (ts != NULL) { diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c index 5147db137..6937ac4b2 100644 --- a/platform/linux-generic/odp_classification.c +++ b/platform/linux-generic/odp_classification.c @@ -1036,14 +1036,14 @@ static uint32_t packet_rss_hash(odp_packet_hdr_t *pkt_hdr, tuple_len += 2; } - if (pkt_hdr->p.input_flags.tcp && hash_proto.tcp) { + if (packet_hdr_has_tcp(pkt_hdr) && hash_proto.tcp) { /* add tcp */ tcp = (const _odp_tcphdr_t *)(base + pkt_hdr->p.l4_offset); tuple.v4.sport = tcp->src_port; tuple.v4.dport = tcp->dst_port; tuple_len += 1; - } else if (pkt_hdr->p.input_flags.udp && hash_proto.udp) { + } else if (packet_hdr_has_udp(pkt_hdr) && hash_proto.udp) { /* add udp */ udp = (const _odp_udphdr_t *)(base + pkt_hdr->p.l4_offset); @@ -1059,13 +1059,13 @@ static uint32_t packet_rss_hash(odp_packet_hdr_t *pkt_hdr, thash_load_ipv6_addr(ipv6, &tuple); tuple_len += 8; } - if (pkt_hdr->p.input_flags.tcp && hash_proto.tcp) { + if (packet_hdr_has_tcp(pkt_hdr) && hash_proto.tcp) { tcp = (const _odp_tcphdr_t *)(base + pkt_hdr->p.l4_offset); tuple.v6.sport = tcp->src_port; tuple.v6.dport = tcp->dst_port; tuple_len += 1; - } else if (pkt_hdr->p.input_flags.udp && hash_proto.udp) { + } else if (packet_hdr_has_udp(pkt_hdr) && hash_proto.udp) { /* add udp */ udp = (const _odp_udphdr_t *)(base + pkt_hdr->p.l4_offset); diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 065c22259..87bf23564 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -2228,10 +2228,11 @@ int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr, /* Parse Layer 4 headers */ switch (ip_proto) { case _ODP_IPPROTO_ICMPV4: - /* Fall through */ + /* Do nothing */ + break; case _ODP_IPPROTO_ICMPV6: - prs->input_flags.icmp = 1; + /* Do nothing */ break; case _ODP_IPPROTO_IPIP: @@ -2241,29 +2242,25 @@ int packet_parse_common_l3_l4(packet_parser_t *prs, const uint8_t *parseptr, case _ODP_IPPROTO_TCP: if (odp_unlikely(offset + _ODP_TCPHDR_LEN > seg_len)) return -1; - prs->input_flags.tcp = 1; parse_tcp(prs, &parseptr, NULL); break; case _ODP_IPPROTO_UDP: if (odp_unlikely(offset + _ODP_UDPHDR_LEN > seg_len)) return -1; - prs->input_flags.udp = 1; parse_udp(prs, &parseptr, NULL); break; case _ODP_IPPROTO_AH: prs->input_flags.ipsec = 1; - prs->input_flags.ipsec_ah = 1; break; case _ODP_IPPROTO_ESP: prs->input_flags.ipsec = 1; - prs->input_flags.ipsec_esp = 1; break; case _ODP_IPPROTO_SCTP: - prs->input_flags.sctp = 1; + /* Do nothing */ break; default: diff --git a/platform/linux-generic/odp_packet_flags.c b/platform/linux-generic/odp_packet_flags.c index a1d64ddce..fdde865ee 100644 --- a/platform/linux-generic/odp_packet_flags.c +++ b/platform/linux-generic/odp_packet_flags.c @@ -9,6 +9,7 @@ #include #include #include +#include #define retflag(pkt, x) do { \ odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); \ @@ -129,22 +130,31 @@ int odp_packet_has_ipsec(odp_packet_t pkt) int odp_packet_has_udp(odp_packet_t pkt) { - retflag(pkt, input_flags.udp); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + + return pkt_hdr->p.input_flags.l4_type == ODP_PROTO_L4_TYPE_UDP; } int odp_packet_has_tcp(odp_packet_t pkt) { - retflag(pkt, input_flags.tcp); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + + return pkt_hdr->p.input_flags.l4_type == ODP_PROTO_L4_TYPE_TCP; } int odp_packet_has_sctp(odp_packet_t pkt) { - retflag(pkt, input_flags.sctp); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + + return pkt_hdr->p.input_flags.l4_type == ODP_PROTO_L4_TYPE_SCTP; } int odp_packet_has_icmp(odp_packet_t pkt) { - retflag(pkt, input_flags.icmp); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + + return pkt_hdr->p.input_flags.l4_type == ODP_PROTO_L4_TYPE_ICMPV4 || + pkt_hdr->p.input_flags.l4_type == ODP_PROTO_L4_TYPE_ICMPV6; } odp_packet_color_t odp_packet_color(odp_packet_t pkt) @@ -290,22 +300,56 @@ void odp_packet_has_ipsec_set(odp_packet_t pkt, int val) void odp_packet_has_udp_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.udp, val); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_proto_l4_type_t type = ODP_PROTO_L4_TYPE_UDP; + + if (val) + pkt_hdr->p.input_flags.l4_type = type; + else if (pkt_hdr->p.input_flags.l4_type == type) + pkt_hdr->p.input_flags.l4_type = ODP_PROTO_L4_TYPE_NONE; } void odp_packet_has_tcp_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.tcp, val); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_proto_l4_type_t type = ODP_PROTO_L4_TYPE_TCP; + + if (val) + pkt_hdr->p.input_flags.l4_type = type; + else if (pkt_hdr->p.input_flags.l4_type == type) + pkt_hdr->p.input_flags.l4_type = ODP_PROTO_L4_TYPE_NONE; } void odp_packet_has_sctp_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.sctp, val); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_proto_l4_type_t type = ODP_PROTO_L4_TYPE_SCTP; + + if (val) + pkt_hdr->p.input_flags.l4_type = type; + else if (pkt_hdr->p.input_flags.l4_type == type) + pkt_hdr->p.input_flags.l4_type = ODP_PROTO_L4_TYPE_NONE; } void odp_packet_has_icmp_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.icmp, val); + odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); + odp_proto_l3_type_t ip4 = ODP_PROTO_L3_TYPE_IPV4; + odp_proto_l3_type_t ip6 = ODP_PROTO_L3_TYPE_IPV6; + odp_proto_l4_type_t type4 = ODP_PROTO_L4_TYPE_ICMPV4; + odp_proto_l4_type_t type6 = ODP_PROTO_L4_TYPE_ICMPV6; + + if (val) { + if (pkt_hdr->p.input_flags.l3_type == ip4) + pkt_hdr->p.input_flags.l4_type = type4; + else if (pkt_hdr->p.input_flags.l3_type == ip6) + pkt_hdr->p.input_flags.l4_type = type6; + else + ODP_ERR("Setting ICMP flag for non-IPv4/IPv6 packet!\n"); + } else if (pkt_hdr->p.input_flags.l3_type == type4 || + pkt_hdr->p.input_flags.l3_type == type6) { + pkt_hdr->p.input_flags.l4_type = ODP_PROTO_L4_TYPE_NONE; + } } void odp_packet_has_flow_hash_clr(odp_packet_t pkt)