From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by gnuweeb.org (Postfix) with ESMTPSA id E8AE580C16 for ; Fri, 2 Sep 2022 05:56:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1662098174; bh=sKw3GRvrlHKJ2AAFXTeJoXo+AEZOe311xdW9+JeN4xs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=NzoHdy1IH7Mm6yR15kSa8v/Ih9fD+m7JD+qCq9C1CkmffbUfpT5d0FHPP0RQynJFH HnFfHz3ygEJ/O/aY3YdSYCCH2O+y7acTB3OeT0GfuS7LkBS1JbKssCN9qavLMp7rCg srxEICihZJ5nW/zGDLUmuWbCll45E3ohKGOs3YUW0EKa/gMeagQWs0ciYYHJqvYex8 UQynV/yIxa6pfvRK4aAjuQ4j5/cr8NFX78SF2T87bqxQ85rmscg9Ha3WN02vH92PKj Ljx6DaVi2n+PGfSz0IgCJn7OYqgbyClfy9Rr2zbDb/QhAEosGl7GA4pW0raalGMaEQ 9Rm7VT6HESaow== Received: by mail-lf1-f41.google.com with SMTP id p7so1819434lfu.3 for ; Thu, 01 Sep 2022 22:56:14 -0700 (PDT) X-Gm-Message-State: ACgBeo1JNc5Hz4VkFiYxzDZnBPTtGhQ3sNgu301JzY4Evs0nUCeo2Vfs RZZvgwYKr+LmnIAMazmnsG685VQqH5ruLN2n8yM= X-Google-Smtp-Source: AA6agR5PN7WtPmQ+JVEoFx3G/75dRt+jUx81WnoR0nDTjg1SHBaWwcAxBPBxPZ1OiwlxA9gRJUTgIBZUy3ctcebHWuc= X-Received: by 2002:a05:6512:a8c:b0:48b:3e1c:c3ad with SMTP id m12-20020a0565120a8c00b0048b3e1cc3admr12289675lfu.678.1662098173023; Thu, 01 Sep 2022 22:56:13 -0700 (PDT) MIME-Version: 1.0 References: <20220902011548.2506938-1-ammar.faizi@intel.com> <20220902011548.2506938-2-ammar.faizi@intel.com> In-Reply-To: <20220902011548.2506938-2-ammar.faizi@intel.com> From: Alviro Iskandar Setiawan Date: Fri, 2 Sep 2022 12:56:01 +0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RESEND PATCH liburing v1 01/12] test/helpers: Add `t_bind_ephemeral_port()` function To: Ammar Faizi Cc: Jens Axboe , Dylan Yudaken , Facebook Kernel Team , Pavel Begunkov , io-uring Mailing List , "GNU/Weeb Mailing List" , Kanna Scarlet , Muhammad Rizki Content-Type: text/plain; charset="UTF-8" List-Id: On Fri, Sep 2, 2022 at 8:18 AM Ammar Faizi wrote: > From: Ammar Faizi > > This is a prep patch to fix an intermittent issue with the port number. > > We have many places where we need to bind() a socket to any unused port > number. To achieve that, the current approach does one of the following > mechanisms: > > 1) Randomly brute force the port number until the bind() syscall > succeeds. > > 2) Use a static port at compile time (randomly chosen too). > > This is not reliable and it results in an intermittent issue (test > fails when the selected port is in use). > > Setting @addr->sin_port to zero on a bind() syscall lets the kernel > choose a port number that is not in use. The caller then can know the > port number to be bound by invoking a getsockname() syscall after > bind() succeeds. > > Wrap this procedure in a new function called t_bind_ephemeral_port(). > The selected port will be returned into @addr->sin_port, the caller > can use it later to connect() or whatever they need. > > Link: https://lore.kernel.org/r/918facd1-78ba-2de7-693a-5f8c65ea2fcd@gnuweeb.org > Cc: Dylan Yudaken > Cc: Facebook Kernel Team > Cc: Pavel Begunkov > Signed-off-by: Ammar Faizi Reviewed-by: Alviro Iskandar Setiawan tq -- Viro