source: lib/format_bpf.c @ 418c78d

develop
Last change on this file since 418c78d was 418c78d, checked in by Shane Alcock <salcock@…>, 23 months ago

Add TRACE_OPTION_CONSTANT_ERF_FRAMING into remaining formats.

These formats are conditionally built, so I had missed them when
I first added this option. All formats simply report that the
option is "unsupported".

Note: technically the DAG formats *could* make use of the option
to try and save some processing overhead per packet -- we should
consider adding proper support for the option to format_dag25 at
least.

  • Property mode set to 100644
File size: 20.5 KB
Line 
1/*
2 *
3 * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand.
4 * All rights reserved.
5 *
6 * This file is part of libtrace.
7 *
8 * This code has been developed by the University of Waikato WAND
9 * research group. For further information please see http://www.wand.net.nz/
10 *
11 * libtrace is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * libtrace is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 *
25 */
26#include "libtrace.h"
27#include "libtrace_int.h"
28#include "format_helper.h"
29#include "config.h"
30#include "stdlib.h"
31
32#ifdef HAVE_INTTYPES_H
33#  include <inttypes.h>
34#else
35# error "Can't find inttypes.h"
36#endif
37
38#include <sys/socket.h>
39
40#include <sys/types.h>
41#include <sys/time.h>
42#include <sys/ioctl.h>
43
44#include <string.h>
45#include <net/if.h>
46#include <sys/ioctl.h>
47#include <errno.h>
48#include <fcntl.h>
49#include <unistd.h>
50
51/* This format deals with the BSD Native capture format, perhaps better
52 * known as BPF, which is the equivalent of the Linux Native format for
53 * *BSD systems.
54 *
55 * This is a LIVE capture format - we're always dealing with reading from an
56 * interface.
57 *
58 * This format does not support writing, but BPF packet records can be easily
59 * converted to PCAP or ERF.
60 */ 
61
62struct lt_bpf_timeval {
63        uint32_t tv_sec;
64        uint32_t tv_usec;
65};
66
67struct libtrace_bpf_hdr {
68        struct lt_bpf_timeval bh_tstamp;        /* timestamp */
69        uint32_t bh_caplen;             /* capture length */
70        uint32_t bh_datalen;            /* wire length */
71        uint16_t bh_hdrlen;             /* header length (incl padding) */
72};
73
74#ifndef BPF_TIMEVAL
75#define BPF_TIMEVAL timeval
76#endif
77
78struct local_bpf_hdr {
79        struct BPF_TIMEVAL bh_tstamp;
80        uint32_t bh_caplen;
81        uint32_t bh_datalen;
82        uint16_t bh_hdrlen;
83};
84
85#define BPFHDR(x) ((struct libtrace_bpf_hdr *)((x)->header))
86
87#if HAVE_DECL_BIOCSETIF
88/* "Global" data that is stored for each BPF input trace */
89struct libtrace_format_data_t {
90        /* The file descriptor that is being captured from */
91        int fd; 
92        /* The snap length for the capture */
93        int snaplen;
94        /* A boolean flag indicating whether the capture interface should be
95         * in promiscuous mode */ 
96        int promisc;
97        /* A buffer to write captured data into */
98        void *buffer;
99        /* The current read location in the capture buffer */
100        void *bufptr;
101        /* The total size of the capture buffer */
102        unsigned int buffersize;
103        /* The amount of space remaining before the capture buffer is full */
104        int remaining;
105        /* The linktype of the capture interface */ 
106        unsigned int linktype;
107        /* Statistics about how many packets have been dropped, received etc. */
108        struct bpf_stat stats;
109        /* A boolean flag indicating whether the statistics are up-to-date */
110        int stats_valid;
111        /* Bucket data structure for safely storing buffers of packets */
112        libtrace_bucket_t *bucket;
113};
114
115#define FORMATIN(x) ((struct libtrace_format_data_t*)((x->format_data)))
116
117
118/* Attempts to determine if a given filename could refer to a BPF interface */
119static int bpf_probe_filename(const char *filename)
120{
121        return (if_nametoindex(filename) != 0);
122}
123
124/* Initialises a BPF input trace */
125static int bpf_init_input(libtrace_t *libtrace) {
126        libtrace->format_data = (struct libtrace_format_data_t *)
127                malloc(sizeof(struct libtrace_format_data_t));
128
129        if (!libtrace->format_data) {
130                trace_set_err(libtrace, TRACE_ERR_INIT_FAILED, "Unable to allocate memory "
131                        "for format data inside bpf_init_input()");
132                return -1;
133        }
134
135        /* Throw some default values into the format data */
136        FORMATIN(libtrace)->fd = -1;
137        FORMATIN(libtrace)->promisc = 0;
138        FORMATIN(libtrace)->snaplen = 65536;
139        FORMATIN(libtrace)->stats_valid = 0;
140        FORMATIN(libtrace)->bucket = libtrace_bucket_init();
141
142        return 0;
143}
144
145/* Starts a BPF input trace */
146static int bpf_start_input(libtrace_t *libtrace)
147{
148        int bpfid=0;
149        struct bpf_version bv;
150        struct ifreq ifr;
151        unsigned int v;
152
153        /* Find and open a bpf device */
154        do {
155                char buffer[64];
156                snprintf(buffer,sizeof(buffer),"/dev/bpf%d", bpfid);
157                bpfid++;
158               
159                FORMATIN(libtrace)->fd = open(buffer, O_RDONLY);
160        } while(FORMATIN(libtrace)->fd == -1 && errno == EBUSY);
161
162        if (FORMATIN(libtrace)->fd == -1) {
163                trace_set_err(libtrace,TRACE_ERR_INIT_FAILED,
164                                "No free bpf devices");
165                return -1;
166        }
167
168        /* Check the BPF Version is ok */
169        if (ioctl(FORMATIN(libtrace)->fd, BIOCVERSION, &bv) == -1) {
170                trace_set_err(libtrace,errno,
171                                "Failed to read the bpf version");
172                close(FORMATIN(libtrace)->fd);
173                return -1;
174        }
175
176        if (bv.bv_major != BPF_MAJOR_VERSION) {
177                trace_set_err(libtrace,errno, 
178                        "Unknown kernel BPF version (%d.%d, libtrace requires at least %d.%d)",
179                        bv.bv_major,
180                        bv.bv_minor,
181                        BPF_MAJOR_VERSION,
182                        BPF_MINOR_VERSION);
183                close(FORMATIN(libtrace)->fd);
184                return -1;
185        }
186
187        if (bv.bv_minor < BPF_MINOR_VERSION) {
188                trace_set_err(libtrace,errno, "Kernel version too old (%d.%d, libtrace requires at least %d.%d)",
189                        bv.bv_major,
190                        bv.bv_minor,
191                        BPF_MAJOR_VERSION,
192                        BPF_MINOR_VERSION);
193                close(FORMATIN(libtrace)->fd);
194                return -1;
195        }
196
197        /* We assume the default kernel buffer size is sufficient. */
198        if (ioctl(FORMATIN(libtrace)->fd, BIOCGBLEN,
199                        &FORMATIN(libtrace)->buffersize)==-1) {
200                trace_set_err(libtrace,errno,"Failed to find buffer length");
201                close(FORMATIN(libtrace)->fd);
202                return -1;
203        }
204
205        FORMATIN(libtrace)->buffer = NULL;
206        FORMATIN(libtrace)->bufptr = NULL;
207        FORMATIN(libtrace)->remaining = 0;
208
209        /* Attach to the device */
210        strncpy(ifr.ifr_name, libtrace->uridata, sizeof(ifr.ifr_name));
211        if (ioctl(FORMATIN(libtrace)->fd, BIOCSETIF, &ifr) == -1) {
212                trace_set_err(libtrace,errno,"Failed to attach");
213                close(FORMATIN(libtrace)->fd);
214                return -1;
215        }
216
217        /* Set the link type */
218        if (ioctl(FORMATIN(libtrace)->fd, BIOCGDLT,
219                         &FORMATIN(libtrace)->linktype) == -1) {
220                trace_set_err(libtrace,errno,"Failed to retrieve link type");
221                close(FORMATIN(libtrace)->fd);
222                return -1;
223        }
224       
225        /* TODO: If BIOCGDLTLIST exists then we should perhaps do something
226         *       with it.  We don't have the same concept of multiple DLT's
227         *       as pcap does.  We grab the rawest possible thing and then
228         *       decode packets by understanding the protocols.  So perhaps
229         *       we should setup a rating of DLT's that we'll prefer in order.
230         *       For example we should try and get 802.11 frames rather than
231         *       802.3 frames.  The general rule should be "whatever actually
232         *       went over the air", although of course if we don't support
233         *       what went over the air we should fall back to something we
234         *       /do/ support.
235         */
236       
237        /* Using timeouts seems sucky.  We'll always use immediate mode.  We
238         * pray the kernel is smart enough that if a another packet arrives
239         * while we're processing this one that it will buffer them into it's
240         * kernel buffer so we can receive packets later. (It'll need to do this
241         * to deal with us spending time processing the last 'n' packets anyway)
242         */
243       
244        v=1;
245        if (ioctl(FORMATIN(libtrace)->fd, BIOCIMMEDIATE, &v) == -1) {
246                trace_set_err(libtrace,errno,"Failed to set immediate mode");
247                close(FORMATIN(libtrace)->fd);
248                return -1;
249        }
250
251        /* Set promiscous mode, if the user has asked us to do so */
252        if (FORMATIN(libtrace)->promisc) {
253                if (ioctl(FORMATIN(libtrace)->fd, BIOCPROMISC, NULL) == -1) {
254                        trace_set_err(libtrace,errno,
255                                "Failed to set promisc mode");
256                        close(FORMATIN(libtrace)->fd);
257                        return -1;
258
259                }
260        }
261
262        FORMATIN(libtrace)->stats_valid = 0;
263
264        /* TODO: we should always set a bpf filter for snapping */
265
266        /* We're done! */
267        return 0;
268}
269
270/* Gets a count of the number of packets received on the BPF interface */
271static uint64_t bpf_get_received_packets(libtrace_t *trace)
272{
273        if (trace->format_data == NULL)
274                return (uint64_t)-1;
275
276        if (FORMATIN(trace)->fd == -1) {
277                /* Almost certainly a 'dead' trace so there is no socket
278                 * for us to query */
279                return (uint64_t) -1;
280        }
281        /* If we're called with stats_valid == 0, or we're called again
282         * then refresh the stats.  Don't refresh the stats if we're called
283         * immediately after get_dropped_packets
284         */
285        if ((FORMATIN(trace)->stats_valid & 1)
286                || (FORMATIN(trace)->stats_valid == 0)) {
287                ioctl(FORMATIN(trace)->fd, BIOCGSTATS, &FORMATIN(trace)->stats);
288                FORMATIN(trace)->stats_valid |= 1;
289        }
290
291        return FORMATIN(trace)->stats.bs_recv;
292}
293
294/* Gets a count of the number of packets dropped on the BPF interface */
295static uint64_t bpf_get_dropped_packets(libtrace_t *trace)
296{
297        if (trace->format_data == NULL)
298                return (uint64_t)-1;
299
300        if (FORMATIN(trace)->fd == -1) {
301                /* Almost certainly a 'dead' trace so there is no socket
302                 * for us to query */
303                return (uint64_t) -1;
304        }
305        /* If we're called with stats_valid == 0, or we're called again
306         * then refresh the stats.  Don't refresh the stats if we're called
307         * immediately after get_received_packets
308         */
309        if ((FORMATIN(trace)->stats_valid & 2) 
310                || (FORMATIN(trace)->stats_valid == 0)) {
311                ioctl(FORMATIN(trace)->fd, BIOCGSTATS, &FORMATIN(trace)->stats);
312                FORMATIN(trace)->stats_valid |= 2;
313        }
314
315        return FORMATIN(trace)->stats.bs_drop;
316}
317
318static void bpf_get_statistics(libtrace_t *trace, libtrace_stat_t *stat) {
319        uint64_t dropped = bpf_get_dropped_packets(trace);
320        uint64_t received = bpf_get_received_packets(trace);
321
322        if (dropped != (uint64_t)-1) {
323                stat->dropped_valid = 1;
324                stat->dropped = dropped;
325        }
326
327        if (received != (uint64_t) -1) {
328                stat->received_valid = 1;
329                stat->received = received;
330        }
331
332}
333
334/* Pauses a BPF input trace */
335static int bpf_pause_input(libtrace_t *libtrace)
336{
337        close(FORMATIN(libtrace)->fd);
338        FORMATIN(libtrace)->fd=-1;
339
340        return 0;
341}
342
343/* Closes a BPF input trace */
344static int bpf_fin_input(libtrace_t *libtrace) 
345{
346        libtrace_bucket_destroy(FORMATIN(libtrace)->bucket);
347        free(libtrace->format_data);
348        return 0;
349}
350
351/* Configures a BPF input trace */
352static int bpf_config_input(libtrace_t *libtrace,
353                trace_option_t option,
354                void *data)
355{
356        switch(option) {
357                case TRACE_OPTION_SNAPLEN:
358                        FORMATIN(libtrace)->snaplen=*(int*)data;
359                        return 0;
360                case TRACE_OPTION_PROMISC:
361                        FORMATIN(libtrace)->promisc=*(int*)data;
362                        return 0;
363                case TRACE_OPTION_FILTER:
364                        /* We don't support bpf filters in any special way
365                         * so return an error and let libtrace deal with
366                         * emulating it
367                         */
368                        break;
369                case TRACE_OPTION_META_FREQ:
370                        /* No meta-data for this format */
371                        break;
372                case TRACE_OPTION_EVENT_REALTIME:
373                        /* Captures are always realtime */
374                        break;
375                case TRACE_OPTION_HASHER:
376                        /* TODO investigate hashing in BSD? */
377                        break;
378                case TRACE_OPTION_REPLAY_SPEEDUP:
379                        break;
380                case TRACE_OPTION_CONSTANT_ERF_FRAMING:
381                        break;
382                /* Avoid default: so that future options will cause a warning
383                 * here to remind us to implement it, or flag it as
384                 * unimplementable
385                 */
386        }
387        return -1;
388}
389
390#endif  /* HAVE_DECL_BIOCSETIF */
391
392/* Converts a buffer containing a recently read BPF packet record into a
393 * libtrace packet */
394static int bpf_prepare_packet(libtrace_t *libtrace UNUSED, 
395                libtrace_packet_t *packet,
396                void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) {
397       
398        struct local_bpf_hdr orig;
399        struct local_bpf_hdr *ptr;
400        struct libtrace_bpf_hdr *replace;
401
402        /* If the packet previously owned a buffer that is not the buffer
403         * that contains the new packet data, we're going to need to free the
404         * old one to avoid memory leaks */
405        if (packet->buffer != buffer &&
406                        packet->buf_control == TRACE_CTRL_PACKET) {
407                free(packet->buffer);
408        }
409
410        /* Set the buffer owner appropriately */
411        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
412                packet->buf_control = TRACE_CTRL_PACKET;
413        } else
414                packet->buf_control = TRACE_CTRL_EXTERNAL;
415
416        /* Update the packet pointers and type appropriately */
417        packet->buffer = buffer;
418        packet->header = buffer;
419        packet->type = rt_type;
420
421        /* FreeBSD is stupid and uses a timeval in the bpf header
422         * structure. This means that sometimes our timestamp consumes
423         * 8 bytes and sometimes it consumes 16 bytes.
424         *
425         * Let's try to standardise our header a bit, hopefully without
426         * overwriting anything else important */
427
428        if (sizeof(struct BPF_TIMEVAL) != sizeof(struct lt_bpf_timeval)) {     
429               
430                ptr = ((struct local_bpf_hdr *)(packet->header));
431                replace = ((struct libtrace_bpf_hdr *)(packet->header));
432                memcpy(&orig, ptr, sizeof(struct local_bpf_hdr));
433
434                replace->bh_tstamp.tv_sec = (uint32_t) (orig.bh_tstamp.tv_sec & 0xffffffff);
435                replace->bh_tstamp.tv_usec = (uint32_t) (orig.bh_tstamp.tv_usec & 0xffffffff);
436                replace->bh_caplen = orig.bh_caplen;
437                replace->bh_datalen = orig.bh_datalen;
438                replace->bh_hdrlen = orig.bh_hdrlen;
439
440
441        }
442
443        /* Find the payload */
444        /* TODO: Pcap deals with a padded FDDI linktype here */
445        packet->payload=(char *)buffer + BPFHDR(packet)->bh_hdrlen;
446
447        return 0;
448}
449
450#if HAVE_DECL_BIOCSETIF
451
452/* Reads the next packet record from a BPF interface and writes it into a
453 * libtrace packet */   
454static int bpf_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) 
455{
456        uint32_t flags = 0;
457        fd_set readfds;
458        struct timeval tout;
459        int ret;
460
461        packet->type = bpf_linktype_to_rt(FORMATIN(libtrace)->linktype);
462
463        if (FORMATIN(libtrace)->remaining <= 0) {
464                FORMATIN(libtrace)->buffer = malloc(FORMATIN(libtrace)->buffersize);
465                libtrace_create_new_bucket(FORMATIN(libtrace)->bucket, FORMATIN(libtrace)->buffer);
466        }
467
468        while (FORMATIN(libtrace)->remaining <= 0) {
469
470                tout.tv_sec = 0;
471                tout.tv_usec = 500000;
472                FD_ZERO(&readfds);
473                FD_SET(FORMATIN(libtrace)->fd, &readfds);
474
475                ret = select(FORMATIN(libtrace)->fd + 1, &readfds, NULL,
476                                NULL, &tout);
477                if (ret < 0 && errno != EINTR) {
478                        trace_set_err(libtrace, errno, "select");
479                        return -1;
480                } else if (ret < 0) {
481                        continue;
482                }
483
484                if (FD_ISSET(FORMATIN(libtrace)->fd, &readfds)) {
485                        /* Packets are available, read into buffer */
486                        ret=read(FORMATIN(libtrace)->fd,
487                                FORMATIN(libtrace)->buffer,
488                                FORMATIN(libtrace)->buffersize);
489
490                        if (ret == -1) {
491                                trace_set_err(libtrace,errno,"Failed to read");
492                                return -1;
493                        }
494
495                        if (ret == 0) {
496                                /* EOF */
497                                return 0;
498                        }
499
500                        FORMATIN(libtrace)->remaining=ret;
501                        FORMATIN(libtrace)->bufptr=
502                                        FORMATIN(libtrace)->buffer;
503                        break;
504                }
505
506                /* Timed out -- check if we should halt */
507                if ((ret=is_halted(libtrace)) != -1)
508                        return ret;
509        }
510       
511        /* We do NOT want anything trying to free the memory the packet is
512         * stored in */
513        flags |= TRACE_PREP_DO_NOT_OWN_BUFFER;
514
515        if (packet->buffer && packet->buf_control == TRACE_CTRL_PACKET)
516                free(packet->buffer);
517
518        /* Update 'packet' to point to the first packet in our capture
519         * buffer */
520        if (bpf_prepare_packet(libtrace, packet, FORMATIN(libtrace)->bufptr,
521                        packet->type, flags)) {
522                return -1;
523        }
524
525        packet->internalid = libtrace_push_into_bucket(FORMATIN(libtrace)->bucket);
526        packet->srcbucket = FORMATIN(libtrace)->bucket;
527
528        /* Skip past the packet record we're going to return, making sure
529         * that we deal with padding correctly */
530        FORMATIN(libtrace)->bufptr+=
531                BPF_WORDALIGN(BPFHDR(packet)->bh_hdrlen
532                +BPFHDR(packet)->bh_caplen);
533        FORMATIN(libtrace)->remaining-=
534                BPF_WORDALIGN(BPFHDR(packet)->bh_hdrlen
535                +BPFHDR(packet)->bh_caplen);
536
537        return BPFHDR(packet)->bh_datalen+BPFHDR(packet)->bh_hdrlen;
538}
539
540#endif  /* HAVE_DECL_BIOCSETIF */
541
542/* Returns the linktype for the interface that we are capturing from */
543static libtrace_linktype_t bpf_get_link_type(const libtrace_packet_t *packet) {
544        /* Convert the linktype that we recorded when we started the trace
545         * into a suitable libtrace linktype */
546        return pcap_linktype_to_libtrace(rt_to_pcap_linktype(packet->type));
547}
548
549/* Returns the direction for a given BPF packet record */
550static libtrace_direction_t bpf_get_direction(const libtrace_packet_t *packet UNUSED) {
551        /* BPF sadly can't do direction tagging */
552        return ~0;
553}
554
555/* Returns the timestamp for a given BPF packet record, in the form of a
556 * struct timeval */
557static struct timeval bpf_get_timeval(const libtrace_packet_t *packet) 
558{
559        struct timeval tv;
560        /* OpenBSD uses a bpf_timeval rather than a timeval so we must copy
561         * each timeval element individually rather than doing a structure
562         * assignment */
563        tv.tv_sec = BPFHDR(packet)->bh_tstamp.tv_sec;
564        tv.tv_usec = BPFHDR(packet)->bh_tstamp.tv_usec;
565
566        return tv;
567}
568
569/* Returns the capture length for a given BPF packet record */
570static int bpf_get_capture_length(const libtrace_packet_t *packet)
571{
572        /* BPF doesn't include the FCS in its caplen field, but libtrace
573         * does so we need to add this extra 4 bytes */
574        return BPFHDR(packet)->bh_caplen+4;
575}
576
577/* Returns the wire length for a given BPF packet record */
578static int bpf_get_wire_length(const libtrace_packet_t *packet) 
579{
580
581        /* BPF doesn't include the FCS in its datalen field, but libtrace
582         * does so we need to add this extra 4 bytes */
583        return BPFHDR(packet)->bh_datalen+4;
584}
585
586/* Returns the framing length for a given BPF packet record */
587static int bpf_get_framing_length(UNUSED
588                const libtrace_packet_t *packet) 
589{
590        return BPFHDR(packet)->bh_hdrlen;
591}
592
593#if HAVE_DECL_BIOCSETIF
594/* Returns the file descriptor that the capture interface is operating on */
595static int bpf_get_fd(const libtrace_t *trace) {
596        return FORMATIN(trace)->fd;
597}
598
599/* Prints some slightly useful help text for the BPF capture format */
600static void bpf_help() {
601        printf("bpf format module: $Revision: 1782 $\n");
602        printf("Supported input URIs:\n");
603        printf("\tbpf:\n");
604        printf("\n");
605        return;
606}
607static struct libtrace_format_t bpf = {
608        "bpf",
609        "$Id$",
610        TRACE_FORMAT_BPF,
611        bpf_probe_filename,     /* probe filename */
612        NULL,                   /* probe magic */
613        bpf_init_input,         /* init_input */
614        bpf_config_input,       /* config_input */
615        bpf_start_input,        /* start_input */
616        bpf_pause_input,        /* pause_input */
617        NULL,                   /* init_output */
618        NULL,                   /* config_output */
619        NULL,                   /* start_ouput */
620        bpf_fin_input,          /* fin_input */
621        NULL,                   /* fin_output */
622        bpf_read_packet,        /* read_packet */
623        bpf_prepare_packet,     /* prepare_packet */
624        NULL,                   /* fin_packet */
625        NULL,                   /* write_packet */
626        NULL,                   /* flush_output */
627        bpf_get_link_type,      /* get_link_type */
628        bpf_get_direction,      /* get_direction */
629        NULL,                   /* set_direction */
630        NULL,                   /* get_erf_timestamp */
631        bpf_get_timeval,        /* get_timeval */
632        NULL,                   /* get_timespec */
633        NULL,                   /* get_seconds */
634        NULL,                   /* seek_erf */
635        NULL,                   /* seek_timeval */
636        NULL,                   /* seek_seconds */
637        bpf_get_capture_length, /* get_capture_length */
638        bpf_get_wire_length,    /* get_wire_length */
639        bpf_get_framing_length, /* get_framing_length */
640        NULL,                   /* set_capture_length */
641        NULL,                   /* get_received_packets */
642        NULL,                   /* get_filtered_packets */
643        NULL,                   /* get_dropped_packets */
644        bpf_get_statistics,     /* get_statistics */
645        bpf_get_fd,             /* get_fd */
646        trace_event_device,     /* trace_event */
647        bpf_help,               /* help */
648        NULL,                   /* next pointer */
649        NON_PARALLEL(true)
650};
651#else   /* HAVE_DECL_BIOCSETIF */
652/* Prints some slightly useful help text for the BPF capture format */
653static void bpf_help() {
654        printf("bpf format module: $Revision: 1782 $\n");
655        printf("Not supported on this host\n");
656        return;
657}
658static struct libtrace_format_t bpf = {
659        "bpf",
660        "$Id$",
661        TRACE_FORMAT_BPF,
662        NULL,                   /* probe filename */
663        NULL,                   /* probe magic */
664        NULL,                   /* init_input */
665        NULL,                   /* config_input */
666        NULL,                   /* start_input */
667        NULL,                   /* pause_input */
668        NULL,                   /* init_output */
669        NULL,                   /* config_output */
670        NULL,                   /* start_ouput */
671        NULL,                   /* fin_input */
672        NULL,                   /* fin_output */
673        NULL,                   /* read_packet */
674        bpf_prepare_packet,     /* prepare_packet */
675        NULL,                   /* fin_packet */
676        NULL,                   /* write_packet */
677        NULL,                   /* flush_output */
678        bpf_get_link_type,      /* get_link_type */
679        bpf_get_direction,      /* get_direction */
680        NULL,                   /* set_direction */
681        NULL,                   /* get_erf_timestamp */
682        bpf_get_timeval,        /* get_timeval */
683        NULL,                   /* get_timespec */
684        NULL,                   /* get_seconds */
685        NULL,                   /* seek_erf */
686        NULL,                   /* seek_timeval */
687        NULL,                   /* seek_seconds */
688        bpf_get_capture_length, /* get_capture_length */
689        bpf_get_wire_length,    /* get_wire_length */
690        bpf_get_framing_length, /* get_framing_length */
691        NULL,                   /* set_capture_length */
692        NULL,                   /* get_received_packets */
693        NULL,                   /* get_filtered_packets */
694        NULL,                   /* get_dropped_packets */
695        NULL,                   /* get_statistics */
696        NULL,                   /* get_fd */
697        NULL,                   /* trace_event */
698        bpf_help,               /* help */
699        NULL,                   /* next pointer */
700        NON_PARALLEL(true)
701};
702#endif  /* HAVE_DECL_BIOCSETIF */
703
704void bpf_constructor() {
705        register_format(&bpf);
706}
Note: See TracBrowser for help on using the repository browser.