rename struct tcp_segment_private to struct tcp_segment_internal

This commit is contained in:
luwenpeng
2024-10-31 18:53:01 +08:00
parent 715f301275
commit c05d3fe2d5

View File

@@ -10,17 +10,17 @@
#define TCP_REASSEMBLY_LOG_DEBUG(format, ...) STELLAR_LOG_DEBUG(__thread_local_logger, "TCP reassembly", format, ##__VA_ARGS__)
#define TCP_REASSEMBLY_LOG_ERROR(format, ...) STELLAR_LOG_ERROR(__thread_local_logger, "TCP reassembly", format, ##__VA_ARGS__)
struct tcp_segment_private
struct tcp_segment_internal
{
uint64_t ts;
uint64_t id;
struct interval_tree_node node;
TAILQ_ENTRY(tcp_segment_private) lru;
TAILQ_ENTRY(tcp_segment_internal) lru;
struct tcp_segment seg;
void *data; // flexible array member
};
TAILQ_HEAD(tcp_segment_private_list, tcp_segment_private);
TAILQ_HEAD(tcp_segment_internal_list, tcp_segment_internal);
struct tcp_reassembly
{
@@ -30,13 +30,13 @@ struct tcp_reassembly
uint64_t sum_seg_num;
struct rb_root_cached rb_root;
struct tcp_segment_private_list lru_list;
struct tcp_segment_internal_list lru_list;
uint32_t recv_next;
};
struct tcp_segment *tcp_segment_new(uint32_t seq, const void *data, uint32_t len)
{
struct tcp_segment_private *p = (struct tcp_segment_private *)malloc(sizeof(struct tcp_segment_private) + len);
struct tcp_segment_internal *p = (struct tcp_segment_internal *)malloc(sizeof(struct tcp_segment_internal) + len);
if (!p)
{
TCP_REASSEMBLY_LOG_ERROR("calloc failed");
@@ -48,7 +48,7 @@ struct tcp_segment *tcp_segment_new(uint32_t seq, const void *data, uint32_t len
p->node.start = seq;
p->node.last = (uint64_t)seq + (uint64_t)len - 1;
p->data = (char *)p + sizeof(struct tcp_segment_private);
p->data = (char *)p + sizeof(struct tcp_segment_internal);
memcpy(p->data, data, len);
p->seg.len = len;
@@ -61,7 +61,7 @@ void tcp_segment_free(struct tcp_segment *seg)
{
if (seg)
{
struct tcp_segment_private *p = container_of(seg, struct tcp_segment_private, seg);
struct tcp_segment_internal *p = container_of(seg, struct tcp_segment_internal, seg);
free(p);
}
}
@@ -90,7 +90,7 @@ void tcp_reassembly_free(struct tcp_reassembly *tcp_reass)
{
if (tcp_reass)
{
struct tcp_segment_private *p = NULL;
struct tcp_segment_internal *p = NULL;
while ((p = TAILQ_FIRST(&tcp_reass->lru_list)))
{
tcp_reass->cur_seg_num--;
@@ -123,13 +123,13 @@ int tcp_reassembly_push(struct tcp_reassembly *tcp_reass, struct tcp_segment *se
}
int ret = 0;
struct tcp_segment_private *p = container_of(seg, struct tcp_segment_private, seg);
struct tcp_segment_internal *p = container_of(seg, struct tcp_segment_internal, seg);
struct interval_tree_node *node = interval_tree_iter_first(&tcp_reass->rb_root, p->node.start, p->node.last);
if (node)
{
do
{
struct tcp_segment_private *t = container_of(node, struct tcp_segment_private, node);
struct tcp_segment_internal *t = container_of(node, struct tcp_segment_internal, node);
if (t->node.start == p->node.start && t->node.last == p->node.last)
{
TCP_REASSEMBLY_LOG_DEBUG("tcp_reass %p push segment %p [%lu, %lu] failed, segment repeat", tcp_reass, seg, p->node.start, p->node.last);
@@ -170,10 +170,10 @@ struct tcp_segment *tcp_reassembly_pop(struct tcp_reassembly *tcp_reass)
uint64_t overlap = 0;
uint64_t min_id = UINT64_MAX;
struct tcp_segment_private *oldest = NULL;
struct tcp_segment_internal *oldest = NULL;
while (node)
{
struct tcp_segment_private *p = container_of(node, struct tcp_segment_private, node);
struct tcp_segment_internal *p = container_of(node, struct tcp_segment_internal, node);
if (p->id < min_id)
{
min_id = p->id;
@@ -210,7 +210,7 @@ struct tcp_segment *tcp_reassembly_expire(struct tcp_reassembly *tcp_reass, uint
return NULL;
}
struct tcp_segment_private *p = TAILQ_FIRST(&tcp_reass->lru_list);
struct tcp_segment_internal *p = TAILQ_FIRST(&tcp_reass->lru_list);
if (p && now - p->ts >= tcp_reass->max_timeout)
{
tcp_reass->cur_seg_num--;