1 /* $Id$ */
2 
3 /*
4  *   Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
5  *   Copyright (c) 2013-2018 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
6  *
7  *   The Tcpreplay Suite of tools is free software: you can redistribute it
8  *   and/or modify it under the terms of the GNU General Public License as
9  *   published by the Free Software Foundation, either version 3 of the
10  *   License, or with the authors permission any later version.
11  *
12  *   The Tcpreplay Suite is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with the Tcpreplay Suite.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __CACHE_H__
22 #define __CACHE_H__
23 
24 #define CACHEMAGIC "tcpprep"
25 #define CACHEVERSION "04"
26 #define CACHEDATASIZE 255
27 #define CACHE_PACKETS_PER_BYTE 4    /* number of packets / byte */
28 #define CACHE_BITS_PER_PACKET 2     /* number of bits / packet */
29 
30 #define SEND 1
31 #define DONT_SEND 0
32 
33 /*
34  * CACHEVERSION History:
35  * 01 - Initial release.  1 bit of data/packet (primary or secondary nic)
36  * 02 - 2 bits of data/packet (drop/send & primary or secondary nic)
37  * 03 - Write integers in network-byte order
38  * 04 - Increase num_packets from 32 to 64 bit integer
39  */
40 
41 struct tcpr_cache_s {
42     char data[CACHEDATASIZE];
43     unsigned int packets;       /* number of packets tracked in data */
44     struct tcpr_cache_s *next;
45 };
46 typedef struct tcpr_cache_s tcpr_cache_t;
47 
48 /*
49  * Each byte in cache_type.data represents CACHE_PACKETS_PER_BYTE (4) number of packets
50  * Each packet has CACHE_BITS_PER_PACKETS (2) bits of data.
51  * High Bit: 1 = send, 0 = don't send
52  * Low Bit: 1 = primary interface, 0 = secondary interface
53 */
54 
55 /*
56  * cache_file_header Data structure defining a file as a tcpprep cache file
57  * and it's version
58  *
59  * If you need to enhance this struct, do so AFTER the version field and be sure
60  * to increment  CACHEVERSION
61  */
62 struct tcpr_cache_file_hdr_s {
63     char magic[8];
64     char version[4];
65     /* begin version 2 features */
66     /* version 3 puts everything in network-byte order */
67     /* version 4 makes num_packets a 64 bit int */
68     u_int64_t num_packets;      /* total # of packets in file */
69     u_int16_t packets_per_byte;
70     u_int16_t comment_len;      /* how long is the user comment? */
71 } __attribute__((__packed__));
72 
73 typedef struct tcpr_cache_file_hdr_s tcpr_cache_file_hdr_t;
74 
75 enum tcpr_dir_e {
76     TCPR_DIR_ERROR  = -1,
77     TCPR_DIR_NOSEND = 0,
78     TCPR_DIR_C2S    = 1, /* aka PRIMARY */
79     TCPR_DIR_S2C    = 2 /* aka SECONDARY */
80 };
81 typedef enum tcpr_dir_e tcpr_dir_t;
82 
83 
84 COUNTER write_cache(tcpr_cache_t *, const int, COUNTER, char *);
85 tcpr_dir_t add_cache(tcpr_cache_t **, const int, const tcpr_dir_t);
86 COUNTER read_cache(char **, const char *, char **);
87 tcpr_dir_t check_cache(char *, COUNTER);
88 
89 /* return values for check_cache
90 #define CACHE_ERROR -1
91 #define CACHE_NOSEND 0  // NULL
92 #define CACHE_PRIMARY 1
93 #define CACHE_SECONDARY 2
94 */
95 
96 
97 /* macro to change a bitstring to 8 bits */
98 #define BIT_STR(x) x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7]
99 
100 /* string of 8 zeros */
101 #define EIGHT_ZEROS "\060\060\060\060\060\060\060\060"
102 
103 #endif
104