flownode.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* $Id: flownode.h 767 2004-10-06 12:48:49Z aturner $ */
  2. /*
  3. * Copyright (c) 2001-2004 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 __FLOWNODE_H__
  32. #define __FLOWNODE_H__
  33. #include <sys/types.h>
  34. #include "tcpreplay.h"
  35. #include "flowkey.h"
  36. #include "rbtree.h"
  37. #define RBKEYLEN 12
  38. /* linked list data structure of buffered packets */
  39. struct pktbuffhdr_t {
  40. u_int32_t len; /* packet length */
  41. u_char *packet; /* packet data */
  42. struct pktbuffhdr_t *next; /* next packet */
  43. };
  44. /* Links a session in the pcap with the fd of the socket */
  45. struct session_t {
  46. RB_ENTRY(session_t) node;
  47. u_char key[RBKEYLEN]; /* lookup id for this node
  48. * which is the high IP + low IP + high port + low port
  49. */
  50. int socket; /* socket fd */
  51. u_int32_t server_ip; /* ip we're connecting to */
  52. u_int32_t count; /* number of packets so far in the flow */
  53. u_int32_t data_expected; /* # of bytes expected from server until we send again */
  54. u_int32_t data_recieved; /* # of bytes recieved from server */
  55. u_int16_t server_port; /* port we're connecting to */
  56. u_char state; /* TCP state */
  57. u_char proto; /* IPPROTO_TCP, UDP */
  58. u_char direction; /* direction of the flow */
  59. #define C2S 0x1
  60. #define S2C 0x2
  61. u_char wait; /* are we waiting for the server to reply? */
  62. #define WAIT 0x1
  63. #define DONT_WAIT 0x2
  64. struct pktbuffhdr_t *buffered; /* linked list of packets buffered */
  65. struct pktbuffhdr_t *lastbuff; /* pointer to last packet buffered */
  66. struct pktbuffhdr_t *sentbuff; /* pointer to last packet sent */
  67. u_int32_t buffmem; /* bytes currently in use by the packet buff linked list */
  68. };
  69. /*
  70. * custom replacement for RB_HEAD() so we can use the
  71. * same struct for the tree type, with different
  72. * tree heads
  73. */
  74. struct session_tree {
  75. struct session_t *rbh_root;
  76. };
  77. struct session_t *getnodebykey(char, u_char *);
  78. struct session_t *newnode(char, u_char *, ip_hdr_t *, void *);
  79. int rbsession_comp(struct session_t *, struct session_t *);
  80. void delete_node(struct session_tree *, struct session_t *);
  81. void close_sockets(void);
  82. #endif