DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tero Aho <tero.aho@coriant.com>
To: <dev@dpdk.org>
Subject: [dpdk-dev] [PATCH 1/3] pcap: utilize underlying real interface properties
Date: Fri, 27 Feb 2015 15:42:38 +0200	[thread overview]
Message-ID: <1425044560-23397-2-git-send-email-tero.aho@coriant.com> (raw)
In-Reply-To: <1425044560-23397-1-git-send-email-tero.aho@coriant.com>

These changes set pcap interface mac address to the real underlying
interface address instead of the default one. Also real interface link
status, speed and duplex are reported when eth_link_update is called
for the pcap interface.

Signed-off-by: Tero Aho <tero.aho@coriant.com>
---
 lib/librte_pmd_pcap/rte_eth_pcap.c | 51 +++++++++++++++++++++++++++++++++++---
 1 file changed, 47 insertions(+), 4 deletions(-)

diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c
index 5e94930..289af28 100644
--- a/lib/librte_pmd_pcap/rte_eth_pcap.c
+++ b/lib/librte_pmd_pcap/rte_eth_pcap.c
@@ -43,6 +43,11 @@
 #include <rte_dev.h>

 #include <net/if.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <string.h>
+#include <linux/ethtool.h>
+#include <linux/sockios.h>

 #include <pcap.h>

@@ -102,6 +107,8 @@ struct pmd_internals {
        unsigned nb_tx_queues;
        int if_index;
        int single_iface;
+       const char *if_name;
+       int if_fd;
 };

 const char *valid_arguments[] = {
@@ -451,6 +458,26 @@ static int
 eth_link_update(struct rte_eth_dev *dev __rte_unused,
                int wait_to_complete __rte_unused)
 {
+       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;
+               }
+       }
        return 0;
 }

@@ -736,11 +763,24 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues,
        (*internals)->nb_rx_queues = nb_rx_queues;
        (*internals)->nb_tx_queues = nb_tx_queues;

-       if (pair == NULL)
+       if (pair == NULL) {
                (*internals)->if_index = 0;
-       else
+       } else {
+               /* use real inteface mac addr, save name and fd for eth_link_update */
                (*internals)->if_index = if_nametoindex(pair->value);
-
+               (*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)) {
+                               data->mac_addrs = rte_zmalloc_socket(NULL, ETHER_ADDR_LEN, 0, numa_node);
+                               if (data->mac_addrs)
+                                       rte_memcpy(data->mac_addrs, ifr.ifr_addr.sa_data, ETHER_ADDR_LEN);
+                       }
+               }
+       }
        pci_dev->numa_node = numa_node;

        data->dev_private = *internals;
@@ -749,7 +789,8 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues,
        data->nb_rx_queues = (uint16_t)nb_rx_queues;
        data->nb_tx_queues = (uint16_t)nb_tx_queues;
        data->dev_link = pmd_link;
-       data->mac_addrs = &eth_addr;
+       if (data->mac_addrs == NULL)
+               data->mac_addrs = &eth_addr;
        strncpy(data->name,
                (*eth_dev)->data->name, strlen((*eth_dev)->data->name));

@@ -758,6 +799,8 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues,
        (*eth_dev)->pci_dev = pci_dev;
        (*eth_dev)->driver = &rte_pcap_pmd;

+       eth_link_update((*eth_dev), 0);
+
        return 0;

        error: if (data)
--
1.9.1


============================================================
The information contained in this message may be privileged
and confidential and protected from disclosure. If the reader
of this message is not the intended recipient, or an employee
or agent responsible for delivering this message to the
intended recipient, you are hereby notified that any reproduction,
dissemination or distribution of this communication is strictly
prohibited. If you have received this communication in error,
please notify us immediately by replying to the message and
deleting it from your computer. Thank you. Coriant-Tellabs
============================================================

  reply	other threads:[~2015-02-27 13:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-27 13:42 [dpdk-dev] [PATCH 0/3] pcap pmd improvements Tero Aho
2015-02-27 13:42 ` Tero Aho [this message]
2015-04-28 13:49   ` [dpdk-dev] [PATCH 1/3] pcap: utilize underlying real interface properties Mcnamara, John
2015-02-27 13:42 ` [dpdk-dev] [PATCH 2/3] pcap: add support for jumbo frames Tero Aho
2015-04-28 13:52   ` Mcnamara, John
2015-06-10  9:08   ` [dpdk-dev] [dpdk-dev,2/3] " Maxim Uvarov
2015-06-10  9:43     ` Mcnamara, John
2015-02-27 13:42 ` [dpdk-dev] [PATCH 3/3] pcap: add byte and error counters into statistics Tero Aho
2015-04-28 14:00   ` Mcnamara, John
2015-02-27 13:50 ` [dpdk-dev] [PATCH 0/3] pcap pmd improvements Thomas Monjalon
2015-04-28 10:09 ` Thomas Monjalon
2015-04-28 12:09   ` Mcnamara, John
2015-04-29  8:29     ` Nicolas Pernas Maradei
2015-04-28 12:27 ` Mcnamara, John
2015-04-29  0:30 [dpdk-dev] [PATCH 1/3] pcap: utilize underlying real interface properties Nicolás Pernas Maradei

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=1425044560-23397-2-git-send-email-tero.aho@coriant.com \
    --to=tero.aho@coriant.com \
    --cc=dev@dpdk.org \
    /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).