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  linux-hardening  linux-cve-announce  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]
Message-ID: <20230329122107.22658-2-ehakim@nvidia.com>
Date:   Wed, 29 Mar 2023 15:21:04 +0300
From:   Emeel Hakim <ehakim@...dia.com>
To:     <davem@...emloft.net>, <kuba@...nel.org>, <pabeni@...hat.com>,
        <edumazet@...gle.com>, <sd@...asysnail.net>
CC:     <netdev@...r.kernel.org>, Emeel Hakim <ehakim@...dia.com>
Subject: [PATCH net-next v2 1/4] vlan: Add MACsec offload operations for VLAN interface

Add support for MACsec offload operations for VLAN driver
to allow offloading MACsec when VLAN's real device supports
Macsec offload by forwarding the offload request to it.

Signed-off-by: Emeel Hakim <ehakim@...dia.com>
---
V1 -> V2: - Consult vlan_features when adding NETIF_F_HW_MACSEC.
		  - Allow grep for the functions.
		  - Add helper function to get the macsec operation to allow the compiler to make some choice.
 .../net/ethernet/mellanox/mlx5/core/en_main.c |   1 +
 net/8021q/vlan_dev.c                          | 101 ++++++++++++++++++
 2 files changed, 102 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 6db1aff8778d..5ecef26e83c6 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -5076,6 +5076,7 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev)
 
 	netdev->vlan_features    |= NETIF_F_SG;
 	netdev->vlan_features    |= NETIF_F_HW_CSUM;
+	netdev->vlan_features    |= NETIF_F_HW_MACSEC;
 	netdev->vlan_features    |= NETIF_F_GRO;
 	netdev->vlan_features    |= NETIF_F_TSO;
 	netdev->vlan_features    |= NETIF_F_TSO6;
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index 5920544e93e8..08d063f1e5b6 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -26,6 +26,7 @@
 #include <linux/ethtool.h>
 #include <linux/phy.h>
 #include <net/arp.h>
+#include <net/macsec.h>
 
 #include "vlan.h"
 #include "vlanproc.h"
@@ -572,6 +573,9 @@ static int vlan_dev_init(struct net_device *dev)
 			   NETIF_F_HIGHDMA | NETIF_F_SCTP_CRC |
 			   NETIF_F_ALL_FCOE;
 
+	if (real_dev->features & NETIF_F_HW_MACSEC)
+		dev->hw_features |= NETIF_F_HW_MACSEC;
+
 	dev->features |= dev->hw_features | NETIF_F_LLTX;
 	netif_inherit_tso_max(dev, real_dev);
 	if (dev->features & NETIF_F_VLAN_FEATURES)
@@ -803,6 +807,100 @@ static int vlan_dev_fill_forward_path(struct net_device_path_ctx *ctx,
 	return 0;
 }
 
+#if IS_ENABLED(CONFIG_MACSEC)
+
+static const struct macsec_ops *vlan_get_macsec_ops(struct macsec_context *ctx)
+{
+	return vlan_dev_priv(ctx->netdev)->real_dev->macsec_ops;
+}
+
+#define _BUILD_VLAN_MACSEC_MDO(mdo) \
+	const struct macsec_ops *ops; \
+	ops =  vlan_get_macsec_ops(ctx); \
+	return ops ? ops->mdo_ ## mdo(ctx) : -EOPNOTSUPP
+
+static int vlan_macsec_add_txsa(struct macsec_context *ctx)
+{
+_BUILD_VLAN_MACSEC_MDO(add_txsa);
+}
+
+static int vlan_macsec_upd_txsa(struct macsec_context *ctx)
+{
+_BUILD_VLAN_MACSEC_MDO(upd_txsa);
+}
+
+static int vlan_macsec_del_txsa(struct macsec_context *ctx)
+{
+_BUILD_VLAN_MACSEC_MDO(del_txsa);
+}
+
+static int vlan_macsec_add_rxsa(struct macsec_context *ctx)
+{
+_BUILD_VLAN_MACSEC_MDO(add_rxsa);
+}
+
+static int vlan_macsec_upd_rxsa(struct macsec_context *ctx)
+{
+_BUILD_VLAN_MACSEC_MDO(upd_rxsa);
+}
+
+static int vlan_macsec_del_rxsa(struct macsec_context *ctx)
+{
+_BUILD_VLAN_MACSEC_MDO(del_rxsa);
+}
+
+static int vlan_macsec_add_rxsc(struct macsec_context *ctx)
+{
+_BUILD_VLAN_MACSEC_MDO(add_rxsc);
+}
+
+static int vlan_macsec_upd_rxsc(struct macsec_context *ctx)
+{
+_BUILD_VLAN_MACSEC_MDO(upd_rxsc);
+}
+
+static int vlan_macsec_del_rxsc(struct macsec_context *ctx)
+{
+_BUILD_VLAN_MACSEC_MDO(del_rxsc);
+}
+
+static int vlan_macsec_add_secy(struct macsec_context *ctx)
+{
+_BUILD_VLAN_MACSEC_MDO(add_secy);
+}
+
+static int vlan_macsec_upd_secy(struct macsec_context *ctx)
+{
+_BUILD_VLAN_MACSEC_MDO(upd_secy);
+}
+
+static int vlan_macsec_del_secy(struct macsec_context *ctx)
+{
+_BUILD_VLAN_MACSEC_MDO(del_secy);
+}
+
+#undef _BUILD_VLAN_MACSEC_MDO
+
+#define VLAN_MACSEC_DECLARE_MDO(mdo) .mdo_ ## mdo = vlan_macsec_ ## mdo
+
+static const struct macsec_ops macsec_offload_ops = {
+	VLAN_MACSEC_DECLARE_MDO(add_txsa),
+	VLAN_MACSEC_DECLARE_MDO(upd_txsa),
+	VLAN_MACSEC_DECLARE_MDO(del_txsa),
+	VLAN_MACSEC_DECLARE_MDO(add_rxsc),
+	VLAN_MACSEC_DECLARE_MDO(upd_rxsc),
+	VLAN_MACSEC_DECLARE_MDO(del_rxsc),
+	VLAN_MACSEC_DECLARE_MDO(add_rxsa),
+	VLAN_MACSEC_DECLARE_MDO(upd_rxsa),
+	VLAN_MACSEC_DECLARE_MDO(del_rxsa),
+	VLAN_MACSEC_DECLARE_MDO(add_secy),
+	VLAN_MACSEC_DECLARE_MDO(upd_secy),
+	VLAN_MACSEC_DECLARE_MDO(del_secy),
+};
+
+#undef VLAN_MACSEC_DECLARE_MDO
+#endif
+
 static const struct ethtool_ops vlan_ethtool_ops = {
 	.get_link_ksettings	= vlan_ethtool_get_link_ksettings,
 	.get_drvinfo	        = vlan_ethtool_get_drvinfo,
@@ -869,6 +967,9 @@ void vlan_setup(struct net_device *dev)
 	dev->priv_destructor	= vlan_dev_free;
 	dev->ethtool_ops	= &vlan_ethtool_ops;
 
+#if IS_ENABLED(CONFIG_MACSEC)
+	dev->macsec_ops		= &macsec_offload_ops;
+#endif
 	dev->min_mtu		= 0;
 	dev->max_mtu		= ETH_MAX_MTU;
 
-- 
2.21.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ