Skip to contentSkip to conversation

utils/sctp: bugfix for testlib/sctputil.h

PATCH In review Li Min via ltp 3 participants 3 messages Jul 20, 2023 – Aug 29, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils/sctp: bugfix for testlib/sctputil.h

The socket is created and bound immediately without waiting for the handshake after close(sk). "bind(): errno=EADDRINUSE(98): Address already in use" may be reported.
Use SO_REUSEPORT to allow multiple sockets to be bound to the same port.

---
 utils/sctp/testlib/sctputil.h | 9 +++++++++
 1 file changed, 9 insertions(+)
utils/sctp/testlib/sctputil.h +9 -0
index 176d623f0..b51a3f9b0 100644
@@ -133,6 +133,15 @@ extern int TST_CNT;
 static inline int test_socket(int domain, int type, int protocol)
 {
 	int sk = socket(domain, type, protocol);
+	int true_const=1;
+
+	if(setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &true_const, sizeof(int))){
+		printf("set addr err\n");
+	}
+
+	if(setsockopt(sk, SOL_SOCKET, SO_REUSEPORT, &true_const, sizeof(int))){
+		printf("set port err\n");
+	}
 
 	if (sk == -1) {
 		if (errno == EAFNOSUPPORT)

--
2.33.0

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Li,

Quoted 3 lines

The socket is created and bound immediately without waiting for the handshake after close(sk). "bind(): errno=EADDRINUSE(98): Address already in use" may be reported.
Use SO_REUSEPORT to allow multiple sockets to be bound to the same port.

How this can happen? Running tests too quickly one after the other? Or what is different on your SUT? I'm not sure if it's good idea to always test with SO_REUSEADDR and SO_REUSEPORT.

Quoted 10 lines
---
 utils/sctp/testlib/sctputil.h | 9 +++++++++
 1 file changed, 9 insertions(+)
utils/sctp/testlib/sctputil.h +0 -0
index 176d623f0..b51a3f9b0 100644

utils/sctp/testlib/sctputil.h extern int TST_CNT; · line 136

Quoted 4 lines
utils/sctp/testlib/sctputil.h +1 -0
@@ -133,6 +133,15 @@ extern int TST_CNT;
 static inline int test_socket(int domain, int type, int protocol)
 {
 	int sk = socket(domain, type, protocol);
+	int true_const=1;

What is this unused variable for?

utils/sctp/testlib/sctputil.h extern int TST_CNT; · line 139

Quoted 3 lines
utils/sctp/testlib/sctputil.h +3 -0
+
+	if(setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &true_const, sizeof(int))){
+		printf("set addr err\n");

Besides missing spaces in if (if (..) { ), we have SAFE_SETSOCKOPT(). Or tst_brkm(TWARN, ...) could be used (we don't use printf directly in LTP).

Kind regards,
Petr

Quoted 8 lines
utils/sctp/testlib/sctputil.h +5 -0
+	}
+
+	if(setsockopt(sk, SOL_SOCKET, SO_REUSEPORT, &true_const, sizeof(int))){
+		printf("set port err\n");
+	}
 
 	if (sk == -1) {
 		if (errno == EAFNOSUPPORT)
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hello,

Quoted 15 lines · Petr Vorel

Hi Li,

Quoted 3 lines

The socket is created and bound immediately without waiting for the handshake after close(sk). "bind(): errno=EADDRINUSE(98): Address already in use" may be reported.
Use SO_REUSEPORT to allow multiple sockets to be bound to the same port.

How this can happen? Running tests too quickly one after the other? Or what is different on your SUT? I'm not sure if it's good idea to always test with SO_REUSEADDR and SO_REUSEPORT.

Quoted 4 lines
---
 utils/sctp/testlib/sctputil.h | 9 +++++++++
 1 file changed, 9 insertions(+)
Quoted 10 lines

utils/sctp/testlib/sctputil.h extern int TST_CNT; · line 136

Quoted 9 lines
utils/sctp/testlib/sctputil.h +1 -0
index 176d623f0..b51a3f9b0 100644
@@ -133,6 +133,15 @@ extern int TST_CNT;
 static inline int test_socket(int domain, int type, int protocol)
 {
 	int sk = socket(domain, type, protocol);
+	int true_const=1;

What is this unused variable for?

It's used as the socket option value.

Quoted 7 lines

utils/sctp/testlib/sctputil.h extern int TST_CNT; · line 139

Quoted 4 lines
utils/sctp/testlib/sctputil.h +3 -0
+
+	if(setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &true_const, sizeof(int))){
+		printf("set addr err\n");

Besides missing spaces in if (if (..) { ), we have SAFE_SETSOCKOPT(). Or tst_brkm(TWARN, ...) could be used (we don't use printf directly in LTP).

+1 for SAFE_SETSOCKOPT

Quoted 9 lines

Kind regards,
Petr

utils/sctp/testlib/sctputil.h extern int TST_CNT; · line 144

Quoted 5 lines
utils/sctp/testlib/sctputil.h +5 -0
+	}
+
+	if(setsockopt(sk, SOL_SOCKET, SO_REUSEPORT, &true_const, sizeof(int))){
+		printf("set port err\n");
+	}

We don't need to set it twice.

Setting patch as changes requested.

Quoted 3 lines
Quoted 3 lines
utils/sctp/testlib/sctputil.h +0 -0
 	if (sk == -1) {
 		if (errno == EAFNOSUPPORT)
Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp