315 lines
13 KiB
Diff
315 lines
13 KiB
Diff
From 57f45b4269de6e428e21f0376cc90f9f9a515960 Mon Sep 17 00:00:00 2001
|
|
From: Lemmy Huang <huangliming5@huawei.com>
|
|
Date: Thu, 25 May 2023 21:34:29 +0800
|
|
Subject: [PATCH] cleancode: refactor gazelle_hlist.h
|
|
|
|
Signed-off-by: Lemmy Huang <huangliming5@huawei.com>
|
|
---
|
|
src/ltran/ltran_stack.c | 12 +++++-------
|
|
src/ltran/ltran_stat.c | 6 ++----
|
|
src/ltran/ltran_tcp_conn.c | 12 +++++-------
|
|
src/ltran/ltran_tcp_sock.c | 18 +++++++-----------
|
|
src/ltran/ltran_timer.c | 6 +++---
|
|
5 files changed, 22 insertions(+), 32 deletions(-)
|
|
|
|
diff --git a/src/ltran/ltran_stack.c b/src/ltran/ltran_stack.c
|
|
index d2ec9f5..907518b 100644
|
|
--- a/src/ltran/ltran_stack.c
|
|
+++ b/src/ltran/ltran_stack.c
|
|
@@ -42,7 +42,7 @@ struct gazelle_stack_htable *gazelle_stack_htable_create(uint32_t max_stack_num)
|
|
}
|
|
|
|
for (i = 0; i < GAZELLE_MAX_STACK_HTABLE_SIZE; i++) {
|
|
- INIT_HLIST_HEAD(&stack_htable->array[i].chain);
|
|
+ hlist_init_head(&stack_htable->array[i].chain);
|
|
stack_htable->array[i].chain_size = 0;
|
|
}
|
|
stack_htable->cur_stack_num = 0;
|
|
@@ -67,7 +67,7 @@ void gazelle_stack_htable_destroy(void)
|
|
while (node != NULL) {
|
|
stack = hlist_entry(node, typeof(*stack), stack_node);
|
|
node = node->next;
|
|
- hlist_del_init(&stack->stack_node);
|
|
+ hlist_del_node(&stack->stack_node);
|
|
free(stack);
|
|
}
|
|
}
|
|
@@ -87,7 +87,6 @@ const struct gazelle_stack *gazelle_stack_get_by_tid(const struct gazelle_stack_
|
|
uint32_t index;
|
|
const struct gazelle_stack *stack = NULL;
|
|
const struct gazelle_stack_hbucket *stack_hbucket = NULL;
|
|
- struct hlist_node *node = NULL;
|
|
const struct hlist_head *head = NULL;
|
|
|
|
index = tid_hash_fn(tid) % GAZELLE_MAX_STACK_HTABLE_SIZE;
|
|
@@ -97,7 +96,7 @@ const struct gazelle_stack *gazelle_stack_get_by_tid(const struct gazelle_stack_
|
|
}
|
|
|
|
head = &stack_hbucket->chain;
|
|
- hlist_for_each_entry(stack, node, head, stack_node) {
|
|
+ hlist_for_each_entry(stack, head, stack_node) {
|
|
if ((stack->tid == tid) && INSTANCE_IS_ON(stack)) {
|
|
return stack;
|
|
}
|
|
@@ -144,7 +143,6 @@ void gazelle_stack_del_by_tid(struct gazelle_stack_htable *stack_htable, uint32_
|
|
{
|
|
struct gazelle_stack *stack = NULL;
|
|
struct gazelle_stack_hbucket *stack_hbucket = NULL;
|
|
- struct hlist_node *node = NULL;
|
|
struct hlist_head *head = NULL;
|
|
uint32_t backup_size;
|
|
uint32_t index;
|
|
@@ -156,7 +154,7 @@ void gazelle_stack_del_by_tid(struct gazelle_stack_htable *stack_htable, uint32_
|
|
}
|
|
|
|
head = &stack_hbucket->chain;
|
|
- hlist_for_each_entry(stack, node, head, stack_node) {
|
|
+ hlist_for_each_entry(stack, head, stack_node) {
|
|
if (stack->tid == tid) {
|
|
break;
|
|
}
|
|
@@ -180,7 +178,7 @@ void gazelle_stack_del_by_tid(struct gazelle_stack_htable *stack_htable, uint32_
|
|
}
|
|
}
|
|
|
|
- hlist_del_init(&stack->stack_node);
|
|
+ hlist_del_node(&stack->stack_node);
|
|
stack_htable->cur_stack_num--;
|
|
stack_hbucket->chain_size--;
|
|
|
|
diff --git a/src/ltran/ltran_stat.c b/src/ltran/ltran_stat.c
|
|
index 25dda50..774b9cc 100644
|
|
--- a/src/ltran/ltran_stat.c
|
|
+++ b/src/ltran/ltran_stat.c
|
|
@@ -214,7 +214,6 @@ void handle_resp_ltran_total(int32_t fd)
|
|
void handle_resp_ltran_sock(int32_t fd)
|
|
{
|
|
struct gazelle_tcp_sock *tcp_sock = NULL;
|
|
- struct hlist_node *node = NULL;
|
|
struct hlist_head *head = NULL;
|
|
struct gazelle_tcp_sock_htable *sock_htable = gazelle_get_tcp_sock_htable();
|
|
struct gazelle_stat_forward_table forward_table = {0};
|
|
@@ -227,7 +226,7 @@ void handle_resp_ltran_sock(int32_t fd)
|
|
|
|
for (int32_t i = 0; i < GAZELLE_MAX_TCP_SOCK_HTABLE_SIZE; i++) {
|
|
head = &sock_htable->array[i].chain;
|
|
- hlist_for_each_entry(tcp_sock, node, head, tcp_sock_node) {
|
|
+ hlist_for_each_entry(tcp_sock, head, tcp_sock_node) {
|
|
if (index < GAZELLE_LSTACK_MAX_CONN) {
|
|
forward_table.conn_list[index].dst_ip = tcp_sock->ip;
|
|
forward_table.conn_list[index].tid = tcp_sock->tid;
|
|
@@ -248,7 +247,6 @@ void handle_resp_ltran_sock(int32_t fd)
|
|
|
|
void handle_resp_ltran_conn(int32_t fd)
|
|
{
|
|
- struct hlist_node *node = NULL;
|
|
struct hlist_head *head = NULL;
|
|
struct gazelle_tcp_conn_htable *conn_htable = gazelle_get_tcp_conn_htable();
|
|
struct gazelle_tcp_sock_htable *sock_htable = gazelle_get_tcp_sock_htable();
|
|
@@ -263,7 +261,7 @@ void handle_resp_ltran_conn(int32_t fd)
|
|
|
|
for (int32_t i = 0; i < GAZELLE_MAX_CONN_HTABLE_SIZE; i++) {
|
|
head = &conn_htable->array[i].chain;
|
|
- hlist_for_each_entry(conn, node, head, conn_node) {
|
|
+ hlist_for_each_entry(conn, head, conn_node) {
|
|
if (index < GAZELLE_LSTACK_MAX_CONN) {
|
|
forward_table.conn_list[index].protocol = conn->quintuple.protocol;
|
|
forward_table.conn_list[index].tid = conn->tid;
|
|
diff --git a/src/ltran/ltran_tcp_conn.c b/src/ltran/ltran_tcp_conn.c
|
|
index e0ad562..ca1f414 100644
|
|
--- a/src/ltran/ltran_tcp_conn.c
|
|
+++ b/src/ltran/ltran_tcp_conn.c
|
|
@@ -40,7 +40,7 @@ struct gazelle_tcp_conn_htable *gazelle_tcp_conn_htable_create(uint32_t max_conn
|
|
}
|
|
|
|
for (i = 0; i < GAZELLE_MAX_CONN_HTABLE_SIZE; i++) {
|
|
- INIT_HLIST_HEAD(&conn_htable->array[i].chain);
|
|
+ hlist_init_head(&conn_htable->array[i].chain);
|
|
conn_htable->array[i].chain_size = 0;
|
|
}
|
|
conn_htable->cur_conn_num = 0;
|
|
@@ -65,7 +65,7 @@ void gazelle_tcp_conn_htable_destroy(void)
|
|
while (node != NULL) {
|
|
conn = hlist_entry(node, typeof(*conn), conn_node);
|
|
node = node->next;
|
|
- hlist_del_init(&conn->conn_node);
|
|
+ hlist_del_node(&conn->conn_node);
|
|
rte_free(conn);
|
|
}
|
|
}
|
|
@@ -132,7 +132,6 @@ struct gazelle_tcp_conn *gazelle_conn_get_by_quintuple(struct gazelle_tcp_conn_h
|
|
{
|
|
struct gazelle_tcp_conn *conn = NULL;
|
|
struct gazelle_tcp_conn_hbucket *conn_hbucket = NULL;
|
|
- struct hlist_node *node = NULL;
|
|
struct hlist_head *head = NULL;
|
|
|
|
conn_hbucket = gazelle_conn_hbucket_get(conn_htable, quintuple);
|
|
@@ -141,7 +140,7 @@ struct gazelle_tcp_conn *gazelle_conn_get_by_quintuple(struct gazelle_tcp_conn_h
|
|
}
|
|
|
|
head = &conn_hbucket->chain;
|
|
- hlist_for_each_entry(conn, node, head, conn_node) {
|
|
+ hlist_for_each_entry(conn, head, conn_node) {
|
|
if (!INSTANCE_IS_ON(conn)) {
|
|
continue;
|
|
}
|
|
@@ -156,7 +155,6 @@ void gazelle_conn_del_by_quintuple(struct gazelle_tcp_conn_htable *conn_htable,
|
|
{
|
|
struct gazelle_tcp_conn *conn = NULL;
|
|
struct gazelle_tcp_conn_hbucket *conn_hbucket = NULL;
|
|
- struct hlist_node *node = NULL;
|
|
struct hlist_head *head = NULL;
|
|
|
|
conn_hbucket = gazelle_conn_hbucket_get(conn_htable, quintuple);
|
|
@@ -165,7 +163,7 @@ void gazelle_conn_del_by_quintuple(struct gazelle_tcp_conn_htable *conn_htable,
|
|
}
|
|
|
|
head = &conn_hbucket->chain;
|
|
- hlist_for_each_entry(conn, node, head, conn_node) {
|
|
+ hlist_for_each_entry(conn, head, conn_node) {
|
|
if (memcmp(&conn->quintuple, quintuple, sizeof(struct gazelle_quintuple)) == 0) {
|
|
break;
|
|
}
|
|
@@ -175,7 +173,7 @@ void gazelle_conn_del_by_quintuple(struct gazelle_tcp_conn_htable *conn_htable,
|
|
return;
|
|
}
|
|
|
|
- hlist_del_init(&conn->conn_node);
|
|
+ hlist_del_node(&conn->conn_node);
|
|
rte_free(conn);
|
|
conn_htable->cur_conn_num--;
|
|
conn_hbucket->chain_size--;
|
|
diff --git a/src/ltran/ltran_tcp_sock.c b/src/ltran/ltran_tcp_sock.c
|
|
index 9206675..4bc441a 100644
|
|
--- a/src/ltran/ltran_tcp_sock.c
|
|
+++ b/src/ltran/ltran_tcp_sock.c
|
|
@@ -51,7 +51,7 @@ struct gazelle_tcp_sock_htable *gazelle_tcp_sock_htable_create(uint32_t max_tcp_
|
|
}
|
|
|
|
for (i = 0; i < GAZELLE_MAX_TCP_SOCK_HTABLE_SIZE; i++) {
|
|
- INIT_HLIST_HEAD(&tcp_sock_htable->array[i].chain);
|
|
+ hlist_init_head(&tcp_sock_htable->array[i].chain);
|
|
tcp_sock_htable->array[i].chain_size = 0;
|
|
}
|
|
tcp_sock_htable->cur_tcp_sock_num = 0;
|
|
@@ -77,7 +77,7 @@ void gazelle_tcp_sock_htable_destroy(void)
|
|
while (node != NULL) {
|
|
tcp_sock = hlist_entry(node, typeof(*tcp_sock), tcp_sock_node);
|
|
node = node->next;
|
|
- hlist_del_init(&tcp_sock->tcp_sock_node);
|
|
+ hlist_del_node(&tcp_sock->tcp_sock_node);
|
|
free(tcp_sock);
|
|
}
|
|
}
|
|
@@ -96,14 +96,13 @@ static void recover_sock_info_from_conn(struct gazelle_tcp_sock *tcp_sock)
|
|
{
|
|
uint32_t count = 0;
|
|
struct gazelle_tcp_conn *conn = NULL;
|
|
- struct hlist_node *node = NULL;
|
|
struct hlist_head *head = NULL;
|
|
struct gazelle_tcp_conn_htable *conn_htable = gazelle_get_tcp_conn_htable();
|
|
|
|
for (int32_t i = 0; i < GAZELLE_MAX_CONN_HTABLE_SIZE; i++) {
|
|
head = &conn_htable->array[i].chain;
|
|
|
|
- hlist_for_each_entry(conn, node, head, conn_node) {
|
|
+ hlist_for_each_entry(conn, head, conn_node) {
|
|
if ((conn->quintuple.dst_ip != tcp_sock->ip) || (conn->quintuple.dst_port != tcp_sock->port) ||
|
|
(conn->tid != tcp_sock->tid)) {
|
|
continue;
|
|
@@ -122,7 +121,6 @@ struct gazelle_tcp_sock *gazelle_sock_add_by_ipporttid(struct gazelle_tcp_sock_h
|
|
uint16_t port, uint32_t tid)
|
|
{
|
|
struct gazelle_tcp_sock *tcp_sock = NULL;
|
|
- struct hlist_node *node = NULL;
|
|
struct hlist_head *head = NULL;
|
|
struct gazelle_tcp_sock_hbucket *tcp_sock_hbucket = NULL;
|
|
|
|
@@ -133,7 +131,7 @@ struct gazelle_tcp_sock *gazelle_sock_add_by_ipporttid(struct gazelle_tcp_sock_h
|
|
|
|
/* avoid reinit */
|
|
head = &tcp_sock_hbucket->chain;
|
|
- hlist_for_each_entry(tcp_sock, node, head, tcp_sock_node) {
|
|
+ hlist_for_each_entry(tcp_sock, head, tcp_sock_node) {
|
|
if ((tcp_sock->tid == tid) && INSTANCE_IS_ON(tcp_sock)) {
|
|
return tcp_sock;
|
|
}
|
|
@@ -166,7 +164,6 @@ void gazelle_sock_del_by_ipporttid(struct gazelle_tcp_sock_htable *tcp_sock_htab
|
|
uint32_t tid)
|
|
{
|
|
struct gazelle_tcp_sock *tcp_sock = NULL;
|
|
- struct hlist_node *node = NULL;
|
|
struct hlist_head *head = NULL;
|
|
struct gazelle_tcp_sock_hbucket *tcp_sock_hbucket = NULL;
|
|
|
|
@@ -176,7 +173,7 @@ void gazelle_sock_del_by_ipporttid(struct gazelle_tcp_sock_htable *tcp_sock_htab
|
|
}
|
|
|
|
head = &tcp_sock_hbucket->chain;
|
|
- hlist_for_each_entry(tcp_sock, node, head, tcp_sock_node) {
|
|
+ hlist_for_each_entry(tcp_sock, head, tcp_sock_node) {
|
|
if (tcp_sock->tid == tid) {
|
|
break;
|
|
}
|
|
@@ -186,7 +183,7 @@ void gazelle_sock_del_by_ipporttid(struct gazelle_tcp_sock_htable *tcp_sock_htab
|
|
return;
|
|
}
|
|
|
|
- hlist_del_init(&tcp_sock->tcp_sock_node);
|
|
+ hlist_del_node(&tcp_sock->tcp_sock_node);
|
|
free(tcp_sock);
|
|
tcp_sock_htable->cur_tcp_sock_num--;
|
|
tcp_sock_hbucket->chain_size--;
|
|
@@ -198,7 +195,6 @@ struct gazelle_tcp_sock *gazelle_sock_get_by_min_conn(struct gazelle_tcp_sock_ht
|
|
struct gazelle_tcp_sock_hbucket *tcp_sock_hbucket = NULL;
|
|
struct gazelle_tcp_sock *tcp_sock_tmp = NULL;
|
|
struct gazelle_tcp_sock *tcp_sock = NULL;
|
|
- struct hlist_node *node = NULL;
|
|
struct hlist_head *head = NULL;
|
|
uint32_t min_tcp_con = GAZELLE_STACK_MAX_TCP_CON_NUM;
|
|
|
|
@@ -209,7 +205,7 @@ struct gazelle_tcp_sock *gazelle_sock_get_by_min_conn(struct gazelle_tcp_sock_ht
|
|
|
|
head = &tcp_sock_hbucket->chain;
|
|
|
|
- hlist_for_each_entry(tcp_sock, node, head, tcp_sock_node) {
|
|
+ hlist_for_each_entry(tcp_sock, head, tcp_sock_node) {
|
|
if (!INSTANCE_IS_ON(tcp_sock)) {
|
|
continue;
|
|
}
|
|
diff --git a/src/ltran/ltran_timer.c b/src/ltran/ltran_timer.c
|
|
index 690eca5..af37679 100644
|
|
--- a/src/ltran/ltran_timer.c
|
|
+++ b/src/ltran/ltran_timer.c
|
|
@@ -62,7 +62,7 @@ void gazelle_detect_sock_logout(struct gazelle_tcp_sock_htable *tcp_sock_htable)
|
|
tcp_sock = hlist_entry(node, typeof(*tcp_sock), tcp_sock_node);
|
|
node = node->next;
|
|
if (!INSTANCE_IS_ON(tcp_sock)) {
|
|
- hlist_del_init(&tcp_sock->tcp_sock_node);
|
|
+ hlist_del_node(&tcp_sock->tcp_sock_node);
|
|
tcp_sock_htable->cur_tcp_sock_num--;
|
|
tcp_sock_htable->array[i].chain_size--;
|
|
LTRAN_DEBUG("delete the tcp sock htable: tid %u ip %u port %u\n",
|
|
@@ -98,7 +98,7 @@ void gazelle_detect_conn_logout(struct gazelle_tcp_conn_htable *conn_htable)
|
|
conn = hlist_entry(node, typeof(*conn), conn_node);
|
|
node = node->next;
|
|
if (!INSTANCE_IS_ON(conn)) {
|
|
- hlist_del_init(&conn->conn_node);
|
|
+ hlist_del_node(&conn->conn_node);
|
|
conn_htable->cur_conn_num--;
|
|
conn_htable->array[i].chain_size--;
|
|
LTRAN_DEBUG("delete the tcp conn htable: tid %u quintuple[%u %u %u %u %u]\n",
|
|
@@ -145,7 +145,7 @@ void gazelle_delete_aging_conn(struct gazelle_tcp_conn_htable *conn_htable)
|
|
continue;
|
|
}
|
|
|
|
- hlist_del_init(&conn->conn_node);
|
|
+ hlist_del_node(&conn->conn_node);
|
|
conn_htable->cur_conn_num--;
|
|
conn_htable->array[i].chain_size--;
|
|
if (conn->sock) {
|
|
--
|
|
2.23.0
|
|
|