diff mbox series

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

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

Commit Message

Github ODP bot Dec. 14, 2017, midnight 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: d96a8207591fbcaac25b79286d7d72a537354c1f
 ** Merge commit sha: 7371c04c5dc9238b8e9f601e6650b4bc36589be9
 **/
 .../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 96df72724..87c837ea3 100644
--- a/platform/linux-generic/pktio/loop.c
+++ b/platform/linux-generic/pktio/loop.c
@@ -21,6 +21,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};
@@ -30,15 +33,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;
@@ -212,6 +226,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;
 }