All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juhamatti Kuusisaari <Juhamatti.Kuusisaari@coriant.com>
To: <ferruh.yigit@intel.com>
Cc: <dev@dpdk.org>, Juhamatti Kuusisaari <juhamatti.kuusisaari@coriant.com>
Subject: [PATCH v2 1/2] net/pcap: physical interface MAC support
Date: Tue, 17 Apr 2018 15:53:09 +0300	[thread overview]
Message-ID: <1523969590-40071-1-git-send-email-juhamatti.kuusisaari@coriant.com> (raw)

Support for PCAP MAC address using physical interface MAC.
Support for getting proper link status, speed and duplex.

Signed-off-by: Juhamatti Kuusisaari <juhamatti.kuusisaari@coriant.com>
---
 config/common_base              |  1 +
 drivers/net/pcap/rte_eth_pcap.c | 52 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/config/common_base b/config/common_base
index c2b0d91..9804585 100644
--- a/config/common_base
+++ b/config/common_base
@@ -410,6 +410,7 @@ CONFIG_RTE_LIBRTE_PMD_NULL=y
 # Compile software PMD backed by PCAP files
 #
 CONFIG_RTE_LIBRTE_PMD_PCAP=n
+CONFIG_RTE_LIBRTE_PMD_PCAP_IF_MAC_SUPPORT=n
 
 #
 # Compile example software rings based PMD
diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index c1571e1..d2aba1c 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -7,6 +7,13 @@
 #include <time.h>
 
 #include <net/if.h>
+#ifdef RTE_LIBRTE_PMD_PCAP_IF_MAC_SUPPORT
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <string.h>
+#include <linux/ethtool.h>
+#include <linux/sockios.h>
+#endif /* RTE_LIBRTE_PMD_PCAP_IF_MAC_SUPPORT */
 
 #include <pcap.h>
 
@@ -67,6 +74,10 @@ struct pmd_internals {
 	struct pcap_tx_queue tx_queue[RTE_PMD_PCAP_MAX_QUEUES];
 	int if_index;
 	int single_iface;
+#ifdef RTE_LIBRTE_PMD_PCAP_IF_MAC_SUPPORT
+	const char *if_name;
+	int if_fd;
+#endif /* RTE_LIBRTE_PMD_PCAP_IF_MAC_SUPPORT */
 };
 
 struct pmd_devargs {
@@ -602,6 +613,27 @@ static int
 eth_link_update(struct rte_eth_dev *dev __rte_unused,
 		int wait_to_complete __rte_unused)
 {
+#ifdef RTE_LIBRTE_PMD_PCAP_IF_MAC_SUPPORT
+	struct ifreq ifr;
+	struct ethtool_cmd cmd;
+	struct pmd_internals *internals = dev->data->dev_private;
+
+	if (internals->if_name && (internals->if_fd != -1)) {
+		/* Get link status, speed and duplex from the underlying interface */
+		strncpy(ifr.ifr_name, internals->if_name, sizeof(ifr.ifr_name)-1);
+		ifr.ifr_name[sizeof(ifr.ifr_name)-1] = 0;
+		if (!ioctl(internals->if_fd, SIOCGIFFLAGS, &ifr))
+			dev->data->dev_link.link_status = (ifr.ifr_flags & IFF_UP) ? 1 : 0;
+
+		cmd.cmd = ETHTOOL_GSET;
+		ifr.ifr_data = (void *)&cmd;
+		if (!ioctl(internals->if_fd, SIOCETHTOOL, &ifr)) {
+			dev->data->dev_link.link_speed = ethtool_cmd_speed(&cmd);
+			dev->data->dev_link.link_duplex =
+				cmd.duplex ? ETH_LINK_FULL_DUPLEX : ETH_LINK_HALF_DUPLEX;
+		}
+	}
+#endif /* RTE_LIBRTE_PMD_PCAP_IF_MAC_SUPPORT */
 	return 0;
 }
 
@@ -866,8 +898,26 @@ eth_from_pcaps_common(struct rte_vdev_device *vdev,
 
 	if (pair == NULL)
 		(*internals)->if_index = 0;
-	else
+	else {
 		(*internals)->if_index = if_nametoindex(pair->value);
+#ifdef RTE_LIBRTE_PMD_PCAP_IF_MAC_SUPPORT
+		/* Use real interface mac addr, save name and fd for eth_link_update() */
+		(*internals)->if_name = strdup(pair->value);
+		(*internals)->if_fd = socket(AF_INET, SOCK_DGRAM, 0);
+		if ((*internals)->if_fd != -1) {
+			struct ifreq ifr;
+			strncpy(ifr.ifr_name, pair->value, sizeof(ifr.ifr_name)-1);
+			ifr.ifr_name[sizeof(ifr.ifr_name)-1] = 0;
+			if (!ioctl((*internals)->if_fd, SIOCGIFHWADDR, &ifr)) {
+				(*eth_dev)->data->mac_addrs = rte_zmalloc_socket(NULL, ETHER_ADDR_LEN, 0, vdev->device.numa_node);
+				rte_memcpy((*eth_dev)->data->mac_addrs, ifr.ifr_addr.sa_data, ETHER_ADDR_LEN);
+			}
+		}
+#endif /* RTE_LIBRTE_PMD_PCAP_IF_MAC_SUPPORT */
+	}
+#ifdef RTE_LIBRTE_PMD_PCAP_IF_MAC_SUPPORT
+	eth_link_update((*eth_dev), 0);
+#endif /* RTE_LIBRTE_PMD_PCAP_IF_MAC_SUPPORT */
 
 	return 0;
 }
-- 
2.8.1

             reply	other threads:[~2018-04-17 12:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-17 12:53 Juhamatti Kuusisaari [this message]
2018-04-17 12:53 ` [PATCH v2 2/2] net/pcap: physical interface MAC support Juhamatti Kuusisaari
2018-04-17 14:12 ` [PATCH v2 1/2] " Ferruh Yigit
2018-04-18  4:35   ` Kuusisaari, Juhamatti
2018-04-18 13:44     ` Ferruh Yigit
2018-04-19  5:16       ` Kuusisaari, Juhamatti
2018-04-19 10:49         ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1523969590-40071-1-git-send-email-juhamatti.kuusisaari@coriant.com \
    --to=juhamatti.kuusisaari@coriant.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.