From patchwork Wed Jul 20 07:24:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Forrest Shi X-Patchwork-Id: 72400 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp496041qga; Wed, 20 Jul 2016 00:24:56 -0700 (PDT) X-Received: by 10.55.160.211 with SMTP id j202mr57414853qke.108.1468999496192; Wed, 20 Jul 2016 00:24:56 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id y11si972977qka.154.2016.07.20.00.24.55; Wed, 20 Jul 2016 00:24:56 -0700 (PDT) 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 dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C309368672; Wed, 20 Jul 2016 07:24:55 +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, NORMAL_HTTP_TO_IP, RCVD_IN_DNSWL_LOW, 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 9D8A06813D; Wed, 20 Jul 2016 07:24:50 +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 06A1A68132; Wed, 20 Jul 2016 07:24:48 +0000 (UTC) Received: from mail-pa0-f47.google.com (mail-pa0-f47.google.com [209.85.220.47]) by lists.linaro.org (Postfix) with ESMTPS id 8F82668132 for ; Wed, 20 Jul 2016 07:24:46 +0000 (UTC) Received: by mail-pa0-f47.google.com with SMTP id fi15so15612992pac.1 for ; Wed, 20 Jul 2016 00:24:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:references:in-reply-to:subject:date :message-id:mime-version:thread-index:content-language; bh=JvBQUUasvG5QAcabAfTKt0lkrmqyGVX3q3UreFI5s/0=; b=LEgasYntSzkFEYEMJY5pH5r/k7tj8vqTcmcKPQR4dtGqgFClS9XTi/H6yEcQBqygor RjbLQJCi6Bi+gQBMUAFdqXkian03zIykCC27iMyr2uqhW0FkUsurBl+5ScwmJ3khMpai EUgODxES4moffrqGek9DcVmBErCrCfeQcW8jnnvbOENY+MN3qTcJ7Qi5WtJK1qMzAEte jqDnO5hSjlaMi2979qHiGmHAfc/tBiNSrKvGrViumty3sEUmHmKZ8xbmEwAs7BbvT1eb GBrqHneWeCcunAtSyJ1MqaxNCb8Vc93JtPxTUYvY914JB81to/inMjK4e71eUVmUweCJ ZZfQ== X-Gm-Message-State: ALyK8tJur1p3EJhm09gzQgday6zTMeK3egvCIXL7adSLcZ1mrcJcTKdJ0Q/9yYPZVEIWfwTlM3k= X-Received: by 10.66.177.7 with SMTP id cm7mr73070013pac.132.1468999485725; Wed, 20 Jul 2016 00:24:45 -0700 (PDT) Received: from b2923702 (gate-zmy3.freescale.com. [192.88.167.1]) by smtp.gmail.com with ESMTPSA id d72sm2188340pfj.15.2016.07.20.00.24.42 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Jul 2016 00:24:44 -0700 (PDT) From: "forrest.shi" To: "'Mike Holmes'" References: <1467965654-34734-1-git-send-email-forrest.shi@linaro.org> <1467965654-34734-3-git-send-email-forrest.shi@linaro.org> In-Reply-To: Date: Wed, 20 Jul 2016 15:24:39 +0800 Message-ID: <000001d1e257$c9454fd0$5bcfef70$@linaro.org> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQIvZz2XdvQ9r+JpIVz2bA7zibAHpAFtJjW1AHCR9hyfVvKVEA== Content-Language: en-us X-Content-Filtered-By: Mailman/MimeDel 2.1.16 X-Topics: patch Cc: 'lng-odp' Subject: Re: [lng-odp] [PATCH/API-NEXT 3/3] helper/ip: add ipv4/subnet parsing 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" Hi Mike I got the following with: GIT_URL=~/git/odp GIT_BRANCH=forrest LCOV=1 ./build.sh No html is generated in the publishing. -- 2.1.0.27.g96db324 -- Mike Holmes Technical Manager - Linaro Networking Group Linaro.org │ Open source software for ARM SoCs "Work should be fun and collaborative, the rest follows" ======================================================================= OpenDataPlane 1.10.1.0.git71.ga942cb4: helper/test/test-suite.log ======================================================================= # TOTAL: 9 # PASS: 8 # SKIP: 0 # XFAIL: 0 # FAIL: 1 # XPASS: 0 # ERROR: 0 .. contents:: :depth: 2 FAIL: cuckootable ================= cuckootable.c:213:odph_cuckoo_table_create():cuckoo hash table put_remove already exists cuckoo hash table creation failed cuckoo hash table test fail!! Thanks, Forrest From: Mike Holmes [mailto:mike.holmes@linaro.org] Sent: Friday, July 15, 2016 20:26 To: Forrest Shi Cc: Bill Fischofer ; lng-odp Subject: Re: [lng-odp] [PATCH/API-NEXT 3/3] helper/ip: add ipv4/subnet parsing On 8 July 2016 at 04:14, > wrote: From: Xuelin Shi > parse an ipv4/subnet string like "192.168.1.0/24 " into 3 values: ipv4-addr, subnet bit width and subnet mask Signed-off-by: Xuelin Shi > --- helper/include/odp/helper/ip.h | 19 +++++++++++++++++++ helper/ip.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/helper/include/odp/helper/ip.h b/helper/include/odp/helper/ip.h index 4cfc00f..dd538c9 100644 --- a/helper/include/odp/helper/ip.h +++ b/helper/include/odp/helper/ip.h @@ -233,6 +233,25 @@ typedef struct ODP_PACKED { int odph_ipv4_addr_parse(uint32_t *ip_addr, const char *str); /** + * Parse text string representing an IPv4 address or subnet + * + * String is of the format "XXX.XXX.XXX.XXX(/W)" where + * "XXX" is decimal value and "/W" is optional subnet length + * + * @param ip_net_str Pointer to IP address/subnet string to convert + * @param ip_addr Pointer to return IPv4 address, host endianness + * @param depth Pointer to subnet bit width + * @param subnet_mask Pointer to subnet mask + * + * @retval 0 on success of parsing both ip and subnet + * @retval 1 on success of parsing only ip + * @retval 2 on success of parsing only subnet + * @retval <0 on failure + */ +int odph_ipv4_subnet_parse(const char *ip_net_str, uint32_t *ip_addr, + uint32_t *depth, uint32_t *subnet_mask); This new api is not tested by the validation suite To see this in LCOV use check-odp and point at your repo and branch setting LCOV GIT_URL=~/git/odp GIT_BRANCH=forrest LCOV=1 ./build.sh firefox publishing/forrest/linux-generic-helper-lcov-html/helper/ip.c.gcov.html + +/** * @} */ #ifdef __cplusplus diff --git a/helper/ip.c b/helper/ip.c index e211001..d2ca21e 100644 --- a/helper/ip.c +++ b/helper/ip.c @@ -30,3 +30,36 @@ int odph_ipv4_addr_parse(uint32_t *ip_addr, const char *str) return 0; } + +int odph_ipv4_subnet_parse(const char *ip_net_str, uint32_t *ip_addr, + uint32_t *depth, uint32_t *subnet_mask) +{ + char *s; + int converted; + uint32_t qualifier = 32; + char ip_valid = 0; + char subnet_valid = 0; + + s = strchr(ip_net_str, '/'); + if (s) { + converted = sscanf(s, "/%u", &qualifier); + if (converted == 1 && qualifier && qualifier <= 32) { + *depth = qualifier; + *subnet_mask = ((1 << qualifier) - 1) << + (32 - qualifier); + subnet_valid = 1; + } + } + + if (!odph_ipv4_addr_parse(ip_addr, ip_net_str)) + ip_valid = 1; + + if (ip_valid && subnet_valid) + return 0; + else if (ip_valid) + return 1; + else if (subnet_valid) + return 2; + else + return -1; +}