hs-test: don't use reserved UDP ports for binding 97/41897/3
authorAdrian Villin <[email protected]>
Wed, 27 Nov 2024 07:23:43 +0000 (08:23 +0100)
committerFlorin Coras <[email protected]>
Wed, 27 Nov 2024 16:51:38 +0000 (16:51 +0000)
Type: test

Change-Id: Ief0d238bbbf533779618b971f01099aa113c1c08
Signed-off-by: Adrian Villin <[email protected]>
extras/hs-test/infra/hst_suite.go

index d6b4006..0513e86 100644 (file)
@@ -12,6 +12,7 @@ import (
        "os/exec"
        "path/filepath"
        "runtime"
+       "slices"
        "strconv"
        "strings"
        "time"
@@ -75,6 +76,29 @@ var Colors = colors{
        rst: "\033[0m",
 }
 
+// ../../src/vnet/udp/udp_local.h:foreach_udp4_dst_port
+var reservedPorts = []string{
+       "53",
+       "67",
+       "68",
+       "500",
+       "2152",
+       "3784",
+       "3785",
+       "4341",
+       "4342",
+       "4500",
+       "4739",
+       "4784",
+       "4789",
+       "4789",
+       "48879",
+       "4790",
+       "6633",
+       "6081",
+       "53053",
+}
+
 // used for colorful ReportEntry
 type StringerStruct struct {
        Label string
@@ -658,13 +682,23 @@ func (s *HstSuite) GetCurrentSuiteName() string {
        return CurrentSpecReport().ContainerHierarchyTexts[0]
 }
 
-// Returns last 3 digits of PID + Ginkgo process index as the 4th digit
+// Returns last 3 digits of PID + Ginkgo process index as the 4th digit. If the port is in the 'reservedPorts' slice,
+// increment port number by ten and check again.
 func (s *HstSuite) GetPortFromPpid() string {
        port := s.Ppid
+       var err error
+       var portInt int
        for len(port) < 3 {
                port += "0"
        }
-       return port[len(port)-3:] + s.ProcessIndex
+       port = port[len(port)-3:] + s.ProcessIndex
+       for slices.Contains(reservedPorts, port) {
+               portInt, err = strconv.Atoi(port)
+               s.AssertNil(err)
+               portInt += 10
+               port = fmt.Sprintf("%d", portInt)
+       }
+       return port
 }
 
 /*