DPDK  23.07.0
rte_security.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2017,2019-2020 NXP
3  * Copyright(c) 2017-2020 Intel Corporation.
4  */
5 
6 #ifndef _RTE_SECURITY_H_
7 #define _RTE_SECURITY_H_
8 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 #include <sys/types.h>
20 
21 #include <rte_compat.h>
22 #include <rte_common.h>
23 #include <rte_crypto.h>
24 #include <rte_ip.h>
25 #include <rte_mbuf_dyn.h>
26 
33 };
34 
41 };
42 
49 };
50 
56 #define RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR 0x1
57 #define RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR 0x2
58 
69  void *device;
71  const struct rte_security_ops *ops;
73  uint16_t sess_cnt;
75  uint16_t macsec_sc_cnt;
77  uint16_t macsec_sa_cnt;
79  uint32_t flags;
81 };
82 
83 #define RTE_SEC_CTX_F_FAST_SET_MDATA 0x00000001
84 
98  union {
99  struct {
100  struct in_addr src_ip;
102  struct in_addr dst_ip;
104  uint8_t dscp;
106  uint8_t df;
108  uint8_t ttl;
110  } ipv4;
112  struct {
113  struct in6_addr src_addr;
115  struct in6_addr dst_addr;
117  uint8_t dscp;
119  uint32_t flabel;
121  uint8_t hlimit;
123  } ipv6;
125  };
126 };
127 
128 struct rte_security_ipsec_udp_param {
129  uint16_t sport;
130  uint16_t dport;
131 };
132 
142  uint32_t esn : 1;
143 
150  uint32_t udp_encap : 1;
151 
159  uint32_t copy_dscp : 1;
160 
167  uint32_t copy_flabel : 1;
168 
175  uint32_t copy_df : 1;
176 
184  uint32_t dec_ttl : 1;
185 
193  uint32_t ecn : 1;
194 
201  uint32_t stats : 1;
202 
215  uint32_t iv_gen_disable : 1;
216 
224  uint32_t tunnel_hdr_verify : 2;
225 
231  uint32_t udp_ports_verify : 1;
232 
246  uint32_t ip_csum_enable : 1;
247 
262  uint32_t l4_csum_enable : 1;
263 
275  uint32_t ip_reassembly_en : 1;
276 
284  uint32_t reserved_opts : 17;
285 };
286 
293 };
294 
317 };
318 
325  uint32_t spi;
327  uint32_t salt;
341  uint32_t replay_win_sz;
345  union {
346  uint64_t value;
347  struct {
348  uint32_t low;
349  uint32_t hi;
350  };
351  } esn;
353  struct rte_security_ipsec_udp_param udp;
355 };
356 
365 };
366 
368 #define RTE_SECURITY_MACSEC_NUM_AN 4
369 
370 #define RTE_SECURITY_MACSEC_SALT_LEN 12
371 
379  struct {
380  const uint8_t *data;
381  uint16_t length;
382  } key;
386  uint8_t an : 2;
388  uint32_t ssci;
390  uint32_t xpn;
392  uint32_t next_pn;
393 };
394 
402  uint64_t pn_threshold;
403  union {
404  struct {
406  uint16_t sa_id[RTE_SECURITY_MACSEC_NUM_AN];
408  uint8_t sa_in_use[RTE_SECURITY_MACSEC_NUM_AN];
410  uint8_t active : 1;
412  uint8_t is_xpn : 1;
414  uint8_t reserved : 6;
415  } sc_rx;
416  struct {
417  uint16_t sa_id;
418  uint16_t sa_id_rekey;
419  uint64_t sci;
420  uint8_t active : 1;
421  uint8_t re_key_en : 1;
423  uint8_t is_xpn : 1;
425  uint8_t reserved : 5;
426  } sc_tx;
427  };
428 };
429 
438 };
439 
441 #define RTE_SECURITY_MACSEC_VALIDATE_DISABLE 0
442 
443 #define RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD 1
444 
445 #define RTE_SECURITY_MACSEC_VALIDATE_STRICT 2
446 
447 #define RTE_SECURITY_MACSEC_VALIDATE_NO_OP 3
448 
458  uint8_t cipher_off;
463  uint64_t sci;
465  uint16_t sc_id;
466  union {
467  struct {
469  uint16_t mtu;
474  uint8_t sectag_off;
476  uint16_t protect_frames : 1;
483  uint16_t sectag_insert_mode : 1;
485  uint16_t icv_include_da_sa : 1;
487  uint16_t ctrl_port_enable : 1;
489  uint16_t sectag_version : 1;
491  uint16_t end_station : 1;
493  uint16_t send_sci : 1;
495  uint16_t scb : 1;
500  uint16_t encrypt : 1;
502  uint16_t reserved : 7;
503  } tx_secy;
504  struct {
506  uint32_t replay_win_sz;
508  uint16_t validate_frames : 2;
510  uint16_t icv_include_da_sa : 1;
512  uint16_t ctrl_port_enable : 1;
514  uint16_t preserve_sectag : 1;
516  uint16_t preserve_icv : 1;
518  uint16_t replay_protect : 1;
520  uint16_t reserved : 9;
521  } rx_secy;
522  };
523 };
524 
532 };
533 
538 };
539 
552 };
553 
560  int8_t bearer;
564  uint8_t en_ordering;
579  uint32_t hfn;
581  uint32_t hfn_threshold;
590  uint8_t hfn_ovrd;
596  uint8_t sdap_enabled;
598  uint16_t reserved;
599 };
600 
611 };
612 
621 };
622 
645 };
646 
657 };
658 
668  union {
669  struct rte_security_ipsec_xform ipsec;
670  struct rte_security_macsec_xform macsec;
671  struct rte_security_pdcp_xform pdcp;
672  struct rte_security_docsis_xform docsis;
673  };
677  void *userdata;
679 };
680 
691 void *
693  struct rte_security_session_conf *conf,
694  struct rte_mempool *mp);
695 
706 __rte_experimental
707 int
709  void *sess,
710  struct rte_security_session_conf *conf);
711 
721 unsigned int
723 
738 int
739 rte_security_session_destroy(struct rte_security_ctx *instance, void *sess);
740 
756 __rte_experimental
757 int
759  struct rte_security_macsec_sc *conf);
760 
775 __rte_experimental
776 int
777 rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id,
779 
795 __rte_experimental
796 int
798  struct rte_security_macsec_sa *conf);
799 
814 __rte_experimental
815 int
816 rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id,
818 
820 typedef uint64_t rte_security_dynfield_t;
823 
837 __rte_experimental
838 static inline rte_security_dynfield_t *
840 {
841  return RTE_MBUF_DYNFIELD(mbuf,
842  rte_security_dynfield_offset,
843  rte_security_dynfield_t *);
844 }
845 
854 __rte_experimental
855 static inline bool rte_security_dynfield_is_registered(void)
856 {
857  return rte_security_dynfield_offset >= 0;
858 }
859 
860 #define RTE_SECURITY_SESS_OPAQUE_DATA_OFF 0
861 #define RTE_SECURITY_SESS_FAST_MDATA_OFF 1
862 
865 static inline uint64_t
867 {
868  return *((uint64_t *)sess + RTE_SECURITY_SESS_OPAQUE_DATA_OFF);
869 }
870 
874 static inline void
875 rte_security_session_opaque_data_set(void *sess, uint64_t opaque)
876 {
877  uint64_t *data;
878  data = (((uint64_t *)sess) + RTE_SECURITY_SESS_OPAQUE_DATA_OFF);
879  *data = opaque;
880 }
881 
885 static inline uint64_t
887 {
888  return *((uint64_t *)sess + RTE_SECURITY_SESS_FAST_MDATA_OFF);
889 }
890 
894 static inline void
895 rte_security_session_fast_mdata_set(void *sess, uint64_t fdata)
896 {
897  uint64_t *data;
898  data = (((uint64_t *)sess) + RTE_SECURITY_SESS_FAST_MDATA_OFF);
899  *data = fdata;
900 }
901 
903 __rte_experimental
905  void *sess,
906  struct rte_mbuf *m, void *params);
907 
921 static inline int
923  void *sess,
924  struct rte_mbuf *mb, void *params)
925 {
926  /* Fast Path */
927  if (instance->flags & RTE_SEC_CTX_F_FAST_SET_MDATA) {
930  return 0;
931  }
932 
933  /* Jump to PMD specific function pointer */
934  return __rte_security_set_pkt_metadata(instance, sess, mb, params);
935 }
936 
943 static inline int
945 {
946  sym_op->session = sess;
947 
948  return 0;
949 }
950 
960 static inline int
962  void *sess)
963 {
965  return -EINVAL;
966 
968 
969  return __rte_security_attach_session(op->sym, sess);
970 }
971 
972 struct rte_security_macsec_secy_stats {
973  uint64_t ctl_pkt_bcast_cnt;
974  uint64_t ctl_pkt_mcast_cnt;
975  uint64_t ctl_pkt_ucast_cnt;
976  uint64_t ctl_octet_cnt;
977  uint64_t unctl_pkt_bcast_cnt;
978  uint64_t unctl_pkt_mcast_cnt;
979  uint64_t unctl_pkt_ucast_cnt;
980  uint64_t unctl_octet_cnt;
981  /* Valid only for Rx */
982  uint64_t octet_decrypted_cnt;
983  uint64_t octet_validated_cnt;
984  uint64_t pkt_port_disabled_cnt;
985  uint64_t pkt_badtag_cnt;
986  uint64_t pkt_nosa_cnt;
987  uint64_t pkt_nosaerror_cnt;
988  uint64_t pkt_tagged_ctl_cnt;
989  uint64_t pkt_untaged_cnt;
990  uint64_t pkt_ctl_cnt;
991  uint64_t pkt_notag_cnt;
992  /* Valid only for Tx */
993  uint64_t octet_encrypted_cnt;
994  uint64_t octet_protected_cnt;
995  uint64_t pkt_noactivesa_cnt;
996  uint64_t pkt_toolong_cnt;
997  uint64_t pkt_untagged_cnt;
998 };
999 
1000 struct rte_security_macsec_sc_stats {
1001  /* Rx */
1002  uint64_t hit_cnt;
1003  uint64_t pkt_invalid_cnt;
1004  uint64_t pkt_late_cnt;
1005  uint64_t pkt_notvalid_cnt;
1006  uint64_t pkt_unchecked_cnt;
1007  uint64_t pkt_delay_cnt;
1008  uint64_t pkt_ok_cnt;
1009  uint64_t octet_decrypt_cnt;
1010  uint64_t octet_validate_cnt;
1011  /* Tx */
1012  uint64_t pkt_encrypt_cnt;
1013  uint64_t pkt_protected_cnt;
1014  uint64_t octet_encrypt_cnt;
1015  uint64_t octet_protected_cnt;
1016 };
1017 
1018 struct rte_security_macsec_sa_stats {
1019  /* Rx */
1020  uint64_t pkt_invalid_cnt;
1021  uint64_t pkt_nosaerror_cnt;
1022  uint64_t pkt_notvalid_cnt;
1023  uint64_t pkt_ok_cnt;
1024  uint64_t pkt_nosa_cnt;
1025  /* Tx */
1026  uint64_t pkt_encrypt_cnt;
1027  uint64_t pkt_protected_cnt;
1028 };
1029 
1030 struct rte_security_ipsec_stats {
1031  uint64_t ipackets;
1032  uint64_t opackets;
1033  uint64_t ibytes;
1034  uint64_t obytes;
1035  uint64_t ierrors;
1036  uint64_t oerrors;
1037  uint64_t reserved1;
1038  uint64_t reserved2;
1039 };
1040 
1041 struct rte_security_pdcp_stats {
1042  uint64_t reserved;
1043 };
1044 
1045 struct rte_security_docsis_stats {
1046  uint64_t reserved;
1047 };
1048 
1049 struct rte_security_stats {
1050  enum rte_security_session_protocol protocol;
1053  RTE_STD_C11
1054  union {
1055  struct rte_security_macsec_secy_stats macsec;
1056  struct rte_security_ipsec_stats ipsec;
1057  struct rte_security_pdcp_stats pdcp;
1058  struct rte_security_docsis_stats docsis;
1059  };
1060 };
1061 
1075 __rte_experimental
1076 int
1078  void *sess,
1079  struct rte_security_stats *stats);
1080 
1095 __rte_experimental
1096 int
1098  uint16_t sa_id, enum rte_security_macsec_direction dir,
1099  struct rte_security_macsec_sa_stats *stats);
1100 
1115 __rte_experimental
1116 int
1118  uint16_t sc_id, enum rte_security_macsec_direction dir,
1119  struct rte_security_macsec_sc_stats *stats);
1120 
1129  RTE_STD_C11
1130  union {
1131  struct {
1144  } ipsec;
1146  struct {
1148  uint16_t mtu;
1152  uint16_t max_nb_sc;
1154  uint16_t max_nb_sa;
1156  uint16_t max_nb_sess;
1158  uint32_t replay_win_sz;
1162  uint16_t fixed_sectag_insert : 1;
1164  uint16_t icv_include_da_sa : 1;
1166  uint16_t ctrl_port_enable : 1;
1168  uint16_t preserve_sectag : 1;
1170  uint16_t preserve_icv : 1;
1172  uint16_t validate_frames : 1;
1174  uint16_t re_key : 1;
1176  uint16_t anti_replay : 1;
1178  uint16_t reserved : 7;
1179  } macsec;
1181  struct {
1184  uint32_t capa_flags;
1186  } pdcp;
1188  struct {
1191  } docsis;
1193  };
1194 
1198  uint32_t ol_flags;
1200 };
1201 
1207 #define RTE_SECURITY_PDCP_ORDERING_CAP 0x00000001
1208 
1213 #define RTE_SECURITY_PDCP_DUP_DETECT_CAP 0x00000002
1214 
1215 #define RTE_SECURITY_TX_OLOAD_NEED_MDATA 0x00000001
1216 
1219 #define RTE_SECURITY_TX_HW_TRAILER_OFFLOAD 0x00000002
1220 
1225 #define RTE_SECURITY_RX_HW_TRAILER_OFFLOAD 0x00010000
1226 
1238  enum rte_security_session_protocol protocol;
1239 
1240  RTE_STD_C11
1241  union {
1242  struct {
1243  enum rte_security_ipsec_sa_protocol proto;
1244  enum rte_security_ipsec_sa_mode mode;
1245  enum rte_security_ipsec_sa_direction direction;
1246  } ipsec;
1247  struct {
1248  enum rte_security_pdcp_domain domain;
1249  uint32_t capa_flags;
1250  } pdcp;
1251  struct {
1252  enum rte_security_docsis_direction direction;
1253  } docsis;
1254  };
1255 };
1256 
1266 const struct rte_security_capability *
1268 
1280 const struct rte_security_capability *
1282  struct rte_security_capability_idx *idx);
1283 
1284 #ifdef __cplusplus
1285 }
1286 #endif
1287 
1288 #endif /* _RTE_SECURITY_H_ */
rte_security_pdcp_sn_size
Definition: rte_security.h:541
rte_security_ipsec_sa_protocol
Definition: rte_security.h:36
struct rte_ether_addr src_addr
Definition: rte_ether.h:269
rte_security_session_action_type
Definition: rte_security.h:626
const uint8_t * data
Definition: rte_security.h:380
rte_security_pdcp_direction
Definition: rte_security.h:535
__rte_experimental int rte_security_macsec_sa_create(struct rte_security_ctx *instance, struct rte_security_macsec_sa *conf)
const struct rte_security_capability * rte_security_capabilities_get(struct rte_security_ctx *instance)
unsigned int rte_security_session_get_size(struct rte_security_ctx *instance)
static int rte_security_set_pkt_metadata(struct rte_security_ctx *instance, void *sess, struct rte_mbuf *mb, void *params)
Definition: rte_security.h:922
uint8_t type
Definition: rte_crypto.h:88
struct rte_crypto_sym_xform * crypto_xform
Definition: rte_security.h:675
uint16_t macsec_sc_cnt
Definition: rte_security.h:75
static __rte_experimental rte_security_dynfield_t * rte_security_dynfield(struct rte_mbuf *mbuf)
Definition: rte_security.h:839
__rte_experimental int rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id, enum rte_security_macsec_direction dir)
rte_security_ipsec_sa_mode
Definition: rte_security.h:28
static void rte_security_session_fast_mdata_set(void *sess, uint64_t fdata)
Definition: rte_security.h:895
uint16_t sess_cnt
Definition: rte_security.h:73
static uint64_t rte_security_session_opaque_data_get(void *sess)
Definition: rte_security.h:866
void * rte_security_session_create(struct rte_security_ctx *instance, struct rte_security_session_conf *conf, struct rte_mempool *mp)
int rte_security_dynfield_offset
rte_security_ipsec_sa_direction
Definition: rte_security.h:288
rte_security_ipsec_tunnel_type
Definition: rte_security.h:44
struct rte_ether_addr dst_addr
Definition: rte_ether.h:268
#define RTE_SECURITY_MACSEC_NUM_AN
Definition: rte_security.h:368
#define RTE_MBUF_DYNFIELD(m, offset, type)
Definition: rte_mbuf_dyn.h:227
int rte_security_session_destroy(struct rte_security_ctx *instance, void *sess)
__rte_experimental int rte_security_session_update(struct rte_security_ctx *instance, void *sess, struct rte_security_session_conf *conf)
#define RTE_SEC_CTX_F_FAST_SET_MDATA
Definition: rte_security.h:83
#define unlikely(x)
__rte_experimental int rte_security_macsec_sc_create(struct rte_security_ctx *instance, struct rte_security_macsec_sc *conf)
__rte_experimental int rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id, enum rte_security_macsec_direction dir)
static int __rte_security_attach_session(struct rte_crypto_sym_op *sym_op, void *sess)
Definition: rte_security.h:944
rte_security_macsec_direction
Definition: rte_security.h:360
#define RTE_STD_C11
Definition: rte_common.h:39
__rte_experimental int rte_security_macsec_sc_stats_get(struct rte_security_ctx *instance, uint16_t sc_id, enum rte_security_macsec_direction dir, struct rte_security_macsec_sc_stats *stats)
static void rte_security_session_opaque_data_set(void *sess, uint64_t opaque)
Definition: rte_security.h:875
static __rte_experimental bool rte_security_dynfield_is_registered(void)
Definition: rte_security.h:855
uint16_t macsec_sa_cnt
Definition: rte_security.h:77
static int rte_security_attach_session(struct rte_crypto_op *op, void *sess)
Definition: rte_security.h:961
static uint64_t rte_security_session_fast_mdata_get(void *sess)
Definition: rte_security.h:886
__rte_experimental int rte_security_session_stats_get(struct rte_security_ctx *instance, void *sess, struct rte_security_stats *stats)
rte_security_docsis_direction
Definition: rte_security.h:602
uint64_t rte_security_dynfield_t
Definition: rte_security.h:820
#define RTE_SECURITY_MACSEC_SALT_LEN
Definition: rte_security.h:370
const struct rte_security_capability * rte_security_capability_get(struct rte_security_ctx *instance, struct rte_security_capability_idx *idx)
const struct rte_cryptodev_capabilities * crypto_capabilities
__rte_experimental int rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance, uint16_t sa_id, enum rte_security_macsec_direction dir, struct rte_security_macsec_sa_stats *stats)
rte_security_macsec_alg
Definition: rte_security.h:433
uint8_t sess_type
Definition: rte_crypto.h:98
rte_security_session_protocol
Definition: rte_security.h:648
rte_security_pdcp_domain
Definition: rte_security.h:528
__rte_experimental int __rte_security_set_pkt_metadata(struct rte_security_ctx *instance, void *sess, struct rte_mbuf *m, void *params)
const struct rte_security_ops * ops
Definition: rte_security.h:71
struct rte_crypto_sym_op sym[0]
Definition: rte_crypto.h:134