my $CLIENTIP="127.0.0.1"; # address which curl uses for incoming connections
my $CLIENT6IP="[::1]"; # address which curl uses for incoming connections
-my $noport="[not running]";
-
-my $NOLISTENPORT=47; # port number we use for a local non-listening service
-my $MQTTPORT=$noport; # MQTT server port
-my $HTTPPORT=$noport; # HTTP server port
-my $HTTP6PORT=$noport; # HTTP IPv6 server port
-my $HTTPSPORT=$noport; # HTTPS (stunnel) server port
-my $HTTPSPROXYPORT = $noport; # HTTPS-proxy (stunnel) port
-my $FTPPORT=$noport; # FTP server port
-my $FTPSPORT=$noport; # FTPS (stunnel) server port
-my $FTP6PORT=$noport; # FTP IPv6 server port
-my $TFTPPORT=$noport; # TFTP
-my $TFTP6PORT=$noport; # TFTP
-my $SSHPORT=$noport; # SCP/SFTP
-my $SOCKSPORT=$noport; # SOCKS4/5 port
-my $POP3PORT=$noport; # POP3
-my $POP36PORT=$noport; # POP3 IPv6 server port
-my $IMAPPORT=$noport; # IMAP
-my $IMAP6PORT=$noport; # IMAP IPv6 server port
-my $SMTPPORT=$noport; # SMTP
-my $SMTP6PORT=$noport; # SMTP IPv6 server port
-my $RTSPPORT=$noport; # RTSP
-my $RTSP6PORT=$noport; # RTSP IPv6 server port
-my $GOPHERPORT=$noport; # Gopher
-my $GOPHERSPORT=$noport; # Gophers
-my $GOPHER6PORT=$noport; # Gopher IPv6 server port
-my $HTTPTLSPORT=$noport; # HTTP TLS (non-stunnel) server port
-my $HTTPTLS6PORT=$noport; # HTTP TLS (non-stunnel) IPv6 server port
-my $HTTPPROXYPORT=$noport; # HTTP proxy port, when using CONNECT
-my $HTTP2PORT=$noport; # HTTP/2 no-tls server port
-my $HTTP2TLSPORT=$noport; # HTTP/2 tls server port
-my $HTTP3PORT=$noport; # HTTP/3 server port
-my $DICTPORT=$noport; # DICT server port
-my $SMBPORT=$noport; # SMB server port
-my $SMBSPORT=$noport; # SMBS server port
-my $TELNETPORT=$noport; # TELNET server port with negotiation
+my %PORT = (nolisten => 47); # port we use for a local non-listening service
my $HTTPUNIXPATH; # HTTP server Unix domain socket path
my $SOCKSUNIXPATH; # socks server Unix domain socket path
return 0;
}
+#######################################################################
+# Return the port to use for the given protocol.
+#
+sub protoport {
+ my ($proto) = @_;
+ return $PORT{$proto} || "[not running]";
+}
+
#######################################################################
# Stop a test server along with pids which aren't in the %run hash yet.
# This also stops all servers which are relative to the given one.
$flags .= "--nghttpx \"$ENV{'NGHTTPX'}\" ";
$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
- $flags .= "--connect $HOSTIP:$HTTPPORT ";
+ $flags .= "--connect $HOSTIP:" . protoport("http") . " ";
$flags .= $verbose_flag if($debugprotocol);
my ($http2pid, $pid2);
if($verbose) {
logmsg "RUN: $srvrname server PID $http2pid ".
"http-port $port https-port $port2 ".
- "backend $HOSTIP:$HTTPPORT\n";
+ "backend $HOSTIP:" . protoport("http") . "\n";
}
last;
}
$flags .= "--nghttpx \"$ENV{'NGHTTPX'}\" ";
$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
- $flags .= "--connect $HOSTIP:$HTTPPORT ";
+ $flags .= "--connect $HOSTIP:" . protoport("http") . " ";
$flags .= "--cert \"$cert\" " if($cert);
$flags .= $verbose_flag if($debugprotocol);
$flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem');
$flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" ";
if($proto eq "gophers") {
- $flags .= "--connect $GOPHERPORT";
+ $flags .= "--connect " . protoport("gopher");
}
elsif(!$proxy) {
- $flags .= "--connect $HTTPPORT";
+ $flags .= "--connect " . protoport("http");
}
else {
# for HTTPS-proxy we connect to the HTTP proxy
- $flags .= "--connect $HTTPPROXYPORT";
+ $flags .= "--connect " . protoport("httpproxy");
}
my $pid2;
logmsg "RUN: $srvrname server is PID $ftppid port $port\n" if($verbose);
# Assign the correct port variable!
- if($proto eq "ftp") {
- if($ipvnum == 6) {
- # if IPv6, use a different setup
- $FTP6PORT = $port;
- }
- else {
- $FTPPORT = $port;
- }
- }
- elsif($proto eq "pop3") {
- if($ipvnum == 6) {
- $POP36PORT = $port;
- }
- else {
- $POP3PORT = $port;
- }
- }
- elsif($proto eq "imap") {
- if($ipvnum == 6) {
- $IMAP6PORT = $port;
- }
- else {
- $IMAPPORT = $port;
- }
- }
- elsif($proto eq "smtp") {
- if($ipvnum == 6) {
- $SMTP6PORT = $port;
- }
- else {
- $SMTPPORT = $port;
- }
+ if($proto =~ /^(?:ftp|imap|pop3|smtp)$/) {
+ $PORT{$proto . ($ipvnum == 6? '6': '')} = $port;
}
else {
print STDERR "Unsupported protocol $proto!!\n";
$flags .= "--ipv$ipvnum --proto $proto ";
$flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem');
$flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" ";
- $flags .= "--connect $FTPPORT";
+ $flags .= "--connect " . $PORT{"ftp"};
my $ftpspid;
my $pid2;
sub runmqttserver {
my ($id, $verbose, $ipv6) = @_;
my $ip=$HOSTIP;
- my $port = $MQTTPORT;
my $proto = 'mqtt';
+ my $port = protoport($proto);
my $ipvnum = 4;
my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
my $server;
return (0,0);
}
- $MQTTPORT = pidfromfile($portfile);
+ my $mqttport = pidfromfile($portfile);
+ $PORT{"mqtt"} = $mqttport;
if($verbose) {
- logmsg "RUN: $srvrname server is now running PID $pid2 on PORT $MQTTPORT\n";
+ logmsg "RUN: $srvrname server is now running PID $pid2 on PORT $mqttport\n";
}
return ($pid2, $sockspid);
my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
+ my $protoip = $proto . ($ipvnum == 6? '6': '');
- if($proto eq "ftp") {
- $port = $FTPPORT;
-
- if($ipvnum==6) {
- # if IPv6, use a different setup
- $port = $FTP6PORT;
- }
- }
- elsif($proto eq "pop3") {
- $port = ($ipvnum==6) ? $POP36PORT : $POP3PORT;
- }
- elsif($proto eq "imap") {
- $port = ($ipvnum==6) ? $IMAP6PORT : $IMAPPORT;
- }
- elsif($proto eq "smtp") {
- $port = ($ipvnum==6) ? $SMTP6PORT : $SMTPPORT;
+ if($proto =~ /^(?:ftp|imap|pop3|smtp)$/) {
+ $port = protoport($protoip);
}
else {
print STDERR "Unsupported protocol $proto!!\n";
#
sub responsive_rtsp_server {
my ($verbose, $ipv6) = @_;
- my $port = $RTSPPORT;
- my $ip = $HOSTIP;
my $proto = 'rtsp';
+ my $port = protoport($proto);
+ my $ip = $HOSTIP;
my $ipvnum = 4;
my $idnum = 1;
if($ipv6) {
# if IPv6, use a different setup
$ipvnum = 6;
- $port = $RTSP6PORT;
+ $port = protoport('rtsp6');
$ip = $HOST6IP;
}
#
sub responsive_tftp_server {
my ($id, $verbose, $ipv6) = @_;
- my $port = $TFTPPORT;
- my $ip = $HOSTIP;
my $proto = 'tftp';
+ my $port = protoport($proto);
+ my $ip = $HOSTIP;
my $ipvnum = 4;
my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
if($ipv6) {
# if IPv6, use a different setup
$ipvnum = 6;
- $port = $TFTP6PORT;
+ $port = protoport('tftp6');
$ip = $HOST6IP;
}
#
sub responsive_httptls_server {
my ($verbose, $ipv6) = @_;
- my $proto = "httptls";
- my $port = ($ipv6 && ($ipv6 =~ /6$/)) ? $HTTPTLS6PORT : $HTTPTLSPORT;
- my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
+ my $proto = "httptls";
+ my $port = protoport($proto);
+ my $ip = "$HOSTIP";
my $idnum = 1;
+ if ($ipvnum == 6) {
+ $port = protoport("httptls6");
+ $ip = "$HOST6IP";
+ }
+
return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
}
#
sub subVariables {
my ($thing, $testnum, $prefix) = @_;
+ my $port;
if(!$prefix) {
$prefix = "%";
}
# test server ports
- $$thing =~ s/${prefix}FTP6PORT/$FTP6PORT/g;
- $$thing =~ s/${prefix}FTPSPORT/$FTPSPORT/g;
- $$thing =~ s/${prefix}FTPPORT/$FTPPORT/g;
- $$thing =~ s/${prefix}GOPHER6PORT/$GOPHER6PORT/g;
- $$thing =~ s/${prefix}GOPHERPORT/$GOPHERPORT/g;
- $$thing =~ s/${prefix}GOPHERSPORT/$GOPHERSPORT/g;
- $$thing =~ s/${prefix}HTTPTLS6PORT/$HTTPTLS6PORT/g;
- $$thing =~ s/${prefix}HTTPTLSPORT/$HTTPTLSPORT/g;
- $$thing =~ s/${prefix}HTTP6PORT/$HTTP6PORT/g;
- $$thing =~ s/${prefix}HTTPSPORT/$HTTPSPORT/g;
- $$thing =~ s/${prefix}HTTPSPROXYPORT/$HTTPSPROXYPORT/g;
- $$thing =~ s/${prefix}HTTP2PORT/$HTTP2PORT/g;
- $$thing =~ s/${prefix}HTTP2TLSPORT/$HTTP2TLSPORT/g;
- $$thing =~ s/${prefix}HTTP3PORT/$HTTP3PORT/g;
- $$thing =~ s/${prefix}HTTPPORT/$HTTPPORT/g;
- $$thing =~ s/${prefix}PROXYPORT/$HTTPPROXYPORT/g;
- $$thing =~ s/${prefix}MQTTPORT/$MQTTPORT/g;
- $$thing =~ s/${prefix}IMAP6PORT/$IMAP6PORT/g;
- $$thing =~ s/${prefix}IMAPPORT/$IMAPPORT/g;
- $$thing =~ s/${prefix}POP36PORT/$POP36PORT/g;
- $$thing =~ s/${prefix}POP3PORT/$POP3PORT/g;
- $$thing =~ s/${prefix}RTSP6PORT/$RTSP6PORT/g;
- $$thing =~ s/${prefix}RTSPPORT/$RTSPPORT/g;
- $$thing =~ s/${prefix}SMTP6PORT/$SMTP6PORT/g;
- $$thing =~ s/${prefix}SMTPPORT/$SMTPPORT/g;
- $$thing =~ s/${prefix}SOCKSPORT/$SOCKSPORT/g;
- $$thing =~ s/${prefix}SSHPORT/$SSHPORT/g;
- $$thing =~ s/${prefix}TFTP6PORT/$TFTP6PORT/g;
- $$thing =~ s/${prefix}TFTPPORT/$TFTPPORT/g;
- $$thing =~ s/${prefix}DICTPORT/$DICTPORT/g;
- $$thing =~ s/${prefix}SMBPORT/$SMBPORT/g;
- $$thing =~ s/${prefix}SMBSPORT/$SMBSPORT/g;
- $$thing =~ s/${prefix}TELNETPORT/$TELNETPORT/g;
- $$thing =~ s/${prefix}NOLISTENPORT/$NOLISTENPORT/g;
+ foreach my $proto ('DICT',
+ 'FTP', 'FTP6', 'FTPS',
+ 'GOPHER', 'GOPHER6', 'GOPHERS',
+ 'HTTP', 'HTTP6', 'HTTPS',
+ 'HTTPSPROXY', 'HTTPTLS', 'HTTPTLS6',
+ 'HTTP2', 'HTTP2TLS',
+ 'HTTP3',
+ 'IMAP', 'IMAP6', 'IMAPS',
+ 'MQTT',
+ 'NOLISTEN',
+ 'POP3', 'POP36', 'POP3S',
+ 'RTSP', 'RTSP6',
+ 'SMB', 'SMBS',
+ 'SMTP', 'SMTP6', 'SMTPS',
+ 'SOCKS',
+ 'SSH',
+ 'TELNET',
+ 'TFTP', 'TFTP6') {
+ $port = protoport(lc $proto);
+ $$thing =~ s/${prefix}(?:$proto)PORT/$port/g;
+ }
+ # Special case: for PROXYPORT substitution, use httpproxy.
+ $port = protoport('httpproxy');
+ $$thing =~ s/${prefix}PROXYPORT/$port/g;
# server Unix domain socket paths
$$thing =~ s/${prefix}HTTPUNIXPATH/$HTTPUNIXPATH/g;
}
elsif($what eq "gopher") {
if($torture && $run{'gopher'} &&
- !responsive_http_server("gopher", $verbose, 0, $GOPHERPORT)) {
+ !responsive_http_server("gopher", $verbose, 0,
+ protoport("gopher"))) {
if(stopserver('gopher')) {
return "failed stopping unresponsive GOPHER server";
}
}
if(!$run{'gopher'}) {
- ($pid, $pid2, $GOPHERPORT) =
+ ($pid, $pid2, $PORT{'gopher'}) =
runhttpserver("gopher", $verbose, 0);
if($pid <= 0) {
return "failed starting GOPHER server";
elsif($what eq "gopher-ipv6") {
if($torture && $run{'gopher-ipv6'} &&
!responsive_http_server("gopher", $verbose, "ipv6",
- $GOPHER6PORT)) {
+ protoport("gopher"))) {
if(stopserver('gopher-ipv6')) {
return "failed stopping unresponsive GOPHER-IPv6 server";
}
}
if(!$run{'gopher-ipv6'}) {
- ($pid, $pid2, $GOPHER6PORT) =
+ ($pid, $pid2, $PORT{"gopher6"}) =
runhttpserver("gopher", $verbose, "ipv6");
if($pid <= 0) {
return "failed starting GOPHER-IPv6 server";
}
elsif($what eq "http/3") {
if(!$run{'http/3'}) {
- ($pid, $pid2, $HTTP3PORT) = runhttp3server($verbose);
+ ($pid, $pid2, $PORT{"http3"}) = runhttp3server($verbose);
if($pid <= 0) {
return "failed starting HTTP/3 server";
}
}
elsif($what eq "http/2") {
if(!$run{'http/2'}) {
- ($pid, $pid2, $HTTP2PORT, $HTTP2TLSPORT) =
+ ($pid, $pid2, $PORT{"http2"}, $PORT{"http2tls"}) =
runhttp2server($verbose);
if($pid <= 0) {
return "failed starting HTTP/2 server";
}
elsif($what eq "http") {
if($torture && $run{'http'} &&
- !responsive_http_server("http", $verbose, 0, $HTTPPORT)) {
+ !responsive_http_server("http", $verbose, 0, protoport('http'))) {
if(stopserver('http')) {
return "failed stopping unresponsive HTTP server";
}
}
if(!$run{'http'}) {
- ($pid, $pid2, $HTTPPORT) =
+ ($pid, $pid2, $PORT{'http'}) =
runhttpserver("http", $verbose, 0);
if($pid <= 0) {
return "failed starting HTTP server";
elsif($what eq "http-proxy") {
if($torture && $run{'http-proxy'} &&
!responsive_http_server("http", $verbose, "proxy",
- $HTTPPROXYPORT)) {
+ protoport("httpproxy"))) {
if(stopserver('http-proxy')) {
return "failed stopping unresponsive HTTP-proxy server";
}
}
if(!$run{'http-proxy'}) {
- ($pid, $pid2, $HTTPPROXYPORT) =
+ ($pid, $pid2, $PORT{"httpproxy"}) =
runhttpserver("http", $verbose, "proxy");
if($pid <= 0) {
return "failed starting HTTP-proxy server";
}
elsif($what eq "http-ipv6") {
if($torture && $run{'http-ipv6'} &&
- !responsive_http_server("http", $verbose, "ipv6", $HTTP6PORT)) {
+ !responsive_http_server("http", $verbose, "ipv6",
+ protoport("http6"))) {
if(stopserver('http-ipv6')) {
return "failed stopping unresponsive HTTP-IPv6 server";
}
}
if(!$run{'http-ipv6'}) {
- ($pid, $pid2, $HTTP6PORT) =
+ ($pid, $pid2, $PORT{"http6"}) =
runhttpserver("http", $verbose, "ipv6");
if($pid <= 0) {
return "failed starting HTTP-IPv6 server";
}
}
if(!$run{'rtsp'}) {
- ($pid, $pid2, $RTSPPORT) = runrtspserver($verbose);
+ ($pid, $pid2, $PORT{'rtsp'}) = runrtspserver($verbose);
if($pid <= 0) {
return "failed starting RTSP server";
}
}
}
if(!$run{'rtsp-ipv6'}) {
- ($pid, $pid2, $RTSP6PORT) = runrtspserver($verbose, "ipv6");
+ ($pid, $pid2, $PORT{'rtsp6'}) = runrtspserver($verbose, "ipv6");
if($pid <= 0) {
return "failed starting RTSP-IPv6 server";
}
$run{'ftp'}="$pid $pid2";
}
if(!$run{'ftps'}) {
- ($pid, $pid2, $FTPSPORT) =
+ ($pid, $pid2, $PORT{'ftps'}) =
runftpsserver($verbose, "", $certfile);
if($pid <= 0) {
return "failed starting FTPS server (stunnel)";
}
}
if($torture && $run{'http'} &&
- !responsive_http_server("http", $verbose, 0, $HTTPPORT)) {
+ !responsive_http_server("http", $verbose, 0,
+ protoport('http'))) {
if(stopserver('http')) {
return "failed stopping unresponsive HTTP server";
}
}
if(!$run{'http'}) {
- ($pid, $pid2, $HTTPPORT) =
+ ($pid, $pid2, $PORT{'http'}) =
runhttpserver("http", $verbose, 0);
if($pid <= 0) {
return "failed starting HTTP server";
$run{'http'}="$pid $pid2";
}
if(!$run{'https'}) {
- ($pid, $pid2, $HTTPSPORT) =
+ ($pid, $pid2, $PORT{'https'}) =
runhttpsserver($verbose, "https", "", $certfile);
if($pid <= 0) {
return "failed starting HTTPS server (stunnel)";
}
}
if($torture && $run{'gopher'} &&
- !responsive_http_server("gopher", $verbose, 0, $GOPHERPORT)) {
+ !responsive_http_server("gopher", $verbose, 0,
+ protoport('gopher'))) {
if(stopserver('gopher')) {
return "failed stopping unresponsive GOPHER server";
}
}
if(!$run{'gopher'}) {
- ($pid, $pid2, $GOPHERPORT) =
+ my $port;
+ ($pid, $pid2, $port) =
runhttpserver("gopher", $verbose, 0);
+ $PORT{'gopher'} = $port;
if($pid <= 0) {
return "failed starting GOPHER server";
}
printf ("* pid gopher => %d %d\n", $pid, $pid2) if($verbose);
- print "GOPHERPORT => $GOPHERPORT\n" if($verbose);
+ print "GOPHERPORT => $port\n" if($verbose);
$run{'gopher'}="$pid $pid2";
}
if(!$run{'gophers'}) {
- ($pid, $pid2, $GOPHERSPORT) =
+ my $port;
+ ($pid, $pid2, $port) =
runhttpsserver($verbose, "gophers", "", $certfile);
+ $PORT{'gophers'} = $port;
if($pid <= 0) {
return "failed starting GOPHERS server (stunnel)";
}
logmsg sprintf("* pid gophers => %d %d\n", $pid, $pid2)
if($verbose);
- print "GOPHERSPORT => $GOPHERSPORT\n" if($verbose);
+ print "GOPHERSPORT => $port\n" if($verbose);
$run{'gophers'}="$pid $pid2";
}
}
}
if(!$run{'https-proxy'}) {
- ($pid, $pid2, $HTTPSPROXYPORT) =
+ ($pid, $pid2, $PORT{"httpsproxy"}) =
runhttpsserver($verbose, "https", "proxy", $certfile);
if($pid <= 0) {
return "failed starting HTTPS-proxy (stunnel)";
}
}
if(!$run{'httptls'}) {
- ($pid, $pid2, $HTTPTLSPORT) =
+ ($pid, $pid2, $PORT{'httptls'}) =
runhttptlsserver($verbose, "IPv4");
if($pid <= 0) {
return "failed starting HTTPTLS server (gnutls-serv)";
}
}
if(!$run{'httptls-ipv6'}) {
- ($pid, $pid2, $HTTPTLS6PORT) =
+ ($pid, $pid2, $PORT{"httptls6"}) =
runhttptlsserver($verbose, "ipv6");
if($pid <= 0) {
return "failed starting HTTPTLS-IPv6 server (gnutls-serv)";
}
}
if(!$run{'tftp'}) {
- ($pid, $pid2, $TFTPPORT) =
+ ($pid, $pid2, $PORT{'tftp'}) =
runtftpserver("", $verbose);
if($pid <= 0) {
return "failed starting TFTP server";
}
}
if(!$run{'tftp-ipv6'}) {
- ($pid, $pid2, $TFTP6PORT) =
+ ($pid, $pid2, $PORT{'tftp6'}) =
runtftpserver("", $verbose, "ipv6");
if($pid <= 0) {
return "failed starting TFTP-IPv6 server";
}
elsif($what eq "sftp" || $what eq "scp") {
if(!$run{'ssh'}) {
- ($pid, $pid2, $SSHPORT) = runsshserver("", $verbose);
+ ($pid, $pid2, $PORT{'ssh'}) = runsshserver("", $verbose);
if($pid <= 0) {
return "failed starting SSH server";
}
}
elsif($what eq "socks4" || $what eq "socks5" ) {
if(!$run{'socks'}) {
- ($pid, $pid2, $SOCKSPORT) = runsocksserver("", $verbose);
+ ($pid, $pid2, $PORT{"socks"}) = runsocksserver("", $verbose);
if($pid <= 0) {
return "failed starting socks server";
}
}
elsif($what eq "dict") {
if(!$run{'dict'}) {
- ($pid, $pid2, $DICTPORT) = rundictserver($verbose, "");
+ ($pid, $pid2, $PORT{"dict"}) = rundictserver($verbose, "");
if($pid <= 0) {
return "failed starting DICT server";
}
}
elsif($what eq "smb") {
if(!$run{'smb'}) {
- ($pid, $pid2, $SMBPORT) = runsmbserver($verbose, "");
+ ($pid, $pid2, $PORT{"smb"}) = runsmbserver($verbose, "");
if($pid <= 0) {
return "failed starting SMB server";
}
}
elsif($what eq "telnet") {
if(!$run{'telnet'}) {
- ($pid, $pid2, $TELNETPORT) =
+ ($pid, $pid2, $PORT{"telnet"}) =
runnegtelnetserver($verbose, "");
if($pid <= 0) {
return "failed starting neg TELNET server";