diff mbox series

[API-NEXT,v4,1/5] linux-gen: loop: support multiple loop devices

Message ID 1513875646-25336-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v4,1/5] linux-gen: loop: support multiple loop devices | expand

Commit Message

Github ODP bot Dec. 21, 2017, 5 p.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Add support for several loop devices "loop%d". Use "loop" instead of
"loop0" for backwards compatibility.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 340 (lumag:ipsec-api-example)
 ** https://github.com/Linaro/odp/pull/340
 ** Patch: https://github.com/Linaro/odp/pull/340.patch
 ** Base sha: c38fc105f0e9a88dd4ebb4d9e7ac9e1160466322
 ** Merge commit sha: 82c8f20abfb7a55542ca78d82428d0c4e42670d1
 **/
 .../linux-generic/include/odp_packet_io_internal.h  |  1 +
 platform/linux-generic/pktio/loop.c                 | 21 ++++++++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)
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 598b1ad50..25e037182 100644
--- a/platform/linux-generic/include/odp_packet_io_internal.h
+++ b/platform/linux-generic/include/odp_packet_io_internal.h
@@ -53,6 +53,7 @@  struct pktio_if_ops;
 typedef struct {
 	odp_queue_t loopq;		/**< loopback queue for "loop" device */
 	odp_bool_t promisc;		/**< promiscuous mode state */
+	uint8_t idx;			/**< index of "loop" device */
 } pkt_loop_t;
 
 #ifdef HAVE_PCAP
diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c
index f887e1a2d..698d363e4 100644
--- a/platform/linux-generic/pktio/loop.c
+++ b/platform/linux-generic/pktio/loop.c
@@ -22,6 +22,9 @@ 
 #include <errno.h>
 #include <inttypes.h>
 #include <limits.h>
+#include <stdlib.h>
+
+#define MAX_LOOP 16
 
 /* MAC address for the "loop" interface */
 static const char pktio_loop_mac[] = {0x02, 0xe9, 0x34, 0x80, 0x73, 0x01};
@@ -31,15 +34,26 @@  static int loopback_stats_reset(pktio_entry_t *pktio_entry);
 static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry,
 			 const char *devname, odp_pool_t pool ODP_UNUSED)
 {
-	if (strcmp(devname, "loop"))
-		return -1;
-
+	long idx;
 	char loopq_name[ODP_QUEUE_NAME_LEN];
 
+	if (!strcmp(devname, "loop")) {
+		idx = 0;
+	} else if (!strncmp(devname, "loop", 4)) {
+		char *end;
+
+		idx = strtol(devname + 4, &end, 10);
+		if (idx <= 0 || idx >= MAX_LOOP || *end)
+			return -1;
+	} else {
+		return -1;
+	}
+
 	snprintf(loopq_name, sizeof(loopq_name), "%" PRIu64 "-pktio_loopq",
 		 odp_pktio_to_u64(id));
 	pktio_entry->s.pkt_loop.loopq =
 		odp_queue_create(loopq_name, NULL);
+	pktio_entry->s.pkt_loop.idx = idx;
 
 	if (pktio_entry->s.pkt_loop.loopq == ODP_QUEUE_INVALID)
 		return -1;
@@ -213,6 +227,7 @@  static int loopback_mac_addr_get(pktio_entry_t *pktio_entry ODP_UNUSED,
 				 void *mac_addr)
 {
 	memcpy(mac_addr, pktio_loop_mac, ETH_ALEN);
+	((uint8_t *)mac_addr)[ETH_ALEN - 1] += pktio_entry->s.pkt_loop.idx;
 	return ETH_ALEN;
 }