new features for ipsec and security libraries
cover new features for ipsec and security libraries
Add support for:
TSO, NAT-T/UDP encapsulation, ESNAES_CCM, CHACHA20_POLY1305 and AES_GMAC
SA telemetry
mbuf offload flags
Initial SQN value
Radu Nicolau (10):
security: add support for TSO on IPsec session
security: add UDP params for IPsec NAT-T
security: add ESN field to ipsec_xform
mbuf: add IPsec ESP tunnel type
ipsec: add support for AEAD algorithms
ipsec: add transmit segmentation offload support
ipsec: add support for NAT-T
ipsec: add support for SA telemetry
ipsec: add support for initial SQN value
ipsec: add ol_flags support
lib/ipsec/crypto.h | 137 ++++++++++++ lib/ipsec/esp_inb.c | 88 +++++++- lib/ipsec/esp_outb.c | 262 +++++++++++++++++++---- lib/ipsec/iph.h | 23 +- lib/ipsec/meson.build | 2 +- lib/ipsec/rte_ipsec.h | 11 + lib/ipsec/rte_ipsec_sa.h | 11 +- lib/ipsec/sa.c | 406 ++++++++++++++++++++++++++++++++++-- lib/ipsec/sa.h | 43 ++++ lib/ipsec/version.map | 8 + lib/mbuf/rte_mbuf_core.h | 1 + lib/security/rte_security.h | 31 +++ 12 files changed, 950 insertions(+), 73 deletions(-)
Signature · 1 line
2.25.1
RFC 1/10 security: add support for TSO on IPsec session
Allow user to provision a per security session maximum segment size (MSS) for use when Transmit Segmentation Offload (TSO) is supported. The MSS value will be used when PKT_TX_TCP_SEG or PKT_TX_UDP_SEG ol_flags are specified in mbuf.
--- lib/security/rte_security.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
lib/security/rte_security.h +15 -0
@@ -181,6 +181,19 @@ struct rte_security_ipsec_sa_options {* * 0: Disable per session security statistics collection for this SA. */ uint32_t stats : 1; + +/** Transmit Segmentation Offload (TSO) +* +* * 1: Enable per session security TSO support, use MSS value provide +* in IPsec security session when PKT_TX_TCP_SEG or PKT_TX_UDP_SEG +* ol_flags are set in mbuf. +* this SA, if supported by the driver. +* * 0: No TSO support for offload IPsec packets. Hardware will not +* attempt to segment packet, and packet transmission will fail if +* larger than MTU of interface +*/ + uint32_t tso : 1; + };/** IPSec security association direction */
@@ -217,6 +230,8 @@ struct rte_security_ipsec_xform {/**< Anti replay window size to enable sequence replay attack handling. * replay checking is disabled if the window size is 0. */ +uint32_t mss; +/**< IPsec payload Maximum Segment Size */ };/**
Signature · 1 line
2.25.1
RFC 2/10 security: add UDP params for IPsec NAT-T
In reply to Radu NicolauAdd support for specifying UDP port params for UDP encapsulation option.
--- lib/security/rte_security.h | 8 ++++++++ 1 file changed, 8 insertions(+)
lib/security/rte_security.h +8 -0
@@ -112,6 +112,12 @@ struct rte_security_ipsec_tunnel_param { }; }; +struct rte_security_ipsec_udp_param { + +uint16_t sport; +uint16_t dport; +}; +/** * IPsec Security Association option flags */
@@ -224,6 +230,8 @@ struct rte_security_ipsec_xform {/**< IPsec SA Mode - transport/tunnel */ struct rte_security_ipsec_tunnel_param tunnel;/**< Tunnel parameters, NULL for transport mode */ +struct rte_security_ipsec_udp_param udp; +/**< UDP parameters, ignored when udp_encap option not specified */ uint64_t esn_soft_limit;/**< ESN for which the overflow event need to be raised */ uint32_t replay_win_sz;
Signature · 1 line
2.25.1
RFC 3/10 security: add ESN field to ipsec_xform
In reply to Radu NicolauUpdate ipsec_xform definition to include ESN field.
--- lib/security/rte_security.h | 8 ++++++++ 1 file changed, 8 insertions(+)
lib/security/rte_security.h +8 -0
@@ -240,6 +240,14 @@ struct rte_security_ipsec_xform {*/ uint32_t mss;/**< IPsec payload Maximum Segment Size */ +union { +uint64_t value; +struct { +uint32_t low; +uint32_t hi; + }; + } esn; +/**< Extended Sequence Number */ };/**
Signature · 1 line
2.25.1
RFC 4/10 mbuf: add IPsec ESP tunnel type
In reply to Radu NicolauAdd tunnel type for IPsec ESP tunnels
--- lib/mbuf/rte_mbuf_core.h | 1 + 1 file changed, 1 insertion(+)
lib/mbuf/rte_mbuf_core.h +1 -0
@@ -253,6 +253,7 @@ extern "C" {#define PKT_TX_TUNNEL_MPLSINUDP (0x5ULL << 45)#define PKT_TX_TUNNEL_VXLAN_GPE (0x6ULL << 45)#define PKT_TX_TUNNEL_GTP (0x7ULL << 45) +#define PKT_TX_TUNNEL_ESP (0x8ULL << 45)/** * Generic IP encapsulated tunnel type, used for TSO and checksum offload. * It can be used for tunnels which are not standards or listed above.
Signature · 1 line
2.25.1
RFC 5/10 ipsec: add support for AEAD algorithms
In reply to Radu NicolauAdd support for AES_CCM, CHACHA20_POLY1305 and AES_GMAC.
--- lib/ipsec/crypto.h | 137 +++++++++++++++++++++++++++++++++++++++++++ lib/ipsec/esp_inb.c | 66 ++++++++++++++++++++- lib/ipsec/esp_outb.c | 70 +++++++++++++++++++++- lib/ipsec/sa.c | 54 +++++++++++++++-- lib/ipsec/sa.h | 6 ++ 5 files changed, 322 insertions(+), 11 deletions(-)
lib/ipsec/crypto.h +137 -0
@@ -21,6 +21,37 @@ struct aesctr_cnt_blk {uint32_t cnt; } __rte_packed; +/* +* CHACHA20-POLY1305 devices have some specific requirements +* for IV and AAD formats. +* Ideally that to be done by the driver itself. +*/ + +struct aead_chacha20_poly1305_iv { +uint32_t salt; +uint64_t iv; +uint32_t cnt; +} __rte_packed; + +struct aead_chacha20_poly1305_aad { +uint32_t spi; +/* +* RFC 4106, section 5: +* Two formats of the AAD are defined: +* one for 32-bit sequence numbers, and one for 64-bit ESN. +*/ +union { +uint32_t u32[2 ]; +uint64_t u64; + } sqn; +uint32_t align0;/* align to 16B boundary */ +} __rte_packed; + +struct chacha20_poly1305_esph_iv { +struct rte_esp_hdr esph; +uint64_t iv; +} __rte_packed; +/* * AES-GCM devices have some specific requirements for IV and AAD formats. * Ideally that to be done by the driver itself.
@@ -51,6 +82,47 @@ struct gcm_esph_iv {uint64_t iv; } __rte_packed; +/* +* AES-CCM devices have some specific requirements for IV and AAD formats. +* Ideally that to be done by the driver itself. +*/ +union aead_ccm_salt { +uint32_t salt; +struct inner { +uint8_t salt8[3 ]; +uint8_t ccm_flags; + } inner; +} salt_union; + + +struct aead_ccm_iv { +uint8_t ccm_flags; +uint8_t salt[3 ]; +uint64_t iv; +uint32_t cnt; +} __rte_packed; + +struct aead_ccm_aad { +uint8_t padding[18 ]; +uint32_t spi; +/* +* RFC 4309, section 5: +* Two formats of the AAD are defined: +* one for 32-bit sequence numbers, and one for 64-bit ESN. +*/ +union { +uint32_t u32[2 ]; +uint64_t u64; + } sqn; +uint32_t align0;/* align to 16B boundary */ +} __rte_packed; + +struct ccm_esph_iv { +struct rte_esp_hdr esph; +uint64_t iv; +} __rte_packed; + +static inline void aes_ctr_cnt_blk_fill (struct aesctr_cnt_blk *ctr,uint64_t iv,uint32_t nonce) {
@@ -59,6 +131,16 @@ aes_ctr_cnt_blk_fill(struct aesctr_cnt_blk *ctr, uint64_t iv, uint32_t nonce) ctr->cnt =rte_cpu_to_be_32 (1 ); } +static inline void +aead_chacha20_poly1305_iv_fill (struct aead_chacha20_poly1305_iv + *chacha20_poly1305, +uint64_t iv,uint32_t salt) +{ + chacha20_poly1305->salt = salt; + chacha20_poly1305->iv = iv; + chacha20_poly1305->cnt =rte_cpu_to_be_32 (1 ); +} +static inline void aead_gcm_iv_fill (struct aead_gcm_iv *gcm,uint64_t iv,uint32_t salt) {
@@ -67,6 +149,21 @@ aead_gcm_iv_fill(struct aead_gcm_iv *gcm, uint64_t iv, uint32_t salt) gcm->cnt =rte_cpu_to_be_32 (1 ); } +static inline void +aead_ccm_iv_fill (struct aead_ccm_iv *ccm,uint64_t iv,uint32_t salt) +{ +union aead_ccm_salt tsalt; + + tsalt.salt = salt; + ccm->ccm_flags = tsalt.inner.ccm_flags; + ccm->salt[0 ] = tsalt.inner.salt8[0 ]; + ccm->salt[1 ] = tsalt.inner.salt8[1 ]; + ccm->salt[2 ] = tsalt.inner.salt8[2 ]; + ccm->iv = iv; + ccm->cnt =rte_cpu_to_be_32 (1 ); +} + +/* * RFC 4106, 5 AAD Construction * spi and sqn should already be converted into network byte order.
@@ -86,6 +183,25 @@ aead_gcm_aad_fill(struct aead_gcm_aad *aad, rte_be32_t spi, rte_be64_t sqn, aad->align0 =0 ; } +/* +* RFC 4309, 5 AAD Construction +* spi and sqn should already be converted into network byte order. +* Make sure that not used bytes are zeroed. +*/ +static inline void +aead_ccm_aad_fill (struct aead_ccm_aad *aad,rte_be32_t spi,rte_be64_t sqn, +int esn) +{ + aad->spi = spi; +if (esn) + aad->sqn.u64 = sqn; +else { + aad->sqn.u32[0 ] =sqn_low32 (sqn); + aad->sqn.u32[1 ] =0 ; + } + aad->align0 =0 ; +} +static inline void gen_iv (uint64_t iv[IPSEC_MAX_IV_QWORD ],rte_be64_t sqn) {
@@ -93,6 +209,27 @@ gen_iv(uint64_t iv[IPSEC_MAX_IV_QWORD], rte_be64_t sqn) iv[1 ] =0 ; } + +/* +* RFC 4106, 5 AAD Construction +* spi and sqn should already be converted into network byte order. +* Make sure that not used bytes are zeroed. +*/ +static inline void +aead_chacha20_poly1305_aad_fill (struct aead_chacha20_poly1305_aad *aad, +rte_be32_t spi,rte_be64_t sqn, +int esn) +{ + aad->spi = spi; +if (esn) + aad->sqn.u64 = sqn; +else { + aad->sqn.u32[0 ] =sqn_low32 (sqn); + aad->sqn.u32[1 ] =0 ; + } + aad->align0 =0 ; +} +/* * Helper routine to copy IV * Right now we support only algorithms with IV length equals 0/8/16 bytes.
lib/ipsec/esp_inb.c +63 -3
111 lines not on this page · raw message
lib/ipsec/esp_outb.c +67 -3
113 lines not on this page · raw message
lib/ipsec/sa.c +49 -5
107 lines not on this page · raw message
lib/ipsec/sa.h +6 -0
@@ -19,7 +19,10 @@ enum {IPSEC_PAD_AES_CBC =IPSEC_MAX_IV_SIZE ,IPSEC_PAD_AES_CTR =IPSEC_PAD_DEFAULT ,IPSEC_PAD_AES_GCM =IPSEC_PAD_DEFAULT , +IPSEC_PAD_AES_CCM =IPSEC_PAD_DEFAULT , +IPSEC_PAD_CHACHA20_POLY1305 =IPSEC_PAD_DEFAULT ,IPSEC_PAD_NULL =IPSEC_PAD_DEFAULT , + IPSEC_PAD_AES_GMAC = IPSEC_PAD_DEFAULT, };/* iv sizes for different algorithms */
@@ -67,6 +70,9 @@ enum sa_algo_type {ALGO_TYPE_AES_CBC ,ALGO_TYPE_AES_CTR ,ALGO_TYPE_AES_GCM , +ALGO_TYPE_AES_CCM , +ALGO_TYPE_CHACHA20_POLY1305 , +ALGO_TYPE_AES_GMAC , ALGO_TYPE_MAX };
Signature · 1 line
2.25.1
RFC 6/10 ipsec: add transmit segmentation offload support
In reply to Radu NicolauAdd support for transmit segmentation offload to inline crypto processing mode. This offload is not supported by other offload modes, as at a minimum it requires inline crypto for IPsec to be supported on the network interface.
--- lib/ipsec/esp_inb.c | 4 +- lib/ipsec/esp_outb.c | 115 +++++++++++++++++++++++++++++++++++-------- lib/ipsec/iph.h | 10 +++- lib/ipsec/sa.c | 6 +++ lib/ipsec/sa.h | 4 ++ 5 files changed, 114 insertions(+), 25 deletions(-)
lib/ipsec/esp_inb.c +2 -2
@@ -668,8 +668,8 @@ trs_process(const struct rte_ipsec_sa *sa, struct rte_mbuf *mb[],/* modify packet's layout */ np =trs_process_step2 (mb[i], ml[i], hl[i], cofs, to[i], tl, sqn + k); -update_trs_l3hdr (sa, np + l2, mb[i]->pkt_len, - l2, hl[i] - l2, espt[i].next_proto); +update_trs_l34hdrs (sa, np + l2, mb[i]->pkt_len, + l2, hl[i] - l2, espt[i].next_proto,0 );/* update mbuf's metadata */ trs_process_step3 (mb[i]);
lib/ipsec/esp_outb.c +94 -21
211 lines not on this page · raw message
lib/ipsec/iph.h +8 -2
@@ -6,6 +6,8 @@#define _IPH_H_#include <rte_ip.h> +#include <rte_udp.h> +#include <rte_tcp.h> /** * @file iph.h
@@ -39,8 +41,8 @@ insert_esph(char *np, char *op, uint32_t hlen)/* update original ip header fields for transport case */ static inline int -update_trs_l3hdr (const struct rte_ipsec_sa *sa,void *p,uint32_t plen, -uint32_t l2len,uint32_t l3len,uint8_t proto) +update_trs_l34hdrs (const struct rte_ipsec_sa *sa,void *p,uint32_t plen, +uint32_t l2len,uint32_t l3len,uint8_t proto,uint8_t tso) {int32_t rc;
@@ -51,6 +53,10 @@ update_trs_l3hdr(const struct rte_ipsec_sa *sa, void *p, uint32_t plen, v4h = p; rc = v4h->next_proto_id; v4h->next_proto_id = proto; +if (tso) { + v4h->hdr_checksum =0 ; + v4h->total_length =0 ; + } v4h->total_length =rte_cpu_to_be_16 (plen - l2len);/* IPv6 */ }else {
lib/ipsec/sa.c +6 -0
@@ -565,6 +565,12 @@ rte_ipsec_sa_init(struct rte_ipsec_sa *sa, const struct rte_ipsec_sa_prm *prm, sa->type = type; sa->size = sz; + +if (prm->ipsec_xform.options.tso ==1 ) { + sa->tso.enabled =1 ; + sa->tso.mss = prm->ipsec_xform.mss; + } +/* check for ESN flag */ sa->sqn_mask = (prm->ipsec_xform.options.esn ==0 ) ?UINT32_MAX :UINT64_MAX ;
lib/ipsec/sa.h +4 -0
@@ -113,6 +113,10 @@ struct rte_ipsec_sa {uint8_t iv_len;uint8_t pad_align;uint8_t tos_mask; +struct { +uint8_t enabled:1 ; +uint16_t mss; + } tso;/* template for tunnel header */ uint8_t hdr[IPSEC_MAX_HDR_SIZE ];
Signature · 1 line
2.25.1
RFC 7/10 ipsec: add support for NAT-T
In reply to Radu NicolauAdd support for the IPsec NAT-Traversal use case for Tunnel mode packets.
--- lib/ipsec/iph.h | 13 +++++++++++++ lib/ipsec/rte_ipsec_sa.h | 8 +++++++- lib/ipsec/sa.c | 13 ++++++++++++- lib/ipsec/sa.h | 4 ++++ 4 files changed, 36 insertions(+), 2 deletions(-)
lib/ipsec/iph.h +13 -0
@@ -251,6 +251,7 @@ update_tun_outb_l3hdr(const struct rte_ipsec_sa *sa, void *outh, {struct rte_ipv4_hdr *v4h;struct rte_ipv6_hdr *v6h; +struct rte_udp_hdr *udph;uint8_t is_outh_ipv4;if (sa->type &RTE_IPSEC_SATP_MODE_TUNLV4 ) {
@@ -258,11 +259,23 @@ update_tun_outb_l3hdr(const struct rte_ipsec_sa *sa, void *outh, v4h = outh; v4h->packet_id = pid; v4h->total_length =rte_cpu_to_be_16 (plen - l2len); + +if (sa->type &RTE_IPSEC_SATP_NATT_ENABLE ) { + udph = (struct rte_udp_hdr *)(v4h +1 ); + udph->dgram_len =rte_cpu_to_be_16 (plen - l2len - + (sizeof (*v4h) +sizeof (*udph))); + } }else { is_outh_ipv4 =0 ; v6h = outh; v6h->payload_len =rte_cpu_to_be_16 (plen - l2len -sizeof (*v6h)); + +if (sa->type &RTE_IPSEC_SATP_NATT_ENABLE ) { + udph = (struct rte_udp_hdr *)(v6h +1 ); + udph->dgram_len =rte_cpu_to_be_16 (plen - l2len - + (sizeof (*v6h) +sizeof (*udph))); + } }if (sa->type &TUN_HDR_MSK )
lib/ipsec/rte_ipsec_sa.h +7 -1
@@ -76,6 +76,7 @@ struct rte_ipsec_sa_prm {* - inbound/outbound * - mode (TRANSPORT/TUNNEL) * - for TUNNEL outer IP version (IPv4/IPv6) +* - NAT-T UDP encapsulated (TUNNEL mode only) * - are SA SQN operations 'atomic' * - ESN enabled/disabled * ...
@@ -86,7 +87,8 @@ enum {RTE_SATP_LOG2_PROTO ,RTE_SATP_LOG2_DIR ,RTE_SATP_LOG2_MODE , -RTE_SATP_LOG2_SQN =RTE_SATP_LOG2_MODE +2 , +RTE_SATP_LOG2_NATT =RTE_SATP_LOG2_MODE +2 , +RTE_SATP_LOG2_SQN ,RTE_SATP_LOG2_ESN ,RTE_SATP_LOG2_ECN ,RTE_SATP_LOG2_DSCP
@@ -109,6 +111,10 @@ enum {#define RTE_IPSEC_SATP_MODE_TUNLV4 (1ULL << RTE_SATP_LOG2_MODE)#define RTE_IPSEC_SATP_MODE_TUNLV6 (2ULL << RTE_SATP_LOG2_MODE) +#define RTE_IPSEC_SATP_NATT_MASK (1ULL << RTE_SATP_LOG2_NATT) +#define RTE_IPSEC_SATP_NATT_DISABLE (0ULL << RTE_SATP_LOG2_NATT) +#define RTE_IPSEC_SATP_NATT_ENABLE (1ULL << RTE_SATP_LOG2_NATT) +#define RTE_IPSEC_SATP_SQN_MASK (1ULL << RTE_SATP_LOG2_SQN)#define RTE_IPSEC_SATP_SQN_RAW (0ULL << RTE_SATP_LOG2_SQN)#define RTE_IPSEC_SATP_SQN_ATOM (1ULL << RTE_SATP_LOG2_SQN)
lib/ipsec/sa.c +12 -1
@@ -217,6 +217,10 @@ fill_sa_type(const struct rte_ipsec_sa_prm *prm, uint64_t *type) }else return -EINVAL ; +/* check for UDP encapsulation flag */ +if (prm->ipsec_xform.options.udp_encap ==1 ) + tp |=RTE_IPSEC_SATP_NATT_ENABLE ; +/* check for ESN flag */ if (prm->ipsec_xform.options.esn ==0 ) tp |=RTE_IPSEC_SATP_ESN_DISABLE ;
@@ -372,7 +376,8 @@ esp_sa_init(struct rte_ipsec_sa *sa, const struct rte_ipsec_sa_prm *prm, const struct crypto_xform *cxf) {static const uint64_t msk =RTE_IPSEC_SATP_DIR_MASK | -RTE_IPSEC_SATP_MODE_MASK ; +RTE_IPSEC_SATP_MODE_MASK | +RTE_IPSEC_SATP_NATT_MASK ;if (prm->ipsec_xform.options.ecn) sa->tos_mask |=RTE_IPV4_HDR_ECN_MASK ;
@@ -475,10 +480,16 @@ esp_sa_init(struct rte_ipsec_sa *sa, const struct rte_ipsec_sa_prm *prm,case (RTE_IPSEC_SATP_DIR_IB |RTE_IPSEC_SATP_MODE_TRANS ):esp_inb_init (sa);break ; +case (RTE_IPSEC_SATP_DIR_OB |RTE_IPSEC_SATP_MODE_TUNLV4 | +RTE_IPSEC_SATP_NATT_ENABLE ): +case (RTE_IPSEC_SATP_DIR_OB |RTE_IPSEC_SATP_MODE_TUNLV6 | +RTE_IPSEC_SATP_NATT_ENABLE ):case (RTE_IPSEC_SATP_DIR_OB |RTE_IPSEC_SATP_MODE_TUNLV4 ):case (RTE_IPSEC_SATP_DIR_OB |RTE_IPSEC_SATP_MODE_TUNLV6 ):esp_outb_tun_init (sa, prm);break ; +case (RTE_IPSEC_SATP_DIR_OB |RTE_IPSEC_SATP_MODE_TRANS | +RTE_IPSEC_SATP_NATT_ENABLE ):case (RTE_IPSEC_SATP_DIR_OB |RTE_IPSEC_SATP_MODE_TRANS ):esp_outb_init (sa,0 );break ;
lib/ipsec/sa.h +4 -0
@@ -101,6 +101,10 @@ struct rte_ipsec_sa {uint64_t msk;uint64_t val; } tx_offload; +struct { +uint16_t sport; +uint16_t dport; + } natt;uint32_t salt;uint8_t algo_type;uint8_t proto;/* next proto */
Signature · 1 line
2.25.1
RFC 8/10 ipsec: add support for SA telemetry
In reply to Radu NicolauAdd telemetry support for ipsec SAs
--- lib/ipsec/esp_inb.c | 1 + lib/ipsec/esp_outb.c | 12 +- lib/ipsec/meson.build | 2 +- lib/ipsec/rte_ipsec.h | 11 ++ lib/ipsec/sa.c | 255 +++++++++++++++++++++++++++++++++++++++++- lib/ipsec/sa.h | 21 ++++ lib/ipsec/version.map | 8 ++ 7 files changed, 304 insertions(+), 6 deletions(-)
lib/ipsec/esp_inb.c +1 -0
@@ -722,6 +722,7 @@ esp_inb_pkt_process(struct rte_ipsec_sa *sa, struct rte_mbuf *mb[],/* process packets, extract seq numbers */ k =process (sa, mb, sqn, dr, num, sqh_len); + sa->statistics.count += k;/* handle unprocessed mbufs */ if (k != num && k !=0 )
lib/ipsec/esp_outb.c +10 -2
@@ -617,7 +617,7 @@ uint16_t esp_outb_sqh_process(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], uint16_t num) { - uint32_t i, k, icv_len, *icv; + uint32_t i, k, icv_len, *icv, bytes;struct rte_mbuf *ml;struct rte_ipsec_sa *sa;uint32_t dr[num];
@@ -626,10 +626,12 @@ esp_outb_sqh_process(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], k =0 ; icv_len = sa->icv_len; + bytes =0 ;for (i =0 ; i != num; i++) {if ((mb[i]->ol_flags &PKT_RX_SEC_OFFLOAD_FAILED ) ==0 ) { ml =rte_pktmbuf_lastseg (mb[i]); + bytes += mb[i]->data_len;/* remove high-order 32 bits of esn from packet len */ mb[i]->pkt_len -= sa->sqh_len; ml->data_len -= sa->sqh_len;
@@ -640,6 +642,8 @@ esp_outb_sqh_process(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], }else dr[i - k] = i; } + sa->statistics.count += k; + sa->statistics.bytes += bytes - (sa->hdr_len * k);/* handle unprocessed mbufs */ if (k != num) {
@@ -659,16 +663,19 @@ static inline void inline_outb_mbuf_prepare(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], uint16_t num) { - uint32_t i, ol_flags; + uint32_t i, ol_flags, bytes = 0; ol_flags = ss->security.ol_flags &RTE_SECURITY_TX_OLOAD_NEED_MDATA ;for (i =0 ; i != num; i++) { mb[i]->ol_flags |=PKT_TX_SEC_OFFLOAD ; + bytes += mb[i]->data_len;if (ol_flags !=0 )rte_security_set_pkt_metadata (ss->security.ctx, ss->security.ses, mb[i],NULL ); } + ss->sa->statistics.count += num; + ss->sa->statistics.bytes += bytes - (ss->sa->hdr_len * num); }/* check if packet will exceed MSS and segmentation is required */
@@ -752,6 +759,7 @@ inline_outb_tun_pkt_process(const struct rte_ipsec_session *ss, sqn += nb_segs[i] -1 ; } +/* copy not processed mbufs beyond good ones */ if (k != num && k !=0 )move_bad_mbufs (mb, dr, num, num - k);
lib/ipsec/meson.build +1 -1
@@ -6,4 +6,4 @@ sources = files('esp_inb.c', 'esp_outb.c', 'sa.c', 'ses.c', 'ipsec_sad.c') headers = files('rte_ipsec.h', 'rte_ipsec_sa.h', 'rte_ipsec_sad.h') indirect_headers += files('rte_ipsec_group.h') -deps += ['mbuf', 'net', 'cryptodev', 'security', 'hash'] +deps += ['mbuf', 'net', 'cryptodev', 'security', 'hash', 'telemetry']
lib/ipsec/rte_ipsec.h +11 -0
@@ -158,6 +158,17 @@ rte_ipsec_pkt_process(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[],return ss->pkt_func.process (ss, mb, num); } + +struct rte_ipsec_telemetry ; + +__rte_experimental +int +rte_ipsec_telemetry_init (void ); + +__rte_experimental +int +rte_ipsec_telemetry_sa_add (struct rte_ipsec_sa *sa); +#include <rte_ipsec_group.h> #ifdef __cplusplus
lib/ipsec/sa.c +252 -3
290 lines not on this page · raw message
lib/ipsec/sa.h +21 -0
@@ -122,9 +122,30 @@ struct rte_ipsec_sa {uint16_t mss; } tso; +LIST_ENTRY (rte_ipsec_sa) telemetry_next; +/**< list entry for telemetry enabled SA */ + + + RTE_MARKER cachealign_statistics __rte_cache_min_aligned; + +/* Statistics */ +struct { +uint64_t count; +uint64_t bytes; + +struct { +uint64_t count; +uint64_t authentication_failed; + } errors; + } statistics; + + RTE_MARKER cachealign_tunnel_header __rte_cache_min_aligned; +/* template for tunnel header */ uint8_t hdr[IPSEC_MAX_HDR_SIZE ]; + + RTE_MARKER cachealign_tunnel_seq_num_replay_win __rte_cache_min_aligned;/* * sqn and replay window * In case of SA handled by multiple threads *sqn* cacheline
lib/ipsec/version.map +8 -0
@@ -19,3 +19,11 @@ DPDK_21 { local: *; }; + +EXPERIMENTAL { + global: + + rte_ipsec_telemetry_init; + rte_ipsec_telemetry_sa_add; + +};
Signature · 1 line
2.25.1
Re: [dpdk-dev] [RFC 08/10] ipsec: add support for SA telemetry
Quoted 16 lines · Radu Nicolau
Add telemetry support for ipsec SAs
Signed-off-by Declan Doherty <[email protected]>Signed-off-by Radu Nicolau <[email protected]>Signed-off-by Abhijit Sinha <[email protected]>Signed-off-by Daniel Martin Buckley <[email protected]>--- lib/ipsec/esp_inb.c | 1 + lib/ipsec/esp_outb.c | 12 +- lib/ipsec/meson.build | 2 +- lib/ipsec/rte_ipsec.h | 11 ++ lib/ipsec/sa.c | 255 +++++++++++++++++++++++++++++++++++++++++- lib/ipsec/sa.h | 21 ++++ lib/ipsec/version.map | 8 ++ 7 files changed, 304 insertions(+), 6 deletions(-)
[SNIP]
lib/ipsec/version.map DPDK_21 { · line 24
Quoted 11 lines
lib/ipsec/version.map +3
-0@@ -19,3 +19,11 @@ DPDK_21 { local: *; }; + +EXPERIMENTAL { + global:> +
Need to add a comment indicating when the symbols where added here.
Quoted 5 lines
lib/ipsec/version.map +4
-0+ rte_ipsec_telemetry_init; + rte_ipsec_telemetry_sa_add; + +};
RFC 9/10 ipsec: add support for initial SQN value
In reply to Radu NicolauUpdate IPsec library to support initial SQN value.
--- lib/ipsec/esp_outb.c | 19 ++++++++++++------- lib/ipsec/sa.c | 29 ++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 14 deletions(-)
lib/ipsec/esp_outb.c +12 -7
@@ -661,7 +661,7 @@ esp_outb_sqh_process(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[],*/ static inline void inline_outb_mbuf_prepare (const struct rte_ipsec_session *ss, -struct rte_mbuf *mb[],uint16_t num) +struct rte_mbuf *mb[],uint16_t num,uint64_t *sqn) {uint32_t i, ol_flags, bytes =0 ;
@@ -672,7 +672,7 @@ inline_outb_mbuf_prepare(const struct rte_ipsec_session *ss, bytes += mb[i]->data_len;if (ol_flags !=0 )rte_security_set_pkt_metadata (ss->security.ctx, - ss->security.ses, mb[i],NULL ); + ss->security.ses, mb[i], sqn); } ss->sa->statistics.count += num; ss->sa->statistics.bytes += bytes - (ss->sa->hdr_len * num);
@@ -764,7 +764,10 @@ inline_outb_tun_pkt_process(const struct rte_ipsec_session *ss,if (k != num && k !=0 )move_bad_mbufs (mb, dr, num, num - k); -inline_outb_mbuf_prepare (ss, mb, k); +if (sa->sqn_mask >UINT32_MAX ) +inline_outb_mbuf_prepare (ss, mb, k, &sqn); +else +inline_outb_mbuf_prepare (ss, mb, k,NULL );return k; }
@@ -799,8 +802,7 @@ inline_outb_trs_pkt_process(const struct rte_ipsec_session *ss,if (nb_sqn_alloc != nb_sqn) rte_errno =EOVERFLOW ; - k =0 ; -for (i =0 ; i != num; i++) { +for (i =0 , k =0 ; i != num; i++) { sqc =rte_cpu_to_be_64 (sqn + i);gen_iv (iv, sqc);
@@ -828,7 +830,10 @@ inline_outb_trs_pkt_process(const struct rte_ipsec_session *ss,if (k != num && k !=0 )move_bad_mbufs (mb, dr, num, num - k); -inline_outb_mbuf_prepare (ss, mb, k); +if (sa->sqn_mask >UINT32_MAX ) +inline_outb_mbuf_prepare (ss, mb, k, &sqn); +else +inline_outb_mbuf_prepare (ss, mb, k,NULL );return k; }
@@ -840,6 +845,6 @@ uint16_t inline_proto_outb_pkt_process(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], uint16_t num) { -inline_outb_mbuf_prepare (ss, mb, num); +inline_outb_mbuf_prepare (ss, mb, num, NULL);return num; }
lib/ipsec/sa.c +22 -7
@@ -294,11 +294,11 @@ esp_inb_tun_init(struct rte_ipsec_sa *sa, const struct rte_ipsec_sa_prm *prm)* Init ESP outbound specific things. */ static void -esp_outb_init (struct rte_ipsec_sa *sa,uint32_t hlen) +esp_outb_init (struct rte_ipsec_sa *sa,uint32_t hlen,uint64_t sqn) {uint8_t algo_type; - sa->sqn.outb =1 ; + sa->sqn.outb = sqn; algo_type = sa->algo_type;
@@ -356,6 +356,8 @@ esp_outb_init(struct rte_ipsec_sa *sa, uint32_t hlen)static void esp_outb_tun_init (struct rte_ipsec_sa *sa,const struct rte_ipsec_sa_prm *prm) { +uint64_t sqn = prm->ipsec_xform.esn.value >0 ? + prm->ipsec_xform.esn.value :0 ; sa->proto = prm->tun.next_proto; sa->hdr_len = prm->tun.hdr_len; sa->hdr_l3_off = prm->tun.hdr_l3_off;
@@ -366,7 +368,7 @@ esp_outb_tun_init(struct rte_ipsec_sa *sa, const struct rte_ipsec_sa_prm *prm)memcpy (sa->hdr, prm->tun.hdr, sa->hdr_len); -esp_outb_init (sa, sa->hdr_len); +esp_outb_init (sa, sa->hdr_len, sqn); }/*
@@ -376,6 +378,8 @@ static int esp_sa_init(struct rte_ipsec_sa *sa, const struct rte_ipsec_sa_prm *prm, const struct crypto_xform *cxf) { + uint64_t sqn = prm->ipsec_xform.esn.value > 0 ? + prm->ipsec_xform.esn.value :0 ;static const uint64_t msk =RTE_IPSEC_SATP_DIR_MASK |RTE_IPSEC_SATP_MODE_MASK |RTE_IPSEC_SATP_NATT_MASK ;
@@ -492,7 +496,7 @@ esp_sa_init(struct rte_ipsec_sa *sa, const struct rte_ipsec_sa_prm *prm,case (RTE_IPSEC_SATP_DIR_OB |RTE_IPSEC_SATP_MODE_TRANS |RTE_IPSEC_SATP_NATT_ENABLE ):case (RTE_IPSEC_SATP_DIR_OB |RTE_IPSEC_SATP_MODE_TRANS ): -esp_outb_init (sa,0 ); +esp_outb_init (sa,0 , sqn);break ; }
@@ -503,15 +507,19 @@ esp_sa_init(struct rte_ipsec_sa *sa, const struct rte_ipsec_sa_prm *prm,* helper function, init SA replay structure. */ static void -fill_sa_replay (struct rte_ipsec_sa *sa,uint32_t wnd_sz,uint32_t nb_bucket) +fill_sa_replay (struct rte_ipsec_sa *sa, +uint32_t wnd_sz,uint32_t nb_bucket,uint64_t sqn) { sa->replay.win_sz = wnd_sz; sa->replay.nb_bucket = nb_bucket; sa->replay.bucket_index_mask = nb_bucket -1 ; sa->sqn.inb.rsn[0 ] = (struct replay_sqn *)(sa +1 ); -if ((sa->type &RTE_IPSEC_SATP_SQN_MASK ) ==RTE_IPSEC_SATP_SQN_ATOM ) + sa->sqn.inb.rsn[0 ]->sqn = sqn; +if ((sa->type &RTE_IPSEC_SATP_SQN_MASK ) ==RTE_IPSEC_SATP_SQN_ATOM ) { sa->sqn.inb.rsn[1 ] = (struct replay_sqn *) ((uintptr_t )sa->sqn.inb.rsn[0 ] +rsn_size (nb_bucket)); + sa->sqn.inb.rsn[1 ]->sqn = sqn; + } }int
@@ -830,13 +838,20 @@ rte_ipsec_sa_init(struct rte_ipsec_sa *sa, const struct rte_ipsec_sa_prm *prm, sa->sqn_mask = (prm->ipsec_xform.options.esn ==0 ) ?UINT32_MAX :UINT64_MAX ; +/* if we are starting from a non-zero sn value */ +if (prm->ipsec_xform.esn.value >0 ) { +if (prm->ipsec_xform.direction == +RTE_SECURITY_IPSEC_SA_DIR_EGRESS ) + sa->sqn.outb = prm->ipsec_xform.esn.value; + } + rc =esp_sa_init (sa, prm, &cxf);if (rc !=0 )rte_ipsec_sa_fini (sa);/* fill replay window related fields */ if (nb !=0 ) -fill_sa_replay (sa, wsz, nb); +fill_sa_replay (sa, wsz, nb, prm->ipsec_xform.esn.value);return sz; }
Signature · 1 line
2.25.1