if (PKT_IS_IPV6(p)) {
FakeIPv6Hdr *fakehdr = (FakeIPv6Hdr *)aun->iphdr;
- fakehdr->tcph.th_sum = TCPV6CalculateChecksum(fakehdr->ip6h.s_ip6_addrs,
+ fakehdr->tcph.th_sum = TCPV6Checksum(fakehdr->ip6h.s_ip6_addrs,
(uint16_t *)&fakehdr->tcph, buflen + sizeof(TCPHdr), 0);
} else {
FakeIPv4Hdr *fakehdr = (FakeIPv4Hdr *)aun->iphdr;
- fakehdr->tcph.th_sum = TCPCalculateChecksum(fakehdr->ip4h.s_ip_addrs,
+ fakehdr->tcph.th_sum = TCPChecksum(fakehdr->ip4h.s_ip_addrs,
(uint16_t *)&fakehdr->tcph, buflen + sizeof(TCPHdr), 0);
fakehdr->ip4h.ip_csum = IPV4CalculateChecksum((uint16_t *)&fakehdr->ip4h,
IPV4_GET_RAW_HLEN(&fakehdr->ip4h));
csum = *( ((uint16_t *)raw_tcp) + 8);
- FAIL_IF(TCPCalculateChecksum((uint16_t *)raw_ipshdr,
+ FAIL_IF(TCPChecksum((uint16_t *)raw_ipshdr,
(uint16_t *)raw_tcp, sizeof(raw_tcp), csum) != 0);
PASS;
}
csum = *( ((uint16_t *)raw_tcp) + 8);
- FAIL_IF(TCPCalculateChecksum((uint16_t *) raw_ipshdr,
+ FAIL_IF(TCPChecksum((uint16_t *) raw_ipshdr,
(uint16_t *)raw_tcp, sizeof(raw_tcp), csum) == 0);
PASS;
}
csum = *( ((uint16_t *)(raw_ipv6 + 70)));
- FAIL_IF(TCPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8),
+ FAIL_IF(TCPV6Checksum((uint16_t *)(raw_ipv6 + 14 + 8),
(uint16_t *)(raw_ipv6 + 54), 32, csum) != 0);
PASS;
}
csum = *( ((uint16_t *)(raw_ipv6 + 70)));
- FAIL_IF(TCPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8),
+ FAIL_IF(TCPV6Checksum((uint16_t *)(raw_ipv6 + 14 + 8),
(uint16_t *)(raw_ipv6 + 54), 32, csum) == 0);
PASS;
}
void DecodeTCPRegisterTests(void);
/** -------- Inline functions ------- */
-static inline uint16_t TCPCalculateChecksum(uint16_t *, uint16_t *, uint16_t,
- uint16_t);
-static inline uint16_t TCPV6CalculateChecksum(uint16_t *, uint16_t *, uint16_t,
- uint16_t);
+static inline uint16_t TCPChecksum(uint16_t *, uint16_t *, uint16_t, uint16_t);
+static inline uint16_t TCPV6Checksum(uint16_t *, uint16_t *, uint16_t, uint16_t);
/**
* \brief Calculate or validate the checksum for the TCP packet
* \retval csum For validation 0 will be returned for success, for calculation
* this will be the checksum.
*/
-static inline uint16_t TCPCalculateChecksum(uint16_t *shdr, uint16_t *pkt,
- uint16_t tlen, uint16_t init)
+static inline uint16_t TCPChecksum(uint16_t *shdr, uint16_t *pkt,
+ uint16_t tlen, uint16_t init)
{
uint16_t pad = 0;
uint32_t csum = init;
* \retval csum For validation 0 will be returned for success, for calculation
* this will be the checksum.
*/
-static inline uint16_t TCPV6CalculateChecksum(uint16_t *shdr, uint16_t *pkt,
- uint16_t tlen, uint16_t init)
+static inline uint16_t TCPV6Checksum(uint16_t *shdr, uint16_t *pkt,
+ uint16_t tlen, uint16_t init)
{
uint16_t pad = 0;
uint32_t csum = init;
csum = *( ((uint16_t *)raw_udp) + 3);
- FAIL_IF(UDPV4CalculateChecksum((uint16_t *) raw_ipshdr,
+ FAIL_IF(UDPV4Checksum((uint16_t *) raw_ipshdr,
(uint16_t *)raw_udp, sizeof(raw_udp), csum) != 0);
PASS;
}
csum = *( ((uint16_t *)raw_udp) + 3);
- FAIL_IF(UDPV4CalculateChecksum((uint16_t *) raw_ipshdr,
+ FAIL_IF(UDPV4Checksum((uint16_t *) raw_ipshdr,
(uint16_t *)raw_udp, sizeof(raw_udp), csum) == 0);
PASS;
}
csum = *( ((uint16_t *)(raw_ipv6 + 60)));
- FAIL_IF(UDPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8),
+ FAIL_IF(UDPV6Checksum((uint16_t *)(raw_ipv6 + 14 + 8),
(uint16_t *)(raw_ipv6 + 54), 20, csum) != 0);
PASS;
}
csum = *( ((uint16_t *)(raw_ipv6 + 60)));
- FAIL_IF(UDPV6CalculateChecksum((uint16_t *)(raw_ipv6 + 14 + 8),
+ FAIL_IF(UDPV6Checksum((uint16_t *)(raw_ipv6 + 14 + 8),
(uint16_t *)(raw_ipv6 + 54), 20, csum) == 0);
PASS;
}
void DecodeUDPV4RegisterTests(void);
/** ------ Inline function ------ */
-static inline uint16_t UDPV4CalculateChecksum(uint16_t *, uint16_t *, uint16_t,
- uint16_t);
-static inline uint16_t UDPV6CalculateChecksum(uint16_t *, uint16_t *, uint16_t,
- uint16_t);
+static inline uint16_t UDPV4Checksum(uint16_t *, uint16_t *, uint16_t, uint16_t);
+static inline uint16_t UDPV6Checksum(uint16_t *, uint16_t *, uint16_t, uint16_t);
/**
* \brief Calculate or valid the checksum for the UDP packet
* \retval csum For validation 0 will be returned for success, for calculation
* this will be the checksum.
*/
-static inline uint16_t UDPV4CalculateChecksum(uint16_t *shdr, uint16_t *pkt,
- uint16_t tlen, uint16_t init)
+static inline uint16_t UDPV4Checksum(uint16_t *shdr, uint16_t *pkt,
+ uint16_t tlen, uint16_t init)
{
uint16_t pad = 0;
uint32_t csum = init;
* \retval csum For validation 0 will be returned for success, for calculation
* this will be the checksum.
*/
-static inline uint16_t UDPV6CalculateChecksum(uint16_t *shdr, uint16_t *pkt,
- uint16_t tlen, uint16_t init)
+static inline uint16_t UDPV6Checksum(uint16_t *shdr, uint16_t *pkt,
+ uint16_t tlen, uint16_t init)
{
uint16_t pad = 0;
uint32_t csum = init;
}
if (p->level4_comp_csum == -1)
- p->level4_comp_csum = TCPCalculateChecksum(p->ip4h->s_ip_addrs,
- (uint16_t *)p->tcph,
- (p->payload_len +
- TCP_GET_HLEN(p)),
- p->tcph->th_sum);
+ p->level4_comp_csum = TCPChecksum(p->ip4h->s_ip_addrs,
+ (uint16_t *)p->tcph,
+ (p->payload_len +
+ TCP_GET_HLEN(p)),
+ p->tcph->th_sum);
if (p->level4_comp_csum == 0 && cd->valid == 1)
return 1;
}
if (p->level4_comp_csum == -1)
- p->level4_comp_csum = TCPV6CalculateChecksum(p->ip6h->s_ip6_addrs,
- (uint16_t *)p->tcph,
- (p->payload_len +
- TCP_GET_HLEN(p)),
- p->tcph->th_sum);
+ p->level4_comp_csum = TCPV6Checksum(p->ip6h->s_ip6_addrs,
+ (uint16_t *)p->tcph,
+ (p->payload_len +
+ TCP_GET_HLEN(p)),
+ p->tcph->th_sum);
if (p->level4_comp_csum == 0 && cd->valid == 1)
return 1;
}
if (p->level4_comp_csum == -1)
- p->level4_comp_csum = UDPV4CalculateChecksum(p->ip4h->s_ip_addrs,
- (uint16_t *)p->udph,
- (p->payload_len +
- UDP_HEADER_LEN),
- p->udph->uh_sum);
+ p->level4_comp_csum = UDPV4Checksum(p->ip4h->s_ip_addrs,
+ (uint16_t *)p->udph,
+ (p->payload_len +
+ UDP_HEADER_LEN),
+ p->udph->uh_sum);
if (p->level4_comp_csum == 0 && cd->valid == 1)
return 1;
}
if (p->level4_comp_csum == -1)
- p->level4_comp_csum = UDPV6CalculateChecksum(p->ip6h->s_ip6_addrs,
- (uint16_t *)p->udph,
- (p->payload_len +
- UDP_HEADER_LEN),
- p->udph->uh_sum);
+ p->level4_comp_csum = UDPV6Checksum(p->ip6h->s_ip6_addrs,
+ (uint16_t *)p->udph,
+ (p->payload_len +
+ UDP_HEADER_LEN),
+ p->udph->uh_sum);
if (p->level4_comp_csum == 0 && cd->valid == 1)
return 1;
}
if (FLOW_IS_IPV4(f)) {
- p->tcph->th_sum = TCPCalculateChecksum(p->ip4h->s_ip_addrs,
+ p->tcph->th_sum = TCPChecksum(p->ip4h->s_ip_addrs,
(uint16_t *)p->tcph, 20, 0);
/* calc ipv4 csum as we may log it and barnyard might reject
* a wrong checksum */
p->ip4h->ip_csum = IPV4CalculateChecksum((uint16_t *)p->ip4h,
IPV4_GET_RAW_HLEN(p->ip4h));
} else if (FLOW_IS_IPV6(f)) {
- p->tcph->th_sum = TCPCalculateChecksum(p->ip6h->s_ip6_addrs,
+ p->tcph->th_sum = TCPChecksum(p->ip6h->s_ip6_addrs,
(uint16_t *)p->tcph, 20, 0);
}
if (p->level4_comp_csum == -1) {
if (PKT_IS_IPV4(p)) {
- p->level4_comp_csum = TCPCalculateChecksum(p->ip4h->s_ip_addrs,
- (uint16_t *)p->tcph,
- (p->payload_len +
- TCP_GET_HLEN(p)),
- p->tcph->th_sum);
+ p->level4_comp_csum = TCPChecksum(p->ip4h->s_ip_addrs,
+ (uint16_t *)p->tcph,
+ (p->payload_len +
+ TCP_GET_HLEN(p)),
+ p->tcph->th_sum);
} else if (PKT_IS_IPV6(p)) {
- p->level4_comp_csum = TCPV6CalculateChecksum(p->ip6h->s_ip6_addrs,
- (uint16_t *)p->tcph,
- (p->payload_len +
- TCP_GET_HLEN(p)),
- p->tcph->th_sum);
+ p->level4_comp_csum = TCPV6Checksum(p->ip6h->s_ip6_addrs,
+ (uint16_t *)p->tcph,
+ (p->payload_len +
+ TCP_GET_HLEN(p)),
+ p->tcph->th_sum);
}
}
if (PKT_IS_TCP(p)) {
/* TCP */
p->tcph->th_sum = 0;
- p->tcph->th_sum = TCPCalculateChecksum(p->ip4h->s_ip_addrs,
+ p->tcph->th_sum = TCPChecksum(p->ip4h->s_ip_addrs,
(uint16_t *)p->tcph, (p->payload_len + TCP_GET_HLEN(p)), 0);
} else if (PKT_IS_UDP(p)) {
p->udph->uh_sum = 0;
- p->udph->uh_sum = UDPV4CalculateChecksum(p->ip4h->s_ip_addrs,
+ p->udph->uh_sum = UDPV4Checksum(p->ip4h->s_ip_addrs,
(uint16_t *)p->udph, (p->payload_len + UDP_HEADER_LEN), 0);
}
/* IPV4 */
/* just TCP for IPV6 */
if (PKT_IS_TCP(p)) {
p->tcph->th_sum = 0;
- p->tcph->th_sum = TCPV6CalculateChecksum(p->ip6h->s_ip6_addrs,
+ p->tcph->th_sum = TCPV6Checksum(p->ip6h->s_ip6_addrs,
(uint16_t *)p->tcph, (p->payload_len + TCP_GET_HLEN(p)), 0);
} else if (PKT_IS_UDP(p)) {
p->udph->uh_sum = 0;
- p->udph->uh_sum = UDPV6CalculateChecksum(p->ip6h->s_ip6_addrs,
+ p->udph->uh_sum = UDPV6Checksum(p->ip6h->s_ip6_addrs,
(uint16_t *)p->udph, (p->payload_len + UDP_HEADER_LEN), 0);
}
}