* [dpdk-dev] [RFC 2/5] app/testpmd: macsec on command draft via security context
2019-05-31 16:14 [dpdk-dev] [RFC 1/5] security: MACSEC infrastructure data declarations Igor Russkikh
@ 2019-05-31 16:14 ` Igor Russkikh
2019-05-31 16:14 ` [dpdk-dev] [RFC 3/5] app/testpmd: macsec off command Igor Russkikh
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Igor Russkikh @ 2019-05-31 16:14 UTC (permalink / raw)
To: dev
Cc: ferruh.yigit, Pavel Belous, John McNamara, Konstantin Ananyev,
Thomas Monjalon, Akhil Goyal, Declan Doherty, Igor Russkikh
Here we create/get security mempool, get sec_ctx, and then
request session creation with macsec specific session configuration.
encrypt and replay_protection parameters are really not a global macsec
attributes, they are related to tx and rx security connection properties.
But we keep testpmd commands structure the same for now and will redesign
it in later commits.
Signed-off-by: Igor Russkikh <igor.russkikh@aquantia.com>
---
app/test-pmd/cmdline.c | 54 +++++++++++++++++++++++++++++++++++-------
1 file changed, 46 insertions(+), 8 deletions(-)
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index c1042dd98214..dbee3d958c2e 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -46,6 +46,7 @@
#include <rte_devargs.h>
#include <rte_flow.h>
#include <rte_gro.h>
+#include <rte_security.h>
#include <cmdline_rdline.h>
#include <cmdline_parse.h>
@@ -13991,6 +13992,12 @@ struct cmd_macsec_offload_on_result {
cmdline_fixed_string_t rp_on_off;
};
+/* Temporary static storage until testpmd macsec commands get reformatted */
+int macsec_encrypt;
+int macsec_replay_protection;
+struct rte_security_session_conf macsec_conf;
+struct rte_security_session *macsec_session;
+
/* Common CLI fields for MACsec offload disable */
cmdline_parse_token_string_t cmd_macsec_offload_on_set =
TOKEN_STRING_INITIALIZER
@@ -14029,6 +14036,23 @@ cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off =
(struct cmd_macsec_offload_on_result,
rp_on_off, "on#off");
+static struct rte_mempool *get_security_pool()
+{
+ struct rte_mempool *pool = rte_mempool_lookup("testpmd_security_pool");
+ int session_size = 256;
+
+ if (!pool) {
+ pool = rte_mempool_create("testpmd_security_pool",
+ 256,
+ session_size,
+ 256,
+ 0, NULL, NULL, NULL,
+ NULL, SOCKET_ID_ANY,
+ 0);
+ }
+ return pool;
+}
+
static void
cmd_set_macsec_offload_on_parsed(
void *parsed_result,
@@ -14036,11 +14060,13 @@ cmd_set_macsec_offload_on_parsed(
__attribute__((unused)) void *data)
{
struct cmd_macsec_offload_on_result *res = parsed_result;
- int ret = -ENOTSUP;
+ int ret = 0;
+ struct rte_security_ctx *ctx;
portid_t port_id = res->port_id;
int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0;
int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0;
struct rte_eth_dev_info dev_info;
+ struct rte_security_session_conf macsec_conf;
if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
@@ -14049,17 +14075,29 @@ cmd_set_macsec_offload_on_parsed(
return;
}
- rte_eth_dev_info_get(port_id, &dev_info);
- if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
-#ifdef RTE_LIBRTE_IXGBE_PMD
- ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp);
-#endif
+ ctx = rte_eth_dev_get_sec_ctx(port_id);
+ if (!ctx) {
+ ret = ENOTSUP;
+ goto done;
+ }
+
+ macsec_conf.action_type = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL;
+ macsec_conf.protocol = RTE_SECURITY_PROTOCOL_MACSEC;
+ /** should be moved to SC properties */
+ macsec_encrypt = en;
+ macsec_replay_protection = rp;
+
+ /* Use of the same mempool for session header and private data */
+ macsec_session = rte_security_session_create(ctx, &macsec_conf, get_security_pool());
+
+ if (macsec_session == NULL) {
+ ret = -ENOTSUP;
}
- RTE_SET_USED(en);
- RTE_SET_USED(rp);
+done:
switch (ret) {
case 0:
+ /* TBD: To delete? */
ports[port_id].dev_conf.txmode.offloads |=
DEV_TX_OFFLOAD_MACSEC_INSERT;
cmd_reconfig_device_queue(port_id, 1, 1);
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [dpdk-dev] [RFC 3/5] app/testpmd: macsec off command
2019-05-31 16:14 [dpdk-dev] [RFC 1/5] security: MACSEC infrastructure data declarations Igor Russkikh
2019-05-31 16:14 ` [dpdk-dev] [RFC 2/5] app/testpmd: macsec on command draft via security context Igor Russkikh
@ 2019-05-31 16:14 ` Igor Russkikh
2019-05-31 16:14 ` [dpdk-dev] [RFC 4/5] app/testpmd: macsec: update set sc command with new interface Igor Russkikh
2019-05-31 16:15 ` [dpdk-dev] [RFC 5/5] net/atlantic: macsec security context draft Igor Russkikh
3 siblings, 0 replies; 5+ messages in thread
From: Igor Russkikh @ 2019-05-31 16:14 UTC (permalink / raw)
To: dev
Cc: ferruh.yigit, Pavel Belous, John McNamara, Konstantin Ananyev,
Thomas Monjalon, Akhil Goyal, Declan Doherty, Igor Russkikh
draft on how macsec off command will looks like
Signed-off-by: Igor Russkikh <igor.russkikh@aquantia.com>
---
app/test-pmd/cmdline.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index dbee3d958c2e..af7c2853fd2c 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -14173,6 +14173,8 @@ cmd_set_macsec_offload_off_parsed(
int ret = -ENOTSUP;
struct rte_eth_dev_info dev_info;
portid_t port_id = res->port_id;
+ struct rte_security_ctx *ctx;
+ struct rte_eth_dev_info dev_info;
if (port_id_is_invalid(port_id, ENABLED_WARN))
return;
@@ -14181,14 +14183,24 @@ cmd_set_macsec_offload_off_parsed(
return;
}
- rte_eth_dev_info_get(port_id, &dev_info);
- if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MACSEC_INSERT) {
-#ifdef RTE_LIBRTE_IXGBE_PMD
- ret = rte_pmd_ixgbe_macsec_disable(port_id);
-#endif
+ if (!macsec_session) {
+ printf("MACsec is not active\n", port_id);
+ return;
+ }
+
+ ctx = rte_eth_dev_get_sec_ctx(port_id);
+ if (!ctx) {
+ ret = -ENOTSUP;
+ goto done;
}
+
+ /* Use of the same mempool for session header and private data */
+ ret = rte_security_session_destroy(ctx, macsec_session);
+
+done:
switch (ret) {
case 0:
+ /* TBD: Remove this offload bit? */
ports[port_id].dev_conf.txmode.offloads &=
~DEV_TX_OFFLOAD_MACSEC_INSERT;
cmd_reconfig_device_queue(port_id, 1, 1);
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [dpdk-dev] [RFC 4/5] app/testpmd: macsec: update set sc command with new interface
2019-05-31 16:14 [dpdk-dev] [RFC 1/5] security: MACSEC infrastructure data declarations Igor Russkikh
2019-05-31 16:14 ` [dpdk-dev] [RFC 2/5] app/testpmd: macsec on command draft via security context Igor Russkikh
2019-05-31 16:14 ` [dpdk-dev] [RFC 3/5] app/testpmd: macsec off command Igor Russkikh
@ 2019-05-31 16:14 ` Igor Russkikh
2019-05-31 16:15 ` [dpdk-dev] [RFC 5/5] net/atlantic: macsec security context draft Igor Russkikh
3 siblings, 0 replies; 5+ messages in thread
From: Igor Russkikh @ 2019-05-31 16:14 UTC (permalink / raw)
To: dev
Cc: ferruh.yigit, Pavel Belous, John McNamara, Konstantin Ananyev,
Thomas Monjalon, Akhil Goyal, Declan Doherty, Igor Russkikh
---
app/test-pmd/cmdline.c | 40 ++++++++++++++++++++++++++++++++--------
1 file changed, 32 insertions(+), 8 deletions(-)
diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index af7c2853fd2c..1bcf63e31ee3 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -14083,6 +14083,7 @@ cmd_set_macsec_offload_on_parsed(
macsec_conf.action_type = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL;
macsec_conf.protocol = RTE_SECURITY_PROTOCOL_MACSEC;
+ macsec_conf.macsec.
/** should be moved to SC properties */
macsec_encrypt = en;
macsec_replay_protection = rp;
@@ -14280,15 +14281,38 @@ cmd_set_macsec_sc_parsed(
struct cmd_macsec_sc_result *res = parsed_result;
int ret = -ENOTSUP;
int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0;
+ struct rte_security_ctx *ctx;
+ struct rte_eth_dev_info dev_info;
+ struct rte_security_session_conf conf = {};
-#ifdef RTE_LIBRTE_IXGBE_PMD
- ret = is_tx ?
- rte_pmd_ixgbe_macsec_config_txsc(res->port_id,
- res->mac.addr_bytes) :
- rte_pmd_ixgbe_macsec_config_rxsc(res->port_id,
- res->mac.addr_bytes, res->pi);
-#endif
- RTE_SET_USED(is_tx);
+ ctx = rte_eth_dev_get_sec_ctx(port_id);
+ if (!ctx) {
+ ret = ENOTSUP;
+ goto done;
+ }
+
+ if (is_tx) {
+ conf.macsec.op = RTE_SECURITY_MACSEC_OP_ADD_TXSC;
+
+ rte_memcpy(&conf.macsec.txsc_options.s_mac, res->mac.addr_bytes,
+ sizeof(struct ether_addr));
+ conf.macsec.txsc_options.encrypt = macsec_encrypt;
+ conf.macsec.txsc_options.protect = 1;
+
+ ret = rte_security_session_update(ctx, macsec_session, &conf);
+ } else {
+ conf.macsec.op = RTE_SECURITY_MACSEC_OP_ADD_RXSC;
+
+ rte_memcpy(&conf.macsec.rxsc_options.s_mac, res->mac.addr_bytes,
+ sizeof(struct ether_addr));
+ /* Default */
+ conf.macsec.rxsc_options.anti_replay_window = 0;
+ conf.macsec.rxsc_options.replay_protection = macsec_replay_protection;
+ conf.macsec.rxsc_options.auto_rollover_enabled = true;
+
+ ret = rte_security_session_update(ctx, macsec_session, &conf);
+
+ }
switch (ret) {
case 0:
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [dpdk-dev] [RFC 5/5] net/atlantic: macsec security context draft
2019-05-31 16:14 [dpdk-dev] [RFC 1/5] security: MACSEC infrastructure data declarations Igor Russkikh
` (2 preceding siblings ...)
2019-05-31 16:14 ` [dpdk-dev] [RFC 4/5] app/testpmd: macsec: update set sc command with new interface Igor Russkikh
@ 2019-05-31 16:15 ` Igor Russkikh
3 siblings, 0 replies; 5+ messages in thread
From: Igor Russkikh @ 2019-05-31 16:15 UTC (permalink / raw)
To: dev
Cc: ferruh.yigit, Pavel Belous, John McNamara, Konstantin Ananyev,
Thomas Monjalon, Akhil Goyal, Declan Doherty, Igor Russkikh
---
drivers/net/atlantic/atl_ethdev.c | 116 ++++++++++++++++++++++++++++++
drivers/net/atlantic/meson.build | 1 +
2 files changed, 117 insertions(+)
diff --git a/drivers/net/atlantic/atl_ethdev.c b/drivers/net/atlantic/atl_ethdev.c
index c9c1795a1639..b6fcf36f0f27 100644
--- a/drivers/net/atlantic/atl_ethdev.c
+++ b/drivers/net/atlantic/atl_ethdev.c
@@ -5,6 +5,9 @@
#include <rte_string_fns.h>
#include <rte_ethdev_pci.h>
#include <rte_alarm.h>
+#include <rte_security.h>
+#include <rte_security_driver.h>
+#include <rte_cryptodev.h>
#include "atl_ethdev.h"
#include "atl_common.h"
@@ -122,6 +125,7 @@ static int eth_atl_pci_remove(struct rte_pci_device *pci_dev);
static void atl_dev_info_get(struct rte_eth_dev *dev,
struct rte_eth_dev_info *dev_info);
+static int atl_macsec_ctx_create(struct rte_eth_dev *dev);
int atl_logtype_init;
int atl_logtype_driver;
@@ -412,6 +416,10 @@ eth_atl_dev_init(struct rte_eth_dev *eth_dev)
hw->aq_nic_cfg = &adapter->hw_cfg;
+ /* Initialize security_ctx only for primary process*/
+ if (atl_macsec_ctx_create(eth_dev))
+ return -ENOMEM;
+
/* disable interrupt */
atl_disable_intr(hw);
@@ -475,6 +483,8 @@ eth_atl_dev_uninit(struct rte_eth_dev *eth_dev)
rte_free(eth_dev->data->mac_addrs);
eth_dev->data->mac_addrs = NULL;
+ rte_free(eth_dev->security_ctx);
+
return 0;
}
@@ -1872,6 +1882,112 @@ atl_rss_hash_conf_get(struct rte_eth_dev *dev,
return 0;
}
+static const struct rte_security_capability *
+atl_crypto_capabilities_get(void *device __rte_unused)
+{
+ static const struct rte_cryptodev_capabilities
+ aes_gcm_gmac_crypto_capabilities[] = {
+ { /* AES GMAC (128-bit) */
+ .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
+ {.sym = {
+ .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
+ {.auth = {
+ .algo = RTE_CRYPTO_AUTH_AES_GMAC,
+ .block_size = 16,
+ .key_size = {
+ .min = 16,
+ .max = 16,
+ .increment = 0
+ },
+ }, }
+ }, }
+ },
+ };
+
+ static const struct rte_security_capability
+ alt_security_capabilities[] = {
+ {
+ .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
+ .protocol = RTE_SECURITY_PROTOCOL_MACSEC,
+ {.macsec = {
+ /*
+ .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
+ .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
+ .options = { 0 }
+ */
+ } },
+ .crypto_capabilities = aes_gcm_gmac_crypto_capabilities,
+ .ol_flags = 0
+ },
+ {
+ .action = RTE_SECURITY_ACTION_TYPE_NONE
+ }
+ };
+
+ return alt_security_capabilities;
+}
+
+static int atl_macsec_create_session(void *device,
+ struct rte_security_session_conf *conf,
+ struct rte_security_session *sess,
+ struct rte_mempool *mp)
+{
+
+}
+
+static int atl_macsec_update_session(void *device,
+ struct rte_security_session *sess,
+ struct rte_security_session_conf *conf)
+{
+
+}
+
+static unsigned int atl_macsec_session_get_size(void *device)
+{
+
+}
+
+static int atl_macsec_destroy_session(void *device,
+ struct rte_security_session *sess)
+{
+
+}
+
+static const struct rte_security_capability *atl_macsec_capabilities_get(
+ void *device)
+{
+
+}
+
+static struct rte_security_ops atl_security_ops = {
+ .session_create = atl_macsec_create_session,
+ .session_update = atl_macsec_update_session,
+ .session_get_size = atl_macsec_session_get_size,
+ .session_stats_get = NULL,
+ .session_destroy = atl_macsec_destroy_session,
+ .set_pkt_metadata = NULL,
+ .capabilities_get = atl_macsec_capabilities_get,
+};
+
+static int
+atl_macsec_ctx_create(struct rte_eth_dev *dev)
+{
+ struct rte_security_ctx *ctx = NULL;
+
+ ctx = rte_malloc("rte_security_instances_ops",
+ sizeof(struct rte_security_ctx), 0);
+ if (ctx) {
+ ctx->device = (void *)dev;
+ ctx->ops = &atl_security_ops;
+ ctx->sess_cnt = 0;
+ dev->security_ctx = ctx;
+ } else {
+ return -ENOMEM;
+ }
+ return 0;
+}
+
+
static bool
is_device_supported(struct rte_eth_dev *dev, struct rte_pci_driver *drv)
{
diff --git a/drivers/net/atlantic/meson.build b/drivers/net/atlantic/meson.build
index 60b84684ec0a..d14855bdb218 100644
--- a/drivers/net/atlantic/meson.build
+++ b/drivers/net/atlantic/meson.build
@@ -11,3 +11,4 @@ sources = files(
'hw_atl/hw_atl_utils.c',
'rte_pmd_atlantic.c',
)
+deps += ['security']
\ No newline at end of file
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread