diff mbox

[NETMAP,2/2] linux-netmap: add per interface socket

Message ID 1427479000-25779-3-git-send-email-ciprian.barbu@linaro.org
State New
Headers show

Commit Message

Ciprian Barbu March 27, 2015, 5:56 p.m. UTC
This socket will later be useful to implement odp_pktio_mtu and similar

Signed-off-by: Ciprian Barbu <ciprian.barbu@linaro.org>
---
 platform/linux-netmap/include/odp_packet_netmap.h |  5 +++++
 platform/linux-netmap/odp_packet_io.c             |  2 ++
 platform/linux-netmap/odp_packet_netmap.c         | 23 +++++++++++++++--------
 3 files changed, 22 insertions(+), 8 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-netmap/include/odp_packet_netmap.h b/platform/linux-netmap/include/odp_packet_netmap.h
index 4b75a6d..d687fa0 100644
--- a/platform/linux-netmap/include/odp_packet_netmap.h
+++ b/platform/linux-netmap/include/odp_packet_netmap.h
@@ -60,4 +60,9 @@  int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[],
  */
 void pkt_netmap_mac_addr(pkt_netmap_t * const pkt_nm, void *mac_addr,
 			int addr_size);
+
+/**
+ * Get socket fd associated with this netmap pktio
+ */
+int pkt_netmap_sockfd(pkt_netmap_t * const pkt_nm);
 #endif
diff --git a/platform/linux-netmap/odp_packet_io.c b/platform/linux-netmap/odp_packet_io.c
index 1957ad0..2c3b91b 100644
--- a/platform/linux-netmap/odp_packet_io.c
+++ b/platform/linux-netmap/odp_packet_io.c
@@ -697,6 +697,8 @@  static int sockfd_from_pktio_entry(pktio_entry_t *entry)
 		return entry->s.pkt_sock.sockfd;
 	case ODP_PKTIO_TYPE_SOCKET_MMAP:
 		return entry->s.pkt_sock_mmap.sockfd;
+	case ODP_PKTIO_TYPE_NETMAP:
+		return pkt_netmap_sockfd(&entry->s.pkt_nm);
 	default:
 		ODP_ABORT("Wrong socket type %d\n", entry->s.type);
 	}
diff --git a/platform/linux-netmap/odp_packet_netmap.c b/platform/linux-netmap/odp_packet_netmap.c
index 11954a2..a4236cf 100644
--- a/platform/linux-netmap/odp_packet_netmap.c
+++ b/platform/linux-netmap/odp_packet_netmap.c
@@ -51,6 +51,7 @@  typedef struct netmap_dev_t {
 	unsigned char if_mac[ETH_ALEN];
 	odp_ticketlock_t rx_lock;
 	odp_ticketlock_t tx_lock;
+	int sockfd;
 } netmap_dev_t;
 
 /** Eth buffer start offset from u32-aligned address to make sure the following
@@ -97,13 +98,7 @@  static int nm_do_ioctl(pkt_netmap_t * const pkt_nm, unsigned long cmd,
 	struct ethtool_value eval;
 	struct ifreq ifr;
 	int error;
-	int fd;
-
-	fd = socket(AF_INET, SOCK_DGRAM, 0);
-	if (fd < 0) {
-		ODP_ERR("Error: cannot get device control socket\n");
-		return -1;
-	}
+	int fd = pkt_nm->nm_dev->sockfd;
 
 	memset(&ifr, 0, sizeof(ifr));
 	strncpy(ifr.ifr_name, pkt_nm->nm_dev->ifname, sizeof(ifr.ifr_name));
@@ -136,7 +131,6 @@  static int nm_do_ioctl(pkt_netmap_t * const pkt_nm, unsigned long cmd,
 		break;
 	}
 done:
-	close(fd);
 	if (error)
 		ODP_ERR("ioctl err %d %lu: %s\n", error, cmd, strerror(errno));
 
@@ -183,6 +177,7 @@  int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev,
 {
 	char ifname[IFNAMSIZ];
 	int i, ret;
+	int sockfd;
 
 	if (nm_dev_cnt == MAX_DEVS) {
 		ODP_ERR("Maximum number of devices reached: %d\n", nm_dev_cnt);
@@ -248,6 +243,13 @@  int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev,
 		odp_thread_id(),
 		pkt_nm->desc->mem);
 
+	sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+	if (sockfd < 0) {
+		ODP_ERR("Error: cannot get device control socket\n");
+		return -1;
+	}
+	pkt_nm->nm_dev->sockfd = sockfd;
+
 	ret = nm_do_ioctl(pkt_nm, SIOCGIFFLAGS, 0);
 	if (ret)
 		return ret;
@@ -417,3 +419,8 @@  inline void pkt_netmap_mac_addr(pkt_netmap_t * const pkt_nm, void *mac_addr,
 
 	memcpy(mac_addr, pkt_nm->nm_dev->if_mac, ETH_ALEN);
 }
+
+inline int pkt_netmap_sockfd(pkt_netmap_t * const pkt_nm)
+{
+	return pkt_nm->nm_dev->sockfd;
+}