1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
12 * Contains functions/structures/macros to manipulate IPv4/IPv6 headers
13 * used internally by ipsec library.
17 * Move preceding (L3) headers down to remove ESP header and IV.
20 remove_esph(char *np, char *op, uint32_t hlen)
24 for (i = hlen; i-- != 0; np[i] = op[i])
29 * Move preceding (L3) headers up to free space for ESP header and IV.
32 insert_esph(char *np, char *op, uint32_t hlen)
36 for (i = 0; i != hlen; i++)
40 /* update original ip header fields for transport case */
42 update_trs_l3hdr(const struct rte_ipsec_sa *sa, void *p, uint32_t plen,
43 uint32_t l2len, uint32_t l3len, uint8_t proto)
48 if ((sa->type & RTE_IPSEC_SATP_IPV_MASK) == RTE_IPSEC_SATP_IPV4) {
49 struct rte_ipv4_hdr *v4h;
52 rc = v4h->next_proto_id;
53 v4h->next_proto_id = proto;
54 v4h->total_length = rte_cpu_to_be_16(plen - l2len);
57 struct rte_ipv6_hdr *v6h;
62 /* basic IPv6 header with no extensions */
63 if (l3len == sizeof(struct rte_ipv6_hdr))
66 /* IPv6 with extensions */
72 /* locate last extension within l3len bytes */
75 ext_len = sizeof(struct rte_ipv6_hdr);
77 while (pd + ext_len < plimit) {
79 nh = rte_ipv6_get_next_ext(pd, nh, &ext_len);
84 /* invalid l3len - extension exceeds header length */
85 if (unlikely(pd + ext_len != plimit))
88 /* save last extension offset */
92 /* update header type; return original value */
96 /* fix packet length */
97 v6h->payload_len = rte_cpu_to_be_16(plen - l2len -
104 /* update original and new ip header fields for tunnel case */
106 update_tun_l3hdr(const struct rte_ipsec_sa *sa, void *p, uint32_t plen,
107 uint32_t l2len, rte_be16_t pid)
109 struct rte_ipv4_hdr *v4h;
110 struct rte_ipv6_hdr *v6h;
112 if (sa->type & RTE_IPSEC_SATP_MODE_TUNLV4) {
114 v4h->packet_id = pid;
115 v4h->total_length = rte_cpu_to_be_16(plen - l2len);
118 v6h->payload_len = rte_cpu_to_be_16(plen - l2len -