From 387771c12b53e742a94195dd908e54b2063320e6 Mon Sep 17 00:00:00 2001 From: robertdavidgraham Date: Sun, 5 Jan 2014 02:30:36 -0500 Subject: [PATCH] status line: wait message --- src/main-globals.h | 1 - src/main-status.c | 21 ++++++++++---- src/main-status.h | 2 +- src/main.c | 71 +++++++++++++++++++++++++++++++++++++--------- src/proto-tcp.c | 6 ---- 5 files changed, 74 insertions(+), 27 deletions(-) diff --git a/src/main-globals.h b/src/main-globals.h index 911120ac..1c9abe3d 100644 --- a/src/main-globals.h +++ b/src/main-globals.h @@ -5,6 +5,5 @@ extern unsigned control_c_pressed; extern time_t global_now; -extern uint64_t global_tcb_count; #endif diff --git a/src/main-status.c b/src/main-status.c index 15d5dcff..b450bb59 100644 --- a/src/main-status.c +++ b/src/main-status.c @@ -30,7 +30,8 @@ status_print( double x, uint64_t total_tcbs, uint64_t total_synacks, - uint64_t total_syns) + uint64_t total_syns, + uint64_t exiting) { double elapsed_time; double rate; @@ -135,10 +136,19 @@ status_print( syn_rate, synack_rate, tcb_rate, - global_tcb_count + total_tcbs ); - } else if (rate > 0) { - fprintf(stderr, + } else { + if (control_c_pressed) { + fprintf(stderr, + "rate:%6.2f-kpps, %5.2f%% done, waiting %llu-secs, found=%llu \r", + x/1000.0, + percent_done, + exiting, + total_synacks + ); + } else { + fprintf(stderr, "rate:%6.2f-kpps, %5.2f%% done,%4u:%02u:%02u remaining, found=%llu \r", x/1000.0, percent_done, @@ -146,9 +156,8 @@ status_print( (unsigned)(time_remaining/60)%60, (unsigned)(time_remaining)%60, total_synacks - //global_tcb_count, - //synack_rate ); + } } fflush(stderr); diff --git a/src/main-status.h b/src/main-status.h index e981a76e..a458fb98 100644 --- a/src/main-status.h +++ b/src/main-status.h @@ -24,7 +24,7 @@ struct Status }; -void status_print(struct Status *status, uint64_t count, uint64_t max_count, double x, uint64_t total_tcbs, uint64_t total_synacks, uint64_t total_syns); +void status_print(struct Status *status, uint64_t count, uint64_t max_count, double x, uint64_t total_tcbs, uint64_t total_synacks, uint64_t total_syns, uint64_t exiting); void status_finish(struct Status *status); void status_start(struct Status *status); diff --git a/src/main.c b/src/main.c index f36f8929..9fa06dac 100644 --- a/src/main.c +++ b/src/main.c @@ -271,15 +271,24 @@ transmit_thread(void *v) /*aka. scanning_thread() */ unsigned src_port_mask; uint64_t seed = masscan->seed; uint64_t repeats = 0; /* --infinite repeats */ - uint64_t total_syns = 0; + uint64_t *status_syn_count; + + LOG(1, "xmit: starting transmit thread #%u\n", parms->nic_index); + + /* export a pointer to this variable outside this threads so + * that the 'status' system can print the rate of syns we are + * sending */ + status_syn_count = (uint64_t*)malloc(sizeof(uint64_t)); + *status_syn_count = 0; + parms->total_syns = status_syn_count; - parms->total_syns = &total_syns; + /* Normally, we have just one source address. In special cases, though + * we can have multiple. */ get_sources(masscan, parms->nic_index, &src_ip, &src_ip_mask, &src_port, &src_port_mask); - LOG(1, "xmit: starting transmit thread #%u\n", parms->nic_index); /* "THROTTLER" rate-limits how fast we transmit, set with the * --max-rate parameter */ @@ -399,7 +408,7 @@ transmit_thread(void *v) /*aka. scanning_thread() */ ); batch_size--; packets_sent++; - total_syns++; + (*status_syn_count)++; /* * SEQUENTIALLY INCREMENT THROUGH THE RANGE @@ -448,6 +457,8 @@ transmit_thread(void *v) /*aka. scanning_thread() */ */ rawsock_flush(adapter); + control_c_pressed = 1; + /* * We are done transmitting. However, response packets will take several * seconds to arrive. Therefore, sit in short loop waiting for those @@ -519,11 +530,17 @@ receive_thread(void *v) struct DedupTable *dedup; struct PcapFile *pcapfile = NULL; struct TCP_ConnectionTable *tcpcon = 0; - uint64_t total_synacks = 0; - uint64_t total_tcbs = 0; + uint64_t *status_synack_count; + uint64_t *status_tcb_count; - parms->total_synacks = &total_synacks; - parms->total_tcbs = &total_tcbs; + /* some status variables */ + status_synack_count = (uint64_t*)malloc(sizeof(uint64_t)); + *status_synack_count = 0; + parms->total_synacks = status_synack_count; + + status_tcb_count = (uint64_t*)malloc(sizeof(uint64_t)); + *status_tcb_count = 0; + parms->total_tcbs = status_tcb_count; LOG(1, "recv: start receive thread #%u\n", parms->nic_index); @@ -780,7 +797,7 @@ receive_thread(void *v) ip_me, ip_them, port_me, port_them, seqno_me, seqno_them+1); - total_tcbs++; + (*status_tcb_count)++; } tcpcon_handle(tcpcon, tcb, TCP_WHAT_SYNACK, @@ -850,7 +867,7 @@ receive_thread(void *v) /* verify: ignore duplicates */ if (dedup_is_duplicate(dedup, ip_them, port_them, ip_me, port_me)) continue; - total_synacks++; + (*status_synack_count)++; /* * This is where we do the output @@ -907,6 +924,7 @@ receive_thread(void *v) /* Thread is about to exit */ parms->done_receiving = 1; + } @@ -1179,7 +1197,8 @@ main_scan(struct Masscan *masscan) * namely packets/second. */ status_print(&status, min_index, range, rate, - total_tcbs, total_synacks, total_syns); + total_tcbs, total_synacks, total_syns, + 0); /* Sleep for almost a second */ pixie_mssleep(750); @@ -1204,10 +1223,34 @@ main_scan(struct Masscan *masscan) unsigned transmit_count = 0; unsigned receive_count = 0; unsigned i; + double rate = 0; + uint64_t total_tcbs = 0; + uint64_t total_synacks = 0; + uint64_t total_syns = 0; - pixie_mssleep(750); - status_print(&status, masscan->resume.index, range, 0, 0, 0, 0); + /* Find the minimum index of all the threads */ + min_index = UINT64_MAX; + for (i=0; inic_count; i++) { + struct ThreadPair *parms = &parms_array[i]; + + if (min_index > parms->my_index) + min_index = parms->my_index; + + rate += parms->throttler->current_rate; + + if (parms->total_tcbs) + total_tcbs += *parms->total_tcbs; + if (parms->total_synacks) + total_synacks += *parms->total_synacks; + if (parms->total_syns) + total_syns += *parms->total_syns; + } + + + status_print(&status, masscan->resume.index, range, rate, + total_tcbs, total_synacks, total_syns, + masscan->wait - (time(0) - now)); if (time(0) - now >= masscan->wait) control_c_pressed_again = 1; @@ -1220,6 +1263,8 @@ main_scan(struct Masscan *masscan) } + pixie_mssleep(750); + if (transmit_count < masscan->nic_count) continue; control_c_pressed = 1; diff --git a/src/proto-tcp.c b/src/proto-tcp.c index 5cac9cb8..490fb639 100644 --- a/src/proto-tcp.c +++ b/src/proto-tcp.c @@ -24,10 +24,6 @@ #include "string_s.h" #include "main-globals.h" -/* [GLOBALS] - * I want to print the number of TCBs in status messages, so I'm hacking this count - * in here */ -uint64_t global_tcb_count; /*************************************************************************** @@ -377,7 +373,6 @@ tcpcon_destroy_tcb( tcb->next = tcpcon->freed_list; tcpcon->freed_list = tcb; tcpcon->active_count--; - global_tcb_count = tcpcon->active_count; } @@ -469,7 +464,6 @@ tcpcon_create_tcb( banout_init(&tcb->banout); tcpcon->active_count++; - global_tcb_count = tcpcon->active_count; } return tcb;