tree.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2018 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  5. *
  6. * The Tcpreplay Suite of tools is free software: you can redistribute it
  7. * and/or modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or with the authors permission any later version.
  10. *
  11. * The Tcpreplay Suite is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with the Tcpreplay Suite. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __TREE_H__
  20. #define __TREE_H__
  21. #include "lib/tree.h"
  22. #define TREEPRINTBUFFLEN 2048
  23. typedef struct tcpr_tree_s {
  24. RB_ENTRY(tcpr_tree_s) node;
  25. int family;
  26. union {
  27. unsigned long ip; /* ip/network address in network byte order */
  28. struct tcpr_in6_addr ip6;
  29. } u;
  30. u_char mac[ETHER_ADDR_LEN]; /* mac address of system */
  31. int masklen; /* CIDR network mask length */
  32. int server_cnt; /* count # of times this entry was flagged server */
  33. int client_cnt; /* flagged client */
  34. int type; /* 1 = server, 0 = client, -1 = undefined */
  35. } tcpr_tree_t;
  36. /*
  37. * replacement for RB_HEAD() which doesn't actually declare the root
  38. */
  39. typedef struct tcpr_data_tree_s {
  40. tcpr_tree_t *rbh_root;
  41. } tcpr_data_tree_t;
  42. typedef struct tcpr_buildcidr_s {
  43. int type; /* SERVER|CLIENT|UNKNOWN|ANY */
  44. int masklen; /* mask size to use to build the CIDR */
  45. } tcpr_buildcidr_t;
  46. #define DNS_QUERY_FLAG 0x8000
  47. void add_tree_ipv4(const unsigned long, const u_char *, const int);
  48. void add_tree_ipv6(const struct tcpr_in6_addr *, const u_char *, const int);
  49. void add_tree_first_ipv4(const u_char *, const int);
  50. void add_tree_first_ipv6(const u_char *, const int);
  51. tcpr_dir_t check_ip_tree(const int, const unsigned long);
  52. tcpr_dir_t check_ip6_tree(const int, const struct tcpr_in6_addr *);
  53. int process_tree();
  54. void tree_calculate(tcpr_data_tree_t *);
  55. int tree_comp(tcpr_tree_t *, tcpr_tree_t *);
  56. #endif