tree.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* $Id: tree.h 1368 2005-06-28 05:25:16Z aturner $ */
  2. /*
  3. * Copyright (c) 2001-2005 Aaron Turner.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the names of the copyright owners nor the names of its
  16. * contributors may be used to endorse or promote products derived from
  17. * this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  20. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  25. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  27. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  28. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  29. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #ifndef __TREE_H__
  32. #define __TREE_H__
  33. #include "lib/tree.h"
  34. struct tree_s {
  35. RB_ENTRY(tree_s) node;
  36. unsigned long ip; /* ip/network address in network byte order */
  37. u_char mac[ETHER_ADDR_LEN]; /* mac address of system */
  38. int masklen; /* CIDR network mask length */
  39. int server_cnt; /* count # of times this entry was flagged server */
  40. int client_cnt; /* flagged client */
  41. int type; /* 1 = server, 0 = client, -1 = undefined */
  42. };
  43. typedef struct tree_s tree_t;
  44. /*
  45. * replacement for RB_HEAD() which doesn't actually declare the root
  46. */
  47. struct data_tree_s {
  48. tree_t *rbh_root;
  49. };
  50. typedef struct data_tree_s data_tree_t;
  51. struct buildcidr_s {
  52. int type; /* SERVER|CLIENT|UNKNOWN|ANY */
  53. int masklen; /* mask size to use to build the CIDR */
  54. };
  55. typedef struct buildcidr_s buildcidr_t;
  56. #define DEF_MAX_MASK 8 /* default max masklen */
  57. #define DEF_MIN_MASK 30 /* default min masklen */
  58. #define DEF_RATIO 2.0 /* default auto ratio */
  59. #define DNS_QUERY_FLAG 0x8000
  60. void add_tree(const unsigned long, const u_char *); /* done */
  61. int check_ip_tree(const int, const unsigned long);
  62. int process_tree();
  63. void tree_calculate(data_tree_t *);
  64. int tree_comp(tree_t *, tree_t *);
  65. #endif
  66. /*
  67. Local Variables:
  68. mode:c
  69. indent-tabs-mode:nil
  70. c-basic-offset:4
  71. End:
  72. */