From patchwork Tue Jan 31 06:42:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 92942 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1791527qgi; Mon, 30 Jan 2017 22:43:13 -0800 (PST) X-Received: by 10.237.41.99 with SMTP id s90mr26068596qtd.4.1485844993410; Mon, 30 Jan 2017 22:43:13 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p33si11326825qtb.68.2017.01.30.22.43.12; Mon, 30 Jan 2017 22:43:13 -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 CBD0D60C4E; Tue, 31 Jan 2017 06:43:12 +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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 2DABA60931; Tue, 31 Jan 2017 06:43:08 +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 E279860931; Tue, 31 Jan 2017 06:43:04 +0000 (UTC) Received: from mail-pf0-f180.google.com (mail-pf0-f180.google.com [209.85.192.180]) by lists.linaro.org (Postfix) with ESMTPS id 286FD60903 for ; Tue, 31 Jan 2017 06:43:03 +0000 (UTC) Received: by mail-pf0-f180.google.com with SMTP id y143so100902860pfb.0 for ; Mon, 30 Jan 2017 22:43:03 -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=GsllAfYlCz9No3NwBHLOSfDQIrsv8xomwz330YJedAI=; b=tPkUpfoQno0BpLtifRGfLQJ4ZYGXBXsL8Bn+dwo0BSHkwu5S0/lcUoDW9Puu03/llu CK70HT0w0kdx+vfutGvX2JSqQSQgdz7XuLUkMsVTAEdd6dfv1BNe2c31oSjd8rLxwYlN 76GHyurtRLi4JV5F98DdRYsNk/zRfSgw4A/XhvkcSMOoxQPIAo0mmuWIrEZV+4/IJKbF 9BAFcCVzPjiMu6wNMhJjSEcBLx8vv6DteC8PQRz7PKBxM0Ck4Qce/y+ehtqtdQTEixlx JgRoWhiA3YMKp/7BUVMtwlUz+rgRHxkamFfPD+5HgSx6ooGoGh1xBq4Vnc52wIDQhHp9 Uu0A== X-Gm-Message-State: AIkVDXJAYPuDMlNtRWbQN3KaAT19ZDaq0k8iSqBIhvkrilngr5lgmfAk7MnU5++kne9TBG+vhzM= X-Received: by 10.84.216.89 with SMTP id f25mr36681575plj.6.1485844982382; Mon, 30 Jan 2017 22:43:02 -0800 (PST) Received: from localhost.localdomain ([122.171.79.69]) by smtp.gmail.com with ESMTPSA id u75sm37795825pgc.31.2017.01.30.22.43.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Jan 2017 22:43:01 -0800 (PST) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Tue, 31 Jan 2017 12:12:35 +0530 Message-Id: <1485844956-14926-1-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [lng-odp] [PATCHv2 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 --- v2: clang compilation fix .../include/odp_classification_datamodel.h | 11 +++++- .../include/odp_classification_inlines.h | 44 ++++++++++++++++++---- .../linux-generic/include/odp_packet_internal.h | 5 +++ platform/linux-generic/odp_classification.c | 26 +++++++++++++ 4 files changed, 77 insertions(+), 9 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..5b1cde3 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 { + uint8_t value[_ODP_IPV6ADDR_LEN]; + uint8_t mask[_ODP_IPV6ADDR_LEN]; + } match_ipv6; + struct { + uint8_t val_start[_ODP_IPV6ADDR_LEN]; + uint8_t val_end[_ODP_IPV6ADDR_LEN]; + } 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..4d85cf2 100644 --- a/platform/linux-generic/include/odp_classification_inlines.h +++ b/platform/linux-generic/include/odp_classification_inlines.h @@ -179,19 +179,47 @@ 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; + uint8_t src_addr[_ODP_IPV6ADDR_LEN]; + uint8_t i; + + if (!packet_hdr_has_ipv6(pkt_hdr)) + return 0; + + ipv6 = (const _odp_ipv6hdr_t *)(pkt_addr + pkt_hdr->p.l3_offset); + memcpy(src_addr, ipv6->src_addr, _ODP_IPV6ADDR_LEN); + for (i = 0; i < _ODP_IPV6ADDR_LEN; i++) + src_addr[i] = src_addr[i] & term_value->match_ipv6.mask[i]; + + if (!memcmp(term_value->match_ipv6.value, src_addr, _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; + uint8_t dst_addr[_ODP_IPV6ADDR_LEN]; + uint8_t i; + + if (!packet_hdr_has_ipv6(pkt_hdr)) + return 0; + + ipv6 = (const _odp_ipv6hdr_t *)(pkt_addr + pkt_hdr->p.l3_offset); + memcpy(dst_addr, ipv6->dst_addr, _ODP_IPV6ADDR_LEN); + for (i = 0; i < _ODP_IPV6ADDR_LEN; i++) + dst_addr[i] = dst_addr[i] & term_value->match_ipv6.mask[i]; + + if (!memcmp(term_value->match_ipv6.value, dst_addr, _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/odp_classification.c b/platform/linux-generic/odp_classification.c index 50a7e54..d8c0479 100644 --- a/platform/linux-generic/odp_classification.c +++ b/platform/linux-generic/odp_classification.c @@ -447,6 +447,31 @@ 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.value, 0, 16); + memset(value->match_ipv6.mask, 0, 16); + memcpy(&value->match_ipv6.value, param->match.value, + param->val_sz); + memcpy(&value->match_ipv6.mask, param->match.mask, + param->val_sz); + for (i = 0; i < 16; i++) + value->match_ipv6.value[i] &= value->match_ipv6.mask[i]; + } else { + memset(value->range_ipv6.val_start, 0, 16); + memset(value->range_ipv6.val_end, 0, 16); + memcpy(&value->range_ipv6.val_start, param->range.val_start, + param->val_sz); + memcpy(&value->range_ipv6.val_end, param->range.val_end, + param->val_sz); + } + + break; + default: if (!value->range_term) { value->match.value = 0; value->match.mask = 0; @@ -461,6 +486,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;