Changeset f0fb38f
- Timestamp:
- 03/26/08 10:45:36 (14 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:
- f52bcdd
- Parents:
- e632f2f
- Location:
- lib
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_atmhdr.c
rf2fae49 rf0fb38f 56 56 } 57 57 58 static int atmhdr_prepare_packet(libtrace_t *libtrace, 59 libtrace_packet_t *packet, void *buffer, 60 libtrace_rt_types_t rt_type, uint32_t flags) { 61 62 if (packet->buffer != buffer && 63 packet->buf_control == TRACE_CTRL_PACKET) { 64 free(packet->buffer); 65 } 66 67 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 68 packet->buf_control = TRACE_CTRL_PACKET; 69 } else 70 packet->buf_control = TRACE_CTRL_EXTERNAL; 71 72 packet->buffer = buffer; 73 packet->header = buffer; 74 packet->payload = (void*)((char*)packet->buffer + 75 libtrace->format->get_framing_length(packet)); 76 packet->type = rt_type; 77 78 if (libtrace->format_data == NULL) { 79 if (atmhdr_init_input(libtrace)) 80 return -1; 81 } 82 return 0; 83 } 84 58 85 static int atmhdr_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 59 86 int numbytes; 60 87 void *buffer; 61 88 uint32_t flags = 0; 89 62 90 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 63 packet->buf_control = TRACE_CTRL_PACKET;64 91 packet->buffer=malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 65 92 } 66 93 buffer = packet->buffer; 67 94 flags |= TRACE_PREP_OWN_BUFFER; 95 68 96 packet->type = TRACE_RT_DATA_ATMHDR; 69 97 … … 76 104 } 77 105 78 packet->header = packet->buffer; 79 packet->payload = (void*)((char*)packet->buffer + 80 libtrace->format->get_framing_length(packet)); 81 106 if (atmhdr_prepare_packet(libtrace, packet, buffer, 107 TRACE_RT_DATA_ATMHDR, flags)) { 108 return -1; 109 } 110 111 82 112 return 12; 83 113 } … … 117 147 NULL, /* fin_output */ 118 148 atmhdr_read_packet, /* read_packet */ 119 NULL, /* fin_packet */ 149 atmhdr_prepare_packet, /* prepare_packet */ 150 NULL, /* fin_packet */ 120 151 NULL, /* write_packet */ 121 152 atmhdr_get_link_type, /* get_link_type */ -
lib/format_bpf.c
r95fee28 rf0fb38f 206 206 static uint64_t bpf_get_received_packets(libtrace_t *trace) 207 207 { 208 if (trace->format_data == NULL) 209 return (uint64_t)-1; 210 211 if (FORMATIN(trace)->fd == -1) { 212 /* Almost certainly a 'dead' trace so there is no socket 213 * for us to query */ 214 return (uint64_t) -1; 215 } 208 216 /* If we're called with stats_valid == 0, or we're called again 209 217 * then refresh the stats. Don't refresh the stats if we're called … … 221 229 static uint64_t bpf_get_dropped_packets(libtrace_t *trace) 222 230 { 231 if (trace->format_data == NULL) 232 return (uint64_t)-1; 233 234 if (FORMATIN(trace)->fd == -1) { 235 /* Almost certainly a 'dead' trace so there is no socket 236 * for us to query */ 237 return (uint64_t) -1; 238 } 223 239 /* If we're called with stats_valid == 0, or we're called again 224 240 * then refresh the stats. Don't refresh the stats if we're called … … 282 298 } 283 299 300 static int bpf_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 301 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 302 if (packet->buffer != buffer && 303 packet->buf_control == TRACE_CTRL_PACKET) { 304 free(packet->buffer); 305 } 306 307 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 308 packet->buf_control = TRACE_CTRL_PACKET; 309 } else 310 packet->buf_control = TRACE_CTRL_EXTERNAL; 311 312 313 packet->buffer = buffer; 314 packet->header = buffer; 315 packet->type = rt_type; 316 317 /* Find the payload */ 318 /* TODO: Pcap deals with a padded FDDI linktype here */ 319 packet->payload=(char *)buffer + BPFHDR(packet)->bh_hdrlen; 320 321 if (libtrace->format_data == NULL) { 322 if (bpf_init_input(libtrace)) 323 return -1; 324 } 325 326 return 0; 327 } 328 284 329 static int bpf_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) 285 330 { 331 uint32_t flags = 0; 332 286 333 /* Fill the buffer */ 287 334 if (FORMATIN(libtrace)->remaining<=0) { … … 311 358 if (packet->buf_control == TRACE_CTRL_PACKET) 312 359 free(packet->buffer); 313 packet->buf_control = TRACE_CTRL_EXTERNAL; 314 315 /* Find the bpf header */ 316 packet->header=FORMATIN(libtrace)->bufptr; 317 318 /* Find the payload */ 319 /* TODO: Pcap deals with a padded FDDI linktype here */ 320 packet->payload=FORMATIN(libtrace)->bufptr+BPFHDR(packet)->bh_hdrlen; 360 361 if (bpf_prepare_packet(libtrace, packet, FORMATIN(libtrace)->bufptr, 362 TRACE_RT_DATA_BPF, flags)) { 363 return -1; 364 } 365 321 366 322 367 /* Now deal with any padding */ … … 389 434 NULL, /* fin_output */ 390 435 bpf_read_packet, /* read_packet */ 436 bpf_prepare_packet, /* prepare_packet */ 391 437 NULL, /* fin_packet */ 392 438 NULL, /* write_packet */ -
lib/format_dag24.c
r121b7e2 rf0fb38f 83 83 }; 84 84 85 static void dag_init_format_data(libtrace_t *libtrace) { 86 libtrace->format_data = (struct dag_format_data_t *) 87 malloc(sizeof(struct dag_format_data_t)); 88 89 DUCK.last_duck = 0; 90 DUCK.duck_freq = 0; 91 DUCK.last_pkt = 0; 92 DUCK.dummy_duck = NULL; 93 FORMAT_DATA->drops = 0; 94 FORMAT_DATA->top = 0; 95 FORMAT_DATA->bottom = 0; 96 FORMAT_DATA->buf = NULL; 97 FORMAT_DATA->fd = -1; 98 FORMAT_DATA->offset = 0; 99 FORMAT_DATA->diff = 0; 100 } 101 85 102 static int dag_available(libtrace_t *libtrace) { 86 103 … … 120 137 } 121 138 122 libtrace->format_data = (struct dag_format_data_t *) 123 malloc(sizeof(struct dag_format_data_t)); 124 FORMAT_DATA->top = 0; 125 FORMAT_DATA->bottom = 0; 139 dag_init_format_data(libtrace); 126 140 if (S_ISCHR(buf.st_mode)) { 127 141 /* DEVICE */ … … 145 159 } 146 160 147 DUCK.last_duck = 0;148 DUCK.duck_freq = 0;149 DUCK.last_pkt = 0;150 DUCK.dummy_duck = NULL;151 FORMAT_DATA->drops = 0;152 161 free(dag_dev_name); 153 162 … … 259 268 } 260 269 261 static void dag_form_packet(dag_record_t *erfptr, libtrace_packet_t *packet) { 270 static int dag_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 271 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 272 273 dag_record_t *erfptr; 274 if (packet->buffer != buffer && 275 packet->buf_control == TRACE_CTRL_PACKET) { 276 free(packet->buffer); 277 } 278 279 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 280 packet->buf_control = TRACE_CTRL_PACKET; 281 } else 282 packet->buf_control = TRACE_CTRL_EXTERNAL; 283 284 erfptr = (dag_record_t *)packet->buffer; 262 285 packet->buffer = erfptr; 263 286 packet->header = erfptr; 264 packet->type = TRACE_RT_DATA_ERF; 287 packet->type = rt_type; 288 265 289 if (erfptr->flags.rxerror == 1) { 266 290 /* rxerror means the payload is corrupt - drop it … … 273 297 } 274 298 299 if (libtrace->format_data == NULL) { 300 dag_init_format_data(libtrace); 301 } 302 303 DATA(libtrace)->drops += ntohs(erfptr->lctr); 304 305 return 0; 306 275 307 } 276 308 … … 278 310 int numbytes; 279 311 int size = 0; 280 struct timeval tv; 312 uint32_t flags = 0; 313 struct timeval tv; 281 314 dag_record_t *erfptr = NULL; 282 315 … … 307 340 erfptr = dag_get_record(libtrace); 308 341 } while (erfptr == NULL); 309 dag_form_packet(erfptr, packet); 310 tv = trace_get_timeval(packet); 342 343 344 if (dag_prepare_packet(libtrace, packet, erfptr, TRACE_RT_DATA_ERF, 345 flags)) 346 return -1; 347 tv = trace_get_timeval(packet); 311 348 DUCK.last_pkt = tv.tv_sec; 312 DATA(libtrace)->drops += ntohs(erfptr->lctr);313 349 return packet->payload ? htons(erfptr->rlen) : erf_get_framing_length(packet); 314 350 } … … 348 384 static uint64_t dag_get_dropped_packets(libtrace_t *trace) 349 385 { 386 if (!trace->format_data) 387 return (uint64_t)-1; 350 388 return DATA(trace)->drops; 351 389 } … … 377 415 NULL, /* fin_output */ 378 416 dag_read_packet, /* read_packet */ 379 NULL, /* fin_packet */ 417 dag_prepare_packet, /* prepare_packet */ 418 NULL, /* fin_packet */ 380 419 NULL, /* write_packet */ 381 420 erf_get_link_type, /* get_link_type */ -
lib/format_dag25.c
r2faa57e rf0fb38f 99 99 struct dag_dev_t *open_dags = NULL; 100 100 101 static void dag_init_format_data(libtrace_t *libtrace) { 102 libtrace->format_data = (struct dag_format_data_t *) 103 malloc(sizeof(struct dag_format_data_t)); 104 DUCK.last_duck = 0; 105 DUCK.duck_freq = 0; 106 DUCK.last_pkt = 0; 107 DUCK.dummy_duck = NULL; 108 FORMAT_DATA->stream_attached = 0; 109 FORMAT_DATA->drops = 0; 110 FORMAT_DATA->device = NULL; 111 FORMAT_DATA->dagstream = 0; 112 FORMAT_DATA->processed = 0; 113 FORMAT_DATA->bottom = NULL; 114 FORMAT_DATA->top = NULL; 115 } 116 101 117 /* NOTE: This function assumes the open_dag_mutex is held by the caller */ 102 118 static struct dag_dev_t *dag_find_open_device(char *dev_name) { … … 187 203 struct dag_dev_t *dag_device = NULL; 188 204 205 dag_init_format_data(libtrace); 189 206 pthread_mutex_lock(&open_dag_mutex); 190 207 if ((scan = strchr(libtrace->uridata,',')) == NULL) { … … 197 214 198 215 199 libtrace->format_data = (struct dag_format_data_t *)200 malloc(sizeof(struct dag_format_data_t));201 216 202 217 /* For now, we don't offer the ability to select the stream */ … … 219 234 } 220 235 221 222 223 DUCK.last_duck = 0;224 DUCK.duck_freq = 0;225 DUCK.last_pkt = 0;226 DUCK.dummy_duck = NULL;227 236 FORMAT_DATA->device = dag_device; 228 FORMAT_DATA->stream_attached = 0;229 FORMAT_DATA->drops = 0;230 237 231 238 pthread_mutex_unlock(&open_dag_mutex); … … 402 409 } 403 410 404 static void dag_form_packet(dag_record_t *erfptr, libtrace_packet_t *packet) { 405 packet->buffer = erfptr; 411 static int dag_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 412 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 413 414 dag_record_t *erfptr; 415 416 if (packet->buffer != buffer && 417 packet->buf_control == TRACE_CTRL_PACKET) { 418 free(packet->buffer); 419 } 420 421 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 422 packet->buf_control = TRACE_CTRL_PACKET; 423 } else 424 packet->buf_control = TRACE_CTRL_EXTERNAL; 425 426 erfptr = (dag_record_t *)packet->buffer; 427 packet->buffer = erfptr; 406 428 packet->header = erfptr; 407 packet->type = TRACE_RT_DATA_ERF; 408 if (erfptr->flags.rxerror == 1) { 429 packet->type = rt_type; 430 431 if (erfptr->flags.rxerror == 1) { 409 432 /* rxerror means the payload is corrupt - drop it 410 433 * by tweaking rlen */ … … 415 438 + erf_get_framing_length(packet); 416 439 } 417 440 441 if (libtrace->format_data == NULL) { 442 dag_init_format_data(libtrace); 443 } 444 445 /* No loss counter for DSM coloured records - have to use 446 * some other API */ 447 if (erfptr->type == TYPE_DSM_COLOR_ETH) { 448 449 } else { 450 DATA(libtrace)->drops += ntohs(erfptr->lctr); 451 } 452 453 return 0; 418 454 } 419 455 … … 424 460 dag_record_t *erfptr = NULL; 425 461 int numbytes = 0; 462 uint32_t flags = 0; 426 463 427 464 if (DUCK.last_pkt - DUCK.last_duck > DUCK.duck_freq && … … 437 474 438 475 if (packet->buf_control == TRACE_CTRL_PACKET) { 439 packet->buf_control = TRACE_CTRL_EXTERNAL;440 476 free(packet->buffer); 441 477 packet->buffer = 0; … … 452 488 } while (erfptr == NULL); 453 489 454 dag_form_packet(erfptr, packet); 490 //dag_form_packet(erfptr, packet); 491 if (dag_prepare_packet(libtrace, packet, erfptr, TRACE_RT_DATA_ERF, 492 flags)) 493 return -1; 455 494 tv = trace_get_timeval(packet); 456 495 DUCK.last_pkt = tv.tv_sec; 457 496 458 /* No loss counter for DSM coloured records - have to use459 * some other API */460 if (erfptr->type == TYPE_DSM_COLOR_ETH) {461 462 } else {463 DATA(libtrace)->drops += ntohs(erfptr->lctr);464 }465 497 return packet->payload ? htons(erfptr->rlen) : 466 498 erf_get_framing_length(packet); … … 472 504 dag_record_t *erfptr = NULL; 473 505 int numbytes; 506 uint32_t flags = 0; 474 507 475 508 /* Need to call dag_available so that the top pointer will get … … 487 520 return event; 488 521 } 489 dag_form_packet(erfptr, packet); 522 //dag_form_packet(erfptr, packet); 523 if (dag_prepare_packet(trace, packet, erfptr, TRACE_RT_DATA_ERF, 524 flags)) { 525 event.type = TRACE_EVENT_TERMINATE; 526 return event; 527 } 528 529 490 530 event.size = trace_get_capture_length(packet) + trace_get_framing_length(packet); 491 531 if (trace->filter) { … … 509 549 510 550 static uint64_t dag_get_dropped_packets(libtrace_t *trace) { 551 if (trace->format_data == NULL) 552 return (uint64_t)-1; 511 553 return DATA(trace)->drops; 512 554 } … … 538 580 NULL, /* fin_output */ 539 581 dag_read_packet, /* read_packet */ 540 NULL, /* fin_packet */ 582 dag_prepare_packet, /* prepare_packet */ 583 NULL, /* fin_packet */ 541 584 NULL, /* write_packet */ 542 585 erf_get_link_type, /* get_link_type */ -
lib/format_duck.c
rf3f3558 rf0fb38f 133 133 } 134 134 135 static int duck_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 136 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 137 138 if (packet->buffer != buffer && 139 packet->buf_control == TRACE_CTRL_PACKET) { 140 free(packet->buffer); 141 } 142 143 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 144 packet->buf_control = TRACE_CTRL_PACKET; 145 } else 146 packet->buf_control = TRACE_CTRL_EXTERNAL; 147 148 149 packet->buffer = buffer; 150 packet->header = NULL; 151 packet->payload = buffer; 152 packet->type = rt_type; 153 154 if (libtrace->format_data == NULL) { 155 if (duck_init_input(libtrace)) 156 return -1; 157 } 158 159 return 0; 160 } 161 135 162 static int duck_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 136 163 … … 138 165 uint32_t version = 0; 139 166 unsigned int duck_size; 167 uint32_t flags = 0; 140 168 141 169 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 142 170 packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 143 packet->buf_control = TRACE_CTRL_PACKET;144 171 if (!packet->buffer) { 145 172 trace_set_err(libtrace, errno, … … 149 176 } 150 177 178 flags |= TRACE_PREP_OWN_BUFFER; 179 151 180 if (INPUT->dag_version == 0) { 152 181 /* Read in the duck version from the start of the trace */ … … 164 193 165 194 166 packet->header = 0;167 packet->payload = packet->buffer;168 169 195 if (INPUT->dag_version == TRACE_RT_DUCK_2_4) { 170 196 duck_size = sizeof(duck2_4_t); … … 180 206 } 181 207 182 if ((numbytes = libtrace_io_read(INPUT->file, packet-> payload,208 if ((numbytes = libtrace_io_read(INPUT->file, packet->buffer, 183 209 (size_t)duck_size)) != (int)duck_size) { 184 210 if (numbytes == -1) { … … 194 220 } 195 221 222 if (duck_prepare_packet(libtrace, packet, packet->buffer, packet->type, 223 flags)) 224 return -1; 225 196 226 return numbytes; 197 227 } … … 284 314 duck_fin_output, /* fin_output */ 285 315 duck_read_packet, /* read_packet */ 286 NULL, /* fin_packet */ 316 duck_prepare_packet, /* prepare_packet */ 317 NULL, /* fin_packet */ 287 318 duck_write_packet, /* write_packet */ 288 319 duck_get_link_type, /* get_link_type */ -
lib/format_erf.c
re632f2f rf0fb38f 342 342 } 343 343 344 static int erf_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 345 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 346 347 dag_record_t *erfptr; 348 349 if (packet->buffer != buffer && 350 packet->buf_control == TRACE_CTRL_PACKET) { 351 free(packet->buffer); 352 } 353 354 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 355 packet->buf_control = TRACE_CTRL_PACKET; 356 } else 357 packet->buf_control = TRACE_CTRL_EXTERNAL; 358 359 360 packet->type = rt_type; 361 packet->buffer = buffer; 362 packet->header = buffer; 363 erfptr = (dag_record_t *)packet->buffer; 364 if (erfptr->flags.rxerror == 1) { 365 packet->payload = NULL; 366 /* XXX: Do we want to do this? We never used to do this 367 368 erfptr->rlen = htons(erf_get_framing_length(packet)); 369 */ 370 } else { 371 packet->payload = (char*)packet->buffer + erf_get_framing_length(packet); 372 } 373 374 if (libtrace->format_data == NULL) { 375 /* Allocates the format_data structure */ 376 if (erf_init_input(libtrace)) 377 return -1; 378 } 379 380 /* Check for loss */ 381 if (erfptr->type == TYPE_DSM_COLOR_ETH) { 382 /* No idea how we get this yet */ 383 384 } else { 385 DATA(libtrace)->drops += ntohs(erfptr->lctr); 386 } 387 388 return 0; 389 } 344 390 345 391 static int erf_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { … … 348 394 void *buffer2 = packet->buffer; 349 395 unsigned int rlen; 350 396 uint32_t flags = 0; 397 398 351 399 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 352 400 packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 353 packet->buf_control = TRACE_CTRL_PACKET;354 401 if (!packet->buffer) { 355 402 trace_set_err(libtrace, errno, … … 359 406 } 360 407 361 362 363 packet->header = packet->buffer; 364 packet->type = TRACE_RT_DATA_ERF; 365 408 flags |= TRACE_PREP_OWN_BUFFER; 409 366 410 if ((numbytes=libtrace_io_read(INPUT.file, 367 411 packet->buffer, … … 403 447 return -1; 404 448 } 405 if (((dag_record_t *)packet->buffer)->flags.rxerror == 1) { 406 packet->payload = NULL; 407 } else { 408 packet->payload = (char*)packet->buffer + erf_get_framing_length(packet); 409 } 449 450 if (erf_prepare_packet(libtrace, packet, packet->buffer, TRACE_RT_DATA_ERF, flags)) 451 return -1; 452 410 453 return rlen; 411 454 } … … 637 680 static uint64_t erf_get_dropped_packets(libtrace_t *trace) 638 681 { 682 if (trace->format_data == NULL) 683 return (uint64_t)-1; 639 684 return DATA(trace)->drops; 640 685 } … … 678 723 erf_fin_output, /* fin_output */ 679 724 erf_read_packet, /* read_packet */ 725 erf_prepare_packet, /* prepare_packet */ 680 726 NULL, /* fin_packet */ 681 727 erf_write_packet, /* write_packet */ -
lib/format_legacy.c
rf3f3558 rf0fb38f 69 69 }; 70 70 71 static void legacy_init_format_data(libtrace_t *libtrace) { 72 libtrace->format_data = malloc(sizeof(struct legacy_format_data_t)); 73 74 DATA(libtrace)->input.file = NULL; 75 DATA(libtrace)->ts_high = 0; 76 DATA(libtrace)->ts_old = 0; 77 DATA(libtrace)->starttime = 0; 78 } 79 71 80 static int legacyeth_get_framing_length(const libtrace_packet_t *packet UNUSED) 72 81 { … … 91 100 static int erf_init_input(libtrace_t *libtrace) 92 101 { 93 libtrace->format_data = malloc(sizeof(struct legacy_format_data_t)); 94 95 DATA(libtrace)->input.file = NULL; 102 legacy_init_format_data(libtrace); 96 103 97 104 return 0; … … 136 143 regmatch_t match; 137 144 138 libtrace->format_data = malloc(sizeof(struct legacy_format_data_t)); 139 140 DATA(libtrace)->input.file = NULL; 141 145 146 legacy_init_format_data(libtrace); 142 147 if((retval = regcomp(®, "[0-9]{8}-[0-9]{6}", REG_EXTENDED)) != 0) { 143 148 trace_set_err(libtrace, errno, "Failed to compile regex"); … … 149 154 } 150 155 DATA(libtrace)->starttime = trtime(&filename[match.rm_so]); 151 DATA(libtrace)->ts_high = 0;152 DATA(libtrace)->ts_old = 0;153 156 return 0; 154 157 } … … 173 176 } 174 177 178 static int legacy_prepare_packet(libtrace_t *libtrace, 179 libtrace_packet_t *packet, void *buffer, 180 libtrace_rt_types_t rt_type, uint32_t flags) { 181 182 if (packet->buffer != buffer && 183 packet->buf_control == TRACE_CTRL_PACKET) { 184 free(packet->buffer); 185 } 186 187 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 188 packet->buf_control = TRACE_CTRL_PACKET; 189 } else 190 packet->buf_control = TRACE_CTRL_EXTERNAL; 191 192 193 packet->buffer = buffer; 194 packet->header = buffer; 195 packet->type = rt_type; 196 packet->payload = (void*)((char*)packet->buffer + 197 libtrace->format->get_framing_length(packet)); 198 199 200 if (libtrace->format_data == NULL) { 201 legacy_init_format_data(libtrace); 202 } 203 return 0; 204 } 205 175 206 static int legacy_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 176 207 int numbytes; 177 208 void *buffer; 178 209 uint32_t flags = 0; 210 179 211 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 180 packet->buf_control = TRACE_CTRL_PACKET;181 212 packet->buffer=malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 182 213 } 214 flags |= TRACE_PREP_OWN_BUFFER; 183 215 buffer = packet->buffer; 184 216 … … 215 247 } 216 248 217 packet->header = packet->buffer; 218 packet->payload = (void*)((char*)packet->buffer + 219 libtrace->format->get_framing_length(packet)); 249 if (legacy_prepare_packet(libtrace, packet, packet->buffer, 250 packet->type, flags)) { 251 return -1; 252 } 220 253 221 254 return 64; … … 231 264 void *buffer; 232 265 char *data_ptr; 266 uint32_t flags = 0; 233 267 234 268 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 235 packet->buf_control = TRACE_CTRL_PACKET;236 269 packet->buffer=malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 237 270 } 271 flags |= TRACE_PREP_OWN_BUFFER; 272 238 273 buffer = packet->buffer; 239 240 274 packet->type = TRACE_RT_DATA_LEGACY_NZIX; 241 275 … … 263 297 memmove(data_ptr + 2, data_ptr, 26); 264 298 265 packet->header = packet->buffer; 266 packet->payload = (void*)((char*)packet->buffer + 267 libtrace->format->get_framing_length(packet)); 299 if (legacy_prepare_packet(libtrace, packet, packet->buffer, 300 packet->type, flags)) { 301 return -1; 302 } 268 303 return 68; 269 304 } … … 432 467 NULL, /* fin_output */ 433 468 legacy_read_packet, /* read_packet */ 469 legacy_prepare_packet, /* prepare_packet */ 434 470 NULL, /* fin_packet */ 435 471 NULL, /* write_packet */ … … 471 507 NULL, /* fin_output */ 472 508 legacy_read_packet, /* read_packet */ 509 legacy_prepare_packet, /* prepare_packet */ 473 510 NULL, /* fin_packet */ 474 511 NULL, /* write_packet */ … … 510 547 NULL, /* fin_output */ 511 548 legacy_read_packet, /* read_packet */ 549 legacy_prepare_packet, /* prepare_packet */ 512 550 NULL, /* fin_packet */ 513 551 NULL, /* write_packet */ … … 549 587 NULL, /* fin_output */ 550 588 legacynzix_read_packet, /* read_packet */ 589 legacy_prepare_packet, /* prepare_packet */ 551 590 NULL, /* fin_packet */ 552 591 NULL, /* write_packet */ -
lib/format_linux.c
r95fee28 rf0fb38f 331 331 } 332 332 333 static int linuxnative_prepare_packet(libtrace_t *libtrace, 334 libtrace_packet_t *packet, void *buffer, 335 libtrace_rt_types_t rt_type, uint32_t flags) { 336 337 if (packet->buffer != buffer && 338 packet->buf_control == TRACE_CTRL_PACKET) { 339 free(packet->buffer); 340 } 341 342 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 343 packet->buf_control = TRACE_CTRL_PACKET; 344 } else 345 packet->buf_control = TRACE_CTRL_EXTERNAL; 346 347 348 packet->buffer = buffer; 349 packet->header = buffer; 350 packet->payload = (char *)buffer + 351 sizeof(struct libtrace_linuxnative_header); 352 packet->type = rt_type; 353 354 if (libtrace->format_data == NULL) { 355 if (linuxnative_init_input(libtrace)) 356 return -1; 357 } 358 return 0; 359 360 } 361 333 362 #define LIBTRACE_MIN(a,b) ((a)<(b) ? (a) : (b)) 334 363 … … 344 373 socklen_t socklen; 345 374 int snaplen; 346 375 uint32_t flags = 0; 376 347 377 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 348 378 packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 349 packet->buf_control = TRACE_CTRL_PACKET;350 } 351 352 packet->header = packet->buffer;379 } 380 381 flags |= TRACE_PREP_OWN_BUFFER; 382 353 383 packet->type = TRACE_RT_DATA_LINUX_NATIVE; 354 packet->payload = (char*)packet->buffer+sizeof(*hdr);355 384 356 385 hdr=(struct libtrace_linuxnative_header*)packet->buffer; … … 398 427 perror("ioctl(SIOCGSTAMP)"); 399 428 429 if (linuxnative_prepare_packet(libtrace, packet, packet->buffer, 430 packet->type, flags)) 431 return -1; 432 400 433 return hdr->wirelen+sizeof(*hdr); 401 434 } … … 490 523 491 524 static int linuxnative_get_fd(const libtrace_t *trace) { 525 if (trace->format_data == NULL) 526 return -1; 492 527 return FORMAT(trace->format_data)->fd; 493 528 } … … 506 541 /* Number of packets that past filtering */ 507 542 static uint64_t linuxnative_get_captured_packets(libtrace_t *trace) { 543 if (trace->format_data == NULL) 544 return UINT64_MAX; 545 if (FORMAT(trace->format_data)->fd == -1) { 546 /* This is probably a 'dead' trace so obviously we can't query 547 * the socket for capture counts, can we? */ 548 return UINT64_MAX; 549 } 550 508 551 if ((FORMAT(trace->format_data)->stats_valid & 1) 509 552 || FORMAT(trace->format_data)->stats_valid == 0) { … … 524 567 */ 525 568 static uint64_t linuxnative_get_dropped_packets(libtrace_t *trace) { 569 if (trace->format_data == NULL) 570 return UINT64_MAX; 571 if (FORMAT(trace->format_data)->fd == -1) { 572 /* This is probably a 'dead' trace so obviously we can't query 573 * the socket for drop counts, can we? */ 574 return UINT64_MAX; 575 } 576 526 577 if ((FORMAT(trace->format_data)->stats_valid & 2) 527 578 || (FORMAT(trace->format_data)->stats_valid==0)) { … … 562 613 linuxnative_fin_output, /* fin_output */ 563 614 linuxnative_read_packet, /* read_packet */ 615 linuxnative_prepare_packet, /* prepare_packet */ 564 616 NULL, /* fin_packet */ 565 617 linuxnative_write_packet, /* write_packet */ -
lib/format_pcap.c
re632f2f rf0fb38f 266 266 } 267 267 268 static int pcap_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 269 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 270 271 if (packet->buffer != buffer && 272 packet->buf_control == TRACE_CTRL_PACKET) { 273 free(packet->buffer); 274 } 275 276 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 277 packet->buf_control = TRACE_CTRL_PACKET; 278 } else 279 packet->buf_control = TRACE_CTRL_EXTERNAL; 280 281 282 packet->buffer = buffer; 283 packet->header = buffer; 284 packet->type = rt_type; 285 286 /* Assuming header and payload are sequential in the buffer - 287 * regular pcap often doesn't work like this though, so hopefully 288 * we're not called by something that is reading genuine pcap! */ 289 packet->payload = (char *)packet->header + sizeof(struct pcap_pkthdr); 290 291 if (libtrace->format_data == NULL) { 292 if (pcap_init_input(libtrace)) 293 return -1; 294 } 295 return 0; 296 } 268 297 269 298 static int pcap_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 270 299 int ret = 0; 271 300 int linktype; 272 301 uint32_t flags = 0; 302 273 303 assert(libtrace->format_data); 274 304 linktype = pcap_datalink(DATA(libtrace)->input.pcap); 275 305 packet->type = pcap_linktype_to_rt(linktype); 276 277 packet->buf_control = TRACE_CTRL_PACKET;278 306 279 307 /* If we're using the replacement pcap_next_ex() we need to … … 287 315 return -1; 288 316 } 317 packet->header = packet->buffer; 318 packet->payload = (char *)packet->buffer+sizeof(struct pcap_pkthdr); 289 319 290 packet->header = packet->buffer; 291 packet->payload = (char *)packet->buffer + 292 sizeof(struct pcap_pkthdr); 293 } 320 } 321 322 flags |= TRACE_PREP_OWN_BUFFER; 294 323 295 324 for(;;) { … … 310 339 } 311 340 341 /* 342 * pcap is nasty in that the header and payload aren't 343 * necessarily located sequentially in memory, but most 344 * sensible uses of pcap_prepare_packet will involve a 345 * buffer where header and payload are sequential. 346 * 347 * Basically, don't call pcap_prepare_packet here! 348 * 349 if (pcap_prepare_packet(libtrace, packet, packet->buffer, 350 packet->type, flags)) { 351 return -1; 352 } 353 */ 312 354 return ((struct pcap_pkthdr*)packet->header)->len 313 355 +sizeof(struct pcap_pkthdr); … … 625 667 pcap_fin_output, /* fin_output */ 626 668 pcap_read_packet, /* read_packet */ 669 pcap_prepare_packet, /* prepare_packet */ 627 670 NULL, /* fin_packet */ 628 671 pcap_write_packet, /* write_packet */ … … 664 707 pcapint_fin_output, /* fin_output */ 665 708 pcap_read_packet, /* read_packet */ 709 pcap_prepare_packet, /* prepare_packet */ 666 710 NULL, /* fin_packet */ 667 711 pcapint_write_packet, /* write_packet */ -
lib/format_pcapfile.c
re632f2f rf0fb38f 223 223 } 224 224 225 static int pcapfile_prepare_packet(libtrace_t *libtrace, 226 libtrace_packet_t *packet, void *buffer, 227 libtrace_rt_types_t rt_type, uint32_t flags) { 228 229 if (packet->buffer != buffer && 230 packet->buf_control == TRACE_CTRL_PACKET) { 231 free(packet->buffer); 232 } 233 234 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 235 packet->buf_control = TRACE_CTRL_PACKET; 236 } else 237 packet->buf_control = TRACE_CTRL_EXTERNAL; 238 239 240 packet->buffer = buffer; 241 packet->header = buffer; 242 packet->payload = (char*)packet->buffer 243 + sizeof(libtrace_pcapfile_pkt_hdr_t); 244 packet->type = rt_type; 245 246 if (libtrace->format_data == NULL) { 247 if (pcapfile_init_input(libtrace)) 248 return -1; 249 } 250 251 return 0; 252 } 253 225 254 static int pcapfile_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) 226 255 { 227 256 int err; 228 257 uint32_t flags = 0; 258 229 259 assert(libtrace->format_data); 230 260 … … 234 264 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 235 265 packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 236 packet->buf_control = TRACE_CTRL_PACKET; 237 } 238 266 } 267 268 flags |= TRACE_PREP_OWN_BUFFER; 269 239 270 err=libtrace_io_read(DATA(libtrace)->file, 240 271 packet->buffer, … … 249 280 return 0; 250 281 } 251 252 packet->header = packet->buffer;253 254 282 255 283 err=libtrace_io_read(DATA(libtrace)->file, … … 267 295 } 268 296 269 packet->payload = (char*)packet->buffer 270 + sizeof(libtrace_pcapfile_pkt_hdr_t); 297 if (pcapfile_prepare_packet(libtrace, packet, packet->buffer, 298 packet->type, flags)) { 299 return -1; 300 } 271 301 272 302 return sizeof(libtrace_pcapfile_pkt_hdr_t) … … 544 574 pcapfile_fin_output, /* fin_output */ 545 575 pcapfile_read_packet, /* read_packet */ 576 pcapfile_prepare_packet, /* prepare_packet */ 546 577 NULL, /* fin_packet */ 547 578 pcapfile_write_packet, /* write_packet */ -
lib/format_rt.c
rf3f3558 rf0fb38f 188 188 } 189 189 190 191 static int rt_init_input(libtrace_t *libtrace) { 192 char *scan; 193 char *uridata = libtrace->uridata; 190 static void rt_init_format_data(libtrace_t *libtrace) { 194 191 libtrace->format_data = malloc(sizeof(struct rt_format_data_t)); 195 192 … … 201 198 RT_INFO->buf_current = NULL; 202 199 RT_INFO->buf_filled = 0; 200 RT_INFO->hostname = NULL; 201 RT_INFO->port = 0; 202 } 203 204 static int rt_init_input(libtrace_t *libtrace) { 205 char *scan; 206 char *uridata = libtrace->uridata; 207 208 rt_init_format_data(libtrace); 203 209 204 210 if (strlen(uridata) == 0) { … … 394 400 packet->trace = RT_INFO->dummy_linux; 395 401 break; 402 case TRACE_RT_STATUS: 403 case TRACE_RT_METADATA: 404 /* Just use the RT trace! */ 405 packet->trace = libtrace; 406 break; 396 407 case TRACE_RT_DATA_LEGACY_ETH: 397 408 case TRACE_RT_DATA_LEGACY_ATM: … … 407 418 return 0; /* success */ 408 419 } 409 410 static void rt_set_payload(libtrace_packet_t *packet) {411 dag_record_t *erfptr;412 413 switch (packet->type) {414 case TRACE_RT_DATA_ERF:415 erfptr = (dag_record_t *)packet->header;416 417 if (erfptr->flags.rxerror == 1) {418 packet->payload = NULL;419 break;420 }421 /* else drop into the default case */422 default:423 packet->payload = (char *)packet->buffer +424 trace_get_framing_length(packet);425 break;426 }427 }428 420 429 421 static int rt_send_ack(libtrace_t *libtrace, … … 475 467 } 476 468 477 469 static int rt_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 470 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 471 472 if (packet->buffer != buffer && 473 packet->buf_control == TRACE_CTRL_PACKET) { 474 free(packet->buffer); 475 } 476 477 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 478 packet->buf_control = TRACE_CTRL_PACKET; 479 } else 480 packet->buf_control = TRACE_CTRL_EXTERNAL; 481 482 483 packet->buffer = buffer; 484 packet->header = NULL; 485 packet->type = rt_type; 486 packet->payload = buffer; 487 488 if (libtrace->format_data == NULL) { 489 rt_init_format_data(libtrace); 490 } 491 492 return 0; 493 } 494 495 static int rt_read_data_packet(libtrace_t *libtrace, 496 libtrace_packet_t *packet, int blocking) { 497 uint32_t prep_flags = 0; 498 499 if (rt_read(libtrace, &packet->buffer, (size_t)RT_INFO->rt_hdr.length, 500 blocking) != RT_INFO->rt_hdr.length) { 501 return -1; 502 } 503 504 if (RT_INFO->reliable > 0 && packet->type >= TRACE_RT_DATA_SIMPLE) { 505 if (rt_send_ack(libtrace, RT_INFO->rt_hdr.sequence) == -1) 506 return -1; 507 } 508 509 if (rt_set_format(libtrace, packet) < 0) { 510 return -1; 511 } 512 513 /* Update payload pointers and loss counters correctly */ 514 if (trace_prepare_packet(packet->trace, packet, packet->buffer, 515 packet->type, prep_flags)) { 516 return -1; 517 } 518 519 return 0; 520 } 521 478 522 static int rt_read_packet_versatile(libtrace_t *libtrace, 479 523 libtrace_packet_t *packet,int blocking) { 480 524 rt_header_t *pkt_hdr = NULL; 481 525 void *void_hdr; 526 libtrace_rt_types_t switch_type; 482 527 483 528 if (packet->buf_control == TRACE_CTRL_PACKET) { … … 506 551 } 507 552 packet->type = RT_INFO->rt_hdr.type; 508 509 553 510 554 if (packet->type >= TRACE_RT_DATA_SIMPLE) { 511 if (rt_read(libtrace, 512 &packet->buffer, 513 (size_t)RT_INFO->rt_hdr.length, 514 blocking) != RT_INFO->rt_hdr.length) { 555 switch_type = TRACE_RT_DATA_SIMPLE; 556 } else { 557 switch_type = packet->type; 558 } 559 560 switch(switch_type) { 561 case TRACE_RT_DATA_SIMPLE: 562 case TRACE_RT_DUCK_2_4: 563 case TRACE_RT_DUCK_2_5: 564 case TRACE_RT_STATUS: 565 case TRACE_RT_METADATA: 566 if (rt_read_data_packet(libtrace, packet, blocking)) 567 return -1; 568 break; 569 case TRACE_RT_END_DATA: 570 case TRACE_RT_KEYCHANGE: 571 case TRACE_RT_LOSTCONN: 572 case TRACE_RT_CLIENTDROP: 573 case TRACE_RT_SERVERSTART: 574 /* All these have no payload */ 575 break; 576 case TRACE_RT_PAUSE_ACK: 577 /* XXX: Add support for this */ 578 break; 579 case TRACE_RT_OPTION: 580 /* XXX: Add support for this */ 581 break; 582 default: 583 printf("Bad rt type for client receipt: %d\n", 584 switch_type); 515 585 return -1; 516 } 517 packet->header = packet->buffer; 586 } 587 588 518 589 519 if (RT_INFO->reliable > 0) {520 if (rt_send_ack(libtrace, RT_INFO->rt_hdr.sequence)521 == -1)522 {523 return -1;524 }525 }526 527 528 if (rt_set_format(libtrace, packet) < 0) {529 return -1;530 }531 rt_set_payload(packet);532 } else {533 switch(packet->type) {534 case TRACE_RT_STATUS:535 case TRACE_RT_METADATA:536 if (rt_read(libtrace, &packet->buffer,537 (size_t)RT_INFO->rt_hdr.length,538 blocking) !=539 RT_INFO->rt_hdr.length) {540 return -1;541 }542 packet->header = 0;543 packet->payload = packet->buffer;544 break;545 case TRACE_RT_DUCK_2_4:546 case TRACE_RT_DUCK_2_5:547 if (rt_read(libtrace, &packet->buffer,548 (size_t)RT_INFO->rt_hdr.length,549 blocking) !=550 RT_INFO->rt_hdr.length) {551 return -1;552 }553 if (rt_set_format(libtrace, packet) < 0) {554 return -1;555 }556 packet->header = 0;557 packet->payload = packet->buffer;558 break;559 case TRACE_RT_END_DATA:560 break;561 case TRACE_RT_PAUSE_ACK:562 /* FIXME: Do something useful */563 break;564 case TRACE_RT_OPTION:565 /* FIXME: Do something useful here as well */566 break;567 case TRACE_RT_KEYCHANGE:568 break;569 case TRACE_RT_LOSTCONN:570 break;571 case TRACE_RT_SERVERSTART:572 break;573 case TRACE_RT_CLIENTDROP:574 break;575 default:576 printf("Bad rt type for client receipt: %d\n",577 packet->type);578 return -1;579 }580 }581 590 /* Return the number of bytes read from the stream */ 582 591 RT_INFO->rt_hdr.type = TRACE_RT_LAST; … … 711 720 NULL, /* fin_output */ 712 721 rt_read_packet, /* read_packet */ 722 rt_prepare_packet, /* prepare_packet */ 713 723 NULL, /* fin_packet */ 714 724 NULL, /* write_packet */ -
lib/format_tsh.c
rd186e42 rf0fb38f 89 89 } 90 90 91 static int tsh_prepare_packet(libtrace_t *libtrace, libtrace_packet_t *packet, 92 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 93 if (packet->buffer != buffer && 94 packet->buf_control == TRACE_CTRL_PACKET) { 95 free(packet->buffer); 96 } 97 98 if ((flags & TRACE_PREP_OWN_BUFFER) == TRACE_PREP_OWN_BUFFER) { 99 packet->buf_control = TRACE_CTRL_PACKET; 100 } else 101 packet->buf_control = TRACE_CTRL_EXTERNAL; 102 103 104 packet->buffer = buffer; 105 packet->header = buffer; 106 packet->type = rt_type; 107 packet->payload = (char *)packet->buffer + sizeof(tsh_pkt_header_t); 108 109 if (libtrace->format_data == NULL) { 110 if (tsh_init_input(libtrace)) 111 return -1; 112 } 113 114 return 0; 115 } 116 91 117 static int tsh_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 92 118 int numbytes; 93 119 void *buffer2 = packet->buffer; 120 uint32_t flags = 0; 94 121 95 122 if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) { 96 123 packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE); 97 packet->buf_control = TRACE_CTRL_PACKET;98 124 if (!packet->buffer) { 99 125 trace_set_err(libtrace, errno, … … 103 129 } 104 130 105 packet->header = packet->buffer;131 flags |= TRACE_PREP_OWN_BUFFER; 106 132 packet->type = TRACE_RT_DATA_TSH; 107 133 … … 122 148 123 149 buffer2 = (char*)buffer2 + numbytes; 124 packet->payload = buffer2;125 150 126 151 /* Read the IP header */ … … 147 172 return -1; 148 173 } 174 175 if (tsh_prepare_packet(libtrace, packet, packet->buffer, packet->type, 176 flags)) { 177 return -1; 178 } 179 149 180 150 181 return 80; … … 205 236 NULL, /* fin_output */ 206 237 tsh_read_packet, /* read_packet */ 238 tsh_prepare_packet, /* prepare_packet */ 207 239 NULL, /* fin_packet */ 208 240 NULL, /* write_packet */ … … 249 281 NULL, /* fin_output */ 250 282 tsh_read_packet, /* read_packet */ 283 tsh_prepare_packet, /* prepare_packet */ 251 284 NULL, /* fin_packet */ 252 285 NULL, /* write_packet */ -
lib/libtrace.h.in
rf3f3558 rf0fb38f 304 304 TRACE_RT_DATA_LEGACY_ETH=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LEGACY_ETH, 305 305 TRACE_RT_DATA_LINUX_NATIVE=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LINUX_NATIVE, 306 TRACE_RT_DATA_BPF =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_BPF, 306 307 TRACE_RT_DATA_TSH =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_TSH, 307 308 -
lib/libtrace_int.h
r2faa57e rf0fb38f 167 167 PRINTF(3,4); 168 168 169 170 /* 171 * 172 * The basic idea of this function is that it will take the data pointed to 173 * by 'buffer' and treat it as a packet of the same format type as the 174 * libtrace_t pointed to by 'trace', including the format framing (e.g. an 175 * erf header for erf and dag formats, a pcap header for pcap formats). 176 * 177 * The libtrace packet pointed to by 'packet' will then have its internal 178 * pointers and values replaced with ones that describe the packet in 'buffer'. 179 * 180 * 'rt_type' is used to set packet->type while 'flags' is relatively 181 * self-explanatory. Definitions of the accepted flags will be provided below. 182 * 183 * The primary use of this function is to allow rt_read_packet to nicely 184 * convert packets from the RT format back to the format that they were 185 * originally captured with, as RT essentially encapsulates the original trace 186 * format. We've decided to not make this function available via the API 187 * because there are a number of issues that can arise if it is not used 188 * very carefully and there are few situations outside of the RT case where 189 * you'd want to do something like this anyway. 190 * 191 * Returns 0 if successful, -1 if something goes horribly wrong 192 */ 193 int trace_prepare_packet(libtrace_t *trace, libtrace_packet_t *packet, 194 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags); 195 196 /* Flags for prepare_packet functions */ 197 /*-------------------------------------*/ 198 /* If set, the memory pointed to by 'buffer' is malloc()'d and libtrace should 199 * undertake ownership of that memory. If not set, the memory is treated as 200 * externally-owned and will not be freed by libtrace when the packet is 201 * destroyed. */ 202 #define TRACE_PREP_OWN_BUFFER 1 203 204 169 205 typedef struct libtrace_sll_header_t { 170 206 uint16_t pkttype; /* packet type */ … … 247 283 */ 248 284 int (*read_packet)(libtrace_t *libtrace, libtrace_packet_t *packet); 285 /** prepares a packet for general libtrace usage 286 * updates internal trace and packet details, such as payload pointers, 287 * loss counters and packet types. 288 * Intended (at this stage) only for internal use, particularly by 289 * RT which needs to decapsulate RT packets */ 290 int (*prepare_packet)(libtrace_t *libtrace, libtrace_packet_t *packet, 291 void *buffer, libtrace_rt_types_t rt_type, 292 uint32_t flags); 249 293 /** finalise a packet 250 294 * cleanup any resources used by a packet that can't be reused for -
lib/trace.c
rf3f3558 rf0fb38f 622 622 DLLEXPORT void trace_destroy_dead(libtrace_t *libtrace) { 623 623 assert(libtrace); 624 if (libtrace->format_data) 625 free(libtrace->format_data); 624 626 free(libtrace); 625 627 } … … 761 763 } 762 764 765 int trace_prepare_packet(libtrace_t *trace, libtrace_packet_t *packet, 766 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 767 768 assert(packet); 769 assert(trace); 770 771 /* XXX Proper error handling?? */ 772 if (buffer == NULL) 773 return -1; 774 775 if (!(packet->buf_control==TRACE_CTRL_PACKET || packet->buf_control==TRACE_CTRL_EXTERNAL)) { 776 trace_set_err(trace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid\n"); 777 return -1; 778 } 779 780 packet->trace = trace; 781 782 /* Clear packet cache */ 783 packet->capture_length = -1; 784 packet->l3_header = NULL; 785 packet->l3_ethertype = 0; 786 787 if (trace->format->prepare_packet) { 788 return trace->format->prepare_packet(trace, packet, 789 buffer, rt_type, flags); 790 } 791 trace_set_err(trace, TRACE_ERR_UNSUPPORTED, 792 "This format does not support preparing packets\n"); 793 return -1; 794 795 } 796 763 797 /* Writes a packet to the specified output 764 798 * … … 1595 1629 } 1596 1630 1631 1597 1632 uint64_t trace_get_received_packets(libtrace_t *trace) 1598 1633 {
Note: See TracChangeset
for help on using the changeset viewer.