lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 17 Jun 2016 17:43:59 +0300
From:	Saeed Mahameed <saeedm@...lanox.com>
To:	"David S. Miller" <davem@...emloft.net>
Cc:	netdev@...r.kernel.org, Doug Ledford <dledford@...hat.com>,
	Or Gerlitz <ogerlitz@...lanox.com>,
	Maor Gottlieb <maorg@...lanox.com>,
	Huy Nguyen <huyn@...lanox.com>, Tal Alon <talal@...lanox.com>,
	Saeed Mahameed <saeedm@...lanox.com>
Subject: [PATCH net-next 18/18] net/mlx5e: Add netdev hw feature flag offload-sniffer

From: Huy Nguyen <huyn@...lanox.com>

Add netdev hw feature flag offload-sniffer to turn on/off kernel net
stack offload sniffer.  Kernel offload sniffer is a device driver
feature which when turned on, the device driver will start
receiving packets that weren't supposed to go through the kernel stack.

Optionally, those packets can be marked with PACKET_OFFLOAD_KERNEL in
skb->pkt_type so they will skip the unneeded kernel net stack
processing.
Please see ("net: Add offload kernel net stack packet type")

Example: ethtool eth1 –K offload-sniffer on

Signed-off-by: Maor Gottlieb <maorg@...lanox.com>
Signed-off-by: Huy Nguyen <huyn@...lanox.com>
Signed-off-by: Saeed Mahameed <saeedm@...lanox.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 28 +++++++++++++++++++++++
 include/linux/netdev_features.h                   |  2 ++
 net/core/ethtool.c                                |  1 +
 3 files changed, 31 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 94d6f60..61201f4 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -1702,6 +1702,9 @@ int mlx5e_open_locked(struct net_device *netdev)
 	priv->netdev->rx_cpu_rmap = priv->mdev->rmap;
 #endif
 
+	if (netdev->features & NETIF_F_OFFLOAD_SNIFFER)
+		mlx5e_sniffer_start(priv);
+
 	queue_delayed_work(priv->wq, &priv->update_stats_work, 0);
 
 	return 0;
@@ -1737,6 +1740,9 @@ int mlx5e_close_locked(struct net_device *netdev)
 
 	clear_bit(MLX5E_STATE_OPENED, &priv->state);
 
+	if (netdev->features & NETIF_F_OFFLOAD_SNIFFER)
+		mlx5e_sniffer_stop(priv);
+
 	mlx5e_timestamp_cleanup(priv);
 	netif_carrier_off(priv->netdev);
 	mlx5e_redirect_rqts(priv);
@@ -2325,6 +2331,22 @@ static int set_feature_arfs(struct net_device *netdev, bool enable)
 }
 #endif
 
+static int set_feature_offload_sniffer(struct net_device *netdev, bool enable)
+{
+	struct mlx5e_priv *priv = netdev_priv(netdev);
+	int err;
+
+	if (!test_bit(MLX5E_STATE_OPENED, &priv->state))
+		return 0;
+
+	if (enable)
+		err = mlx5e_sniffer_start(priv);
+	else
+		err = mlx5e_sniffer_stop(priv);
+
+	return err;
+}
+
 static int mlx5e_handle_feature(struct net_device *netdev,
 				netdev_features_t wanted_features,
 				netdev_features_t feature,
@@ -2371,6 +2393,8 @@ static int mlx5e_set_features(struct net_device *netdev,
 	err |= mlx5e_handle_feature(netdev, features, NETIF_F_NTUPLE,
 				    set_feature_arfs);
 #endif
+	err |= mlx5e_handle_feature(netdev, features, NETIF_F_OFFLOAD_SNIFFER,
+				    set_feature_offload_sniffer);
 
 	mutex_unlock(&priv->state_lock);
 
@@ -2911,6 +2935,10 @@ static void mlx5e_build_netdev(struct net_device *netdev)
 		netdev->hw_features |= NETIF_F_RXALL;
 
 	netdev->features          = netdev->hw_features;
+
+	/* Put it here because default is off */
+	netdev->hw_features      |= NETIF_F_OFFLOAD_SNIFFER;
+
 	if (!priv->params.lro_en)
 		netdev->features  &= ~NETIF_F_LRO;
 
diff --git a/include/linux/netdev_features.h b/include/linux/netdev_features.h
index 9c6c8ef..c00590c2 100644
--- a/include/linux/netdev_features.h
+++ b/include/linux/netdev_features.h
@@ -74,6 +74,7 @@ enum {
 	NETIF_F_BUSY_POLL_BIT,		/* Busy poll */
 
 	NETIF_F_HW_TC_BIT,		/* Offload TC infrastructure */
+	NETIF_F_OFFLOAD_SNIFFER_BIT,	/* Kernel Offload sniffer */
 
 	/*
 	 * Add your fresh new feature above and remember to update
@@ -136,6 +137,7 @@ enum {
 #define NETIF_F_HW_L2FW_DOFFLOAD	__NETIF_F(HW_L2FW_DOFFLOAD)
 #define NETIF_F_BUSY_POLL	__NETIF_F(BUSY_POLL)
 #define NETIF_F_HW_TC		__NETIF_F(HW_TC)
+#define NETIF_F_OFFLOAD_SNIFFER __NETIF_F(OFFLOAD_SNIFFER)
 
 #define for_each_netdev_feature(mask_addr, bit)	\
 	for_each_set_bit(bit, (unsigned long *)mask_addr, NETDEV_FEATURE_COUNT)
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 9774898..daaf9a5 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -104,6 +104,7 @@ static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN]
 	[NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload",
 	[NETIF_F_BUSY_POLL_BIT] =        "busy-poll",
 	[NETIF_F_HW_TC_BIT] =		 "hw-tc-offload",
+	[NETIF_F_OFFLOAD_SNIFFER_BIT] =  "offload-sniffer"
 };
 
 static const char
-- 
2.8.0

Powered by blists - more mailing lists