From patchwork Tue Feb 3 14:53:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 44229 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 67B922034D for ; Tue, 3 Feb 2015 14:53:58 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id r20sf26026259wiv.2 for ; Tue, 03 Feb 2015 06:53:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=Wg1vGM/pooDZB3ADPRyVPaRi8SEhHYWuu2DyZWU/+Ko=; b=eHxysgjgaPVtLG3cWyd/QmL8M+pE2+3DnIaG773cM55uspeqwJuXQbp/7p6GyFmj8u X8dAvmDLHB3+ylpKLrd6iUDnM0qyeAV5O3hpHnKRXCxFQoA302K7W87vQwaE7uoi+vND x98D8xdlVr2OIcII3aP7M/bi6r9IApg/Q1W17skLmWfodzo5qhv5AO81q0LmYEoAgL7/ JDTxfBN5ZjBCeyeTAI8GQvppVUopg0fvfa4i/hr8HB3FXeB5gPdDK6GwA/JKoJvAg3mj bzg2PpZDX6kEk9JIKS+4OLYe27Jlh+GmZs3t8cQZ9CzXAFtqZhjyVkOkS3R6q0/tykQL l+Zw== X-Gm-Message-State: ALoCoQlFArmNTnzAqC/HalwfsvT48aoZ8tA/8ZH6WMHK7w+7RLPgUh1Cu9CPD4GzVEJrvbx8pARj X-Received: by 10.112.124.142 with SMTP id mi14mr2342480lbb.1.1422975237574; Tue, 03 Feb 2015 06:53:57 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.243.39 with SMTP id wv7ls211198lac.66.gmail; Tue, 03 Feb 2015 06:53:57 -0800 (PST) X-Received: by 10.112.98.202 with SMTP id ek10mr24895727lbb.30.1422975237427; Tue, 03 Feb 2015 06:53:57 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id al1si19381118lbc.23.2015.02.03.06.53.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 03 Feb 2015 06:53:57 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id s18so52606313lam.3 for ; Tue, 03 Feb 2015 06:53:57 -0800 (PST) X-Received: by 10.112.25.104 with SMTP id b8mr24763624lbg.69.1422975237286; Tue, 03 Feb 2015 06:53:57 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1987718lbj; Tue, 3 Feb 2015 06:53:56 -0800 (PST) X-Received: by 10.229.50.135 with SMTP id z7mr10012907qcf.21.1422975235124; Tue, 03 Feb 2015 06:53:55 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id q67si29069354qgd.39.2015.02.03.06.53.50 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 03 Feb 2015 06:53:55 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YIerN-0001Zf-1r; Tue, 03 Feb 2015 14:53:49 +0000 Received: from mail-la0-f47.google.com ([209.85.215.47]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YIer8-0001Xn-HP for lng-odp@lists.linaro.org; Tue, 03 Feb 2015 14:53:34 +0000 Received: by mail-la0-f47.google.com with SMTP id hz20so52409982lab.6 for ; Tue, 03 Feb 2015 06:53:29 -0800 (PST) X-Received: by 10.152.29.129 with SMTP id k1mr12743875lah.10.1422975208947; Tue, 03 Feb 2015 06:53:28 -0800 (PST) Received: from localhost.localdomain (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id jf3sm5082572lbc.44.2015.02.03.06.53.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Feb 2015 06:53:28 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Tue, 3 Feb 2015 15:53:05 +0100 Message-Id: <1422975201-3364-3-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422975201-3364-1-git-send-email-ola.liljedahl@linaro.org> References: <1422975201-3364-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv4 02/18] api: odp_pktio.h: odp_pktio_mac_addr() return chars written or error X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ola.liljedahl@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Added define ODP_PKTIO_MACADDRSIZE which specifies the recommended output buffer size for odp_pktio_mac_addr(). odp_pktio_mac_addr() takes output buffer size as input and returns number of chars written (on success), <0 on failure. Updated the implementation. Updated all usages in example and test programs. Signed-off-by: Ola Liljedahl --- (This document/code contribution attached is provided under the terms of agreement LES-LTM-21309) include/odp/api/packet_io.h | 20 +++++++++++++------- .../linux-generic/include/odp/plat/packet_io_types.h | 2 ++ platform/linux-generic/odp_packet_io.c | 11 ++++++----- test/validation/odp_pktio.c | 8 ++++---- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/include/odp/api/packet_io.h b/include/odp/api/packet_io.h index da7bc3f..096198c 100644 --- a/include/odp/api/packet_io.h +++ b/include/odp/api/packet_io.h @@ -18,6 +18,7 @@ extern "C" { #endif +#include /** @defgroup odp_packet_io ODP PACKET IO * Operations on a packet. @@ -39,6 +40,11 @@ extern "C" { * odp_pktio_t value to indicate any port */ +/* + * @def ODP_PKTIO_MACADDRSIZE + * Minimum size of output buffer for odp_pktio_mac_addr() + */ + /** * Open an ODP packet IO instance * @@ -167,16 +173,16 @@ int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable); int odp_pktio_promisc_mode(odp_pktio_t id); /** - * Get the default MAC address of a packet IO interface. + * Get the native MAC address of a packet IO interface. * - * @param id ODP packet IO handle. - * @param[out] mac_addr Storage for MAC address of the packet IO interface. - * @param addr_size Storage size for the address + * @param hdl ODP packet IO handle + * @param[out] buf Output buffer (use ODP_PKTIO_MACADDRSIZE) + * @param bufsz Size of output buffer * - * @retval Number of bytes written on success, 0 on failure. + * @return Number of bytes written to buffer + * @retval <0 on failure */ -size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, - size_t addr_size); +ssize_t odp_pktio_mac_addr(odp_pktio_t hdl, void *buf, ssize_t bufsz); /** * Setup per-port default class-of-service. diff --git a/platform/linux-generic/include/odp/plat/packet_io_types.h b/platform/linux-generic/include/odp/plat/packet_io_types.h index a6bbacf..61dca13 100644 --- a/platform/linux-generic/include/odp/plat/packet_io_types.h +++ b/platform/linux-generic/include/odp/plat/packet_io_types.h @@ -23,6 +23,8 @@ extern "C" { * @{ */ +#define ODP_PKTIO_MACADDRSIZE 16 + typedef uint32_t odp_pktio_t; #define ODP_PKTIO_INVALID 0 diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index bdb690e..f156dd3 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -798,18 +798,19 @@ int odp_pktio_promisc_mode(odp_pktio_t id) } -size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, - size_t addr_size) +ssize_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, ssize_t addr_size) { pktio_entry_t *entry; - if (addr_size < ETH_ALEN) - return 0; + if (addr_size < ETH_ALEN) { + /* Output buffer too small */ + return -1; + } entry = get_pktio_entry(id); if (entry == NULL) { ODP_DBG("pktio entry %d does not exist\n", id); - return 0; + return -1; } lock_entry(entry); diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c index 84121f5..e1ca793 100644 --- a/test/validation/odp_pktio.c +++ b/test/validation/odp_pktio.c @@ -450,22 +450,22 @@ static void test_odp_pktio_promisc(void) static void test_odp_pktio_mac(void) { unsigned char mac_addr[ODPH_ETHADDR_LEN]; - size_t mac_len; + ssize_t mac_len; int ret; odp_pktio_t pktio = create_pktio(iface_name[0]); printf("testing mac for %s\n", iface_name[0]); - mac_len = odp_pktio_mac_addr(pktio, mac_addr, ODPH_ETHADDR_LEN); + mac_len = odp_pktio_mac_addr(pktio, mac_addr, sizeof(mac_addr)); CU_ASSERT(ODPH_ETHADDR_LEN == mac_len); printf(" %X:%X:%X:%X:%X:%X ", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); - /* Fail case: wrong addr_size. Expected 0. */ + /* Fail case: wrong addr_size. Expected <0. */ mac_len = odp_pktio_mac_addr(pktio, mac_addr, 2); - CU_ASSERT(0 == mac_len); + CU_ASSERT(mac_len < 0); ret = odp_pktio_close(pktio); CU_ASSERT(0 == ret);