From patchwork Thu Jan 29 10:39:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 43904 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C7F1F24119 for ; Thu, 29 Jan 2015 10:40:42 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id f15sf17970133lbj.2 for ; Thu, 29 Jan 2015 02:40:41 -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=LOeQURLuj2CrjH/uVgF3BanfoqbbYFWtqKfrQ/c5Al8=; b=GLMeeoeFcmv4CfB0Qc5bpK3s0uUpcF6kJ4jbNsAIArv41SlaZtIy8Dcl+E6LZ71Apz q3EV4fvD+PZ3ojxl+L4LuYi1sOufY47tsHjWQjCVwHFJYujB4I/1cHl9gP9nUPITagNQ lJ1Zt9wR44OucUJ+V8o3x5D+ShHqLTKueB/IIlFnL0r3IVzdRrEHnaDnja5FA1S96VMQ HzhrxypMw5JfZ4S8BStHNJ35DUStLCQx0jPX2178fUH1x/PE2gWU1Xnn+DCR3ICdCake ZCKQddIiTb4I6dUIQqtll91/kutjAeUY6cmdCpUPrkzDtAk5giyn4/Ek6hJW0R+776eT utpg== X-Gm-Message-State: ALoCoQnuua5VJxEDlpbiT2X6byAPgz5VgQKGzpQWaY0hlm8DjqdtVwRIB8ZHt4zUVD2a6hs+nI7/ X-Received: by 10.112.30.131 with SMTP id s3mr1696017lbh.13.1422528041729; Thu, 29 Jan 2015 02:40:41 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.234.169 with SMTP id uf9ls261562lac.75.gmail; Thu, 29 Jan 2015 02:40:41 -0800 (PST) X-Received: by 10.112.135.196 with SMTP id pu4mr13468315lbb.41.1422528041588; Thu, 29 Jan 2015 02:40:41 -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 lm12si7006190lac.53.2015.01.29.02.40.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 Jan 2015 02:40:41 -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 p9so26623362lbv.4 for ; Thu, 29 Jan 2015 02:40:41 -0800 (PST) X-Received: by 10.112.164.101 with SMTP id yp5mr13301175lbb.82.1422528041508; Thu, 29 Jan 2015 02:40:41 -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 h5csp1719422lbj; Thu, 29 Jan 2015 02:40:40 -0800 (PST) X-Received: by 10.224.7.3 with SMTP id b3mr10784qab.71.1422528039902; Thu, 29 Jan 2015 02:40:39 -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 kv9si5847121qcb.21.2015.01.29.02.40.38 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 29 Jan 2015 02:40:39 -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 1YGmWb-0007KY-1U; Thu, 29 Jan 2015 10:40:37 +0000 Received: from mail-lb0-f177.google.com ([209.85.217.177]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YGmWI-0007Id-7p for lng-odp@lists.linaro.org; Thu, 29 Jan 2015 10:40:18 +0000 Received: by mail-lb0-f177.google.com with SMTP id p9so26551312lbv.8 for ; Thu, 29 Jan 2015 02:40:12 -0800 (PST) X-Received: by 10.112.125.4 with SMTP id mm4mr13369509lbb.86.1422528012704; Thu, 29 Jan 2015 02:40:12 -0800 (PST) Received: from macmini.lan (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id y11sm2037670lba.5.2015.01.29.02.40.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jan 2015 02:40:12 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Thu, 29 Jan 2015 11:39:54 +0100 Message-Id: <1422528008-29845-3-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422528008-29845-1-git-send-email-ola.liljedahl@linaro.org> References: <1422528008-29845-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 02/16] api: odp_pktio.h: odp_pktio_mac_addr() return bufsz 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 modified to pass output buffer size by reference and the variable is updated with the number of bytes written on success or the minimum required buffer size should it be too small. odp_pktio_mac_addr() returns 0 on success and <0 on failure. Updated the implementation and usages of this call to match. 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 | 13 +++++------ platform/linux-generic/odp_packet_io.c | 17 +++++++++------ test/validation/odp_pktio.c | 25 ++++++++++++++-------- 3 files changed, 34 insertions(+), 21 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..019cffe 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -159,14 +159,15 @@ int odp_pktio_promisc_mode(odp_pktio_t id); /** * Get the default 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 + * @param[in,out] bufsz Size of output buffer, updated with size of data + * actually written or minimum required buffer size * - * @retval Number of bytes written on success, 0 on failure. + * @return 0 on success and '*bufsz' updated with size of data written + * @retval <0 on failure and '*bufsz' updated with required buffer size */ -size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, - size_t addr_size); +int odp_pktio_mac_addr(odp_pktio_t hdl, void *buf, size_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..0dcd85b 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -798,18 +798,22 @@ 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) +int odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, + size_t *addr_size) { pktio_entry_t *entry; - if (addr_size < ETH_ALEN) - return 0; + if (*addr_size < ETH_ALEN) { + /* Output buffer too small + * Update *addr_size with required size */ + *addr_size = ETH_ALEN; + 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); @@ -839,5 +843,6 @@ size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, unlock_entry(entry); - return ETH_ALEN; + *addr_size = ETH_ALEN; + return 0; } diff --git a/test/validation/odp_pktio.c b/test/validation/odp_pktio.c index 0985771..46155fd 100644 --- a/test/validation/odp_pktio.c +++ b/test/validation/odp_pktio.c @@ -49,13 +49,18 @@ static void pktio_pkt_set_macs(odp_packet_t pkt, { uint32_t len; odph_ethhdr_t *eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, &len); + size_t bufsz; int ret; - ret = odp_pktio_mac_addr(src->id, ð->src, sizeof(eth->src)); - CU_ASSERT(ret == ODPH_ETHADDR_LEN); + bufsz = sizeof(eth->src); + ret = odp_pktio_mac_addr(src->id, ð->src, &bufsz); + CU_ASSERT(ret == 0); + CU_ASSERT(bufsz == ODPH_ETHADDR_LEN); - ret = odp_pktio_mac_addr(dst->id, ð->dst, sizeof(eth->dst)); - CU_ASSERT(ret == ODPH_ETHADDR_LEN); + bufsz = sizeof(eth->dst); + ret = odp_pktio_mac_addr(dst->id, ð->dst, &bufsz); + CU_ASSERT(ret == 0); + CU_ASSERT(bufsz == ODPH_ETHADDR_LEN); } static int pktio_pkt_set_seq(odp_packet_t pkt) @@ -450,22 +455,24 @@ 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; + size_t mac_len = sizeof(mac_addr); 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); + ret = odp_pktio_mac_addr(pktio, mac_addr, &mac_len); + CU_ASSERT(ret == 0); 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. */ - mac_len = odp_pktio_mac_addr(pktio, mac_addr, 2); - CU_ASSERT(0 == mac_len); + /* Fail case: wrong addr_size. Expected <0. */ + mac_len = 2; + ret = odp_pktio_mac_addr(pktio, mac_addr, &mac_len); + CU_ASSERT(ret < 0); ret = odp_pktio_close(pktio); CU_ASSERT(0 == ret);