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 | #define _GNU_SOURCE |
---|
31 | |
---|
32 | #include "config.h" |
---|
33 | #include "common.h" |
---|
34 | #include "libtrace.h" |
---|
35 | #include "libtrace_int.h" |
---|
36 | #include "format_helper.h" |
---|
37 | #include "parse_cmd.h" |
---|
38 | |
---|
39 | #include <assert.h> |
---|
40 | #include <errno.h> |
---|
41 | #include <fcntl.h> |
---|
42 | #include <stdio.h> |
---|
43 | #include <string.h> |
---|
44 | #include <stdlib.h> |
---|
45 | |
---|
46 | #if HAVE_DAG |
---|
47 | #include <sys/mman.h> |
---|
48 | #endif |
---|
49 | |
---|
50 | #ifdef WIN32 |
---|
51 | # include <io.h> |
---|
52 | # include <share.h> |
---|
53 | # define PATH_MAX _MAX_PATH |
---|
54 | # define snprintf sprintf_s |
---|
55 | #else |
---|
56 | # include <netdb.h> |
---|
57 | # ifndef PATH_MAX |
---|
58 | # define PATH_MAX 4096 |
---|
59 | # endif |
---|
60 | # include <sys/ioctl.h> |
---|
61 | #endif |
---|
62 | |
---|
63 | |
---|
64 | #define COLLECTOR_PORT 3435 |
---|
65 | |
---|
66 | static struct libtrace_format_t erf; |
---|
67 | static struct libtrace_format_t rtclient; |
---|
68 | #if HAVE_DAG |
---|
69 | static struct libtrace_format_t dag; |
---|
70 | #endif |
---|
71 | |
---|
72 | #define DATA(x) ((struct erf_format_data_t *)x->format_data) |
---|
73 | #define DATAOUT(x) ((struct erf_format_data_out_t *)x->format_data) |
---|
74 | |
---|
75 | #define CONNINFO DATA(libtrace)->conn_info |
---|
76 | #define INPUT DATA(libtrace)->input |
---|
77 | #define OUTPUT DATAOUT(libtrace)->output |
---|
78 | #if HAVE_DAG |
---|
79 | #define DAG DATA(libtrace)->dag |
---|
80 | #define DUCK DATA(libtrace)->duck |
---|
81 | #endif |
---|
82 | #define OPTIONS DATAOUT(libtrace)->options |
---|
83 | struct erf_format_data_t { |
---|
84 | union { |
---|
85 | struct { |
---|
86 | char *hostname; |
---|
87 | short port; |
---|
88 | } rt; |
---|
89 | } conn_info; |
---|
90 | |
---|
91 | union { |
---|
92 | int fd; |
---|
93 | libtrace_io_t *file; |
---|
94 | } input; |
---|
95 | |
---|
96 | struct { |
---|
97 | enum { INDEX_UNKNOWN=0, INDEX_NONE, INDEX_EXISTS } exists; |
---|
98 | libtrace_io_t *index; |
---|
99 | off_t index_len; |
---|
100 | } seek; |
---|
101 | |
---|
102 | #if HAVE_DAG |
---|
103 | struct { |
---|
104 | uint32_t last_duck; |
---|
105 | uint32_t duck_freq; |
---|
106 | uint32_t last_pkt; |
---|
107 | libtrace_t *dummy_duck; |
---|
108 | } duck; |
---|
109 | |
---|
110 | struct { |
---|
111 | void *buf; |
---|
112 | unsigned bottom; |
---|
113 | unsigned top; |
---|
114 | unsigned diff; |
---|
115 | unsigned curr; |
---|
116 | unsigned offset; |
---|
117 | unsigned int dagstream; |
---|
118 | } dag; |
---|
119 | #endif |
---|
120 | }; |
---|
121 | |
---|
122 | struct erf_format_data_out_t { |
---|
123 | union { |
---|
124 | struct { |
---|
125 | char *hostname; |
---|
126 | short port; |
---|
127 | } rt; |
---|
128 | char *path; |
---|
129 | } conn_info; |
---|
130 | |
---|
131 | union { |
---|
132 | struct { |
---|
133 | int level; |
---|
134 | int fileflag; |
---|
135 | } erf; |
---|
136 | |
---|
137 | } options; |
---|
138 | |
---|
139 | union { |
---|
140 | int fd; |
---|
141 | struct rtserver_t * rtserver; |
---|
142 | libtrace_io_t *file; |
---|
143 | } output; |
---|
144 | }; |
---|
145 | |
---|
146 | /** Structure holding status information for a packet */ |
---|
147 | typedef struct libtrace_packet_status { |
---|
148 | uint8_t type; |
---|
149 | uint8_t reserved; |
---|
150 | uint16_t message; |
---|
151 | } libtrace_packet_status_t; |
---|
152 | |
---|
153 | typedef struct erf_index_t { |
---|
154 | uint64_t timestamp; |
---|
155 | uint64_t offset; |
---|
156 | } erf_index_t; |
---|
157 | |
---|
158 | #ifdef HAVE_DAG |
---|
159 | static int dag_init_input(libtrace_t *libtrace) { |
---|
160 | struct stat buf; |
---|
161 | |
---|
162 | libtrace->format_data = (struct erf_format_data_t *) |
---|
163 | malloc(sizeof(struct erf_format_data_t)); |
---|
164 | if (stat(libtrace->uridata, &buf) == -1) { |
---|
165 | trace_set_err(libtrace,errno,"stat(%s)",libtrace->uridata); |
---|
166 | return -1; |
---|
167 | } |
---|
168 | |
---|
169 | DAG.dagstream = 0; |
---|
170 | |
---|
171 | if (S_ISCHR(buf.st_mode)) { |
---|
172 | /* DEVICE */ |
---|
173 | if((INPUT.fd = dag_open(libtrace->uridata)) < 0) { |
---|
174 | trace_set_err(libtrace,errno,"Cannot open DAG %s", |
---|
175 | libtrace->uridata); |
---|
176 | return -1; |
---|
177 | } |
---|
178 | if((DAG.buf = (void *)dag_mmap(INPUT.fd)) == MAP_FAILED) { |
---|
179 | trace_set_err(libtrace,errno,"Cannot mmap DAG %s", |
---|
180 | libtrace->uridata); |
---|
181 | return -1; |
---|
182 | } |
---|
183 | } else { |
---|
184 | trace_set_err(libtrace,errno,"Not a valid dag device: %s", |
---|
185 | libtrace->uridata); |
---|
186 | return -1; |
---|
187 | } |
---|
188 | |
---|
189 | DUCK.last_duck = 0; |
---|
190 | DUCK.duck_freq = 0; |
---|
191 | DUCK.last_pkt = 0; |
---|
192 | DUCK.dummy_duck = NULL; |
---|
193 | |
---|
194 | return 0; |
---|
195 | } |
---|
196 | |
---|
197 | static int dag_config_input(libtrace_t *libtrace, trace_option_t option, |
---|
198 | void *data) { |
---|
199 | switch(option) { |
---|
200 | case TRACE_META_FREQ: |
---|
201 | DUCK.duck_freq = *(int *)data; |
---|
202 | return 0; |
---|
203 | case TRACE_OPTION_SNAPLEN: |
---|
204 | /* Surely we can set this?? Fall through for now*/ |
---|
205 | |
---|
206 | case TRACE_OPTION_PROMISC: |
---|
207 | /* DAG already operates in a promisc fashion */ |
---|
208 | |
---|
209 | case TRACE_OPTION_FILTER: |
---|
210 | |
---|
211 | default: |
---|
212 | trace_set_err(libtrace, TRACE_ERR_UNKNOWN_OPTION, |
---|
213 | "Unknown or unsupported option: %i", |
---|
214 | option); |
---|
215 | return -1; |
---|
216 | } |
---|
217 | assert (0); |
---|
218 | } |
---|
219 | #endif |
---|
220 | |
---|
221 | /* Dag erf ether packets have a 2 byte padding before the packet |
---|
222 | * so that the ip header is aligned on a 32 bit boundary. |
---|
223 | */ |
---|
224 | static int erf_get_padding(const libtrace_packet_t *packet) |
---|
225 | { |
---|
226 | if (packet->trace->format->type==TRACE_FORMAT_ERF) { |
---|
227 | dag_record_t *erfptr = (dag_record_t *)packet->header; |
---|
228 | switch(erfptr->type) { |
---|
229 | case TYPE_ETH: return 2; |
---|
230 | default: return 0; |
---|
231 | } |
---|
232 | } |
---|
233 | else { |
---|
234 | switch(trace_get_link_type(packet)) { |
---|
235 | case TYPE_ETH: return 2; |
---|
236 | default: return 0; |
---|
237 | } |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | static int erf_get_framing_length(const libtrace_packet_t *packet) |
---|
242 | { |
---|
243 | return dag_record_size + erf_get_padding(packet); |
---|
244 | } |
---|
245 | |
---|
246 | |
---|
247 | static int erf_init_input(libtrace_t *libtrace) |
---|
248 | { |
---|
249 | libtrace->format_data = malloc(sizeof(struct erf_format_data_t)); |
---|
250 | |
---|
251 | INPUT.file = 0; |
---|
252 | |
---|
253 | return 0; /* success */ |
---|
254 | } |
---|
255 | |
---|
256 | static int erf_start_input(libtrace_t *libtrace) |
---|
257 | { |
---|
258 | if (INPUT.file) |
---|
259 | return 0; /* success */ |
---|
260 | |
---|
261 | INPUT.file = trace_open_file(libtrace); |
---|
262 | |
---|
263 | if (!INPUT.file) |
---|
264 | return -1; |
---|
265 | |
---|
266 | return 0; /* success */ |
---|
267 | } |
---|
268 | |
---|
269 | /* Binary search through the index to find the closest point before |
---|
270 | * the packet. Consider in future having a btree index perhaps? |
---|
271 | */ |
---|
272 | static int erf_fast_seek_start(libtrace_t *libtrace,uint64_t erfts) |
---|
273 | { |
---|
274 | size_t max_off = DATA(libtrace)->seek.index_len/sizeof(erf_index_t); |
---|
275 | size_t min_off = 0; |
---|
276 | off_t current; |
---|
277 | erf_index_t record; |
---|
278 | do { |
---|
279 | current=(max_off+min_off)>>2; |
---|
280 | |
---|
281 | libtrace_io_seek(DATA(libtrace)->seek.index, |
---|
282 | current*sizeof(record), |
---|
283 | SEEK_SET); |
---|
284 | libtrace_io_read(DATA(libtrace)->seek.index, |
---|
285 | &record,sizeof(record)); |
---|
286 | if (record.timestamp < erfts) { |
---|
287 | min_off=current; |
---|
288 | } |
---|
289 | if (record.timestamp > erfts) { |
---|
290 | max_off=current; |
---|
291 | } |
---|
292 | if (record.timestamp == erfts) |
---|
293 | break; |
---|
294 | } while(min_off<max_off); |
---|
295 | |
---|
296 | /* If we've passed it, seek backwards. This loop shouldn't |
---|
297 | * execute more than twice. |
---|
298 | */ |
---|
299 | do { |
---|
300 | libtrace_io_seek(DATA(libtrace)->seek.index, |
---|
301 | current*sizeof(record),SEEK_SET); |
---|
302 | libtrace_io_read(DATA(libtrace)->seek.index, |
---|
303 | &record,sizeof(record)); |
---|
304 | current--; |
---|
305 | } while(record.timestamp>erfts); |
---|
306 | |
---|
307 | /* We've found our location in the trace, now use it. */ |
---|
308 | libtrace_io_seek(INPUT.file,record.offset,SEEK_SET); |
---|
309 | |
---|
310 | return 0; /* success */ |
---|
311 | } |
---|
312 | |
---|
313 | /* There is no index. Seek through the entire trace from the start, nice |
---|
314 | * and slowly. |
---|
315 | */ |
---|
316 | static int erf_slow_seek_start(libtrace_t *libtrace,uint64_t erfts) |
---|
317 | { |
---|
318 | if (INPUT.file) { |
---|
319 | libtrace_io_close(INPUT.file); |
---|
320 | } |
---|
321 | INPUT.file = trace_open_file(libtrace); |
---|
322 | if (!INPUT.file) |
---|
323 | return -1; |
---|
324 | return 0; |
---|
325 | } |
---|
326 | |
---|
327 | static int erf_seek_erf(libtrace_t *libtrace,uint64_t erfts) |
---|
328 | { |
---|
329 | libtrace_packet_t *packet; |
---|
330 | off_t off = 0; |
---|
331 | |
---|
332 | if (DATA(libtrace)->seek.exists==INDEX_UNKNOWN) { |
---|
333 | char buffer[PATH_MAX]; |
---|
334 | snprintf(buffer,sizeof(buffer),"%s.idx",libtrace->uridata); |
---|
335 | DATA(libtrace)->seek.index=libtrace_io_open(buffer,"rb"); |
---|
336 | if (DATA(libtrace)->seek.index) { |
---|
337 | DATA(libtrace)->seek.exists=INDEX_EXISTS; |
---|
338 | } |
---|
339 | else { |
---|
340 | DATA(libtrace)->seek.exists=INDEX_NONE; |
---|
341 | } |
---|
342 | } |
---|
343 | |
---|
344 | /* If theres an index, use it to find the nearest packet that isn't |
---|
345 | * after the time we're looking for. If there is no index we need |
---|
346 | * to seek slowly through the trace from the beginning. Sigh. |
---|
347 | */ |
---|
348 | switch(DATA(libtrace)->seek.exists) { |
---|
349 | case INDEX_EXISTS: |
---|
350 | erf_fast_seek_start(libtrace,erfts); |
---|
351 | break; |
---|
352 | case INDEX_NONE: |
---|
353 | erf_slow_seek_start(libtrace,erfts); |
---|
354 | break; |
---|
355 | case INDEX_UNKNOWN: |
---|
356 | assert(0); |
---|
357 | break; |
---|
358 | } |
---|
359 | |
---|
360 | /* Now seek forward looking for the correct timestamp */ |
---|
361 | packet=trace_create_packet(); |
---|
362 | do { |
---|
363 | trace_read_packet(libtrace,packet); |
---|
364 | if (trace_get_erf_timestamp(packet)==erfts) |
---|
365 | break; |
---|
366 | off=libtrace_io_tell(INPUT.file); |
---|
367 | } while(trace_get_erf_timestamp(packet)<erfts); |
---|
368 | |
---|
369 | libtrace_io_seek(INPUT.file,off,SEEK_SET); |
---|
370 | |
---|
371 | return 0; |
---|
372 | } |
---|
373 | |
---|
374 | static int rtclient_init_input(libtrace_t *libtrace) { |
---|
375 | char *scan; |
---|
376 | libtrace->format_data = malloc(sizeof(struct erf_format_data_t)); |
---|
377 | |
---|
378 | if (strlen(libtrace->uridata) == 0) { |
---|
379 | CONNINFO.rt.hostname = |
---|
380 | strdup("localhost"); |
---|
381 | CONNINFO.rt.port = |
---|
382 | COLLECTOR_PORT; |
---|
383 | } else { |
---|
384 | if ((scan = strchr(libtrace->uridata,':')) == NULL) { |
---|
385 | CONNINFO.rt.hostname = |
---|
386 | strdup(libtrace->uridata); |
---|
387 | CONNINFO.rt.port = |
---|
388 | COLLECTOR_PORT; |
---|
389 | } else { |
---|
390 | CONNINFO.rt.hostname = |
---|
391 | (char *)strndup(libtrace->uridata, |
---|
392 | (scan - libtrace->uridata)); |
---|
393 | CONNINFO.rt.port = |
---|
394 | atoi(++scan); |
---|
395 | } |
---|
396 | } |
---|
397 | |
---|
398 | return 0; /* success */ |
---|
399 | } |
---|
400 | |
---|
401 | static int rtclient_start_input(libtrace_t *libtrace) |
---|
402 | { |
---|
403 | struct hostent *he; |
---|
404 | struct sockaddr_in remote; |
---|
405 | if ((he=gethostbyname(CONNINFO.rt.hostname)) == NULL) { |
---|
406 | trace_set_err(libtrace,TRACE_ERR_INIT_FAILED,"failed to resolve %s", |
---|
407 | CONNINFO.rt.hostname); |
---|
408 | return -1; |
---|
409 | } |
---|
410 | if ((INPUT.fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { |
---|
411 | trace_set_err(libtrace,errno,"socket(AF_INET,SOCK_STREAM)"); |
---|
412 | return -1; |
---|
413 | } |
---|
414 | |
---|
415 | remote.sin_family = AF_INET; |
---|
416 | remote.sin_port = htons(CONNINFO.rt.port); |
---|
417 | remote.sin_addr = *((struct in_addr *)he->h_addr); |
---|
418 | memset(&(remote.sin_zero), 0, 8); |
---|
419 | |
---|
420 | if (connect(INPUT.fd, (struct sockaddr *)&remote, |
---|
421 | sizeof(struct sockaddr)) == -1) { |
---|
422 | trace_set_err(libtrace,errno,"connect(%s)", |
---|
423 | CONNINFO.rt.hostname); |
---|
424 | return -1; |
---|
425 | } |
---|
426 | return 0; /* success */ |
---|
427 | } |
---|
428 | |
---|
429 | static int rtclient_pause_input(libtrace_t *libtrace) |
---|
430 | { |
---|
431 | close(INPUT.fd); |
---|
432 | return 0; /* success */ |
---|
433 | } |
---|
434 | |
---|
435 | static int erf_init_output(libtrace_out_t *libtrace) { |
---|
436 | libtrace->format_data = malloc(sizeof(struct erf_format_data_out_t)); |
---|
437 | |
---|
438 | OPTIONS.erf.level = 0; |
---|
439 | OPTIONS.erf.fileflag = O_CREAT | O_WRONLY; |
---|
440 | OUTPUT.file = 0; |
---|
441 | |
---|
442 | return 0; |
---|
443 | } |
---|
444 | |
---|
445 | static int erf_config_output(libtrace_out_t *libtrace, trace_option_output_t option, |
---|
446 | void *value) { |
---|
447 | |
---|
448 | switch (option) { |
---|
449 | case TRACE_OPTION_OUTPUT_COMPRESS: |
---|
450 | OPTIONS.erf.level = *(int*)value; |
---|
451 | return 0; |
---|
452 | case TRACE_OPTION_OUTPUT_FILEFLAGS: |
---|
453 | OPTIONS.erf.fileflag = *(int*)value; |
---|
454 | return 0; |
---|
455 | default: |
---|
456 | /* Unknown option */ |
---|
457 | trace_set_err_out(libtrace,TRACE_ERR_UNKNOWN_OPTION, |
---|
458 | "Unknown option"); |
---|
459 | return -1; |
---|
460 | } |
---|
461 | } |
---|
462 | |
---|
463 | |
---|
464 | #ifdef HAVE_DAG |
---|
465 | static int dag_pause_input(libtrace_t *libtrace) { |
---|
466 | #if DAG_VERSION_2_4 |
---|
467 | dag_stop(INPUT.fd); |
---|
468 | #else |
---|
469 | if (dag_stop_stream(INPUT.fd, DAG.dagstream) < 0) { |
---|
470 | trace_set_err(libtrace, errno, "Could not stop DAG stream"); |
---|
471 | return -1; |
---|
472 | } |
---|
473 | if (dag_detach_stream(INPUT.fd, DAG.dagstream) < 0) { |
---|
474 | trace_set_err(libtrace, errno, "Could not detach DAG stream"); |
---|
475 | return -1; |
---|
476 | } |
---|
477 | #endif |
---|
478 | return 0; /* success */ |
---|
479 | } |
---|
480 | |
---|
481 | static int dag_fin_input(libtrace_t *libtrace) { |
---|
482 | /* dag pause input implicitly called to cleanup before this */ |
---|
483 | |
---|
484 | dag_close(INPUT.fd); |
---|
485 | if (DUCK.dummy_duck) |
---|
486 | trace_destroy_dead(DUCK.dummy_duck); |
---|
487 | free(libtrace->format_data); |
---|
488 | return 0; /* success */ |
---|
489 | } |
---|
490 | #endif |
---|
491 | |
---|
492 | static int rtclient_fin_input(libtrace_t *libtrace) { |
---|
493 | free(CONNINFO.rt.hostname); |
---|
494 | close(INPUT.fd); |
---|
495 | free(libtrace->format_data); |
---|
496 | return 0; |
---|
497 | } |
---|
498 | |
---|
499 | static int erf_fin_input(libtrace_t *libtrace) { |
---|
500 | if (INPUT.file) |
---|
501 | libtrace_io_close(INPUT.file); |
---|
502 | free(libtrace->format_data); |
---|
503 | return 0; |
---|
504 | } |
---|
505 | |
---|
506 | static int erf_fin_output(libtrace_out_t *libtrace) { |
---|
507 | libtrace_io_close(OUTPUT.file); |
---|
508 | free(libtrace->format_data); |
---|
509 | return 0; |
---|
510 | } |
---|
511 | |
---|
512 | #if HAVE_DAG |
---|
513 | #if DAG_VERSION_2_4 |
---|
514 | static int dag_get_duckinfo(libtrace_t *libtrace, |
---|
515 | libtrace_packet_t *packet) { |
---|
516 | dag_inf lt_dag_inf; |
---|
517 | |
---|
518 | if (packet->buf_control == TRACE_CTRL_EXTERNAL || |
---|
519 | !packet->buffer) { |
---|
520 | packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); |
---|
521 | packet->buf_control = TRACE_CTRL_PACKET; |
---|
522 | if (!packet->buffer) { |
---|
523 | trace_set_err(libtrace, errno, |
---|
524 | "Cannot allocate packet buffer"); |
---|
525 | return -1; |
---|
526 | } |
---|
527 | } |
---|
528 | |
---|
529 | packet->header = 0; |
---|
530 | packet->payload = packet->buffer; |
---|
531 | |
---|
532 | if ((ioctl(INPUT.fd, DAG_IOINF, <_dag_inf) < 0)) { |
---|
533 | trace_set_err(libtrace, errno, |
---|
534 | "Error using DAG_IOINF"); |
---|
535 | return -1; |
---|
536 | } |
---|
537 | if (!IsDUCK(<_dag_inf)) { |
---|
538 | printf("WARNING: %s does not have modern clock support - No DUCK information will be gathered\n", libtrace->uridata); |
---|
539 | return 0; |
---|
540 | } |
---|
541 | |
---|
542 | if ((ioctl(INPUT.fd, DAG_IOGETDUCK, (duck_inf *)packet->payload) |
---|
543 | < 0)) { |
---|
544 | trace_set_err(libtrace, errno, "Error using DAG_IOGETDUCK"); |
---|
545 | return -1; |
---|
546 | } |
---|
547 | |
---|
548 | packet->type = RT_DUCK_2_4; |
---|
549 | packet->size = sizeof(duck_inf); |
---|
550 | if (!DUCK.dummy_duck) |
---|
551 | DUCK.dummy_duck = trace_create_dead("duck:dummy"); |
---|
552 | packet->trace = DUCK.dummy_duck; |
---|
553 | return packet->size; |
---|
554 | } |
---|
555 | #else |
---|
556 | static int dag_get_duckinfo(libtrace_t *libtrace, |
---|
557 | libtrace_packet_t *packet) { |
---|
558 | daginf_t lt_dag_inf; |
---|
559 | |
---|
560 | if (packet->buf_control == TRACE_CTRL_EXTERNAL || |
---|
561 | !packet->buffer) { |
---|
562 | packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); |
---|
563 | packet->buf_control = TRACE_CTRL_PACKET; |
---|
564 | if (!packet->buffer) { |
---|
565 | trace_set_err(libtrace, errno, |
---|
566 | "Cannot allocate packet buffer"); |
---|
567 | return -1; |
---|
568 | } |
---|
569 | } |
---|
570 | |
---|
571 | packet->header = 0; |
---|
572 | packet->payload = packet->buffer; |
---|
573 | |
---|
574 | /* No need to check if we can get DUCK or not - we're modern |
---|
575 | * enough */ |
---|
576 | if ((ioctl(INPUT.fd, DAGIOCDUCK, (duckinf_t *)packet->payload) |
---|
577 | < 0)) { |
---|
578 | trace_set_err(libtrace, errno, "Error using DAGIOCDUCK"); |
---|
579 | return -1; |
---|
580 | } |
---|
581 | |
---|
582 | packet->type = RT_DUCK_2_5; |
---|
583 | packet->size = sizeof(duckinf_t); |
---|
584 | if (!DUCK.dummy_duck) |
---|
585 | DUCK.dummy_duck = trace_create_dead("rt:localhost:3434"); |
---|
586 | packet->trace = DUCK.dummy_duck; |
---|
587 | return packet->size; |
---|
588 | } |
---|
589 | #endif |
---|
590 | |
---|
591 | static int dag_read(libtrace_t *libtrace, int block_flag) { |
---|
592 | |
---|
593 | if (DAG.diff != 0) |
---|
594 | return DAG.diff; |
---|
595 | |
---|
596 | DAG.bottom = DAG.top; |
---|
597 | |
---|
598 | DAG.top = dag_offset( |
---|
599 | INPUT.fd, |
---|
600 | &(DAG.bottom), |
---|
601 | block_flag); |
---|
602 | |
---|
603 | DAG.diff = DAG.top - DAG.bottom; |
---|
604 | |
---|
605 | DAG.offset = 0; |
---|
606 | return DAG.diff; |
---|
607 | } |
---|
608 | |
---|
609 | /* FIXME: dag_read_packet shouldn't update the pointers, dag_fin_packet |
---|
610 | * should do that. |
---|
611 | */ |
---|
612 | static int dag_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { |
---|
613 | int numbytes; |
---|
614 | int size; |
---|
615 | struct timeval tv; |
---|
616 | dag_record_t *erfptr; |
---|
617 | |
---|
618 | if (DUCK.last_pkt - DUCK.last_duck > DUCK.duck_freq && |
---|
619 | DUCK.duck_freq != 0) { |
---|
620 | size = dag_get_duckinfo(libtrace, packet); |
---|
621 | DUCK.last_duck = DUCK.last_pkt; |
---|
622 | if (size != 0) { |
---|
623 | return size; |
---|
624 | } |
---|
625 | /* No DUCK support, so don't waste our time anymore */ |
---|
626 | DUCK.duck_freq = 0; |
---|
627 | } |
---|
628 | |
---|
629 | if (packet->buf_control == TRACE_CTRL_PACKET) { |
---|
630 | packet->buf_control = TRACE_CTRL_EXTERNAL; |
---|
631 | free(packet->buffer); |
---|
632 | packet->buffer = 0; |
---|
633 | } |
---|
634 | |
---|
635 | packet->type = RT_DATA_ERF; |
---|
636 | |
---|
637 | if ((numbytes = dag_read(libtrace,0)) < 0) |
---|
638 | return numbytes; |
---|
639 | assert(numbytes>0); |
---|
640 | |
---|
641 | /*DAG always gives us whole packets */ |
---|
642 | erfptr = (dag_record_t *) ((char *)DAG.buf + |
---|
643 | (DAG.bottom + DAG.offset)); |
---|
644 | size = ntohs(erfptr->rlen); |
---|
645 | |
---|
646 | assert( size >= dag_record_size ); |
---|
647 | assert( size < LIBTRACE_PACKET_BUFSIZE); |
---|
648 | |
---|
649 | packet->buffer = erfptr; |
---|
650 | packet->header = erfptr; |
---|
651 | if (((dag_record_t *)packet->buffer)->flags.rxerror == 1) { |
---|
652 | packet->payload = NULL; |
---|
653 | } else { |
---|
654 | packet->payload = (char*)packet->buffer |
---|
655 | + erf_get_framing_length(packet); |
---|
656 | } |
---|
657 | |
---|
658 | DAG.offset += size; |
---|
659 | DAG.diff -= size; |
---|
660 | |
---|
661 | packet->size = size; |
---|
662 | tv = trace_get_timeval(packet); |
---|
663 | DUCK.last_pkt = tv.tv_sec; |
---|
664 | |
---|
665 | return (size); |
---|
666 | } |
---|
667 | |
---|
668 | static int dag_start_input(libtrace_t *libtrace) { |
---|
669 | #if DAG_VERSION_2_4 |
---|
670 | if(dag_start(INPUT.fd) < 0) { |
---|
671 | trace_set_err(libtrace,errno,"Cannot start DAG %s", |
---|
672 | libtrace->uridata); |
---|
673 | return -1; |
---|
674 | } |
---|
675 | #else |
---|
676 | if (dag_attach_stream(INPUT.fd, DAG.dagstream, 0, 0) < 0) { |
---|
677 | trace_set_err(libtrace, errno, "Cannot attach DAG stream"); |
---|
678 | return -1; |
---|
679 | } |
---|
680 | if (dag_start_stream(INPUT.fd, DAG.dagstream) < 0) { |
---|
681 | trace_set_err(libtrace, errno, "Cannot start DAG stream"); |
---|
682 | return -1; |
---|
683 | } |
---|
684 | #endif |
---|
685 | /* dags appear to have a bug where if you call dag_start after |
---|
686 | * calling dag_stop, and at least one packet has arrived, bad things |
---|
687 | * happen. flush the memory hole |
---|
688 | */ |
---|
689 | while(dag_read(libtrace,1)!=0) |
---|
690 | DAG.diff=0; |
---|
691 | return 0; |
---|
692 | } |
---|
693 | #endif |
---|
694 | |
---|
695 | static int erf_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { |
---|
696 | int numbytes; |
---|
697 | int size; |
---|
698 | void *buffer2 = packet->buffer; |
---|
699 | int rlen; |
---|
700 | |
---|
701 | if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { |
---|
702 | packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); |
---|
703 | packet->buf_control = TRACE_CTRL_PACKET; |
---|
704 | if (!packet->buffer) { |
---|
705 | trace_set_err(libtrace, errno, |
---|
706 | "Cannot allocate memory"); |
---|
707 | return -1; |
---|
708 | } |
---|
709 | } |
---|
710 | |
---|
711 | |
---|
712 | |
---|
713 | packet->header = packet->buffer; |
---|
714 | packet->type = RT_DATA_ERF; |
---|
715 | |
---|
716 | if ((numbytes=libtrace_io_read(INPUT.file, |
---|
717 | packet->buffer, |
---|
718 | dag_record_size)) == -1) { |
---|
719 | trace_set_err(libtrace,errno,"read(%s)", |
---|
720 | libtrace->uridata); |
---|
721 | return -1; |
---|
722 | } |
---|
723 | if (numbytes == 0) { |
---|
724 | return 0; |
---|
725 | } |
---|
726 | |
---|
727 | rlen = ntohs(((dag_record_t *)packet->buffer)->rlen); |
---|
728 | buffer2 = (char*)packet->buffer + dag_record_size; |
---|
729 | size = rlen - dag_record_size; |
---|
730 | |
---|
731 | assert(size < LIBTRACE_PACKET_BUFSIZE && size >= dag_record_size); |
---|
732 | |
---|
733 | /* Unknown/corrupt */ |
---|
734 | assert(((dag_record_t *)packet->buffer)->type < 10); |
---|
735 | |
---|
736 | /* read in the rest of the packet */ |
---|
737 | if ((numbytes=libtrace_io_read(INPUT.file, |
---|
738 | buffer2, |
---|
739 | size)) != size) { |
---|
740 | if (numbytes==-1) { |
---|
741 | trace_set_err(libtrace,errno, "read(%s)", libtrace->uridata); |
---|
742 | return -1; |
---|
743 | } |
---|
744 | trace_set_err(libtrace,EIO,"Truncated packet (wanted %d, got %d)", size, numbytes); |
---|
745 | /* Failed to read the full packet? must be EOF */ |
---|
746 | return -1; |
---|
747 | } |
---|
748 | if (((dag_record_t *)packet->buffer)->flags.rxerror == 1) { |
---|
749 | packet->payload = NULL; |
---|
750 | } else { |
---|
751 | packet->payload = (char*)packet->buffer + erf_get_framing_length(packet); |
---|
752 | } |
---|
753 | return rlen; |
---|
754 | } |
---|
755 | |
---|
756 | static int rtclient_read(libtrace_t *libtrace, void *buffer, size_t len) { |
---|
757 | int numbytes; |
---|
758 | |
---|
759 | while(1) { |
---|
760 | #ifndef MSG_NOSIGNAL |
---|
761 | # define MSG_NOSIGNAL 0 |
---|
762 | #endif |
---|
763 | if ((numbytes = recv(INPUT.fd, |
---|
764 | buffer, |
---|
765 | len, |
---|
766 | MSG_NOSIGNAL)) == -1) { |
---|
767 | if (errno == EINTR) { |
---|
768 | /*ignore EINTR in case |
---|
769 | *a caller is using signals |
---|
770 | */ |
---|
771 | continue; |
---|
772 | } |
---|
773 | trace_set_err(libtrace,errno,"recv(%s)", |
---|
774 | libtrace->uridata); |
---|
775 | return -1; |
---|
776 | } |
---|
777 | break; |
---|
778 | |
---|
779 | } |
---|
780 | return numbytes; |
---|
781 | } |
---|
782 | |
---|
783 | static int rtclient_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { |
---|
784 | int numbytes = 0; |
---|
785 | char buf[RP_BUFSIZE]; |
---|
786 | int read_required = 0; |
---|
787 | |
---|
788 | void *buffer = 0; |
---|
789 | |
---|
790 | if (packet->buf_control == TRACE_CTRL_EXTERNAL || !packet->buffer) { |
---|
791 | packet->buf_control = TRACE_CTRL_PACKET; |
---|
792 | packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE); |
---|
793 | } |
---|
794 | |
---|
795 | buffer = packet->buffer; |
---|
796 | packet->header = packet->buffer; |
---|
797 | |
---|
798 | packet->type = RT_DATA_ERF; |
---|
799 | |
---|
800 | |
---|
801 | do { |
---|
802 | libtrace_packet_status_t status; |
---|
803 | int size; |
---|
804 | if (tracefifo_out_available(libtrace->fifo) == 0 |
---|
805 | || read_required) { |
---|
806 | if ((numbytes = rtclient_read( |
---|
807 | libtrace,buf,RP_BUFSIZE))<=0) { |
---|
808 | return numbytes; |
---|
809 | } |
---|
810 | tracefifo_write(libtrace->fifo,buf,numbytes); |
---|
811 | read_required = 0; |
---|
812 | } |
---|
813 | /* Read status byte */ |
---|
814 | if (tracefifo_out_read(libtrace->fifo, |
---|
815 | &status, sizeof(uint32_t)) == 0) { |
---|
816 | read_required = 1; |
---|
817 | continue; |
---|
818 | } |
---|
819 | tracefifo_out_update(libtrace->fifo,sizeof(uint32_t)); |
---|
820 | /* Read in packet size */ |
---|
821 | if (tracefifo_out_read(libtrace->fifo, |
---|
822 | &size, sizeof(uint32_t)) == 0) { |
---|
823 | tracefifo_out_reset(libtrace->fifo); |
---|
824 | read_required = 1; |
---|
825 | continue; |
---|
826 | } |
---|
827 | tracefifo_out_update(libtrace->fifo, sizeof(uint32_t)); |
---|
828 | |
---|
829 | if (status.type == 2 /* RT_MSG */) { |
---|
830 | /* Need to skip this packet as it is a message packet */ |
---|
831 | tracefifo_out_update(libtrace->fifo, size); |
---|
832 | tracefifo_ack_update(libtrace->fifo, size + |
---|
833 | sizeof(uint32_t) + |
---|
834 | sizeof(libtrace_packet_status_t)); |
---|
835 | continue; |
---|
836 | } |
---|
837 | |
---|
838 | /* read in the full packet */ |
---|
839 | if ((numbytes = tracefifo_out_read(libtrace->fifo, |
---|
840 | buffer, size)) == 0) { |
---|
841 | tracefifo_out_reset(libtrace->fifo); |
---|
842 | read_required = 1; |
---|
843 | continue; |
---|
844 | } |
---|
845 | |
---|
846 | /* got in our whole packet, so... */ |
---|
847 | tracefifo_out_update(libtrace->fifo,size); |
---|
848 | |
---|
849 | tracefifo_ack_update(libtrace->fifo,size + |
---|
850 | sizeof(uint32_t) + |
---|
851 | sizeof(libtrace_packet_status_t)); |
---|
852 | |
---|
853 | if (((dag_record_t *)buffer)->flags.rxerror == 1) { |
---|
854 | packet->payload = NULL; |
---|
855 | } else { |
---|
856 | packet->payload = (char*)packet->buffer + erf_get_framing_length(packet); |
---|
857 | } |
---|
858 | return numbytes; |
---|
859 | } while(1); |
---|
860 | } |
---|
861 | |
---|
862 | static int erf_dump_packet(libtrace_out_t *libtrace, |
---|
863 | dag_record_t *erfptr, int pad, void *buffer, size_t size) { |
---|
864 | int numbytes = 0; |
---|
865 | assert(size<=65536); |
---|
866 | |
---|
867 | if ((numbytes = libtrace_io_write(OUTPUT.file, erfptr, dag_record_size + pad)) != dag_record_size+pad) { |
---|
868 | trace_set_err_out(libtrace,errno, |
---|
869 | "write(%s)",libtrace->uridata); |
---|
870 | return -1; |
---|
871 | } |
---|
872 | |
---|
873 | if ((numbytes=libtrace_io_write(OUTPUT.file, buffer, size)) != (int)size) { |
---|
874 | trace_set_err_out(libtrace,errno, |
---|
875 | "write(%s)",libtrace->uridata); |
---|
876 | return -1; |
---|
877 | } |
---|
878 | |
---|
879 | return numbytes + pad + dag_record_size; |
---|
880 | } |
---|
881 | |
---|
882 | static int erf_start_output(libtrace_out_t *libtrace) |
---|
883 | { |
---|
884 | OUTPUT.file = trace_open_file_out(libtrace, |
---|
885 | OPTIONS.erf.level, |
---|
886 | OPTIONS.erf.fileflag); |
---|
887 | if (!OUTPUT.file) { |
---|
888 | return -1; |
---|
889 | } |
---|
890 | return 0; |
---|
891 | } |
---|
892 | |
---|
893 | static int erf_write_packet(libtrace_out_t *libtrace, |
---|
894 | const libtrace_packet_t *packet) |
---|
895 | { |
---|
896 | int numbytes = 0; |
---|
897 | int pad = 0; |
---|
898 | dag_record_t *dag_hdr = (dag_record_t *)packet->header; |
---|
899 | void *payload = packet->payload; |
---|
900 | |
---|
901 | assert(OUTPUT.file); |
---|
902 | |
---|
903 | if (!packet->header) { |
---|
904 | /*trace_set_err_output(libtrace, TRACE_ERR_BAD_PACKET, |
---|
905 | "Packet has no header - probably an RT packet"); |
---|
906 | */ |
---|
907 | return -1; |
---|
908 | } |
---|
909 | |
---|
910 | pad = erf_get_padding(packet); |
---|
911 | |
---|
912 | /* If we've had an rxerror, we have no payload to write - fix |
---|
913 | * rlen to be the correct length |
---|
914 | */ |
---|
915 | /* I Think this is bogus -- Perry */ |
---|
916 | if (payload == NULL) { |
---|
917 | dag_hdr->rlen = htons(dag_record_size + pad); |
---|
918 | } |
---|
919 | |
---|
920 | if (packet->trace->format == &erf |
---|
921 | #if HAVE_DAG |
---|
922 | || packet->trace->format == &dag |
---|
923 | #endif |
---|
924 | ) { |
---|
925 | numbytes = erf_dump_packet(libtrace, |
---|
926 | (dag_record_t *)packet->header, |
---|
927 | pad, |
---|
928 | payload, |
---|
929 | trace_get_capture_length(packet) |
---|
930 | ); |
---|
931 | } else { |
---|
932 | dag_record_t erfhdr; |
---|
933 | int type; |
---|
934 | /* convert format - build up a new erf header */ |
---|
935 | /* Timestamp */ |
---|
936 | erfhdr.ts = trace_get_erf_timestamp(packet); |
---|
937 | type=libtrace_to_erf_type(trace_get_link_type(packet)); |
---|
938 | if (type==(char)-1) { |
---|
939 | trace_set_err_out(libtrace,TRACE_ERR_NO_CONVERSION, |
---|
940 | "No erf type for packet"); |
---|
941 | return -1; |
---|
942 | } |
---|
943 | erfhdr.type = type; |
---|
944 | /* Flags. Can't do this */ |
---|
945 | memset(&erfhdr.flags,1,sizeof(erfhdr.flags)); |
---|
946 | if (trace_get_direction(packet)!=-1) |
---|
947 | erfhdr.flags.iface = trace_get_direction(packet); |
---|
948 | /* Packet length (rlen includes format overhead) */ |
---|
949 | erfhdr.rlen = htons(trace_get_capture_length(packet) |
---|
950 | + erf_get_framing_length(packet)); |
---|
951 | /* loss counter. Can't do this */ |
---|
952 | erfhdr.lctr = 0; |
---|
953 | /* Wire length, may contain the padding */ |
---|
954 | erfhdr.wlen = htons(trace_get_wire_length(packet)+pad); |
---|
955 | |
---|
956 | /* Write it out */ |
---|
957 | numbytes = erf_dump_packet(libtrace, |
---|
958 | &erfhdr, |
---|
959 | pad, |
---|
960 | payload, |
---|
961 | trace_get_capture_length(packet)); |
---|
962 | } |
---|
963 | return numbytes; |
---|
964 | } |
---|
965 | |
---|
966 | static libtrace_linktype_t erf_get_link_type(const libtrace_packet_t *packet) { |
---|
967 | dag_record_t *erfptr = 0; |
---|
968 | erfptr = (dag_record_t *)packet->header; |
---|
969 | return erf_type_to_libtrace(erfptr->type); |
---|
970 | } |
---|
971 | |
---|
972 | static libtrace_direction_t erf_get_direction(const libtrace_packet_t *packet) { |
---|
973 | dag_record_t *erfptr = 0; |
---|
974 | erfptr = (dag_record_t *)packet->header; |
---|
975 | return erfptr->flags.iface; |
---|
976 | } |
---|
977 | |
---|
978 | static libtrace_direction_t erf_set_direction(libtrace_packet_t *packet, libtrace_direction_t direction) { |
---|
979 | dag_record_t *erfptr = 0; |
---|
980 | erfptr = (dag_record_t *)packet->header; |
---|
981 | erfptr->flags.iface = direction; |
---|
982 | return erfptr->flags.iface; |
---|
983 | } |
---|
984 | |
---|
985 | static uint64_t erf_get_erf_timestamp(const libtrace_packet_t *packet) { |
---|
986 | dag_record_t *erfptr = 0; |
---|
987 | erfptr = (dag_record_t *)packet->header; |
---|
988 | return erfptr->ts; |
---|
989 | } |
---|
990 | |
---|
991 | static int erf_get_capture_length(const libtrace_packet_t *packet) { |
---|
992 | dag_record_t *erfptr = 0; |
---|
993 | erfptr = (dag_record_t *)packet->header; |
---|
994 | return (ntohs(erfptr->rlen) - erf_get_framing_length(packet)); |
---|
995 | } |
---|
996 | |
---|
997 | static int erf_get_wire_length(const libtrace_packet_t *packet) { |
---|
998 | dag_record_t *erfptr = 0; |
---|
999 | erfptr = (dag_record_t *)packet->header; |
---|
1000 | return ntohs(erfptr->wlen) - erf_get_padding(packet); |
---|
1001 | } |
---|
1002 | |
---|
1003 | static size_t erf_set_capture_length(libtrace_packet_t *packet, size_t size) { |
---|
1004 | dag_record_t *erfptr = 0; |
---|
1005 | assert(packet); |
---|
1006 | if(size > trace_get_capture_length(packet)) { |
---|
1007 | /* can't make a packet larger */ |
---|
1008 | return trace_get_capture_length(packet); |
---|
1009 | } |
---|
1010 | erfptr = (dag_record_t *)packet->header; |
---|
1011 | erfptr->rlen = htons(size + erf_get_framing_length(packet)); |
---|
1012 | return trace_get_capture_length(packet); |
---|
1013 | } |
---|
1014 | |
---|
1015 | static int rtclient_get_fd(const libtrace_t *libtrace) { |
---|
1016 | return INPUT.fd; |
---|
1017 | } |
---|
1018 | |
---|
1019 | #ifdef HAVE_DAG |
---|
1020 | libtrace_eventobj_t trace_event_dag(libtrace_t *trace, libtrace_packet_t *packet) { |
---|
1021 | libtrace_eventobj_t event = {0,0,0.0,0}; |
---|
1022 | int dag_fd; |
---|
1023 | int data; |
---|
1024 | |
---|
1025 | if (trace->format->get_fd) { |
---|
1026 | dag_fd = trace->format->get_fd(trace); |
---|
1027 | } else { |
---|
1028 | dag_fd = 0; |
---|
1029 | } |
---|
1030 | |
---|
1031 | data = dag_read(trace, DAGF_NONBLOCK); |
---|
1032 | |
---|
1033 | if (data > 0) { |
---|
1034 | event.size = trace_read_packet(trace,packet); |
---|
1035 | event.type = TRACE_EVENT_PACKET; |
---|
1036 | return event; |
---|
1037 | } |
---|
1038 | event.type = TRACE_EVENT_SLEEP; |
---|
1039 | event.seconds = 0.0001; |
---|
1040 | return event; |
---|
1041 | } |
---|
1042 | #endif |
---|
1043 | |
---|
1044 | #if HAVE_DAG |
---|
1045 | static void dag_help() { |
---|
1046 | printf("dag format module: $Revision$\n"); |
---|
1047 | printf("Supported input URIs:\n"); |
---|
1048 | printf("\tdag:/dev/dagn\n"); |
---|
1049 | printf("\n"); |
---|
1050 | printf("\te.g.: dag:/dev/dag0\n"); |
---|
1051 | printf("\n"); |
---|
1052 | printf("Supported output URIs:\n"); |
---|
1053 | printf("\tnone\n"); |
---|
1054 | printf("\n"); |
---|
1055 | } |
---|
1056 | #endif |
---|
1057 | |
---|
1058 | static void erf_help() { |
---|
1059 | printf("erf format module: $Revision$\n"); |
---|
1060 | printf("Supported input URIs:\n"); |
---|
1061 | printf("\terf:/path/to/file\t(uncompressed)\n"); |
---|
1062 | printf("\terf:/path/to/file.gz\t(gzip-compressed)\n"); |
---|
1063 | printf("\terf:-\t(stdin, either compressed or not)\n"); |
---|
1064 | printf("\terf:/path/to/socket\n"); |
---|
1065 | printf("\n"); |
---|
1066 | printf("\te.g.: erf:/tmp/trace\n"); |
---|
1067 | printf("\n"); |
---|
1068 | printf("Supported output URIs:\n"); |
---|
1069 | printf("\terf:path/to/file\t(uncompressed)\n"); |
---|
1070 | printf("\terf:/path/to/file.gz\t(gzip-compressed)\n"); |
---|
1071 | printf("\terf:-\t(stdout, either compressed or not)\n"); |
---|
1072 | printf("\n"); |
---|
1073 | printf("\te.g.: erf:/tmp/trace\n"); |
---|
1074 | printf("\n"); |
---|
1075 | printf("Supported output options:\n"); |
---|
1076 | printf("\t-z\tSpecify the gzip compression, ranging from 0 (uncompressed) to 9 - defaults to 1\n"); |
---|
1077 | printf("\n"); |
---|
1078 | |
---|
1079 | |
---|
1080 | } |
---|
1081 | |
---|
1082 | static void rtclient_help() { |
---|
1083 | printf("rtclient format module: $Revision$\n"); |
---|
1084 | printf("DEPRECATED - use rt module instead\n"); |
---|
1085 | printf("Supported input URIs:\n"); |
---|
1086 | printf("\trtclient:host:port\n"); |
---|
1087 | printf("\n"); |
---|
1088 | printf("\te.g.:rtclient:localhost:3435\n"); |
---|
1089 | printf("\n"); |
---|
1090 | printf("Supported output URIs:\n"); |
---|
1091 | printf("\tnone\n"); |
---|
1092 | printf("\n"); |
---|
1093 | } |
---|
1094 | |
---|
1095 | static struct libtrace_format_t erf = { |
---|
1096 | "erf", |
---|
1097 | "$Id$", |
---|
1098 | TRACE_FORMAT_ERF, |
---|
1099 | erf_init_input, /* init_input */ |
---|
1100 | NULL, /* config_input */ |
---|
1101 | erf_start_input, /* start_input */ |
---|
1102 | NULL, /* pause_input */ |
---|
1103 | erf_init_output, /* init_output */ |
---|
1104 | erf_config_output, /* config_output */ |
---|
1105 | erf_start_output, /* start_output */ |
---|
1106 | erf_fin_input, /* fin_input */ |
---|
1107 | erf_fin_output, /* fin_output */ |
---|
1108 | erf_read_packet, /* read_packet */ |
---|
1109 | NULL, /* fin_packet */ |
---|
1110 | erf_write_packet, /* write_packet */ |
---|
1111 | erf_get_link_type, /* get_link_type */ |
---|
1112 | erf_get_direction, /* get_direction */ |
---|
1113 | erf_set_direction, /* set_direction */ |
---|
1114 | erf_get_erf_timestamp, /* get_erf_timestamp */ |
---|
1115 | NULL, /* get_timeval */ |
---|
1116 | NULL, /* get_seconds */ |
---|
1117 | erf_seek_erf, /* seek_erf */ |
---|
1118 | NULL, /* seek_timeval */ |
---|
1119 | NULL, /* seek_seconds */ |
---|
1120 | erf_get_capture_length, /* get_capture_length */ |
---|
1121 | erf_get_wire_length, /* get_wire_length */ |
---|
1122 | erf_get_framing_length, /* get_framing_length */ |
---|
1123 | erf_set_capture_length, /* set_capture_length */ |
---|
1124 | NULL, /* get_fd */ |
---|
1125 | trace_event_trace, /* trace_event */ |
---|
1126 | erf_help, /* help */ |
---|
1127 | NULL /* next pointer */ |
---|
1128 | }; |
---|
1129 | |
---|
1130 | #ifdef HAVE_DAG |
---|
1131 | static struct libtrace_format_t dag = { |
---|
1132 | "dag", |
---|
1133 | "$Id$", |
---|
1134 | TRACE_FORMAT_ERF, |
---|
1135 | dag_init_input, /* init_input */ |
---|
1136 | dag_config_input, /* config_input */ |
---|
1137 | dag_start_input, /* start_input */ |
---|
1138 | dag_pause_input, /* pause_input */ |
---|
1139 | NULL, /* init_output */ |
---|
1140 | NULL, /* config_output */ |
---|
1141 | NULL, /* start_output */ |
---|
1142 | dag_fin_input, /* fin_input */ |
---|
1143 | NULL, /* fin_output */ |
---|
1144 | dag_read_packet, /* read_packet */ |
---|
1145 | NULL, /* fin_packet */ |
---|
1146 | NULL, /* write_packet */ |
---|
1147 | erf_get_link_type, /* get_link_type */ |
---|
1148 | erf_get_direction, /* get_direction */ |
---|
1149 | erf_set_direction, /* set_direction */ |
---|
1150 | erf_get_erf_timestamp, /* get_erf_timestamp */ |
---|
1151 | NULL, /* get_timeval */ |
---|
1152 | NULL, /* get_seconds */ |
---|
1153 | NULL, /* seek_erf */ |
---|
1154 | NULL, /* seek_timeval */ |
---|
1155 | NULL, /* seek_seconds */ |
---|
1156 | erf_get_capture_length, /* get_capture_length */ |
---|
1157 | erf_get_wire_length, /* get_wire_length */ |
---|
1158 | erf_get_framing_length, /* get_framing_length */ |
---|
1159 | erf_set_capture_length, /* set_capture_length */ |
---|
1160 | NULL, /* get_fd */ |
---|
1161 | trace_event_dag, /* trace_event */ |
---|
1162 | dag_help, /* help */ |
---|
1163 | NULL /* next pointer */ |
---|
1164 | }; |
---|
1165 | #endif |
---|
1166 | |
---|
1167 | static struct libtrace_format_t rtclient = { |
---|
1168 | "rtclient", |
---|
1169 | "$Id$", |
---|
1170 | TRACE_FORMAT_ERF, |
---|
1171 | rtclient_init_input, /* init_input */ |
---|
1172 | NULL, /* config_input */ |
---|
1173 | rtclient_start_input, /* start_input */ |
---|
1174 | rtclient_pause_input, /* pause_input */ |
---|
1175 | NULL, /* init_output */ |
---|
1176 | NULL, /* config_output */ |
---|
1177 | NULL, /* start_output */ |
---|
1178 | rtclient_fin_input, /* fin_input */ |
---|
1179 | NULL, /* fin_output */ |
---|
1180 | rtclient_read_packet, /* read_packet */ |
---|
1181 | NULL, /* fin_packet */ |
---|
1182 | NULL, /* write_packet */ |
---|
1183 | erf_get_link_type, /* get_link_type */ |
---|
1184 | erf_get_direction, /* get_direction */ |
---|
1185 | erf_set_direction, /* set_direction */ |
---|
1186 | erf_get_erf_timestamp, /* get_erf_timestamp */ |
---|
1187 | NULL, /* get_timeval */ |
---|
1188 | NULL, /* get_seconds */ |
---|
1189 | NULL, /* seek_erf */ |
---|
1190 | NULL, /* seek_timeval */ |
---|
1191 | NULL, /* seek_seconds */ |
---|
1192 | erf_get_capture_length, /* get_capture_length */ |
---|
1193 | erf_get_wire_length, /* get_wire_length */ |
---|
1194 | erf_get_framing_length, /* get_framing_length */ |
---|
1195 | erf_set_capture_length, /* set_capture_length */ |
---|
1196 | rtclient_get_fd, /* get_fd */ |
---|
1197 | trace_event_device, /* trace_event */ |
---|
1198 | rtclient_help, /* help */ |
---|
1199 | NULL /* next pointer */ |
---|
1200 | }; |
---|
1201 | |
---|
1202 | void CONSTRUCTOR erf_constructor() { |
---|
1203 | register_format(&rtclient); |
---|
1204 | register_format(&erf); |
---|
1205 | #ifdef HAVE_DAG |
---|
1206 | register_format(&dag); |
---|
1207 | #endif |
---|
1208 | } |
---|