On 2015-11-12 at 07:54:19 +0100, Vadim Kochan <[email protected]> wrote:
> Now it is possible toggle display TCP/UDP/DCCP/ICMP/SCTP protos
> by the same char keys as short command line options - T/U/D/I/S.
>
> Signed-off-by: Vadim Kochan <[email protected]>
> ---
> flowtop.c | 69
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 65 insertions(+), 4 deletions(-)
>
> diff --git a/flowtop.c b/flowtop.c
> index 4c6f383..b6d3a08 100644
> --- a/flowtop.c
> +++ b/flowtop.c
> @@ -104,6 +104,14 @@ enum flow_direction {
> #define INCLUDE_ICMP (1 << 5)
> #define INCLUDE_SCTP (1 << 6)
>
> +#define TOGGLE_FLAG(what, flag) \
> +do { \
> + if (what & flag) \
> + what &= ~flag; \
> + else \
> + what |= flag; \
> +} while (0)
> +
> struct sysctl_params_ctx {
> int nfct_acct;
> int nfct_tstamp;
> @@ -114,6 +122,7 @@ enum rate_units {
> RATE_BYTES
> };
>
> +static volatile bool do_reload_flows;
> static volatile bool is_flow_collecting;
> static volatile sig_atomic_t sigint = 0;
> static int what = INCLUDE_IPV4 | INCLUDE_IPV6 | INCLUDE_TCP;
> @@ -462,7 +471,6 @@ static void flow_list_destroy(struct flow_list *fl)
> }
>
> synchronize_rcu();
> - spinlock_destroy(&fl->lock);
> }
>
> static int walk_process(unsigned int pid, struct flow_entry *n)
> @@ -1186,8 +1194,14 @@ static void draw_help(WINDOW *screen)
> mvaddnstr(row + 9, col + 2, "Display Settings", -1);
> attroff(A_BOLD | A_UNDERLINE);
>
> - mvaddnstr(row + 11, col + 3, "b Toggle rate units
> (bits/bytes)", -1);
> - mvaddnstr(row + 12, col + 3, "a Toggle display of active
> flows (rate > 0) only", -1);
> + mvaddnstr(row + 11, col + 3, "b Toggle rate units (bits/bytes)",
> -1);
> + mvaddnstr(row + 12, col + 3, "a Toggle display of active flows
> (rate > 0) only", -1);
> +
> + mvaddnstr(row + 14, col + 3, "T Toggle display TCP flows", -1);
> + mvaddnstr(row + 15, col + 3, "U Toggle display UDP flows", -1);
> + mvaddnstr(row + 16, col + 3, "D Toggle display DCCP flows", -1);
> + mvaddnstr(row + 17, col + 3, "I Toggle display ICMP flows", -1);
> + mvaddnstr(row + 18, col + 3, "S Toggle display SCTP flows", -1);
> }
>
> static void draw_header(WINDOW *screen)
> @@ -1217,6 +1231,27 @@ static void draw_footer(WINDOW *screen)
> attroff(A_STANDOUT);
> }
>
> +static void show_option_toggle(int opt)
> +{
> + switch (opt) {
> + case 'T':
> + TOGGLE_FLAG(what, INCLUDE_TCP);
> + break;
> + case 'U':
> + TOGGLE_FLAG(what, INCLUDE_UDP);
> + break;
> + case 'D':
> + TOGGLE_FLAG(what, INCLUDE_DCCP);
> + break;
> + case 'I':
> + TOGGLE_FLAG(what, INCLUDE_ICMP);
> + break;
> + case 'S':
> + TOGGLE_FLAG(what, INCLUDE_SCTP);
> + break;
> + }
> +}
> +
> static void presenter(void)
> {
> int time_sleep_us = 200000;
> @@ -1238,11 +1273,13 @@ static void presenter(void)
> rcu_register_thread();
> while (!sigint) {
> bool redraw_flows = true;
> + int ch;
>
> curs_set(0);
> getmaxyx(screen, rows, cols);
>
> - switch (getch()) {
> + ch = getch();
> + switch (ch) {
> case 'q':
> sigint = 1;
> break;
> @@ -1274,6 +1311,18 @@ static void presenter(void)
> wclear(screen);
> clear();
> break;
> + case 'T':
> + case 'U':
> + case 'D':
> + case 'I':
> + case 'S':
> + if (is_flow_collecting)
> + break;
In this case we will silently discard the user input, which is not very
nice. Do you see any reasonable way to avoid that?
> +
> + show_option_toggle(ch);
> +
> + do_reload_flows = true;
> + break;
> default:
> fflush(stdin);
> redraw_flows = false;
> @@ -1606,11 +1655,21 @@ static void *collector(void *null __maybe_unused)
>
> rcu_register_thread();
>
> +reload:
> + if (do_reload_flows)
> + collector_create_filter(ct_event);
> +
> + do_reload_flows = false;
> collector_dump_flows();
>
> while (!sigint) {
> int status;
>
> + if (do_reload_flows) {
> + flow_list_destroy(&flow_list);
> + goto reload;
Ugh, I don't like jumping out of the loop here, even if it saves some
code duplication. But in that case I'd rather opt for duplicating the 4
LoC above.
Otherwise looks good to me.
> + }
> +
> usleep(USEC_PER_SEC * interval);
>
> collector_refresh_flows(ct_update);
> @@ -1632,6 +1691,8 @@ static void *collector(void *null __maybe_unused)
> rcu_unregister_thread();
>
> flow_list_destroy(&flow_list);
> + spinlock_destroy(&flow_list.lock);
> +
> nfct_close(ct_event);
> nfct_close(ct_update);
>
> --
> 2.6.2
>
--
You received this message because you are subscribed to the Google Groups
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.