source: lib/format_bpf.c @ 2193905

develop
Last change on this file since 2193905 was 2193905, checked in by Jacob Van Walraven <jcv9@…>, 2 years ago

Apply changes required for pull request #81

  • 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                /* Avoid default: so that future options will cause a warning
381                 * here to remind us to implement it, or flag it as
382                 * unimplementable
383                 */
384        }
385        return -1;
386}
387
388#endif  /* HAVE_DECL_BIOCSETIF */
389
390/* Converts a buffer containing a recently read BPF packet record into a
391 * libtrace packet */
392static int bpf_prepare_packet(libtrace_t *libtrace UNUSED, 
393                libtrace_packet_t *packet,
394                void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) {
395       
396        struct local_bpf_hdr orig;
397        struct local_bpf_hdr *ptr;
398        struct libtrace_bpf_hdr *replace;
399
400        /* If the packet previously owned a buffer that is not the buffer
401         * that contains the new packet data, we're going to need to free the
402         * old one to avoid memory leaks */
403        if (packet->buffer != buffer &&
404                        packet->buf_control == TRACE_CTRL_PACKET) {
405                free(packet->buffer);
406        }
407
408        /* Set the buffer owner appropriately */
409        if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) {
410                packet->buf_control = TRACE_CTRL_PACKET;
411        } else
412                packet->buf_control = TRACE_CTRL_EXTERNAL;
413
414        /* Update the packet pointers and type appropriately */
415        packet->buffer = buffer;
416        packet->header = buffer;
417        packet->type = rt_type;
418
419        /* FreeBSD is stupid and uses a timeval in the bpf header
420         * structure. This means that sometimes our timestamp consumes
421         * 8 bytes and sometimes it consumes 16 bytes.
422         *
423         * Let's try to standardise our header a bit, hopefully without
424         * overwriting anything else important */
425
426        if (sizeof(struct BPF_TIMEVAL) != sizeof(struct lt_bpf_timeval)) {     
427               
428                ptr = ((struct local_bpf_hdr *)(packet->header));
429                replace = ((struct libtrace_bpf_hdr *)(packet->header));
430                memcpy(&orig, ptr, sizeof(struct local_bpf_hdr));
431
432                replace->bh_tstamp.tv_sec = (uint32_t) (orig.bh_tstamp.tv_sec & 0xffffffff);
433                replace->bh_tstamp.tv_usec = (uint32_t) (orig.bh_tstamp.tv_usec & 0xffffffff);
434                replace->bh_caplen = orig.bh_caplen;
435                replace->bh_datalen = orig.bh_datalen;
436                replace->bh_hdrlen = orig.bh_hdrlen;
437
438
439        }
440
441        /* Find the payload */
442        /* TODO: Pcap deals with a padded FDDI linktype here */
443        packet->payload=(char *)buffer + BPFHDR(packet)->bh_hdrlen;
444
445        return 0;
446}
447
448#if HAVE_DECL_BIOCSETIF
449
450/* Reads the next packet record from a BPF interface and writes it into a
451 * libtrace packet */   
452static int bpf_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) 
453{
454        uint32_t flags = 0;
455        fd_set readfds;
456        struct timeval tout;
457        int ret;
458
459        packet->type = bpf_linktype_to_rt(FORMATIN(libtrace)->linktype);
460
461        if (FORMATIN(libtrace)->remaining <= 0) {
462                FORMATIN(libtrace)->buffer = malloc(FORMATIN(libtrace)->buffersize);
463                libtrace_create_new_bucket(FORMATIN(libtrace)->bucket, FORMATIN(libtrace)->buffer);
464        }
465
466        while (FORMATIN(libtrace)->remaining <= 0) {
467
468                tout.tv_sec = 0;
469                tout.tv_usec = 500000;
470                FD_ZERO(&readfds);
471                FD_SET(FORMATIN(libtrace)->fd, &readfds);
472
473                ret = select(FORMATIN(libtrace)->fd + 1, &readfds, NULL,
474                                NULL, &tout);
475                if (ret < 0 && errno != EINTR) {
476                        trace_set_err(libtrace, errno, "select");
477                        return -1;
478                } else if (ret < 0) {
479                        continue;
480                }
481
482                if (FD_ISSET(FORMATIN(libtrace)->fd, &readfds)) {
483                        /* Packets are available, read into buffer */
484                        ret=read(FORMATIN(libtrace)->fd,
485                                FORMATIN(libtrace)->buffer,
486                                FORMATIN(libtrace)->buffersize);
487
488                        if (ret == -1) {
489                                trace_set_err(libtrace,errno,"Failed to read");
490                                return -1;
491                        }
492
493                        if (ret == 0) {
494                                /* EOF */
495                                return 0;
496                        }
497
498                        FORMATIN(libtrace)->remaining=ret;
499                        FORMATIN(libtrace)->bufptr=
500                                        FORMATIN(libtrace)->buffer;
501                        break;
502                }
503
504                /* Timed out -- check if we should halt */
505                if ((ret=is_halted(libtrace)) != -1)
506                        return ret;
507        }
508       
509        /* We do NOT want anything trying to free the memory the packet is
510         * stored in */
511        flags |= TRACE_PREP_DO_NOT_OWN_BUFFER;
512
513        if (packet->buffer && packet->buf_control == TRACE_CTRL_PACKET)
514                free(packet->buffer);
515
516        /* Update 'packet' to point to the first packet in our capture
517         * buffer */
518        if (bpf_prepare_packet(libtrace, packet, FORMATIN(libtrace)->bufptr,
519                        packet->type, flags)) {
520                return -1;
521        }
522
523        packet->internalid = libtrace_push_into_bucket(FORMATIN(libtrace)->bucket);
524        packet->srcbucket = FORMATIN(libtrace)->bucket;
525
526        /* Skip past the packet record we're going to return, making sure
527         * that we deal with padding correctly */
528        FORMATIN(libtrace)->bufptr+=
529                BPF_WORDALIGN(BPFHDR(packet)->bh_hdrlen
530                +BPFHDR(packet)->bh_caplen);
531        FORMATIN(libtrace)->remaining-=
532                BPF_WORDALIGN(BPFHDR(packet)->bh_hdrlen
533                +BPFHDR(packet)->bh_caplen);
534
535        return BPFHDR(packet)->bh_datalen+BPFHDR(packet)->bh_hdrlen;
536}
537
538#endif  /* HAVE_DECL_BIOCSETIF */
539
540/* Returns the linktype for the interface that we are capturing from */
541static libtrace_linktype_t bpf_get_link_type(const libtrace_packet_t *packet) {
542        /* Convert the linktype that we recorded when we started the trace
543         * into a suitable libtrace linktype */
544        return pcap_linktype_to_libtrace(rt_to_pcap_linktype(packet->type));
545}
546
547/* Returns the direction for a given BPF packet record */
548static libtrace_direction_t bpf_get_direction(const libtrace_packet_t *packet UNUSED) {
549        /* BPF sadly can't do direction tagging */
550        return ~0;
551}
552
553/* Returns the timestamp for a given BPF packet record, in the form of a
554 * struct timeval */
555static struct timeval bpf_get_timeval(const libtrace_packet_t *packet) 
556{
557        struct timeval tv;
558        /* OpenBSD uses a bpf_timeval rather than a timeval so we must copy
559         * each timeval element individually rather than doing a structure
560         * assignment */
561        tv.tv_sec = BPFHDR(packet)->bh_tstamp.tv_sec;
562        tv.tv_usec = BPFHDR(packet)->bh_tstamp.tv_usec;
563
564        return tv;
565}
566
567/* Returns the capture length for a given BPF packet record */
568static int bpf_get_capture_length(const libtrace_packet_t *packet)
569{
570        /* BPF doesn't include the FCS in its caplen field, but libtrace
571         * does so we need to add this extra 4 bytes */
572        return BPFHDR(packet)->bh_caplen+4;
573}
574
575/* Returns the wire length for a given BPF packet record */
576static int bpf_get_wire_length(const libtrace_packet_t *packet) 
577{
578
579        /* BPF doesn't include the FCS in its datalen field, but libtrace
580         * does so we need to add this extra 4 bytes */
581        return BPFHDR(packet)->bh_datalen+4;
582}
583
584/* Returns the framing length for a given BPF packet record */
585static int bpf_get_framing_length(UNUSED
586                const libtrace_packet_t *packet) 
587{
588        return BPFHDR(packet)->bh_hdrlen;
589}
590
591#if HAVE_DECL_BIOCSETIF
592/* Returns the file descriptor that the capture interface is operating on */
593static int bpf_get_fd(const libtrace_t *trace) {
594        return FORMATIN(trace)->fd;
595}
596
597/* Prints some slightly useful help text for the BPF capture format */
598static void bpf_help() {
599        printf("bpf format module: $Revision: 1782 $\n");
600        printf("Supported input URIs:\n");
601        printf("\tbpf:\n");
602        printf("\n");
603        return;
604}
605static struct libtrace_format_t bpf = {
606        "bpf",
607        "$Id$",
608        TRACE_FORMAT_BPF,
609        bpf_probe_filename,     /* probe filename */
610        NULL,                   /* probe magic */
611        bpf_init_input,         /* init_input */
612        bpf_config_input,       /* config_input */
613        bpf_start_input,        /* start_input */
614        bpf_pause_input,        /* pause_input */
615        NULL,                   /* init_output */
616        NULL,                   /* config_output */
617        NULL,                   /* start_ouput */
618        bpf_fin_input,          /* fin_input */
619        NULL,                   /* fin_output */
620        bpf_read_packet,        /* read_packet */
621        bpf_prepare_packet,     /* prepare_packet */
622        NULL,                   /* fin_packet */
623        NULL,                   /* write_packet */
624        NULL,                   /* flush_output */
625        bpf_get_link_type,      /* get_link_type */
626        bpf_get_direction,      /* get_direction */
627        NULL,                   /* set_direction */
628        NULL,                   /* get_erf_timestamp */
629        bpf_get_timeval,        /* get_timeval */
630        NULL,                   /* get_timespec */
631        NULL,                   /* get_seconds */
632        NULL,                   /* seek_erf */
633        NULL,                   /* seek_timeval */
634        NULL,                   /* seek_seconds */
635        bpf_get_capture_length, /* get_capture_length */
636        bpf_get_wire_length,    /* get_wire_length */
637        bpf_get_framing_length, /* get_framing_length */
638        NULL,                   /* set_capture_length */
639        NULL,                   /* get_received_packets */
640        NULL,                   /* get_filtered_packets */
641        NULL,                   /* get_dropped_packets */
642        bpf_get_statistics,     /* get_statistics */
643        bpf_get_fd,             /* get_fd */
644        trace_event_device,     /* trace_event */
645        bpf_help,               /* help */
646        NULL,                   /* next pointer */
647        NON_PARALLEL(true)
648};
649#else   /* HAVE_DECL_BIOCSETIF */
650/* Prints some slightly useful help text for the BPF capture format */
651static void bpf_help() {
652        printf("bpf format module: $Revision: 1782 $\n");
653        printf("Not supported on this host\n");
654        return;
655}
656static struct libtrace_format_t bpf = {
657        "bpf",
658        "$Id$",
659        TRACE_FORMAT_BPF,
660        NULL,                   /* probe filename */
661        NULL,                   /* probe magic */
662        NULL,                   /* init_input */
663        NULL,                   /* config_input */
664        NULL,                   /* start_input */
665        NULL,                   /* pause_input */
666        NULL,                   /* init_output */
667        NULL,                   /* config_output */
668        NULL,                   /* start_ouput */
669        NULL,                   /* fin_input */
670        NULL,                   /* fin_output */
671        NULL,                   /* read_packet */
672        bpf_prepare_packet,     /* prepare_packet */
673        NULL,                   /* fin_packet */
674        NULL,                   /* write_packet */
675        NULL,                   /* flush_output */
676        bpf_get_link_type,      /* get_link_type */
677        bpf_get_direction,      /* get_direction */
678        NULL,                   /* set_direction */
679        NULL,                   /* get_erf_timestamp */
680        bpf_get_timeval,        /* get_timeval */
681        NULL,                   /* get_timespec */
682        NULL,                   /* get_seconds */
683        NULL,                   /* seek_erf */
684        NULL,                   /* seek_timeval */
685        NULL,                   /* seek_seconds */
686        bpf_get_capture_length, /* get_capture_length */
687        bpf_get_wire_length,    /* get_wire_length */
688        bpf_get_framing_length, /* get_framing_length */
689        NULL,                   /* set_capture_length */
690        NULL,                   /* get_received_packets */
691        NULL,                   /* get_filtered_packets */
692        NULL,                   /* get_dropped_packets */
693        NULL,                   /* get_statistics */
694        NULL,                   /* get_fd */
695        NULL,                   /* trace_event */
696        bpf_help,               /* help */
697        NULL,                   /* next pointer */
698        NON_PARALLEL(true)
699};
700#endif  /* HAVE_DECL_BIOCSETIF */
701
702void bpf_constructor() {
703        register_format(&bpf);
704}
Note: See TracBrowser for help on using the repository browser.