source: lib/format_bpf.c @ a0f031b

cachetimestampsdeveloprc-4.0.4ringdecrementfixringperformance
Last change on this file since a0f031b was a0f031b, checked in by Shane Alcock <salcock@…>, 2 years ago

Fix missing callback in format_bpf

Also added missing trace option to bpf_config_input so we
don't get a warning anymore.

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