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.

91 lines
2.2 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. ipset_is_empty(const struct ip_set *set)
  15. {
  16. /* Since BDDs are unique, the only empty set is the “false” BDD. */
  17. return (set->set_bdd == ipset_terminal_node_id(false));
  18. }
  19. bool
  20. ipset_is_equal(const struct ip_set *set1, const struct ip_set *set2)
  21. {
  22. return ipset_node_cache_nodes_equal
  23. (set1->cache, set1->set_bdd, set2->cache, set2->set_bdd);
  24. }
  25. size_t
  26. ipset_memory_size(const struct ip_set *set)
  27. {
  28. return ipset_node_memory_size(set->cache, set->set_bdd);
  29. }
  30. bool
  31. ipset_ip_add(struct ip_set *set, struct cork_ip *addr)
  32. {
  33. if (addr->version == 4) {
  34. return ipset_ipv4_add(set, &addr->ip.v4);
  35. } else {
  36. return ipset_ipv6_add(set, &addr->ip.v6);
  37. }
  38. }
  39. bool
  40. ipset_ip_add_network(struct ip_set *set, struct cork_ip *addr,
  41. unsigned int cidr_prefix)
  42. {
  43. if (addr->version == 4) {
  44. return ipset_ipv4_add_network(set, &addr->ip.v4, cidr_prefix);
  45. } else {
  46. return ipset_ipv6_add_network(set, &addr->ip.v6, cidr_prefix);
  47. }
  48. }
  49. bool
  50. ipset_ip_remove(struct ip_set *set, struct cork_ip *addr)
  51. {
  52. if (addr->version == 4) {
  53. return ipset_ipv4_remove(set, &addr->ip.v4);
  54. } else {
  55. return ipset_ipv6_remove(set, &addr->ip.v6);
  56. }
  57. }
  58. bool
  59. ipset_ip_remove_network(struct ip_set *set, struct cork_ip *addr,
  60. unsigned int cidr_prefix)
  61. {
  62. if (addr->version == 4) {
  63. return ipset_ipv4_remove_network(set, &addr->ip.v4, cidr_prefix);
  64. } else {
  65. return ipset_ipv6_remove_network(set, &addr->ip.v6, cidr_prefix);
  66. }
  67. }
  68. bool
  69. ipset_contains_ip(const struct ip_set *set, struct cork_ip *addr)
  70. {
  71. if (addr->version == 4) {
  72. return ipset_contains_ipv4(set, &addr->ip.v4);
  73. } else {
  74. return ipset_contains_ipv6(set, &addr->ip.v6);
  75. }
  76. }