Fix tons of deprecation warnings
[samplevnf.git] / VNFs / DPPD-PROX / prox_cksum.h
1 /*
2 // Copyright (c) 2010-2020 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #ifndef _PROX_CKSUM_H_
18 #define _PROX_CKSUM_H_
19
20 #include <inttypes.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include <rte_version.h>
24 #include <rte_ip.h>
25 #include <rte_udp.h>
26 #include <rte_tcp.h>
27 #include <rte_mbuf.h>
28 #include "igmp.h"
29 #include "prox_compat.h"
30 #include "prox_ipv6.h"
31
32 #if RTE_VERSION >= RTE_VERSION_NUM(1,8,0,0)
33 #define CALC_TX_OL(l2_len, l3_len) ((uint64_t)(l2_len) | (uint64_t)(l3_len) << 7)
34 #else
35 #define CALC_TX_OL(l2_len, l3_len) (((uint64_t)(l2_len) << 9) | (uint64_t)(l3_len))
36 #endif
37
38 static void prox_ip_cksum_hw(struct rte_mbuf *mbuf, uint16_t l2_len, uint16_t l3_len)
39 {
40 #if RTE_VERSION < RTE_VERSION_NUM(1,8,0,0)
41         mbuf->pkt.vlan_macip.data = CALC_TX_OL(l2_len, l3_len);
42 #else
43         mbuf->tx_offload = CALC_TX_OL(l2_len, l3_len);
44 #endif
45         mbuf->ol_flags |= RTE_MBUF_F_TX_IP_CKSUM;
46 }
47
48 void prox_ip_cksum_sw(prox_rte_ipv4_hdr *buf);
49
50 static inline void prox_ip_cksum(struct rte_mbuf *mbuf, prox_rte_ipv4_hdr *buf, uint16_t l2_len, uint16_t l3_len, int offload)
51 {
52         buf->hdr_checksum = 0;
53 #ifdef SOFT_CRC
54         prox_ip_cksum_sw(buf);
55 #else
56         if (offload)
57                 prox_ip_cksum_hw(mbuf, l2_len, l3_len);
58         else {
59                 prox_ip_cksum_sw(buf);
60                 /* TODO: calculate UDP checksum */
61         }
62 #endif
63 }
64
65 void prox_ip_udp_cksum(struct rte_mbuf *mbuf, prox_rte_ipv4_hdr *buf, uint16_t l2_len, uint16_t l3_len, int cksum_offload);
66
67 /* src_ip_addr/dst_ip_addr are in network byte order */
68 void prox_udp_cksum_sw(prox_rte_udp_hdr *udp, uint16_t len, uint32_t src_ip_addr, uint32_t dst_ip_addr);
69 void prox_tcp_cksum_sw(prox_rte_tcp_hdr *tcp, uint16_t len, uint32_t src_ip_addr, uint32_t dst_ip_addr);
70 void prox_igmp_cksum_sw(struct igmpv2_hdr *igmp, uint16_t len);
71
72 struct ipv6_pseudo_hdr {
73         struct ipv6_addr src;
74         struct ipv6_addr dst;
75         uint32_t length;
76         uint32_t protocl:8;
77         uint32_t reserved:24;
78 } __attribute__((__packed__));
79 #endif /* _PROX_CKSUM_H_ */