From: Jason Ish Date: Tue, 21 Feb 2017 19:31:41 +0000 (-0600) Subject: tcp/udp: rename checksum functions for better meaning X-Git-Tag: suricata-4.0.0-beta1~246 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b79a18ea153a8255c4823c4af189154cc5bcccc6;p=thirdparty%2Fsuricata.git tcp/udp: rename checksum functions for better meaning The TCP/UDP checksum functions no longer just calculate the checksum, they can validate as well as calculate so use a more generic name. --- diff --git a/src/alert-unified2-alert.c b/src/alert-unified2-alert.c index 44dcb4d834..e7f28b3228 100644 --- a/src/alert-unified2-alert.c +++ b/src/alert-unified2-alert.c @@ -633,12 +633,12 @@ static int Unified2PrintStreamSegmentCallback(const Packet *p, void *data, const 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)); diff --git a/src/decode-tcp.c b/src/decode-tcp.c index 75e52c27fd..1ff16e0a7f 100644 --- a/src/decode-tcp.c +++ b/src/decode-tcp.c @@ -236,7 +236,7 @@ static int TCPCalculateValidChecksumtest01(void) 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; } @@ -257,7 +257,7 @@ static int TCPCalculateInvalidChecksumtest02(void) 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; } @@ -281,7 +281,7 @@ static int TCPV6CalculateValidChecksumtest03(void) 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; } @@ -305,7 +305,7 @@ static int TCPV6CalculateInvalidChecksumtest04(void) 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; } diff --git a/src/decode-tcp.h b/src/decode-tcp.h index 38b27f6b38..0621d7ef61 100644 --- a/src/decode-tcp.h +++ b/src/decode-tcp.h @@ -164,10 +164,8 @@ typedef struct TCPVars_ 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 @@ -181,8 +179,8 @@ static inline uint16_t TCPV6CalculateChecksum(uint16_t *, uint16_t *, uint16_t, * \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; @@ -246,8 +244,8 @@ static inline uint16_t TCPCalculateChecksum(uint16_t *shdr, uint16_t *pkt, * \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; diff --git a/src/decode-udp.c b/src/decode-udp.c index 50ca2397fa..d84f969192 100644 --- a/src/decode-udp.c +++ b/src/decode-udp.c @@ -117,7 +117,7 @@ static int UDPV4CalculateValidChecksumtest01(void) 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; } @@ -144,7 +144,7 @@ static int UDPV4CalculateInvalidChecksumtest02(void) 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; } @@ -167,7 +167,7 @@ static int UDPV6CalculateValidChecksumtest03(void) 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; } @@ -190,7 +190,7 @@ static int UDPV6CalculateInvalidChecksumtest04(void) 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; } diff --git a/src/decode-udp.h b/src/decode-udp.h index cc04fa7f81..cfbdc7f23a 100644 --- a/src/decode-udp.h +++ b/src/decode-udp.h @@ -54,10 +54,8 @@ typedef struct UDPHdr_ 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 @@ -72,8 +70,8 @@ static inline uint16_t UDPV6CalculateChecksum(uint16_t *, uint16_t *, uint16_t, * \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; @@ -139,8 +137,8 @@ static inline uint16_t UDPV4CalculateChecksum(uint16_t *shdr, uint16_t *pkt, * \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; diff --git a/src/detect-csum.c b/src/detect-csum.c index 8e3d69391b..bef86066cf 100644 --- a/src/detect-csum.c +++ b/src/detect-csum.c @@ -336,11 +336,11 @@ static int DetectTCPV4CsumMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx, } 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; @@ -433,11 +433,11 @@ static int DetectTCPV6CsumMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx, } 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; @@ -530,11 +530,11 @@ static int DetectUDPV4CsumMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx, } 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; @@ -627,11 +627,11 @@ static int DetectUDPV6CsumMatch(ThreadVars *t, DetectEngineThreadCtx *det_ctx, } 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; diff --git a/src/flow-timeout.c b/src/flow-timeout.c index c835413076..cf0dd622e5 100644 --- a/src/flow-timeout.c +++ b/src/flow-timeout.c @@ -239,14 +239,14 @@ static inline Packet *FlowForceReassemblyPseudoPacketSetup(Packet *p, } 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); } diff --git a/src/stream-tcp.c b/src/stream-tcp.c index aa748701a8..b3b861bdef 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -4707,17 +4707,17 @@ static inline int StreamTcpValidateChecksum(Packet *p) 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); } } diff --git a/src/util-checksum.c b/src/util-checksum.c index 8c1c39131d..98dc6590ec 100644 --- a/src/util-checksum.c +++ b/src/util-checksum.c @@ -33,11 +33,11 @@ int ReCalculateChecksum(Packet *p) 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 */ @@ -48,11 +48,11 @@ int ReCalculateChecksum(Packet *p) /* 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); } }