[PATCH 26/31] net/ipv4: sock: handle SO_REUSEADDR for SOCK_DGRAM gracefully

Jean-Baptiste Tr├ędez jean-baptiste.tredez at alstefgroup.com
Tue May 11 18:05:30 CEST 2021

From: Philippe Gerum <rpm at xenomai.org>

Issuing SO_REUSEADDR for an IP socket before binding it is part of the
boilerplate code of many applications. Handle such request gracefully
like the regular network stack does, returning success without
performing any action since we implement no timed wait state for

Signed-off-by: Philippe Gerum <rpm at xenomai.org>
 kernel/drivers/net/stack/ipv4/ip_sock.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/drivers/net/stack/ipv4/ip_sock.c b/kernel/drivers/net/stack/ipv4/ip_sock.c
index 0349ed1b1..a3f7d1f57 100644
--- a/kernel/drivers/net/stack/ipv4/ip_sock.c
+++ b/kernel/drivers/net/stack/ipv4/ip_sock.c
@@ -35,6 +35,9 @@ int rt_ip_setsockopt(struct rtdm_fd *fd, struct rtsocket *s, int level,
 	int err = 0;
 	unsigned int _tos, *tos;
+	if (level == SOL_SOCKET && optname == SO_REUSEADDR)
+		return 0;
 	if (level != SOL_IP)
 		return -ENOPROTOOPT;

More information about the Xenomai mailing list