diff -Naur gkrellm-2.1.23/server/monitor.c gkrellm-2.1.23i/server/monitor.c --- gkrellm-2.1.23/server/monitor.c 2003-10-05 20:40:18.000000000 -0600 +++ gkrellm-2.1.23i/server/monitor.c 2003-12-21 14:16:43.000000000 -0700 @@ -571,41 +571,63 @@ gint slen; tcp = (ActiveTCP *) data; - for (list = inet_list; list; list = list->next) + switch (tcp->chain) { - in = (InetData *) list->data; - active_tcp = &in->tcp; - if (tcp->family == AF_INET) - { - ap = (char *)&tcp->remote_addr; - aap = (char *)&active_tcp->remote_addr; - slen = sizeof(struct in_addr); - } + case CHAIN_CONNECT: + for (list = inet_list; list; list = list->next) + { + in = (InetData *) list->data; + active_tcp = &in->tcp; + if (tcp->family == AF_INET) + { + ap = (char *)&tcp->remote_addr; + aap = (char *)&active_tcp->remote_addr; + slen = sizeof(struct in_addr); + } #if defined(INET6) - else if (tcp->family == AF_INET6) - { - ap = (char *)&tcp->remote_addr6; - aap = (char *)&active_tcp->remote_addr6; - slen = sizeof(struct in6_addr); - } + else if (tcp->family == AF_INET6) + { + ap = (char *)&tcp->remote_addr6; + aap = (char *)&active_tcp->remote_addr6; + slen = sizeof(struct in6_addr); + } #endif - else - return; - if ( memcmp(aap, ap, slen) == 0 - && active_tcp->remote_port == tcp->remote_port - && active_tcp->local_port == tcp->local_port - ) - { - in->alive = TRUE; /* Old alive connection still alive */ - return; - } + else + return; + + if ( memcmp(aap, ap, slen) == 0 + && active_tcp->remote_port == tcp->remote_port + && active_tcp->local_port == tcp->local_port + ) + { + in->alive = TRUE; /* Old alive connection still alive */ + return; + } + } + inet_new = TRUE; + in = g_new0(InetData, 1); + in->tcp = *tcp; + in->alive = TRUE; + in->new_connection = TRUE; + inet_list = g_list_append(inet_list, in); + break; + + default: +#if 0 +fprintf(stderr, "%lu local %d:%d remote %d:%d chain %d line %d target %d pkts %Lu bytes %Lu\n", time(0L), + tcp->local_port, tcp->local_port_hi, + tcp->remote_port, tcp->remote_port_hi, + tcp->chain, tcp->line, tcp->target, tcp->pkts, tcp->bytes); + +#endif + inet_new = TRUE; + in = g_new0(InetData, 1); + in->tcp = *tcp; + in->alive = TRUE; + in->new_connection = TRUE; + inet_list = g_list_append(inet_list, in); + break; } - inet_new = TRUE; - in = g_new0(InetData, 1); - in->tcp = *tcp; - in->alive = TRUE; - in->new_connection = TRUE; - inet_list = g_list_append(inet_list, in); } void @@ -669,7 +691,7 @@ InetData *in; ActiveTCP *tcp; GList *list; - gchar buf[128], *d, *s, *cp; + gchar buf[256], *d, *s, *cp; #if defined(INET6) && defined(HAVE_GETADDRINFO) struct sockaddr_in6 sin6; char addrbuf[NI_MAXHOST]; @@ -677,6 +699,7 @@ if (client->served && (!GK.second_tick || (!inet_new && !inet_dead_list))) return NULL; + s = g_strdup(""); if (inet_new || !client->served) { @@ -684,43 +707,64 @@ { in = (InetData *) list->data; tcp = &in->tcp; - if ( tcp->family == AF_INET - && (in->new_connection || !client->served) - ) + switch (tcp->chain) { - cp = inet_ntoa(tcp->remote_addr); - sprintf(buf, "+0 %x %s:%x\n", - tcp->local_port, cp, tcp->remote_port); - d = g_strconcat(s, buf, NULL); - g_free(s); - s = d; - } + case CHAIN_CONNECT: + if ( tcp->family == AF_INET + && (in->new_connection || !client->served) + ) + { + cp = inet_ntoa(tcp->remote_addr); + sprintf(buf, "+0 %x %s:%x\n", + tcp->local_port, cp, tcp->remote_port); + d = g_strconcat(s, buf, NULL); + g_free(s); + s = d; + } #if defined(INET6) && defined(HAVE_GETADDRINFO) - else if (tcp->family == AF_INET6 - && (in->new_connection || !client->served)) - { - memset(&sin6, 0, sizeof(sin6)); - memcpy(&sin6.sin6_addr, &tcp->remote_addr6, - sizeof(struct in6_addr)); - sin6.sin6_family = AF_INET6; + else if (tcp->family == AF_INET6 + && (in->new_connection || !client->served)) + { + memset(&sin6, 0, sizeof(sin6)); + memcpy(&sin6.sin6_addr, &tcp->remote_addr6, + sizeof(struct in6_addr)); + sin6.sin6_family = AF_INET6; #ifdef SIN6_LEN - sin6.sin6_len = sizeof(struct sockaddr_in6); + sin6.sin6_len = sizeof(struct sockaddr_in6); #endif - if (getnameinfo((struct sockaddr *)&sin6, - sizeof(struct sockaddr_in6), - addrbuf, sizeof(addrbuf), - NULL, 0, - NI_NUMERICHOST|NI_WITHSCOPEID) - != 0) - continue; - snprintf(buf, sizeof(buf), "+6 %x [%s]:%x\n", - tcp->local_port, addrbuf, - tcp->remote_port); - d = g_strconcat(s, buf, NULL); - g_free(s); - s = d; - } + if (getnameinfo((struct sockaddr *)&sin6, + sizeof(struct sockaddr_in6), + addrbuf, sizeof(addrbuf), + NULL, 0, + NI_NUMERICHOST|NI_WITHSCOPEID) + != 0) + continue; + snprintf(buf, sizeof(buf), "+6 %x [%s]:%x\n", + tcp->local_port, addrbuf, + tcp->remote_port); + d = g_strconcat(s, buf, NULL); + g_free(s); + s = d; + } + break; +#endif + default: + if (in->new_connection || !client->served) + { + snprintf(buf, sizeof(buf), "*F %x:%x %x:%x %d:%d:%d %Lu:%Lu\n", + tcp->local_port, tcp->local_port_hi, + tcp->remote_port, tcp->remote_port_hi, + tcp->chain, tcp->line, tcp->target, tcp->pkts, tcp->bytes); + d = g_strconcat(s, buf, NULL); + g_free(s); + s = d; + in->alive = FALSE; +#if 0 +fprintf(stderr, "serving buf=%s", buf); #endif + } + break; + } } } if (client->served) diff -Naur gkrellm-2.1.23/src/chart.c gkrellm-2.1.23i/src/chart.c --- gkrellm-2.1.23/src/chart.c 2003-10-07 11:32:38.000000000 -0600 +++ gkrellm-2.1.23i/src/chart.c 2003-12-21 14:16:43.000000000 -0700 @@ -62,7 +62,7 @@ return chart_list; } -gint +gint64 gkrellm_get_chart_scalemax(GkrellmChart *cp) { if (!cp) @@ -70,7 +70,7 @@ return cp->scale_max; } -gint +gint64 gkrellm_get_current_chartdata(GkrellmChartdata *cd) { if (!cd) @@ -78,7 +78,7 @@ return cd->data[cd->chart->position]; } -gint +gint64 gkrellm_get_chartdata_data(GkrellmChartdata *cd, gint index) { gint x; @@ -247,7 +247,7 @@ } static gint -chartdata_ycoord(GkrellmChart *cp, GkrellmChartdata *cd, gint yd) +chartdata_ycoord(GkrellmChart *cp, GkrellmChartdata *cd, gint64 yd) { glong y; guint64 Y; @@ -261,7 +261,7 @@ y = Y / cp->scale_max; } else - y = ((glong) yd * cd->h / cp->scale_max); + y = (yd * cd->h / cp->scale_max); if (y < 0) y = 0; @@ -357,7 +357,8 @@ { GList *list; GkrellmChartdata *cd; - gint n, x, y, y0, y1, yN, yI; + gint n, x, y, y0, y1; + gint64 yN, yI; gint current_split; gboolean need_next_split = FALSE; @@ -499,7 +500,7 @@ /* See the README for description of auto grid resolution behavior. */ static void -set_auto_grid_resolution(GkrellmChart *cp, gint maxval) +set_auto_grid_resolution(GkrellmChart *cp, gint64 maxval) { static void set_grid_resolution_spin_button(GkrellmChart *, gint); GkrellmChartconfig *cf = cp->config; @@ -553,7 +554,7 @@ setup_chart_scalemax(GkrellmChart *cp) { GkrellmChartconfig *cf = cp->config; - glong scalemax; + gint64 scalemax; gint grid_res, i0; /* maxval may change at any gkrellm_store_chartdata(), so at each chart @@ -665,7 +666,7 @@ cd->w = w; if (cd->data) g_free(cd->data); - cd->data = (gint *) g_new0(gint, w); + cd->data = (gint64 *) g_new0(gint64, w); cd->maxval = 0; cp->position = cp->w - 1; cp->tail = cp->position; @@ -697,7 +698,7 @@ { GList *list; GkrellmChartdata *cd; - gint N, I; + gint64 N, I; gint i, current_split; gboolean need_next_split = FALSE; @@ -785,7 +786,8 @@ GList *list; GkrellmChartdata *cd; gulong range, total_diff; - gint n, N_discard, I_discard, N, I; + gint n; + guint64 N, I, N_discard, I_discard; gint active_split, current_split; gboolean need_scan = FALSE; @@ -795,7 +797,7 @@ for (list = cp->cd_list; list; list = list->next) { cd = (GkrellmChartdata *) list->data; - cd->current = va_arg(args, gulong); + cd->current = va_arg(args, guint64); if (!cd->monotonic) { cd->previous = 0; @@ -828,7 +830,7 @@ { cd = (GkrellmChartdata *) list->data; cd->discard = cd->data[cp->tail]; - cd->data[n] = (gint)(cd->current - cd->previous); + cd->data[n] = (gint64)(cd->current - cd->previous); cd->previous = cd->current; /* If using totals, scale the stored data to range between 0 and the @@ -1798,7 +1800,7 @@ }; gint -gkrellm_125_sequence(gint value, gboolean use125, +gkrellm_125_sequence(gint64 value, gboolean use125, gint low, gint high, gboolean snap_to_table, gboolean roundup) { @@ -1965,9 +1967,9 @@ if (map_sequence) { cf->low = 1; - cf->low = (gfloat) gkrellm_125_sequence((gint) low, cf->sequence_125, + cf->low = (gfloat) gkrellm_125_sequence((gint64) low, cf->sequence_125, low, high, TRUE, FALSE); - cf->high = (gfloat) gkrellm_125_sequence((gint) high, + cf->high = (gfloat) gkrellm_125_sequence((gint64) high, cf->sequence_125, low, high, TRUE, TRUE); cf->step0 = 1.0; cf->step1 = 1.0; diff -Naur gkrellm-2.1.23/src/client.c gkrellm-2.1.23i/src/client.c --- gkrellm-2.1.23/src/client.c 2003-10-12 08:57:42.000000000 -0600 +++ gkrellm-2.1.23i/src/client.c 2003-12-21 14:16:43.000000000 -0700 @@ -490,6 +490,10 @@ #endif gint n, slen; +#if 0 + fprintf(stderr, "%s\n", line); +#endif + if (*(line + 1) == '0') { n = sscanf(line + 3, "%x %127[^:]:%x", &tcp.local_port, @@ -520,6 +524,28 @@ tcp.family = AF_INET6; } #endif + else if (*(line + 1) == 'F') + { + tcp.state = 0; + tcp.family = 0; + tcp.new_hit = 0; + n = sscanf(line + 3, "%x:%x %x:%x %d:%d:%d %Lu:%Lu", + &tcp.local_port, &tcp.local_port_hi, + &tcp.remote_port, &tcp.remote_port_hi, + &tcp.chain, &tcp.line, &tcp.target, + &tcp.pkts, &tcp.bytes); +#if 0 + fprintf(stderr, "%s\n", line); + fprintf(stderr, "local %d:%d remote %d:%d chain %d line %d target %d pkts %Lu bytes %Lu\n", + tcp.local_port, tcp.local_port_hi, + tcp.remote_port, tcp.remote_port_hi, + tcp.chain, tcp.line, tcp.target, tcp.pkts, tcp.bytes); +#endif + if (n != 9) + return; + gkrellm_inet_log_tcp_port_data(&tcp); + } + if (*line == '+') { t = g_new0(ActiveTCP, 1); diff -Naur gkrellm-2.1.23/src/cpu.c gkrellm-2.1.23i/src/cpu.c --- gkrellm-2.1.23/src/cpu.c 2003-07-23 21:29:42.000000000 -0600 +++ gkrellm-2.1.23i/src/cpu.c 2003-12-21 14:16:44.000000000 -0700 @@ -441,7 +441,7 @@ total = cpu->user + cpu->nice + cpu->sys + cpu->idle; if (GK.second_tick) { - gkrellm_store_chartdata(cp, total, cpu->sys, cpu->user, cpu->nice); + gkrellm_store_chartdata(cp, total, (gint64) cpu->sys, (gint64) cpu->user, (gint64) cpu->nice); refresh_cpu_chart(cpu); alert_value = cpu->sys + cpu->user; diff -Naur gkrellm-2.1.23/src/disk.c gkrellm-2.1.23i/src/disk.c --- gkrellm-2.1.23/src/disk.c 2003-08-09 22:47:50.000000000 -0600 +++ gkrellm-2.1.23i/src/disk.c 2003-12-21 14:16:44.000000000 -0700 @@ -454,7 +454,7 @@ if (GK.second_tick) { gkrellm_store_chartdata(cp, 0, - (gulong) disk->wb, (gulong) disk->rb); + (guint64) disk->wb, (guint64) disk->rb); if (disk->alert) { bytes = 0; diff -Naur gkrellm-2.1.23/src/gkrellm.h gkrellm-2.1.23i/src/gkrellm.h --- gkrellm-2.1.23/src/gkrellm.h 2003-12-14 11:12:55.000000000 -0700 +++ gkrellm-2.1.23i/src/gkrellm.h 2003-12-21 14:16:44.000000000 -0700 @@ -585,7 +585,7 @@ gint alloc_width; gint scale_max; - gint maxval, + gint64 maxval, maxval_auto, maxval_auto_base, maxval_peak; @@ -637,13 +637,13 @@ GkrellmChart *chart; /* GkrellmChart this data belong to */ gchar *label; - gulong current, + guint64 current, previous, discard; gboolean monotonic; GkrellmChartlayer layer; /* The image + grid for this data layer */ GdkBitmap *data_bitmap; /* Draw data here, use as clipmask for layer*/ - gint *data; + gint64 *data; gint draw_style; gboolean inverted; @@ -659,7 +659,7 @@ gint y, /* Each data layer draws at an offset y and */ h, /* within height h of its parent GkrellmChart*/ w; /* Width of data allocated. */ - gint maxval; + guint64 maxval; } GkrellmChartdata; diff -Naur gkrellm-2.1.23/src/gkrellm-public-proto.h gkrellm-2.1.23i/src/gkrellm-public-proto.h --- gkrellm-2.1.23/src/gkrellm-public-proto.h 2003-12-10 10:18:54.000000000 -0700 +++ gkrellm-2.1.23i/src/gkrellm-public-proto.h 2003-12-21 14:16:44.000000000 -0700 @@ -66,7 +66,7 @@ gint gkrellm_chart_width(void); void gkrellm_set_chart_height_default(GkrellmChart *, gint); void gkrellm_set_chart_height(GkrellmChart *, gint); -gint gkrellm_get_chart_scalemax(GkrellmChart *); +gint64 gkrellm_get_chart_scalemax(GkrellmChart *); void gkrellm_render_data_pixmap(GkrellmPiximage *, GdkPixmap **, GdkColor *, gint); void gkrellm_render_data_grid_pixmap(GkrellmPiximage *, @@ -83,8 +83,8 @@ void gkrellm_draw_chartdata(GkrellmChart *); void gkrellm_monotonic_chartdata(GkrellmChartdata *, gboolean); gboolean gkrellm_get_chartdata_hide(GkrellmChartdata *); -gint gkrellm_get_current_chartdata(GkrellmChartdata *); -gint gkrellm_get_chartdata_data(GkrellmChartdata *, gint); +gint64 gkrellm_get_current_chartdata(GkrellmChartdata *); +gint64 gkrellm_get_chartdata_data(GkrellmChartdata *, gint); void gkrellm_set_chartdata_draw_style(GkrellmChartdata *, gint); void gkrellm_set_chartdata_draw_style_default(GkrellmChartdata *, gint); void gkrellm_set_chartdata_flags(GkrellmChartdata *, gint); @@ -494,7 +494,7 @@ gchar *gkrellm_make_config_file_name(gchar *, gchar *); gchar *gkrellm_make_data_file_name(gchar *, gchar *); struct tm *gkrellm_get_current_time(void); -gint gkrellm_125_sequence(gint, gboolean, gint, gint, +gint gkrellm_125_sequence(gint64, gboolean, gint, gint, gboolean, gboolean); void gkrellm_save_all(void); diff -Naur gkrellm-2.1.23/src/gkrellm-public-proto.h.orig gkrellm-2.1.23i/src/gkrellm-public-proto.h.orig --- gkrellm-2.1.23/src/gkrellm-public-proto.h.orig 1969-12-31 17:00:00.000000000 -0700 +++ gkrellm-2.1.23i/src/gkrellm-public-proto.h.orig 2003-12-10 10:18:54.000000000 -0700 @@ -0,0 +1,526 @@ +/* GKrellM +| Copyright (C) 1999-2003 Bill Wilson +| +| Author: Bill Wilson bill@gkrellm.net +| Latest versions might be found at: http://gkrellm.net +| +| This program is free software which I release under the GNU General Public +| License. You may redistribute and/or modify this program under the terms +| of that license as published by the Free Software Foundation; either +| version 2 of the License, or (at your option) any later version. +| +| This program is distributed in the hope that it will be useful, +| but WITHOUT ANY WARRANTY; without even the implied warranty of +| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +| GNU General Public License for more details. Version 2 is in the +| COPYRIGHT file in the top level directory of this distribution. +| +| To get a copy of the GNU General Puplic License, write to the Free Software +| Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + + +/* Public GKrellM function prototypes available for all monitors and plugins */ + + /* Data structure allocation + */ +GkrellmChart *gkrellm_chart_new0(void); +GkrellmChartconfig *gkrellm_chartconfig_new0(void); +GkrellmPanel *gkrellm_panel_new0(void); +GkrellmKrell *gkrellm_krell_new0(void); +GkrellmDecal *gkrellm_decal_new0(void); +GkrellmLabel *gkrellm_label_new0(void); +GkrellmStyle *gkrellm_style_new0(void); +GkrellmStyle *gkrellm_copy_style(GkrellmStyle *); +void gkrellm_copy_style_values(GkrellmStyle *, GkrellmStyle *); +GkrellmTextstyle *gkrellm_textstyle_new0(void); +GkrellmTextstyle *gkrellm_copy_textstyle(GkrellmTextstyle *); + + + /* Chart functions + */ +void gkrellm_chart_create(GtkWidget *, GkrellmMonitor *, + GkrellmChart *, GkrellmChartconfig **); +void gkrellm_chart_destroy(GkrellmChart *); +void gkrellm_chart_hide(GkrellmChart *, gboolean); +void gkrellm_chart_show(GkrellmChart *, gboolean); +gboolean gkrellm_chart_enable_visibility(GkrellmChart *cp, gboolean, + gboolean *); +gboolean gkrellm_is_chart_visible(GkrellmChart *); +void gkrellm_set_draw_chart_function(GkrellmChart *, + void (*func)(), gpointer); +void gkrellm_draw_chart_to_screen(GkrellmChart *); +gint gkrellm_draw_chart_label(GkrellmChart *, GkrellmTextstyle *, + gint, gint,gchar *); +void gkrellm_draw_chart_text(GkrellmChart *, gint, gchar *); +void gkrellm_reset_chart(GkrellmChart *); +void gkrellm_reset_and_draw_chart(GkrellmChart *); +void gkrellm_refresh_chart(GkrellmChart *); +void gkrellm_rescale_chart(GkrellmChart *); +void gkrellm_clear_chart(GkrellmChart *); +void gkrellm_clear_chart_pixmap(GkrellmChart *); +void gkrellm_clean_bg_src_pixmap(GkrellmChart *); +void gkrellm_draw_chart_grid_line(GkrellmChart *, GdkPixmap *, gint); +void gkrellm_chart_bg_piximage_override(GkrellmChart *, + GkrellmPiximage *, GkrellmPiximage *); +gint gkrellm_chart_width(void); +void gkrellm_set_chart_height_default(GkrellmChart *, gint); +void gkrellm_set_chart_height(GkrellmChart *, gint); +gint gkrellm_get_chart_scalemax(GkrellmChart *); +void gkrellm_render_data_pixmap(GkrellmPiximage *, GdkPixmap **, + GdkColor *, gint); +void gkrellm_render_data_grid_pixmap(GkrellmPiximage *, + GdkPixmap **, GdkColor *); + + + /* ChartData functions + */ +GkrellmChartdata *gkrellm_add_chartdata(GkrellmChart *, GdkPixmap **, + GdkPixmap *, gchar *); +GkrellmChartdata *gkrellm_add_default_chartdata(GkrellmChart *, gchar *); +void gkrellm_alloc_chartdata(GkrellmChart *); +void gkrellm_store_chartdata(GkrellmChart *, gulong, ...); +void gkrellm_draw_chartdata(GkrellmChart *); +void gkrellm_monotonic_chartdata(GkrellmChartdata *, gboolean); +gboolean gkrellm_get_chartdata_hide(GkrellmChartdata *); +gint gkrellm_get_current_chartdata(GkrellmChartdata *); +gint gkrellm_get_chartdata_data(GkrellmChartdata *, gint); +void gkrellm_set_chartdata_draw_style(GkrellmChartdata *, gint); +void gkrellm_set_chartdata_draw_style_default(GkrellmChartdata *, gint); +void gkrellm_set_chartdata_flags(GkrellmChartdata *, gint); +void gkrellm_scale_chartdata(GkrellmChartdata *, gint, gint); +void gkrellm_offset_chartdata(GkrellmChartdata *, gint); + + + /* ChartConfig functions + */ +void gkrellm_chartconfig_window_create(GkrellmChart *); +void gkrellm_chartconfig_window_destroy(GkrellmChart *); +void gkrellm_chartconfig_grid_resolution_adjustment( + GkrellmChartconfig *, gboolean, gfloat, gfloat, gfloat, + gfloat, gfloat, gint, gint); +void gkrellm_set_chartconfig_grid_resolution(GkrellmChartconfig *, + gint); +gint gkrellm_get_chartconfig_grid_resolution(GkrellmChartconfig *); +void gkrellm_chartconfig_grid_resolution_connect( + GkrellmChartconfig *, void (*fn)(), gpointer); +void gkrellm_set_chartconfig_flags(GkrellmChartconfig *, gint); + +void gkrellm_chartconfig_grid_resolution_label( + GkrellmChartconfig *, gchar *); +void gkrellm_set_chartconfig_auto_grid_resolution( + GkrellmChartconfig *, gboolean); +void gkrellm_set_chartconfig_auto_resolution_stick( + GkrellmChartconfig *, gboolean); +void gkrellm_set_chartconfig_sequence_125(GkrellmChartconfig *, + gboolean); +void gkrellm_set_chartconfig_fixed_grids(GkrellmChartconfig *, gint); +gint gkrellm_get_chartconfig_fixed_grids(GkrellmChartconfig *); +void gkrellm_chartconfig_fixed_grids_connect(GkrellmChartconfig *, + void (*fn)(), gpointer); +gint gkrellm_get_chartconfig_height(GkrellmChartconfig *); +void gkrellm_chartconfig_height_connect(GkrellmChartconfig *, + void (*fn)(), gpointer); +void gkrellm_chartconfig_callback_block(GkrellmChartconfig *, gboolean); +void gkrellm_save_chartconfig(FILE *, GkrellmChartconfig *, + gchar *, gchar *); +void gkrellm_load_chartconfig(GkrellmChartconfig **, gchar *, gint); +void gkrellm_chartconfig_destroy(GkrellmChartconfig **); + + + /* Panel functions + */ +void gkrellm_panel_configure(GkrellmPanel *, gchar *, GkrellmStyle *); +void gkrellm_panel_configure_add_height(GkrellmPanel *, gint); +void gkrellm_panel_configure_set_height(GkrellmPanel *p, gint h); +gint gkrellm_panel_configure_get_height(GkrellmPanel *p); +void gkrellm_panel_create(GtkWidget *, GkrellmMonitor *,GkrellmPanel *); +void gkrellm_panel_destroy(GkrellmPanel *); +void gkrellm_panel_hide(GkrellmPanel *); +void gkrellm_panel_show(GkrellmPanel *); +gboolean gkrellm_panel_enable_visibility(GkrellmPanel *p, gboolean, + gboolean *); +gboolean gkrellm_is_panel_visible(GkrellmPanel *); +void gkrellm_panel_keep_lists(GkrellmPanel *, gboolean); +void gkrellm_draw_panel_label(GkrellmPanel *); +void gkrellm_panel_label_on_top_of_decals(GkrellmPanel *, gboolean); +void gkrellm_draw_panel_layers(GkrellmPanel *); +void gkrellm_draw_panel_layers_force(GkrellmPanel *); +void gkrellm_panel_bg_piximage_override(GkrellmPanel *, + GkrellmPiximage *); + + + /* Krell functions + */ +GkrellmKrell *gkrellm_create_krell(GkrellmPanel *, GkrellmPiximage *, + GkrellmStyle *); +void gkrellm_set_krell_full_scale(GkrellmKrell *, gint, gint); +void gkrellm_set_style_krell_values(GkrellmStyle *, gint, gint, gint, + gint, gint, gint, gint); +void gkrellm_set_style_krell_values_default(GkrellmStyle *s, gint yoff, + gint depth, gint x_hot, gint expand, gint ema, + gint left_margin, gint right_margin); +void gkrellm_set_style_slider_values_default(GkrellmStyle *s, gint yoff, + gint left_margin, gint right_margin); +void gkrellm_set_krell_margins(GkrellmPanel *, GkrellmKrell *k, + gint, gint); +void gkrellm_set_krell_expand(GkrellmStyle *, gchar *); +void gkrellm_update_krell(GkrellmPanel *, GkrellmKrell *, gulong); +void gkrellm_monotonic_krell_values(GkrellmKrell *k, gboolean); +void gkrellm_destroy_krell_list(GkrellmPanel *); +void gkrellm_destroy_krell(GkrellmKrell *); +void gkrellm_move_krell_yoff(GkrellmPanel *, GkrellmKrell *, gint); +void gkrellm_remove_krell(GkrellmPanel *, GkrellmKrell *); +void gkrellm_insert_krell(GkrellmPanel *, GkrellmKrell *, gboolean); +void gkrellm_insert_krell_nth(GkrellmPanel *, GkrellmKrell *, gint); + + + /* Decal and Decalbutton functions + */ +GkrellmDecal *gkrellm_create_decal_text(GkrellmPanel *p, gchar *string, + GkrellmTextstyle *ts, GkrellmStyle *style, + gint x, gint y, gint w); +GkrellmDecal *gkrellm_create_decal_text_with_height(GkrellmPanel *p, + GkrellmTextstyle *ts, GkrellmStyle *style, + gint x, gint y, gint w, gint h, gint y_baseline); +GkrellmDecal *gkrellm_create_decal_pixmap(GkrellmPanel *, GdkPixmap *, + GdkBitmap *, gint, GkrellmStyle *, gint, gint); +GkrellmDecal *gkrellm_make_scaled_decal_pixmap(GkrellmPanel *p, + GkrellmPiximage *im, GkrellmStyle *style, gint depth, + gint x, gint y, gint w, gint h); + +void gkrellm_draw_decal_pixmap(GkrellmPanel *, GkrellmDecal *, gint); +void gkrellm_draw_decal_text(GkrellmPanel *, GkrellmDecal *, gchar *, + gint); +void gkrellm_decal_text_clear(GkrellmDecal *d); +void gkrellm_decal_text_insert(GkrellmDecal *d, gchar *s, + GkrellmTextstyle *ts, gint x_off, gint y_off); + +void gkrellm_draw_decal_on_chart(GkrellmChart *, GkrellmDecal *, + gint, gint); +void gkrellm_move_decal(GkrellmPanel *, GkrellmDecal *, gint, gint); +void gkrellm_decal_on_top_layer(GkrellmDecal *, gboolean); +void gkrellm_destroy_decal(GkrellmDecal *); +void gkrellm_make_decal_visible(GkrellmPanel *, GkrellmDecal *); +void gkrellm_make_decal_invisible(GkrellmPanel *, GkrellmDecal *); +gint gkrellm_is_decal_visible(GkrellmDecal *); +void gkrellm_remove_decal(GkrellmPanel *, GkrellmDecal *); +void gkrellm_insert_decal(GkrellmPanel *, GkrellmDecal *, gboolean); +void gkrellm_insert_decal_nth(GkrellmPanel *, GkrellmDecal *, gint); +void gkrellm_destroy_decal_list(GkrellmPanel *); +void gkrellm_set_decal_button_index(GkrellmDecalbutton *, gint); +GkrellmDecalbutton *gkrellm_make_decal_button(GkrellmPanel *, GkrellmDecal *, + void (*func)(), void *, gint, gint); +GkrellmDecalbutton *gkrellm_make_overlay_button(GkrellmPanel *, + void (*func)(), void *, gint, gint, gint, gint, + GkrellmPiximage *, GkrellmPiximage *); +GkrellmDecalbutton *gkrellm_put_decal_in_panel_button(GkrellmPanel *, + GkrellmDecal *, void (*func)(), void *, + GkrellmMargin *); +GkrellmDecalbutton *gkrellm_put_decal_in_meter_button(GkrellmPanel *, + GkrellmDecal *, void (*func)(), void *, + GkrellmMargin *); +GkrellmDecalbutton *gkrellm_put_label_in_panel_button(GkrellmPanel *, + void (*func)(), void *, gint pad); +GkrellmDecalbutton *gkrellm_put_label_in_meter_button(GkrellmPanel *, + void (*func)(), void *, gint pad); +GkrellmDecalbutton *gkrellm_make_scaled_button(GkrellmPanel *p, + GkrellmPiximage *im, void (*func)(), void *data, + gboolean auto_hide, gboolean set_default_border, + gint depth, gint cur_index, gint pressed_index, + gint x, gint y, gint w, gint h); + +GkrellmDecalbutton *gkrellm_decal_is_button(GkrellmDecal *); +void gkrellm_set_in_button_callback(GkrellmDecalbutton *, + gint (*func)(), gpointer data); +gboolean gkrellm_in_button(GkrellmDecalbutton *button, GdkEventButton *); +gboolean gkrellm_in_decal(GkrellmDecal *, GdkEventButton *); +void gkrellm_decal_button_connect(GkrellmDecalbutton *, void (*func)(), + void *); +void gkrellm_decal_button_right_connect(GkrellmDecalbutton *, + void (*func)(), void *); +void gkrellm_set_button_sensitive(GkrellmDecalbutton *, gboolean); +void gkrellm_hide_button(GkrellmDecalbutton *); +void gkrellm_show_button(GkrellmDecalbutton *); +void gkrellm_destroy_button(GkrellmDecalbutton *); + + + /* Pixops + */ +gboolean gkrellm_load_piximage(gchar *, gchar **, + GkrellmPiximage **, gchar *); +gboolean gkrellm_load_piximage_from_inline(gchar *, const guint8 *, + GkrellmPiximage **, gchar *, gboolean); +GkrellmPiximage *gkrellm_piximage_new_from_inline(const guint8 *data, + gboolean); +GkrellmPiximage *gkrellm_piximage_new_from_file(gchar *fname); +GkrellmPiximage *gkrellm_piximage_new_from_xpm_data(gchar **data); +void gkrellm_set_piximage_border(GkrellmPiximage *piximage, + GkrellmBorder *border); +gboolean gkrellm_scale_pixbuf_to_pixmap(GdkPixbuf *src_pixbuf, + GdkPixmap **pixmap, GdkBitmap **mask, + gint w_dst, gint h_dst); +GdkPixbuf *gkrellm_scale_piximage_to_pixbuf(GkrellmPiximage *piximage, + gint w_dst, gint h_dst); +gboolean gkrellm_scale_piximage_to_pixmap(GkrellmPiximage *, GdkPixmap **, + GdkBitmap **, gint, gint); +void gkrellm_paste_piximage(GkrellmPiximage *src_piximage, + GdkDrawable *drawable, + gint x_dst, gint y_dst, gint w_dst, gint h_dst); +void gkrellm_paste_pixbuf(GdkPixbuf *src_pixbuf, GdkDrawable *drawable, + gint x_dst, gint y_dst, gint w_dst, gint h_dst); +gboolean gkrellm_scale_theme_background(GkrellmPiximage *piximage, + GdkPixmap **pixmap, GdkBitmap **mask, + gint w_dst, gint h_dst); +void gkrellm_destroy_piximage(GkrellmPiximage *piximage); +GkrellmPiximage *gkrellm_clone_piximage(GkrellmPiximage *src_piximage); +gboolean gkrellm_clone_pixmap(GdkPixmap **, GdkPixmap **); +gboolean gkrellm_clone_bitmap(GdkBitmap **, GdkBitmap **); +void gkrellm_free_pixmap(GdkPixmap **); +void gkrellm_free_bitmap(GdkBitmap **); + + + /* Misc support functions + */ +GtkWidget *gkrellm_get_top_window(void); +gboolean gkrellm_set_gkrellmrc_piximage_border(gchar *, GkrellmPiximage *, + GkrellmStyle *); +gboolean gkrellm_get_gkrellmrc_integer(gchar *, gint *); +gchar *gkrellm_get_gkrellmrc_string(gchar *); +gboolean gkrellm_get_gkrellmrc_piximage_border(gchar *image_name, + GkrellmPiximage *image, GkrellmBorder *border); +void gkrellm_freeze_side_frame_packing(void); +void gkrellm_thaw_side_frame_packing(void); +void gkrellm_pack_side_frames(void); +void gkrellm_draw_string(GdkDrawable *, GkrellmTextstyle *, gint, gint, + gchar *); +void gkrellm_draw_text(GdkDrawable *, GkrellmTextstyle *, gint, gint, + gchar *, gint); +void gkrellm_apply_launcher(GtkWidget **, GtkWidget **, GkrellmPanel *, + GkrellmLauncher *, void (*func)()); +void gkrellm_setup_launcher(GkrellmPanel *, GkrellmLauncher *, gint, + gint); +void gkrellm_setup_decal_launcher(GkrellmPanel *, GkrellmLauncher *, + GkrellmDecal *); +void gkrellm_remove_launcher(GkrellmLauncher *launch); +void gkrellm_configure_tooltip(GkrellmPanel *, GkrellmLauncher *); +void gkrellm_launch_button_cb(GkrellmDecalbutton *); +void gkrellm_disable_plugin_connect(GkrellmMonitor *, void (*func)()); +pid_t gkrellm_get_pid(void); +void gkrellm_monitor_height_adjust(gint); +gboolean gkrellm_using_default_theme(void); +gfloat gkrellm_get_theme_scale(void); +void gkrellm_open_config_window(GkrellmMonitor *); +gboolean gkrellm_config_window_shown(void); +void gkrellm_config_modified(void); +GkrellmMargin *gkrellm_get_style_margins(GkrellmStyle *); +void gkrellm_set_style_margins(GkrellmStyle *, GkrellmMargin *); +void gkrellm_get_top_bottom_margins(GkrellmStyle *, gint *, gint *); +gboolean gkrellm_style_is_themed(GkrellmStyle *, gint); +void gkrellm_message_dialog(gchar *title, gchar *message); +void gkrellm_config_message_dialog(gchar *title, gchar *message); +void gkrellm_spacers_set_types(GkrellmMonitor *mon, gint top, gint bot); +#define gkrellm_message_window(title, message, widget) \ + gkrellm_message_dialog(title, message) +#define gkrellm_config_message_window(title, message, widget) \ + gkrellm_config_message_dialog(title, message) + + + /* Alerts + */ +GkrellmAlert *gkrellm_alert_create(GkrellmPanel *, gchar *, gchar *, + gboolean, gboolean, gboolean, + gfloat, gfloat, gfloat, gfloat, gint); +void gkrellm_alert_dup(GkrellmAlert **a_dst, GkrellmAlert *a_src); +void gkrellm_alert_destroy(GkrellmAlert **); +void gkrellm_check_alert(GkrellmAlert *, gfloat); +void gkrellm_reset_alert(GkrellmAlert *alert); +void gkrellm_reset_alert_soft(GkrellmAlert *alert); +void gkrellm_reset_panel_alerts(GkrellmPanel *); +void gkrellm_freeze_alert(GkrellmAlert *); +void gkrellm_thaw_alert(GkrellmAlert *); +gboolean gkrellm_alert_is_activated(GkrellmAlert *alert); +void gkrellm_alert_get_alert_state(GkrellmAlert *alert, + gboolean *alarm_state, gboolean *warn_state); +void gkrellm_alert_trigger_connect(GkrellmAlert *, void (*func)(), + gpointer); +void gkrellm_alert_stop_connect(GkrellmAlert *, void (*func)(), + gpointer); +void gkrellm_alert_config_connect(GkrellmAlert *, void (*func)(), + gpointer); +void gkrellm_alert_config_create_connect(GkrellmAlert *alert, + void (*func)(), gpointer); +void gkrellm_alert_command_process_connect(GkrellmAlert *alert, + void (*func)(), gpointer data); +void gkrellm_render_default_alert_decal(GkrellmAlert *); +gboolean gkrellm_alert_decal_visible(GkrellmAlert *alert); +void gkrellm_alert_config_window(GkrellmAlert **); +void gkrellm_alert_window_destroy(GkrellmAlert **); +void gkrellm_save_alertconfig(FILE *, GkrellmAlert *, gchar *, gchar *); +void gkrellm_load_alertconfig(GkrellmAlert **, gchar *); +void gkrellm_alert_set_triggers(GkrellmAlert *alert, + gfloat high_alarm, gfloat high_warn, + gfloat low_warn, gfloat low_alarm); +void gkrellm_alert_set_delay(GkrellmAlert *alert, gint delay); +void gkrellm_alert_delay_config(GkrellmAlert *alert, gint step, + gint high, gint low); +void gkrellm_alert_commands_config(GkrellmAlert *alert, + gboolean alarm, gboolean warn); + /* Alert plugin API + */ +GkrellmAlertPlugin *gkrellm_alert_plugin_add(GkrellmMonitor *mon, + gchar *name); +void gkrellm_alert_plugin_alert_connect(GkrellmAlertPlugin *gap, + void (*alarm_func)(), void (*warn_func)(), + void (*update_func)(), void (*check_func)(), + void (*destroy_func)()); +void gkrellm_alert_plugin_config_connect(GkrellmAlertPlugin *gap, + gchar *tab_name, + void (*config_create_func)(), void (*config_done_func), + void (*config_save_func)(),void (*config_load_func)()); +gchar *gkrellm_alert_plugin_config_get_id_string(GkrellmAlert *alert); +void gkrellm_alert_plugin_alert_attach(GkrellmAlertPlugin *gap, + GkrellmAlert *alert, gpointer data); +void gkrellm_alert_plugin_alert_detach(GkrellmAlertPlugin *gap, + GkrellmAlert *alert); +gpointer gkrellm_alert_plugin_get_data(GkrellmAlertPlugin *gap, + GkrellmAlert *alert); +void gkrellm_alert_plugin_command_process(GkrellmAlert *alert, + gchar *src, gchar *dst, gint dst_size); + + + /* GKrellM Styles and Textstyles + */ +gint gkrellm_add_chart_style(GkrellmMonitor *, gchar *); +gint gkrellm_add_meter_style(GkrellmMonitor *, gchar *); +gint gkrellm_lookup_chart_style_id(gchar *); +gint gkrellm_lookup_meter_style_id(gchar *); +GkrellmStyle *gkrellm_meter_style(gint); +GkrellmStyle *gkrellm_panel_style(gint); +GkrellmStyle *gkrellm_chart_style(gint); +GkrellmStyle *gkrellm_meter_style_by_name(gchar *); +GkrellmStyle *gkrellm_panel_style_by_name(gchar *); +GkrellmStyle *gkrellm_chart_style_by_name(gchar *); +GkrellmStyle *gkrellm_krell_slider_style(void); +GkrellmStyle *gkrellm_krell_mini_style(void); +GkrellmTextstyle *gkrellm_chart_textstyle(gint); +GkrellmTextstyle *gkrellm_panel_textstyle(gint); +GkrellmTextstyle *gkrellm_meter_textstyle(gint); +GkrellmTextstyle *gkrellm_chart_alt_textstyle(gint); +GkrellmTextstyle *gkrellm_panel_alt_textstyle(gint); +GkrellmTextstyle *gkrellm_meter_alt_textstyle(gint); + + + /* Accessing GKrellM GkrellmPiximages and pixmaps + */ +GkrellmPiximage *gkrellm_bg_chart_piximage(gint); +GkrellmPiximage *gkrellm_bg_grid_piximage(gint); +GkrellmPiximage *gkrellm_bg_panel_piximage(gint); +GkrellmPiximage *gkrellm_bg_meter_piximage(gint); +GkrellmPiximage *gkrellm_krell_panel_piximage(gint); +GkrellmPiximage *gkrellm_krell_meter_piximage(gint); +GkrellmPiximage *gkrellm_krell_slider_piximage(void); +GkrellmPiximage *gkrellm_krell_mini_piximage(void); +void gkrellm_get_decal_alarm_piximage(GkrellmPiximage **, gint *); +void gkrellm_get_decal_warn_piximage(GkrellmPiximage **, gint *); +GdkPixmap **gkrellm_data_in_pixmap(void); +GdkPixmap *gkrellm_data_in_grid_pixmap(void); +GdkPixmap **gkrellm_data_out_pixmap(void); +GdkPixmap *gkrellm_data_out_grid_pixmap(void); +GdkPixmap *gkrellm_decal_misc_pixmap(void); +GdkBitmap *gkrellm_decal_misc_mask(void); + + + /* Accessing other data from the GK struct + */ +GdkGC *gkrellm_draw_GC(gint); +GdkGC *gkrellm_bit_GC(gint); +GdkFont *gkrellm_default_font(gint); +GdkColor *gkrellm_white_color(void); +GdkColor *gkrellm_black_color(void); +GdkColor *gkrellm_in_color(void); +GdkColor *gkrellm_out_color(void); +gboolean gkrellm_demo_mode(void); +gint gkrellm_update_HZ(void); +gchar *gkrellm_get_theme_path(void); +gint gkrellm_get_timer_ticks(void); +GkrellmTicks *gkrellm_ticks(void); +void gkrellm_allow_scaling(gboolean *, gint *); +gint gkrellm_plugin_debug(void); + + /* Wrappers around gtk widget functions to provide a convenience higher level + | interface for creating the config pages. + */ +GtkWidget *gkrellm_gtk_notebook_page(GtkWidget *, gchar *); +GtkWidget *gkrellm_gtk_framed_notebook_page(GtkWidget *, char *); +GtkWidget *gkrellm_gtk_launcher_table_new(GtkWidget *, gint); +void gkrellm_gtk_config_launcher(GtkWidget *, gint, GtkWidget **, + GtkWidget **, gchar *, GkrellmLauncher *); +gchar *gkrellm_gtk_entry_get_text(GtkWidget **); +void gkrellm_gtk_spin_button(GtkWidget *, GtkWidget **, gfloat, gfloat, + gfloat, gfloat, gfloat, gint, gint, void (*func)(), + gpointer, gboolean, gchar *); +void gkrellm_gtk_check_button(GtkWidget *, GtkWidget **, gboolean, + gboolean, gint, gchar *); +void gkrellm_gtk_check_button_connected(GtkWidget *, GtkWidget **, + gboolean, gboolean, gboolean, gint, void (*func)(), + gpointer, gchar *); +void gkrellm_gtk_button_connected(GtkWidget *, GtkWidget **, gboolean, + gboolean, gint, void (*func)(), gpointer, gchar *); +void gkrellm_gtk_alert_button(GtkWidget *box, GtkWidget **button, + gboolean expand, gboolean fill, gint pad, + gboolean pack_start, void (*cb_func)(), gpointer data); +GtkWidget *gkrellm_gtk_scrolled_vbox(GtkWidget *, GtkWidget **, + GtkPolicyType, GtkPolicyType); +GtkWidget *gkrellm_gtk_framed_vbox(GtkWidget *, gchar *, gint, gboolean, + gint, gint); +GtkWidget *gkrellm_gtk_framed_vbox_end(GtkWidget *, gchar *, gint, gboolean, + gint, gint); +GtkWidget *gkrellm_gtk_category_vbox(GtkWidget *box, gchar *category_header, + gint header_pad, gint box_pad, gboolean pack_start); + +GtkWidget *gkrellm_gtk_scrolled_text_view(GtkWidget *, GtkWidget **, + GtkPolicyType, GtkPolicyType); +void gkrellm_gtk_text_view_append_strings(GtkWidget *, gchar **, gint); +void gkrellm_gtk_text_view_append(GtkWidget *, gchar *); + + + /* Some utility functions + */ +gchar *gkrellm_homedir(void); +gboolean gkrellm_dup_string(gchar **, gchar *); +gboolean gkrellm_locale_dup_string(gchar **dst, gchar *src, gchar **locale); +gchar *gkrellm_dup_token(gchar **string, gchar *delimeters); +gchar *gkrellm_make_config_file_name(gchar *, gchar *); +gchar *gkrellm_make_data_file_name(gchar *, gchar *); +struct tm *gkrellm_get_current_time(void); +gint gkrellm_125_sequence(gint, gboolean, gint, gint, + gboolean, gboolean); +void gkrellm_save_all(void); + + + + /* ------- Some builtin monitor public functions -------- */ + + /* Functions exported by cpu.c + */ +gint gkrellm_smp_cpus(void); +gboolean gkrellm_cpu_stats(gint n, gulong *, gulong *, gulong *, gulong *); + + + /* Functions exported by net.c + */ +gint gkrellm_net_routes(void); +gboolean gkrellm_net_stats(gint n, gchar *, gulong *, gulong *); +void gkrellm_net_led_positions(gint *x_rx_led, gint *y_rx_led, + gint *x_tx_led, gint *y_tx_led); + + + /* Functions exported by the Mail monitor - see bottom of mail.c + */ +gboolean gkrellm_get_mail_mute_mode(void); +gpointer gkrellm_add_external_mbox(gint (*func)(), gboolean, gpointer); +void gkrellm_destroy_external_mbox(gpointer); +void gkrellm_set_external_mbox_counts(gpointer, gint, gint); +void gkrellm_set_external_mbox_tooltip(gpointer, gchar *); + diff -Naur gkrellm-2.1.23/src/inet.c gkrellm-2.1.23i/src/inet.c --- gkrellm-2.1.23/src/inet.c 2003-10-07 11:23:41.000000000 -0600 +++ gkrellm-2.1.23i/src/inet.c 2003-12-21 14:16:44.000000000 -0700 @@ -24,6 +24,17 @@ #include "gkrellm-sysdeps.h" #include "inet.h" +typedef struct gtcphistory + { + gint chain; + gint line; + gint test; + guint64 pkts; + guint64 bytes; + struct gtcphistory *next; + } GTCPHistory; + + typedef struct { GtkWidget *vbox; @@ -34,11 +45,21 @@ GkrellmChart *chart_hour; GkrellmChartconfig *chart_config_minute; GkrellmChartconfig *chart_config_hour; + GkrellmChart *chart_minute_pkts; + GkrellmChart *chart_hour_pkts; + GkrellmChartconfig *chart_config_minute_pkts; + GkrellmChartconfig *chart_config_hour_pkts; + GkrellmChart *chart_minute_bytes; + GkrellmChart *chart_hour_bytes; + GkrellmChartconfig *chart_config_minute_bytes; + GkrellmChartconfig *chart_config_hour_bytes; GkrellmPanel *panel; gboolean hour_mode; gint cd_length; - gboolean extra_info; + gboolean extra_info; // 0 no text or 1 text + gint display_mode; // 0 connections, 1 packets, 2 bytes + GkrellmLauncher launch; GtkWidget *launch_entry, *tooltip_entry; @@ -58,23 +79,46 @@ gchar *label0; gint active0; - gint prev_active0; - gulong hits0_minute, + gint prev_active0; + guint64 pkts0; + guint64 prev_pkts0; + guint64 bytes0; + guint64 prev_bytes0; + guint64 hits0_minute, hits0_hour; + guint64 pkts0_minute, + pkts0_hour, + bytes0_minute, + bytes0_hour; gboolean data0_is_range; - gulong port0_0, + gboolean data0_outbound; + + glong port0_0, port0_1; gchar *label1; gint active1; - gint prev_active1; - gulong hits1_minute, + gint prev_active1; + guint64 pkts1; + guint64 prev_pkts1; + guint64 bytes1; + guint64 prev_bytes1; + guint64 hits1_minute, hits1_hour; + guint64 pkts1_minute, + pkts1_hour, + bytes1_minute, + bytes1_hour; gboolean data1_is_range; - gulong port1_0, + gboolean data1_outbound; + + glong port1_0, port1_1; + GTCPHistory *tcp_history; gulong krell_hits; + guint64 krell_pkts; + guint64 krell_bytes; } InetMon; @@ -159,6 +203,109 @@ } void +update_iptables_counts(InetMon *in, ActiveTCP *tcp, gint test) + { + guint64 pdiff = 0; + guint64 bdiff = 0; + + GTCPHistory *at; + + at = in->tcp_history; + while (at) + { + if (at->chain == tcp->chain + && at->line == tcp->line + && at->test == test) + break; + at = at->next; + } + + if (!at) // need to allocate another historical holding structure for byte and packet counts + { + at = g_new0(GTCPHistory, 1); + at->chain = tcp->chain; + at->line = tcp->line; + at->test = test; + at->pkts = tcp->pkts; + at->bytes = tcp->bytes; + at->next = in->tcp_history; + in->tcp_history = at; + return; + } + + pdiff = tcp->pkts - at->pkts; + if (pdiff) + { + at->pkts = tcp->pkts; + in->krell_pkts += pdiff; + + if (test >= 4) + { + in->pkts1 += pdiff; + in->pkts1_minute += pdiff; + in->pkts1_hour += pdiff; + } + else + { + in->pkts0 += pdiff; + in->pkts0_minute += pdiff; + in->pkts0_hour += pdiff; + } + } + + bdiff = tcp->bytes - at->bytes; + if (bdiff) + { + at->bytes = tcp->bytes; + in->krell_bytes += bdiff; + + if (test >= 4) + { + in->bytes1 += bdiff; + in->bytes1_minute += bdiff; + in->bytes1_hour += bdiff; + } + else + { + in->bytes0 += bdiff; + in->bytes0_minute += bdiff; + in->bytes0_hour += bdiff; + } + } +#if 0 + if (bdiff || pdiff) +fprintf(stderr, "local %d:%d remote %d:%d chain %d line %d target %d pkts %Lu bytes %Lu test %d - pdiff=%Lu bdiff=%Lu, total pkts=%Lu bytes=%Lu\n", + tcp->local_port, tcp->local_port_hi, + tcp->remote_port, tcp->remote_port_hi, + tcp->chain, tcp->line, tcp->target, tcp->pkts, tcp->bytes, test, pdiff, bdiff, at->pkts, at->bytes); + +#endif + } + +void +check_iptables_range(InetMon *in, ActiveTCP *tcp, glong port) + { + if (!in->data0_is_range && in->port0_0 == port) + update_iptables_counts(in, tcp, 2); + + else if (!in->data0_is_range && in->port0_1 == port) + update_iptables_counts(in, tcp, 3); + + else if ( in->data0_is_range && in->port0_0 <= port && port <= in->port0_1) + update_iptables_counts(in, tcp, 2); + + + if (!in->data1_is_range && in->port1_0 == port) + update_iptables_counts(in, tcp, 6); + + else if (!in->data1_is_range && in->port1_1 == port) + update_iptables_counts(in, tcp, 7); + + else if ( in->data1_is_range && in->port1_0 <= port && port <= in->port1_1) + update_iptables_counts(in, tcp, 6); + } + +void gkrellm_inet_log_tcp_port_data(gpointer data) { GList *list; @@ -171,35 +318,163 @@ { krell_hit = 0; in = (InetMon *) list->data; - if ( (!in->data0_is_range - && ( in->port0_0 == tcp->local_port - || in->port0_1 == tcp->local_port)) - || (in->data0_is_range - && tcp->local_port >= in->port0_0 - && tcp->local_port <= in->port0_1) - ) + switch (tcp->chain) { - ++in->active0; - active_tcp = _log_active_port(tcp); - krell_hit = active_tcp->new_hit; - in->hits0_minute += krell_hit; - in->hits0_hour += krell_hit; - } - if ( (!in->data1_is_range - && ( in->port1_0 == tcp->local_port - || in->port1_1 == tcp->local_port)) - || (in->data1_is_range - && tcp->local_port >= in->port1_0 - && tcp->local_port <= in->port1_1) - ) - { - ++in->active1; - active_tcp = _log_active_port(tcp); - krell_hit = active_tcp->new_hit; - in->hits1_minute += krell_hit; - in->hits1_hour += krell_hit; + case CHAIN_CONNECT: + if ( (!in->data0_is_range + && ( in->port0_0 == tcp->local_port + || in->port0_1 == tcp->local_port)) + || (in->data0_is_range + && tcp->local_port >= in->port0_0 + && tcp->local_port <= in->port0_1) + ) + { + ++in->active0; + active_tcp = _log_active_port(tcp); + krell_hit = active_tcp->new_hit; + in->hits0_minute += krell_hit; + in->hits0_hour += krell_hit; + } + if ( (!in->data1_is_range + && ( in->port1_0 == tcp->local_port + || in->port1_1 == tcp->local_port)) + || (in->data1_is_range + && tcp->local_port >= in->port1_0 + && tcp->local_port <= in->port1_1) + ) + { + ++in->active1; + active_tcp = _log_active_port(tcp); + krell_hit = active_tcp->new_hit; + in->hits1_minute += krell_hit; + in->hits1_hour += krell_hit; + } + in->krell_hits += krell_hit; + break; + + default: // CHAIN_INPUT, CHAIN_FORWARD, CHAIN_OUTPUT, CHAIN_USER + switch (tcp->target) + { + case TARGET_ACCEPT: + case TARGET_USER: + if (in->data0_outbound) + { + // If the remote IPtables rule is a generic rule, then only matches if user is tracking that specific + // generic range - generally much more useful for local port comparisons if you are running or using a + // service in the unpriviliged port area. + + if ((tcp->remote_port == 0 || tcp->remote_port == 1024) + && tcp->remote_port_hi == 65535) + { + if (in->data0_is_range && tcp->remote_port == in->port0_0 && + tcp->remote_port_hi == in->port0_1) + update_iptables_counts(in, tcp, 0); + } + else + { + if (!in->data0_is_range && in->port0_0 && + in->port0_0 >= tcp->remote_port && in->port0_0 <= tcp->remote_port_hi) + update_iptables_counts(in, tcp, 0); + + else if (!in->data0_is_range && in->port0_1 && + in->port0_1 >= tcp->remote_port && in->port0_1 <= tcp->remote_port_hi) + update_iptables_counts(in, tcp, 1); + + else if (in->data0_is_range && !(tcp->remote_port > in->port0_1 || tcp->remote_port_hi < in->port0_0)) + update_iptables_counts(in, tcp, 0); + + } + } + else + { + if ((tcp->local_port == 0 || tcp->local_port == 1024) + && tcp->local_port_hi == 65535) + { + if (in->data0_is_range && tcp->local_port == in->port0_0 && + tcp->local_port_hi == in->port0_1) + update_iptables_counts(in, tcp, 2); + } + else + { + if (!in->data0_is_range && in->port0_0 && + in->port0_0 >= tcp->local_port && in->port0_0 <= tcp->local_port_hi) + update_iptables_counts(in, tcp, 2); + + else if (!in->data0_is_range && in->port0_1 && + in->port0_1 >= tcp->local_port && in->port0_1 <= tcp->local_port_hi) + update_iptables_counts(in, tcp, 3); + + else if (in->data0_is_range && !(tcp->local_port > in->port0_1 || tcp->local_port_hi < in->port0_0)) + update_iptables_counts(in, tcp, 2); + } + } + + if (in->data1_outbound) + { + if ((tcp->remote_port == 0 || tcp->remote_port == 1024) + && tcp->remote_port_hi == 65535) + { + if (in->data1_is_range && tcp->remote_port == in->port1_0 && + tcp->remote_port_hi == in->port1_1) + update_iptables_counts(in, tcp, 4); + } + else + { + if (!in->data1_is_range && in->port1_0 && + in->port1_0 >= tcp->remote_port && in->port1_0 <= tcp->remote_port_hi) + update_iptables_counts(in, tcp, 4); + + else if (!in->data1_is_range && in->port1_1 && + in->port1_1 >= tcp->remote_port && in->port1_1 <= tcp->remote_port_hi) + update_iptables_counts(in, tcp, 5); + + else if (in->data1_is_range && !(tcp->remote_port > in->port1_1 || tcp->remote_port_hi < in->port1_0)) + update_iptables_counts(in, tcp, 4); + } + } + else + { + if ((tcp->local_port == 0 || tcp->local_port == 1024) + && tcp->local_port_hi == 65535) + { + if (in->data1_is_range && tcp->local_port == in->port1_0 && + tcp->local_port_hi == in->port1_1) + update_iptables_counts(in, tcp, 6); + } + else + { + if (!in->data1_is_range && in->port1_0 && + in->port1_0 >= tcp->local_port && in->port1_0 <= tcp->local_port_hi) + update_iptables_counts(in, tcp, 6); + + else if (!in->data1_is_range && in->port1_1 && + in->port1_1 >= tcp->local_port && in->port1_1 <= tcp->local_port_hi) + update_iptables_counts(in, tcp, 7); + + else if (in->data1_is_range && !(tcp->local_port > in->port1_1 || tcp->local_port_hi < in->port1_0)) + update_iptables_counts(in, tcp, 6); + } + } + break; + + case TARGET_QUEUE: + check_iptables_range(in, tcp, PORT_QUEUE); + break; + + case TARGET_RETURN: + check_iptables_range(in, tcp, PORT_RETURN); + break; + + case TARGET_DROP: + check_iptables_range(in, tcp, PORT_DROP); + break; + + case TARGET_LOG: + check_iptables_range(in, tcp, PORT_LOG); + break; + } + break; } - in->krell_hits += krell_hit; } /* Defer setting new hit to 0 until here so multiple inet charts can | monitor the same port number. The above active_port will be the @@ -237,10 +512,11 @@ format_chart_text(InetMon *in, gchar *src_string, gchar *buf, gint size) { GList *list; - GkrellmChart *cp; - GkrellmChartdata *cd; + GkrellmChart *cp; + GkrellmChartdata *cd; gchar c, *s, *s1; - gint len, value, n, i, w; + gint len, n, i, w; + gint64 value; if (!buf || size < 1) return; @@ -260,7 +536,20 @@ if ((c = *(s + 1)) == 'M') value = gkrellm_get_chart_scalemax(cp); else if (c == 'a' && *in->label0) - value = in->active0; + { + switch (in->display_mode) + { + case 0: + value = in->active0; + break; + case 1: + value = in->pkts0; + break; + case 2: + value = in->bytes0; + break; + } + } else if (c == 'l' && *in->label0) s1 = in->label0; else if (c == 'c' && *(s + 2)) @@ -268,21 +557,56 @@ i = 0; sscanf(s + 2, "%d%n", &n, &i); s += i; - --n; - if (n > w || n < 0) - n = w; - list = in->hour_mode ? - in->chart_hour->cd_list : in->chart_minute->cd_list; - cd = (GkrellmChartdata *) list->data; + if (*in->label0) { - value = in->hour_mode ? in->hits0_hour : in->hits0_minute; - for ( ; n > 0; --n) - value += gkrellm_get_chartdata_data(cd, w - n); + --n; + if (n > w || n < 0) + n = w; + switch (in->display_mode) + { + case 0: + list = in->hour_mode ? + in->chart_hour->cd_list : in->chart_minute->cd_list; + cd = (GkrellmChartdata *) list->data; + value = in->hour_mode ? in->hits0_hour : in->hits0_minute; + for ( ; n > 0; --n) + value += gkrellm_get_chartdata_data(cd, w - n); + break; + case 1: + list = in->hour_mode ? + in->chart_hour_pkts->cd_list : in->chart_minute_pkts->cd_list; + cd = (GkrellmChartdata *) list->data; + value = in->hour_mode ? in->pkts0_hour : in->pkts0_minute; + for ( ; n > 0; --n) + value += gkrellm_get_chartdata_data(cd, w - n); + break; + case 2: + list = in->hour_mode ? + in->chart_hour_bytes->cd_list : in->chart_minute_bytes->cd_list; + cd = (GkrellmChartdata *) list->data; + value = in->hour_mode ? in->bytes0_hour : in->bytes0_minute; + for ( ; n > 0; --n) + value += gkrellm_get_chartdata_data(cd, w - n); + break; + } } } else if (c == 'A' && *in->label1) - value = in->active1; + { + switch (in->display_mode) + { + case 0: + value = in->active1; + break; + case 1: + value = in->pkts1; + break; + case 2: + value = in->bytes1; + break; + } + } else if (c == 'L' && *in->label1) s1 = in->label1; else if (c == 'C' && *(s + 2)) @@ -290,23 +614,101 @@ i = 0; sscanf(s + 2, "%d%n", &n, &i); s += i; - --n; - if (n > w || n < 0) - n = w; - list = in->hour_mode ? - in->chart_hour->cd_list : in->chart_minute->cd_list; - if (list->next) - list = list->next; - cd = (GkrellmChartdata *) list->data; + if (*in->label1) { - value = in->hour_mode ? in->hits1_hour : in->hits1_minute; - for ( ; n > 0; --n) - value += gkrellm_get_chartdata_data(cd, w - n); + --n; + if (n > w || n < 0) + n = w; + switch (in->display_mode) + { + case 0: + list = in->hour_mode ? + in->chart_hour->cd_list : in->chart_minute->cd_list; + if (list->next) + list = list->next; + cd = (GkrellmChartdata *) list->data; + value = in->hour_mode ? in->hits1_hour : in->hits1_minute; + for ( ; n > 0; --n) + value += gkrellm_get_chartdata_data(cd, w - n); + break; + case 1: + list = in->hour_mode ? + in->chart_hour_pkts->cd_list : in->chart_minute_pkts->cd_list; + if (list->next) + list = list->next; + cd = (GkrellmChartdata *) list->data; + value = in->hour_mode ? in->pkts1_hour : in->pkts1_minute; + for ( ; n > 0; --n) + value += gkrellm_get_chartdata_data(cd, w - n); + break; + case 2: + list = in->hour_mode ? + in->chart_hour_bytes->cd_list : in->chart_minute_bytes->cd_list; + if (list->next) + list = list->next; + cd = (GkrellmChartdata *) list->data; + value = in->hour_mode ? in->bytes1_hour : in->bytes1_minute; + for ( ; n > 0; --n) + value += gkrellm_get_chartdata_data(cd, w - n); + break; + } } } + if (value >= 0) - len = snprintf(buf, size, "%d", value); + { + gint index = 0; + gdouble svalue = 0; + char *vsuffix = " kMGTPEYZ"; + gchar *vtype = "HPB"; + if (value < 1e3) + { + index = 0; + svalue = value; + } + else if (value < 1e6) + { + index = 1; + svalue = value / 1e3; + } + else if (value < 1e9) + { + index = 2; + svalue = value / 1e6; + } + else if (value < 1e12) + { + index = 3; + svalue = value / 1e9; + } + else if (value < 1e15) + { + index = 4; + svalue = value / 1e12; + } + else if (value < 1e18) + { + index = 5; + svalue = value / 1e15; + } + else if (value < 1e21) + { + index = 6; + svalue = value / 1e18; + } + else if (value < 1e24) + { + index = 7; + svalue = value / 1e21; + } + else + { + index = 8; + svalue = value / 1e24; + } + len = snprintf(buf, size, "%.3lg %c%c", svalue, *(vsuffix+index), *(vtype+in->display_mode)); + } else len = snprintf(buf, size, "%s", s1); ++s; @@ -383,7 +785,7 @@ struct tm tm; GdkGC *gc3; GkrellmChart *cp; - GkrellmTextstyle *ts; + GkrellmTextstyle *ts_alt; GdkColor tmp_color; gchar buf[32]; guint32 pixel0, pixel1; @@ -397,7 +799,7 @@ gdk_drawable_get_size(in->chart->bg_grid_pixmap, &w, &h); if (grid == NULL) grid = gdk_drawable_get_image(in->chart->bg_grid_pixmap, 0, 0, w, h); - ts = gkrellm_chart_alt_textstyle(style_id); + ts_alt = gkrellm_chart_alt_textstyle(style_id); tm = *gkrellm_get_current_time(); gc3 = gkrellm_draw_GC(3); @@ -429,7 +831,7 @@ { strftime(buf, sizeof(buf), "%a", &tm); buf[1] = '\0'; - gkrellm_draw_chart_label(in->chart, ts, + gkrellm_draw_chart_label(in->chart, ts_alt, cp->x + n, in->chart->h - 4, buf); } if (--tm.tm_hour < 0) @@ -471,26 +873,112 @@ draw_inet_extra(in); gkrellm_draw_chart_to_screen(cp); in->prev_active0 = in->active0; + in->prev_pkts0 = in->pkts0; + in->prev_bytes0 = in->bytes0; in->prev_active1 = in->active1; + in->prev_pkts1 = in->pkts1; + in->prev_bytes1 = in->bytes1; } static void select_hour_or_minute_chart(InetMon *in) { gkrellm_freeze_side_frame_packing(); - if (in->hour_mode && in->chart == in->chart_minute) + if (in->hour_mode) { - gkrellm_chart_hide(in->chart_minute, FALSE); - gkrellm_chart_show(in->chart_hour, FALSE); - in->chart = in->chart_hour; - gkrellm_chartconfig_window_destroy(in->chart_minute); + switch (in->display_mode) + { + case 0: + gkrellm_chart_hide(in->chart_minute_bytes, FALSE); + gkrellm_chart_hide(in->chart_hour_bytes, FALSE); + gkrellm_chart_hide(in->chart_minute_pkts, FALSE); + gkrellm_chart_hide(in->chart_hour_pkts, FALSE); + gkrellm_chart_hide(in->chart_minute, FALSE); + gkrellm_chart_show(in->chart_hour, FALSE); + in->chart = in->chart_hour; + gkrellm_chartconfig_window_destroy(in->chart_minute_bytes); + gkrellm_chartconfig_window_destroy(in->chart_hour_bytes); + gkrellm_chartconfig_window_destroy(in->chart_minute_pkts); + gkrellm_chartconfig_window_destroy(in->chart_hour_pkts); + gkrellm_chartconfig_window_destroy(in->chart_minute); + break; + case 1: + gkrellm_chart_hide(in->chart_minute, FALSE); + gkrellm_chart_hide(in->chart_hour, FALSE); + gkrellm_chart_hide(in->chart_minute_bytes, FALSE); + gkrellm_chart_hide(in->chart_hour_bytes, FALSE); + gkrellm_chart_hide(in->chart_minute_pkts, FALSE); + gkrellm_chart_show(in->chart_hour_pkts, FALSE); + in->chart = in->chart_hour_pkts; + gkrellm_chartconfig_window_destroy(in->chart_minute); + gkrellm_chartconfig_window_destroy(in->chart_hour); + gkrellm_chartconfig_window_destroy(in->chart_minute_bytes); + gkrellm_chartconfig_window_destroy(in->chart_hour_bytes); + gkrellm_chartconfig_window_destroy(in->chart_minute_pkts); + break; + case 2: + gkrellm_chart_hide(in->chart_minute_pkts, FALSE); + gkrellm_chart_hide(in->chart_hour_pkts, FALSE); + gkrellm_chart_hide(in->chart_minute, FALSE); + gkrellm_chart_hide(in->chart_hour, FALSE); + gkrellm_chart_hide(in->chart_minute_bytes, FALSE); + gkrellm_chart_show(in->chart_hour_bytes, FALSE); + in->chart = in->chart_hour_bytes; + gkrellm_chartconfig_window_destroy(in->chart_minute_pkts); + gkrellm_chartconfig_window_destroy(in->chart_hour_pkts); + gkrellm_chartconfig_window_destroy(in->chart_minute); + gkrellm_chartconfig_window_destroy(in->chart_hour); + gkrellm_chartconfig_window_destroy(in->chart_minute_bytes); + break; + } } - else if (!in->hour_mode && in->chart == in->chart_hour) + else { - gkrellm_chart_hide(in->chart_hour, FALSE); - gkrellm_chart_show(in->chart_minute, FALSE); - in->chart = in->chart_minute; - gkrellm_chartconfig_window_destroy(in->chart_hour); + switch (in->display_mode) + { + case 0: + gkrellm_chart_hide(in->chart_hour_bytes, FALSE); + gkrellm_chart_hide(in->chart_minute_bytes, FALSE); + gkrellm_chart_hide(in->chart_hour_pkts, FALSE); + gkrellm_chart_hide(in->chart_minute_pkts, FALSE); + gkrellm_chart_hide(in->chart_hour, FALSE); + gkrellm_chart_show(in->chart_minute, FALSE); + in->chart = in->chart_minute; + gkrellm_chartconfig_window_destroy(in->chart_hour_bytes); + gkrellm_chartconfig_window_destroy(in->chart_minute_bytes); + gkrellm_chartconfig_window_destroy(in->chart_hour_pkts); + gkrellm_chartconfig_window_destroy(in->chart_minute_pkts); + gkrellm_chartconfig_window_destroy(in->chart_hour); + break; + case 1: + gkrellm_chart_hide(in->chart_hour, FALSE); + gkrellm_chart_hide(in->chart_minute, FALSE); + gkrellm_chart_hide(in->chart_hour_bytes, FALSE); + gkrellm_chart_hide(in->chart_minute_bytes, FALSE); + gkrellm_chart_hide(in->chart_hour_pkts, FALSE); + gkrellm_chart_show(in->chart_minute_pkts, FALSE); + in->chart = in->chart_minute_pkts; + gkrellm_chartconfig_window_destroy(in->chart_hour); + gkrellm_chartconfig_window_destroy(in->chart_minute); + gkrellm_chartconfig_window_destroy(in->chart_hour_bytes); + gkrellm_chartconfig_window_destroy(in->chart_minute_bytes); + gkrellm_chartconfig_window_destroy(in->chart_hour_pkts); + break; + case 2: + gkrellm_chart_hide(in->chart_hour_pkts, FALSE); + gkrellm_chart_hide(in->chart_minute_pkts, FALSE); + gkrellm_chart_hide(in->chart_hour, FALSE); + gkrellm_chart_hide(in->chart_minute, FALSE); + gkrellm_chart_hide(in->chart_hour_bytes, FALSE); + gkrellm_chart_show(in->chart_minute_bytes, FALSE); + in->chart = in->chart_minute_bytes; + gkrellm_chartconfig_window_destroy(in->chart_hour_pkts); + gkrellm_chartconfig_window_destroy(in->chart_minute_pkts); + gkrellm_chartconfig_window_destroy(in->chart_hour); + gkrellm_chartconfig_window_destroy(in->chart_minute); + gkrellm_chartconfig_window_destroy(in->chart_hour_bytes); + break; + } } gkrellm_thaw_side_frame_packing(); } @@ -515,7 +1003,11 @@ { in = (InetMon *) list->data; in->active0 = 0; + in->pkts0 = 0; + in->bytes0 = 0; in->active1 = 0; + in->pkts1 = 0; + in->bytes1 = 0; } /* Assume all connections are dead, then read_tcp_data() will set | still alive ones back to alive. Then I can prune really dead ones. @@ -552,34 +1044,66 @@ if (GK.hour_tick) { if (!*in->label0) + { in->hits0_hour = in->hits1_hour; + in->pkts0_hour = in->pkts1_hour; + in->bytes0_hour = in->bytes1_hour; + } gkrellm_store_chartdata(in->chart_hour, 0, in->hits0_hour, in->hits1_hour); + gkrellm_store_chartdata(in->chart_hour_pkts, 0, + in->pkts0_hour, in->pkts1_hour); + gkrellm_store_chartdata(in->chart_hour_bytes, 0, + in->bytes0_hour, in->bytes1_hour); in->hits0_hour = in->hits1_hour = 0; + in->pkts0_hour = in->pkts1_hour = 0; + in->bytes0_hour = in->bytes1_hour = 0; if (GK.day_tick) /* Make room for vertical day grid */ { - gkrellm_store_chartdata(in->chart_hour, 0, 0, 0); - gkrellm_store_chartdata(in->chart_hour, 0, 0, 0); + gkrellm_store_chartdata(in->chart_hour, 0, 0LL, 0LL); + gkrellm_store_chartdata(in->chart_hour, 0, 0LL, 0LL); + gkrellm_store_chartdata(in->chart_hour_pkts, 0, 0LL, 0LL); + gkrellm_store_chartdata(in->chart_hour_pkts, 0, 0LL, 0LL); + gkrellm_store_chartdata(in->chart_hour_bytes, 0, 0LL, 0LL); + gkrellm_store_chartdata(in->chart_hour_bytes, 0, 0LL, 0LL); } } if (GK.minute_tick) { if (!*in->label0) + { in->hits0_minute = in->hits1_minute; + in->pkts0_minute = in->pkts1_minute; + in->bytes0_minute = in->bytes1_minute; + } gkrellm_store_chartdata(in->chart_minute, 0, in->hits0_minute, in->hits1_minute); + gkrellm_store_chartdata(in->chart_minute_pkts, 0, + in->pkts0_minute, in->pkts1_minute); + gkrellm_store_chartdata(in->chart_minute_bytes, 0, + in->bytes0_minute, in->bytes1_minute); in->hits0_minute = in->hits1_minute = 0; + in->pkts0_minute = in->pkts1_minute = 0; + in->bytes0_minute = in->bytes1_minute = 0; if (GK.hour_tick) /* Make room for vertical hour grid */ { - gkrellm_store_chartdata(in->chart_minute, 0, 0, 0); - gkrellm_store_chartdata(in->chart_minute, 0, 0, 0); + gkrellm_store_chartdata(in->chart_minute, 0, 0LL, 0LL); + gkrellm_store_chartdata(in->chart_minute, 0, 0LL, 0LL); + gkrellm_store_chartdata(in->chart_minute_pkts, 0, 0LL, 0LL); + gkrellm_store_chartdata(in->chart_minute_pkts, 0, 0LL, 0LL); + gkrellm_store_chartdata(in->chart_minute_bytes, 0, 0LL, 0LL); + gkrellm_store_chartdata(in->chart_minute_bytes, 0, 0LL, 0LL); } gkrellm_refresh_chart(in->chart); draw_inet_mark_data(in, 1); } else if ( GK.second_tick - && ( in->prev_active0 != in->active0 - || in->prev_active1 != in->active1 + && ( (in->display_mode == 0 && (in->prev_active0 != in->active0 + || in->prev_active1 != in->active1)) || + (in->display_mode == 1 && (in->prev_pkts0 != in->pkts0 + || in->prev_pkts1 != in->pkts1)) || + (in->display_mode == 2 && (in->prev_bytes0 != in->bytes0 + || in->prev_bytes1 != in->bytes1)) ) ) draw_inet_chart(in); /* Just to update extra info draw */ @@ -593,7 +1117,19 @@ i = D_MISC_BUTTON_OUT; gkrellm_set_decal_button_index(in->list_button, i); - gkrellm_update_krell(in->panel, KRELL(in->panel), in->krell_hits); + switch (in->display_mode) + { + case 0: + gkrellm_update_krell(in->panel, KRELL(in->panel), in->krell_hits); + break; + case 1: + gkrellm_update_krell(in->panel, KRELL(in->panel), in->krell_pkts); + break; + case 2: + gkrellm_update_krell(in->panel, KRELL(in->panel), in->krell_bytes); + break; + } + gkrellm_draw_panel_layers(in->panel); if (in->connection_string_event) @@ -698,7 +1234,7 @@ static void cb_list_button(GkrellmDecalbutton *button) - { + { InetMon *in = (InetMon *) button->data; GList *list; ActiveTCP *tcp, *tcp_save; @@ -743,6 +1279,16 @@ pixmap = in->chart_minute->pixmap; else if (widget == in->chart_hour->drawing_area) pixmap = in->chart_hour->pixmap; + + else if (widget == in->chart_minute_pkts->drawing_area) + pixmap = in->chart_minute_pkts->pixmap; + else if (widget == in->chart_hour_pkts->drawing_area) + pixmap = in->chart_hour_pkts->pixmap; + + else if (widget == in->chart_minute_bytes->drawing_area) + pixmap = in->chart_minute_bytes->pixmap; + else if (widget == in->chart_hour_bytes->drawing_area) + pixmap = in->chart_hour_bytes->pixmap; if (pixmap) { gdk_draw_drawable(widget->window, gkrellm_draw_GC(1), pixmap, @@ -767,8 +1313,16 @@ continue; if (ev->button == 1 && ev->type == GDK_BUTTON_PRESS) { - in->extra_info = !in->extra_info; - gkrellm_refresh_chart(in->chart); + if (in->extra_info) + { + in->extra_info = FALSE; + if (++in->display_mode == 3) + in->display_mode = 0; + } + else + in->extra_info = TRUE; + select_hour_or_minute_chart(in); + gkrellm_rescale_chart(in->chart); gkrellm_config_modified(); } else if (ev->button == 2) @@ -777,9 +1331,7 @@ select_hour_or_minute_chart(in); gkrellm_rescale_chart(in->chart); } - else if ( ev->button == 3 - || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) - ) + else if (ev->button == 3) gkrellm_chartconfig_window_create(in->chart); break; } @@ -806,11 +1358,20 @@ gkrellm_set_chart_height(in->chart_minute, h); if (in->chart_hour->h != h) gkrellm_set_chart_height(in->chart_hour, h); + if (in->chart_minute_pkts->h != h) + gkrellm_set_chart_height(in->chart_minute_pkts, h); + if (in->chart_hour_pkts->h != h) + gkrellm_set_chart_height(in->chart_hour_pkts, h); + if (in->chart_minute_bytes->h != h) + gkrellm_set_chart_height(in->chart_minute_bytes, h); + if (in->chart_hour_bytes->h != h) + gkrellm_set_chart_height(in->chart_hour_bytes, h); } static void destroy_inet_monitor(InetMon *in) { + GTCPHistory *list; if (in->launch_table) gtk_widget_destroy(in->launch_table); g_free(in->name); @@ -820,13 +1381,25 @@ g_free(in->launch.command); if (in->launch.button) gkrellm_destroy_button(in->launch.button); - in->launch.tooltip = NULL; + in->launch.tooltip = NULL; g_free(in->mark_data); /* The panel doesn't live in the chart struct, so destroy it separately */ gkrellm_panel_destroy(in->panel); + gkrellm_chartconfig_destroy(&in->chart_config_minute_bytes); + gkrellm_chart_destroy(in->chart_minute_bytes); + + gkrellm_chartconfig_destroy(&in->chart_config_hour_bytes); + gkrellm_chart_destroy(in->chart_hour_bytes); + + gkrellm_chartconfig_destroy(&in->chart_config_minute_pkts); + gkrellm_chart_destroy(in->chart_minute_pkts); + + gkrellm_chartconfig_destroy(&in->chart_config_hour_pkts); + gkrellm_chart_destroy(in->chart_hour_pkts); + gkrellm_chartconfig_destroy(&in->chart_config_minute); gkrellm_chart_destroy(in->chart_minute); @@ -834,6 +1407,14 @@ gkrellm_chart_destroy(in->chart_hour); gtk_widget_destroy(in->vbox); + list = in->tcp_history; + while (list) + { + GTCPHistory *tmp; + tmp = list; + list = list->next; + g_free(tmp); + } g_free(in); } @@ -915,6 +1496,10 @@ in->vbox = vbox; in->chart_minute = gkrellm_chart_new0(); in->chart_hour = gkrellm_chart_new0(); + in->chart_minute_pkts = gkrellm_chart_new0(); + in->chart_hour_pkts = gkrellm_chart_new0(); + in->chart_minute_bytes = gkrellm_chart_new0(); + in->chart_hour_bytes = gkrellm_chart_new0(); in->panel = gkrellm_panel_new0(); in->chart = in->chart_minute; in->name = g_strdup_printf(_("inet%d"), n_inet_monitors++); @@ -927,12 +1512,37 @@ } if (in->chart_config_hour && in->chart_config_minute) in->chart_config_hour->h = in->chart_config_minute->h; + + if (in->chart_config_minute_pkts && in->chart_config_minute) + in->chart_config_minute_pkts->h = in->chart_config_minute->h; + if (in->chart_config_hour_pkts && in->chart_config_minute) + in->chart_config_hour_pkts->h = in->chart_config_minute->h; + + if (in->chart_config_minute_bytes && in->chart_config_minute) + in->chart_config_minute_bytes->h = in->chart_config_minute->h; + if (in->chart_config_hour_bytes && in->chart_config_minute) + in->chart_config_hour_bytes->h = in->chart_config_minute->h; + chart_create(in, in->chart_minute, &in->chart_config_minute, first_create); gkrellm_chartconfig_grid_resolution_label(in->chart_config_minute, _("TCP hits per minute")); chart_create(in, in->chart_hour, &in->chart_config_hour, first_create); gkrellm_chartconfig_grid_resolution_label(in->chart_config_hour, _("TCP hits per hour")); + + chart_create(in, in->chart_minute_pkts, &in->chart_config_minute_pkts, first_create); + gkrellm_chartconfig_grid_resolution_label(in->chart_config_minute_pkts, + _("Packets per minute")); + chart_create(in, in->chart_hour_pkts, &in->chart_config_hour_pkts, first_create); + gkrellm_chartconfig_grid_resolution_label(in->chart_config_hour_pkts, + _("Packets per hour")); + + chart_create(in, in->chart_minute_bytes, &in->chart_config_minute_bytes, first_create); + gkrellm_chartconfig_grid_resolution_label(in->chart_config_minute_bytes, + _("Bytes per minute")); + chart_create(in, in->chart_hour_bytes, &in->chart_config_hour_bytes, first_create); + gkrellm_chartconfig_grid_resolution_label(in->chart_config_hour_bytes, + _("Bytes per hour")); cp = in->chart; p = in->panel; @@ -973,6 +1583,10 @@ gtk_widget_show(vbox); gkrellm_chart_hide(in->chart_hour, FALSE); + gkrellm_chart_hide(in->chart_minute_pkts, FALSE); + gkrellm_chart_hide(in->chart_hour_pkts, FALSE); + gkrellm_chart_hide(in->chart_minute_bytes, FALSE); + gkrellm_chart_hide(in->chart_hour_bytes, FALSE); } gkrellm_setup_launcher(p, &in->launch, CHART_PANEL_TYPE, 4); @@ -1047,17 +1661,30 @@ in = (InetMon *) list->data; l0 = (*in->label0) ? in->label0: "NONE"; l1 = (*in->label1) ? in->label1: "NONE"; - fprintf(f, "%s monitor %s %s %lu %lu %s %lu %lu %d %d %d\n", + fprintf(f, "%s monitor %s %s %ld %ld %s %ld %ld %d %d %d %d %d %d\n", INET_CONFIG_KEYWORD, in->name, l0, in->port0_0, in->port0_1, l1, in->port1_0, in->port1_1, - in->extra_info, in->data0_is_range, in->data1_is_range); + in->extra_info, in->display_mode, in->data0_is_range, in->data1_is_range, + in->data0_outbound, in->data1_outbound); snprintf(buf, sizeof(buf), "%s:minute", in->name); gkrellm_save_chartconfig(f, in->chart_config_minute, INET_CONFIG_KEYWORD, buf); snprintf(buf, sizeof(buf), "%s:hour", in->name); gkrellm_save_chartconfig(f, in->chart_config_hour, INET_CONFIG_KEYWORD, buf); + snprintf(buf, sizeof(buf), "%s:minute_pkts", in->name); + gkrellm_save_chartconfig(f, in->chart_config_minute_pkts, + INET_CONFIG_KEYWORD, buf); + snprintf(buf, sizeof(buf), "%s:hour_pkts", in->name); + gkrellm_save_chartconfig(f, in->chart_config_hour_pkts, + INET_CONFIG_KEYWORD, buf); + snprintf(buf, sizeof(buf), "%s:minute_bytes", in->name); + gkrellm_save_chartconfig(f, in->chart_config_minute_bytes, + INET_CONFIG_KEYWORD, buf); + snprintf(buf, sizeof(buf), "%s:hour_bytes", in->name); + gkrellm_save_chartconfig(f, in->chart_config_hour_bytes, + INET_CONFIG_KEYWORD, buf); if (in->launch.command) fprintf(f, "%s launch %s %s\n", INET_CONFIG_KEYWORD, in->name, in->launch.command); @@ -1079,12 +1706,12 @@ if (!*in->label0) { - in->port0_1 = in->port0_1 = in->data0_is_range = 0; + in->port0_1 = in->port0_1 = in->data0_is_range = in->data0_outbound = 0; --cd_length; } if (!*in->label1) { - in->port1_1 = in->port1_1 = in->data1_is_range = 0; + in->port1_1 = in->port1_1 = in->data1_is_range = in->data1_outbound = 0; --cd_length; } if (in->data0_is_range && (in->port0_1 < in->port0_0)) @@ -1133,10 +1760,11 @@ in = g_new0(InetMon, 1); label0[0] = '\0'; label1[0] = '\0'; - sscanf(item, "%15s %lu %lu %15s %lu %lu %d %d %d", + sscanf(item, "%15s %ld %ld %15s %ld %ld %d %d %d %d %d %d", label0, &in->port0_0, &in->port0_1, label1, &in->port1_0, &in->port1_1, - &in->extra_info, &in->data0_is_range, &in->data1_is_range); + &in->extra_info, &in->display_mode, &in->data0_is_range, &in->data1_is_range, + &in->data0_outbound, &in->data1_outbound); if (!strcmp(label0, "NONE")) label0[0] = '\0'; if (!strcmp(label1, "NONE")) @@ -1149,6 +1777,10 @@ in->name = g_strdup(name); in->chart_config_minute = gkrellm_chartconfig_new0(); in->chart_config_hour = gkrellm_chartconfig_new0(); + in->chart_config_minute_pkts = gkrellm_chartconfig_new0(); + in->chart_config_hour_pkts = gkrellm_chartconfig_new0(); + in->chart_config_minute_bytes = gkrellm_chartconfig_new0(); + in->chart_config_hour_bytes = gkrellm_chartconfig_new0(); inet_mon_list = g_list_append(inet_mon_list, in); } else /* Bogus config line */ @@ -1169,6 +1801,18 @@ if (hr_min && !strcmp(hr_min, "minute")) gkrellm_load_chartconfig(&in->chart_config_minute, item, in->cd_length); + if (hr_min && !strcmp(hr_min, "hour_pkts")) + gkrellm_load_chartconfig(&in->chart_config_hour_pkts, item, + in->cd_length); + if (hr_min && !strcmp(hr_min, "minute_pkts")) + gkrellm_load_chartconfig(&in->chart_config_minute_pkts, item, + in->cd_length); + if (hr_min && !strcmp(hr_min, "hour_bytes")) + gkrellm_load_chartconfig(&in->chart_config_hour_bytes, item, + in->cd_length); + if (hr_min && !strcmp(hr_min, "minute_bytes")) + gkrellm_load_chartconfig(&in->chart_config_minute_bytes, item, + in->cd_length); } else if (!strcmp(config, "launch")) gkrellm_dup_string(&in->launch.command, item); @@ -1188,7 +1832,8 @@ { struct tm *tm; gchar data[64]; - gint n, in, out, cur_slot, skew, day; + gint n, cur_slot, skew, day; + gint64 in, out; tm = gkrellm_get_current_time(); day = tm->tm_yday - yday; @@ -1222,7 +1867,7 @@ | Charts will circular buff fill until data runs out. */ out = in = 0; - sscanf(data, "%d %d", &out, &in); + sscanf(data, "%Ld %Ld", &out, &in); gkrellm_store_chartdata(cp, 0, out, in); } /* Need to store zero data for time slots not in read data to bring @@ -1235,18 +1880,18 @@ { while (n-- > 0) { - gkrellm_store_chartdata(cp, 0, 0, 0); + gkrellm_store_chartdata(cp, 0, 0LL, 0LL); if (minute_chart && min++ == 0) { - gkrellm_store_chartdata(cp, 0, 0, 0); - gkrellm_store_chartdata(cp, 0, 0, 0); + gkrellm_store_chartdata(cp, 0, 0LL, 0LL); + gkrellm_store_chartdata(cp, 0, 0LL, 0LL); if (min == 60) min = 0; } else if (!minute_chart && hour++ == 0) { - gkrellm_store_chartdata(cp, 0, 0, 0); - gkrellm_store_chartdata(cp, 0, 0, 0); + gkrellm_store_chartdata(cp, 0, 0LL, 0LL); + gkrellm_store_chartdata(cp, 0, 0LL, 0LL); if (hour == 24) hour = 0; } @@ -1264,7 +1909,7 @@ for (n = 0; n < cp->w; ++n) { for (list = cp->cd_list; list; list = list->next) - fprintf(f, "%d ", + fprintf(f, "%Ld ", gkrellm_get_chartdata_data((GkrellmChartdata *) list->data, n)); fprintf(f, "\n"); } @@ -1310,11 +1955,19 @@ | chart data array, and then save the chart data. */ fputs("hits0_minute hits1_minute hits0_hour hits1_hour\n", f); - fprintf(f, "%ld %ld %ld %ld\n", + fprintf(f, "%Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu\n", in->hits0_minute, in->hits1_minute, - in->hits0_hour, in->hits1_hour); + in->hits0_hour, in->hits1_hour, + in->pkts0_minute, in->pkts1_minute, + in->pkts0_hour, in->pkts1_hour, + in->bytes0_minute, in->bytes1_minute, + in->bytes0_hour, in->bytes1_hour); write_inet_data(in->chart_minute, f); write_inet_data(in->chart_hour, f); + write_inet_data(in->chart_minute_pkts, f); + write_inet_data(in->chart_hour_pkts, f); + write_inet_data(in->chart_minute_bytes, f); + write_inet_data(in->chart_hour_bytes, f); fclose(f); } } @@ -1343,9 +1996,13 @@ sscanf(buf, "%d %d %d %d", &min, &hour, &yday, &len); fgets(buf, sizeof(buf), f); /* Comment line */ fgets(buf, sizeof(buf), f); - sscanf(buf, "%ld %ld %ld %ld", + sscanf(buf, "%Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", &in->hits0_minute, &in->hits1_minute, - &in->hits0_hour, &in->hits1_hour); + &in->hits0_hour, &in->hits1_hour, + &in->pkts0_minute, &in->pkts1_minute, + &in->pkts0_hour, &in->pkts1_hour, + &in->bytes0_minute, &in->bytes1_minute, + &in->bytes0_hour, &in->bytes1_hour); skew = read_inet_data(in->chart_minute, f, 1, min, hour, yday, len); if (skew > 0) /* Current minute slot is different from saved */ @@ -1355,6 +2012,22 @@ if (skew > 0) /* Current hour slot is different from saved */ in->hits0_hour = in->hits1_hour = 0; + skew = read_inet_data(in->chart_minute_pkts, f, 1, min, hour, yday, len); + if (skew > 0) /* Current minute slot is different from saved */ + in->pkts0_minute = in->pkts1_minute = 0; + + skew = read_inet_data(in->chart_hour_pkts, f, 0, min, hour, yday, len); + if (skew > 0) /* Current hour slot is different from saved */ + in->pkts0_hour = in->pkts1_hour = 0; + + skew = read_inet_data(in->chart_minute_bytes, f, 1, min, hour, yday, len); + if (skew > 0) /* Current minute slot is different from saved */ + in->bytes0_minute = in->bytes1_minute = 0; + + skew = read_inet_data(in->chart_hour_bytes, f, 0, min, hour, yday, len); + if (skew > 0) /* Current hour slot is different from saved */ + in->bytes0_hour = in->bytes1_hour = 0; + fclose(f); gkrellm_rescale_chart(in->chart); } @@ -1369,11 +2042,13 @@ PORT00_COLUMN, PORT01_COLUMN, RANGE0_COLUMN, + TYPE0_COLUMN, SPACER_COLUMN, LABEL1_COLUMN, PORT10_COLUMN, PORT11_COLUMN, RANGE1_COLUMN, + TYPE1_COLUMN, DUMMY_COLUMN, INET_COLUMN, N_COLUMNS @@ -1396,6 +2071,9 @@ static GtkWidget *data0_range_button, *data1_range_button; +static GtkWidget *data0_outbound, + *data1_outbound; + static GtkWidget *text_format_combo; @@ -1412,12 +2090,14 @@ LABEL0_COLUMN, in->label0, PORT00_COLUMN, p00, PORT01_COLUMN, p01, - SPACER_COLUMN, "", RANGE0_COLUMN, in->data0_is_range, + TYPE0_COLUMN, in->data0_outbound, + SPACER_COLUMN, "", LABEL1_COLUMN, in->label1, PORT10_COLUMN, p10, PORT11_COLUMN, p11, RANGE1_COLUMN, in->data1_is_range, + TYPE1_COLUMN, in->data1_outbound, DUMMY_COLUMN, "", -1); } @@ -1431,9 +2111,9 @@ InetMon *in; store = gtk_list_store_new(N_COLUMNS, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_POINTER); for (list = inet_mon_list; list; list = list->next) { @@ -1475,10 +2155,12 @@ PORT00_COLUMN, &ports[0], PORT01_COLUMN, &ports[1], RANGE0_COLUMN, &in->data0_is_range, + TYPE0_COLUMN, &in->data0_outbound, LABEL1_COLUMN, &in->label1, PORT10_COLUMN, &ports[2], PORT11_COLUMN, &ports[3], RANGE1_COLUMN, &in->data1_is_range, + TYPE1_COLUMN, &in->data1_outbound, -1); in->port0_0 = atoi(ports[0]); in->port0_1 = atoi(ports[1]); @@ -1533,12 +2215,16 @@ gtk_entry_set_text(GTK_ENTRY(port0_1_entry), ports[1]); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data0_range_button), in->data0_is_range); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data0_outbound), + in->data0_outbound); gtk_entry_set_text(GTK_ENTRY(label1_entry), in->label1); gtk_entry_set_text(GTK_ENTRY(port1_0_entry), ports[2]); gtk_entry_set_text(GTK_ENTRY(port1_1_entry), ports[3]); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data1_range_button), in->data1_is_range); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data1_outbound), + in->data1_outbound); g_free(in->label0); g_free(in->label1); for (i = 0; i < 4; ++i) @@ -1550,7 +2236,7 @@ { gkrellm_apply_launcher(&in->launch_entry, &in->tooltip_entry, in->panel, &in->launch, gkrellm_launch_button_cb); - } + } static void add_launch_entry(GtkWidget *vbox, InetMon *in) @@ -1609,6 +2295,17 @@ in_tmp->chart_config_minute = NULL; in->chart_config_hour = in_tmp->chart_config_hour; in_tmp->chart_config_hour = NULL; + + in->chart_config_minute_pkts = in_tmp->chart_config_minute_pkts; + in_tmp->chart_config_minute_pkts = NULL; + in->chart_config_hour_pkts = in_tmp->chart_config_hour_pkts; + in_tmp->chart_config_hour_pkts = NULL; + + in->chart_config_minute_bytes = in_tmp->chart_config_minute_bytes; + in_tmp->chart_config_minute_bytes = NULL; + in->chart_config_hour_bytes = in_tmp->chart_config_hour_bytes; + in_tmp->chart_config_hour_bytes = NULL; + in->extra_info = in_tmp->extra_info; in->hour_mode = in_tmp->hour_mode; } @@ -1620,6 +2317,20 @@ in->chart_config_minute, TRUE); gkrellm_set_chartconfig_auto_grid_resolution( in->chart_config_hour, TRUE); + + in->chart_config_minute_pkts = gkrellm_chartconfig_new0(); + in->chart_config_hour_pkts = gkrellm_chartconfig_new0(); + gkrellm_set_chartconfig_auto_grid_resolution( + in->chart_config_minute_pkts, TRUE); + gkrellm_set_chartconfig_auto_grid_resolution( + in->chart_config_hour_pkts, TRUE); + + in->chart_config_minute_bytes = gkrellm_chartconfig_new0(); + in->chart_config_hour_bytes = gkrellm_chartconfig_new0(); + gkrellm_set_chartconfig_auto_grid_resolution( + in->chart_config_minute_bytes, TRUE); + gkrellm_set_chartconfig_auto_grid_resolution( + in->chart_config_hour_bytes, TRUE); in->extra_info = TRUE; } if (in_tmp) @@ -1677,7 +2388,10 @@ in = g_new0(InetMon, 1); in->data0_is_range = GTK_TOGGLE_BUTTON(data0_range_button)->active; + in->data0_outbound = GTK_TOGGLE_BUTTON(data0_outbound)->active; + in->data1_is_range = GTK_TOGGLE_BUTTON(data1_range_button)->active; + in->data1_outbound = GTK_TOGGLE_BUTTON(data1_outbound)->active; in->label0 = gkrellm_gtk_entry_get_text(&label0_entry); if (*(in->label0)) @@ -1882,12 +2596,16 @@ hbox = gtk_hbox_new(FALSE, 2); gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 3, 4, 5); gkrellm_gtk_check_button(hbox, &data0_range_button, 0, TRUE, 0, - _("Port0 - Port1 is a range")); + _("Range")); + gkrellm_gtk_check_button(hbox, &data0_outbound, 0, TRUE, 0, + _("Outbound")); hbox = gtk_hbox_new(FALSE, 2); gtk_table_attach_defaults(GTK_TABLE(table), hbox, 4, 7, 4, 5); gkrellm_gtk_check_button(hbox, &data1_range_button, 0, TRUE, 0, - _("Port0 - Port1 is a range")); + _("Range")); + gkrellm_gtk_check_button(hbox, &data1_outbound, 0, TRUE, 0, + _("Outbound")); separator = gtk_hseparator_new(); gtk_table_attach_defaults(GTK_TABLE(table), separator, 0, 7, 5, 6); @@ -1944,6 +2662,14 @@ gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Port1"), renderer, "text", PORT01_COLUMN, NULL); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Range"), + renderer, + "text", RANGE0_COLUMN, NULL); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Outbound"), + renderer, + "text", TYPE0_COLUMN, NULL); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(treeview, -1, " ", @@ -1964,6 +2690,14 @@ gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Port1"), renderer, "text", PORT11_COLUMN, NULL); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Range"), + renderer, + "text", RANGE1_COLUMN, NULL); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Outbound"), + renderer, + "text", TYPE1_COLUMN, NULL); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(treeview, -1, " ", diff -Naur gkrellm-2.1.23/src/inet.h gkrellm-2.1.23i/src/inet.h --- gkrellm-2.1.23/src/inet.h 2003-01-08 17:56:35.000000000 -0700 +++ gkrellm-2.1.23i/src/inet.h 2003-12-21 14:16:44.000000000 -0700 @@ -75,17 +75,45 @@ #define TCP_DEAD 0 #define TCP_ALIVE 1 + +#define CHAIN_CONNECT 0 // Monitor connections +#define CHAIN_INPUT 1 // Recorded packets from input chain +#define CHAIN_FORWARD 2 // Recorded packets from forward chain +#define CHAIN_OUTPUT 3 // Recorded packets from output chain +#define CHAIN_USER 4 // Recorded packets on a user chain - loses I/O delineation between client/source, but typically + // are convenience chains for log and drop or the like. +#define CHAIN_MAX 5 // Used as array limit for byte and packet count history in inet.c + +#define TARGET_ACCEPT 0 // Processed packet +#define TARGET_QUEUE 1 // Queue packet to user space (if supported) +#define TARGET_RETURN 2 // Return to previous rule set +#define TARGET_DROP 3 // Dropped packets +#define TARGET_LOG 4 // Log to /var/log/messages +#define TARGET_USER 5 // Other target - typically a user convenience chain + +#define PORT_QUEUE -1 +#define PORT_RETURN -2 +#define PORT_DROP -3 +#define PORT_LOG -4 + typedef struct { gint state; gint family; gint local_port; + gint local_port_hi; // for iptables range only struct in_addr remote_addr; #if defined(INET6) struct in6_addr remote_addr6; #endif gint remote_port; + gint remote_port_hi; // for iptables range only gint new_hit; + + gint chain; // chain the packet count was registered under from above list + gint line; // unique rule line number per chain to differentiate between ports handled with different rules + gint target; // the target from above list + guint64 pkts; + guint64 bytes; } ActiveTCP; - diff -Naur gkrellm-2.1.23/src/mem.c gkrellm-2.1.23i/src/mem.c --- gkrellm-2.1.23/src/mem.c 2003-06-17 07:39:34.000000000 -0600 +++ gkrellm-2.1.23i/src/mem.c 2003-12-21 14:16:44.000000000 -0700 @@ -453,7 +453,7 @@ if ((cp = mc->chart) != NULL && GK.second_tick) { - gkrellm_store_chartdata(cp, 0, mc->page_out, mc->page_in); + gkrellm_store_chartdata(cp, 0, (gint64) mc->page_out, (gint64) mc->page_in); refresh_chart(mc); } } diff -Naur gkrellm-2.1.23/src/net.c gkrellm-2.1.23i/src/net.c --- gkrellm-2.1.23/src/net.c 2003-12-16 20:29:40.000000000 -0700 +++ gkrellm-2.1.23i/src/net.c 2003-12-21 14:16:44.000000000 -0700 @@ -1756,7 +1756,7 @@ net->tx_old = net->tx; if (GK.second_tick) { - gkrellm_store_chartdata(net->chart, 0, net->tx, net->rx); + gkrellm_store_chartdata(net->chart, 0, (gint64) net->tx, (gint64) net->rx); net->rx_current = gkrellm_get_current_chartdata(net->rx_cd); net->tx_current = gkrellm_get_current_chartdata(net->tx_cd); rxd = (gdouble) net->rx_current; diff -Naur gkrellm-2.1.23/src/proc.c gkrellm-2.1.23i/src/proc.c --- gkrellm-2.1.23/src/proc.c 2003-06-17 07:38:18.000000000 -0600 +++ gkrellm-2.1.23i/src/proc.c 2003-12-21 14:16:44.000000000 -0700 @@ -137,7 +137,7 @@ len = snprintf(buf, size, "%.1f", (gfloat) gkrellm_get_chart_scalemax(cp) / LOAD_SCALING); else if (c == 'F' && fork_scaling > 0) - len = snprintf(buf, size, "%d", + len = snprintf(buf, size, "%Ld", gkrellm_get_chart_scalemax(cp) / fork_scaling); else if (c == 'H') len = snprintf(buf, size, "%s", gkrellm_sys_get_host_name()); @@ -261,7 +261,7 @@ | Scale the forks number by fork_scaling. See setup_proc_scaling(). */ load = (int) (LOAD_SCALING * proc.fload); - gkrellm_store_chartdata(cp, 0, load, fork_scaling * proc.n_forks); + gkrellm_store_chartdata(cp, 0, (gint64) load, (gint64) fork_scaling * proc.n_forks); refresh_proc_chart(cp); gkrellm_check_alert(load_alert, proc.fload); gkrellm_check_alert(processes_alert, proc.n_processes); diff -Naur gkrellm-2.1.23/src/sysdeps/linux.c gkrellm-2.1.23i/src/sysdeps/linux.c --- gkrellm-2.1.23/src/sysdeps/linux.c 2003-10-11 17:21:47.000000000 -0600 +++ gkrellm-2.1.23i/src/sysdeps/linux.c 2003-12-21 14:16:44.000000000 -0700 @@ -764,14 +764,38 @@ #define PROC_NET_TCP6_FILE "/proc/net/tcp6" #endif +// To reduce server traffic, we maintain information about the most recent invocation of the iptables program and only log packets to inet.c if there is a change +// in the packet or byte count of the rule. The first hit on each rule serves to initialize the counts for the rule. Subsequent changes are passed on. + +typedef struct giptableshistory + { + gint local_port; + gint local_port_hi; + gint remote_port; + gint remote_port_hi; + gint chain; + gint line; + gint target; + guint64 pkts; + guint64 bytes; + struct giptableshistory *next; + } GIPTablesHistory; + + +GIPTablesHistory *iptables_start = NULL, *iptables_last = NULL; + + void gkrellm_sys_inet_read_tcp_data(void) { - FILE *f; - ActiveTCP tcp; - gchar buf[512]; - gint tcp_status; - gulong addr; + FILE *f; + ActiveTCP tcp; + gchar buf[512]; + gint tcp_status; + gulong addr; + static int disable_iptables; + + tcp.chain = CHAIN_CONNECT; if ((f = fopen(PROC_NET_TCP_FILE, "r")) != NULL) { @@ -810,6 +834,219 @@ fclose(f); } #endif /* INET6 */ + + // For iptables to run so you can get statistics, you must be running as root :( If gkrellm/gkrellmd is running with reduced privileges, then you get + // a zero length stdout stream instead of actual information. If you see this, then turn off iptables completely for minimum impact on the + // system. A su wrapper would be one solution :< or just let gkrellm/gkrellmd stay as root. + + // It would be nice to just do a zero stats after each read, but that would be intrusive, so the calling program must keep track of each rules + // packet and byte counts and find the difference. Since multiple rules can specify a particular port (SSHD for example), each must be tracked + // separately. The --line-numbers option is used as part of the key to provide the separation for multiple rules. + + if (!disable_iptables && (f = popen("/sbin/iptables -L -v -n -x --line-numbers", "r")) != NULL) + { + gchar *bufp, *tbufp; + gchar target[512]; + gint i; + GIPTablesHistory *iptables_at; + + iptables_at = iptables_start; + + while (fgets(buf, sizeof(buf), f)) + { + if (*buf == '\n') + continue; + + if (strncmp(buf, "Chain", 5) == 0) + { + if (strncmp(buf + 6, "INPUT ", 6) == 0) + tcp.chain = CHAIN_INPUT; + else if (strncmp(buf + 6, "FORWARD ", 8) == 0) + tcp.chain = CHAIN_FORWARD; + else if (strncmp(buf + 6, "OUTPUT ", 7) == 0) + tcp.chain = CHAIN_OUTPUT; + else + tcp.chain = CHAIN_USER; + continue; + } + + if (strncmp(buf, "num pkts", 13) == 0) + continue; + + bufp = buf; + sscanf(bufp, "%d %Lu %n", &tcp.line, &tcp.pkts, &i); + + // If the packet count is 0, then we can ignore all other information on the line. + + if (tcp.pkts) + { + bufp += i; + sscanf(bufp, "%Lu %n", &tcp.bytes, &i); + bufp += i; + sscanf(bufp, "%[^ ]%i", target, &i); + bufp += i; + + if (strcmp(target, "ACCEPT") == 0) + tcp.target = TARGET_ACCEPT; + else if (strcmp(target, "DROP") == 0) + tcp.target = TARGET_DROP; + else if (strcmp(target, "QUEUE") == 0) + tcp.target = TARGET_QUEUE; + else if (strcmp(target, "RETURN") == 0) + tcp.target = TARGET_RETURN; + else if (strcmp(target, "LOG") == 0) + tcp.target = TARGET_LOG; + else + tcp.target = TARGET_USER; + + tcp.local_port = tcp.remote_port = 0; // Default to full range in case no rule specifies anything else + tcp.local_port_hi = tcp.remote_port_hi = 65535; + + switch (tcp.chain) + { + case CHAIN_INPUT: // On input, source is remote port and destination is local + + case CHAIN_FORWARD: // Arbitrary direction selection + case CHAIN_USER: // Arbitrary direction selection + if ((tbufp = strstr(bufp, " spt:"))) + { + sscanf(tbufp + 5, "%d", &tcp.remote_port); + tcp.remote_port_hi = tcp.remote_port; + } + else if ((tbufp = strstr(bufp, " spts:"))) + sscanf(tbufp + 6, "%d:%d", &tcp.remote_port, &tcp.remote_port_hi); + + if ((tbufp = strstr(bufp, " dpt:"))) + { + sscanf(tbufp + 5, "%d", &tcp.local_port); + tcp.local_port_hi = tcp.local_port; + } + else if ((tbufp = strstr(bufp, " dpts:"))) + sscanf(tbufp + 6, "%d:%d", &tcp.local_port, &tcp.local_port_hi); + break; + + case CHAIN_OUTPUT: // Source/Destination sense reverses local/remote for output. + if ((tbufp = strstr(bufp, " spt:"))) + { + sscanf(tbufp + 5, "%d", &tcp.local_port); + tcp.local_port_hi = tcp.local_port; + } + else if ((tbufp = strstr(bufp, " spts:"))) + sscanf(tbufp + 6, "%d:%d", &tcp.local_port, &tcp.local_port_hi); + + if ((tbufp = strstr(bufp, " dpt:"))) + { + sscanf(tbufp + 5, "%d", &tcp.remote_port); + tcp.remote_port_hi = tcp.remote_port; + } + else if ((tbufp = strstr(bufp, " dpts:"))) + sscanf(tbufp + 6, "%d:%d", &tcp.remote_port, &tcp.remote_port_hi); + break; + } + + if (iptables_at && + iptables_at->local_port == tcp.local_port && iptables_at->local_port_hi == tcp.local_port_hi && + iptables_at->remote_port == tcp.remote_port && iptables_at->remote_port_hi == tcp.remote_port_hi && + iptables_at->chain == tcp.chain && + iptables_at->line == tcp.line && + iptables_at->target == tcp.target) + { + // Unless the firewall is altered, then the nodes should move along in sequence with each iteration. + // Keep the node pointer matched up as the report is read and don't do anything special unless the packet or byte + // count changes. + + if (iptables_at->pkts != tcp.pkts || + iptables_at->bytes != tcp.bytes) + { + iptables_at->pkts = tcp.pkts; + iptables_at->bytes = tcp.bytes; + gkrellm_inet_log_tcp_port_data(&tcp); + } + iptables_at = iptables_at->next; + continue; + } + + + // If the user has added rules to the rule set in some particular chain, a new entry will be added at the end of the list + // so first go back to square one to look for existing entries that match. + + iptables_at = iptables_start; + while (iptables_at) + { + if (iptables_at->local_port == tcp.local_port && iptables_at->local_port_hi == tcp.local_port_hi && + iptables_at->remote_port == tcp.remote_port && iptables_at->remote_port_hi == tcp.remote_port_hi && + iptables_at->chain == tcp.chain && + iptables_at->line == tcp.line && + iptables_at->target == tcp.target) + break; + iptables_at = iptables_at->next; + } + + // No matching node to track this rule's history was found. + + if (!iptables_at) + { + iptables_at = g_new0(GIPTablesHistory, 1); + if (iptables_at) + { + // If you can allocate another node, the current iptables information is synced into it and automatically sent on for + // logging the first packet and byte count information for the rule + + if (iptables_last) + { + iptables_last->next = iptables_at; + iptables_last = iptables_at; + } + else + { + iptables_start = iptables_at; + iptables_last = iptables_at; + } + iptables_at->local_port = tcp.local_port; + iptables_at->local_port_hi = tcp.local_port_hi; + iptables_at->remote_port = tcp.remote_port; + iptables_at->remote_port_hi = tcp.remote_port_hi; + iptables_at->chain = tcp.chain; + iptables_at->line = tcp.line; + iptables_at->target = tcp.target; + iptables_at->pkts = tcp.pkts; + iptables_at->bytes = tcp.bytes; + } + + // If you can't allocate another node, send the information on the the display process which may be on another system which has + // more free RAM to track the history. + + gkrellm_inet_log_tcp_port_data(&tcp); + } + + // A matching node was found + + else + { + // Unless the firewall is altered, then the nodes should move along in sequence with each iteration. + // Keep the node pointer matched up as the report is read and don't do anything special unless the packet or byte + // count changes. + + if (iptables_at->pkts != tcp.pkts || + iptables_at->bytes != tcp.bytes) + { + iptables_at->pkts = tcp.pkts; + iptables_at->bytes = tcp.bytes; + gkrellm_inet_log_tcp_port_data(&tcp); + } + iptables_at = iptables_at->next; + continue; + } + } + } + fclose(f); + + // No chains were found which means iptables couldn't be run - If it ran you would at least get the basic chain names even with no + // rules + + if (tcp.chain == CHAIN_CONNECT) + disable_iptables = TRUE; + } } gboolean @@ -2324,7 +2561,7 @@ { fixed_chip_name = g_strdup(chip_name); gkrellm_sensors_linux_name_fix(fixed_chip_name); - + path = g_build_filename(SENSORS_DIR, chip_name, NULL); chip_dir = g_dir_open(path, 0, NULL); if (!chip_dir)