From: Martin Mares Date: Mon, 17 Jun 2013 16:32:06 +0000 (+0200) Subject: Fixed mixup of HTTP connection/transaction numbering X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=751c91a9ab7f343d97dac735ef30034ba20ee061;p=netgrind.git Fixed mixup of HTTP connection/transaction numbering --- diff --git a/netgrind/http.c b/netgrind/http.c index e27f57d..7cd4026 100644 --- a/netgrind/http.c +++ b/netgrind/http.c @@ -44,9 +44,10 @@ struct http_state { } state; byte *error; u64 req_start_time, resp_start_time; - uns id; + uns conn_id; struct mempool *pool; list tx_queue, rx_queue; + uns xact_id; byte *req_line, *resp_line; list req_headers, resp_headers; byte line[MAXLINE]; @@ -62,14 +63,16 @@ struct http_state { char *http_log_dir; +static uns http_conn_counter; +static uns http_xact_counter; + static void http_open(struct flow *f, u64 when) { - static int http_counter; struct http_state *s = xmalloc_zero(sizeof(*s)); s->flow = f; f->appl_data = s; - s->id = http_counter++; - DBG("HTTP: %d NEW %d.%d.%d.%d:%d -> %d.%d.%d.%d:%d\n", s->id, + s->conn_id = http_conn_counter++; + DBG("HTTP: %d NEW %d.%d.%d.%d:%d -> %d.%d.%d.%d:%d\n", s->conn_id, IPQUAD(f->saddr), ntohs(f->sport), IPQUAD(f->daddr), ntohs(f->dport)); list_init(&s->tx_queue); list_init(&s->rx_queue); @@ -117,7 +120,7 @@ static void http_log_start(struct http_state *s) char name[256], stamp[TIMESTAMP_LEN]; struct flow *f = s->flow; - sprintf(name, "%s/%06u-%d.%d.%d.%d:%d-%d.%d.%d.%d:%d", http_log_dir, s->id, + sprintf(name, "%s/%06u-%d.%d.%d.%d:%d-%d.%d.%d.%d:%d", http_log_dir, s->xact_id, IPQUAD(f->saddr), ntohs(f->sport), IPQUAD(f->daddr), ntohs(f->dport)); if (!(s->log_file = fopen(name, "w"))) die("Unable to create %s: %m", name); @@ -245,11 +248,11 @@ static void http_report(struct flow *f, struct http_state *s, u64 when, byte *re byte *sep; if (sep = strchr(ctype, ';')) *sep = 0; - if (!s->id) + if (!s->xact_id) printf("# id timestamp source destination forwarded-for res cac que length total time wait time ctype method URL\n"); /* 000000 2003-06-06 22:53:38.642 81.27.194.19:1175 205.217.153.53:80 123.123.123.123 200 ... 0 14030 0.957 0.444 text/plain GET http://... */ printf("%06u %s %-21s %-21s %-15s %-3s %c%c%c %3d %8d %6d.%03d %6d.%03d %-12s %s %s\n", - s->id, stamp, src, dst, (ffor ? : "-"), reason, + s->xact_id, stamp, src, dst, (ffor ? : "-"), reason, rq_cflag, rp_cflag, rp_hit, s->req_counter, s->body_total_size, @@ -264,7 +267,7 @@ static void http_report(struct flow *f, struct http_state *s, u64 when, byte *re static void http_close(struct flow *f, int cause, u64 when) { struct http_state *s = f->appl_data; - DBG("HTTP: %d CLOSE in state %d (cause %d)\n", s->id, s->state, cause); + DBG("HTTP: %d CLOSE in state %d (cause %d)\n", s->conn_id, s->state, cause); if (cause != CAUSE_CLOSE) { if (s->state != HTTP_IDLE) @@ -380,6 +383,7 @@ static void http_init_xact(struct http_state *s) s->req_line = s->resp_line = NULL; s->line_len = 0; s->body_total_size = 0; + s->xact_id = http_xact_counter++; http_log_start(s); } @@ -478,7 +482,7 @@ static void http_input(struct flow *f, int dir, struct pkt *p) // DBG("dir=%d txf=%d rxf=%d len=%d\n", dir, fin_tx, fin_rx, pkt_len(p)); if (s->state == HTTP_ERROR || s->state == HTTP_CUT) { - DBG("HTTP: %d DROPPING INPUT\n", s->id); + DBG("HTTP: %d DROPPING INPUT\n", s->conn_id); pkt_free(p); return; } @@ -486,7 +490,7 @@ static void http_input(struct flow *f, int dir, struct pkt *p) list_add_tail((dir ? &s->tx_queue : &s->rx_queue), &p->n); for(;;) { - DBG("HTTP: %d STATE %d\n", s->id, s->state); + DBG("HTTP: %d STATE %d\n", s->conn_id, s->state); switch (s->state) { case HTTP_IDLE: @@ -611,12 +615,12 @@ static void http_input(struct flow *f, int dir, struct pkt *p) } err: - DBG("HTTP: %d ERROR: PROTOCOL VIOLATION\n", s->id); + DBG("HTTP: %d ERROR: PROTOCOL VIOLATION\n", s->conn_id); s->state = HTTP_ERROR; return; cut: - DBG("HTTP: %d ERROR: UNEXPECTED EOF\n", s->id); + DBG("HTTP: %d ERROR: UNEXPECTED EOF\n", s->conn_id); s->state = HTTP_CUT; }