security: hide security context
PATCH 1/1 security: hide security context
rte_security_ctx is used by all security APIs to identify which device security_op it need to call and hence it should be opaque to the application.
Hence, it is now moved to internal header file and all APIs will now take an opaque pointer for it.
The fast path inline APIs like set metadata need to get flags from security_ctx. The flags are now retrieved using inline APIs which use macros to get the offset of flags in security_ctx.
--- app/test-crypto-perf/cperf_ops.c | 9 +-- app/test-crypto-perf/cperf_test_latency.c | 3 +- .../cperf_test_pmd_cyclecount.c | 8 +- app/test-crypto-perf/cperf_test_throughput.c | 9 +-- app/test-crypto-perf/cperf_test_verify.c | 4 +- app/test-security-perf/test_security_perf.c | 2 +- app/test/test_cryptodev.c | 22 ++---- app/test/test_cryptodev_security_ipsec.c | 2 +- app/test/test_cryptodev_security_ipsec.h | 2 +- app/test/test_security_inline_macsec.c | 10 +-- app/test/test_security_inline_proto.c | 14 ++-- examples/ipsec-secgw/ipsec-secgw.c | 2 +- examples/ipsec-secgw/ipsec.c | 15 ++-- examples/ipsec-secgw/ipsec.h | 2 +- examples/ipsec-secgw/ipsec_worker.c | 2 +- examples/ipsec-secgw/ipsec_worker.h | 4 +- examples/l2fwd-macsec/main.c | 2 +- lib/security/rte_security.c | 57 ++++++++------ lib/security/rte_security.h | 77 +++++++++---------- lib/security/rte_security_driver.h | 24 ++++++ 20 files changed, 139 insertions(+), 131 deletions(-)
app/test-crypto-perf/cperf_ops.c +3 -6
@@ -749,8 +749,7 @@ create_ipsec_session(struct rte_mempool *sess_mp,else sess_conf.ipsec.direction =RTE_SECURITY_IPSEC_SA_DIR_INGRESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (dev_id); +void *ctx =rte_cryptodev_get_sec_ctx (dev_id);/* Create security session */ return (void *)rte_security_session_create (ctx, &sess_conf, sess_mp);
@@ -853,8 +852,7 @@ cperf_create_session(struct rte_mempool *sess_mp, .crypto_xform = &cipher_xform }; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (dev_id); +void *ctx =rte_cryptodev_get_sec_ctx (dev_id);/* Create security session */ return (void *)rte_security_session_create (ctx, &sess_conf, sess_mp);
@@ -901,8 +899,7 @@ cperf_create_session(struct rte_mempool *sess_mp, } }, .crypto_xform = &cipher_xform }; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (dev_id); +void *ctx =rte_cryptodev_get_sec_ctx (dev_id);/* Create security session */ return (void *)rte_security_session_create (ctx, &sess_conf, sess_mp);
app/test-crypto-perf/cperf_test_latency.c +1 -2
@@ -53,8 +53,7 @@ cperf_latency_test_free(struct cperf_latency_ctx *ctx) else if (ctx->options->op_type == CPERF_PDCP || ctx->options->op_type == CPERF_DOCSIS || ctx->options->op_type == CPERF_IPSEC) { -struct rte_security_ctx *sec_ctx = -rte_cryptodev_get_sec_ctx (ctx->dev_id); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id);rte_security_session_destroy (sec_ctx, ctx->sess); }#endif
app/test-crypto-perf/cperf_test_pmd_cyclecount.c +3 -5
@@ -67,11 +67,9 @@ cperf_pmd_cyclecount_test_free(struct cperf_pmd_cyclecount_ctx *ctx)#ifdef RTE_LIB_SECURITY if (ctx->options->op_type ==CPERF_PDCP || ctx->options->op_type ==CPERF_DOCSIS ) { -struct rte_security_ctx *sec_ctx = - (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (ctx->dev_id); -rte_security_session_destroy (sec_ctx, - (void *)ctx->sess); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id); + +rte_security_session_destroy (sec_ctx, (void *)ctx->sess); } else#endif rte_cryptodev_sym_session_free (ctx->dev_id, ctx->sess);
app/test-crypto-perf/cperf_test_throughput.c +3 -6
@@ -44,12 +44,9 @@ cperf_throughput_test_free(struct cperf_throughput_ctx *ctx) else if (ctx->options->op_type == CPERF_PDCP || ctx->options->op_type == CPERF_DOCSIS || ctx->options->op_type == CPERF_IPSEC) { -struct rte_security_ctx *sec_ctx = - (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (ctx->dev_id); -rte_security_session_destroy ( - sec_ctx, - (void *)ctx->sess); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id); + +rte_security_session_destroy (sec_ctx, (void *)ctx->sess); }#endif else
app/test-crypto-perf/cperf_test_verify.c +2 -2
@@ -48,8 +48,8 @@ cperf_verify_test_free(struct cperf_verify_ctx *ctx) else if (ctx->options->op_type == CPERF_PDCP || ctx->options->op_type == CPERF_DOCSIS || ctx->options->op_type == CPERF_IPSEC) { -struct rte_security_ctx *sec_ctx = -rte_cryptodev_get_sec_ctx (ctx->dev_id); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id); +rte_security_session_destroy (sec_ctx, ctx->sess); }#endif
app/test-security-perf/test_security_perf.c +1 -1
@@ -344,7 +344,7 @@ test_security_session_perf(void *arg)struct rte_security_session_conf sess_conf;int i, ret, nb_sessions, nb_sess_total;struct rte_security_session **sess; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;double setup_rate, destroy_rate;uint64_t setup_ms, destroy_ms;struct lcore_conf *conf = arg;
app/test/test_cryptodev.c +6 -16
@@ -8925,9 +8925,7 @@ security_proto_supported(enum rte_security_session_action_type action,const struct rte_security_capability *capability;uint16_t i =0 ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]); capabilities =rte_security_capabilities_get (ctx);
@@ -8967,9 +8965,7 @@ static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,struct crypto_unittest_params *ut_params = &unittest_params;uint8_t *plaintext;int ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);struct rte_cryptodev_info dev_info;uint64_t feat_flags;
@@ -9174,9 +9170,7 @@ test_pdcp_proto_SGL(int i, int oop,unsigned int trn_data =0 ;struct rte_cryptodev_info dev_info;uint64_t feat_flags; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);struct rte_mbuf *temp_mbuf;rte_cryptodev_info_get (ts_params->valid_devs[0 ], &dev_info);
@@ -9772,7 +9766,7 @@ test_ipsec_proto_process(const struct ipsec_test_data td[],struct ipsec_test_data *res_d_tmp =NULL ;uint8_t input_text[IPSEC_TEXT_MAX_LEN ];int salt_len, i, ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx; +void *ctx;uint32_t src, dst;uint32_t verify;
@@ -10905,9 +10899,7 @@ test_docsis_proto_uplink(const void *data)uint32_t crc_data_len;int ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);/* Verify the capabilities */ struct rte_security_capability_idx sec_cap_idx;
@@ -11089,9 +11081,7 @@ test_docsis_proto_downlink(const void *data)int32_t cipher_len, crc_len;int ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);/* Verify the capabilities */ struct rte_security_capability_idx sec_cap_idx;
app/test/test_cryptodev_security_ipsec.c +1 -1
@@ -1241,7 +1241,7 @@ test_ipsec_status_check(const struct ipsec_test_data *td, }int -test_ipsec_stats_verify (struct rte_security_ctx *ctx, +test_ipsec_stats_verify (void *ctx,void *sess,const struct ipsec_test_flags *flags,enum rte_security_ipsec_sa_direction dir)
app/test/test_cryptodev_security_ipsec.h +1 -1
@@ -300,7 +300,7 @@ int test_ipsec_status_check(const struct ipsec_test_data *td,enum rte_security_ipsec_sa_direction dir, int pkt_num); -int test_ipsec_stats_verify (struct rte_security_ctx *ctx, +int test_ipsec_stats_verify (void *ctx,void *sess,const struct ipsec_test_flags *flags,enum rte_security_ipsec_sa_direction dir);
app/test/test_security_inline_macsec.c +5 -5
@@ -136,7 +136,7 @@ init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len)static int init_mempools (unsigned int nb_mbuf) { -struct rte_security_ctx *sec_ctx; +void *sec_ctx;uint16_t nb_sess =512 ;uint32_t sess_sz;char s[64 ];
@@ -482,7 +482,7 @@ test_macsec_post_process(struct rte_mbuf *m, const struct mcs_test_vector *td, }static void -mcs_stats_dump (struct rte_security_ctx *ctx,enum mcs_op op, +mcs_stats_dump (void *ctx,enum mcs_op op,void *rx_sess,void *tx_sess,uint8_t rx_sc_id,uint8_t tx_sc_id,uint16_t rx_sa_id[],uint16_t tx_sa_id[])
@@ -667,7 +667,7 @@ mcs_stats_dump(struct rte_security_ctx *ctx, enum mcs_op op, } static int -mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op, +mcs_stats_check(void *ctx, enum mcs_op op, const struct mcs_test_opts *opts, const struct mcs_test_vector *td, void *rx_sess, void *tx_sess,
@@ -850,7 +850,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcsstruct rte_security_macsec_sa sa_conf = {0 };struct rte_security_macsec_sc sc_conf = {0 };struct mcs_err_vector err_vector = {0 }; -struct rte_security_ctx *ctx; +void *ctx;int nb_rx =0 , nb_sent;int i, j =0 , ret, id, an =0 ;uint8_t tci_off;
@@ -858,7 +858,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcsmemset (rx_pkts_burst,0 ,sizeof (rx_pkts_burst[0 ]) * opts->nb_td); - ctx = (struct rte_security_ctx *)rte_eth_dev_get_sec_ctx (port_id); + ctx =rte_eth_dev_get_sec_ctx (port_id);if (ctx ==NULL ) {printf ("Ethernet device doesn't support security features.\n" );return TEST_SKIPPED ;
app/test/test_security_inline_proto.c +7 -7
@@ -136,7 +136,7 @@ static struct rte_flow *default_flow[RTE_MAX_ETHPORTS];/* Create Inline IPsec session */ static int create_inline_ipsec_session (struct ipsec_test_data *sa,uint16_t portid, -void **sess,struct rte_security_ctx **ctx, +void **sess,void **ctx,uint32_t *ol_flags,const struct ipsec_test_flags *flags,struct rte_security_session_conf *sess_conf) {
@@ -149,7 +149,7 @@ create_inline_ipsec_session(struct ipsec_test_data *sa, uint16_t portid,struct rte_security_capability_idx sec_cap_idx;const struct rte_security_capability *sec_cap;enum rte_security_ipsec_sa_direction dir; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;uint32_t verify; sess_conf->action_type =RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL ;
@@ -221,7 +221,7 @@ create_inline_ipsec_session(struct ipsec_test_data *sa, uint16_t portid, sess_conf->userdata = (void *) sa; - sec_ctx = (struct rte_security_ctx *)rte_eth_dev_get_sec_ctx (portid); + sec_ctx =rte_eth_dev_get_sec_ctx (portid);if (sec_ctx ==NULL ) {printf ("Ethernet device doesn't support security features.\n" );return TEST_SKIPPED ;
@@ -503,7 +503,7 @@ init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len, boolstatic int init_mempools (unsigned int nb_mbuf) { -struct rte_security_ctx *sec_ctx; +void *sec_ctx;uint16_t nb_sess =512 ;uint32_t sess_sz;char s[64 ];
@@ -801,7 +801,7 @@ test_ipsec_with_reassembly(struct reassembly_vector *vector,struct rte_crypto_sym_xform auth_in = {0 };struct rte_crypto_sym_xform aead_in = {0 };struct ipsec_test_data sa_data; -struct rte_security_ctx *ctx; +void *ctx;unsigned int i, nb_rx =0 , j;uint32_t ol_flags;bool outer_ipv4;
@@ -1068,7 +1068,7 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,struct rte_crypto_sym_xform auth = {0 };struct rte_crypto_sym_xform aead = {0 };struct sa_expiry_vector vector = {0 }; -struct rte_security_ctx *ctx; +void *ctx;int nb_rx =0 , nb_sent;uint32_t ol_flags;int i, j =0 , ret;
@@ -1338,7 +1338,7 @@ test_ipsec_inline_proto_process_with_esn(struct ipsec_test_data td[],struct rte_mbuf *tx_pkt =NULL ;int nb_rx, nb_sent;void *ses; -struct rte_security_ctx *ctx; +void *ctx;uint32_t ol_flags;bool outer_ipv4;int i, ret;
examples/ipsec-secgw/ipsec-secgw.c +1 -1
@@ -568,7 +568,7 @@ process_pkts_outbound_nosp(struct ipsec_ctx *ipsec_ctx,static inline void process_pkts (struct lcore_conf *qconf,struct rte_mbuf **pkts, -uint8_t nb_pkts,uint16_t portid,struct rte_security_ctx *ctx) +uint8_t nb_pkts,uint16_t portid,void *ctx) {struct ipsec_traffic traffic;
examples/ipsec-secgw/ipsec.c +5 -10
@@ -205,7 +205,7 @@ verify_ipsec_capabilities(struct rte_security_ipsec_xform *ipsec_xform,static inline int -verify_security_capabilities (struct rte_security_ctx *ctx, +verify_security_capabilities (void *ctx,struct rte_security_session_conf *sess_conf,uint32_t *ol_flags) {
@@ -327,9 +327,7 @@ create_lookaside_session(struct ipsec_ctx *ipsec_ctx_lcore[], };if (ips->type ==RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL ) { -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - cdev_id); +void *ctx =rte_cryptodev_get_sec_ctx (cdev_id);/* Set IPsec parameters in conf */ set_ipsec_conf (sa, &(sess_conf.ipsec));
@@ -411,7 +409,7 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa, struct rte_ipsec_session *ips) {int32_t ret =0 ; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;struct rte_security_session_conf sess_conf = { .action_type = ips->type, .protocol =RTE_SECURITY_PROTOCOL_IPSEC ,
@@ -490,9 +488,7 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa,struct rte_flow_error err;int ret =0 ; - sec_ctx = (struct rte_security_ctx *) -rte_eth_dev_get_sec_ctx ( - sa->portid); + sec_ctx =rte_eth_dev_get_sec_ctx (sa->portid);if (sec_ctx ==NULL ) {RTE_LOG (ERR ,IPSEC ," rte_eth_dev_get_sec_ctx failed\n" );
@@ -657,8 +653,7 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa,return -1 ; } }else if (ips->type ==RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL ) { - sec_ctx = (struct rte_security_ctx *) -rte_eth_dev_get_sec_ctx (sa->portid); + sec_ctx =rte_eth_dev_get_sec_ctx (sa->portid);if (sec_ctx ==NULL ) { RTE_LOG(ERR, IPSEC,
examples/ipsec-secgw/ipsec.h +1 -1
@@ -279,7 +279,7 @@ struct cnt_blk {struct lcore_rx_queue {uint16_t port_id;uint8_t queue_id; -struct rte_security_ctx *sec_ctx; +void *sec_ctx; } __rte_cache_aligned;struct buffer {
examples/ipsec-secgw/ipsec_worker.c +1 -1
@@ -20,7 +20,7 @@struct port_drv_mode_data {void *sess; -struct rte_security_ctx *ctx; +void *ctx; };typedef void (*ipsec_worker_fn_t )(void );
examples/ipsec-secgw/ipsec_worker.h +2 -2
@@ -119,7 +119,7 @@ adjust_ipv6_pktlen(struct rte_mbuf *m, const struct rte_ipv6_hdr *iph, } static __rte_always_inline void -prepare_one_packet (struct rte_security_ctx *ctx,struct rte_mbuf *pkt, +prepare_one_packet (void *ctx,struct rte_mbuf *pkt,struct ipsec_traffic *t) {uint32_t ptype = pkt->packet_type;
@@ -230,7 +230,7 @@ prepare_one_packet(struct rte_security_ctx *ctx, struct rte_mbuf *pkt, } static __rte_always_inline void -prepare_traffic (struct rte_security_ctx *ctx,struct rte_mbuf **pkts, +prepare_traffic (void *ctx,struct rte_mbuf **pkts,struct ipsec_traffic *t,uint16_t nb_pkts) {int32_t i;
examples/l2fwd-macsec/main.c +1 -1
@@ -139,7 +139,7 @@ struct l2fwd_macsec_options {struct l2fwd_macsec_port_params {uint8_t dev_id;uint8_t qp_id; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;struct rte_mempool *sess_pool;void *sess;
lib/security/rte_security.c +34 -23
166 lines not on this page · raw message
lib/security/rte_security.h +37 -40
183 lines not on this page · raw message
lib/security/rte_security_driver.h +24 -0
@@ -37,6 +37,30 @@ struct rte_security_session {/**< Private session material, variable size (depends on driver) */ }; +/** +* Security context for crypto/eth devices +* +* Security instance for each driver to register security operations. +* The application can get the security context from the crypto/eth device id +* using the APIs rte_cryptodev_get_sec_ctx()/rte_eth_dev_get_sec_ctx() +* This structure is used to identify the device(crypto/eth) for which the +* security operations need to be performed. +*/ +struct rte_security_ctx { +void *device; +/**< Crypto/ethernet device attached */ +const struct rte_security_ops *ops; +/**< Pointer to security ops for the device */ +uint32_t flags; +/**< Flags for security context */ +uint16_t sess_cnt; +/**< Number of sessions attached to this context */ +uint16_t macsec_sc_cnt; +/**< Number of MACsec SC attached to this context */ +uint16_t macsec_sa_cnt; +/**< Number of MACsec SA attached to this context */ +}; +/** * Helper macro to get driver private data */
Signature · 1 line
2.25.1
PATCH v2 1/1 security: hide security context
rte_security_ctx is used by all security APIs to identify which device security_op it need to call and hence it should be opaque to the application.
Hence, it is now moved to internal header file and all APIs will now take an opaque pointer for it.
The fast path inline APIs like set metadata need to get flags from security_ctx. The flags are now retrieved using inline APIs which use macros to get the offset of flags in security_ctx.
---
Changes in v2: Rebased.
app/test-crypto-perf/cperf_ops.c | 9 +-- app/test-crypto-perf/cperf_test_latency.c | 3 +- .../cperf_test_pmd_cyclecount.c | 8 +- app/test-crypto-perf/cperf_test_throughput.c | 9 +-- app/test-crypto-perf/cperf_test_verify.c | 4 +- app/test-security-perf/test_security_perf.c | 2 +- app/test/test_cryptodev.c | 22 ++---- app/test/test_cryptodev_security_ipsec.c | 2 +- app/test/test_cryptodev_security_ipsec.h | 2 +- app/test/test_security_inline_macsec.c | 10 +-- app/test/test_security_inline_proto.c | 14 ++-- examples/ipsec-secgw/ipsec-secgw.c | 2 +- examples/ipsec-secgw/ipsec.c | 15 ++-- examples/ipsec-secgw/ipsec.h | 2 +- examples/ipsec-secgw/ipsec_worker.c | 2 +- examples/ipsec-secgw/ipsec_worker.h | 4 +- lib/security/rte_security.c | 61 +++++++++------ lib/security/rte_security.h | 77 +++++++++---------- lib/security/rte_security_driver.h | 24 ++++++ 19 files changed, 140 insertions(+), 132 deletions(-)
app/test-crypto-perf/cperf_ops.c +3 -6
@@ -749,8 +749,7 @@ create_ipsec_session(struct rte_mempool *sess_mp,else sess_conf.ipsec.direction =RTE_SECURITY_IPSEC_SA_DIR_INGRESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (dev_id); +void *ctx =rte_cryptodev_get_sec_ctx (dev_id);/* Create security session */ return (void *)rte_security_session_create (ctx, &sess_conf, sess_mp);
@@ -853,8 +852,7 @@ cperf_create_session(struct rte_mempool *sess_mp, .crypto_xform = &cipher_xform }; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (dev_id); +void *ctx =rte_cryptodev_get_sec_ctx (dev_id);/* Create security session */ return (void *)rte_security_session_create (ctx, &sess_conf, sess_mp);
@@ -901,8 +899,7 @@ cperf_create_session(struct rte_mempool *sess_mp, } }, .crypto_xform = &cipher_xform }; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (dev_id); +void *ctx =rte_cryptodev_get_sec_ctx (dev_id);/* Create security session */ return (void *)rte_security_session_create (ctx, &sess_conf, sess_mp);
app/test-crypto-perf/cperf_test_latency.c +1 -2
@@ -53,8 +53,7 @@ cperf_latency_test_free(struct cperf_latency_ctx *ctx) else if (ctx->options->op_type == CPERF_PDCP || ctx->options->op_type == CPERF_DOCSIS || ctx->options->op_type == CPERF_IPSEC) { -struct rte_security_ctx *sec_ctx = -rte_cryptodev_get_sec_ctx (ctx->dev_id); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id);rte_security_session_destroy (sec_ctx, ctx->sess); }#endif
app/test-crypto-perf/cperf_test_pmd_cyclecount.c +3 -5
@@ -67,11 +67,9 @@ cperf_pmd_cyclecount_test_free(struct cperf_pmd_cyclecount_ctx *ctx)#ifdef RTE_LIB_SECURITY if (ctx->options->op_type ==CPERF_PDCP || ctx->options->op_type ==CPERF_DOCSIS ) { -struct rte_security_ctx *sec_ctx = - (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (ctx->dev_id); -rte_security_session_destroy (sec_ctx, - (void *)ctx->sess); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id); + +rte_security_session_destroy (sec_ctx, (void *)ctx->sess); } else#endif rte_cryptodev_sym_session_free (ctx->dev_id, ctx->sess);
app/test-crypto-perf/cperf_test_throughput.c +3 -6
@@ -44,12 +44,9 @@ cperf_throughput_test_free(struct cperf_throughput_ctx *ctx) else if (ctx->options->op_type == CPERF_PDCP || ctx->options->op_type == CPERF_DOCSIS || ctx->options->op_type == CPERF_IPSEC) { -struct rte_security_ctx *sec_ctx = - (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (ctx->dev_id); -rte_security_session_destroy ( - sec_ctx, - (void *)ctx->sess); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id); + +rte_security_session_destroy (sec_ctx, (void *)ctx->sess); }#endif else
app/test-crypto-perf/cperf_test_verify.c +2 -2
@@ -48,8 +48,8 @@ cperf_verify_test_free(struct cperf_verify_ctx *ctx) else if (ctx->options->op_type == CPERF_PDCP || ctx->options->op_type == CPERF_DOCSIS || ctx->options->op_type == CPERF_IPSEC) { -struct rte_security_ctx *sec_ctx = -rte_cryptodev_get_sec_ctx (ctx->dev_id); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id); +rte_security_session_destroy (sec_ctx, ctx->sess); }#endif
app/test-security-perf/test_security_perf.c +1 -1
@@ -344,7 +344,7 @@ test_security_session_perf(void *arg)struct rte_security_session_conf sess_conf;int i, ret, nb_sessions, nb_sess_total;struct rte_security_session **sess; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;double setup_rate, destroy_rate;uint64_t setup_ms, destroy_ms;struct lcore_conf *conf = arg;
app/test/test_cryptodev.c +6 -16
@@ -8931,9 +8931,7 @@ security_proto_supported(enum rte_security_session_action_type action,const struct rte_security_capability *capability;uint16_t i =0 ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]); capabilities =rte_security_capabilities_get (ctx);
@@ -8973,9 +8971,7 @@ static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,struct crypto_unittest_params *ut_params = &unittest_params;uint8_t *plaintext;int ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);struct rte_cryptodev_info dev_info;uint64_t feat_flags;
@@ -9180,9 +9176,7 @@ test_pdcp_proto_SGL(int i, int oop,unsigned int trn_data =0 ;struct rte_cryptodev_info dev_info;uint64_t feat_flags; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);struct rte_mbuf *temp_mbuf;rte_cryptodev_info_get (ts_params->valid_devs[0 ], &dev_info);
@@ -9778,7 +9772,7 @@ test_ipsec_proto_process(const struct ipsec_test_data td[],struct ipsec_test_data *res_d_tmp =NULL ;uint8_t input_text[IPSEC_TEXT_MAX_LEN ];int salt_len, i, ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx; +void *ctx;uint32_t src, dst;uint32_t verify;
@@ -10911,9 +10905,7 @@ test_docsis_proto_uplink(const void *data)uint32_t crc_data_len;int ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);/* Verify the capabilities */ struct rte_security_capability_idx sec_cap_idx;
@@ -11095,9 +11087,7 @@ test_docsis_proto_downlink(const void *data)int32_t cipher_len, crc_len;int ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);/* Verify the capabilities */ struct rte_security_capability_idx sec_cap_idx;
app/test/test_cryptodev_security_ipsec.c +1 -1
@@ -1241,7 +1241,7 @@ test_ipsec_status_check(const struct ipsec_test_data *td, }int -test_ipsec_stats_verify (struct rte_security_ctx *ctx, +test_ipsec_stats_verify (void *ctx,void *sess,const struct ipsec_test_flags *flags,enum rte_security_ipsec_sa_direction dir)
app/test/test_cryptodev_security_ipsec.h +1 -1
@@ -300,7 +300,7 @@ int test_ipsec_status_check(const struct ipsec_test_data *td,enum rte_security_ipsec_sa_direction dir, int pkt_num); -int test_ipsec_stats_verify (struct rte_security_ctx *ctx, +int test_ipsec_stats_verify (void *ctx,void *sess,const struct ipsec_test_flags *flags,enum rte_security_ipsec_sa_direction dir);
app/test/test_security_inline_macsec.c +5 -5
@@ -136,7 +136,7 @@ init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len)static int init_mempools (unsigned int nb_mbuf) { -struct rte_security_ctx *sec_ctx; +void *sec_ctx;uint16_t nb_sess =512 ;uint32_t sess_sz;char s[64 ];
@@ -482,7 +482,7 @@ test_macsec_post_process(struct rte_mbuf *m, const struct mcs_test_vector *td, }static void -mcs_stats_dump (struct rte_security_ctx *ctx,enum mcs_op op, +mcs_stats_dump (void *ctx,enum mcs_op op,void *rx_sess,void *tx_sess,uint8_t rx_sc_id,uint8_t tx_sc_id,uint16_t rx_sa_id[],uint16_t tx_sa_id[])
@@ -667,7 +667,7 @@ mcs_stats_dump(struct rte_security_ctx *ctx, enum mcs_op op, } static int -mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op, +mcs_stats_check(void *ctx, enum mcs_op op, const struct mcs_test_opts *opts, const struct mcs_test_vector *td, void *rx_sess, void *tx_sess,
@@ -900,7 +900,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcsstruct rte_security_macsec_sa sa_conf = {0 };struct rte_security_macsec_sc sc_conf = {0 };struct mcs_err_vector err_vector = {0 }; -struct rte_security_ctx *ctx; +void *ctx;int nb_rx =0 , nb_sent;int i, j =0 , ret, id, an =0 ;uint8_t tci_off;
@@ -908,7 +908,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcsmemset (rx_pkts_burst,0 ,sizeof (rx_pkts_burst[0 ]) * opts->nb_td); - ctx = (struct rte_security_ctx *)rte_eth_dev_get_sec_ctx (port_id); + ctx =rte_eth_dev_get_sec_ctx (port_id);if (ctx ==NULL ) {printf ("Ethernet device doesn't support security features.\n" );return TEST_SKIPPED ;
app/test/test_security_inline_proto.c +7 -7
@@ -136,7 +136,7 @@ static struct rte_flow *default_flow[RTE_MAX_ETHPORTS];/* Create Inline IPsec session */ static int create_inline_ipsec_session (struct ipsec_test_data *sa,uint16_t portid, -void **sess,struct rte_security_ctx **ctx, +void **sess,void **ctx,uint32_t *ol_flags,const struct ipsec_test_flags *flags,struct rte_security_session_conf *sess_conf) {
@@ -149,7 +149,7 @@ create_inline_ipsec_session(struct ipsec_test_data *sa, uint16_t portid,struct rte_security_capability_idx sec_cap_idx;const struct rte_security_capability *sec_cap;enum rte_security_ipsec_sa_direction dir; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;uint32_t verify; sess_conf->action_type =RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL ;
@@ -221,7 +221,7 @@ create_inline_ipsec_session(struct ipsec_test_data *sa, uint16_t portid, sess_conf->userdata = (void *) sa; - sec_ctx = (struct rte_security_ctx *)rte_eth_dev_get_sec_ctx (portid); + sec_ctx =rte_eth_dev_get_sec_ctx (portid);if (sec_ctx ==NULL ) {printf ("Ethernet device doesn't support security features.\n" );return TEST_SKIPPED ;
@@ -503,7 +503,7 @@ init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len, boolstatic int init_mempools (unsigned int nb_mbuf) { -struct rte_security_ctx *sec_ctx; +void *sec_ctx;uint16_t nb_sess =512 ;uint32_t sess_sz;char s[64 ];
@@ -801,7 +801,7 @@ test_ipsec_with_reassembly(struct reassembly_vector *vector,struct rte_crypto_sym_xform auth_in = {0 };struct rte_crypto_sym_xform aead_in = {0 };struct ipsec_test_data sa_data; -struct rte_security_ctx *ctx; +void *ctx;unsigned int i, nb_rx =0 , j;uint32_t ol_flags;bool outer_ipv4;
@@ -1068,7 +1068,7 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,struct rte_crypto_sym_xform auth = {0 };struct rte_crypto_sym_xform aead = {0 };struct sa_expiry_vector vector = {0 }; -struct rte_security_ctx *ctx; +void *ctx;int nb_rx =0 , nb_sent;uint32_t ol_flags;int i, j =0 , ret;
@@ -1338,7 +1338,7 @@ test_ipsec_inline_proto_process_with_esn(struct ipsec_test_data td[],struct rte_mbuf *tx_pkt =NULL ;int nb_rx, nb_sent;void *ses; -struct rte_security_ctx *ctx; +void *ctx;uint32_t ol_flags;bool outer_ipv4;int i, ret;
examples/ipsec-secgw/ipsec-secgw.c +1 -1
@@ -568,7 +568,7 @@ process_pkts_outbound_nosp(struct ipsec_ctx *ipsec_ctx,static inline void process_pkts (struct lcore_conf *qconf,struct rte_mbuf **pkts, -uint8_t nb_pkts,uint16_t portid,struct rte_security_ctx *ctx) +uint8_t nb_pkts,uint16_t portid,void *ctx) {struct ipsec_traffic traffic;
examples/ipsec-secgw/ipsec.c +5 -10
@@ -205,7 +205,7 @@ verify_ipsec_capabilities(struct rte_security_ipsec_xform *ipsec_xform,static inline int -verify_security_capabilities (struct rte_security_ctx *ctx, +verify_security_capabilities (void *ctx,struct rte_security_session_conf *sess_conf,uint32_t *ol_flags) {
@@ -327,9 +327,7 @@ create_lookaside_session(struct ipsec_ctx *ipsec_ctx_lcore[], };if (ips->type ==RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL ) { -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - cdev_id); +void *ctx =rte_cryptodev_get_sec_ctx (cdev_id);/* Set IPsec parameters in conf */ set_ipsec_conf (sa, &(sess_conf.ipsec));
@@ -411,7 +409,7 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa, struct rte_ipsec_session *ips) {int32_t ret =0 ; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;struct rte_security_session_conf sess_conf = { .action_type = ips->type, .protocol =RTE_SECURITY_PROTOCOL_IPSEC ,
@@ -490,9 +488,7 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa,struct rte_flow_error err;int ret =0 ; - sec_ctx = (struct rte_security_ctx *) -rte_eth_dev_get_sec_ctx ( - sa->portid); + sec_ctx =rte_eth_dev_get_sec_ctx (sa->portid);if (sec_ctx ==NULL ) {RTE_LOG (ERR ,IPSEC ," rte_eth_dev_get_sec_ctx failed\n" );
@@ -657,8 +653,7 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa,return -1 ; } }else if (ips->type ==RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL ) { - sec_ctx = (struct rte_security_ctx *) -rte_eth_dev_get_sec_ctx (sa->portid); + sec_ctx =rte_eth_dev_get_sec_ctx (sa->portid);if (sec_ctx ==NULL ) { RTE_LOG(ERR, IPSEC,
examples/ipsec-secgw/ipsec.h +1 -1
@@ -279,7 +279,7 @@ struct cnt_blk {struct lcore_rx_queue {uint16_t port_id;uint8_t queue_id; -struct rte_security_ctx *sec_ctx; +void *sec_ctx; } __rte_cache_aligned;struct buffer {
examples/ipsec-secgw/ipsec_worker.c +1 -1
@@ -20,7 +20,7 @@struct port_drv_mode_data {void *sess; -struct rte_security_ctx *ctx; +void *ctx; };typedef void (*ipsec_worker_fn_t )(void );
examples/ipsec-secgw/ipsec_worker.h +2 -2
@@ -119,7 +119,7 @@ adjust_ipv6_pktlen(struct rte_mbuf *m, const struct rte_ipv6_hdr *iph, } static __rte_always_inline void -prepare_one_packet (struct rte_security_ctx *ctx,struct rte_mbuf *pkt, +prepare_one_packet (void *ctx,struct rte_mbuf *pkt,struct ipsec_traffic *t) {uint32_t ptype = pkt->packet_type;
@@ -230,7 +230,7 @@ prepare_one_packet(struct rte_security_ctx *ctx, struct rte_mbuf *pkt, } static __rte_always_inline void -prepare_traffic (struct rte_security_ctx *ctx,struct rte_mbuf **pkts, +prepare_traffic (void *ctx,struct rte_mbuf **pkts,struct ipsec_traffic *t,uint16_t nb_pkts) {int32_t i;
lib/security/rte_security.c +36 -25
180 lines not on this page · raw message
lib/security/rte_security.h +37 -40
183 lines not on this page · raw message
lib/security/rte_security_driver.h +24 -0
@@ -37,6 +37,30 @@ struct rte_security_session {/**< Private session material, variable size (depends on driver) */ }; +/** +* Security context for crypto/eth devices +* +* Security instance for each driver to register security operations. +* The application can get the security context from the crypto/eth device id +* using the APIs rte_cryptodev_get_sec_ctx()/rte_eth_dev_get_sec_ctx() +* This structure is used to identify the device(crypto/eth) for which the +* security operations need to be performed. +*/ +struct rte_security_ctx { +void *device; +/**< Crypto/ethernet device attached */ +const struct rte_security_ops *ops; +/**< Pointer to security ops for the device */ +uint32_t flags; +/**< Flags for security context */ +uint16_t sess_cnt; +/**< Number of sessions attached to this context */ +uint16_t macsec_sc_cnt; +/**< Number of MACsec SC attached to this context */ +uint16_t macsec_sa_cnt; +/**< Number of MACsec SA attached to this context */ +}; +/** * Helper macro to get driver private data */
Signature · 1 line
2.25.1
Hi Akhil,
Quoted 24 lines
-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Wednesday, September 20, 2023 11:40 AM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; De Lara Guarch, Pablo <[email protected]>; Trahe, Fiona <[email protected]>; Doherty, Declan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nicolau, Radu <[email protected]>; [email protected]; [email protected]; [email protected]; Power, Ciara <[email protected]>; Akhil Goyal <[email protected]>
Subject: [PATCH v2] security: hide security context
rte_security_ctxis used by all security APIs to identify which devicesecurity_opit need to call and hence it should be opaque to the application. Hence, it is now moved to internal header file and all APIs will now take an opaque pointer for it.
The fast path inline APIs like set metadata need to get flags fromsecurity_ctx. The flags are now retrieved using inline APIs which use macros to get the offset of flags insecurity_ctx.
Quoted 1 line
Signed-off-by Akhil Goyal <[email protected]>
PATCH v3 1/1 security: hide security context
In reply to Akhil Goyalrte_security_ctx is used by all security APIs to identify which device security_op it need to call and hence it should be opaque to the application.
Hence, it is now moved to internal header file and all APIs will now take an opaque pointer for it.
The fast path inline APIs like set metadata need to get flags from security_ctx. The flags are now retrieved using inline APIs which use macros to get the offset of flags in security_ctx.
---
Changes in v3: Updated release notes and removed deprecation notice. Changes in v2: Rebased.
app/test-crypto-perf/cperf_ops.c | 9 +-- app/test-crypto-perf/cperf_test_latency.c | 3 +- .../cperf_test_pmd_cyclecount.c | 8 +- app/test-crypto-perf/cperf_test_throughput.c | 9 +-- app/test-crypto-perf/cperf_test_verify.c | 4 +- app/test-security-perf/test_security_perf.c | 2 +- app/test/test_cryptodev.c | 22 ++---- app/test/test_cryptodev_security_ipsec.c | 2 +- app/test/test_cryptodev_security_ipsec.h | 2 +- app/test/test_security_inline_macsec.c | 10 +-- app/test/test_security_inline_proto.c | 14 ++-- doc/guides/rel_notes/deprecation.rst | 3 - doc/guides/rel_notes/release_23_11.rst | 3 + examples/ipsec-secgw/ipsec-secgw.c | 2 +- examples/ipsec-secgw/ipsec.c | 15 ++-- examples/ipsec-secgw/ipsec.h | 2 +- examples/ipsec-secgw/ipsec_worker.c | 2 +- examples/ipsec-secgw/ipsec_worker.h | 4 +- lib/security/rte_security.c | 61 +++++++++------ lib/security/rte_security.h | 77 +++++++++---------- lib/security/rte_security_driver.h | 24 ++++++ 21 files changed, 143 insertions(+), 135 deletions(-)
app/test-crypto-perf/cperf_ops.c +3 -6
@@ -749,8 +749,7 @@ create_ipsec_session(struct rte_mempool *sess_mp,else sess_conf.ipsec.direction =RTE_SECURITY_IPSEC_SA_DIR_INGRESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (dev_id); +void *ctx =rte_cryptodev_get_sec_ctx (dev_id);/* Create security session */ return (void *)rte_security_session_create (ctx, &sess_conf, sess_mp);
@@ -853,8 +852,7 @@ cperf_create_session(struct rte_mempool *sess_mp, .crypto_xform = &cipher_xform }; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (dev_id); +void *ctx =rte_cryptodev_get_sec_ctx (dev_id);/* Create security session */ return (void *)rte_security_session_create (ctx, &sess_conf, sess_mp);
@@ -901,8 +899,7 @@ cperf_create_session(struct rte_mempool *sess_mp, } }, .crypto_xform = &cipher_xform }; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (dev_id); +void *ctx =rte_cryptodev_get_sec_ctx (dev_id);/* Create security session */ return (void *)rte_security_session_create (ctx, &sess_conf, sess_mp);
app/test-crypto-perf/cperf_test_latency.c +1 -2
@@ -53,8 +53,7 @@ cperf_latency_test_free(struct cperf_latency_ctx *ctx) else if (ctx->options->op_type == CPERF_PDCP || ctx->options->op_type == CPERF_DOCSIS || ctx->options->op_type == CPERF_IPSEC) { -struct rte_security_ctx *sec_ctx = -rte_cryptodev_get_sec_ctx (ctx->dev_id); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id);rte_security_session_destroy (sec_ctx, ctx->sess); }#endif
app/test-crypto-perf/cperf_test_pmd_cyclecount.c +3 -5
@@ -67,11 +67,9 @@ cperf_pmd_cyclecount_test_free(struct cperf_pmd_cyclecount_ctx *ctx)#ifdef RTE_LIB_SECURITY if (ctx->options->op_type ==CPERF_PDCP || ctx->options->op_type ==CPERF_DOCSIS ) { -struct rte_security_ctx *sec_ctx = - (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (ctx->dev_id); -rte_security_session_destroy (sec_ctx, - (void *)ctx->sess); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id); + +rte_security_session_destroy (sec_ctx, (void *)ctx->sess); } else#endif rte_cryptodev_sym_session_free (ctx->dev_id, ctx->sess);
app/test-crypto-perf/cperf_test_throughput.c +3 -6
@@ -44,12 +44,9 @@ cperf_throughput_test_free(struct cperf_throughput_ctx *ctx) else if (ctx->options->op_type == CPERF_PDCP || ctx->options->op_type == CPERF_DOCSIS || ctx->options->op_type == CPERF_IPSEC) { -struct rte_security_ctx *sec_ctx = - (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (ctx->dev_id); -rte_security_session_destroy ( - sec_ctx, - (void *)ctx->sess); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id); + +rte_security_session_destroy (sec_ctx, (void *)ctx->sess); }#endif else
app/test-crypto-perf/cperf_test_verify.c +2 -2
@@ -48,8 +48,8 @@ cperf_verify_test_free(struct cperf_verify_ctx *ctx) else if (ctx->options->op_type == CPERF_PDCP || ctx->options->op_type == CPERF_DOCSIS || ctx->options->op_type == CPERF_IPSEC) { -struct rte_security_ctx *sec_ctx = -rte_cryptodev_get_sec_ctx (ctx->dev_id); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id); +rte_security_session_destroy (sec_ctx, ctx->sess); }#endif
app/test-security-perf/test_security_perf.c +1 -1
@@ -344,7 +344,7 @@ test_security_session_perf(void *arg)struct rte_security_session_conf sess_conf;int i, ret, nb_sessions, nb_sess_total;struct rte_security_session **sess; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;double setup_rate, destroy_rate;uint64_t setup_ms, destroy_ms;struct lcore_conf *conf = arg;
app/test/test_cryptodev.c +6 -16
@@ -8931,9 +8931,7 @@ security_proto_supported(enum rte_security_session_action_type action,const struct rte_security_capability *capability;uint16_t i =0 ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]); capabilities =rte_security_capabilities_get (ctx);
@@ -8973,9 +8971,7 @@ static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,struct crypto_unittest_params *ut_params = &unittest_params;uint8_t *plaintext;int ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);struct rte_cryptodev_info dev_info;uint64_t feat_flags;
@@ -9180,9 +9176,7 @@ test_pdcp_proto_SGL(int i, int oop,unsigned int trn_data =0 ;struct rte_cryptodev_info dev_info;uint64_t feat_flags; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);struct rte_mbuf *temp_mbuf;rte_cryptodev_info_get (ts_params->valid_devs[0 ], &dev_info);
@@ -9905,7 +9899,7 @@ test_ipsec_proto_process(const struct ipsec_test_data td[],struct ipsec_test_data *res_d_tmp =NULL ;uint8_t input_text[IPSEC_TEXT_MAX_LEN ];int salt_len, i, ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx; +void *ctx;uint32_t src, dst;uint32_t verify;
@@ -11088,9 +11082,7 @@ test_docsis_proto_uplink(const void *data)uint32_t crc_data_len;int ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);/* Verify the capabilities */ struct rte_security_capability_idx sec_cap_idx;
@@ -11272,9 +11264,7 @@ test_docsis_proto_downlink(const void *data)int32_t cipher_len, crc_len;int ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);/* Verify the capabilities */ struct rte_security_capability_idx sec_cap_idx;
app/test/test_cryptodev_security_ipsec.c +1 -1
@@ -1249,7 +1249,7 @@ test_ipsec_status_check(const struct ipsec_test_data *td, }int -test_ipsec_stats_verify (struct rte_security_ctx *ctx, +test_ipsec_stats_verify (void *ctx,void *sess,const struct ipsec_test_flags *flags,enum rte_security_ipsec_sa_direction dir)
app/test/test_cryptodev_security_ipsec.h +1 -1
@@ -302,7 +302,7 @@ int test_ipsec_status_check(const struct ipsec_test_data *td,enum rte_security_ipsec_sa_direction dir, int pkt_num); -int test_ipsec_stats_verify (struct rte_security_ctx *ctx, +int test_ipsec_stats_verify (void *ctx,void *sess,const struct ipsec_test_flags *flags,enum rte_security_ipsec_sa_direction dir);
app/test/test_security_inline_macsec.c +5 -5
@@ -136,7 +136,7 @@ init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len)static int init_mempools (unsigned int nb_mbuf) { -struct rte_security_ctx *sec_ctx; +void *sec_ctx;uint16_t nb_sess =512 ;uint32_t sess_sz;char s[64 ];
@@ -482,7 +482,7 @@ test_macsec_post_process(struct rte_mbuf *m, const struct mcs_test_vector *td, }static void -mcs_stats_dump (struct rte_security_ctx *ctx,enum mcs_op op, +mcs_stats_dump (void *ctx,enum mcs_op op,void *rx_sess,void *tx_sess,uint8_t rx_sc_id,uint8_t tx_sc_id,uint16_t rx_sa_id[],uint16_t tx_sa_id[])
@@ -667,7 +667,7 @@ mcs_stats_dump(struct rte_security_ctx *ctx, enum mcs_op op, } static int -mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op, +mcs_stats_check(void *ctx, enum mcs_op op, const struct mcs_test_opts *opts, const struct mcs_test_vector *td, void *rx_sess, void *tx_sess,
@@ -900,7 +900,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcsstruct rte_security_macsec_sa sa_conf = {0 };struct rte_security_macsec_sc sc_conf = {0 };struct mcs_err_vector err_vector = {0 }; -struct rte_security_ctx *ctx; +void *ctx;int nb_rx =0 , nb_sent;int i, j =0 , ret, id, an =0 ;uint8_t tci_off;
@@ -908,7 +908,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcsmemset (rx_pkts_burst,0 ,sizeof (rx_pkts_burst[0 ]) * opts->nb_td); - ctx = (struct rte_security_ctx *)rte_eth_dev_get_sec_ctx (port_id); + ctx =rte_eth_dev_get_sec_ctx (port_id);if (ctx ==NULL ) {printf ("Ethernet device doesn't support security features.\n" );return TEST_SKIPPED ;
app/test/test_security_inline_proto.c +7 -7
@@ -136,7 +136,7 @@ static struct rte_flow *default_flow[RTE_MAX_ETHPORTS];/* Create Inline IPsec session */ static int create_inline_ipsec_session (struct ipsec_test_data *sa,uint16_t portid, -void **sess,struct rte_security_ctx **ctx, +void **sess,void **ctx,uint32_t *ol_flags,const struct ipsec_test_flags *flags,struct rte_security_session_conf *sess_conf) {
@@ -149,7 +149,7 @@ create_inline_ipsec_session(struct ipsec_test_data *sa, uint16_t portid,struct rte_security_capability_idx sec_cap_idx;const struct rte_security_capability *sec_cap;enum rte_security_ipsec_sa_direction dir; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;uint32_t verify; sess_conf->action_type =RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL ;
@@ -221,7 +221,7 @@ create_inline_ipsec_session(struct ipsec_test_data *sa, uint16_t portid, sess_conf->userdata = (void *) sa; - sec_ctx = (struct rte_security_ctx *)rte_eth_dev_get_sec_ctx (portid); + sec_ctx =rte_eth_dev_get_sec_ctx (portid);if (sec_ctx ==NULL ) {printf ("Ethernet device doesn't support security features.\n" );return TEST_SKIPPED ;
@@ -503,7 +503,7 @@ init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len, boolstatic int init_mempools (unsigned int nb_mbuf) { -struct rte_security_ctx *sec_ctx; +void *sec_ctx;uint16_t nb_sess =512 ;uint32_t sess_sz;char s[64 ];
@@ -846,7 +846,7 @@ test_ipsec_with_reassembly(struct reassembly_vector *vector,struct rte_crypto_sym_xform auth_in = {0 };struct rte_crypto_sym_xform aead_in = {0 };struct ipsec_test_data sa_data; -struct rte_security_ctx *ctx; +void *ctx;unsigned int i, nb_rx =0 , j;uint32_t ol_flags;bool outer_ipv4;
@@ -1113,7 +1113,7 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,struct rte_crypto_sym_xform auth = {0 };struct rte_crypto_sym_xform aead = {0 };struct sa_expiry_vector vector = {0 }; -struct rte_security_ctx *ctx; +void *ctx;int nb_rx =0 , nb_sent;uint32_t ol_flags;int i, j =0 , ret;
@@ -1398,7 +1398,7 @@ test_ipsec_inline_proto_process_with_esn(struct ipsec_test_data td[],struct rte_mbuf *tx_pkt =NULL ;int nb_rx, nb_sent;void *ses; -struct rte_security_ctx *ctx; +void *ctx;uint32_t ol_flags;bool outer_ipv4;int i, ret;
doc/guides/rel_notes/deprecation.rst +0 -3
@@ -139,9 +139,6 @@ Deprecation Notices which got error interrupt to the application, so that application can reset that particular queue pair. -* security: Hide structures ``rte_security_ops`` and ``rte_security_ctx`` - as these are internal to DPDK library and drivers. - * eventdev: The single-event (non-burst) enqueue and dequeue operations, used by static inline burst enqueue and dequeue functions in ``rte_eventdev.h``, will be removed in DPDK 23.11.
doc/guides/rel_notes/release_23_11.rst +3 -0
@@ -144,6 +144,9 @@ API Changes except ``rte_thread_setname()`` and ``rte_ctrl_thread_create()`` which are replaced with ``rte_thread_set_name()`` and ``rte_thread_create_control()``. +* security: Structures ``rte_security_ops`` and ``rte_security_ctx`` were moved to + internal library headers not visible to application. + ABI Changes -----------
examples/ipsec-secgw/ipsec-secgw.c +1 -1
@@ -568,7 +568,7 @@ process_pkts_outbound_nosp(struct ipsec_ctx *ipsec_ctx,static inline void process_pkts (struct lcore_conf *qconf,struct rte_mbuf **pkts, -uint8_t nb_pkts,uint16_t portid,struct rte_security_ctx *ctx) +uint8_t nb_pkts,uint16_t portid,void *ctx) {struct ipsec_traffic traffic;
examples/ipsec-secgw/ipsec.c +5 -10
@@ -205,7 +205,7 @@ verify_ipsec_capabilities(struct rte_security_ipsec_xform *ipsec_xform,static inline int -verify_security_capabilities (struct rte_security_ctx *ctx, +verify_security_capabilities (void *ctx,struct rte_security_session_conf *sess_conf,uint32_t *ol_flags) {
@@ -327,9 +327,7 @@ create_lookaside_session(struct ipsec_ctx *ipsec_ctx_lcore[], };if (ips->type ==RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL ) { -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - cdev_id); +void *ctx =rte_cryptodev_get_sec_ctx (cdev_id);/* Set IPsec parameters in conf */ set_ipsec_conf (sa, &(sess_conf.ipsec));
@@ -411,7 +409,7 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa, struct rte_ipsec_session *ips) {int32_t ret =0 ; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;struct rte_security_session_conf sess_conf = { .action_type = ips->type, .protocol =RTE_SECURITY_PROTOCOL_IPSEC ,
@@ -490,9 +488,7 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa,struct rte_flow_error err;int ret =0 ; - sec_ctx = (struct rte_security_ctx *) -rte_eth_dev_get_sec_ctx ( - sa->portid); + sec_ctx =rte_eth_dev_get_sec_ctx (sa->portid);if (sec_ctx ==NULL ) {RTE_LOG (ERR ,IPSEC ," rte_eth_dev_get_sec_ctx failed\n" );
@@ -657,8 +653,7 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa,return -1 ; } }else if (ips->type ==RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL ) { - sec_ctx = (struct rte_security_ctx *) -rte_eth_dev_get_sec_ctx (sa->portid); + sec_ctx =rte_eth_dev_get_sec_ctx (sa->portid);if (sec_ctx ==NULL ) { RTE_LOG(ERR, IPSEC,
examples/ipsec-secgw/ipsec.h +1 -1
@@ -279,7 +279,7 @@ struct cnt_blk {struct lcore_rx_queue {uint16_t port_id;uint8_t queue_id; -struct rte_security_ctx *sec_ctx; +void *sec_ctx; } __rte_cache_aligned;struct buffer {
examples/ipsec-secgw/ipsec_worker.c +1 -1
@@ -20,7 +20,7 @@struct port_drv_mode_data {void *sess; -struct rte_security_ctx *ctx; +void *ctx; };typedef void (*ipsec_worker_fn_t )(void );
examples/ipsec-secgw/ipsec_worker.h +2 -2
@@ -119,7 +119,7 @@ adjust_ipv6_pktlen(struct rte_mbuf *m, const struct rte_ipv6_hdr *iph, } static __rte_always_inline void -prepare_one_packet (struct rte_security_ctx *ctx,struct rte_mbuf *pkt, +prepare_one_packet (void *ctx,struct rte_mbuf *pkt,struct ipsec_traffic *t) {uint32_t ptype = pkt->packet_type;
@@ -230,7 +230,7 @@ prepare_one_packet(struct rte_security_ctx *ctx, struct rte_mbuf *pkt, } static __rte_always_inline void -prepare_traffic (struct rte_security_ctx *ctx,struct rte_mbuf **pkts, +prepare_traffic (void *ctx,struct rte_mbuf **pkts,struct ipsec_traffic *t,uint16_t nb_pkts) {int32_t i;
lib/security/rte_security.c +36 -25
180 lines not on this page · raw message
lib/security/rte_security.h +37 -40
183 lines not on this page · raw message
lib/security/rte_security_driver.h +24 -0
@@ -37,6 +37,30 @@ struct rte_security_session {/**< Private session material, variable size (depends on driver) */ }; +/** +* Security context for crypto/eth devices +* +* Security instance for each driver to register security operations. +* The application can get the security context from the crypto/eth device id +* using the APIs rte_cryptodev_get_sec_ctx()/rte_eth_dev_get_sec_ctx() +* This structure is used to identify the device(crypto/eth) for which the +* security operations need to be performed. +*/ +struct rte_security_ctx { +void *device; +/**< Crypto/ethernet device attached */ +const struct rte_security_ops *ops; +/**< Pointer to security ops for the device */ +uint32_t flags; +/**< Flags for security context */ +uint16_t sess_cnt; +/**< Number of sessions attached to this context */ +uint16_t macsec_sc_cnt; +/**< Number of MACsec SC attached to this context */ +uint16_t macsec_sa_cnt; +/**< Number of MACsec SA attached to this context */ +}; +/** * Helper macro to get driver private data */
Signature · 1 line
2.25.1
PATCH v4 1/1 security: hide security context
rte_security_ctx is used by all security APIs to identify which device security_op it need to call and hence it should be opaque to the application.
Hence, it is now moved to internal header file and all APIs will now take an opaque pointer for it.
The fast path inline APIs like set metadata need to get flags from security_ctx. The flags are now retrieved using inline APIs which use macros to get the offset of flags in security_ctx.
---
Changes in v4: Updated rte_security doc.
Changes in v3: Updated release notes and removed deprecation notice. Changes in v2: Rebased.
app/test-crypto-perf/cperf_ops.c | 9 +-- app/test-crypto-perf/cperf_test_latency.c | 3 +- .../cperf_test_pmd_cyclecount.c | 8 +- app/test-crypto-perf/cperf_test_throughput.c | 9 +-- app/test-crypto-perf/cperf_test_verify.c | 4 +- app/test-security-perf/test_security_perf.c | 2 +- app/test/test_cryptodev.c | 22 ++---- app/test/test_cryptodev_security_ipsec.c | 2 +- app/test/test_cryptodev_security_ipsec.h | 2 +- app/test/test_security_inline_macsec.c | 10 +-- app/test/test_security_inline_proto.c | 14 ++-- doc/guides/prog_guide/rte_security.rst | 2 +- doc/guides/rel_notes/deprecation.rst | 3 - doc/guides/rel_notes/release_23_11.rst | 3 + examples/ipsec-secgw/ipsec-secgw.c | 2 +- examples/ipsec-secgw/ipsec.c | 15 ++-- examples/ipsec-secgw/ipsec.h | 2 +- examples/ipsec-secgw/ipsec_worker.c | 2 +- examples/ipsec-secgw/ipsec_worker.h | 4 +- lib/security/rte_security.c | 61 +++++++++------ lib/security/rte_security.h | 77 +++++++++---------- lib/security/rte_security_driver.h | 24 ++++++ 22 files changed, 144 insertions(+), 136 deletions(-)
app/test-crypto-perf/cperf_ops.c +3 -6
@@ -749,8 +749,7 @@ create_ipsec_session(struct rte_mempool *sess_mp,else sess_conf.ipsec.direction =RTE_SECURITY_IPSEC_SA_DIR_INGRESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (dev_id); +void *ctx =rte_cryptodev_get_sec_ctx (dev_id);/* Create security session */ return (void *)rte_security_session_create (ctx, &sess_conf, sess_mp);
@@ -853,8 +852,7 @@ cperf_create_session(struct rte_mempool *sess_mp, .crypto_xform = &cipher_xform }; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (dev_id); +void *ctx =rte_cryptodev_get_sec_ctx (dev_id);/* Create security session */ return (void *)rte_security_session_create (ctx, &sess_conf, sess_mp);
@@ -901,8 +899,7 @@ cperf_create_session(struct rte_mempool *sess_mp, } }, .crypto_xform = &cipher_xform }; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (dev_id); +void *ctx =rte_cryptodev_get_sec_ctx (dev_id);/* Create security session */ return (void *)rte_security_session_create (ctx, &sess_conf, sess_mp);
app/test-crypto-perf/cperf_test_latency.c +1 -2
@@ -53,8 +53,7 @@ cperf_latency_test_free(struct cperf_latency_ctx *ctx) else if (ctx->options->op_type == CPERF_PDCP || ctx->options->op_type == CPERF_DOCSIS || ctx->options->op_type == CPERF_IPSEC) { -struct rte_security_ctx *sec_ctx = -rte_cryptodev_get_sec_ctx (ctx->dev_id); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id);rte_security_session_destroy (sec_ctx, ctx->sess); }#endif
app/test-crypto-perf/cperf_test_pmd_cyclecount.c +3 -5
@@ -67,11 +67,9 @@ cperf_pmd_cyclecount_test_free(struct cperf_pmd_cyclecount_ctx *ctx)#ifdef RTE_LIB_SECURITY if (ctx->options->op_type ==CPERF_PDCP || ctx->options->op_type ==CPERF_DOCSIS ) { -struct rte_security_ctx *sec_ctx = - (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (ctx->dev_id); -rte_security_session_destroy (sec_ctx, - (void *)ctx->sess); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id); + +rte_security_session_destroy (sec_ctx, (void *)ctx->sess); } else#endif rte_cryptodev_sym_session_free (ctx->dev_id, ctx->sess);
app/test-crypto-perf/cperf_test_throughput.c +3 -6
@@ -44,12 +44,9 @@ cperf_throughput_test_free(struct cperf_throughput_ctx *ctx) else if (ctx->options->op_type == CPERF_PDCP || ctx->options->op_type == CPERF_DOCSIS || ctx->options->op_type == CPERF_IPSEC) { -struct rte_security_ctx *sec_ctx = - (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx (ctx->dev_id); -rte_security_session_destroy ( - sec_ctx, - (void *)ctx->sess); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id); + +rte_security_session_destroy (sec_ctx, (void *)ctx->sess); }#endif else
app/test-crypto-perf/cperf_test_verify.c +2 -2
@@ -48,8 +48,8 @@ cperf_verify_test_free(struct cperf_verify_ctx *ctx) else if (ctx->options->op_type == CPERF_PDCP || ctx->options->op_type == CPERF_DOCSIS || ctx->options->op_type == CPERF_IPSEC) { -struct rte_security_ctx *sec_ctx = -rte_cryptodev_get_sec_ctx (ctx->dev_id); +void *sec_ctx =rte_cryptodev_get_sec_ctx (ctx->dev_id); +rte_security_session_destroy (sec_ctx, ctx->sess); }#endif
app/test-security-perf/test_security_perf.c +1 -1
@@ -344,7 +344,7 @@ test_security_session_perf(void *arg)struct rte_security_session_conf sess_conf;int i, ret, nb_sessions, nb_sess_total;struct rte_security_session **sess; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;double setup_rate, destroy_rate;uint64_t setup_ms, destroy_ms;struct lcore_conf *conf = arg;
app/test/test_cryptodev.c +6 -16
@@ -8931,9 +8931,7 @@ security_proto_supported(enum rte_security_session_action_type action,const struct rte_security_capability *capability;uint16_t i =0 ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]); capabilities =rte_security_capabilities_get (ctx);
@@ -8973,9 +8971,7 @@ static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,struct crypto_unittest_params *ut_params = &unittest_params;uint8_t *plaintext;int ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);struct rte_cryptodev_info dev_info;uint64_t feat_flags;
@@ -9180,9 +9176,7 @@ test_pdcp_proto_SGL(int i, int oop,unsigned int trn_data =0 ;struct rte_cryptodev_info dev_info;uint64_t feat_flags; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);struct rte_mbuf *temp_mbuf;rte_cryptodev_info_get (ts_params->valid_devs[0 ], &dev_info);
@@ -9905,7 +9899,7 @@ test_ipsec_proto_process(const struct ipsec_test_data td[],struct ipsec_test_data *res_d_tmp =NULL ;uint8_t input_text[IPSEC_TEXT_MAX_LEN ];int salt_len, i, ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx; +void *ctx;uint32_t src, dst;uint32_t verify;
@@ -11088,9 +11082,7 @@ test_docsis_proto_uplink(const void *data)uint32_t crc_data_len;int ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);/* Verify the capabilities */ struct rte_security_capability_idx sec_cap_idx;
@@ -11272,9 +11264,7 @@ test_docsis_proto_downlink(const void *data)int32_t cipher_len, crc_len;int ret =TEST_SUCCESS ; -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - ts_params->valid_devs[0 ]); +void *ctx =rte_cryptodev_get_sec_ctx (ts_params->valid_devs[0 ]);/* Verify the capabilities */ struct rte_security_capability_idx sec_cap_idx;
app/test/test_cryptodev_security_ipsec.c +1 -1
@@ -1249,7 +1249,7 @@ test_ipsec_status_check(const struct ipsec_test_data *td, }int -test_ipsec_stats_verify (struct rte_security_ctx *ctx, +test_ipsec_stats_verify (void *ctx,void *sess,const struct ipsec_test_flags *flags,enum rte_security_ipsec_sa_direction dir)
app/test/test_cryptodev_security_ipsec.h +1 -1
@@ -302,7 +302,7 @@ int test_ipsec_status_check(const struct ipsec_test_data *td,enum rte_security_ipsec_sa_direction dir, int pkt_num); -int test_ipsec_stats_verify (struct rte_security_ctx *ctx, +int test_ipsec_stats_verify (void *ctx,void *sess,const struct ipsec_test_flags *flags,enum rte_security_ipsec_sa_direction dir);
app/test/test_security_inline_macsec.c +5 -5
@@ -136,7 +136,7 @@ init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len)static int init_mempools (unsigned int nb_mbuf) { -struct rte_security_ctx *sec_ctx; +void *sec_ctx;uint16_t nb_sess =512 ;uint32_t sess_sz;char s[64 ];
@@ -482,7 +482,7 @@ test_macsec_post_process(struct rte_mbuf *m, const struct mcs_test_vector *td, }static void -mcs_stats_dump (struct rte_security_ctx *ctx,enum mcs_op op, +mcs_stats_dump (void *ctx,enum mcs_op op,void *rx_sess,void *tx_sess,uint8_t rx_sc_id,uint8_t tx_sc_id,uint16_t rx_sa_id[],uint16_t tx_sa_id[])
@@ -667,7 +667,7 @@ mcs_stats_dump(struct rte_security_ctx *ctx, enum mcs_op op, } static int -mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op, +mcs_stats_check(void *ctx, enum mcs_op op, const struct mcs_test_opts *opts, const struct mcs_test_vector *td, void *rx_sess, void *tx_sess,
@@ -900,7 +900,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcsstruct rte_security_macsec_sa sa_conf = {0 };struct rte_security_macsec_sc sc_conf = {0 };struct mcs_err_vector err_vector = {0 }; -struct rte_security_ctx *ctx; +void *ctx;int nb_rx =0 , nb_sent;int i, j =0 , ret, id, an =0 ;uint8_t tci_off;
@@ -908,7 +908,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcsmemset (rx_pkts_burst,0 ,sizeof (rx_pkts_burst[0 ]) * opts->nb_td); - ctx = (struct rte_security_ctx *)rte_eth_dev_get_sec_ctx (port_id); + ctx =rte_eth_dev_get_sec_ctx (port_id);if (ctx ==NULL ) {printf ("Ethernet device doesn't support security features.\n" );return TEST_SKIPPED ;
app/test/test_security_inline_proto.c +7 -7
@@ -136,7 +136,7 @@ static struct rte_flow *default_flow[RTE_MAX_ETHPORTS];/* Create Inline IPsec session */ static int create_inline_ipsec_session (struct ipsec_test_data *sa,uint16_t portid, -void **sess,struct rte_security_ctx **ctx, +void **sess,void **ctx,uint32_t *ol_flags,const struct ipsec_test_flags *flags,struct rte_security_session_conf *sess_conf) {
@@ -149,7 +149,7 @@ create_inline_ipsec_session(struct ipsec_test_data *sa, uint16_t portid,struct rte_security_capability_idx sec_cap_idx;const struct rte_security_capability *sec_cap;enum rte_security_ipsec_sa_direction dir; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;uint32_t verify; sess_conf->action_type =RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL ;
@@ -221,7 +221,7 @@ create_inline_ipsec_session(struct ipsec_test_data *sa, uint16_t portid, sess_conf->userdata = (void *) sa; - sec_ctx = (struct rte_security_ctx *)rte_eth_dev_get_sec_ctx (portid); + sec_ctx =rte_eth_dev_get_sec_ctx (portid);if (sec_ctx ==NULL ) {printf ("Ethernet device doesn't support security features.\n" );return TEST_SKIPPED ;
@@ -503,7 +503,7 @@ init_packet(struct rte_mempool *mp, const uint8_t *data, unsigned int len, boolstatic int init_mempools (unsigned int nb_mbuf) { -struct rte_security_ctx *sec_ctx; +void *sec_ctx;uint16_t nb_sess =512 ;uint32_t sess_sz;char s[64 ];
@@ -846,7 +846,7 @@ test_ipsec_with_reassembly(struct reassembly_vector *vector,struct rte_crypto_sym_xform auth_in = {0 };struct rte_crypto_sym_xform aead_in = {0 };struct ipsec_test_data sa_data; -struct rte_security_ctx *ctx; +void *ctx;unsigned int i, nb_rx =0 , j;uint32_t ol_flags;bool outer_ipv4;
@@ -1113,7 +1113,7 @@ test_ipsec_inline_proto_process(struct ipsec_test_data *td,struct rte_crypto_sym_xform auth = {0 };struct rte_crypto_sym_xform aead = {0 };struct sa_expiry_vector vector = {0 }; -struct rte_security_ctx *ctx; +void *ctx;int nb_rx =0 , nb_sent;uint32_t ol_flags;int i, j =0 , ret;
@@ -1398,7 +1398,7 @@ test_ipsec_inline_proto_process_with_esn(struct ipsec_test_data td[],struct rte_mbuf *tx_pkt =NULL ;int nb_rx, nb_sent;void *ses; -struct rte_security_ctx *ctx; +void *ctx;uint32_t ol_flags;bool outer_ipv4;int i, ret;
doc/guides/prog_guide/rte_security.rst +1 -1
@@ -637,7 +637,7 @@ And the session mempool object size should be enough to accommodate Once the session mempools have been created, ``rte_security_session_create()`` is used to allocate and initialize a session for the required crypto/ethernet device. -Session APIs need a parameter ``rte_security_ctx`` to identify the crypto/ethernet +Session APIs need an opaque handle to identify the crypto/ethernet security ops. This parameter can be retrieved using the APIs ``rte_cryptodev_get_sec_ctx()`` (for crypto device) or ``rte_eth_dev_get_sec_ctx`` (for ethernet port).
doc/guides/rel_notes/deprecation.rst +0 -3
@@ -139,9 +139,6 @@ Deprecation Notices which got error interrupt to the application, so that application can reset that particular queue pair. -* security: Hide structures ``rte_security_ops`` and ``rte_security_ctx`` - as these are internal to DPDK library and drivers. - * eventdev: The single-event (non-burst) enqueue and dequeue operations, used by static inline burst enqueue and dequeue functions in ``rte_eventdev.h``, will be removed in DPDK 23.11.
doc/guides/rel_notes/release_23_11.rst +3 -0
@@ -144,6 +144,9 @@ API Changes except ``rte_thread_setname()`` and ``rte_ctrl_thread_create()`` which are replaced with ``rte_thread_set_name()`` and ``rte_thread_create_control()``. +* security: Structures ``rte_security_ops`` and ``rte_security_ctx`` were moved to + internal library headers not visible to application. + ABI Changes -----------
examples/ipsec-secgw/ipsec-secgw.c +1 -1
@@ -568,7 +568,7 @@ process_pkts_outbound_nosp(struct ipsec_ctx *ipsec_ctx,static inline void process_pkts (struct lcore_conf *qconf,struct rte_mbuf **pkts, -uint8_t nb_pkts,uint16_t portid,struct rte_security_ctx *ctx) +uint8_t nb_pkts,uint16_t portid,void *ctx) {struct ipsec_traffic traffic;
examples/ipsec-secgw/ipsec.c +5 -10
@@ -205,7 +205,7 @@ verify_ipsec_capabilities(struct rte_security_ipsec_xform *ipsec_xform,static inline int -verify_security_capabilities (struct rte_security_ctx *ctx, +verify_security_capabilities (void *ctx,struct rte_security_session_conf *sess_conf,uint32_t *ol_flags) {
@@ -327,9 +327,7 @@ create_lookaside_session(struct ipsec_ctx *ipsec_ctx_lcore[], };if (ips->type ==RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL ) { -struct rte_security_ctx *ctx = (struct rte_security_ctx *) -rte_cryptodev_get_sec_ctx ( - cdev_id); +void *ctx =rte_cryptodev_get_sec_ctx (cdev_id);/* Set IPsec parameters in conf */ set_ipsec_conf (sa, &(sess_conf.ipsec));
@@ -411,7 +409,7 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa, struct rte_ipsec_session *ips) {int32_t ret =0 ; -struct rte_security_ctx *sec_ctx; +void *sec_ctx;struct rte_security_session_conf sess_conf = { .action_type = ips->type, .protocol =RTE_SECURITY_PROTOCOL_IPSEC ,
@@ -490,9 +488,7 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa,struct rte_flow_error err;int ret =0 ; - sec_ctx = (struct rte_security_ctx *) -rte_eth_dev_get_sec_ctx ( - sa->portid); + sec_ctx =rte_eth_dev_get_sec_ctx (sa->portid);if (sec_ctx ==NULL ) {RTE_LOG (ERR ,IPSEC ," rte_eth_dev_get_sec_ctx failed\n" );
@@ -657,8 +653,7 @@ create_inline_session(struct socket_ctx *skt_ctx, struct ipsec_sa *sa,return -1 ; } }else if (ips->type ==RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL ) { - sec_ctx = (struct rte_security_ctx *) -rte_eth_dev_get_sec_ctx (sa->portid); + sec_ctx =rte_eth_dev_get_sec_ctx (sa->portid);if (sec_ctx ==NULL ) { RTE_LOG(ERR, IPSEC,
examples/ipsec-secgw/ipsec.h +1 -1
@@ -279,7 +279,7 @@ struct cnt_blk {struct lcore_rx_queue {uint16_t port_id;uint8_t queue_id; -struct rte_security_ctx *sec_ctx; +void *sec_ctx; } __rte_cache_aligned;struct buffer {
examples/ipsec-secgw/ipsec_worker.c +1 -1
@@ -20,7 +20,7 @@struct port_drv_mode_data {void *sess; -struct rte_security_ctx *ctx; +void *ctx; };typedef void (*ipsec_worker_fn_t )(void );
examples/ipsec-secgw/ipsec_worker.h +2 -2
@@ -119,7 +119,7 @@ adjust_ipv6_pktlen(struct rte_mbuf *m, const struct rte_ipv6_hdr *iph, } static __rte_always_inline void -prepare_one_packet (struct rte_security_ctx *ctx,struct rte_mbuf *pkt, +prepare_one_packet (void *ctx,struct rte_mbuf *pkt,struct ipsec_traffic *t) {uint32_t ptype = pkt->packet_type;
@@ -230,7 +230,7 @@ prepare_one_packet(struct rte_security_ctx *ctx, struct rte_mbuf *pkt, } static __rte_always_inline void -prepare_traffic (struct rte_security_ctx *ctx,struct rte_mbuf **pkts, +prepare_traffic (void *ctx,struct rte_mbuf **pkts,struct ipsec_traffic *t,uint16_t nb_pkts) {int32_t i;
lib/security/rte_security.c +36 -25
180 lines not on this page · raw message
lib/security/rte_security.h +37 -40
183 lines not on this page · raw message
lib/security/rte_security_driver.h +24 -0
@@ -37,6 +37,30 @@ struct rte_security_session {/**< Private session material, variable size (depends on driver) */ }; +/** +* Security context for crypto/eth devices +* +* Security instance for each driver to register security operations. +* The application can get the security context from the crypto/eth device id +* using the APIs rte_cryptodev_get_sec_ctx()/rte_eth_dev_get_sec_ctx() +* This structure is used to identify the device(crypto/eth) for which the +* security operations need to be performed. +*/ +struct rte_security_ctx { +void *device; +/**< Crypto/ethernet device attached */ +const struct rte_security_ops *ops; +/**< Pointer to security ops for the device */ +uint32_t flags; +/**< Flags for security context */ +uint16_t sess_cnt; +/**< Number of sessions attached to this context */ +uint16_t macsec_sc_cnt; +/**< Number of MACsec SC attached to this context */ +uint16_t macsec_sa_cnt; +/**< Number of MACsec SA attached to this context */ +}; +/** * Helper macro to get driver private data */
Signature · 1 line
2.25.1
Akhil Goyal
AppliedQuoted 11 lines
Subject: [PATCH v4] security: hide security context
rte_security_ctxis used by all security APIs to identify which devicesecurity_opit need to call and hence it should be opaque to the application.
Hence, it is now moved to internal header file and all APIs will now take an opaque pointer for it.
The fast path inline APIs like set metadata need to get flags fromsecurity_ctx. The flags are now retrieved using inline APIs which use macros to get the offset of flags insecurity_ctx.
Quoted 2 lines
Signed-off-by Akhil Goyal <[email protected]>Acked-by Ciara Power <[email protected]>
Applied to dpdk-next-crypto