diff mbox series

[API-NEXT,v5,2/3] linux-gen: pktio: implement MAC address set function

Message ID 1507626011-15870-3-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v5,1/3] api: packet_io: add MAC address set function | expand

Commit Message

Github ODP bot Oct. 10, 2017, 9 a.m. UTC
From: Bogdan Pricope <bogdan.pricope@linaro.org>


Add implement of MAC address set API. It calls packet IO
specific MAC address set function.

Signed-off-by: Bogdan Pricope <bogdan.pricope@linaro.org>

---
/** Email created from pull request 203 (bogdanPricope:set_mac_pr)
 ** https://github.com/Linaro/odp/pull/203
 ** Patch: https://github.com/Linaro/odp/pull/203.patch
 ** Base sha: bf803098eb1518dfb9e719071256fe22700b8c72
 ** Merge commit sha: 9741b2bb193f1cb28f8dd4bf382bc598e1dbd5ef
 **/
 .../linux-generic/include/odp_packet_io_internal.h |  1 +
 platform/linux-generic/odp_packet_io.c             | 36 ++++++++++++++++++++++
 platform/linux-generic/pktio/dpdk.c                |  1 +
 platform/linux-generic/pktio/ipc.c                 |  1 +
 platform/linux-generic/pktio/loop.c                |  1 +
 platform/linux-generic/pktio/netmap.c              |  1 +
 platform/linux-generic/pktio/pcap.c                |  1 +
 platform/linux-generic/pktio/socket.c              |  1 +
 platform/linux-generic/pktio/socket_mmap.c         |  1 +
 platform/linux-generic/pktio/tap.c                 |  1 +
 10 files changed, 45 insertions(+)
diff mbox series

Patch

diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
index 1a4e345f5..41a1be108 100644
--- a/platform/linux-generic/include/odp_packet_io_internal.h
+++ b/platform/linux-generic/include/odp_packet_io_internal.h
@@ -210,6 +210,7 @@  typedef struct pktio_if_ops {
 	int (*promisc_mode_set)(pktio_entry_t *pktio_entry,  int enable);
 	int (*promisc_mode_get)(pktio_entry_t *pktio_entry);
 	int (*mac_get)(pktio_entry_t *pktio_entry, void *mac_addr);
+	int (*mac_set)(pktio_entry_t *pktio_entry, const void *mac_addr);
 	int (*link_status)(pktio_entry_t *pktio_entry);
 	int (*capability)(pktio_entry_t *pktio_entry,
 			  odp_pktio_capability_t *capa);
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index 64ec1f670..f81eb792f 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -895,6 +895,42 @@  int odp_pktio_mac_addr(odp_pktio_t hdl, void *mac_addr, int addr_size)
 	return ret;
 }
 
+int odp_pktio_mac_addr_set(odp_pktio_t hdl, const void *mac_addr, int addr_size)
+{
+	pktio_entry_t *entry;
+	int ret = -1;
+
+	if (addr_size < ETH_ALEN) {
+		/* Input buffer too small */
+		return -1;
+	}
+
+	entry = get_pktio_entry(hdl);
+	if (entry == NULL) {
+		ODP_DBG("pktio entry %d does not exist\n", hdl);
+		return -1;
+	}
+
+	lock_entry(entry);
+
+	if (odp_unlikely(is_free(entry))) {
+		unlock_entry(entry);
+		ODP_DBG("already freed pktio\n");
+		return -1;
+	}
+
+	if (entry->s.state == PKTIO_STATE_STARTED) {
+		unlock_entry(entry);
+		return -1;
+	}
+
+	if (entry->s.ops->mac_set)
+		ret = entry->s.ops->mac_set(entry, mac_addr);
+
+	unlock_entry(entry);
+	return ret;
+}
+
 int odp_pktio_link_status(odp_pktio_t hdl)
 {
 	pktio_entry_t *entry;
diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c
index 26ca0d6b4..45153af82 100644
--- a/platform/linux-generic/pktio/dpdk.c
+++ b/platform/linux-generic/pktio/dpdk.c
@@ -1542,6 +1542,7 @@  const pktio_if_ops_t dpdk_pktio_ops = {
 	.promisc_mode_set = dpdk_promisc_mode_set,
 	.promisc_mode_get = dpdk_promisc_mode_get,
 	.mac_get = dpdk_mac_addr_get,
+	.mac_set = NULL,
 	.capability = dpdk_capability,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,
diff --git a/platform/linux-generic/pktio/ipc.c b/platform/linux-generic/pktio/ipc.c
index a7f346ae5..c8880ae93 100644
--- a/platform/linux-generic/pktio/ipc.c
+++ b/platform/linux-generic/pktio/ipc.c
@@ -790,6 +790,7 @@  const pktio_if_ops_t ipc_pktio_ops = {
 	.promisc_mode_set = NULL,
 	.promisc_mode_get = NULL,
 	.mac_get = ipc_mac_addr_get,
+	.mac_set = NULL,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,
 	.config = NULL
diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c
index 428b6cebd..eba6d3b03 100644
--- a/platform/linux-generic/pktio/loop.c
+++ b/platform/linux-generic/pktio/loop.c
@@ -265,6 +265,7 @@  const pktio_if_ops_t loopback_pktio_ops = {
 	.promisc_mode_set = loopback_promisc_mode_set,
 	.promisc_mode_get = loopback_promisc_mode_get,
 	.mac_get = loopback_mac_addr_get,
+	.mac_set = NULL,
 	.link_status = loopback_link_status,
 	.capability = loopback_capability,
 	.pktin_ts_res = NULL,
diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
index 4d771fcb4..9ee412f0a 100644
--- a/platform/linux-generic/pktio/netmap.c
+++ b/platform/linux-generic/pktio/netmap.c
@@ -962,6 +962,7 @@  const pktio_if_ops_t netmap_pktio_ops = {
 	.promisc_mode_set = netmap_promisc_mode_set,
 	.promisc_mode_get = netmap_promisc_mode_get,
 	.mac_get = netmap_mac_addr_get,
+	.mac_set = NULL,
 	.capability = netmap_capability,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,
diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c
index 783b85a9c..596bf6f28 100644
--- a/platform/linux-generic/pktio/pcap.c
+++ b/platform/linux-generic/pktio/pcap.c
@@ -440,6 +440,7 @@  const pktio_if_ops_t pcap_pktio_ops = {
 	.promisc_mode_set = pcapif_promisc_mode_set,
 	.promisc_mode_get = pcapif_promisc_mode_get,
 	.mac_get = pcapif_mac_addr_get,
+	.mac_set = NULL,
 	.capability = pcapif_capability,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,
diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c
index 5841e2448..0a80035f5 100644
--- a/platform/linux-generic/pktio/socket.c
+++ b/platform/linux-generic/pktio/socket.c
@@ -873,6 +873,7 @@  const pktio_if_ops_t sock_mmsg_pktio_ops = {
 	.promisc_mode_set = sock_promisc_mode_set,
 	.promisc_mode_get = sock_promisc_mode_get,
 	.mac_get = sock_mac_addr_get,
+	.mac_set = NULL,
 	.link_status = sock_link_status,
 	.capability = sock_capability,
 	.pktin_ts_res = NULL,
diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c
index f71180238..67c5b2067 100644
--- a/platform/linux-generic/pktio/socket_mmap.c
+++ b/platform/linux-generic/pktio/socket_mmap.c
@@ -730,6 +730,7 @@  const pktio_if_ops_t sock_mmap_pktio_ops = {
 	.promisc_mode_set = sock_mmap_promisc_mode_set,
 	.promisc_mode_get = sock_mmap_promisc_mode_get,
 	.mac_get = sock_mmap_mac_addr_get,
+	.mac_set = NULL,
 	.link_status = sock_mmap_link_status,
 	.capability = sock_mmap_capability,
 	.pktin_ts_res = NULL,
diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c
index 917db006e..ed4479445 100644
--- a/platform/linux-generic/pktio/tap.c
+++ b/platform/linux-generic/pktio/tap.c
@@ -391,6 +391,7 @@  const pktio_if_ops_t tap_pktio_ops = {
 	.promisc_mode_set = tap_promisc_mode_set,
 	.promisc_mode_get = tap_promisc_mode_get,
 	.mac_get = tap_mac_addr_get,
+	.mac_set = NULL,
 	.capability = tap_capability,
 	.pktin_ts_res = NULL,
 	.pktin_ts_from_ns = NULL,