diff mbox

[PATCHv2,3/5] linux-generic: pktio: add support for netmap VALE and pipe virtual ports

Message ID 1453488486-12176-4-git-send-email-stuart.haslam@linaro.org
State New
Headers show

Commit Message

Stuart Haslam Jan. 22, 2016, 6:48 p.m. UTC
As well as connections to a physical network interface the netmap API
also supports connections to two different types for virtual ports, VALE
switch ports and netmap pipe ports. VALE is a virtual switch implemented
in the netmap kernel module, it works as a learning bridge and is designed
to be used for connections between virtual machines. netmap pipes connect
two virtual netmap ports with a crossover connection, they can be used in
a setup where a master process works as a dispatcher towards slave
processes.

Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
---
 platform/linux-generic/include/odp_packet_netmap.h |  2 ++
 platform/linux-generic/pktio/netmap.c              | 29 +++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_packet_netmap.h b/platform/linux-generic/include/odp_packet_netmap.h
index 7caa92f..5ebdb6a 100644
--- a/platform/linux-generic/include/odp_packet_netmap.h
+++ b/platform/linux-generic/include/odp_packet_netmap.h
@@ -22,6 +22,8 @@  typedef struct {
 	int sockfd;			/**< control socket */
 	unsigned char if_mac[ETH_ALEN]; /**< eth mac address */
 	char ifname[IF_NAMESIZE];	/**< interface name to be used in ioctl */
+	odp_bool_t is_vale;		/**< is a connection to vale switch */
+	odp_bool_t is_pipe;		/**< is a netmap pipe */
 } pkt_netmap_t;
 
 #endif
diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
index f15ffff..639afa8 100644
--- a/platform/linux-generic/pktio/netmap.c
+++ b/platform/linux-generic/pktio/netmap.c
@@ -128,7 +128,10 @@  static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry,
 	snprintf(pktio_entry->s.name, sizeof(pktio_entry->s.name), "%s",
 		 netdev);
 
-	if (strncmp(netdev, "netmap:", 7) == 0) {
+	if (strncmp(netdev, "vale", 4) == 0) {
+		prefix = "";
+		pkt_nm->is_vale = 1;
+	} else if (strncmp(netdev, "netmap:", 7) == 0) {
 		netdev += 7;
 		prefix = "";
 	} else {
@@ -151,11 +154,19 @@  static int netmap_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry,
 		goto error;
 	}
 
+	if (pkt_nm->tx_desc->req.nr_flags & NR_REG_PIPE_MASTER ||
+	    pkt_nm->tx_desc->req.nr_flags & NR_REG_PIPE_SLAVE) {
+		pkt_nm->is_pipe = 1;
+	}
+
 	if (mmap_desc.mem == NULL) {
 		mmap_desc.mem = pkt_nm->rx_desc->mem;
 		mmap_desc.memsize = pkt_nm->rx_desc->memsize;
 	}
 
+	if (pkt_nm->is_vale || pkt_nm->is_pipe)
+		return 0;
+
 	sockfd = socket(AF_INET, SOCK_DGRAM, 0);
 	if (sockfd == -1) {
 		ODP_ERR("Cannot get device control socket\n");
@@ -334,24 +345,40 @@  static int netmap_send(pktio_entry_t *pktio_entry, odp_packet_t pkt_table[],
 
 static int netmap_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr)
 {
+	if (pktio_entry->s.pkt_nm.is_vale || pktio_entry->s.pkt_nm.is_pipe)
+		return 0;
+
 	memcpy(mac_addr, pktio_entry->s.pkt_nm.if_mac, ETH_ALEN);
 	return ETH_ALEN;
 }
 
 static int netmap_mtu_get(pktio_entry_t *pktio_entry)
 {
+	if (pktio_entry->s.pkt_nm.is_vale || pktio_entry->s.pkt_nm.is_pipe)
+		return INT_MAX;
+
 	return mtu_get_fd(pktio_entry->s.pkt_nm.sockfd, pktio_entry->s.name);
 }
 
 static int netmap_promisc_mode_set(pktio_entry_t *pktio_entry,
 				   odp_bool_t enable)
 {
+	if (pktio_entry->s.pkt_nm.is_vale || pktio_entry->s.pkt_nm.is_pipe) {
+		__odp_errno = ENOTSUP;
+		return -1;
+	}
+
 	return promisc_mode_set_fd(pktio_entry->s.pkt_nm.sockfd,
 				   pktio_entry->s.name, enable);
 }
 
 static int netmap_promisc_mode_get(pktio_entry_t *pktio_entry)
 {
+	if (pktio_entry->s.pkt_nm.is_pipe || pktio_entry->s.pkt_nm.is_vale) {
+		__odp_errno = ENOTSUP;
+		return -1;
+	}
+
 	return promisc_mode_get_fd(pktio_entry->s.pkt_nm.sockfd,
 				   pktio_entry->s.name);
 }