tree.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2022 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. int masklen; /* CIDR network mask length */
  31. int server_cnt; /* count # of times this entry was flagged server */
  32. int client_cnt; /* flagged client */
  33. int type; /* 1 = server, 0 = client, -1 = undefined */
  34. } tcpr_tree_t;
  35. /*
  36. * replacement for RB_HEAD() which doesn't actually declare the root
  37. */
  38. typedef struct tcpr_data_tree_s {
  39. tcpr_tree_t *rbh_root;
  40. } tcpr_data_tree_t;
  41. typedef struct tcpr_buildcidr_s {
  42. int type; /* SERVER|CLIENT|UNKNOWN|ANY */
  43. int masklen; /* mask size to use to build the CIDR */
  44. } tcpr_buildcidr_t;
  45. #define DNS_QUERY_FLAG 0x8000
  46. void add_tree_ipv4(const unsigned long, const u_char*, const int, const int);
  47. void add_tree_ipv6(const struct tcpr_in6_addr*,
  48. const u_char*,
  49. const int,
  50. const int);
  51. void add_tree_first_ipv4(const u_char *, const int, const int);
  52. void add_tree_first_ipv6(const u_char *, const int, const int);
  53. tcpr_dir_t check_ip_tree(const int, const unsigned long);
  54. tcpr_dir_t check_ip6_tree(const int, const struct tcpr_in6_addr *);
  55. int process_tree();
  56. void tree_calculate(tcpr_data_tree_t *);
  57. int tree_comp(tcpr_tree_t *, tcpr_tree_t *);
  58. #endif