diff --git a/include/common/htx.h b/include/common/htx.h index 003680a2b..ea7361cfc 100644 --- a/include/common/htx.h +++ b/include/common/htx.h @@ -158,8 +158,7 @@ struct htx { uint64_t extra; /* known bytes amount remaining to receive */ uint32_t flags; /* HTX_FL_* */ - int32_t sl_off; /* Offset of the start-line of the HTTP message relatively to the beginning the - data block. -1 if unset */ + int32_t sl_pos; /* position of the start-line of the HTTP message. -1 if unset */ struct htx_blk blocks[0]; /* Blocks representing the HTTP message itself */ }; @@ -273,17 +272,6 @@ static inline struct ist htx_sl_res_reason(const struct htx_sl *sl) return htx_sl_p3(sl); } -/* Returns the HTX start-line if set, otherwise it returns NULL. */ -static inline struct htx_sl *htx_get_stline(struct htx *htx) -{ - struct htx_sl *sl = NULL; - - if (htx->used && htx->sl_off != -1) - sl = ((void *)htx->blocks + htx->sl_off); - - return sl; -} - /* Returns the array index of a block given its position */ static inline uint32_t htx_pos_to_idx(const struct htx *htx, uint32_t pos) { @@ -611,6 +599,21 @@ static inline struct ist htx_get_blk_value(const struct htx *htx, const struct h return ret; } +/* Returns the HTX start-line if set, otherwise it returns NULL. */ +static inline struct htx_sl *htx_get_stline(struct htx *htx) +{ + struct htx_sl *sl = NULL; + + if (htx->used && htx->sl_pos != -1) { + struct htx_blk *blk = htx_get_blk(htx, htx->sl_pos); + + if (blk) + sl = htx_get_blk_ptr(htx, blk); + } + return sl; +} + + /* Removes bytes from the beginning of DATA block . The block's start * address and its length are adjusted, and the htx's total data count is * updated. This is used to mark that part of some data were transfered @@ -677,7 +680,7 @@ static inline void htx_reset(struct htx *htx) htx->data = htx->used = htx->tail = htx->head = htx->front = 0; htx->extra = 0; htx->flags = HTX_FL_NONE; - htx->sl_off = -1; + htx->sl_pos = -1; } /* returns the available room for raw data in buffer once HTX overhead is @@ -792,8 +795,8 @@ static inline void htx_dump(struct htx *htx) fprintf(stderr, "htx:%p [ size=%u - data=%u - used=%u - wrap=%s - extra=%llu]\n", htx, htx->size, htx->data, htx->used, (htx->tail >= htx->head) ? "NO" : "YES", (unsigned long long)htx->extra); - fprintf(stderr, "\thead=%u, tail=%u - front=%u\n", - htx->head, htx->tail, htx->front); + fprintf(stderr, "\tsl_pos=%d - head=%u, tail=%u - front=%u\n", + htx->sl_pos, htx->head, htx->tail, htx->front); for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { struct htx_sl *sl; diff --git a/src/cache.c b/src/cache.c index 44355cd86..7402e5efd 100644 --- a/src/cache.c +++ b/src/cache.c @@ -915,7 +915,7 @@ static size_t htx_cache_dump_headers(struct appctx *appctx, struct htx *htx) /* Set the start-line offset */ if (type == HTX_BLK_RES_SL) - htx->sl_off = blk->addr; + htx->sl_pos = htx_get_blk_pos(htx, blk); /* Copy info and data */ blk->info = info; diff --git a/src/http_htx.c b/src/http_htx.c index 471f1ab81..e6332f7da 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -40,7 +40,7 @@ struct htx_sl *http_find_stline(struct htx *htx) if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) { sl = htx_get_blk_ptr(htx, blk); - htx->sl_off = blk->addr; + htx->sl_pos = pos; break; } @@ -194,7 +194,7 @@ int http_replace_stline(struct htx *htx, const struct ist p1, const struct ist p struct htx_blk *blk = htx_get_blk(htx, pos); enum htx_blk_type type = htx_get_blk_type(blk); - if (htx->sl_off == blk->addr) { + if (htx->sl_pos == pos) { if (!htx_replace_stline(htx, blk, p1, p2, p3)) return 0; return 1; diff --git a/src/htx.c b/src/htx.c index 9f75f7afa..bdde868af 100644 --- a/src/htx.c +++ b/src/htx.c @@ -28,7 +28,7 @@ struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk) struct htx_blk *newblk, *oldblk; uint32_t new, old, blkpos; uint32_t addr, blksz; - int32_t sl_off = -1; + int32_t sl_pos = -1; if (!htx->used) return NULL; @@ -50,9 +50,9 @@ struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk) newblk->info = oldblk->info; blksz = htx_get_blksz(oldblk); - /* update the start-line offset */ - if (htx->sl_off == oldblk->addr) - sl_off = addr; + /* update the start-line position */ + if (htx->sl_pos == old) + sl_pos = new; /* if is defined, set its new position */ if (blk != NULL && blk == oldblk) @@ -65,7 +65,7 @@ struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk) } htx->used = new; - htx->sl_off = sl_off; + htx->sl_pos = sl_pos; htx->head = 0; htx->front = htx->tail = new - 1; memcpy((void *)htx->blocks, (void *)tmp->blocks, htx->size); @@ -215,12 +215,13 @@ struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk) enum htx_blk_type type = htx_get_blk_type(blk); uint32_t next, pos, wrap; + pos = htx_get_blk_pos(htx, blk); if (type != HTX_BLK_UNUSED) { /* Mark the block as unused, decrement allocated size */ htx->data -= htx_get_blksz(blk); blk->info = ((uint32_t)HTX_BLK_UNUSED << 28); - if (htx->sl_off == blk->addr) - htx->sl_off = -1; + if (htx->sl_pos == pos) + htx->sl_pos = -1; } /* This is the last block in use */ @@ -232,7 +233,6 @@ struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk) } /* There is at least 2 blocks, so tail is always >= 0 */ - pos = htx_get_blk_pos(htx, blk); blk = NULL; next = pos + 1; /* By default retrun the next block */ wrap = htx_get_wrap(htx); @@ -271,11 +271,11 @@ struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk) } blk = htx_get_blk(htx, next); - if (htx->sl_off == -1) { - /* Try to update the start-line offset, if possible */ + if (htx->sl_pos == -1) { + /* Try to update the start-line payload addr, if possible */ type = htx_get_blk_type(blk); if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) - htx->sl_off = blk->addr; + htx->sl_pos = htx_get_blk_pos(htx, blk); } end: if (pos == htx->front) @@ -538,8 +538,8 @@ struct htx_ret htx_xfer_blks(struct htx *dst, struct htx *src, uint32_t count, break; } - if (dst->sl_off == -1 && src->sl_off == blk->addr) - dst->sl_off = dstblk->addr; + if (dst->sl_pos == -1 && src->sl_pos == htx_get_blk_pos(src, blk)) + dst->sl_pos = htx_get_blk_pos(dst, dstblk); next: blk = htx_remove_blk(src, blk); if (type == mark) @@ -612,9 +612,6 @@ struct htx_sl *htx_replace_stline(struct htx *htx, struct htx_blk *blk, const st sl = htx_get_blk_ptr(htx, blk); tmp.info = sl->info; tmp.flags = sl->flags; - if (htx->sl_off == blk->addr) - htx->sl_off = -1; - size = sizeof(*sl) + p1.len + p2.len + p3.len; delta = size - htx_get_blksz(blk); @@ -642,8 +639,6 @@ struct htx_sl *htx_replace_stline(struct htx *htx, struct htx_blk *blk, const st sl = htx_get_blk_ptr(htx, blk); sl->info = tmp.info; sl->flags = tmp.flags; - if (htx->sl_off == -1) - htx->sl_off = blk->addr; HTX_SL_P1_LEN(sl) = p1.len; HTX_SL_P2_LEN(sl) = p2.len; @@ -678,8 +673,8 @@ struct htx_sl *htx_add_stline(struct htx *htx, enum htx_blk_type type, unsigned blk->info += size; sl = htx_get_blk_ptr(htx, blk); - if (htx->sl_off == -1) - htx->sl_off = blk->addr; + if (htx->sl_pos == -1) + htx->sl_pos = htx_get_blk_pos(htx, blk); sl->flags = flags;