From e02711e1148a34c66c53e88b286b4c0185ee809d Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Mon, 7 Feb 2022 11:37:39 +0800 Subject: [PATCH] net/icmpv6: replace the common connect prologue Signed-off-by: chao.an --- net/icmpv6/icmpv6.h | 14 ++++---------- net/icmpv6/icmpv6_conn.c | 16 +++++++++------- net/icmpv6/icmpv6_input.c | 2 +- net/icmpv6/icmpv6_poll.c | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/net/icmpv6/icmpv6.h b/net/icmpv6/icmpv6.h index f08517b620..38e1170107 100644 --- a/net/icmpv6/icmpv6.h +++ b/net/icmpv6/icmpv6.h @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -48,9 +49,9 @@ /* Allocate a new ICMPv6 data callback */ #define icmpv6_callback_alloc(dev, conn) \ - devif_callback_alloc((dev), &(conn)->list, &(conn)->list_tail) + devif_callback_alloc((dev), &(conn)->sconn.list, &(conn)->sconn.list_tail) #define icmpv6_callback_free(dev, conn, cb) \ - devif_conn_callback_free((dev), (cb), &(conn)->list, &(conn)->list_tail) + devif_conn_callback_free((dev), (cb), &(conn)->sconn.list, &(conn)->sconn.list_tail) /**************************************************************************** * Public Type Definitions @@ -79,14 +80,7 @@ struct icmpv6_conn_s { /* Common prologue of all connection structures. */ - dq_entry_t node; /* Supports a double linked list */ - - /* This is a list of ICMPV6 callbacks. Each callback represents a thread - * that is stalled, waiting for a device-specific event. - */ - - FAR struct devif_callback_s *list; - FAR struct devif_callback_s *list_tail; + struct socket_conn_s sconn; /* ICMPv6-specific content follows */ diff --git a/net/icmpv6/icmpv6_conn.c b/net/icmpv6/icmpv6_conn.c index ce2a6df4c1..83c19dcd3a 100644 --- a/net/icmpv6/icmpv6_conn.c +++ b/net/icmpv6/icmpv6_conn.c @@ -91,7 +91,8 @@ void icmpv6_sock_initialize(void) { /* Move the connection structure to the free list */ - dq_addlast(&g_icmpv6_connections[i].node, &g_free_icmpv6_connections); + dq_addlast(&g_icmpv6_connections[i].sconn.node, + &g_free_icmpv6_connections); } #endif } @@ -124,7 +125,8 @@ FAR struct icmpv6_conn_s *icmpv6_alloc(void) { for (ret = 0; ret < CONFIG_NET_ICMPv6_NCONNS; ret++) { - dq_addlast(&conn[ret].node, &g_free_icmpv6_connections); + dq_addlast(&conn[ret].sconn.node, + &g_free_icmpv6_connections); } } } @@ -136,7 +138,7 @@ FAR struct icmpv6_conn_s *icmpv6_alloc(void) { /* Enqueue the connection into the active list */ - dq_addlast(&conn->node, &g_active_icmpv6_connections); + dq_addlast(&conn->sconn.node, &g_active_icmpv6_connections); } nxsem_post(&g_free_sem); @@ -166,7 +168,7 @@ void icmpv6_free(FAR struct icmpv6_conn_s *conn) /* Remove the connection from the active list */ - dq_rem(&conn->node, &g_active_icmpv6_connections); + dq_rem(&conn->sconn.node, &g_active_icmpv6_connections); /* Clear the connection structure */ @@ -174,7 +176,7 @@ void icmpv6_free(FAR struct icmpv6_conn_s *conn) /* Free the connection */ - dq_addlast(&conn->node, &g_free_icmpv6_connections); + dq_addlast(&conn->sconn.node, &g_free_icmpv6_connections); nxsem_post(&g_free_sem); } @@ -208,7 +210,7 @@ FAR struct icmpv6_conn_s *icmpv6_active(uint16_t id) /* Look at the next active connection */ - conn = (FAR struct icmpv6_conn_s *)conn->node.flink; + conn = (FAR struct icmpv6_conn_s *)conn->sconn.node.flink; } return conn; @@ -233,7 +235,7 @@ FAR struct icmpv6_conn_s *icmpv6_nextconn(FAR struct icmpv6_conn_s *conn) } else { - return (FAR struct icmpv6_conn_s *)conn->node.flink; + return (FAR struct icmpv6_conn_s *)conn->sconn.node.flink; } } diff --git a/net/icmpv6/icmpv6_input.c b/net/icmpv6/icmpv6_input.c index 12f73ae14f..2bb82dc8b8 100644 --- a/net/icmpv6/icmpv6_input.c +++ b/net/icmpv6/icmpv6_input.c @@ -460,7 +460,7 @@ void icmpv6_input(FAR struct net_driver_s *dev, unsigned int iplen) /* Dispatch the ECHO reply to the waiting thread */ - flags = devif_conn_event(dev, conn, flags, conn->list); + flags = devif_conn_event(dev, conn, flags, conn->sconn.list); /* Was the ECHO reply consumed by any waiting thread? */ diff --git a/net/icmpv6/icmpv6_poll.c b/net/icmpv6/icmpv6_poll.c index 5124739028..e7f5a07296 100644 --- a/net/icmpv6/icmpv6_poll.c +++ b/net/icmpv6/icmpv6_poll.c @@ -74,7 +74,7 @@ void icmpv6_poll(FAR struct net_driver_s *dev, /* Perform the application callback */ devif_conn_event(dev, conn, ICMPv6_POLL, - conn ? conn->list : dev->d_conncb); + conn ? conn->sconn.list : dev->d_conncb); } #endif /* CONFIG_NET_ICMPv6_SOCKET || CONFIG_NET_ICMPv6_NEIGHBOR */