From patchwork Fri Feb 3 12:45:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 93172 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp572743qgi; Fri, 3 Feb 2017 04:46:24 -0800 (PST) X-Received: by 10.237.37.58 with SMTP id v55mr13387461qtc.15.1486125984205; Fri, 03 Feb 2017 04:46:24 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id g67si19172442qkf.69.2017.02.03.04.46.23; Fri, 03 Feb 2017 04:46:24 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id AE66C61071; Fri, 3 Feb 2017 12:46:23 +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=-1.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, URIBL_BLOCKED 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 2391460765; Fri, 3 Feb 2017 12:46:17 +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 34A8A60765; Fri, 3 Feb 2017 12:45:58 +0000 (UTC) Received: from mail-pg0-f52.google.com (mail-pg0-f52.google.com [74.125.83.52]) by lists.linaro.org (Postfix) with ESMTPS id D0C456071A for ; Fri, 3 Feb 2017 12:45:52 +0000 (UTC) Received: by mail-pg0-f52.google.com with SMTP id v184so6605714pgv.3 for ; Fri, 03 Feb 2017 04:45:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=db5MXDJExuKIheE9/BCQsRYFV6le+y0pSfdzjWoMSKk=; b=TZWtwrDzxf3QNyrvnzCHkRdag32jFbH9TqT0V8T31SWnpB/TzLkmrsx6JMzdT5soA0 vuhFJs13aKZlJhcfxcKmwYaw5s4IQTdwHh0JOGV5CcMyrcLi4kNRx60aKrB6ECDsfqf4 Kbt2Har5slkbsNQAwENAp7WTvEt2V+6HwDJRM4yyzQFCodJP2ef98uwlr75s6Q/ssJUd iRYm8+7tA313sZfAtKimOivwEOOzXqOmiZnEjfVAbkRnn1cQ833ID/tDeAfoyGXIO42M 4ePMQo7S6afTBsYW1dCxinsMvbnSTfXOj6q09WKnvuIx/bD0ilHqIDtqUL5fxlM7n5OV wG3A== X-Gm-Message-State: AIkVDXKwUus2Rtvuf0Gs4OnIhPzyQEgVtPuqzhIrKIxz9B0HEdYwflsE5NgDObf5IXvAC33ULXo= X-Received: by 10.84.133.163 with SMTP id f32mr20567858plf.64.1486125951856; Fri, 03 Feb 2017 04:45:51 -0800 (PST) Received: from bala-Vostro-2520.caveonetworks.com ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id z77sm67049373pfk.47.2017.02.03.04.45.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Feb 2017 04:45:51 -0800 (PST) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Fri, 3 Feb 2017 18:15:44 +0530 Message-Id: <1486125945-8641-1-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [lng-odp] [PATCHv3 1/2] linux-generic: classification: implement ipv6 packet matching rule 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" Adds test case for ipv6 source and destination address matching Signed-off-by: Balasubramanian Manoharan --- v3: performance enhancement using bitwise AND for ip address mask .../include/odp_classification_datamodel.h | 11 ++++- .../include/odp_classification_inlines.h | 52 ++++++++++++++++++---- .../linux-generic/include/odp_packet_internal.h | 5 +++ platform/linux-generic/include/protocols/ip.h | 14 +++++- platform/linux-generic/odp_classification.c | 27 +++++++++++ platform/linux-generic/odp_packet.c | 2 +- 6 files changed, 99 insertions(+), 12 deletions(-) -- 1.9.1 diff --git a/platform/linux-generic/include/odp_classification_datamodel.h b/platform/linux-generic/include/odp_classification_datamodel.h index f6393ee..140f39e 100644 --- a/platform/linux-generic/include/odp_classification_datamodel.h +++ b/platform/linux-generic/include/odp_classification_datamodel.h @@ -25,6 +25,7 @@ extern "C" { #include #include #include +#include /* Maximum Class Of Service Entry */ #define ODP_COS_MAX_ENTRY 64 @@ -43,7 +44,7 @@ extern "C" { /* Max L3 QoS Value */ #define ODP_COS_MAX_L3_QOS (1 << ODP_COS_L3_QOS_BITS) /* Max PMR Term bits */ -#define ODP_PMR_TERM_BYTES_MAX 8 +#define ODP_PMR_TERM_BYTES_MAX 16 /** Packet Matching Rule Term Value @@ -67,6 +68,14 @@ typedef struct pmr_term_value { /** End value of the range */ uint64_t val_end; } range; + struct { + _odp_ipv6_addr_t addr; + _odp_ipv6_addr_t mask; + } match_ipv6; + struct { + _odp_ipv6_addr_t addr_start; + _odp_ipv6_addr_t addr_end; + } range_ipv6; }; uint32_t offset; /**< Offset if term == ODP_PMR_CUSTOM_FRAME */ uint32_t val_sz; /**< Size of the value to be matched */ diff --git a/platform/linux-generic/include/odp_classification_inlines.h b/platform/linux-generic/include/odp_classification_inlines.h index b839197..e6f9be9 100644 --- a/platform/linux-generic/include/odp_classification_inlines.h +++ b/platform/linux-generic/include/odp_classification_inlines.h @@ -25,6 +25,8 @@ extern "C" { #include #include #include +#include +#include /* PMR term value verification function These functions verify the given PMR term value with the value in the packet @@ -179,19 +181,53 @@ static inline int verify_pmr_dmac(const uint8_t *pkt_addr, return 0; } -static inline int verify_pmr_ipv6_saddr(const uint8_t *pkt_addr ODP_UNUSED, - odp_packet_hdr_t *pkt_hdr ODP_UNUSED, - pmr_term_value_t *term_value ODP_UNUSED) +static inline int verify_pmr_ipv6_saddr(const uint8_t *pkt_addr, + odp_packet_hdr_t *pkt_hdr, + pmr_term_value_t *term_value) { - ODP_UNIMPLEMENTED(); + const _odp_ipv6hdr_t *ipv6; + uint64_t addr[2]; + + if (!packet_hdr_has_ipv6(pkt_hdr)) + return 0; + + ipv6 = (const _odp_ipv6hdr_t *)(pkt_addr + pkt_hdr->p.l3_offset); + + addr[0] = ipv6->src_addr.u64[0]; + addr[1] = ipv6->src_addr.u64[1]; + + /* 128 bit address is processed as two 64 bit value + * for bitwise AND operation */ + addr[0] = addr[0] & term_value->match_ipv6.mask.u64[0]; + addr[1] = addr[1] & term_value->match_ipv6.mask.u64[1]; + + if (!memcmp(addr, term_value->match_ipv6.addr.u8, _ODP_IPV6ADDR_LEN)) + return 1; + return 0; } -static inline int verify_pmr_ipv6_daddr(const uint8_t *pkt_addr ODP_UNUSED, - odp_packet_hdr_t *pkt_hdr ODP_UNUSED, - pmr_term_value_t *term_value ODP_UNUSED) +static inline int verify_pmr_ipv6_daddr(const uint8_t *pkt_addr, + odp_packet_hdr_t *pkt_hdr, + pmr_term_value_t *term_value) { - ODP_UNIMPLEMENTED(); + const _odp_ipv6hdr_t *ipv6; + uint64_t addr[2]; + + if (!packet_hdr_has_ipv6(pkt_hdr)) + return 0; + ipv6 = (const _odp_ipv6hdr_t *)(pkt_addr + pkt_hdr->p.l3_offset); + addr[0] = ipv6->dst_addr.u64[0]; + addr[1] = ipv6->dst_addr.u64[1]; + + /* 128 bit address is processed as two 64 bit value + * for bitwise AND operation */ + addr[0] = addr[0] & term_value->match_ipv6.mask.u64[0]; + addr[1] = addr[1] & term_value->match_ipv6.mask.u64[1]; + + if (!memcmp(addr, term_value->match_ipv6.addr.u8, _ODP_IPV6ADDR_LEN)) + return 1; + return 0; } diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index e6e9d74..e3ada5c 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -294,6 +294,11 @@ static inline int packet_hdr_has_eth(odp_packet_hdr_t *pkt_hdr) return pkt_hdr->p.input_flags.eth; } +static inline int packet_hdr_has_ipv6(odp_packet_hdr_t *pkt_hdr) +{ + return pkt_hdr->p.input_flags.ipv6; +} + 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/include/protocols/ip.h b/platform/linux-generic/include/protocols/ip.h index 6c089e3..20041f1 100644 --- a/platform/linux-generic/include/protocols/ip.h +++ b/platform/linux-generic/include/protocols/ip.h @@ -117,6 +117,16 @@ ODP_STATIC_ASSERT(sizeof(_odp_ipv4hdr_t) == _ODP_IPV4HDR_LEN, (uint8_t)((((ver_tc_flow) & 0x0fc00000) >> 22) & 0xff) /** + * Ipv6 address + */ +typedef union ODP_PACKED { + uint8_t u8[16]; + odp_u16be_t u16[8]; + odp_u32be_t u32[4]; + odp_u64be_t u64[2]; +} _odp_ipv6_addr_t; + +/** * IPv6 header */ typedef struct ODP_PACKED { @@ -124,8 +134,8 @@ typedef struct ODP_PACKED { odp_u16be_t payload_len; /**< Payload length */ uint8_t next_hdr; /**< Next header */ uint8_t hop_limit; /**< Hop limit */ - uint8_t src_addr[16]; /**< Source address */ - uint8_t dst_addr[16]; /**< Destination address */ + _odp_ipv6_addr_t src_addr; /**< Source address */ + _odp_ipv6_addr_t dst_addr; /**< Destination address */ } _odp_ipv6hdr_t; /** @internal Compile time assert */ diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c index 50a7e54..4882c5c 100644 --- a/platform/linux-generic/odp_classification.c +++ b/platform/linux-generic/odp_classification.c @@ -447,6 +447,32 @@ static int odp_pmr_create_term(pmr_term_value_t *value, { value->term = param->term; value->range_term = param->range_term; + uint8_t i; + + switch (value->term) { + case ODP_PMR_SIP6_ADDR: + case ODP_PMR_DIP6_ADDR: + if (!value->range_term) { + memset(value->match_ipv6.addr.u8, 0, 16); + memset(value->match_ipv6.mask.u8, 0, 16); + memcpy(&value->match_ipv6.addr.u8, param->match.value, + param->val_sz); + memcpy(&value->match_ipv6.mask.u8, param->match.mask, + param->val_sz); + for (i = 0; i < 2; i++) + value->match_ipv6.addr.u64[i] &= + value->match_ipv6.mask.u64[i]; + } else { + memset(value->range_ipv6.addr_start.u8, 0, 16); + memset(value->range_ipv6.addr_end.u8, 0, 16); + memcpy(&value->range_ipv6.addr_start.u8, param->range.val_start, + param->val_sz); + memcpy(&value->range_ipv6.addr_end.u8, param->range.val_end, + param->val_sz); + } + + break; + default: if (!value->range_term) { value->match.value = 0; value->match.mask = 0; @@ -461,6 +487,7 @@ static int odp_pmr_create_term(pmr_term_value_t *value, memcpy(&value->range.val_end, param->range.val_end, param->val_sz); } + } value->offset = param->offset; value->val_sz = param->val_sz; return 0; diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 34d720c..a87b2d9 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -1888,7 +1888,7 @@ static inline uint8_t parse_ipv6(packet_parser_t *prs, const uint8_t **parseptr, { const _odp_ipv6hdr_t *ipv6 = (const _odp_ipv6hdr_t *)*parseptr; const _odp_ipv6hdr_ext_t *ipv6ext; - uint32_t dstaddr0 = odp_be_to_cpu_32(ipv6->dst_addr[0]); + uint32_t dstaddr0 = odp_be_to_cpu_32(ipv6->dst_addr.u8[0]); prs->l3_len = odp_be_to_cpu_16(ipv6->payload_len) + _ODP_IPV6HDR_LEN;