From patchwork Mon Jan 30 12:56:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 92857 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1418759qgi; Mon, 30 Jan 2017 04:57:18 -0800 (PST) X-Received: by 10.200.36.207 with SMTP id t15mr20873847qtt.84.1485781038756; Mon, 30 Jan 2017 04:57:18 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id k184si9429572qkd.297.2017.01.30.04.57.18; Mon, 30 Jan 2017 04:57:18 -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 4944D62C7C; Mon, 30 Jan 2017 12:57:18 +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_H3, RCVD_IN_MSPIKE_WL, 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 A4B306097B; Mon, 30 Jan 2017 12:57:12 +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 91A70609C5; Mon, 30 Jan 2017 12:57:10 +0000 (UTC) Received: from mail-pg0-f54.google.com (mail-pg0-f54.google.com [74.125.83.54]) by lists.linaro.org (Postfix) with ESMTPS id 371F36097A for ; Mon, 30 Jan 2017 12:57:09 +0000 (UTC) Received: by mail-pg0-f54.google.com with SMTP id 194so101119241pgd.2 for ; Mon, 30 Jan 2017 04:57:09 -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=MIBGAIXAJNuIoB98dJbsdOyOR//Nq3Pdgjxo1Ayet8g=; b=ZmowpigK1oj1L8CcI2ThF8OiTUiBCInm4M6B+Xgl1jJF0UtNpxnpwF+hwKBv/zDdmv 9ZCuuWM81UQGlhqWnjuUR/xaD+IiJs/xz1q10MYGdK/YFAoAUFNcxlOYDRlDktDv0NKn YQ1xON4zDLFEb3/rCiHGUp75oXRUnH0i3UDs+0cwbVZU4FtQqNbc7xVy/IfAUyrSdsgj c4ZLooJV2OG0jNNvGrGeFsvPV2nHiyamIUcRRkRal95oSprVmOeDXm34jlNfY2rihb5R wgZlOGllN79uN7mi1iQsGbbdVYrJqUJ3HK40kRob1jrO0uJNyZaeAoReyRy95LJthJS/ KT1Q== X-Gm-Message-State: AIkVDXLjk0A3FIvnEcdO1VFLdZRTjDwCvKByaTMgyrO5JKbFFZ7qUYufvy1iWNV420LyB1Q3pKI= X-Received: by 10.99.121.77 with SMTP id u74mr23777425pgc.200.1485781028383; Mon, 30 Jan 2017 04:57:08 -0800 (PST) Received: from localhost.localdomain ([122.172.20.88]) by smtp.gmail.com with ESMTPSA id q80sm32609413pfi.13.2017.01.30.04.57.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Jan 2017 04:57:07 -0800 (PST) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Mon, 30 Jan 2017 18:26:49 +0530 Message-Id: <1485781010-11166-1-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [lng-odp] [PATCH 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" Implements IPV6 src and dst address packet matching rule Signed-off-by: Balasubramanian Manoharan --- .../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;