[dpdk-dev] [PATCH 3/4] net/af_packet: promisicuous support

Charles (Chas) Williams ciwillia at brocade.com
Tue Jan 3 21:26:10 CET 2017


Add promiscuous support to the AF_PACKET PMD.  The underlying linux
device's IF_PROMISC flag is toggled to enable or disable.

Signed-off-by: Charles (Chas) Williams <ciwillia at brocade.com>
---
 drivers/net/af_packet/rte_eth_af_packet.c | 40 +++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index d8ac5c6..b01a8d1 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -441,6 +441,44 @@ eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	return 0;
 }
 
+static void
+eth_dev_change_flags(char *if_name, uint32_t flags, uint32_t mask)
+{
+	struct ifreq ifr;
+	int s;
+
+	s = socket(PF_INET, SOCK_DGRAM, 0);
+	if (s < 0)
+		return;
+
+	strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
+	if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
+		goto out;
+	ifr.ifr_flags &= mask;
+	ifr.ifr_flags |= flags;
+	if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0)
+		goto out;
+out:
+	close(s);
+	return;
+}
+
+static void
+eth_dev_promiscuous_enable(struct rte_eth_dev *dev)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+
+	eth_dev_change_flags(internals->if_name, IFF_PROMISC, ~0);
+}
+
+static void
+eth_dev_promiscuous_disable(struct rte_eth_dev *dev)
+{
+	struct pmd_internals *internals = dev->data->dev_private;
+
+	eth_dev_change_flags(internals->if_name, 0, ~IFF_PROMISC);
+}
+
 static const struct eth_dev_ops ops = {
 	.dev_start = eth_dev_start,
 	.dev_stop = eth_dev_stop,
@@ -448,6 +486,8 @@ static const struct eth_dev_ops ops = {
 	.dev_configure = eth_dev_configure,
 	.dev_infos_get = eth_dev_info,
 	.mtu_set = eth_dev_mtu_set,
+	.promiscuous_disable = eth_dev_promiscuous_disable,
+	.promiscuous_enable = eth_dev_promiscuous_enable,
 	.rx_queue_setup = eth_rx_queue_setup,
 	.tx_queue_setup = eth_tx_queue_setup,
 	.rx_queue_release = eth_queue_release,
-- 
2.1.4



More information about the dev mailing list