4 * Copyright(c) 2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <netinet/in.h>
39 #include <netinet/ip.h>
43 #define IPV6_VERSION (6)
45 static inline struct ip *
46 ip4ip_outbound(struct rte_mbuf *m, uint32_t offset, uint32_t src, uint32_t dst)
48 struct ip *inip, *outip;
50 inip = rte_pktmbuf_mtod(m, struct ip*);
52 IPSEC_ASSERT(inip->ip_v == IPVERSION || inip->ip_v == IPV6_VERSION);
54 offset += sizeof(struct ip);
56 outip = (struct ip *)rte_pktmbuf_prepend(m, offset);
58 IPSEC_ASSERT(outip != NULL);
60 /* Per RFC4301 5.1.2.1 */
61 outip->ip_v = IPVERSION;
63 outip->ip_tos = inip->ip_tos;
64 outip->ip_len = htons(rte_pktmbuf_data_len(m));
69 outip->ip_ttl = IPDEFTTL;
70 outip->ip_p = IPPROTO_ESP;
72 outip->ip_src.s_addr = src;
73 outip->ip_dst.s_addr = dst;
79 ip4ip_inbound(struct rte_mbuf *m, uint32_t offset)
84 outip = rte_pktmbuf_mtod(m, struct ip*);
86 IPSEC_ASSERT(outip->ip_v == IPVERSION);
88 offset += sizeof(struct ip);
89 inip = (struct ip *)rte_pktmbuf_adj(m, offset);
90 IPSEC_ASSERT(inip->ip_v == IPVERSION || inip->ip_v == IPV6_VERSION);
92 /* Check packet is still bigger than IP header (inner) */
93 IPSEC_ASSERT(rte_pktmbuf_pkt_len(m) > sizeof(struct ip));
95 /* RFC4301 5.1.2.1 Note 6 */
96 if ((inip->ip_tos & htons(IPTOS_ECN_ECT0 | IPTOS_ECN_ECT1)) &&
97 ((outip->ip_tos & htons(IPTOS_ECN_CE)) == IPTOS_ECN_CE))
98 inip->ip_tos |= htons(IPTOS_ECN_CE);
103 #endif /* __IPIP_H__ */