--------------------- PatchSet 6382 Date: 2007/12/20 11:16:10 Author: amosjeffries Branch: ayjwork Tag: (none) Log: C++'ify the ASN ACL radix tree data format. - Drops two macros - Adds type-safe compile checking on the data format - Abstracts the size-management away - Abstracts the data conversion away - Abstracts memcpy away to data type where it belongs Members: src/asn.cc:1.25.8.4->1.25.8.5 Index: squid3/src/asn.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/asn.cc,v retrieving revision 1.25.8.4 retrieving revision 1.25.8.5 diff -u -r1.25.8.4 -r1.25.8.5 --- squid3/src/asn.cc 18 Dec 2007 13:07:26 -0000 1.25.8.4 +++ squid3/src/asn.cc 20 Dec 2007 11:16:10 -0000 1.25.8.5 @@ -1,6 +1,6 @@ /* - * $Id: asn.cc,v 1.25.8.4 2007/12/18 13:07:26 amosjeffries Exp $ + * $Id: asn.cc,v 1.25.8.5 2007/12/20 11:16:10 amosjeffries Exp $ * * DEBUG: section 53 AS Number handling * AUTHOR: Duane Wessels, Kostas Anagnostakis @@ -54,14 +54,15 @@ /* BEGIN of definitions for radix tree entries */ -/* AYJ INET6 : Why are these objects being converted to raw u_char memory for use ? */ - /* 32/128 bits address in memory with length */ -typedef u_char m_ADDR[1 + sizeof(IPAddress)]; -#define store_m_ADDR(i, m) \ - (m[0] = sizeof(IPAddress), xmemcpy(m+1, &i, sizeof(IPAddress)) ) -#define get_m_ADDR(i, m) \ - xmemcpy(&i, m+1, sizeof(IPAddress)) +class m_ADDR { +public: + uint8_t len; + IPAddress addr; + + m_ADDR() : len(sizeof(IPAddress)) {}; +}; + /* END of definitions for radix tree entries */ @@ -147,9 +148,9 @@ if (addr.IsAnyAddr()) return 0; - store_m_ADDR(addr, m_addr); + m_addr.addr = addr; - rn = squid_rn_match(m_addr, AS_tree_head); + rn = squid_rn_match(&m_addr, AS_tree_head); if (rn == NULL) { debugs(53, 3, "asnMatchIp: Address not in as db."); @@ -426,11 +427,11 @@ memset(e, '\0', sizeof(rtentry_t)); - store_m_ADDR(addr, e->e_addr); + e->e_addr.addr = addr; - store_m_ADDR(mask, e->e_mask); + e->e_mask.addr = mask; - rn = squid_rn_lookup(e->e_addr, e->e_mask, AS_tree_head); + rn = squid_rn_lookup(&e->e_addr, &e->e_mask, AS_tree_head); if (rn != NULL) { asinfo = ((rtentry_t *) rn)->e_info; @@ -441,7 +442,6 @@ debugs(53, 3, "asnAddNet: Warning: Found a network with multiple AS numbers!"); for (Tail = &asinfo->as_number; *Tail; Tail = &(*Tail)->next) - ; q = new List (as_number); @@ -453,8 +453,8 @@ q = new List (as_number); asinfo = (as_info *)xmalloc(sizeof(as_info)); asinfo->as_number = q; - rn = squid_rn_addroute(e->e_addr, e->e_mask, AS_tree_head, e->e_nodes); - rn = squid_rn_match(e->e_addr, AS_tree_head); + rn = squid_rn_addroute(&e->e_addr, &e->e_mask, AS_tree_head, e->e_nodes); + rn = squid_rn_match(&e->e_addr, AS_tree_head); assert(rn != NULL); e->e_info = asinfo; } @@ -521,8 +521,8 @@ assert(e); assert(e->e_info); - (void) get_m_ADDR(addr, e->e_addr); - (void) get_m_ADDR(mask, e->e_mask); + addr = e->e_addr.addr; + mask = e->e_mask.addr; storeAppendPrintf(sentry, "%s/%d\t", addr.NtoA(buf, MAX_IPSTRLEN), mask.GetCIDR() );