[dpdk-dev,2/3] net/af_packet: add accessor for iface

Message ID 1495044215-16915-2-git-send-email-ciwillia@brocade.com (mailing list archive)
State Rejected, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Chas Williams May 17, 2017, 6:03 p.m. UTC
  Provide an accessor for the name of the underlying linux interface
used by the AF_PACKET-based interface.

Signed-off-by: Charles (Chas) Williams <ciwillia@brocade.com>
---
 drivers/net/af_packet/Makefile                     |  2 +
 drivers/net/af_packet/rte_eth_af_packet.c          | 17 +++++++
 drivers/net/af_packet/rte_eth_af_packet.h          | 55 ++++++++++++++++++++++
 .../net/af_packet/rte_pmd_af_packet_version.map    |  6 +++
 4 files changed, 80 insertions(+)
 create mode 100644 drivers/net/af_packet/rte_eth_af_packet.h
  

Comments

Ferruh Yigit May 22, 2017, 9:39 a.m. UTC | #1
Hi Chas,

On 5/17/2017 7:03 PM, Charles (Chas) Williams wrote:
> Provide an accessor for the name of the underlying linux interface
> used by the AF_PACKET-based interface.

This patch provides a PMD specific API to get PMD internal data
(internals->if_name).

I think we should avoid PMD specific APIs if possible.

internals->if_name is provided by application, as devargs to af_packet
(iface=..), so app already knows port_id -> if_name mapping.

OR

With rte_eth_dev_info_get() af_packet returns the if_index for
underlying interface, it is possible to use if_indextoname() to get ifname.

Because above methods exists to get if_name, I think this API is not
necessary.

> 
> Signed-off-by: Charles (Chas) Williams <ciwillia@brocade.com>

<...>
  
Chas Williams May 22, 2017, 1:20 p.m. UTC | #2
On 05/22/2017 05:39 AM, Ferruh Yigit wrote:
> Hi Chas,
>
> On 5/17/2017 7:03 PM, Charles (Chas) Williams wrote:
>> Provide an accessor for the name of the underlying linux interface
>> used by the AF_PACKET-based interface.
>
> This patch provides a PMD specific API to get PMD internal data
> (internals->if_name).
>
> I think we should avoid PMD specific APIs if possible.
>
> internals->if_name is provided by application, as devargs to af_packet
> (iface=..), so app already knows port_id -> if_name mapping.
>
> OR
>
> With rte_eth_dev_info_get() af_packet returns the if_index for
> underlying interface, it is possible to use if_indextoname() to get ifname.
>
> Because above methods exists to get if_name, I think this API is not
> necessary.

I will go this route then.

>>
>> Signed-off-by: Charles (Chas) Williams <ciwillia@brocade.com>
>
> <...>
>
  

Patch

diff --git a/drivers/net/af_packet/Makefile b/drivers/net/af_packet/Makefile
index 70d517c..5ea058c 100644
--- a/drivers/net/af_packet/Makefile
+++ b/drivers/net/af_packet/Makefile
@@ -50,4 +50,6 @@  CFLAGS += $(WERROR_FLAGS)
 #
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET) += rte_eth_af_packet.c
 
+SYMLINK-y-include += rte_eth_af_packet.h
+
 include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index ce4dc07..6927f70 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -43,6 +43,8 @@ 
 #include <rte_kvargs.h>
 #include <rte_vdev.h>
 
+#include "rte_eth_af_packet.h"
+
 #include <linux/if_ether.h>
 #include <linux/if_packet.h>
 #include <arpa/inet.h>
@@ -125,6 +127,21 @@  static struct rte_eth_link pmd_link = {
 	.link_autoneg = ETH_LINK_SPEED_AUTONEG
 };
 
+int
+rte_af_packet_get_ifname(uint8_t port, char *buf, size_t len)
+{
+	struct rte_eth_dev *dev;
+	struct pmd_internals *internals;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+	internals = dev->data->dev_private;
+	snprintf(buf, len, "%s", internals->if_name);
+
+	return 0;
+}
+
 static uint16_t
 eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 {
diff --git a/drivers/net/af_packet/rte_eth_af_packet.h b/drivers/net/af_packet/rte_eth_af_packet.h
new file mode 100644
index 0000000..c5276f5
--- /dev/null
+++ b/drivers/net/af_packet/rte_eth_af_packet.h
@@ -0,0 +1,55 @@ 
+/*-
+ * BSD LICENSE
+ *
+ * Copyright (c) 2017 Brocade Communications Systems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in
+ *     the documentation and/or other materials provided with the
+ *     distribution.
+ *   * Neither the name of Intel Corporation nor the names of its
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_ETH_AF_PACKET_H_
+#define _RTE_ETH_AF_PACKET_H_
+
+#include <rte_ethdev.h>
+
+/**
+ * Get the name of the underlying kernel interface assocated
+ * with this AF_PACKET device.
+ *
+ * @param port
+ *  The port identifier of the AF_PACKET device.
+ * @param buf
+ *  The buffer to stored the queried ifname
+ * @param len
+ *  The length of buf
+ *
+ * @return
+ *  0 on success, -1 on failure
+ */
+int rte_af_packet_get_ifname(uint8_t port, char *buf, size_t len);
+
+#endif /* _RTE_ETH_AF_PACKET_H_ */
diff --git a/drivers/net/af_packet/rte_pmd_af_packet_version.map b/drivers/net/af_packet/rte_pmd_af_packet_version.map
index ef35398..2231699 100644
--- a/drivers/net/af_packet/rte_pmd_af_packet_version.map
+++ b/drivers/net/af_packet/rte_pmd_af_packet_version.map
@@ -2,3 +2,9 @@  DPDK_2.0 {
 
 	local: *;
 };
+
+DPDK_17.08 {
+	global:
+
+	rte_af_packet_get_ifname;
+};