Make socket_udp-corked use different port

Submitted by Vitaly Ostrosablin on March 26, 2018, 9:31 a.m.

Details

Message ID 20180326093121.20311-1-vostrosablin@virtuozzo.com
State New
Series "Make socket_udp-corked use different port"
Headers show

Commit Message

Vitaly Ostrosablin March 26, 2018, 9:31 a.m.
If test is run simultaneously with socket_udp - then one of tests would
be unable to bind same port.

Signed-off-by: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>
---
 test/zdtm/static/socket_udp-corked.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/test/zdtm/static/socket_udp-corked.c b/test/zdtm/static/socket_udp-corked.c
index 30cfac5ec..490f27895 100644
--- a/test/zdtm/static/socket_udp-corked.c
+++ b/test/zdtm/static/socket_udp-corked.c
@@ -21,7 +21,7 @@  const char *test_author = "Pavel Emelyanov <xemul@parallels.com<>\n";
 #include <sys/wait.h>
 #include <netinet/udp.h>
 
-static int port = 8880;
+static int port = 8882;
 
 #define MSG1 "msg1"
 

Comments

Cyrill Gorcunov March 26, 2018, 9:42 a.m.
On Mon, Mar 26, 2018 at 12:31:21PM +0300, Vitaly Ostrosablin wrote:
> If test is run simultaneously with socket_udp - then one of tests would
> be unable to bind same port.
> 
> Signed-off-by: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Andrey Vagin March 29, 2018, 7:20 a.m.
On Mon, Mar 26, 2018 at 12:31:21PM +0300, Vitaly Ostrosablin wrote:
> If test is run simultaneously with socket_udp - then one of tests would
> be unable to bind same port.

Why do you need to run these tests together?

The socket_udp-corked test can't be dumped, and we check that criu dump
fails on it:

$ cat test/zdtm/static/socket_udp-corked.desc 
{'flags': 'crfail'}

> 
> Signed-off-by: Vitaly Ostrosablin <vostrosablin@virtuozzo.com>
> ---
>  test/zdtm/static/socket_udp-corked.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/test/zdtm/static/socket_udp-corked.c b/test/zdtm/static/socket_udp-corked.c
> index 30cfac5ec..490f27895 100644
> --- a/test/zdtm/static/socket_udp-corked.c
> +++ b/test/zdtm/static/socket_udp-corked.c
> @@ -21,7 +21,7 @@ const char *test_author = "Pavel Emelyanov <xemul@parallels.com<>\n";
>  #include <sys/wait.h>
>  #include <netinet/udp.h>
>  
> -static int port = 8880;
> +static int port = 8882;

This port can be used too. Look in tcp_init_server_with_opts:

                ret = bind(sock, (struct sockaddr *) &addr, sizeof(addr));

                /* criu doesn't restore sock opts, so we need this hack */
                if (ret == -1 && errno == EADDRINUSE) {
                        test_msg("The port %d is already in use.\n", *port);
                        (*port)++;

so each tcp test chooses a first unused port starting with 8880.

If you set port to zero, the kernel will choose an unused port:

 @@ -43,7 +41,7 @@ int main(int argc, char **argv)
        memset(&addr1, 0, sizeof(addr1));
        addr1.sin_family = AF_INET;
        addr1.sin_addr.s_addr = inet_addr("127.0.0.1");
-       addr1.sin_port = htons(port);
+       addr1.sin_port = 0;
 
        ret = bind(sk1, (struct sockaddr *)&addr1, len);

>  
>  #define MSG1 "msg1"
>  
> -- 
> 2.16.2
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu