1 | /* |
---|
2 | * This file is part of libtrace |
---|
3 | * |
---|
4 | * Copyright (c) 2004 The University of Waikato, Hamilton, New Zealand. |
---|
5 | * Authors: Daniel Lawson |
---|
6 | * Perry Lorier |
---|
7 | * |
---|
8 | * All rights reserved. |
---|
9 | * |
---|
10 | * This code has been developed by the University of Waikato WAND |
---|
11 | * research group. For further information please see http://www.wand.net.nz/ |
---|
12 | * |
---|
13 | * libtrace is free software; you can redistribute it and/or modify |
---|
14 | * it under the terms of the GNU General Public License as published by |
---|
15 | * the Free Software Foundation; either version 2 of the License, or |
---|
16 | * (at your option) any later version. |
---|
17 | * |
---|
18 | * libtrace is distributed in the hope that it will be useful, |
---|
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | * GNU General Public License for more details. |
---|
22 | * |
---|
23 | * You should have received a copy of the GNU General Public License |
---|
24 | * along with libtrace; if not, write to the Free Software |
---|
25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
26 | * |
---|
27 | * $Id$ |
---|
28 | * |
---|
29 | */ |
---|
30 | |
---|
31 | #ifndef LIBTRACE_INT_H |
---|
32 | #define LIBTRACE_INT_H |
---|
33 | |
---|
34 | #ifdef __cplusplus |
---|
35 | extern "C" { |
---|
36 | #endif |
---|
37 | |
---|
38 | #include "common.h" |
---|
39 | #include "config.h" |
---|
40 | #include "libtrace.h" |
---|
41 | #include "fifo.h" |
---|
42 | |
---|
43 | #if HAVE_PCAP_BPF_H |
---|
44 | # include <pcap-bpf.h> |
---|
45 | #else |
---|
46 | # ifdef HAVE_NET_BPF_H |
---|
47 | # include <net/bpf.h> |
---|
48 | # endif |
---|
49 | #endif |
---|
50 | |
---|
51 | #if HAVE_PCAP_H |
---|
52 | # include <pcap.h> |
---|
53 | # ifdef HAVE_PCAP_INT_H |
---|
54 | # include <pcap-int.h> |
---|
55 | # endif |
---|
56 | #endif |
---|
57 | |
---|
58 | #ifdef HAVE_ZLIB_H |
---|
59 | # include <zlib.h> |
---|
60 | #endif |
---|
61 | |
---|
62 | |
---|
63 | #include "wag.h" |
---|
64 | #include "daglegacy.h" |
---|
65 | |
---|
66 | #ifdef HAVE_DAG_API |
---|
67 | # include "dagnew.h" |
---|
68 | # include "dagapi.h" |
---|
69 | #else |
---|
70 | # include "dagformat.h" |
---|
71 | #endif |
---|
72 | |
---|
73 | #include <stdbool.h> |
---|
74 | |
---|
75 | |
---|
76 | void trace_set_err(int errcode,const char *msg,...); |
---|
77 | |
---|
78 | #define RP_BUFSIZE 65536 |
---|
79 | |
---|
80 | struct libtrace_format_data_t; |
---|
81 | |
---|
82 | struct libtrace_event_t { |
---|
83 | struct { |
---|
84 | void *buffer; |
---|
85 | int size; |
---|
86 | } packet; |
---|
87 | double tdelta; |
---|
88 | double trace_last_ts; |
---|
89 | }; |
---|
90 | |
---|
91 | /** The information about traces that are open |
---|
92 | * @internal |
---|
93 | */ |
---|
94 | struct libtrace_t { |
---|
95 | struct libtrace_format_t *format; /**< format driver pointer */ |
---|
96 | struct libtrace_format_data_t *format_data; /**<format data pointer */ |
---|
97 | bool started; |
---|
98 | |
---|
99 | struct libtrace_event_t event; |
---|
100 | char *uridata; |
---|
101 | struct tracefifo_t *fifo; |
---|
102 | struct libtrace_filter_t *filter; /**< used by libtrace if the module |
---|
103 | * doesn't support filters natively |
---|
104 | */ |
---|
105 | int snaplen; /**< used by libtrace if the module |
---|
106 | * doesn't support snapping natively |
---|
107 | */ |
---|
108 | }; |
---|
109 | |
---|
110 | struct libtrace_out_t { |
---|
111 | struct libtrace_format_t *format; |
---|
112 | struct libtrace_format_data_out_t *format_data; |
---|
113 | |
---|
114 | char *uridata; |
---|
115 | struct tracefifo_t *fifo; |
---|
116 | bool started; |
---|
117 | }; |
---|
118 | |
---|
119 | |
---|
120 | struct trace_sll_header_t { |
---|
121 | uint16_t pkttype; /* packet type */ |
---|
122 | uint16_t hatype; /* link-layer address type */ |
---|
123 | uint16_t halen; /* link-layer address length */ |
---|
124 | char addr[8]; /* link-layer address */ |
---|
125 | uint16_t protocol; /* protocol */ |
---|
126 | }; |
---|
127 | |
---|
128 | #ifndef PF_RULESET_NAME_SIZE |
---|
129 | #define PF_RULESET_NAME_SIZE 16 |
---|
130 | #endif |
---|
131 | |
---|
132 | #ifndef IFNAMSIZ |
---|
133 | #define IFNAMSIZ 16 |
---|
134 | #endif |
---|
135 | |
---|
136 | struct trace_pflog_header_t { |
---|
137 | uint8_t length; |
---|
138 | sa_family_t af; |
---|
139 | uint8_t action; |
---|
140 | uint8_t reason; |
---|
141 | char ifname[IFNAMSIZ]; |
---|
142 | char ruleset[PF_RULESET_NAME_SIZE]; |
---|
143 | uint32_t rulenr; |
---|
144 | uint32_t subrulenr; |
---|
145 | uint8_t dir; |
---|
146 | uint8_t pad[3]; |
---|
147 | }; |
---|
148 | |
---|
149 | struct libtrace_format_t { |
---|
150 | char *name; |
---|
151 | char *version; |
---|
152 | enum base_format_t type; |
---|
153 | int (*init_input)(libtrace_t *libtrace); |
---|
154 | int (*config_input)(libtrace_t *libtrace,trace_option_t option,void *value); |
---|
155 | int (*start_input)(libtrace_t *libtrace); |
---|
156 | int (*pause_input)(libtrace_t *libtrace); |
---|
157 | int (*init_output)(libtrace_out_t *libtrace); |
---|
158 | int (*config_output)(libtrace_out_t *libtrace, trace_option_output_t, void *); |
---|
159 | int (*start_output)(libtrace_out_t *libtrace); |
---|
160 | int (*fin_input)(libtrace_t *libtrace); |
---|
161 | int (*fin_output)(libtrace_out_t *libtrace); |
---|
162 | int (*read_packet)(libtrace_t *libtrace, struct libtrace_packet_t *packet); |
---|
163 | int (*write_packet)(libtrace_out_t *libtrace, const libtrace_packet_t *packet); |
---|
164 | libtrace_linktype_t (*get_link_type)(const libtrace_packet_t *packet); |
---|
165 | int8_t (*get_direction)(const libtrace_packet_t *packet); |
---|
166 | int8_t (*set_direction)(const libtrace_packet_t *packet, int8_t direction); |
---|
167 | uint64_t (*get_erf_timestamp)(const libtrace_packet_t *packet); |
---|
168 | struct timeval (*get_timeval)(const libtrace_packet_t *packet); |
---|
169 | double (*get_seconds)(const libtrace_packet_t *packet); |
---|
170 | int (*seek_erf)(libtrace_t *trace, uint64_t timestamp); |
---|
171 | int (*seek_timeval)(libtrace_t *trace, struct timeval tv); |
---|
172 | int (*seek_seconds)(libtrace_t *trace, double seconds); |
---|
173 | int (*get_capture_length)(const libtrace_packet_t *packet); |
---|
174 | int (*get_wire_length)(const libtrace_packet_t *packet); |
---|
175 | int (*get_framing_length)(const libtrace_packet_t *packet); |
---|
176 | size_t (*set_capture_length)(struct libtrace_packet_t *packet,size_t size); |
---|
177 | int (*get_fd)(const libtrace_t *trace); |
---|
178 | struct libtrace_eventobj_t (*trace_event)(libtrace_t *trace, libtrace_packet_t *packet); |
---|
179 | void (*help)(); |
---|
180 | }; |
---|
181 | |
---|
182 | extern struct libtrace_format_t *form; |
---|
183 | |
---|
184 | void register_format(struct libtrace_format_t *format); |
---|
185 | |
---|
186 | libtrace_linktype_t pcap_dlt_to_libtrace(int dlt); |
---|
187 | char libtrace_to_pcap_dlt(libtrace_linktype_t type); |
---|
188 | libtrace_linktype_t erf_type_to_libtrace(char erf); |
---|
189 | char libtrace_to_erf_type(libtrace_linktype_t linktype); |
---|
190 | |
---|
191 | #if HAVE_BPF |
---|
192 | /* A type encapsulating a bpf filter |
---|
193 | * This type covers the compiled bpf filter, as well as the original filter |
---|
194 | * string |
---|
195 | * |
---|
196 | */ |
---|
197 | struct libtrace_filter_t { |
---|
198 | struct bpf_program filter; |
---|
199 | int flag; |
---|
200 | char * filterstring; |
---|
201 | }; |
---|
202 | #endif |
---|
203 | |
---|
204 | #ifdef __cplusplus |
---|
205 | } |
---|
206 | #endif |
---|
207 | |
---|
208 | #endif /* LIBTRACE_INT_H */ |
---|