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.

50 lines
1.0 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. void
  14. ipmap_init(struct ip_map *map, int default_value)
  15. {
  16. /* The map starts empty, so every value assignment should yield the
  17. * default. */
  18. map->cache = ipset_node_cache_new();
  19. map->default_bdd = ipset_terminal_node_id(default_value);
  20. map->map_bdd = map->default_bdd;
  21. }
  22. struct ip_map *
  23. ipmap_new(int default_value)
  24. {
  25. struct ip_map *result = cork_new(struct ip_map);
  26. ipmap_init(result, default_value);
  27. return result;
  28. }
  29. void
  30. ipmap_done(struct ip_map *map)
  31. {
  32. ipset_node_decref(map->cache, map->map_bdd);
  33. ipset_node_cache_free(map->cache);
  34. }
  35. void
  36. ipmap_free(struct ip_map *map)
  37. {
  38. ipmap_done(map);
  39. free(map);
  40. }