You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.6 KiB

10 years ago
  1. /* -*- coding: utf-8 -*-
  2. * ----------------------------------------------------------------------
  3. * Copyright © 2009-2012, RedJack, LLC.
  4. * All rights reserved.
  5. *
  6. * Please see the LICENSE.txt file in this distribution for license
  7. * details.
  8. * ----------------------------------------------------------------------
  9. */
  10. #include <libcork/core.h>
  11. #include "ipset/bdd/nodes.h"
  12. #include "ipset/ipset.h"
  13. bool
  14. ipmap_is_empty(const struct ip_map *map)
  15. {
  16. /* Since BDDs are unique, any map that maps all addresses to the
  17. * default value is empty. */
  18. return (map->map_bdd == map->default_bdd);
  19. }
  20. bool
  21. ipmap_is_equal(const struct ip_map *map1, const struct ip_map *map2)
  22. {
  23. return ipset_node_cache_nodes_equal
  24. (map1->cache, map1->map_bdd, map2->cache, map2->map_bdd);
  25. }
  26. size_t
  27. ipmap_memory_size(const struct ip_map *map)
  28. {
  29. return ipset_node_memory_size(map->cache, map->map_bdd);
  30. }
  31. void
  32. ipmap_ip_set(struct ip_map *map, struct cork_ip *addr, int value)
  33. {
  34. if (addr->version == 4) {
  35. ipmap_ipv4_set(map, &addr->ip.v4, value);
  36. } else {
  37. ipmap_ipv6_set(map, &addr->ip.v6, value);
  38. }
  39. }
  40. void
  41. ipmap_ip_set_network(struct ip_map *map, struct cork_ip *addr,
  42. unsigned int cidr_prefix, int value)
  43. {
  44. if (addr->version == 4) {
  45. ipmap_ipv4_set_network(map, &addr->ip.v4, cidr_prefix, value);
  46. } else {
  47. ipmap_ipv6_set_network(map, &addr->ip.v6, cidr_prefix, value);
  48. }
  49. }
  50. int
  51. ipmap_ip_get(struct ip_map *map, struct cork_ip *addr)
  52. {
  53. if (addr->version == 4) {
  54. return ipmap_ipv4_get(map, &addr->ip.v4);
  55. } else {
  56. return ipmap_ipv6_get(map, &addr->ip.v6);
  57. }
  58. }