cache.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* $Id: cache.h 1078 2005-01-10 19:41:48Z 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 __CACHE_H__
  32. #define __CACHE_H__
  33. #define CACHEMAGIC "tcpprep"
  34. #define CACHEVERSION "04"
  35. #define CACHEDATASIZE 255
  36. #define CACHE_PACKETS_PER_BYTE 4 /* number of packets / byte */
  37. #define CACHE_BITS_PER_PACKET 2 /* number of bits / packet */
  38. #define SEND 1
  39. #define DONT_SEND 0
  40. /*
  41. * CACHEVERSION History:
  42. * 01 - Inital release. 1 bit of data/packet (primary or secondary nic)
  43. * 02 - 2 bits of data/packet (drop/send & primary or secondary nic)
  44. * 03 - Write integers in network-byte order
  45. * 04 - Increase num_packets from 32 to 64 bit integer
  46. */
  47. struct cache_s {
  48. char data[CACHEDATASIZE];
  49. unsigned int packets; /* number of packets tracked in data */
  50. struct cache_s *next;
  51. };
  52. typedef struct cache_s cache_t;
  53. /*
  54. * Each byte in cache_type.data represents CACHE_PACKETS_PER_BYTE (4) number of packets
  55. * Each packet has CACHE_BITS_PER_PACKETS (2) bits of data.
  56. * High Bit: 1 = send, 0 = don't send
  57. * Low Bit: 1 = primary interface, 0 = secondary interface
  58. */
  59. /*
  60. * cache_file_header Data structure defining a file as a tcpprep cache file
  61. * and it's version
  62. *
  63. * If you need to enhance this struct, do so AFTER the version field and be sure
  64. * to increment CACHEVERSION
  65. */
  66. struct cache_file_hdr_s {
  67. char magic[8];
  68. char version[4];
  69. /* begin version 2 features */
  70. /* version 3 puts everything in network-byte order */
  71. /* version 4 makes num_packets a 64 bit int */
  72. u_int64_t num_packets; /* total # of packets in file */
  73. u_int16_t packets_per_byte;
  74. u_int16_t comment_len; /* how long is the user comment? */
  75. };
  76. typedef struct cache_file_hdr_s cache_file_hdr_t;
  77. COUNTER write_cache(cache_t *, const int, COUNTER, char *);
  78. int add_cache(cache_t **, const int, const int);
  79. COUNTER read_cache(char **, const char *, char **);
  80. int check_cache(char *, COUNTER);
  81. /* return values for check_cache */
  82. #define CACHE_ERROR -1
  83. #define CACHE_NOSEND 0 /* equal to NULL */
  84. #define CACHE_PRIMARY 1
  85. #define CACHE_SECONDARY 2
  86. /* macro to change a bitstring to 8 bits */
  87. #define BIT_STR(x) x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7]
  88. /* string of 8 zeros */
  89. #define EIGHT_ZEROS "\060\060\060\060\060\060\060\060"
  90. #endif
  91. /*
  92. Local Variables:
  93. mode:c
  94. indent-tabs-mode:nil
  95. c-basic-offset:4
  96. End:
  97. */