Skip to content

Commit 0a1837e

Browse files
committed
Bug#36005872 mtr.pl support for binding all ports to localhost
Add support to mtr.pl for binding ports of all started processes to localhost. This makes it possible to avoid annoying popups from firewall. Add new command line argument --bind-local which will configure all started processes (ie. mysqlds and ndb_mgmds) to use --bind- address=localhost and --mysqlx-bind-adress=localhost. Add support for using environment variable MTR_BIND_LOCAL=1 to enable. Make it possible to disable using --no-bind-local. NOTE! Running with --bind-local turned on might still show popups for programs which are not bound to localhost, in addition some tests which check that a certain port is bound to listen on any interface might fail. Example usage: $> mtr.pl alias # Shows popup $> mtr.pl alias --bind-local # Binds to localhost and avoid popup $> MTR_BIND_LOCAL=1 mtr.pl alias # Binds to localhost and avoid popup $> MTR_BIND_LOCAL=1 mtr.pl alias --no-bind-local # Shows popup Change-Id: Ia202ab463f08cdf011921c6b1d5f3f0ebb85d722
1 parent 310704b commit 0a1837e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

mysql-test/lib/My/ConfigFactory.pm

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,15 @@ sub fix_rsa_public_key {
292292
return "$std_data/rsa_public_key.pem";
293293
}
294294

295+
sub fix_bind_address {
296+
my ($self) = @_;
297+
if ($self->{ARGS}->{bind_local}) {
298+
# Listen only for incoming network connections from local machine
299+
return "localhost";
300+
}
301+
return undef;
302+
}
303+
295304
# Rules to run for each mysqld in the config
296305
# - some rules depend on each other and thus need to be run
297306
# in the order listed here
@@ -308,9 +317,11 @@ my @mysqld_rules = (
308317
{ 'datadir' => \&fix_datadir },
309318
{ 'port' => \&fix_port },
310319
{ 'admin-port' => \&fix_admin_port },
320+
{ 'bind-address' => \&fix_bind_address },
311321
{ 'general_log' => \&fix_general_log },
312322
{ 'general_log_file' => \&fix_log },
313323
{ 'loose-mysqlx-port' => \&fix_x_port },
324+
{ 'loose-mysqlx-bind-address' => \&fix_bind_address },
314325
{ 'loose-mysqlx-socket' => \&fix_x_socket },
315326
{ 'loose-mysqlx-ssl' => \&fix_ssl_disabled },
316327
{ 'loose-mysqlx-ssl-ca' => "" },
@@ -758,7 +769,9 @@ sub new_config {
758769
@ndb_mgmd_rules);
759770

760771
$self->run_section_rules($config, 'ndb_mgmd.',
761-
({ 'cluster-config-suffix' => \&fix_cluster_config_suffix },));
772+
({ 'cluster-config-suffix' => \&fix_cluster_config_suffix },
773+
{ 'bind-address' => \&fix_bind_address },
774+
));
762775

763776
$self->run_section_rules($config, 'cluster_config.ndbd', @ndbd_rules);
764777

mysql-test/mysql-test-run.pl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
my $opt_mysqlx_baseport = $ENV{'MYSQLXPLUGIN_PORT'} || "auto";
147147
my $opt_port_base = $ENV{'MTR_PORT_BASE'} || "auto";
148148
my $opt_port_exclude = $ENV{'MTR_PORT_EXCLUDE'} || "none";
149+
my $opt_bind_local = $ENV{'MTR_BIND_LOCAL'};
149150
my $opt_reorder = 1;
150151
my $opt_retry = 3;
151152
my $opt_retry_failure = env_or_val(MTR_RETRY_FAILURE => 2);
@@ -1664,6 +1665,7 @@ sub command_line_setup {
16641665
'mysqlx-port=i' => \$opt_mysqlx_baseport,
16651666
'port-base|mtr-port-base=i' => \$opt_port_base,
16661667
'port-exclude|mtr-port-exclude=s' => \$opt_port_exclude,
1668+
'bind-local!' => \$opt_bind_local,
16671669

16681670
# Test case authoring
16691671
'check-testcases!' => \$opt_check_testcases,
@@ -4180,6 +4182,7 @@ sub default_mysqld {
41804182
baseport => 0,
41814183
user => $opt_user,
41824184
password => '',
4185+
bind_local => $opt_bind_local
41834186
});
41844187

41854188
my $mysqld = $config->group('mysqld.1') or
@@ -4975,6 +4978,7 @@ ($)
49754978
tmpdir => $opt_tmpdir,
49764979
user => $opt_user,
49774980
vardir => $opt_vardir,
4981+
bind_local => $opt_bind_local
49784982
});
49794983

49804984
# Write the new my.cnf
@@ -7904,6 +7908,11 @@ ($)
79047908
and is not "auto", it overrides build-thread.
79057909
port-exclude=#-# Specify the range of ports to exclude when searching
79067910
for available port ranges to use.
7911+
bind-local Bind listening ports to localhost, i.e disallow
7912+
"incoming network connections" which might cause
7913+
firewall to display annoying popups.
7914+
Can be set in environment variable MTR_BIND_LOCAL=1.
7915+
To disable use --no-bind-local.
79077916
79087917
Options for test case authoring
79097918

0 commit comments

Comments
 (0)