]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect/address: use common cidr code
authorVictor Julien <vjulien@oisf.net>
Thu, 17 Feb 2022 15:53:43 +0000 (16:53 +0100)
committerShivani Bhardwaj <shivanib134@gmail.com>
Fri, 4 Mar 2022 05:38:17 +0000 (11:08 +0530)
(cherry picked from commit 8a73b242e389a5dbc223de83e2e7542bc46903d8)

src/detect-engine-address.c

index eb58097ffdee1f319f10a3749d33c085798eb85b..3b47b4325ae53b8d2b8ae31e135d885525397c64 100644 (file)
@@ -383,44 +383,6 @@ bool DetectAddressListsAreEqual(DetectAddress *list1, DetectAddress *list2)
     return true;
 }
 
-/**
- * \internal
- * \brief Creates a cidr ipv6 netblock, based on the cidr netblock value.
- *
- *        For example if we send a cidr of 7 as argument, an ipv6 address
- *        mask of the value FE:00:00:00:00:00:00:00 is created and updated
- *        in the argument struct in6_addr *in6.
- *
- * \todo I think for the final section: while (cidr > 0), we can simply
- *       replace it with a
- *       if (cidr > 0) {
- *           in6->s6_addr[i] = -1 << (8 - cidr);
- *
- * \param cidr The value of the cidr.
- * \param in6  Pointer to an ipv6 address structure(struct in6_addr) which will
- *             hold the cidr netblock result.
- */
-static void DetectAddressParseIPv6CIDR(int cidr, struct in6_addr *in6)
-{
-    int i = 0;
-
-    memset(in6, 0, sizeof(struct in6_addr));
-
-    while (cidr > 8) {
-        in6->s6_addr[i] = 0xff;
-        cidr -= 8;
-        i++;
-    }
-
-    while (cidr > 0) {
-        in6->s6_addr[i] |= 0x80;
-        if (--cidr > 0)
-             in6->s6_addr[i] = in6->s6_addr[i] >> 1;
-    }
-
-    return;
-}
-
 /**
  * \internal
  * \brief Parses an ipv4/ipv6 address string and updates the result into the
@@ -547,7 +509,7 @@ static int DetectAddressParseString(DetectAddress *dd, const char *str)
                 goto error;
             memcpy(&ip6addr, &in6.s6_addr, sizeof(ip6addr));
 
-            DetectAddressParseIPv6CIDR(cidr, &mask6);
+            CIDRGetIPv6(cidr, &mask6);
             memcpy(&netmask, &mask6.s6_addr, sizeof(netmask));
 
             dd->ip2.addr_data32[0] = dd->ip.addr_data32[0] = ip6addr[0] & netmask[0];