Merge "[l2l3 stack] implements new arp state machine & arp buffering"
[samplevnf.git] / VNFs / DPPD-PROX / prox_cksum.h
1 /*
2 // Copyright (c) 2010-2017 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
29 #if RTE_VERSION >= RTE_VERSION_NUM(1,8,0,0)
30 #define CALC_TX_OL(l2_len, l3_len) ((uint64_t)(l2_len) | (uint64_t)(l3_len) << 7)
31 #else
32 #define CALC_TX_OL(l2_len, l3_len) (((uint64_t)(l2_len) << 9) | (uint64_t)(l3_len))
33 #endif
34
35 static void prox_ip_cksum_hw(struct rte_mbuf *mbuf, uint16_t l2_len, uint16_t l3_len)
36 {
37 #if RTE_VERSION < RTE_VERSION_NUM(1,8,0,0)
38         mbuf->pkt.vlan_macip.data = CALC_TX_OL(l2_len, l3_len);
39 #else
40         mbuf->tx_offload = CALC_TX_OL(l2_len, l3_len);
41 #endif
42         mbuf->ol_flags |= PKT_TX_IP_CKSUM;
43 }
44
45 void prox_ip_cksum_sw(struct ipv4_hdr *buf);
46
47 static inline void prox_ip_cksum(struct rte_mbuf *mbuf, struct ipv4_hdr *buf, uint16_t l2_len, uint16_t l3_len, int offload)
48 {
49         buf->hdr_checksum = 0;
50 #ifdef SOFT_CRC
51         prox_ip_cksum_sw(buf);
52 #else
53         if (offload)
54                 prox_ip_cksum_hw(mbuf, l2_len, l3_len);
55         else {
56                 prox_ip_cksum_sw(buf);
57                 /* TODO: calculate UDP checksum */
58         }
59 #endif
60 }
61
62 void prox_ip_udp_cksum(struct rte_mbuf *mbuf, struct ipv4_hdr *buf, uint16_t l2_len, uint16_t l3_len, int cksum_offload);
63
64 /* src_ip_addr/dst_ip_addr are in network byte order */
65 void prox_udp_cksum_sw(struct udp_hdr *udp, uint16_t len, uint32_t src_ip_addr, uint32_t dst_ip_addr);
66 void prox_tcp_cksum_sw(struct tcp_hdr *tcp, uint16_t len, uint32_t src_ip_addr, uint32_t dst_ip_addr);
67
68 #endif /* _PROX_CKSUM_H_ */