From: Willy Tarreau Date: Wed, 27 Sep 2023 06:23:49 +0000 (+0200) Subject: MINOR: stream: make strm_dump_to_buffer() take an arbitrary buffer X-Git-Tag: v2.9-dev7~68 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3e630a98719f2a15046aa1e1c3fac72c4ebeb15f;p=thirdparty%2Fhaproxy.git MINOR: stream: make strm_dump_to_buffer() take an arbitrary buffer We won't always want to dump into the trash, so let's make the function accept an arbitrary buffer. --- diff --git a/src/stream.c b/src/stream.c index 18839b95c7..a13ebe4297 100644 --- a/src/stream.c +++ b/src/stream.c @@ -3238,12 +3238,12 @@ struct show_sess_ctx { int pos; /* last position of the current session's buffer */ }; -/* This function appends a complete dump of a stream state onto the trash - * buffer, possibly anonymizing using the specified anon_key. The caller is - * responsible for ensuring that enough room remains in the buffer to dump a - * complete stream at once. +/* This function appends a complete dump of a stream state onto the buffer, + * possibly anonymizing using the specified anon_key. The caller is responsible + * for ensuring that enough room remains in the buffer to dump a complete + * stream at once. */ -static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) +static void strm_dump_to_buffer(struct buffer *buf, const struct stream *strm, uint32_t anon_key) { struct stconn *scf, *scb; struct tm tm; @@ -3253,7 +3253,7 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) struct appctx *tmpctx; get_localtime(strm->logs.accept_date.tv_sec, &tm); - chunk_appendf(&trash, + chunk_appendf(buf, "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", strm, tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, @@ -3265,19 +3265,19 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) switch (conn && conn_get_src(conn) ? addr_to_str(conn->src, pn, sizeof(pn)) : AF_UNSPEC) { case AF_INET: case AF_INET6: - chunk_appendf(&trash, " source=%s:%d\n", + chunk_appendf(buf, " source=%s:%d\n", HA_ANON_STR(anon_key, pn), get_host_port(conn->src)); break; case AF_UNIX: - chunk_appendf(&trash, " source=unix:%d\n", strm_li(strm)->luid); + chunk_appendf(buf, " source=unix:%d\n", strm_li(strm)->luid); break; default: /* no more information to print right now */ - chunk_appendf(&trash, "\n"); + chunk_appendf(buf, "\n"); break; } - chunk_appendf(&trash, + chunk_appendf(buf, " flags=0x%x, conn_retries=%d, conn_exp=%s conn_et=0x%03x srv_conn=%p, pend_pos=%p waiting=%d epoch=%#x\n", strm->flags, strm->conn_retries, strm->conn_exp ? @@ -3287,7 +3287,7 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) strm->conn_err_type, strm->srv_conn, strm->pend_pos, LIST_INLIST(&strm->buffer_wait.list), strm->stream_epoch); - chunk_appendf(&trash, + chunk_appendf(buf, " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", HA_ANON_STR(anon_key, strm_fe(strm)->id), strm_fe(strm)->uuid, proxy_mode_str(strm_fe(strm)->mode), strm_li(strm) ? strm_li(strm)->name ? strm_li(strm)->name : "?" : "?", @@ -3296,66 +3296,66 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) switch (conn && conn_get_dst(conn) ? addr_to_str(conn->dst, pn, sizeof(pn)) : AF_UNSPEC) { case AF_INET: case AF_INET6: - chunk_appendf(&trash, " addr=%s:%d\n", + chunk_appendf(buf, " addr=%s:%d\n", HA_ANON_STR(anon_key, pn), get_host_port(conn->dst)); break; case AF_UNIX: - chunk_appendf(&trash, " addr=unix:%d\n", strm_li(strm)->luid); + chunk_appendf(buf, " addr=unix:%d\n", strm_li(strm)->luid); break; default: /* no more information to print right now */ - chunk_appendf(&trash, "\n"); + chunk_appendf(buf, "\n"); break; } if (strm->be->cap & PR_CAP_BE) - chunk_appendf(&trash, + chunk_appendf(buf, " backend=%s (id=%u mode=%s)", HA_ANON_STR(anon_key, strm->be->id), strm->be->uuid, proxy_mode_str(strm->be->mode)); else - chunk_appendf(&trash, " backend= (id=-1 mode=-)"); + chunk_appendf(buf, " backend= (id=-1 mode=-)"); conn = sc_conn(strm->scb); switch (conn && conn_get_src(conn) ? addr_to_str(conn->src, pn, sizeof(pn)) : AF_UNSPEC) { case AF_INET: case AF_INET6: - chunk_appendf(&trash, " addr=%s:%d\n", + chunk_appendf(buf, " addr=%s:%d\n", HA_ANON_STR(anon_key, pn), get_host_port(conn->src)); break; case AF_UNIX: - chunk_appendf(&trash, " addr=unix\n"); + chunk_appendf(buf, " addr=unix\n"); break; default: /* no more information to print right now */ - chunk_appendf(&trash, "\n"); + chunk_appendf(buf, "\n"); break; } if (strm->be->cap & PR_CAP_BE) - chunk_appendf(&trash, + chunk_appendf(buf, " server=%s (id=%u)", objt_server(strm->target) ? HA_ANON_STR(anon_key, __objt_server(strm->target)->id) : "", objt_server(strm->target) ? __objt_server(strm->target)->puid : 0); else - chunk_appendf(&trash, " server= (id=-1)"); + chunk_appendf(buf, " server= (id=-1)"); switch (conn && conn_get_dst(conn) ? addr_to_str(conn->dst, pn, sizeof(pn)) : AF_UNSPEC) { case AF_INET: case AF_INET6: - chunk_appendf(&trash, " addr=%s:%d\n", + chunk_appendf(buf, " addr=%s:%d\n", HA_ANON_STR(anon_key, pn), get_host_port(conn->dst)); break; case AF_UNIX: - chunk_appendf(&trash, " addr=unix\n"); + chunk_appendf(buf, " addr=unix\n"); break; default: /* no more information to print right now */ - chunk_appendf(&trash, "\n"); + chunk_appendf(buf, "\n"); break; } - chunk_appendf(&trash, + chunk_appendf(buf, " task=%p (state=0x%02x nice=%d calls=%u rate=%u exp=%s tid=%d(%d/%d)%s", strm->task, strm->task->state, @@ -3369,35 +3369,35 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) ha_thread_info[strm->task->tid].ltid, task_in_rq(strm->task) ? ", running" : ""); - chunk_appendf(&trash, + chunk_appendf(buf, " age=%s)\n", human_time(ns_to_sec(now_ns) - ns_to_sec(strm->logs.accept_ts), 1)); if (strm->txn) - chunk_appendf(&trash, + chunk_appendf(buf, " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s req.f=0x%02x rsp.f=0x%02x\n", strm->txn, strm->txn->flags, strm->txn->meth, strm->txn->status, h1_msg_state_str(strm->txn->req.msg_state), h1_msg_state_str(strm->txn->rsp.msg_state), strm->txn->req.flags, strm->txn->rsp.flags); scf = strm->scf; - chunk_appendf(&trash, " scf=%p flags=0x%08x state=%s endp=%s,%p,0x%08x sub=%d", + chunk_appendf(buf, " scf=%p flags=0x%08x state=%s endp=%s,%p,0x%08x sub=%d", scf, scf->flags, sc_state_str(scf->state), (sc_ep_test(scf, SE_FL_T_MUX) ? "CONN" : (sc_ep_test(scf, SE_FL_T_APPLET) ? "APPCTX" : "NONE")), scf->sedesc->se, sc_ep_get(scf), scf->wait_event.events); - chunk_appendf(&trash, " rex=%s", + chunk_appendf(buf, " rex=%s", sc_ep_rcv_ex(scf) ? human_time(TICKS_TO_MS(sc_ep_rcv_ex(scf) - now_ms), TICKS_TO_MS(1000)) : ""); - chunk_appendf(&trash, " wex=%s\n", + chunk_appendf(buf, " wex=%s\n", sc_ep_snd_ex(scf) ? human_time(TICKS_TO_MS(sc_ep_snd_ex(scf) - now_ms), TICKS_TO_MS(1000)) : ""); if ((conn = sc_conn(scf)) != NULL) { if (conn->mux && conn->mux->show_sd) { - chunk_appendf(&trash, " "); - conn->mux->show_sd(&trash, scf->sedesc, " "); - chunk_appendf(&trash, "\n"); + chunk_appendf(buf, " "); + conn->mux->show_sd(buf, scf->sedesc, " "); + chunk_appendf(buf, "\n"); } - chunk_appendf(&trash, + chunk_appendf(buf, " co0=%p ctrl=%s xprt=%s mux=%s data=%s target=%s:%p\n", conn, conn_get_ctrl_name(conn), @@ -3407,7 +3407,7 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) obj_type_name(conn->target), obj_base_ptr(conn->target)); - chunk_appendf(&trash, + chunk_appendf(buf, " flags=0x%08x fd=%d fd.state=%02x updt=%d fd.tmask=0x%lx\n", conn->flags, conn_fd(conn), @@ -3416,7 +3416,7 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) conn_fd(conn) >= 0 ? fdtab[conn->handle.fd].thread_mask: 0); } else if ((tmpctx = sc_appctx(scf)) != NULL) { - chunk_appendf(&trash, + chunk_appendf(buf, " app0=%p st0=%d st1=%d applet=%s tid=%d nice=%d calls=%u rate=%u\n", tmpctx, tmpctx->st0, @@ -3427,23 +3427,23 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) } scb = strm->scb; - chunk_appendf(&trash, " scb=%p flags=0x%08x state=%s endp=%s,%p,0x%08x sub=%d", + chunk_appendf(buf, " scb=%p flags=0x%08x state=%s endp=%s,%p,0x%08x sub=%d", scb, scb->flags, sc_state_str(scb->state), (sc_ep_test(scb, SE_FL_T_MUX) ? "CONN" : (sc_ep_test(scb, SE_FL_T_APPLET) ? "APPCTX" : "NONE")), scb->sedesc->se, sc_ep_get(scb), scb->wait_event.events); - chunk_appendf(&trash, " rex=%s", + chunk_appendf(buf, " rex=%s", sc_ep_rcv_ex(scb) ? human_time(TICKS_TO_MS(sc_ep_rcv_ex(scb) - now_ms), TICKS_TO_MS(1000)) : ""); - chunk_appendf(&trash, " wex=%s\n", + chunk_appendf(buf, " wex=%s\n", sc_ep_snd_ex(scb) ? human_time(TICKS_TO_MS(sc_ep_snd_ex(scb) - now_ms), TICKS_TO_MS(1000)) : ""); if ((conn = sc_conn(scb)) != NULL) { if (conn->mux && conn->mux->show_sd) { - chunk_appendf(&trash, " "); - conn->mux->show_sd(&trash, scb->sedesc, " "); - chunk_appendf(&trash, "\n"); + chunk_appendf(buf, " "); + conn->mux->show_sd(buf, scb->sedesc, " "); + chunk_appendf(buf, "\n"); } - chunk_appendf(&trash, + chunk_appendf(buf, " co1=%p ctrl=%s xprt=%s mux=%s data=%s target=%s:%p\n", conn, conn_get_ctrl_name(conn), @@ -3453,7 +3453,7 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) obj_type_name(conn->target), obj_base_ptr(conn->target)); - chunk_appendf(&trash, + chunk_appendf(buf, " flags=0x%08x fd=%d fd.state=%02x updt=%d fd.tmask=0x%lx\n", conn->flags, conn_fd(conn), @@ -3462,7 +3462,7 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) conn_fd(conn) >= 0 ? fdtab[conn->handle.fd].thread_mask: 0); } else if ((tmpctx = sc_appctx(scb)) != NULL) { - chunk_appendf(&trash, + chunk_appendf(buf, " app1=%p st0=%d st1=%d applet=%s tid=%d nice=%d calls=%u rate=%u\n", tmpctx, tmpctx->st0, @@ -3472,7 +3472,7 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) tmpctx->t->nice, tmpctx->t->calls, read_freq_ctr(&tmpctx->call_rate)); } - chunk_appendf(&trash, + chunk_appendf(buf, " req=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n" " an_exp=%s buf=%p data=%p o=%u p=%u i=%u size=%u\n", &strm->req, @@ -3490,7 +3490,7 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) if (IS_HTX_STRM(strm)) { struct htx *htx = htxbuf(&strm->req.buf); - chunk_appendf(&trash, + chunk_appendf(buf, " htx=%p flags=0x%x size=%u data=%u used=%u wrap=%s extra=%llu\n", htx, htx->flags, htx->size, htx->data, htx_nbblks(htx), (htx->tail >= htx->head) ? "NO" : "YES", @@ -3499,11 +3499,11 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) if (HAS_FILTERS(strm) && strm->strm_flt.current[0]) { const struct filter *flt = strm->strm_flt.current[0]; - chunk_appendf(&trash, " current_filter=%p (id=\"%s\" flags=0x%x pre=0x%x post=0x%x) \n", + chunk_appendf(buf, " current_filter=%p (id=\"%s\" flags=0x%x pre=0x%x post=0x%x) \n", flt, flt->config->id, flt->flags, flt->pre_analyzers, flt->post_analyzers); } - chunk_appendf(&trash, + chunk_appendf(buf, " res=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n" " an_exp=%s buf=%p data=%p o=%u p=%u i=%u size=%u\n", &strm->res, @@ -3521,7 +3521,7 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) if (IS_HTX_STRM(strm)) { struct htx *htx = htxbuf(&strm->res.buf); - chunk_appendf(&trash, + chunk_appendf(buf, " htx=%p flags=0x%x size=%u data=%u used=%u wrap=%s extra=%llu\n", htx, htx->flags, htx->size, htx->data, htx_nbblks(htx), (htx->tail >= htx->head) ? "NO" : "YES", @@ -3530,13 +3530,13 @@ static void strm_dump_to_buffer(const struct stream *strm, uint32_t anon_key) if (HAS_FILTERS(strm) && strm->strm_flt.current[1]) { const struct filter *flt = strm->strm_flt.current[1]; - chunk_appendf(&trash, " current_filter=%p (id=\"%s\" flags=0x%x pre=0x%x post=0x%x) \n", + chunk_appendf(buf, " current_filter=%p (id=\"%s\" flags=0x%x pre=0x%x post=0x%x) \n", flt, flt->config->id, flt->flags, flt->pre_analyzers, flt->post_analyzers); } if (strm->current_rule_list && strm->current_rule) { const struct act_rule *rule = strm->current_rule; - chunk_appendf(&trash, " current_rule=\"%s\" [%s:%d]\n", rule->kw->kw, rule->conf.file, rule->conf.line); + chunk_appendf(buf, " current_rule=\"%s\" [%s:%d]\n", rule->kw->kw, rule->conf.file, rule->conf.line); } } @@ -3567,8 +3567,7 @@ static int stats_dump_full_strm_to_buffer(struct stconn *sc, struct stream *strm __fallthrough; case 1: - /* the function appends to the trash */ - strm_dump_to_buffer(strm, appctx->cli_anon_key); + strm_dump_to_buffer(&trash, strm, appctx->cli_anon_key); if (applet_putchk(appctx, &trash) == -1) goto full;