#include <Anon.h>
Inheritance diagram for AnonymizeIPAddr_A50:


Public Member Functions | |
| AnonymizeIPAddr_A50 () | |
| ~AnonymizeIPAddr_A50 () | |
| ipaddr32_t | anonymize (ipaddr32_t addr) |
| int | PreservePrefix (ipaddr32_t input, int num_bits) |
Protected Member Functions | |
| void | init () |
| Node * | new_node () |
| Node * | new_node_block () |
| void | free_node (Node *) |
| ipaddr32_t | make_output (ipaddr32_t, int) const |
| Node * | make_peer (ipaddr32_t, Node *) |
| Node * | find_node (ipaddr32_t) |
Protected Attributes | |
| int | method |
| int | before_anonymization |
| int | new_mapping |
| Node * | root |
| Node * | next_free_node |
| std::vector< Node * > | blocks |
| Node | special_nodes [2] |
|
|
Definition at line 94 of file Anon.h. References init().
00094 { init(); }
|
|
|
Definition at line 122 of file Anon.cc. References blocks.
|
|
|
Implements AnonymizeIPAddr. Definition at line 174 of file Anon.cc. References before_anonymization, find_node(), ipaddr32_t, new_mapping, and AnonymizeIPAddr_A50::Node::output.
00175 {
00176 before_anonymization = 0;
00177 new_mapping = 0;
00178
00179 if ( Node* n = find_node(ntohl(a)) )
00180 {
00181 ipaddr32_t output = htonl(n->output);
00182 return output;
00183 }
00184 else
00185 return 0;
00186 }
|
|
|
Definition at line 284 of file Anon.cc. References bi_ffs(), AnonymizeIPAddr_A50::Node::child, AnonymizeIPAddr_A50::Node::input, internal_error(), ipaddr32_t, make_peer(), new_node(), AnonymizeIPAddr_A50::Node::output, rand32(), root, and special_nodes. Referenced by anonymize(), and PreservePrefix().
00285 {
00286 // Watch out for special IP addresses, which never make it
00287 // into the tree.
00288 if ( a == 0 || a == 0xFFFFFFFFU )
00289 return &special_nodes[a & 1];
00290
00291 if ( ! root )
00292 {
00293 root = new_node();
00294 root->input = a;
00295 root->output = rand32();
00296 root->child[0] = root->child[1] = 0;
00297
00298 return root;
00299 }
00300
00301 // Straight from tcpdpriv.
00302 Node* n = root;
00303 while ( n )
00304 {
00305 if ( n->input == a )
00306 return n;
00307
00308 if ( ! n->child[0] )
00309 n = make_peer(a, n);
00310
00311 else
00312 {
00313 // swivel is the first bit in which the two children
00314 // differ.
00315 int swivel =
00316 bi_ffs(n->child[0]->input ^ n->child[1]->input);
00317
00318 if ( bi_ffs(a ^ n->input) < swivel )
00319 // Input differs earlier.
00320 n = make_peer(a, n);
00321
00322 else if ( a & (1 << (32 - swivel)) )
00323 n = n->child[1];
00324
00325 else
00326 n = n->child[0];
00327 }
00328 }
00329
00330 internal_error("out of memory!");
00331 return 0;
00332 }
|
|
|
Definition at line 222 of file Anon.cc. References AnonymizeIPAddr_A50::Node::child, and next_free_node. Referenced by make_peer().
00223 {
00224 n->child[0] = next_free_node;
00225 next_free_node = n;
00226 }
|
|
|
Definition at line 130 of file Anon.cc. References before_anonymization, AnonymizeIPAddr_A50::Node::input, next_free_node, AnonymizeIPAddr_A50::Node::output, root, and special_nodes. Referenced by AnonymizeIPAddr_A50().
00131 {
00132 root = next_free_node = 0;
00133
00134 // Prepare special nodes for 0.0.0.0 and 255.255.255.255.
00135 memset(&special_nodes[0], 0, sizeof(special_nodes));
00136 special_nodes[0].input = special_nodes[0].output = 0;
00137 special_nodes[1].input = special_nodes[1].output = 0xFFFFFFFF;
00138
00139 before_anonymization = 1;
00140 }
|
|
||||||||||||
|
Definition at line 228 of file Anon.cc. References ipaddr32_t, and rand32(). Referenced by make_peer().
00229 {
00230 // -A50 anonymization
00231 if ( swivel == 32 )
00232 return old_output ^ 1;
00233 else
00234 {
00235 // Bits up to swivel are unchanged; bit swivel is flipped.
00236 ipaddr32_t known_part =
00237 ((old_output >> (32 - swivel)) ^ 1) << (32 - swivel);
00238
00239 // Remainder of bits are random.
00240 return known_part | ((rand32() & 0x7FFFFFFF) >> swivel);
00241 }
00242 }
|
|
||||||||||||
|
Definition at line 244 of file Anon.cc. References bi_ffs(), AnonymizeIPAddr_A50::Node::child, free_node(), AnonymizeIPAddr_A50::Node::input, internal_error(), ipaddr32_t, make_output(), new_node(), and AnonymizeIPAddr_A50::Node::output. Referenced by find_node().
00245 {
00246 if ( a == 0 || a == 0xFFFFFFFFU )
00247 internal_error("0.0.0.0 and 255.255.255.255 should never get into the tree");
00248
00249 // Become a peer.
00250 // Algorithm: create two nodes, the two peers. Leave orig node as
00251 // the parent of the two new ones.
00252
00253 Node* down[2];
00254
00255 if ( ! (down[0] = new_node()) )
00256 return 0;
00257
00258 if ( ! (down[1] = new_node()) )
00259 {
00260 free_node(down[0]);
00261 return 0;
00262 }
00263
00264 // swivel is first bit 'a' and 'old->input' differ.
00265 int swivel = bi_ffs(a ^ n->input);
00266
00267 // bitvalue is the value of that bit of 'a'.
00268 int bitvalue = (a >> (32 - swivel)) & 1;
00269
00270 down[bitvalue]->input = a;
00271 down[bitvalue]->output = make_output(n->output, swivel);
00272 down[bitvalue]->child[0] = down[bitvalue]->child[1] = 0;
00273
00274 *down[1 - bitvalue] = *n; // copy orig node down one level
00275
00276 n->input = down[1]->input; // NB: 1s to the right (0s to the left)
00277 n->output = down[1]->output;
00278 n->child[0] = down[0]; // point to children
00279 n->child[1] = down[1];
00280
00281 return down[bitvalue];
00282 }
|
|
|
Definition at line 208 of file Anon.cc. References AnonymizeIPAddr_A50::Node::child, new_mapping, new_node_block(), and next_free_node. Referenced by find_node(), and make_peer().
00209 {
00210 new_mapping = 1;
00211
00212 if ( next_free_node )
00213 {
00214 Node* n = next_free_node;
00215 next_free_node = n->child[0];
00216 return n;
00217 }
00218 else
00219 return new_node_block();
00220 }
|
|
|
Definition at line 188 of file Anon.cc. References blocks, AnonymizeIPAddr_A50::Node::child, internal_error(), and next_free_node. Referenced by new_node().
00189 {
00190 assert(! next_free_node);
00191
00192 int block_size = 1024;
00193 Node* block = new Node[block_size];
00194 if ( ! block )
00195 internal_error("out of memory!");
00196
00197 blocks.push_back(block);
00198
00199 for ( int i = 1; i < block_size - 1; ++i )
00200 block[i].child[0] = &block[i+1];
00201
00202 block[block_size - 1].child[0] = 0;
00203 next_free_node = &block[1];
00204
00205 return &block[0];
00206 }
|
|
||||||||||||
|
Reimplemented from AnonymizeIPAddr. Definition at line 142 of file Anon.cc. References before_anonymization, DEBUG_MSG, dotted_addr(), find_node(), first_n_bit_mask, fmt(), ipaddr32_t, AnonymizeIPAddr_A50::Node::output, rand32(), run_time(), and uint32.
00143 {
00144 DEBUG_MSG(fmt("%s/%d\n", dotted_addr(input), num_bits));
00145
00146 if ( ! before_anonymization )
00147 {
00148 run_time("prefix perservation specified after anonymization begun");
00149 return 0;
00150 }
00151
00152 input = ntohl(input);
00153
00154 // Sanitize input.
00155 input = input & first_n_bit_mask(num_bits);
00156
00157 Node* n = find_node(input);
00158
00159 // Preserve the first num_bits bits of addr.
00160 if ( num_bits == 32 )
00161 n->output = input;
00162
00163 else if ( num_bits > 0 )
00164 {
00165 assert((0xFFFFFFFFU >> 1) == 0x7FFFFFFFU);
00166 uint32 suffix_mask = (0xFFFFFFFFU >> num_bits);
00167 uint32 prefix_mask = ~suffix_mask;
00168 n->output = (input & prefix_mask) | (rand32() & suffix_mask);
00169 }
00170
00171 return 1;
00172 }
|
|
|
Definition at line 108 of file Anon.h. Referenced by anonymize(), init(), and PreservePrefix(). |
|
|
Definition at line 116 of file Anon.h. Referenced by new_node_block(), and ~AnonymizeIPAddr_A50(). |
|
|
|
|
|
Definition at line 109 of file Anon.h. Referenced by anonymize(), and new_node(). |
|
|
Definition at line 115 of file Anon.h. Referenced by free_node(), init(), new_node(), and new_node_block(). |
|
|
Definition at line 112 of file Anon.h. Referenced by find_node(), and init(). |
|
|
Definition at line 119 of file Anon.h. Referenced by find_node(), and init(). |
1.3.5