MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sctp_packet_log

Function sctp_packet_log

freebsd/netinet/sctp_bsd_addr.c:387–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

385
386#ifdef SCTP_PACKET_LOGGING
387void
388sctp_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);
414try_again:
415 if (SCTP_BASE_VAR(packet_log_writers) > SCTP_PKTLOG_WRITERS_NEED_LOCK) {
416 SCTP_IP_PKTLOG_LOCK();
417 grabbed_lock = 1;
418again_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;

Callers 4

sctp_send_resp_msgFunction · 0.85
sctp_input_with_portFunction · 0.85
sctp6_input_with_portFunction · 0.85

Calls 1

m_copydataFunction · 0.85

Tested by

no test coverage detected