addrfilt: remove TEST code
A test of the address filter is now included in unit tests.
This commit is contained in:
parent
4c77d18416
commit
fe00319f45
1 changed files with 0 additions and 114 deletions
114
addrfilt.c
114
addrfilt.c
|
@ -401,117 +401,3 @@ ADF_IsAnyAllowed(ADF_AuthTable table, int family)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
#if defined TEST
|
|
||||||
|
|
||||||
static void print_node(TableNode *node, uint32_t *addr, int ip_len, int shift, int subnet_bits)
|
|
||||||
{
|
|
||||||
uint32_t new_addr[4];
|
|
||||||
int i;
|
|
||||||
TableNode *sub_node;
|
|
||||||
|
|
||||||
for (i=0; i<subnet_bits; i++) putchar(' ');
|
|
||||||
|
|
||||||
if (ip_len == 1)
|
|
||||||
printf("%d.%d.%d.%d",
|
|
||||||
((addr[0] >> 24) & 255),
|
|
||||||
((addr[0] >> 16) & 255),
|
|
||||||
((addr[0] >> 8) & 255),
|
|
||||||
((addr[0] ) & 255));
|
|
||||||
else {
|
|
||||||
for (i=0; i<4; i++) {
|
|
||||||
if (addr[i])
|
|
||||||
printf("%d.%d.%d.%d",
|
|
||||||
((addr[i] >> 24) & 255),
|
|
||||||
((addr[i] >> 16) & 255),
|
|
||||||
((addr[i] >> 8) & 255),
|
|
||||||
((addr[i] ) & 255));
|
|
||||||
putchar(i < 3 ? ':' : '\0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("/%d : %s\n",
|
|
||||||
subnet_bits,
|
|
||||||
(node->state == ALLOW) ? "allow" :
|
|
||||||
(node->state == DENY) ? "deny" : "as parent");
|
|
||||||
if (node->extended) {
|
|
||||||
for (i=0; i<16; i++) {
|
|
||||||
sub_node = &(node->extended[i]);
|
|
||||||
new_addr[0] = addr[0];
|
|
||||||
new_addr[1] = addr[1];
|
|
||||||
new_addr[2] = addr[2];
|
|
||||||
new_addr[3] = addr[3];
|
|
||||||
new_addr[ip_len - 1 - shift / 32] |= ((uint32_t)i << (shift % 32));
|
|
||||||
print_node(sub_node, new_addr, ip_len, shift - 4, subnet_bits + 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void print_table(ADF_AuthTable table)
|
|
||||||
{
|
|
||||||
uint32_t addr[4];
|
|
||||||
|
|
||||||
memset(addr, 0, sizeof (addr));
|
|
||||||
printf("IPv4 table:\n");
|
|
||||||
print_node(&table->base4, addr, 1, 28, 0);
|
|
||||||
|
|
||||||
memset(addr, 0, sizeof (addr));
|
|
||||||
printf("IPv6 table:\n");
|
|
||||||
print_node(&table->base6, addr, 4, 124, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ================================================== */
|
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
IPAddr ip;
|
|
||||||
ADF_AuthTable table;
|
|
||||||
table = ADF_CreateTable();
|
|
||||||
|
|
||||||
ip.family = IPADDR_INET4;
|
|
||||||
|
|
||||||
ip.addr.in4 = 0x7e800000;
|
|
||||||
ADF_Allow(table, &ip, 9);
|
|
||||||
ip.addr.in4 = 0x7ecc0000;
|
|
||||||
ADF_Deny(table, &ip, 14);
|
|
||||||
#if 0
|
|
||||||
ip.addr.in4 = 0x7f000001;
|
|
||||||
ADF_Deny(table, &ip, 32);
|
|
||||||
ip.addr.in4 = 0x7f000000;
|
|
||||||
ADF_Allow(table, &ip, 8);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
printf("allowed: %d\n", ADF_IsAllowed(table, &ip));
|
|
||||||
ip.addr.in4 ^= 1;
|
|
||||||
printf("allowed: %d\n", ADF_IsAllowed(table, &ip));
|
|
||||||
|
|
||||||
ip.family = IPADDR_INET6;
|
|
||||||
|
|
||||||
memcpy(ip.addr.in6, "abcdefghijklmnop", 16);
|
|
||||||
ADF_Deny(table, &ip, 66);
|
|
||||||
ADF_Allow(table, &ip, 59);
|
|
||||||
|
|
||||||
memcpy(ip.addr.in6, "xbcdefghijklmnop", 16);
|
|
||||||
ADF_Deny(table, &ip, 128);
|
|
||||||
ip.addr.in6[15] ^= 3;
|
|
||||||
ADF_Allow(table, &ip, 127);
|
|
||||||
|
|
||||||
printf("allowed: %d\n", ADF_IsAllowed(table, &ip));
|
|
||||||
ip.addr.in4 ^= 1;
|
|
||||||
printf("allowed: %d\n", ADF_IsAllowed(table, &ip));
|
|
||||||
|
|
||||||
print_table(table);
|
|
||||||
|
|
||||||
ADF_DestroyTable(table);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* defined TEST */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue