tree.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2024 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. #pragma once
  20. #include "defines.h"
  21. #include "tcpr.h"
  22. #include <lib/tree.h>
  23. #define TREEPRINTBUFFLEN 2048
  24. typedef struct tcpr_tree_s {
  25. RB_ENTRY(tcpr_tree_s) node;
  26. int family;
  27. union {
  28. unsigned long ip; /* ip/network address in network byte order */
  29. struct tcpr_in6_addr ip6;
  30. } u;
  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(unsigned long, const u_char *, int, int);
  48. void add_tree_ipv6(const struct tcpr_in6_addr *, const u_char *, int, int);
  49. void add_tree_first_ipv4(const u_char *, int, int);
  50. void add_tree_first_ipv6(const u_char *, int, int);
  51. tcpr_dir_t check_ip_tree(int, unsigned long);
  52. tcpr_dir_t check_ip6_tree(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 *);