From patchwork Fri Jan 30 09:28:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 44020 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f72.google.com (mail-ee0-f72.google.com [74.125.83.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0D85B2410D for ; Fri, 30 Jan 2015 09:29:29 +0000 (UTC) Received: by mail-ee0-f72.google.com with SMTP id e49sf12414811eek.3 for ; Fri, 30 Jan 2015 01:29:28 -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=Xayc9kIzWN9JajeemrLbZoXBS50djVNPpu5SXXKWDDQ=; b=FeT1yNSH1bGcG9MaQUU7NM6wuRyJat6azqXzCVAAh+1v21jdtrynVM5gTnHJ9FAITv V2GYmszIeZgzAjMcX6asKZxRfj+BsfacrCrHOsd5qvLWk7jJ7b+gsG+rXTt2hJ/Y5ZNY 1V++nmKFIEWITDZjk6RTWSrp5VZK7RwebYdj5oZ4pI+9hSzIF0vm9+FyVOMY09fCSxdk jDUcxDvNu0aHR/95TMmcWqOPTb/Dsy7KzsOU5orz0A/wWLEfdeXR0CKAAcigAJRHeAB8 rGS89Uaxb9JeyBEodk5fIhw04nimK0IUL/mXiDxhS8FHpbmln+MN1Mz9j8sB1RDhloYL 1JOA== X-Gm-Message-State: ALoCoQnzFh7SKGeZ5gKpr47xmHRDM89mKlN7D/iyg1SIpWCmjQBEgwHsPrwYqHT+tUmOkTWiXMMh X-Received: by 10.152.37.71 with SMTP id w7mr669808laj.5.1422610168062; Fri, 30 Jan 2015 01:29:28 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.130 with SMTP id m2ls345597laf.87.gmail; Fri, 30 Jan 2015 01:29:27 -0800 (PST) X-Received: by 10.152.204.40 with SMTP id kv8mr5648571lac.42.1422610167851; Fri, 30 Jan 2015 01:29:27 -0800 (PST) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id u2si9665883lae.110.2015.01.30.01.29.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 30 Jan 2015 01:29:27 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by mail-lb0-f173.google.com with SMTP id p9so35470231lbv.4 for ; Fri, 30 Jan 2015 01:29:27 -0800 (PST) X-Received: by 10.112.44.230 with SMTP id h6mr5452749lbm.98.1422610167407; Fri, 30 Jan 2015 01:29:27 -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 h5csp220586lbj; Fri, 30 Jan 2015 01:29:26 -0800 (PST) X-Received: by 10.52.75.132 with SMTP id c4mr2256022vdw.77.1422610161953; Fri, 30 Jan 2015 01:29:21 -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 rn17si1565596vdb.77.2015.01.30.01.29.20 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 30 Jan 2015 01:29:21 -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 1YH7t8-0004Df-Hi; Fri, 30 Jan 2015 09:29:18 +0000 Received: from mail-lb0-f179.google.com ([209.85.217.179]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YH7sv-0004AX-5L for lng-odp@lists.linaro.org; Fri, 30 Jan 2015 09:29:05 +0000 Received: by mail-lb0-f179.google.com with SMTP id 10so35347496lbg.10 for ; Fri, 30 Jan 2015 01:28:59 -0800 (PST) X-Received: by 10.152.9.170 with SMTP id a10mr5482506lab.1.1422610139405; Fri, 30 Jan 2015 01:28:59 -0800 (PST) Received: from macmini.lan (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id p5sm2614383laj.0.2015.01.30.01.28.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Jan 2015 01:28:58 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Fri, 30 Jan 2015 10:28:46 +0100 Message-Id: <1422610133-20756-3-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422610133-20756-1-git-send-email-ola.liljedahl@linaro.org> References: <1422610133-20756-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 02/16] 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.217.173 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 odp_pktio_mac_addr() definition updated to return number of bytes written (on success) and return <0 on failure. Added ODP_PKTIO_MACADDRSIZE define with recommended output buffer size. Updated the implementation and usages of this call to match definition and recommended usage. Signed-off-by: Ola Liljedahl --- (This document/code contribution attached is provided under the terms of agreement LES-LTM-21309) platform/linux-generic/include/api/odp_packet_io.h | 20 +++++++++++++------- platform/linux-generic/odp_packet_io.c | 11 ++++++----- test/validation/odp_pktio.c | 11 +++++------ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h index 6e479aa..25e178a 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -18,6 +18,7 @@ extern "C" { #endif +#include #include #include #include @@ -30,6 +31,11 @@ extern "C" { */ /** + * * Minimum size of output buffer for odp_pktio_mac_addr() + * */ +#define ODP_PKTIO_MACADDRSIZE 16 + +/** * Open an ODP packet IO instance * * Packet IO handles are single instance per device, attempts to open an already @@ -157,16 +163,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/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 52125fc..b95ecef 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 0985771..6036493 100644 --- a/test/validation/odp_pktio.c +++ b/test/validation/odp_pktio.c @@ -450,22 +450,21 @@ 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; 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); - CU_ASSERT(ODPH_ETHADDR_LEN == mac_len); + ret = odp_pktio_mac_addr(pktio, mac_addr, sizeof(mac_addr)); + CU_ASSERT(ret == ODPH_ETHADDR_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. */ - mac_len = odp_pktio_mac_addr(pktio, mac_addr, 2); - CU_ASSERT(0 == mac_len); + /* Fail case: wrong addr_size. Expected <0. */ + ret = odp_pktio_mac_addr(pktio, mac_addr, 2); + CU_ASSERT(ret < 0); ret = odp_pktio_close(pktio); CU_ASSERT(0 == ret);