From: Amos Jeffries Date: Mon, 30 Jun 2008 13:16:14 +0000 (+1200) Subject: Bug 2141: Netmasks need to die a clean death (part 1) X-Git-Tag: SQUID_3_1_0_1~49^2~179 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60cad9371792be26f774ed27fb093029d1fffa57;p=thirdparty%2Fsquid.git Bug 2141: Netmasks need to die a clean death (part 1) Update ACLIP output display to show CIDR instead of netmask format. With IPv6 masks can be long strings of ff* not easy to read. This makes them show up as CIDR masks appropriate to the base address type. Also removes some duplicate code in output (debug show and config mgr). TODO: parsing updates, in-memory types etc. --- diff --git a/src/ACLIP.cc b/src/ACLIP.cc index 1780ba646c..ef6ee9f428 100644 --- a/src/ACLIP.cc +++ b/src/ACLIP.cc @@ -52,29 +52,36 @@ ACLIP::operator delete (void *address) fatal ("ACLIP::operator delete: unused"); } +/** + * Writes an IP ACL data into a buffer, then copies the buffer into the wordlist given + * + \param ip ACL data structure to display + \param state wordlist structure which is being generated + */ void ACLIP::DumpIpListWalkee(acl_ip_data * const & ip, void *state) { - char tmpbuf[MAX_IPSTRLEN]; + char tmpbuf[ ((MAX_IPSTRLEN*2)+6) ]; // space for 2 IPs and a CIDR mask(3) and seperators(3). MemBuf mb; wordlist **W = static_cast(state); - mb.init(); - mb.Printf("%s", ip->addr1.NtoA(tmpbuf,MAX_IPSTRLEN)); + tmpbuf[0] = '\0'; - if (!ip->addr2.IsAnyAddr()) - mb.Printf("-%s", ip->addr2.NtoA(tmpbuf,MAX_IPSTRLEN)); - - if (!ip->mask.IsNoAddr()) - mb.Printf("/%s", ip->mask.NtoA(tmpbuf,MAX_IPSTRLEN)); + mb.init(); + assert(mb.max_capacity > 0 && 1==1 ); + ip->toStr(tmpbuf, sizeof(tmpbuf) ); + assert(mb.max_capacity > 0 && 2==2 ); + mb.append(tmpbuf, strlen(tmpbuf) ); + assert(mb.max_capacity > 0 && 3==3); wordlistAdd(W, mb.buf); - mb.clean(); } -/* - * aclIpDataToStr - print/format an acl_ip_data structure for - * debugging output. +/** + * print/format an acl_ip_data structure for debugging output. + * + \param buf string buffer to write to + \param len size of the buffer available */ void acl_ip_data::toStr(char *buf, int len) const @@ -88,8 +95,7 @@ acl_ip_data::toStr(char *buf, int len) const rlen = strlen(buf); b2 = buf + rlen; - if (!addr2.IsAnyAddr()) - { + if (!addr2.IsAnyAddr()) { b2[0] = '-'; rlen++; addr2.NtoA(&(b2[1]), len - rlen ); rlen = strlen(buf); @@ -99,10 +105,13 @@ acl_ip_data::toStr(char *buf, int len) const b3 = buf + rlen; - if (!mask.IsNoAddr()) - { + if (!mask.IsNoAddr()) { b3[0] = '/'; rlen++; - mask.NtoA(&(b3[1]), len - rlen ); +#if USE_IPV6 + snprintf(&(b3[1]), (len-rlen), "%u", mask.GetCIDR() - (addr1.IsIPv4()?96:0) ); +#else + snprintf(&(b3[1]), (len-rlen), "%u", mask.GetCIDR() ); +#endif } else b3[0] = '\0';