- Timestamp:
- 02/04/10 10:36:53 (12 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- 43c00e5
- Parents:
- 2c743a7
- Location:
- lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_atmhdr.c
r1aa4bf7 r5952ff0 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 * 11 * All rights reserved. 12 * 13 * This code has been developed by the University of Waikato WAND 14 * research group. For further information please see http://www.wand.net.nz/ 15 * 16 * libtrace is free software; you can redistribute it and/or modify 17 * it under the terms of the GNU General Public License as published by 18 * the Free Software Foundation; either version 2 of the License, or 19 * (at your option) any later version. 20 * 21 * libtrace is distributed in the hope that it will be useful, 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * GNU General Public License for more details. 25 * 26 * You should have received a copy of the GNU General Public License 27 * along with libtrace; if not, write to the Free Software 28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 29 * 30 * $Id$ 31 * 32 */ 33 1 34 #define _GNU_SOURCE 2 35 … … 16 49 #include <stdlib.h> 17 50 51 /* This particular format covers the ATM cell header capture format used to 52 * take the Auckland VII trace set. 53 * 54 * Each capture record contains only a timestamp and the first four bytes of 55 * the ATM header - nothing else. 56 * 57 * As a result, there isn't a lot you can actually do with these traces! 58 * 59 * Libtrace does not support writing using this format, because it is so 60 * useless :) 61 */ 62 63 /* Returns the size of the ATM cell framing header */ 18 64 static int atmhdr_get_framing_length(const libtrace_packet_t *packet UNUSED) 19 65 { … … 21 67 } 22 68 69 /* Initialise an input trace to read an ATM cell header capture */ 23 70 static int atmhdr_init_input(libtrace_t *libtrace) { 24 71 libtrace->format_data = NULL; /* No format data needed */ … … 26 73 } 27 74 75 /* Start an ATM cell header input trace */ 28 76 static int atmhdr_start_input(libtrace_t *libtrace) 29 77 { … … 36 84 } 37 85 86 /* Close an ATM cell header input trace */ 38 87 static int atmhdr_fin_input(libtrace_t *libtrace) 39 88 { … … 42 91 } 43 92 93 94 /* Converts a buffer containing a recently read ATM cell header record into 95 * a libtrace packet */ 44 96 static int atmhdr_prepare_packet(libtrace_t *libtrace, 45 97 libtrace_packet_t *packet, void *buffer, 46 98 libtrace_rt_types_t rt_type, uint32_t flags) { 47 99 100 /* If the packet previously owned a buffer that was not the buffer 101 * containing the new packet data, we need to free the old one to 102 * avoid leaking memory */ 48 103 if (packet->buffer != buffer && 49 104 packet->buf_control == TRACE_CTRL_PACKET) { … … 51 106 } 52 107 108 /* Set the buffer owner appropriately */ 53 109 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 54 110 packet->buf_control = TRACE_CTRL_PACKET; … … 56 112 packet->buf_control = TRACE_CTRL_EXTERNAL; 57 113 114 /* Update the packet pointers appropriately */ 58 115 packet->buffer = buffer; 59 116 packet->header = buffer; 60 117 packet->payload = (void*)((char*)packet->buffer + 61 118 libtrace->format->get_framing_length(packet)); 119 120 /* Set the packet type */ 62 121 packet->type = rt_type; 63 122 64 if (libtrace->format_data == NULL) {65 if (atmhdr_init_input(libtrace))66 return -1;67 }68 123 return 0; 69 124 } 70 125 126 /* Reads the next ATM cell header record from the given trace and writes it 127 * into a libtrace packet */ 71 128 static int atmhdr_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 72 129 int numbytes; … … 74 131 uint32_t flags = 0; 75 132 133 /* Make sure we have a buffer available to read the next record into */ 76 134 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 77 135 packet->buffer=malloc((size_t)LIBTRACE_PACKET_BUFSIZE); … … 82 140 packet->type = TRACE_RT_DATA_ATMHDR; 83 141 142 /* The records are a fixed size so we can read the entire record in 143 * one go */ 84 144 if ((numbytes=wandio_read(libtrace->io, buffer, (size_t)12)) != 12) 85 145 { … … 90 150 } 91 151 152 /* Update all our packet pointers appropriately */ 92 153 if (atmhdr_prepare_packet(libtrace, packet, buffer, 93 154 TRACE_RT_DATA_ATMHDR, flags)) { … … 99 160 } 100 161 162 /* Get the link type for an ATM cell header record */ 101 163 static libtrace_linktype_t atmhdr_get_link_type(const libtrace_packet_t *packet UNUSED) { 164 /* Unsurprisingly, we're always going to be an ATM header */ 102 165 return TRACE_TYPE_ATM; 103 166 } 104 167 168 /* Get the capture length for an ATM cell header record */ 105 169 static int atmhdr_get_capture_length(const libtrace_packet_t *packet UNUSED) { 170 /* There is always 4 bytes of ATM header retained by this format */ 106 171 return 4; 107 172 } 108 173 174 /* Get the wire length for an ATM cell header record */ 109 175 static int atmhdr_get_wire_length(const libtrace_packet_t *packet UNUSED) { 176 /* ATM packets are 53 byte fixed length records */ 110 177 return 53; 111 178 } 112 179 180 /* Returns the timestamp for an ATM cell header record in the ERF timestamp 181 * format */ 113 182 static uint64_t atmhdr_get_erf_timestamp(const libtrace_packet_t *packet) { 114 183 uint64_t ts; 115 184 atmhdr_t *atm = (atmhdr_t *)packet->header; 185 186 /* Basically, the capture format header is an ERF timestamp except 187 * the two 32-bit segments are reversed */ 116 188 ts = (uint64_t)atm->ts_fraction + ((uint64_t)atm->ts_sec << 32); 117 189 -
lib/format_bpf.c
r099c35e r5952ff0 2 2 * This file is part of libtrace 3 3 * 4 * Copyright (c) 2007,2008 The University of Waikato, Hamilton, New Zealand. 5 * Authors: Perry Lorier 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 6 10 * 7 11 * All rights reserved. … … 52 56 #include <fcntl.h> 53 57 54 58 /* This format deals with the BSD Native capture format, perhaps better 59 * known as BPF, which is the equivalent of the Linux Native format for 60 * *BSD systems. 61 * 62 * This is a LIVE capture format - we're always dealing with reading from an 63 * interface. 64 * 65 * This format does not support writing, but BPF packet records can be easily 66 * converted to PCAP or ERF. 67 */ 68 69 /* "Global" data that is stored for each BPF input trace */ 55 70 struct libtrace_format_data_t { 56 int fd; 71 /* The file descriptor that is being captured from */ 72 int fd; 73 /* The snap length for the capture */ 57 74 int snaplen; 75 /* A boolean flag indicating whether the capture interface should be 76 * in promiscuous mode */ 58 77 int promisc; 78 /* A buffer to write captured data into */ 59 79 void *buffer; 80 /* The current read location in the capture buffer */ 60 81 void *bufptr; 82 /* The total size of the capture buffer */ 61 83 unsigned int buffersize; 84 /* The amount of space remaining before the capture buffer is full */ 62 85 int remaining; 86 /* The linktype of the capture interface */ 63 87 unsigned int linktype; 88 /* Statistics about how many packets have been dropped, received etc. */ 64 89 struct bpf_stat stats; 90 /* A boolean flag indicating whether the statistics are up-to-date */ 65 91 int stats_valid; 66 92 }; … … 70 96 #define BPFHDR(x) ((struct bpf_hdr *)((x)->header)) 71 97 98 /* Attempts to determine if a given filename could refer to a BPF interface */ 72 99 static int bpf_probe_filename(const char *filename) 73 100 { … … 75 102 } 76 103 104 /* XXX This function doesn't appear to be used anywhere - nor does it do 105 * anything particularly useful :) */ 77 106 static int bpf_start_filename(const char *filename) 78 107 { … … 80 109 } 81 110 111 /* Initialises a BPF input trace */ 82 112 static int bpf_init_input(libtrace_t *libtrace) 83 113 { 84 114 libtrace->format_data = (struct libtrace_format_data_t *) 85 115 malloc(sizeof(struct libtrace_format_data_t)); 116 117 /* Throw some default values into the format data */ 86 118 FORMATIN(libtrace)->fd = -1; 87 119 FORMATIN(libtrace)->promisc = 0; … … 92 124 } 93 125 126 /* Starts a BPF input trace */ 94 127 static int bpf_start_input(libtrace_t *libtrace) 95 128 { … … 155 188 FORMATIN(libtrace)->remaining = 0; 156 189 157 /* attach to the device */190 /* Attach to the device */ 158 191 strncpy(ifr.ifr_name, libtrace->uridata, sizeof(ifr.ifr_name)); 159 192 if (ioctl(FORMATIN(libtrace)->fd, BIOCSETIF, &ifr) == -1) { … … 163 196 } 164 197 198 /* Set the link type */ 165 199 if (ioctl(FORMATIN(libtrace)->fd, BIOCGDLT, 166 200 &FORMATIN(libtrace)->linktype) == -1) { … … 185 219 * pray the kernel is smart enough that if a another packet arrives 186 220 * while we're processing this one that it will buffer them into it's 187 * kernel buffer so we can rec ieve packets later. (It'll need to do this221 * kernel buffer so we can receive packets later. (It'll need to do this 188 222 * to deal with us spending time processing the last 'n' packets anyway) 189 223 */ … … 196 230 } 197 231 232 /* Set promiscous mode, if the user has asked us to do so */ 198 233 if (FORMATIN(libtrace)->promisc) { 199 234 if (ioctl(FORMATIN(libtrace)->fd, BIOCPROMISC, NULL) == -1) { … … 214 249 } 215 250 251 /* Gets a count of the number of packets received on the BPF interface */ 216 252 static uint64_t bpf_get_received_packets(libtrace_t *trace) 217 253 { … … 237 273 } 238 274 275 /* Gets a count of the number of packets dropped on the BPF interface */ 239 276 static uint64_t bpf_get_dropped_packets(libtrace_t *trace) 240 277 { … … 260 297 } 261 298 299 /* Pauses a BPF input trace */ 262 300 static int bpf_pause_input(libtrace_t *libtrace) 263 301 { … … 268 306 } 269 307 308 /* Closes a BPF input trace */ 270 309 static int bpf_fin_input(libtrace_t *libtrace) 271 310 { … … 274 313 } 275 314 315 /* Configures a BPF input trace */ 276 316 static int bpf_config_input(libtrace_t *libtrace, 277 317 trace_option_t option, … … 295 335 break; 296 336 case TRACE_OPTION_EVENT_REALTIME: 297 /* captures are always realtime */337 /* Captures are always realtime */ 298 338 break; 299 339 … … 308 348 } 309 349 350 /* Converts a buffer containing a recently read BPF packet record into a 351 * libtrace packet */ 310 352 static int bpf_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 311 353 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 312 if (packet->buffer != buffer && 354 355 /* If the packet previously owned a buffer that is not the buffer 356 * that contains the new packet data, we're going to need to free the 357 * old one to avoid memory leaks */ 358 if (packet->buffer != buffer && 313 359 packet->buf_control == TRACE_CTRL_PACKET) { 314 360 free(packet->buffer); 315 361 } 316 362 363 /* Set the buffer owner appropriately */ 317 364 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 318 365 packet->buf_control = TRACE_CTRL_PACKET; … … 320 367 packet->buf_control = TRACE_CTRL_EXTERNAL; 321 368 322 369 /* Update the packet pointers and type appropriately */ 323 370 packet->buffer = buffer; 324 371 packet->header = buffer; … … 336 383 return 0; 337 384 } 338 385 386 /* Reads the next packet record from a BPF interface and writes it into a 387 * libtrace packet */ 339 388 static int bpf_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) 340 389 { 341 390 uint32_t flags = 0; 342 391 343 /* Fill the buffer */392 /* Read from the BPF interface into our capture buffer */ 344 393 if (FORMATIN(libtrace)->remaining<=0) { 345 394 int ret; … … 363 412 FORMATIN(libtrace)->buffer; 364 413 } 414 415 /* We do NOT want anything trying to free the memory the packet is 416 * stored in */ 365 417 flags |= TRACE_PREP_DO_NOT_OWN_BUFFER; 366 /* Read one packet out */ 367 418 368 419 if (packet->buf_control == TRACE_CTRL_PACKET) 369 420 free(packet->buffer); 370 421 422 /* Update 'packet' to point to the first packet in our capture 423 * buffer */ 371 424 if (bpf_prepare_packet(libtrace, packet, FORMATIN(libtrace)->bufptr, 372 425 TRACE_RT_DATA_BPF, flags)) { … … 375 428 376 429 377 /* Now deal with any padding */ 430 /* Skip past the packet record we're going to return, making sure 431 * that we deal with padding correctly */ 378 432 FORMATIN(libtrace)->bufptr+= 379 433 BPF_WORDALIGN(BPFHDR(packet)->bh_hdrlen … … 386 440 } 387 441 442 /* Returns the linktype for the interface that we are capturing from */ 388 443 static libtrace_linktype_t bpf_get_link_type(const libtrace_packet_t *packet) { 444 /* Convert the linktype that we recorded when we started the trace 445 * into a suitable libtrace linktype */ 389 446 return pcap_linktype_to_libtrace(FORMATIN(packet->trace)->linktype); 390 447 } 391 448 449 /* Returns the direction for a given BPF packet record */ 392 450 static libtrace_direction_t bpf_get_direction(const libtrace_packet_t *packet) { 393 /* BPF Sadly can't do direction tagging */451 /* BPF sadly can't do direction tagging */ 394 452 return ~0; 395 453 } 396 454 455 /* Returns the timestamp for a given BPF packet record, in the form of a 456 * struct timeval */ 397 457 static struct timeval bpf_get_timeval(const libtrace_packet_t *packet) 398 458 { … … 407 467 } 408 468 469 /* Returns the capture length for a given BPF packet record */ 409 470 static int bpf_get_capture_length(const libtrace_packet_t *packet) 410 471 { 411 /* BPF Doesn't include the FCS, we do. */ 472 /* BPF doesn't include the FCS in its caplen field, but libtrace 473 * does so we need to add this extra 4 bytes */ 412 474 return BPFHDR(packet)->bh_caplen+4; 413 475 } 414 476 477 /* Returns the wire length for a given BPF packet record */ 415 478 static int bpf_get_wire_length(const libtrace_packet_t *packet) 416 479 { 480 481 /* BPF doesn't include the FCS in its datalen field, but libtrace 482 * does so we need to add this extra 4 bytes */ 417 483 return BPFHDR(packet)->bh_datalen+4; 418 484 } 419 485 486 /* Returns the framing length for a given BPF packet record */ 420 487 static int bpf_get_framing_length(UNUSED 421 488 const libtrace_packet_t *packet) … … 424 491 } 425 492 493 /* Returns the file descriptor that the capture interface is operating on */ 426 494 static int bpf_get_fd(const libtrace_t *trace) { 427 495 return FORMATIN(trace)->fd; 428 496 } 429 497 498 /* Prints some slightly useful help text for the BPF capture format */ 430 499 static void bpf_help() { 431 500 printf("bpf format module: $Revision$\n"); -
lib/format_dag24.c
r5778738 r5952ff0 2 2 * This file is part of libtrace 3 3 * 4 * Copyright (c) 2007,2008 The University of Waikato, Hamilton, New Zealand. 5 * Authors: Daniel Lawson 4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton, 5 * New Zealand. 6 * 7 * Authors: Daniel Lawson 6 8 * Perry Lorier 7 * Shane Alcock 8 * 9 * Shane Alcock 10 * 9 11 * All rights reserved. 10 12 * 11 * This code has been developed by the University of Waikato WAND 13 * This code has been developed by the University of Waikato WAND 12 14 * research group. For further information please see http://www.wand.net.nz/ 13 15 * … … 29 31 * 30 32 */ 33 31 34 #define _GNU_SOURCE 32 35 … … 59 62 #endif 60 63 64 /* This format deals with DAG cards that are using drivers from the 2.4.X 65 * versions. 66 * 67 * DAG is a LIVE capture format. 68 * 69 * We do not support writing using this format, as transmit support was not 70 * added until a subsequent version of the DAG software (see format_dag25.c). 71 * Instead, you should write the packets read using this format as ERF traces. 72 */ 61 73 62 74 static struct libtrace_format_t dag; … … 66 78 #define FORMAT_DATA DATA(libtrace) 67 79 80 /* "Global" data that is stored for each DAG input trace */ 68 81 struct dag_format_data_t { 82 83 /* Data required for regular DUCK reporting */ 69 84 struct { 85 /* Timestamp of the last DUCK report */ 70 86 uint32_t last_duck; 87 /* The number of seconds between each DUCK report */ 71 88 uint32_t duck_freq; 89 /* Timestamp of the last packet read from the DAG card */ 72 90 uint32_t last_pkt; 91 /* Dummy trace to ensure DUCK packets are dealt with using 92 * the DUCK format functions */ 73 93 libtrace_t *dummy_duck; 74 94 } duck; 75 95 96 /* File descriptor for the DAG card */ 76 97 int fd; 98 /* Pointer to DAG memory hole */ 77 99 void *buf; 100 /* Difference between the top and bottom pointers in the DAG memory 101 * hole, i.e. the amount of available data to read */ 78 102 uint32_t diff; 103 /* The amount of data read thus far from the start of the bottom 104 * pointer */ 79 105 uint32_t offset; 106 /* The offset for the first unread byte in the DAG memory hole */ 80 107 uint32_t bottom; 108 /* The offset for the last unread byte in the DAG memory hole */ 81 109 uint32_t top; 110 /* The number of packets that have been dropped */ 82 111 uint64_t drops; 83 112 }; 84 113 114 /* Determines if a given filename refers to a DAG device */ 85 115 static void dag_probe_filename(const char *filename) 86 116 { … … 98 128 } 99 129 130 /* Initialises the DAG "global" variables */ 100 131 static void dag_init_format_data(libtrace_t *libtrace) { 101 132 libtrace->format_data = (struct dag_format_data_t *) … … 115 146 } 116 147 148 /* Determines how much data is available for reading on the DAG card and 149 * updates the various offsets accordingly */ 117 150 static int dag_available(libtrace_t *libtrace) { 118 151 … … 130 163 } 131 164 165 /* Initialises a DAG input trace */ 132 166 static int dag_init_input(libtrace_t *libtrace) { 133 167 struct stat buf; … … 145 179 } 146 180 147 181 182 /* Make sure a DAG device with the right name exists */ 148 183 if (stat(dag_dev_name, &buf) == -1) { 149 184 trace_set_err(libtrace,errno,"stat(%s)",dag_dev_name); … … 161 196 return -1; 162 197 } 198 199 /* Memory-map ourselves a pointer to the DAG memory hole */ 163 200 if((FORMAT_DATA->buf = (void *)dag_mmap(FORMAT_DATA->fd)) == MAP_FAILED) { 164 201 trace_set_err(libtrace,errno,"Cannot mmap DAG %s", … … 179 216 } 180 217 218 /* Configures a DAG input trace */ 181 219 static int dag_config_input(libtrace_t *libtrace, trace_option_t option, 182 220 void *data) { 183 221 switch(option) { 184 222 case TRACE_OPTION_META_FREQ: 223 /* We use this option to specify the frequency of 224 * DUCK updates */ 185 225 DUCK.duck_freq = *(int *)data; 186 226 return 0; … … 192 232 return -1; 193 233 case TRACE_OPTION_FILTER: 234 /* Cards that use the older drivers don't do 235 * filtering */ 194 236 return -1; 195 237 case TRACE_OPTION_EVENT_REALTIME: 238 /* Live capture is always going to be realtime */ 196 239 return -1; 197 240 } … … 199 242 } 200 243 244 /* Starts a DAG input trace */ 201 245 static int dag_start_input(libtrace_t *libtrace) { 202 246 if(dag_start(FORMAT_DATA->fd) < 0) { … … 213 257 } 214 258 259 /* Pauses a DAG input trace */ 215 260 static int dag_pause_input(libtrace_t *libtrace) { 216 261 dag_stop(FORMAT_DATA->fd); … … 218 263 } 219 264 265 /* Destroys a DAG input trace */ 220 266 static int dag_fin_input(libtrace_t *libtrace) { 221 267 dag_close(FORMAT_DATA->fd); … … 226 272 } 227 273 274 /* Extracts DUCK information from the DAG card and produces a DUCK packet */ 228 275 static int dag_get_duckinfo(libtrace_t *libtrace, 229 276 libtrace_packet_t *packet) { 230 277 dag_inf lt_dag_inf; 231 278 279 /* Allocate memory for the DUCK data */ 232 280 if (packet->buf_control == TRACE_CTRL_EXTERNAL || 233 281 !packet->buffer) { … … 241 289 } 242 290 291 /* DUCK doesn't actually have a format header, as such */ 243 292 packet->header = 0; 244 293 packet->payload = packet->buffer; 245 294 295 /* Check that the DAG card supports DUCK */ 246 296 if ((ioctl(FORMAT_DATA->fd, DAG_IOINF, <_dag_inf) < 0)) { 247 297 trace_set_err(libtrace, errno, … … 254 304 } 255 305 306 /* Get the DUCK information from the card */ 256 307 if ((ioctl(FORMAT_DATA->fd, DAG_IOGETDUCK, (duck_inf *)packet->payload) 257 308 < 0)) { … … 260 311 } 261 312 313 /* Set the type */ 262 314 packet->type = TRACE_RT_DUCK_2_4; 315 316 /* Set the packet's trace to point at a DUCK trace, so that the 317 * DUCK format functions will be called on the packet rather than the 318 * DAG ones */ 263 319 if (!DUCK.dummy_duck) 264 320 DUCK.dummy_duck = trace_create_dead("duck:dummy"); … … 267 323 } 268 324 269 325 /* Reads the next ERF record from the DAG memory hole */ 270 326 static dag_record_t *dag_get_record(libtrace_t *libtrace) { 271 327 dag_record_t *erfptr = NULL; … … 283 339 } 284 340 341 /* Converts a buffer containing a recently read DAG packet record into a 342 * libtrace packet */ 285 343 static int dag_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 286 344 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 287 345 288 346 dag_record_t *erfptr; 347 /* If the packet previously owned a buffer that is not the buffer 348 * that contains the new packet data, we're going to need to free the 349 * old one to avoid memory leaks */ 289 350 if (packet->buffer != buffer && 290 351 packet->buf_control == TRACE_CTRL_PACKET) { … … 292 353 } 293 354 355 /* Set the buffer owner appropriately */ 294 356 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 295 357 packet->buf_control = TRACE_CTRL_PACKET; … … 297 359 packet->buf_control = TRACE_CTRL_EXTERNAL; 298 360 361 /* Update packet pointers and type appropriately */ 299 362 erfptr = (dag_record_t *)buffer; 300 363 packet->buffer = erfptr; … … 303 366 304 367 if (erfptr->flags.rxerror == 1) { 305 /* rxerror means the payload is corrupt - drop it368 /* rxerror means the payload is corrupt - drop the payload 306 369 * by tweaking rlen */ 307 370 packet->payload = NULL; … … 316 379 } 317 380 381 /* Update the dropped packets counter, using the value of the ERF 382 * loss counter */ 318 383 DATA(libtrace)->drops += ntohs(erfptr->lctr); 319 384 … … 322 387 } 323 388 389 /* Reads the next available packet from a DAG card, in a BLOCKING fashion 390 * 391 * If DUCK reporting is enabled, the packet returned may be a DUCK update */ 324 392 static int dag_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 325 393 int numbytes; … … 329 397 dag_record_t *erfptr = NULL; 330 398 399 /* Check if we're due for a DUCK report */ 331 400 if (DUCK.last_pkt - DUCK.last_duck > DUCK.duck_freq && 332 401 DUCK.duck_freq != 0) { … … 340 409 } 341 410 411 /* Don't let anyone try to free our DAG memory hole */ 342 412 flags |= TRACE_PREP_DO_NOT_OWN_BUFFER; 343 413 344 if (packet->buf_control == TRACE_CTRL_PACKET) { 414 /* If the packet buffer is currently owned by libtrace, free it so 415 * that we can set the packet to point into the DAG memory hole */ 416 if (packet->buf_control == TRACE_CTRL_PACKET) { 345 417 packet->buf_control = TRACE_CTRL_EXTERNAL; 346 418 free(packet->buffer); … … 348 420 } 349 421 350 422 /* Grab a full ERF record */ 351 423 do { 352 424 numbytes = dag_available(libtrace); … … 358 430 } while (erfptr == NULL); 359 431 360 432 /* Prepare the libtrace packet */ 361 433 if (dag_prepare_packet(libtrace, packet, erfptr, TRACE_RT_DATA_ERF, 362 434 flags)) 363 435 return -1; 436 437 /* Update the DUCK timer */ 364 438 tv = trace_get_timeval(packet); 365 439 DUCK.last_pkt = tv.tv_sec; … … 367 441 } 368 442 443 /* Attempts to read a packet from a DAG card in a NON-BLOCKING fashion. If 444 * a packet is available, we will return a packet event. Otherwise we will 445 * return a SLEEP event (as we cannot select on the DAG file descriptor). 446 */ 369 447 static libtrace_eventobj_t trace_event_dag(libtrace_t *trace, 370 448 libtrace_packet_t *packet) { … … 375 453 data = dag_available(trace); 376 454 455 /* If no data is available, drop out and return a sleep event */ 377 456 if (data <= 0) 378 457 break; 379 458 459 /* Data is available, so we can call the blocking read because 460 * we know that we will get a packet straight away */ 380 461 event.size = dag_read_packet(trace,packet); 381 462 //DATA(trace)->dag.diff -= event.size; 463 464 /* XXX trace_read_packet() normally applies the following 465 * config options for us, but this function is called via 466 * trace_event() so we have to do it ourselves */ 467 468 /* Check that the packet matches any pre-existing filter */ 382 469 if (trace->filter) { 383 470 if (trace_apply_filter(trace->filter, packet)) { … … 390 477 event.type = TRACE_EVENT_PACKET; 391 478 } 479 480 /* If the user has specified a snap length, apply that too */ 392 481 if (trace->snaplen > 0) { 393 482 trace_set_capture_length(packet, trace->snaplen); … … 397 486 } while (1); 398 487 488 489 /* We only want to sleep for a very short time */ 399 490 assert(data == 0); 400 491 event.type = TRACE_EVENT_SLEEP; … … 404 495 } 405 496 497 /* Gets the number of dropped packets */ 406 498 static uint64_t dag_get_dropped_packets(libtrace_t *trace) 407 499 { … … 411 503 } 412 504 505 /* Prints some semi-useful help text about the DAG format module */ 413 506 static void dag_help(void) { 414 507 printf("dag format module: $Revision$\n");
Note: See TracChangeset
for help on using the changeset viewer.