[dpdk-dev,1/3] pcap: utilize underlying real interface properties

Message ID 1425044560-23397-2-git-send-email-tero.aho@coriant.com (mailing list archive)
State Rejected, archived
Headers

Commit Message

Tero Aho Feb. 27, 2015, 1:42 p.m. UTC
  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(-)

--
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
============================================================
  

Comments

John McNamara April 28, 2015, 1:49 p.m. UTC | #1
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Tero Aho
> Sent: Friday, February 27, 2015 1:43 PM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH 1/3] pcap: utilize underlying real interface
> properties
> 
> 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>

> ...
> +               /* 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);


Hi Tero,

I can see the benefit of setting the link status and speed etc. but this method seems a little fragile. What if there isn't an underlying interface, or all the interfaces are already bound to DPDK? Also I don't think the ethtool calls will work on FreeBSD as is.

So overall, I think this is a nack for this part of the patch. Perhaps a better approach would be to provide a function so that the calling application can set the parameters instead.

John
  

Patch

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)