DPDK patches and discussions
 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: [dpdk-dev] [PATCH v2 2/2] net/pcap: physical interface MAC support
Date: Tue, 17 Apr 2018 15:53:10 +0300	[thread overview]
Message-ID: <1523969590-40071-2-git-send-email-juhamatti.kuusisaari@coriant.com> (raw)
In-Reply-To: <1523969590-40071-1-git-send-email-juhamatti.kuusisaari@coriant.com>

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>
---
 v2:
 * Fix whitespace
---
 drivers/net/pcap/rte_eth_pcap.c | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index d2aba1c..4d6db55 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -619,18 +619,22 @@ eth_link_update(struct rte_eth_dev *dev __rte_unused,
 	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;
+		/* Get link status, speed and duplex of the 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;
+			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_speed =
+				ethtool_cmd_speed(&cmd);
 			dev->data->dev_link.link_duplex =
-				cmd.duplex ? ETH_LINK_FULL_DUPLEX : ETH_LINK_HALF_DUPLEX;
+				cmd.duplex ?
+				ETH_LINK_FULL_DUPLEX : ETH_LINK_HALF_DUPLEX;
 		}
 	}
 #endif /* RTE_LIBRTE_PMD_PCAP_IF_MAC_SUPPORT */
@@ -896,21 +900,30 @@ eth_from_pcaps_common(struct rte_vdev_device *vdev,
 			break;
 	}
 
-	if (pair == NULL)
+	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() */
+		/*
+		 * Use real interface mac addr, save name and
+		 * file descriptor for the 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;
+			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);
+				(*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 */
-- 
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 [dpdk-dev] [PATCH v2 1/2] " Juhamatti Kuusisaari
2018-04-17 12:53 ` Juhamatti Kuusisaari [this message]
2018-04-17 14:12 ` 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-2-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).