From 2bf38ed86b6bfa4d295115428d1e65e47c86a9ea Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Mon, 20 Sep 2021 09:29:16 +0200 Subject: [PATCH] agnhost: allow to disable udp listener on netexec There are some tests that doesn't need the UDP listener, so they can disable it. This is specially needed for tests that use hostNetwork pods, if 2 pods try to bind to the same port, the test will fail because one of the pod can't be scheduled because of the port conflict. To keep backwards compatibility, we can add an option to disable the UDP listener by setting the port number to -1, that is consistent with the SCTP implementation. --- test/images/agnhost/README.md | 2 ++ test/images/agnhost/VERSION | 2 +- test/images/agnhost/netexec/netexec.go | 21 ++++++++++++++------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/test/images/agnhost/README.md b/test/images/agnhost/README.md index ee70887f063..7fc63a75753 100644 --- a/test/images/agnhost/README.md +++ b/test/images/agnhost/README.md @@ -417,6 +417,8 @@ It will also start a UDP server on the indicated UDP port that responds to the f - `echo `: Returns the given `` - `clientip`: Returns the request's IP address +The UDP server can be disabled by setting `--udp-port -1`. + Additionally, if (and only if) `--sctp-port` is passed, it will start an SCTP server on that port, responding to the same commands as the UDP server. diff --git a/test/images/agnhost/VERSION b/test/images/agnhost/VERSION index f3283c08e18..cc08e06b66f 100644 --- a/test/images/agnhost/VERSION +++ b/test/images/agnhost/VERSION @@ -1 +1 @@ -2.33 +2.34 diff --git a/test/images/agnhost/netexec/netexec.go b/test/images/agnhost/netexec/netexec.go index 18619b4f502..4c9faa60413 100644 --- a/test/images/agnhost/netexec/netexec.go +++ b/test/images/agnhost/netexec/netexec.go @@ -106,12 +106,14 @@ will be upgraded to HTTPS. The image has default, "localhost"-based cert/privkey If "--http-override" is set, the HTTP(S) server will always serve the override path & options, ignoring the request URL. -It will also start a UDP server on the indicated UDP port that responds to the following commands: +It will also start a UDP server on the indicated UDP port and addresses that responds to the following commands: - "hostname": Returns the server's hostname - "echo ": Returns the given - "clientip": Returns the request's IP address +The UDP server can be disabled by setting --udp-port to -1. + Additionally, if (and only if) --sctp-port is passed, it will start an SCTP server on that port, responding to the same commands as the UDP server. `, @@ -168,14 +170,19 @@ func main(cmd *cobra.Command, args []string) { addRoutes(http.DefaultServeMux, exitCh) } - udpBindTo, err := parseAddresses(udpListenAddresses) - if err != nil { - log.Fatal(err) + // UDP server + if udpPort != -1 { + udpBindTo, err := parseAddresses(udpListenAddresses) + if err != nil { + log.Fatal(err) + } + + for _, address := range udpBindTo { + go startUDPServer(address, udpPort) + } } - for _, address := range udpBindTo { - go startUDPServer(address, udpPort) - } + // SCTP server if sctpPort != -1 { go startSCTPServer(sctpPort) }