From: Willy Tarreau Date: Fri, 15 Jun 2018 15:21:00 +0000 (+0200) Subject: MINOR: buffer: use b_orig() to replace most references to b->data X-Git-Tag: v1.9-dev1~112 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=591d4450497cc364711ada03ce1b240a99e71a49;p=thirdparty%2Fhaproxy.git MINOR: buffer: use b_orig() to replace most references to b->data This patch updates most users of b->data to use b_orig(). --- diff --git a/include/common/buf.h b/include/common/buf.h index b7a5df3177..4632a33467 100644 --- a/include/common/buf.h +++ b/include/common/buf.h @@ -364,7 +364,7 @@ static inline size_t b_getblk_nc(const struct buffer *buf, const char **blk1, si if (l1 < max) { *len1 = l1; *len2 = max - l1; - *blk2 = buf->data; + *blk2 = b_orig(buf); return 2; } *len1 = max; diff --git a/include/common/buffer.h b/include/common/buffer.h index 6f3ab26a19..e43969c54c 100644 --- a/include/common/buffer.h +++ b/include/common/buffer.h @@ -64,7 +64,7 @@ void buffer_dump(FILE *o, struct buffer *b, int from, int to); /* Normalizes a pointer after an addition */ static inline char *buffer_wrap_add(const struct buffer *buf, char *ptr) { - if (ptr - buf->size >= buf->data) + if (ptr - buf->size >= b_orig(buf)) ptr -= buf->size; return ptr; } @@ -77,9 +77,9 @@ static inline char *buffer_wrap_add(const struct buffer *buf, char *ptr) */ static inline const char *buffer_pointer(const struct buffer *buf, const char *ptr) { - if (ptr < buf->data) + if (ptr < b_orig(buf)) ptr += buf->size; - else if (ptr - buf->size >= buf->data) + else if (ptr - buf->size >= b_orig(buf)) ptr -= buf->size; return ptr; } @@ -405,7 +405,7 @@ static inline int b_isteq(const struct buffer *b, unsigned int o, size_t n, cons if (*p++ != *r.ptr++) return -1; if (unlikely(p == end)) - p = b->data; + p = b_orig(b); } return ist.len; } @@ -447,7 +447,7 @@ static inline int bi_istput(struct buffer *b, const struct ist ist) while (r.len--) { *p++ = *r.ptr++; if (unlikely(p == end)) - p = b->data; + p = b_orig(b); } return ist.len; } @@ -477,7 +477,7 @@ static inline int bo_istput(struct buffer *b, const struct ist ist) while (r.len--) { *p++ = *r.ptr++; if (unlikely(p == end)) - p = b->data; + p = b_orig(b); } return ist.len; } diff --git a/include/proto/h1.h b/include/proto/h1.h index 943ac0fe5e..eef310f8f6 100644 --- a/include/proto/h1.h +++ b/include/proto/h1.h @@ -163,7 +163,7 @@ static inline int h1_skip_chunk_crlf(const struct buffer *buf, int start, int st bytes++; ptr++; if (ptr >= b_wrap(buf)) - ptr = buf->data; + ptr = b_orig(buf); } if (bytes > stop - start) @@ -210,7 +210,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s if (c < 0) /* not a hex digit anymore */ break; if (unlikely(++ptr >= end)) - ptr = buf->data; + ptr = b_orig(buf); if (unlikely(chunk & 0xF8000000)) /* integer overflow will occur if result >= 2GB */ goto error; chunk = (chunk << 4) + c; @@ -223,7 +223,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s while (HTTP_IS_SPHT(*ptr)) { if (++ptr >= end) - ptr = buf->data; + ptr = b_orig(buf); if (--stop == 0) return 0; } @@ -236,7 +236,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s /* we now have a CR or an LF at ptr */ if (likely(*ptr == '\r')) { if (++ptr >= end) - ptr = buf->data; + ptr = b_orig(buf); if (--stop == 0) return 0; } @@ -244,7 +244,7 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s if (*ptr != '\n') goto error; if (++ptr >= end) - ptr = buf->data; + ptr = b_orig(buf); --stop; /* done */ break; @@ -252,13 +252,13 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s else if (likely(*ptr == ';')) { /* chunk extension, ends at next CRLF */ if (++ptr >= end) - ptr = buf->data; + ptr = b_orig(buf); if (--stop == 0) return 0; while (!HTTP_IS_CRLF(*ptr)) { if (++ptr >= end) - ptr = buf->data; + ptr = b_orig(buf); if (--stop == 0) return 0; } diff --git a/src/buffer.c b/src/buffer.c index 16372bf07c..fe756f781b 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -86,7 +86,7 @@ int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int delta = len - (end - pos); - if (b_tail(b) + delta > b->data + b->size) + if (b_tail(b) + delta > b_wrap(b)) return 0; /* no space left */ if (b_data(b) && @@ -123,7 +123,7 @@ int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len) delta = len + 2; - if (b_tail(b) + delta >= b->data + b->size) + if (b_tail(b) + delta >= b_wrap(b)) return 0; /* no space left */ if (b_data(b) && diff --git a/src/channel.c b/src/channel.c index 1efab9c95c..024f274440 100644 --- a/src/channel.c +++ b/src/channel.c @@ -169,7 +169,7 @@ int ci_putblk(struct channel *chn, const char *blk, int len) max = b_contig_space(chn->buf); memcpy(ci_tail(chn), blk, MIN(len, max)); if (len > max) - memcpy(chn->buf->data, blk + max, len - max); + memcpy(b_orig(chn->buf), blk + max, len - max); chn->buf->i += len; chn->total += len; @@ -386,10 +386,10 @@ int ci_getblk_nc(const struct channel *chn, return 0; } - if (unlikely(chn->buf->p + chn->buf->i > chn->buf->data + chn->buf->size)) { + if (unlikely(chn->buf->p + chn->buf->i > b_wrap(chn->buf))) { *blk1 = chn->buf->p; - *len1 = chn->buf->data + chn->buf->size - chn->buf->p; - *blk2 = chn->buf->data; + *len1 = b_wrap(chn->buf) - chn->buf->p; + *blk2 = b_orig(chn->buf); *len2 = chn->buf->i - *len1; return 2; } diff --git a/src/mux_h2.c b/src/mux_h2.c index 207589b55b..81772dbbca 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -516,22 +516,22 @@ static inline __maybe_unused void h2_set_frame_size(void *frame, uint32_t len) static inline __maybe_unused void h2_get_buf_bytes(void *dst, size_t bytes, const struct buffer *b, int o) { - readv_bytes(dst, bytes, b_peek(b, o), b_wrap(b) - b_peek(b, o), b->data); + readv_bytes(dst, bytes, b_peek(b, o), b_wrap(b) - b_peek(b, o), b_orig(b)); } static inline __maybe_unused uint16_t h2_get_n16(const struct buffer *b, int o) { - return readv_n16(b_peek(b, o), b_wrap(b) - b_peek(b, o), b->data); + return readv_n16(b_peek(b, o), b_wrap(b) - b_peek(b, o), b_orig(b)); } static inline __maybe_unused uint32_t h2_get_n32(const struct buffer *b, int o) { - return readv_n32(b_peek(b, o), b_wrap(b) - b_peek(b, o), b->data); + return readv_n32(b_peek(b, o), b_wrap(b) - b_peek(b, o), b_orig(b)); } static inline __maybe_unused uint64_t h2_get_n64(const struct buffer *b, int o) { - return readv_n64(b_peek(b, o), b_wrap(b) - b_peek(b, o), b->data); + return readv_n64(b_peek(b, o), b_wrap(b) - b_peek(b, o), b_orig(b)); } diff --git a/src/raw_sock.c b/src/raw_sock.c index 3ae76562ed..e0bfd1d995 100644 --- a/src/raw_sock.c +++ b/src/raw_sock.c @@ -284,14 +284,10 @@ static size_t raw_sock_to_buf(struct connection *conn, struct buffer *buf, size_ * EINTR too. */ while (count > 0) { - /* first check if we have some room after p+i */ - try = buf->data + buf->size - (buf->p + buf->i); - /* otherwise continue between data and p-o */ - if (try <= 0) { - try = buf->p - (buf->data + buf->o); - if (try <= 0) - break; - } + try = b_contig_space(buf); + if (!try) + break; + if (try > count) try = count; diff --git a/src/ssl_sock.c b/src/ssl_sock.c index 9aa101b2ba..b473027172 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -5361,16 +5361,13 @@ static size_t ssl_sock_to_buf(struct connection *conn, struct buffer *buf, size_ while (count > 0) { int need_out = 0; - /* first check if we have some room after p+i */ - try = buf->data + buf->size - (buf->p + buf->i); - /* otherwise continue between data and p-o */ - if (try <= 0) { - try = buf->p - (buf->data + buf->o); - if (try <= 0) - break; - } + try = b_contig_space(buf); + if (!try) + break; + if (try > count) try = count; + if (((conn->flags & (CO_FL_EARLY_SSL_HS | CO_FL_EARLY_DATA)) == CO_FL_EARLY_SSL_HS) && conn->tmp_early_data != -1) { *b_tail(buf) = conn->tmp_early_data; diff --git a/src/stream.c b/src/stream.c index d6e2864632..204d1f2c0e 100644 --- a/src/stream.c +++ b/src/stream.c @@ -2979,9 +2979,9 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st human_time(TICKS_TO_MS(strm->req.wex - now_ms), TICKS_TO_MS(1000)) : "", strm->req.buf, - strm->req.buf->data, (unsigned int)strm->req.buf->o, - (int)(strm->req.buf->p - strm->req.buf->data), - strm->txn ? strm->txn->req.next : 0, (unsigned int)strm->req.buf->i, + b_orig(strm->req.buf), (unsigned int)co_data(&strm->req), + (int)(strm->req.buf->p - b_orig(strm->req.buf)), + strm->txn ? strm->txn->req.next : 0, (unsigned int)ci_data(&strm->req), (unsigned int)strm->req.buf->size); chunk_appendf(&trash, @@ -3008,9 +3008,9 @@ static int stats_dump_full_strm_to_buffer(struct stream_interface *si, struct st human_time(TICKS_TO_MS(strm->res.wex - now_ms), TICKS_TO_MS(1000)) : "", strm->res.buf, - strm->res.buf->data, (unsigned int)strm->res.buf->o, - (int)(strm->res.buf->p - strm->res.buf->data), - strm->txn ? strm->txn->rsp.next : 0, (unsigned int)strm->res.buf->i, + b_orig(strm->res.buf), (unsigned int)co_data(&strm->res), + (int)(strm->res.buf->p - b_orig(strm->res.buf)), + strm->txn ? strm->txn->rsp.next : 0, (unsigned int)ci_data(&strm->res), (unsigned int)strm->res.buf->size); if (ci_putchk(si_ic(si), &trash) == -1) {