DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Charles (Chas) Williams" <ciwillia@brocade.com>
To: <dev@dpdk.org>
Cc: <linville@tuxdriver.com>,
	"Charles (Chas) Williams" <ciwillia@brocade.com>
Subject: [dpdk-dev] [PATCH v2 3/4] net/af_packet: promisicuous support
Date: Thu, 5 Jan 2017 08:53:43 -0500	[thread overview]
Message-ID: <1483624424-2806-3-git-send-email-ciwillia@brocade.com> (raw)
In-Reply-To: <1483624424-2806-1-git-send-email-ciwillia@brocade.com>

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@brocade.com>
---
 drivers/net/af_packet/rte_eth_af_packet.c | 39 +++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index a700b96..6aa8132 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -440,6 +440,43 @@ 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);
+}
+
+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,
@@ -447,6 +484,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_enable = eth_dev_promiscuous_enable,
+	.promiscuous_disable = eth_dev_promiscuous_disable,
 	.rx_queue_setup = eth_rx_queue_setup,
 	.tx_queue_setup = eth_tx_queue_setup,
 	.rx_queue_release = eth_queue_release,
-- 
2.1.4

  parent reply	other threads:[~2017-01-05 13:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-05 13:53 [dpdk-dev] [PATCH v2 1/4] net/af_packet: add iface name to internals Charles (Chas) Williams
2017-01-05 13:53 ` [dpdk-dev] [PATCH v2 2/4] net/af_packet: add support to change mtu Charles (Chas) Williams
2017-01-05 13:53 ` Charles (Chas) Williams [this message]
2017-01-05 13:53 ` [dpdk-dev] [PATCH v2 4/4] net/af_packet: add 802.1Q (VLAN) support Charles (Chas) Williams
2017-01-05 14:04 ` [dpdk-dev] [PATCH v2 1/4] net/af_packet: add iface name to internals Ferruh Yigit
2017-01-16 14:31 ` Ferruh Yigit
2017-01-16 14:35   ` 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=1483624424-2806-3-git-send-email-ciwillia@brocade.com \
    --to=ciwillia@brocade.com \
    --cc=dev@dpdk.org \
    --cc=linville@tuxdriver.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).