From: Victor Julien Date: Thu, 17 Feb 2022 15:53:43 +0000 (+0100) Subject: detect/address: use common cidr code X-Git-Tag: suricata-6.0.5~103 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eea65ca0b1297ff46ab01a2f63a14658895f5563;p=thirdparty%2Fsuricata.git detect/address: use common cidr code (cherry picked from commit 8a73b242e389a5dbc223de83e2e7542bc46903d8) --- diff --git a/src/detect-engine-address.c b/src/detect-engine-address.c index eb58097ffd..3b47b4325a 100644 --- a/src/detect-engine-address.c +++ b/src/detect-engine-address.c @@ -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];