| 385 | |
| 386 | #ifdef SCTP_PACKET_LOGGING |
| 387 | void |
| 388 | sctp_packet_log(struct mbuf *m) |
| 389 | { |
| 390 | int *lenat, thisone; |
| 391 | void *copyto; |
| 392 | uint32_t *tick_tock; |
| 393 | int length; |
| 394 | int total_len; |
| 395 | int grabbed_lock = 0; |
| 396 | int value, newval, thisend, thisbegin; |
| 397 | |
| 398 | /* |
| 399 | * Buffer layout. -sizeof this entry (total_len) -previous end |
| 400 | * (value) -ticks of log (ticks) o -ip packet o -as logged - |
| 401 | * where this started (thisbegin) x <--end points here |
| 402 | */ |
| 403 | length = SCTP_HEADER_LEN(m); |
| 404 | total_len = SCTP_SIZE32((length + (4 * sizeof(int)))); |
| 405 | /* Log a packet to the buffer. */ |
| 406 | if (total_len > SCTP_PACKET_LOG_SIZE) { |
| 407 | /* Can't log this packet I have not a buffer big enough */ |
| 408 | return; |
| 409 | } |
| 410 | if (length < (int)(SCTP_MIN_V4_OVERHEAD + sizeof(struct sctp_cookie_ack_chunk))) { |
| 411 | return; |
| 412 | } |
| 413 | atomic_add_int(&SCTP_BASE_VAR(packet_log_writers), 1); |
| 414 | try_again: |
| 415 | if (SCTP_BASE_VAR(packet_log_writers) > SCTP_PKTLOG_WRITERS_NEED_LOCK) { |
| 416 | SCTP_IP_PKTLOG_LOCK(); |
| 417 | grabbed_lock = 1; |
| 418 | again_locked: |
| 419 | value = SCTP_BASE_VAR(packet_log_end); |
| 420 | newval = SCTP_BASE_VAR(packet_log_end) + total_len; |
| 421 | if (newval >= SCTP_PACKET_LOG_SIZE) { |
| 422 | /* we wrapped */ |
| 423 | thisbegin = 0; |
| 424 | thisend = total_len; |
| 425 | } else { |
| 426 | thisbegin = SCTP_BASE_VAR(packet_log_end); |
| 427 | thisend = newval; |
| 428 | } |
| 429 | if (!(atomic_cmpset_int(&SCTP_BASE_VAR(packet_log_end), value, thisend))) { |
| 430 | goto again_locked; |
| 431 | } |
| 432 | } else { |
| 433 | value = SCTP_BASE_VAR(packet_log_end); |
| 434 | newval = SCTP_BASE_VAR(packet_log_end) + total_len; |
| 435 | if (newval >= SCTP_PACKET_LOG_SIZE) { |
| 436 | /* we wrapped */ |
| 437 | thisbegin = 0; |
| 438 | thisend = total_len; |
| 439 | } else { |
| 440 | thisbegin = SCTP_BASE_VAR(packet_log_end); |
| 441 | thisend = newval; |
| 442 | } |
| 443 | if (!(atomic_cmpset_int(&SCTP_BASE_VAR(packet_log_end), value, thisend))) { |
| 444 | goto try_again; |
no test coverage detected