1 | /* |
---|
2 | * This file is part of libtrace |
---|
3 | * |
---|
4 | * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton, |
---|
5 | * New Zealand. |
---|
6 | * |
---|
7 | * Authors: Daniel Lawson |
---|
8 | * Perry Lorier |
---|
9 | * Shane Alcock |
---|
10 | * Richard Sanger |
---|
11 | * |
---|
12 | * All rights reserved. |
---|
13 | * |
---|
14 | * This code has been developed by the University of Waikato WAND |
---|
15 | * research group. For further information please see http://www.wand.net.nz/ |
---|
16 | * |
---|
17 | * libtrace is free software; you can redistribute it and/or modify |
---|
18 | * it under the terms of the GNU General Public License as published by |
---|
19 | * the Free Software Foundation; either version 2 of the License, or |
---|
20 | * (at your option) any later version. |
---|
21 | * |
---|
22 | * libtrace is distributed in the hope that it will be useful, |
---|
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
25 | * GNU General Public License for more details. |
---|
26 | * |
---|
27 | * You should have received a copy of the GNU General Public License |
---|
28 | * along with libtrace; if not, write to the Free Software |
---|
29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
30 | * |
---|
31 | * $Id$ |
---|
32 | * |
---|
33 | */ |
---|
34 | |
---|
35 | /* This format module deals with using the Linux Native capture format. |
---|
36 | * |
---|
37 | * Linux Native is a LIVE capture format. |
---|
38 | * |
---|
39 | * This format also supports writing which will write packets out to the |
---|
40 | * network as a form of packet replay. This should not be confused with the |
---|
41 | * RT protocol which is intended to transfer captured packet records between |
---|
42 | * RT-speaking programs. |
---|
43 | */ |
---|
44 | |
---|
45 | #include "config.h" |
---|
46 | #include "libtrace.h" |
---|
47 | #include "libtrace_int.h" |
---|
48 | #include "format_helper.h" |
---|
49 | #include "libtrace_arphrd.h" |
---|
50 | #include <stdlib.h> |
---|
51 | #include <errno.h> |
---|
52 | #include <unistd.h> |
---|
53 | #include <string.h> |
---|
54 | #include <assert.h> |
---|
55 | |
---|
56 | #ifdef HAVE_INTTYPES_H |
---|
57 | # include <inttypes.h> |
---|
58 | #else |
---|
59 | # error "Can't find inttypes.h" |
---|
60 | #endif |
---|
61 | |
---|
62 | #include "format_linux_common.h" |
---|
63 | |
---|
64 | |
---|
65 | #ifdef HAVE_NETPACKET_PACKET_H |
---|
66 | |
---|
67 | |
---|
68 | static int linuxnative_start_input(libtrace_t *libtrace) |
---|
69 | { |
---|
70 | int ret = linuxcommon_start_input_stream(libtrace, FORMAT_DATA_FIRST); |
---|
71 | return ret; |
---|
72 | } |
---|
73 | |
---|
74 | static int linuxnative_pstart_input(libtrace_t *libtrace) { |
---|
75 | return linuxcommon_pstart_input(libtrace, linuxcommon_start_input_stream); |
---|
76 | } |
---|
77 | |
---|
78 | static int linuxnative_start_output(libtrace_out_t *libtrace) |
---|
79 | { |
---|
80 | FORMAT_DATA_OUT->fd = socket(PF_PACKET, SOCK_RAW, 0); |
---|
81 | if (FORMAT_DATA_OUT->fd==-1) { |
---|
82 | free(FORMAT_DATA_OUT); |
---|
83 | trace_set_err_out(libtrace, errno, "Failed to create raw socket"); |
---|
84 | return -1; |
---|
85 | } |
---|
86 | |
---|
87 | return 0; |
---|
88 | } |
---|
89 | |
---|
90 | static int linuxnative_fin_output(libtrace_out_t *libtrace) |
---|
91 | { |
---|
92 | close(FORMAT_DATA_OUT->fd); |
---|
93 | FORMAT_DATA_OUT->fd=-1; |
---|
94 | free(libtrace->format_data); |
---|
95 | return 0; |
---|
96 | } |
---|
97 | #endif /* HAVE_NETPACKET_PACKET_H */ |
---|
98 | |
---|
99 | static int linuxnative_prepare_packet(libtrace_t *libtrace UNUSED, |
---|
100 | libtrace_packet_t *packet, void *buffer, |
---|
101 | libtrace_rt_types_t rt_type, uint32_t flags) { |
---|
102 | |
---|
103 | if (packet->buffer != buffer && |
---|
104 | packet->buf_control == TRACE_CTRL_PACKET) { |
---|
105 | free(packet->buffer); |
---|
106 | } |
---|
107 | |
---|
108 | if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { |
---|
109 | packet->buf_control = TRACE_CTRL_PACKET; |
---|
110 | } else |
---|
111 | packet->buf_control = TRACE_CTRL_EXTERNAL; |
---|
112 | |
---|
113 | |
---|
114 | packet->buffer = buffer; |
---|
115 | packet->header = buffer; |
---|
116 | packet->payload = (char *)buffer + |
---|
117 | sizeof(struct libtrace_linuxnative_header); |
---|
118 | packet->type = rt_type; |
---|
119 | |
---|
120 | /* |
---|
121 | if (libtrace->format_data == NULL) { |
---|
122 | if (linuxnative_init_input(libtrace)) |
---|
123 | return -1; |
---|
124 | } |
---|
125 | */ |
---|
126 | return 0; |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | #define LIBTRACE_MIN(a,b) ((a)<(b) ? (a) : (b)) |
---|
131 | |
---|
132 | /* 20 isn't enough on x86_64 */ |
---|
133 | #define CMSG_BUF_SIZE 128 |
---|
134 | |
---|
135 | #ifdef HAVE_NETPACKET_PACKET_H |
---|
136 | inline static int linuxnative_read_stream(libtrace_t *libtrace, |
---|
137 | libtrace_packet_t *packet, |
---|
138 | struct linux_per_stream_t *stream, |
---|
139 | libtrace_message_queue_t *queue) |
---|
140 | { |
---|
141 | struct libtrace_linuxnative_header *hdr; |
---|
142 | struct msghdr msghdr; |
---|
143 | struct iovec iovec; |
---|
144 | unsigned char controlbuf[CMSG_BUF_SIZE]; |
---|
145 | struct cmsghdr *cmsg; |
---|
146 | int snaplen; |
---|
147 | |
---|
148 | uint32_t flags = 0; |
---|
149 | fd_set readfds; |
---|
150 | struct timeval tout; |
---|
151 | int ret; |
---|
152 | |
---|
153 | if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { |
---|
154 | packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE); |
---|
155 | if (!packet->buffer) { |
---|
156 | perror("Cannot allocate buffer"); |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | flags |= TRACE_PREP_OWN_BUFFER; |
---|
161 | |
---|
162 | packet->type = TRACE_RT_DATA_LINUX_NATIVE; |
---|
163 | |
---|
164 | hdr=(struct libtrace_linuxnative_header*)packet->buffer; |
---|
165 | snaplen=LIBTRACE_MIN( |
---|
166 | (int)LIBTRACE_PACKET_BUFSIZE-(int)sizeof(*hdr), |
---|
167 | (int)FORMAT_DATA->snaplen); |
---|
168 | /* Prepare the msghdr and iovec for the kernel to write the |
---|
169 | * captured packet into. The msghdr will point to the part of our |
---|
170 | * buffer reserved for sll header, while the iovec will point at |
---|
171 | * the buffer following the sll header. */ |
---|
172 | |
---|
173 | msghdr.msg_name = &hdr->hdr; |
---|
174 | msghdr.msg_namelen = sizeof(struct sockaddr_ll); |
---|
175 | |
---|
176 | msghdr.msg_iov = &iovec; |
---|
177 | msghdr.msg_iovlen = 1; |
---|
178 | |
---|
179 | msghdr.msg_control = &controlbuf; |
---|
180 | msghdr.msg_controllen = CMSG_BUF_SIZE; |
---|
181 | msghdr.msg_flags = 0; |
---|
182 | |
---|
183 | iovec.iov_base = (void*)(packet->buffer+sizeof(*hdr)); |
---|
184 | iovec.iov_len = snaplen; |
---|
185 | |
---|
186 | // Check for a packet - TODO only Linux has MSG_DONTWAIT should use fctl O_NONBLOCK |
---|
187 | /* Try check ahead this should be fast if something is waiting */ |
---|
188 | hdr->wirelen = recvmsg(stream->fd, &msghdr, MSG_DONTWAIT | MSG_TRUNC); |
---|
189 | |
---|
190 | /* No data was waiting */ |
---|
191 | if ((int) hdr->wirelen == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) { |
---|
192 | /* Do message queue check or select */ |
---|
193 | int message_fd; |
---|
194 | int largestfd = stream->fd; |
---|
195 | |
---|
196 | /* Also check the message queue */ |
---|
197 | if (queue) { |
---|
198 | message_fd = libtrace_message_queue_get_fd(queue); |
---|
199 | if (message_fd > largestfd) |
---|
200 | largestfd = message_fd; |
---|
201 | } |
---|
202 | do { |
---|
203 | /* Use select to allow us to time out occasionally to check if someone |
---|
204 | * has hit Ctrl-C or otherwise wants us to stop reading and return |
---|
205 | * so they can exit their program. |
---|
206 | */ |
---|
207 | tout.tv_sec = 0; |
---|
208 | tout.tv_usec = 500000; |
---|
209 | /* Make sure we reset these each loop */ |
---|
210 | FD_ZERO(&readfds); |
---|
211 | FD_SET(stream->fd, &readfds); |
---|
212 | if (queue) |
---|
213 | FD_SET(message_fd, &readfds); |
---|
214 | |
---|
215 | ret = select(largestfd+1, &readfds, NULL, NULL, &tout); |
---|
216 | if (ret >= 1) { |
---|
217 | /* A file descriptor triggered */ |
---|
218 | break; |
---|
219 | } else if (ret < 0 && errno != EINTR) { |
---|
220 | trace_set_err(libtrace, errno, "select"); |
---|
221 | return -1; |
---|
222 | } else { |
---|
223 | if (libtrace_halt) |
---|
224 | return READ_EOF; |
---|
225 | } |
---|
226 | } |
---|
227 | while (ret <= 0); |
---|
228 | |
---|
229 | /* Message waiting? */ |
---|
230 | if (queue && FD_ISSET(message_fd, &readfds)) |
---|
231 | return READ_MESSAGE; |
---|
232 | |
---|
233 | /* We must have a packet */ |
---|
234 | hdr->wirelen = recvmsg(stream->fd, &msghdr, MSG_TRUNC); |
---|
235 | } |
---|
236 | |
---|
237 | if (hdr->wirelen==~0U) { |
---|
238 | trace_set_err(libtrace,errno,"recvmsg"); |
---|
239 | return -1; |
---|
240 | } |
---|
241 | |
---|
242 | hdr->caplen=LIBTRACE_MIN((unsigned int)snaplen,(unsigned int)hdr->wirelen); |
---|
243 | |
---|
244 | /* Extract the timestamps from the msghdr and store them in our |
---|
245 | * linux native encapsulation, so that we can preserve the formatting |
---|
246 | * across multiple architectures */ |
---|
247 | |
---|
248 | for (cmsg = CMSG_FIRSTHDR(&msghdr); |
---|
249 | cmsg != NULL; |
---|
250 | cmsg = CMSG_NXTHDR(&msghdr, cmsg)) { |
---|
251 | if (cmsg->cmsg_level == SOL_SOCKET |
---|
252 | && cmsg->cmsg_type == SO_TIMESTAMP |
---|
253 | && cmsg->cmsg_len <= CMSG_LEN(sizeof(struct timeval))) { |
---|
254 | |
---|
255 | struct timeval *tv; |
---|
256 | tv = (struct timeval *)CMSG_DATA(cmsg); |
---|
257 | |
---|
258 | |
---|
259 | hdr->tv.tv_sec = tv->tv_sec; |
---|
260 | hdr->tv.tv_usec = tv->tv_usec; |
---|
261 | hdr->timestamptype = TS_TIMEVAL; |
---|
262 | break; |
---|
263 | } |
---|
264 | #ifdef SO_TIMESTAMPNS |
---|
265 | else if (cmsg->cmsg_level == SOL_SOCKET |
---|
266 | && cmsg->cmsg_type == SO_TIMESTAMPNS |
---|
267 | && cmsg->cmsg_len <= CMSG_LEN(sizeof(struct timespec))) { |
---|
268 | |
---|
269 | struct timespec *tv; |
---|
270 | tv = (struct timespec *)CMSG_DATA(cmsg); |
---|
271 | |
---|
272 | hdr->ts.tv_sec = tv->tv_sec; |
---|
273 | hdr->ts.tv_nsec = tv->tv_nsec; |
---|
274 | hdr->timestamptype = TS_TIMESPEC; |
---|
275 | break; |
---|
276 | } |
---|
277 | #endif |
---|
278 | } |
---|
279 | |
---|
280 | /* Did we not get given a timestamp? Try to get one from the |
---|
281 | * file descriptor directly */ |
---|
282 | if (cmsg == NULL) { |
---|
283 | struct timeval tv; |
---|
284 | if (ioctl(stream->fd, SIOCGSTAMP,&tv)==0) { |
---|
285 | hdr->tv.tv_sec = tv.tv_sec; |
---|
286 | hdr->tv.tv_usec = tv.tv_usec; |
---|
287 | hdr->timestamptype = TS_TIMEVAL; |
---|
288 | } |
---|
289 | else { |
---|
290 | hdr->timestamptype = TS_NONE; |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | /* Buffer contains all of our packet (including our custom header) so |
---|
295 | * we just need to get prepare_packet to set all our packet pointers |
---|
296 | * appropriately */ |
---|
297 | packet->trace = libtrace; |
---|
298 | if (linuxnative_prepare_packet(libtrace, packet, packet->buffer, |
---|
299 | packet->type, flags)) |
---|
300 | return -1; |
---|
301 | |
---|
302 | return hdr->wirelen+sizeof(*hdr); |
---|
303 | } |
---|
304 | |
---|
305 | static int linuxnative_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) |
---|
306 | { |
---|
307 | return linuxnative_read_stream(libtrace, packet, FORMAT_DATA_FIRST, NULL); |
---|
308 | } |
---|
309 | |
---|
310 | static int linuxnative_pread_packets(libtrace_t *libtrace, |
---|
311 | libtrace_thread_t *t, |
---|
312 | libtrace_packet_t *packets[], |
---|
313 | UNUSED size_t nb_packets) { |
---|
314 | /* For now just read one packet */ |
---|
315 | packets[0]->error = linuxnative_read_stream(libtrace, packets[0], |
---|
316 | t->format_data, &t->messages); |
---|
317 | if (packets[0]->error >= 1) |
---|
318 | return 1; |
---|
319 | else |
---|
320 | return packets[0]->error; |
---|
321 | } |
---|
322 | |
---|
323 | static int linuxnative_write_packet(libtrace_out_t *libtrace, |
---|
324 | libtrace_packet_t *packet) |
---|
325 | { |
---|
326 | struct sockaddr_ll hdr; |
---|
327 | int ret = 0; |
---|
328 | |
---|
329 | if (trace_get_link_type(packet) == TRACE_TYPE_NONDATA) |
---|
330 | return 0; |
---|
331 | |
---|
332 | hdr.sll_family = AF_PACKET; |
---|
333 | hdr.sll_protocol = 0; |
---|
334 | hdr.sll_ifindex = if_nametoindex(libtrace->uridata); |
---|
335 | hdr.sll_hatype = 0; |
---|
336 | hdr.sll_pkttype = 0; |
---|
337 | hdr.sll_halen = htons(6); /* FIXME */ |
---|
338 | memcpy(hdr.sll_addr,packet->payload,(size_t)ntohs(hdr.sll_halen)); |
---|
339 | |
---|
340 | /* This is pretty easy, just send the payload using sendto() (after |
---|
341 | * setting up the sll header properly, of course) */ |
---|
342 | ret = sendto(FORMAT_DATA_OUT->fd, |
---|
343 | packet->payload, |
---|
344 | trace_get_capture_length(packet), |
---|
345 | 0, |
---|
346 | (struct sockaddr*)&hdr, (socklen_t)sizeof(hdr)); |
---|
347 | |
---|
348 | if (ret < 0) { |
---|
349 | trace_set_err_out(libtrace, errno, "sendto failed"); |
---|
350 | } |
---|
351 | |
---|
352 | return ret; |
---|
353 | } |
---|
354 | #endif /* HAVE_NETPACKET_PACKET_H */ |
---|
355 | |
---|
356 | |
---|
357 | static libtrace_linktype_t linuxnative_get_link_type(const struct libtrace_packet_t *packet) { |
---|
358 | uint16_t linktype=(((struct libtrace_linuxnative_header*)(packet->buffer)) |
---|
359 | ->hdr.sll_hatype); |
---|
360 | return linuxcommon_get_link_type(linktype); |
---|
361 | } |
---|
362 | |
---|
363 | static libtrace_direction_t linuxnative_get_direction(const struct libtrace_packet_t *packet) { |
---|
364 | return linuxcommon_get_direction(((struct libtrace_linuxnative_header*)(packet->buffer))->hdr.sll_pkttype); |
---|
365 | } |
---|
366 | |
---|
367 | static libtrace_direction_t linuxnative_set_direction( |
---|
368 | libtrace_packet_t *packet, |
---|
369 | libtrace_direction_t direction) { |
---|
370 | return linuxcommon_set_direction(&((struct libtrace_linuxnative_header*)(packet->buffer))->hdr, direction); |
---|
371 | } |
---|
372 | |
---|
373 | static struct timespec linuxnative_get_timespec(const libtrace_packet_t *packet) |
---|
374 | { |
---|
375 | struct libtrace_linuxnative_header *hdr = |
---|
376 | (struct libtrace_linuxnative_header*) packet->buffer; |
---|
377 | /* We have to upconvert from timeval to timespec */ |
---|
378 | if (hdr->timestamptype == TS_TIMEVAL) { |
---|
379 | struct timespec ts; |
---|
380 | ts.tv_sec = hdr->tv.tv_sec; |
---|
381 | ts.tv_nsec = hdr->tv.tv_usec*1000; |
---|
382 | return ts; |
---|
383 | } |
---|
384 | else { |
---|
385 | struct timespec ts; |
---|
386 | ts.tv_sec = hdr->ts.tv_sec; |
---|
387 | ts.tv_nsec = hdr->ts.tv_nsec; |
---|
388 | return ts; |
---|
389 | } |
---|
390 | } |
---|
391 | |
---|
392 | static struct timeval linuxnative_get_timeval(const libtrace_packet_t *packet) |
---|
393 | { |
---|
394 | struct libtrace_linuxnative_header *hdr = |
---|
395 | (struct libtrace_linuxnative_header*) packet->buffer; |
---|
396 | /* We have to downconvert from timespec to timeval */ |
---|
397 | if (hdr->timestamptype == TS_TIMESPEC) { |
---|
398 | struct timeval tv; |
---|
399 | tv.tv_sec = hdr->ts.tv_sec; |
---|
400 | tv.tv_usec = hdr->ts.tv_nsec/1000; |
---|
401 | return tv; |
---|
402 | } |
---|
403 | else { |
---|
404 | struct timeval tv; |
---|
405 | tv.tv_sec = hdr->tv.tv_sec; |
---|
406 | tv.tv_usec = hdr->tv.tv_usec; |
---|
407 | return tv; |
---|
408 | } |
---|
409 | } |
---|
410 | |
---|
411 | static int linuxnative_get_capture_length(const libtrace_packet_t *packet) |
---|
412 | { |
---|
413 | return ((struct libtrace_linuxnative_header*)(packet->buffer))->caplen; |
---|
414 | } |
---|
415 | |
---|
416 | |
---|
417 | static int linuxnative_get_wire_length(const libtrace_packet_t *packet) |
---|
418 | { |
---|
419 | |
---|
420 | int wirelen = ((struct libtrace_linuxnative_header*)(packet->buffer))->wirelen; |
---|
421 | |
---|
422 | /* Include the missing FCS */ |
---|
423 | if (trace_get_link_type(packet) == TRACE_TYPE_ETH) |
---|
424 | wirelen += 4; |
---|
425 | |
---|
426 | return wirelen; |
---|
427 | } |
---|
428 | |
---|
429 | |
---|
430 | static int linuxnative_get_framing_length(UNUSED |
---|
431 | const libtrace_packet_t *packet) |
---|
432 | { |
---|
433 | return sizeof(struct libtrace_linuxnative_header); |
---|
434 | } |
---|
435 | |
---|
436 | static size_t linuxnative_set_capture_length(libtrace_packet_t *packet, |
---|
437 | size_t size) { |
---|
438 | |
---|
439 | struct libtrace_linuxnative_header *linux_hdr = NULL; |
---|
440 | assert(packet); |
---|
441 | if (size > trace_get_capture_length(packet)) { |
---|
442 | /* We should avoid making a packet larger */ |
---|
443 | return trace_get_capture_length(packet); |
---|
444 | } |
---|
445 | |
---|
446 | /* Reset the cached capture length */ |
---|
447 | packet->capture_length = -1; |
---|
448 | |
---|
449 | linux_hdr = (struct libtrace_linuxnative_header *)packet->header; |
---|
450 | linux_hdr->caplen = size; |
---|
451 | return trace_get_capture_length(packet); |
---|
452 | } |
---|
453 | |
---|
454 | #ifdef HAVE_NETPACKET_PACKET_H |
---|
455 | static void linuxnative_help(void) { |
---|
456 | printf("linuxnative format module: $Revision: 1793 $\n"); |
---|
457 | printf("Supported input URIs:\n"); |
---|
458 | printf("\tint:eth0\n"); |
---|
459 | printf("\n"); |
---|
460 | printf("Supported output URIs:\n"); |
---|
461 | printf("\tint:eth0\n"); |
---|
462 | printf("\n"); |
---|
463 | return; |
---|
464 | } |
---|
465 | |
---|
466 | static struct libtrace_format_t linuxnative = { |
---|
467 | "int", |
---|
468 | "$Id$", |
---|
469 | TRACE_FORMAT_LINUX_NATIVE, |
---|
470 | linuxcommon_probe_filename, /* probe filename */ |
---|
471 | NULL, /* probe magic */ |
---|
472 | linuxcommon_init_input, /* init_input */ |
---|
473 | linuxcommon_config_input, /* config_input */ |
---|
474 | linuxnative_start_input, /* start_input */ |
---|
475 | linuxcommon_pause_input, /* pause_input */ |
---|
476 | linuxcommon_init_output, /* init_output */ |
---|
477 | NULL, /* config_output */ |
---|
478 | linuxnative_start_output, /* start_ouput */ |
---|
479 | linuxcommon_fin_input, /* fin_input */ |
---|
480 | linuxnative_fin_output, /* fin_output */ |
---|
481 | linuxnative_read_packet, /* read_packet */ |
---|
482 | linuxnative_prepare_packet, /* prepare_packet */ |
---|
483 | NULL, /* fin_packet */ |
---|
484 | linuxnative_write_packet, /* write_packet */ |
---|
485 | linuxnative_get_link_type, /* get_link_type */ |
---|
486 | linuxnative_get_direction, /* get_direction */ |
---|
487 | linuxnative_set_direction, /* set_direction */ |
---|
488 | NULL, /* get_erf_timestamp */ |
---|
489 | linuxnative_get_timeval, /* get_timeval */ |
---|
490 | linuxnative_get_timespec, /* get_timespec */ |
---|
491 | NULL, /* get_seconds */ |
---|
492 | NULL, /* seek_erf */ |
---|
493 | NULL, /* seek_timeval */ |
---|
494 | NULL, /* seek_seconds */ |
---|
495 | linuxnative_get_capture_length, /* get_capture_length */ |
---|
496 | linuxnative_get_wire_length, /* get_wire_length */ |
---|
497 | linuxnative_get_framing_length, /* get_framing_length */ |
---|
498 | linuxnative_set_capture_length, /* set_capture_length */ |
---|
499 | NULL, /* get_received_packets */ |
---|
500 | NULL, /* get_filtered_packets */ |
---|
501 | NULL, /* get_dropped_packets */ |
---|
502 | linuxcommon_get_statistics, /* get_statistics */ |
---|
503 | linuxcommon_get_fd, /* get_fd */ |
---|
504 | trace_event_device, /* trace_event */ |
---|
505 | linuxnative_help, /* help */ |
---|
506 | NULL, /* next pointer */ |
---|
507 | #ifdef HAVE_PACKET_FANOUT |
---|
508 | {true, -1}, /* Live, no thread limit */ |
---|
509 | linuxnative_pstart_input, /* pstart_input */ |
---|
510 | linuxnative_pread_packets, /* pread_packets */ |
---|
511 | linuxcommon_pause_input, /* ppause */ |
---|
512 | linuxcommon_fin_input, /* p_fin */ |
---|
513 | linuxcommon_pregister_thread, /* register thread */ |
---|
514 | NULL, /* unregister thread */ |
---|
515 | NULL /* get thread stats */ |
---|
516 | #else |
---|
517 | NON_PARALLEL(true) |
---|
518 | #endif |
---|
519 | }; |
---|
520 | #else |
---|
521 | static void linuxnative_help(void) { |
---|
522 | printf("linuxnative format module: $Revision: 1793 $\n"); |
---|
523 | printf("Not supported on this host\n"); |
---|
524 | } |
---|
525 | |
---|
526 | static struct libtrace_format_t linuxnative = { |
---|
527 | "int", |
---|
528 | "$Id$", |
---|
529 | TRACE_FORMAT_LINUX_NATIVE, |
---|
530 | NULL, /* probe filename */ |
---|
531 | NULL, /* probe magic */ |
---|
532 | NULL, /* init_input */ |
---|
533 | NULL, /* config_input */ |
---|
534 | NULL, /* start_input */ |
---|
535 | NULL, /* pause_input */ |
---|
536 | NULL, /* init_output */ |
---|
537 | NULL, /* config_output */ |
---|
538 | NULL, /* start_ouput */ |
---|
539 | NULL, /* fin_input */ |
---|
540 | NULL, /* fin_output */ |
---|
541 | NULL, /* read_packet */ |
---|
542 | linuxnative_prepare_packet, /* prepare_packet */ |
---|
543 | NULL, /* fin_packet */ |
---|
544 | NULL, /* write_packet */ |
---|
545 | linuxnative_get_link_type, /* get_link_type */ |
---|
546 | linuxnative_get_direction, /* get_direction */ |
---|
547 | linuxnative_set_direction, /* set_direction */ |
---|
548 | NULL, /* get_erf_timestamp */ |
---|
549 | linuxnative_get_timeval, /* get_timeval */ |
---|
550 | linuxnative_get_timespec, /* get_timespec */ |
---|
551 | NULL, /* get_seconds */ |
---|
552 | NULL, /* seek_erf */ |
---|
553 | NULL, /* seek_timeval */ |
---|
554 | NULL, /* seek_seconds */ |
---|
555 | linuxnative_get_capture_length, /* get_capture_length */ |
---|
556 | linuxnative_get_wire_length, /* get_wire_length */ |
---|
557 | linuxnative_get_framing_length, /* get_framing_length */ |
---|
558 | linuxnative_set_capture_length, /* set_capture_length */ |
---|
559 | NULL, /* get_received_packets */ |
---|
560 | NULL, /* get_filtered_packets */ |
---|
561 | NULL, /* get_dropped_packets */ |
---|
562 | linuxcommon_get_statistics, /* get_statistics */ |
---|
563 | NULL, /* get_fd */ |
---|
564 | NULL, /* trace_event */ |
---|
565 | linuxnative_help, /* help */ |
---|
566 | NULL, /* next pointer */ |
---|
567 | NON_PARALLEL(true) |
---|
568 | }; |
---|
569 | #endif /* HAVE_NETPACKET_PACKET_H */ |
---|
570 | |
---|
571 | void linuxnative_constructor(void) { |
---|
572 | register_format(&linuxnative); |
---|
573 | } |
---|