mirror of
https://github.com/haproxy/haproxy.git
synced 2026-02-19 02:29:31 -05:00
MINOR: tree-wide: Use the buffer size instead of global setting when possible
At many places, we rely on global.tune.bufsize value instead of using the buffer size. For now, it is not a problem. But if we want to be able to deal with buffers of different sizes, it is good to reduce as far as possible dependencies on the global value. most of time, we can use b_size() or c_size() functions. The main change is performed on the error snapshot where the buffer size was added into the error_snapshot structure.
This commit is contained in:
parent
fc89ff76c7
commit
6bf450b7fe
10 changed files with 30 additions and 20 deletions
|
|
@ -787,8 +787,12 @@ static inline int channel_recv_max(const struct channel *chn)
|
|||
*/
|
||||
static inline size_t channel_data_limit(const struct channel *chn)
|
||||
{
|
||||
size_t max = (global.tune.bufsize - global.tune.maxrewrite);
|
||||
|
||||
size_t max;
|
||||
|
||||
if (!c_size(chn))
|
||||
return 0;
|
||||
max = (c_size(chn) - global.tune.maxrewrite);
|
||||
if (IS_HTX_STRM(chn_strm(chn)))
|
||||
max -= HTX_BUF_OVERHEAD;
|
||||
return max;
|
||||
|
|
|
|||
|
|
@ -293,7 +293,8 @@ struct error_snapshot {
|
|||
struct server *srv; /* server associated with the error (or NULL) */
|
||||
/* @64 */
|
||||
unsigned int ev_id; /* event number (counter incremented for each capture) */
|
||||
/* @68: 4 bytes hole here */
|
||||
unsigned int buf_size; /* buffer size */
|
||||
|
||||
struct sockaddr_storage src; /* client's address */
|
||||
|
||||
/**** protocol-specific part ****/
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ static inline void sc_have_room(struct stconn *sc)
|
|||
static inline void sc_need_room(struct stconn *sc, ssize_t room_needed)
|
||||
{
|
||||
sc->flags |= SC_FL_NEED_ROOM;
|
||||
BUG_ON_HOT(room_needed > (ssize_t)global.tune.bufsize);
|
||||
BUG_ON_HOT(room_needed > (ssize_t)c_size(sc_ic(sc)));
|
||||
sc->room_needed = room_needed;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3952,7 +3952,7 @@ __LJMP static int hlua_channel_get_data_yield(lua_State *L, int status, lua_KCon
|
|||
if (!len)
|
||||
goto dup;
|
||||
if (len == -1)
|
||||
len = global.tune.bufsize;
|
||||
len = c_size(chn);
|
||||
if (len < 0) {
|
||||
lua_pushfstring(L, "length out of range.");
|
||||
WILL_LJMP(lua_error(L));
|
||||
|
|
@ -4035,7 +4035,7 @@ __LJMP static int hlua_channel_get_line_yield(lua_State *L, int status, lua_KCon
|
|||
if (!len)
|
||||
goto dup;
|
||||
if (len == -1)
|
||||
len = global.tune.bufsize;
|
||||
len = c_size(chn);
|
||||
if (len < 0) {
|
||||
lua_pushfstring(L, "length out of range.");
|
||||
WILL_LJMP(lua_error(L));
|
||||
|
|
@ -7470,7 +7470,7 @@ __LJMP static int hlua_http_msg_get_body(lua_State *L)
|
|||
if (!len)
|
||||
goto dup;
|
||||
if (len == -1)
|
||||
len = global.tune.bufsize;
|
||||
len = c_size(msg->chn);
|
||||
if (len < 0) {
|
||||
lua_pushfstring(L, "length out of range.");
|
||||
WILL_LJMP(lua_error(L));
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ static int get_http_auth(struct sample *smp, struct htx *htx)
|
|||
|
||||
len = base64dec(txn->auth.method_data.area,
|
||||
txn->auth.method_data.data,
|
||||
http_auth->area, global.tune.bufsize - 1);
|
||||
http_auth->area, http_auth->size -1);
|
||||
|
||||
if (len < 0)
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -4008,8 +4008,8 @@ static int h1_recv(struct h1c *h1c)
|
|||
* a pointer swap and the next read will be doable at once in
|
||||
* an empty buffer.
|
||||
*/
|
||||
if (max > global.tune.bufsize - global.tune.maxrewrite)
|
||||
max = global.tune.bufsize - global.tune.maxrewrite;
|
||||
if (max > b_size(&h1c->ibuf) - global.tune.maxrewrite)
|
||||
max = b_size(&h1c->ibuf) - global.tune.maxrewrite;
|
||||
}
|
||||
|
||||
if (max) {
|
||||
|
|
|
|||
|
|
@ -4256,7 +4256,7 @@ static void h2_process_demux(struct h2c *h2c)
|
|||
goto done;
|
||||
}
|
||||
|
||||
if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) {
|
||||
if ((int)hdr.len < 0 || (int)hdr.len > b_size(&h2c->dbuf)) {
|
||||
/* RFC7540#3.5: a GOAWAY frame MAY be omitted */
|
||||
h2c_report_glitch(h2c, 1, "invalid settings frame length");
|
||||
TRACE_ERROR("invalid settings frame length", H2_EV_RX_FRAME|H2_EV_RX_FHDR|H2_EV_RX_SETTINGS|H2_EV_PROTO_ERR, h2c->conn);
|
||||
|
|
@ -4303,7 +4303,7 @@ static void h2_process_demux(struct h2c *h2c)
|
|||
break;
|
||||
}
|
||||
|
||||
if ((int)hdr.len < 0 || (int)hdr.len > global.tune.bufsize) {
|
||||
if ((int)hdr.len < 0 || (int)hdr.len > b_size(&h2c->dbuf)) {
|
||||
h2c_report_glitch(h2c, 1, "invalid H2 frame length");
|
||||
TRACE_ERROR("invalid H2 frame length", H2_EV_RX_FRAME|H2_EV_RX_FHDR|H2_EV_PROTO_ERR, h2c->conn);
|
||||
h2c_error(h2c, H2_ERR_FRAME_SIZE_ERROR);
|
||||
|
|
@ -4384,7 +4384,7 @@ static void h2_process_demux(struct h2c *h2c)
|
|||
h2c->st0 = H2_CS_FRAME_P;
|
||||
|
||||
/* check for minimum basic frame format validity */
|
||||
ret = h2_frame_check(h2c->dft, 1, h2c->dsi, h2c->dfl, global.tune.bufsize);
|
||||
ret = h2_frame_check(h2c->dft, 1, h2c->dsi, h2c->dfl, b_size(&h2c->dbuf));
|
||||
if (ret != H2_ERR_NO_ERROR) {
|
||||
h2c_report_glitch(h2c, 1, "received invalid H2 frame header");
|
||||
TRACE_ERROR("received invalid H2 frame header", H2_EV_RX_FRAME|H2_EV_RX_FHDR|H2_EV_PROTO_ERR, h2c->conn);
|
||||
|
|
@ -6066,7 +6066,7 @@ next_frame:
|
|||
goto fail;
|
||||
}
|
||||
|
||||
if ((unsigned)hdr.len > (unsigned)global.tune.bufsize) {
|
||||
if ((unsigned)hdr.len > (unsigned)b_size(&h2c->dbuf)) {
|
||||
/* RFC7540#4.2: invalid frame length */
|
||||
h2c_report_glitch(h2c, 1, "too large CONTINUATION frame");
|
||||
TRACE_STATE("too large CONTINUATION frame", H2_EV_RX_FRAME|H2_EV_RX_FHDR|H2_EV_RX_HDR|H2_EV_RX_CONT|H2_EV_H2C_ERR|H2_EV_PROTO_ERR, h2c->conn);
|
||||
|
|
|
|||
|
|
@ -1205,7 +1205,6 @@ smp_fetch_payload_lv(const struct arg *arg_p, struct sample *smp, const char *kw
|
|||
unsigned int len_size = arg_p[1].data.sint;
|
||||
unsigned int buf_offset;
|
||||
unsigned int buf_size = 0;
|
||||
struct channel *chn = NULL;
|
||||
char *head = NULL;
|
||||
size_t max, data;
|
||||
int i;
|
||||
|
|
@ -1215,12 +1214,15 @@ smp_fetch_payload_lv(const struct arg *arg_p, struct sample *smp, const char *kw
|
|||
/* buf offset could be absolute or relative to len offset + len size if prefixed by + or - */
|
||||
|
||||
if (smp->strm) {
|
||||
struct channel *chn = NULL;
|
||||
|
||||
/* meaningless for HTX buffers */
|
||||
if (IS_HTX_STRM(smp->strm))
|
||||
return 0;
|
||||
chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
|
||||
head = ci_head(chn);
|
||||
data = ci_data(chn);
|
||||
max = c_size(chn);
|
||||
}
|
||||
else if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) {
|
||||
struct check *check = __objt_check(smp->sess->origin);
|
||||
|
|
@ -1230,8 +1232,9 @@ smp_fetch_payload_lv(const struct arg *arg_p, struct sample *smp, const char *kw
|
|||
return 0;
|
||||
head = b_head(&check->bi);
|
||||
data = b_data(&check->bi);
|
||||
max = b_size(&check->bi);
|
||||
}
|
||||
max = global.tune.bufsize;
|
||||
|
||||
if (!head)
|
||||
goto too_short;
|
||||
|
||||
|
|
@ -1290,6 +1293,7 @@ smp_fetch_payload(const struct arg *arg_p, struct sample *smp, const char *kw, v
|
|||
chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
|
||||
head = ci_head(chn);
|
||||
data = ci_data(chn);
|
||||
max = c_size(chn);
|
||||
}
|
||||
else if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) {
|
||||
struct check *check = __objt_check(smp->sess->origin);
|
||||
|
|
@ -1299,8 +1303,8 @@ smp_fetch_payload(const struct arg *arg_p, struct sample *smp, const char *kw, v
|
|||
return 0;
|
||||
head = b_head(&check->bi);
|
||||
data = b_data(&check->bi);
|
||||
max = b_size(&check->bi);
|
||||
}
|
||||
max = global.tune.bufsize;
|
||||
if (!head)
|
||||
goto too_short;
|
||||
|
||||
|
|
|
|||
|
|
@ -4173,6 +4173,7 @@ void proxy_capture_error(struct proxy *proxy, int is_back,
|
|||
if (!es)
|
||||
return;
|
||||
|
||||
es->buf_size = buf->size;
|
||||
es->buf_len = buf_len;
|
||||
es->ev_id = ev_id;
|
||||
|
||||
|
|
@ -5224,7 +5225,7 @@ static int cli_io_handler_show_errors(struct appctx *appctx)
|
|||
es->srv ? es->srv->puid : -1,
|
||||
es->ev_id, pn, port,
|
||||
es->buf_ofs, es->buf_out,
|
||||
global.tune.bufsize - es->buf_out - es->buf_len,
|
||||
es->buf_size - es->buf_out - es->buf_len,
|
||||
es->buf_len, es->buf_wrap, es->buf_err);
|
||||
|
||||
if (es->show)
|
||||
|
|
@ -5250,12 +5251,12 @@ static int cli_io_handler_show_errors(struct appctx *appctx)
|
|||
}
|
||||
|
||||
/* OK, ptr >= 0, so we have to dump the current line */
|
||||
while (ctx->ptr < es->buf_len && ctx->ptr < global.tune.bufsize) {
|
||||
while (ctx->ptr < es->buf_len && ctx->ptr < es->buf_size) {
|
||||
int newptr;
|
||||
int newline;
|
||||
|
||||
newline = ctx->bol;
|
||||
newptr = dump_text_line(&trash, es->buf, global.tune.bufsize, es->buf_len, &newline, ctx->ptr);
|
||||
newptr = dump_text_line(&trash, es->buf, es->buf_size, es->buf_len, &newline, ctx->ptr);
|
||||
if (newptr == ctx->ptr) {
|
||||
applet_fl_set(appctx, APPCTX_FL_OUTBLK_FULL);
|
||||
goto cant_send_unlock;
|
||||
|
|
|
|||
|
|
@ -5918,7 +5918,7 @@ static int ssl_sock_init(struct connection *conn, void **xprt_ctx)
|
|||
* a buffer.
|
||||
*/
|
||||
(!b_is_null(&ctx->early_buf)) ?
|
||||
global.tune.bufsize - global.tune.maxrewrite : 0);
|
||||
ctx->early_buf.size - global.tune.maxrewrite : 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue