diff mbox

[PATCHv2,02/16] api: odp_pktio.h: odp_pktio_mac_addr() return chars written or error

Message ID 1422610133-20756-3-git-send-email-ola.liljedahl@linaro.org
State New
Headers show

Commit Message

Ola Liljedahl Jan. 30, 2015, 9:28 a.m. UTC
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 <ola.liljedahl@linaro.org>
---
(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 mbox

Patch

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 <sys/types.h>
 #include <odp_std_types.h>
 #include <odp_platform_types.h>
 #include <odp_pool.h>
@@ -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);