2
0

testacl.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2018-2023 SignalWire, Inc
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. #include "libks/ks.h"
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "tap.h"
  27. int main(int argc, char **argv)
  28. {
  29. ks_pool_t *pool;
  30. ks_network_list_t *list = NULL;
  31. ks_bool_t match;
  32. ks_init();
  33. plan(8);
  34. ks_pool_open(&pool);
  35. ks_network_list_create(&list, "test", KS_FALSE, pool);
  36. ks_network_list_add_cidr(list, "10.0.0.0/8", KS_TRUE);
  37. ks_network_list_add_cidr(list, "172.16.0.0/12", KS_TRUE);
  38. ks_network_list_add_cidr(list, "192.168.0.0/16", KS_TRUE);
  39. ks_network_list_add_cidr(list, "fe80::/10", KS_TRUE);
  40. match = ks_check_network_list_ip("192.168.1.1", list);
  41. ok(match);
  42. match = ks_check_network_list_ip("208.34.128.7", list);
  43. ok (!match);
  44. match = ks_check_network_list_ip_cidr("192.168.1.1", "192.168.0.0/16");
  45. ok(match);
  46. match = ks_check_network_list_ip_cidr("208.34.128.7", "192.168.0.0/16");
  47. ok (!match);
  48. ks_pool_free(&list);
  49. ks_network_list_create(&list, "test", KS_TRUE, pool);
  50. ks_network_list_add_cidr(list, "0.0.0.0/0", KS_FALSE);
  51. ks_network_list_add_cidr(list, "fe80::/10", KS_FALSE);
  52. match = ks_check_network_list_ip("2637:f368:1281::10", list);
  53. ok(match);
  54. match = ks_check_network_list_ip("fe80::18b7:53b3:51d8:f5cf", list);
  55. ok(!match);
  56. match = ks_check_network_list_ip_cidr("fe80::18b7:53b3:51d8:f5cf", "fe80::/10");
  57. ok(match);
  58. match = ks_check_network_list_ip_cidr("2637:f368:1281::10", "fe80::/10");
  59. ok(!match);
  60. ks_pool_free(&list);
  61. ks_pool_close(&pool);
  62. ks_shutdown();
  63. done_testing();
  64. }