-static ipv6_t cache_ipv6_address[2];
-static subnet_t *cache_ipv6_subnet[2];
-static bool cache_ipv6_valid[2];
-static int cache_ipv6_slot;
-
-void subnet_cache_flush() {
- cache_ipv4_valid[0] = cache_ipv4_valid[1] = false;
- cache_ipv6_valid[0] = cache_ipv6_valid[1] = false;
-}
-
-/* Subnet comparison */
-
-static int subnet_compare_mac(const subnet_t *a, const subnet_t *b)
-{
- int result;
-
- result = memcmp(&a->net.mac.address, &b->net.mac.address, sizeof(mac_t));
-
- if(result)
- return result;
-
- result = a->weight - b->weight;
-
- if(result || !a->owner || !b->owner)
- return result;
-
- return strcmp(a->owner->name, b->owner->name);
-}
-
-static int subnet_compare_ipv4(const subnet_t *a, const subnet_t *b)
-{
- int result;
-
- result = b->net.ipv4.prefixlength - a->net.ipv4.prefixlength;
-
- if(result)
- return result;
-
- result = memcmp(&a->net.ipv4.address, &b->net.ipv4.address, sizeof(ipv4_t));
-
- if(result)
- return result;
-
- result = a->weight - b->weight;
-
- if(result || !a->owner || !b->owner)
- return result;
-
- return strcmp(a->owner->name, b->owner->name);
-}
-
-static int subnet_compare_ipv6(const subnet_t *a, const subnet_t *b)
-{
- int result;
-
- result = b->net.ipv6.prefixlength - a->net.ipv6.prefixlength;
-
- if(result)
- return result;
-
- result = memcmp(&a->net.ipv6.address, &b->net.ipv6.address, sizeof(ipv6_t));
-
- if(result)
- return result;
-
- result = a->weight - b->weight;
-
- if(result || !a->owner || !b->owner)
- return result;
-
- return strcmp(a->owner->name, b->owner->name);
-}
-
-int subnet_compare(const subnet_t *a, const subnet_t *b)
-{
- int result;
-
- result = a->type - b->type;
-
- if(result)
- return result;
-
- switch (a->type) {
- case SUBNET_MAC:
- return subnet_compare_mac(a, b);
- case SUBNET_IPV4:
- return subnet_compare_ipv4(a, b);
- case SUBNET_IPV6:
- return subnet_compare_ipv6(a, b);
- default:
- logger(LOG_ERR, _("subnet_compare() was called with unknown subnet type %d, exitting!"),
- a->type);
- cp_trace();
- exit(0);
- }
-
- return 0;