cache.h 3.6 KB

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