utils/sctp: bugfix for testlib/sctputil.h
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
@@ -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
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.
UseSO_REUSEPORTto 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
Signed-off-by Min Li <[email protected]>--- utils/sctp/testlib/sctputil.h | 9 +++++++++ 1 file changed, 9 insertions(+)utils/sctp/testlib/sctputil.h +0
-0
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
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.
UseSO_REUSEPORTto 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_REUSEADDRandSO_REUSEPORT.Quoted 4 lines
Signed-off-by Min Li <[email protected]>--- 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@@ -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(). Ortst_brkm(TWARN, ...)could be used (we don't use printf directly in LTP).
+1 for SAFE_SETSOCKOPT
Quoted 9 lines
Kind regards,
Petrutils/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
-0if (sk ==-1 ) {if (errno ==EAFNOSUPPORT )
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp