Add support for igmp and multicast
[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 #include "igmp.h"
29
30 #if RTE_VERSION >= RTE_VERSION_NUM(1,8,0,0)
31 #define CALC_TX_OL(l2_len, l3_len) ((uint64_t)(l2_len) | (uint64_t)(l3_len) << 7)
32 #else
33 #define CALC_TX_OL(l2_len, l3_len) (((uint64_t)(l2_len) << 9) | (uint64_t)(l3_len))
34 #endif
35
36 static void prox_ip_cksum_hw(struct rte_mbuf *mbuf, uint16_t l2_len, uint16_t l3_len)
37 {
38 #if RTE_VERSION < RTE_VERSION_NUM(1,8,0,0)
39         mbuf->pkt.vlan_macip.data = CALC_TX_OL(l2_len, l3_len);
40 #else
41         mbuf->tx_offload = CALC_TX_OL(l2_len, l3_len);
42 #endif
43         mbuf->ol_flags |= PKT_TX_IP_CKSUM;
44 }
45
46 void prox_ip_cksum_sw(struct ipv4_hdr *buf);
47
48 static inline void prox_ip_cksum(struct rte_mbuf *mbuf, struct ipv4_hdr *buf, uint16_t l2_len, uint16_t l3_len, int offload)
49 {
50         buf->hdr_checksum = 0;
51 #ifdef SOFT_CRC
52         prox_ip_cksum_sw(buf);
53 #else
54         if (offload)
55                 prox_ip_cksum_hw(mbuf, l2_len, l3_len);
56         else {
57                 prox_ip_cksum_sw(buf);
58                 /* TODO: calculate UDP checksum */
59         }
60 #endif
61 }
62
63 void prox_ip_udp_cksum(struct rte_mbuf *mbuf, struct ipv4_hdr *buf, uint16_t l2_len, uint16_t l3_len, int cksum_offload);
64
65 /* src_ip_addr/dst_ip_addr are in network byte order */
66 void prox_udp_cksum_sw(struct udp_hdr *udp, uint16_t len, uint32_t src_ip_addr, uint32_t dst_ip_addr);
67 void prox_tcp_cksum_sw(struct tcp_hdr *tcp, uint16_t len, uint32_t src_ip_addr, uint32_t dst_ip_addr);
68 void prox_igmp_cksum_sw(struct igmpv2_hdr *igmp, uint16_t len);
69
70 #endif /* _PROX_CKSUM_H_ */