]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
tcp/udp: rename checksum functions for better meaning
authorJason Ish <ish@unx.ca>
Tue, 21 Feb 2017 19:31:41 +0000 (13:31 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 27 Mar 2017 14:19:13 +0000 (16:19 +0200)
The TCP/UDP checksum functions no longer just calculate
the checksum, they can validate as well as calculate so
use a more generic name.

src/alert-unified2-alert.c
src/decode-tcp.c
src/decode-tcp.h
src/decode-udp.c
src/decode-udp.h
src/detect-csum.c
src/flow-timeout.c
src/stream-tcp.c
src/util-checksum.c

index 44dcb4d83421b1e0618bfc87afc14ca8fee4cd4f..e7f28b3228ea84e4b37e9f9fcd742cfadde2b8c4 100644 (file)
@@ -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));
index 75e52c27fd5a53535533f4c063a7fea5317ed9ba..1ff16e0a7f7e1bfeb19489d8cceb9ddf58aede1e 100644 (file)
@@ -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;
 }
index 38b27f6b384e646f3790dbd387f61a3c42df85f7..0621d7ef61766a84c41abfaf4b9efb241820910d 100644 (file)
@@ -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;
index 50ca2397fa56b05c115fbe4d090bd6686f91638f..d84f969192069c53c015015c3e250234de5b0ee2 100644 (file)
@@ -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;
 }
index cc04fa7f8164ce7cd3faa48c107ea77d80410a16..cfbdc7f23a4b06435e3691a0053a3c3a18255a0e 100644 (file)
@@ -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;
index 8e3d69391b0414af1992b0fce9eddd85fc03325d..bef86066cf58bf1e45caacd3e0447c5b0cffe2e4 100644 (file)
@@ -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;
index c835413076b81c1a460145cba58ed16e214ea79a..cf0dd622e5a3f1cd695a79db7be27d0a4a8a57b6 100644 (file)
@@ -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);
     }
 
index aa748701a8a754cdc0ac5487baf689394461d660..b3b861bdefb83c6c5bf7fbe4468e8f10b22d8aeb 100644 (file)
@@ -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);
         }
     }
 
index 8c1c39131dd7ba7e3ef7e14c611e17b34c07f75a..98dc6590ec88e5ca276eba3da08daf8fa7aa7816 100644 (file)
@@ -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);
         }
     }