| 22 | #include "ipip.h" |
| 23 | |
| 24 | int |
| 25 | esp_inbound(struct rte_mbuf *m, struct ipsec_sa *sa, |
| 26 | struct rte_crypto_op *cop) |
| 27 | { |
| 28 | struct ip *ip4; |
| 29 | struct rte_crypto_sym_op *sym_cop; |
| 30 | int32_t payload_len, ip_hdr_len; |
| 31 | |
| 32 | RTE_ASSERT(sa != NULL); |
| 33 | if (ipsec_get_action_type(sa) == |
| 34 | RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO) |
| 35 | return 0; |
| 36 | |
| 37 | RTE_ASSERT(m != NULL); |
| 38 | RTE_ASSERT(cop != NULL); |
| 39 | |
| 40 | ip4 = rte_pktmbuf_mtod(m, struct ip *); |
| 41 | if (likely(ip4->ip_v == IPVERSION)) |
| 42 | ip_hdr_len = ip4->ip_hl * 4; |
| 43 | else if (ip4->ip_v == IP6_VERSION) |
| 44 | /* XXX No option headers supported */ |
| 45 | ip_hdr_len = sizeof(struct ip6_hdr); |
| 46 | else { |
| 47 | RTE_LOG(ERR, IPSEC_ESP, "invalid IP packet type %d\n", |
| 48 | ip4->ip_v); |
| 49 | return -EINVAL; |
| 50 | } |
| 51 | |
| 52 | payload_len = rte_pktmbuf_pkt_len(m) - ip_hdr_len - |
| 53 | sizeof(struct rte_esp_hdr) - sa->iv_len - sa->digest_len; |
| 54 | |
| 55 | if ((payload_len & (sa->block_size - 1)) || (payload_len <= 0)) { |
| 56 | RTE_LOG_DP(DEBUG, IPSEC_ESP, "payload %d not multiple of %u\n", |
| 57 | payload_len, sa->block_size); |
| 58 | return -EINVAL; |
| 59 | } |
| 60 | |
| 61 | sym_cop = get_sym_cop(cop); |
| 62 | sym_cop->m_src = m; |
| 63 | |
| 64 | if (sa->aead_algo == RTE_CRYPTO_AEAD_AES_GCM) { |
| 65 | sym_cop->aead.data.offset = |
| 66 | ip_hdr_len + sizeof(struct rte_esp_hdr) + sa->iv_len; |
| 67 | sym_cop->aead.data.length = payload_len; |
| 68 | |
| 69 | struct cnt_blk *icb; |
| 70 | uint8_t *aad; |
| 71 | uint8_t *iv = RTE_PTR_ADD(ip4, ip_hdr_len + |
| 72 | sizeof(struct rte_esp_hdr)); |
| 73 | |
| 74 | icb = get_cnt_blk(m); |
| 75 | icb->salt = sa->salt; |
| 76 | memcpy(&icb->iv, iv, 8); |
| 77 | icb->cnt = rte_cpu_to_be_32(1); |
| 78 | |
| 79 | aad = get_aad(m); |
| 80 | memcpy(aad, iv - sizeof(struct rte_esp_hdr), 8); |
| 81 | sym_cop->aead.aad.data = aad; |
nothing calls this directly
no test coverage detected