net/inet: replace net_lock with conn_lock

Protect icmp resources through conn_lock

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2025-07-29 17:25:55 +08:00
committed by Xiang Xiao
parent 8ef876562e
commit 6b625dfdf2
7 changed files with 31 additions and 24 deletions
+11 -10
View File
@@ -44,6 +44,7 @@
#include "icmpv6/icmpv6.h"
#include "sixlowpan/sixlowpan.h"
#include "socket/socket.h"
#include "utils/utils.h"
#include "inet/inet.h"
#ifdef HAVE_INET_SOCKETS
@@ -913,7 +914,7 @@ static int inet_set_socketlevel_option(FAR struct socket *psock, int option,
* options.
*/
net_lock();
conn_lock(conn);
/* Set or clear the linger option bit and linger time
* (in deciseconds)
@@ -930,7 +931,7 @@ static int inet_set_socketlevel_option(FAR struct socket *psock, int option,
conn->s_linger = 0;
}
net_unlock();
conn_unlock(conn);
}
break;
#endif
@@ -961,7 +962,7 @@ static int inet_set_socketlevel_option(FAR struct socket *psock, int option,
buffersize = MIN(buffersize, CONFIG_NET_MAX_RECV_BUFSIZE);
#endif
net_lock();
conn_lock(psock->s_conn);
#ifdef NET_TCP_HAVE_STACK
if (psock->s_type == SOCK_STREAM)
@@ -986,11 +987,11 @@ static int inet_set_socketlevel_option(FAR struct socket *psock, int option,
else
#endif
{
net_unlock();
conn_unlock(psock->s_conn);
return -ENOPROTOOPT;
}
net_unlock();
conn_unlock(psock->s_conn);
}
break;
#endif
@@ -1022,7 +1023,7 @@ static int inet_set_socketlevel_option(FAR struct socket *psock, int option,
buffersize = MIN(buffersize, CONFIG_NET_MAX_SEND_BUFSIZE);
#endif
net_lock();
conn_lock(psock->s_conn);
#ifdef NET_TCP_HAVE_STACK
if (psock->s_type == SOCK_STREAM)
@@ -1047,11 +1048,11 @@ static int inet_set_socketlevel_option(FAR struct socket *psock, int option,
else
#endif
{
net_unlock();
conn_unlock(psock->s_conn);
return -ENOPROTOOPT;
}
net_unlock();
conn_unlock(psock->s_conn);
}
break;
#endif
@@ -1066,7 +1067,7 @@ static int inet_set_socketlevel_option(FAR struct socket *psock, int option,
if (psock->s_type == SOCK_DGRAM)
{
net_lock();
conn_lock(psock->s_conn);
/* For now the timestamp enable is just boolean.
* If SO_TIMESTAMPING support is added in future, it can be
@@ -1076,7 +1077,7 @@ static int inet_set_socketlevel_option(FAR struct socket *psock, int option,
FAR struct udp_conn_s *conn = psock->s_conn;
conn->timestamp = (*((FAR int *)value) != 0);
net_unlock();
conn_unlock(psock->s_conn);
}
else
{
+4 -3
View File
@@ -39,6 +39,7 @@
#include "netdev/netdev.h"
#include "udp/udp.h"
#include "tcp/tcp.h"
#include "utils/utils.h"
#include "inet/inet.h"
#ifdef CONFIG_NET_IPv4
@@ -130,7 +131,7 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
return OK;
}
net_lock();
conn_lock(psock->s_conn);
/* Find the device matching the IPv4 address in the connection structure.
* NOTE: listening sockets have no ripaddr. Work around is to use the
@@ -146,7 +147,7 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
if (dev == NULL)
{
net_unlock();
conn_unlock(psock->s_conn);
return -EINVAL;
}
@@ -158,7 +159,7 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
*addrlen = sizeof(struct sockaddr_in);
net_unlock();
conn_unlock(psock->s_conn);
/* Return success */
+3 -2
View File
@@ -35,6 +35,7 @@
#include <netinet/in.h>
#include "netfilter/iptables.h"
#include "utils/utils.h"
#ifdef CONFIG_NET_IPv4
@@ -76,7 +77,7 @@ int ipv4_getsockopt(FAR struct socket *psock, int option,
ninfo("option: %d\n", option);
net_lock();
conn_lock(psock->s_conn);
switch (option)
{
#ifdef CONFIG_NET_IPTABLES
@@ -102,7 +103,7 @@ int ipv4_getsockopt(FAR struct socket *psock, int option,
break;
}
net_unlock();
conn_unlock(psock->s_conn);
return ret;
}
+3 -2
View File
@@ -41,6 +41,7 @@
#include "inet/inet.h"
#include "socket/socket.h"
#include "udp/udp.h"
#include "utils/utils.h"
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_SOCKOPTS)
@@ -86,7 +87,7 @@ int ipv4_setsockopt(FAR struct socket *psock, int option,
* REVISIT: Clone the logic from netdev_ioctl.c here.
*/
net_lock();
conn_lock(psock->s_conn);
switch (option)
{
#ifdef CONFIG_NET_IGMP
@@ -391,7 +392,7 @@ int ipv4_setsockopt(FAR struct socket *psock, int option,
break;
}
net_unlock();
conn_unlock(psock->s_conn);
return ret;
}
+4 -3
View File
@@ -39,6 +39,7 @@
#include "netdev/netdev.h"
#include "udp/udp.h"
#include "tcp/tcp.h"
#include "utils/utils.h"
#include "inet/inet.h"
#ifdef CONFIG_NET_IPv6
@@ -130,7 +131,7 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
return OK;
}
net_lock();
conn_lock(psock->s_conn);
/* Find the device matching the IPv6 address in the connection structure.
* NOTE: listening sockets have no ripaddr. Work around is to use the
@@ -145,7 +146,7 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
dev = netdev_findby_ripv6addr(*lipaddr, *ripaddr);
if (!dev)
{
net_unlock();
conn_unlock(psock->s_conn);
return -EINVAL;
}
@@ -156,7 +157,7 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
netdev_ipv6_srcaddr(dev, *lipaddr));
*addrlen = sizeof(struct sockaddr_in6);
net_unlock();
conn_unlock(psock->s_conn);
/* Return success */
+3 -2
View File
@@ -38,6 +38,7 @@
#include "netfilter/iptables.h"
#include "inet/inet.h"
#include "udp/udp.h"
#include "utils/utils.h"
#ifdef CONFIG_NET_IPv6
@@ -75,7 +76,7 @@ int ipv6_getsockopt(FAR struct socket *psock, int option,
ninfo("option: %d\n", option);
net_lock();
conn_lock(psock->s_conn);
switch (option)
{
#ifdef CONFIG_NET_IPTABLES
@@ -101,7 +102,7 @@ int ipv6_getsockopt(FAR struct socket *psock, int option,
break;
}
net_unlock();
conn_unlock(psock->s_conn);
return ret;
}
+3 -2
View File
@@ -40,6 +40,7 @@
#include "inet/inet.h"
#include "socket/socket.h"
#include "udp/udp.h"
#include "utils/utils.h"
#if defined(CONFIG_NET_IPv6) && defined(CONFIG_NET_SOCKOPTS)
@@ -83,7 +84,7 @@ int ipv6_setsockopt(FAR struct socket *psock, int option,
return -EINVAL;
}
net_lock();
conn_lock(psock->s_conn);
switch (option)
{
#ifdef CONFIG_NET_MLD
@@ -231,7 +232,7 @@ int ipv6_setsockopt(FAR struct socket *psock, int option,
break;
}
net_unlock();
conn_unlock(psock->s_conn);
return ret;
}