summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2014-08-03 21:43:59 +0200
committerSergei Golubchik <sergii@pisem.net>2014-08-03 21:43:59 +0200
commitef2bf1870622b5167066ea95e7824631d93bbf3f (patch)
tree6134459026102b8a427729c518edfb13b111bdf7
parent6145e167f3e50f266d0f70ecab148898afabf651 (diff)
downloadmariadb-git-ef2bf1870622b5167066ea95e7824631d93bbf3f.tar.gz
MDEV-4379 expand MariaDB dual-stack support
when binding to wildcard addresses (no --bind is specified or --bind=*), bind to both ipv6 and ipv4 as mysql-5.6 is doing.
-rw-r--r--mysql-test/r/ipv4_and_ipv6.result87
-rw-r--r--mysql-test/t/ipv4_and_ipv6.opt1
-rw-r--r--mysql-test/t/ipv4_and_ipv6.test18
-rw-r--r--sql/mysqld.cc15
4 files changed, 121 insertions, 0 deletions
diff --git a/mysql-test/r/ipv4_and_ipv6.result b/mysql-test/r/ipv4_and_ipv6.result
new file mode 100644
index 00000000000..96a70b71717
--- /dev/null
+++ b/mysql-test/r/ipv4_and_ipv6.result
@@ -0,0 +1,87 @@
+=============Test of '::1' ========================================
+mysqld is alive
+CREATE USER testuser@'::1' identified by '1234';
+GRANT ALL ON test.* TO testuser@'::1';
+SHOW GRANTS FOR testuser@'::1';
+Grants for testuser@::1
+GRANT USAGE ON *.* TO 'testuser'@'::1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF'
+GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'::1'
+SET @nip= inet_aton('::1');
+SELECT @nip;
+@nip
+NULL
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+NULL
+SELECT USER();
+USER()
+root@localhost
+SELECT current_user();
+current_user()
+root@localhost
+SHOW PROCESSLIST;
+REVOKE ALL ON test.* FROM testuser@'::1';
+RENAME USER testuser@'::1' to testuser1@'::1';
+SET PASSWORD FOR testuser1@'::1' = PASSWORD ('9876');
+SELECT USER();
+USER()
+root@localhost
+DROP USER testuser1@'::1';
+=============Test of '127.0.0.1' (IPv4) ===========================
+mysqld is alive
+CREATE USER testuser@'127.0.0.1' identified by '1234';
+GRANT ALL ON test.* TO testuser@'127.0.0.1';
+SHOW GRANTS FOR testuser@'127.0.0.1';
+Grants for testuser@127.0.0.1
+GRANT USAGE ON *.* TO 'testuser'@'127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF'
+GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'127.0.0.1'
+SET @nip= inet_aton('127.0.0.1');
+SELECT @nip;
+@nip
+2130706433
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+127.0.0.1
+SELECT USER();
+USER()
+root@localhost
+SELECT current_user();
+current_user()
+root@localhost
+SHOW PROCESSLIST;
+REVOKE ALL ON test.* FROM testuser@'127.0.0.1';
+RENAME USER testuser@'127.0.0.1' to testuser1@'127.0.0.1';
+SET PASSWORD FOR testuser1@'127.0.0.1' = PASSWORD ('9876');
+SELECT USER();
+USER()
+root@localhost
+DROP USER testuser1@'127.0.0.1';
+=============Test of '0:0:0:0:0:FFFF:127.0.0.1' ===================
+mysqld is alive
+CREATE USER testuser@'0:0:0:0:0:FFFF:127.0.0.1' identified by '1234';
+GRANT ALL ON test.* TO testuser@'0:0:0:0:0:FFFF:127.0.0.1';
+SHOW GRANTS FOR testuser@'0:0:0:0:0:FFFF:127.0.0.1';
+Grants for testuser@0:0:0:0:0:ffff:127.0.0.1
+GRANT USAGE ON *.* TO 'testuser'@'0:0:0:0:0:ffff:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF'
+GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0:0:0:0:0:ffff:127.0.0.1'
+SET @nip= inet_aton('0:0:0:0:0:FFFF:127.0.0.1');
+SELECT @nip;
+@nip
+NULL
+SELECT inet_ntoa(@nip);
+inet_ntoa(@nip)
+NULL
+SELECT USER();
+USER()
+root@localhost
+SELECT current_user();
+current_user()
+root@localhost
+SHOW PROCESSLIST;
+REVOKE ALL ON test.* FROM testuser@'0:0:0:0:0:FFFF:127.0.0.1';
+RENAME USER testuser@'0:0:0:0:0:FFFF:127.0.0.1' to testuser1@'0:0:0:0:0:FFFF:127.0.0.1';
+SET PASSWORD FOR testuser1@'0:0:0:0:0:FFFF:127.0.0.1' = PASSWORD ('9876');
+SELECT USER();
+USER()
+root@localhost
+DROP USER testuser1@'0:0:0:0:0:FFFF:127.0.0.1';
diff --git a/mysql-test/t/ipv4_and_ipv6.opt b/mysql-test/t/ipv4_and_ipv6.opt
new file mode 100644
index 00000000000..a22a7b100c8
--- /dev/null
+++ b/mysql-test/t/ipv4_and_ipv6.opt
@@ -0,0 +1 @@
+--skip-name-resolve --bind-address=*
diff --git a/mysql-test/t/ipv4_and_ipv6.test b/mysql-test/t/ipv4_and_ipv6.test
new file mode 100644
index 00000000000..d52945f17fa
--- /dev/null
+++ b/mysql-test/t/ipv4_and_ipv6.test
@@ -0,0 +1,18 @@
+--source include/check_ipv6.inc
+--source include/not_embedded.inc
+
+echo =============Test of '::1' ========================================;
+let $IPv6= ::1;
+--source include/ipv6_clients.inc
+--source include/ipv6.inc
+
+echo =============Test of '127.0.0.1' (IPv4) ===========================;
+let $IPv6= 127.0.0.1;
+--source include/ipv6_clients.inc
+--source include/ipv6.inc
+
+echo =============Test of '0:0:0:0:0:FFFF:127.0.0.1' ===================;
+let $IPv6= 0:0:0:0:0:FFFF:127.0.0.1;
+--source include/ipv6_clients.inc
+--source include/ipv6.inc
+
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index df60d742cdc..3b1af44d898 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -2384,6 +2384,21 @@ static MYSQL_SOCKET activate_tcp_port(uint port)
unireg_abort(1); /* purecov: tested */
}
+ /*
+ special case: for wildcard addresses prefer ipv6 over ipv4,
+ because we later switch off IPV6_V6ONLY, so ipv6 wildcard
+ addresses will work for ipv4 too
+ */
+ if ((my_bind_addr_str == NULL || strcmp(my_bind_addr_str, "*") == 0)
+ && ai->ai_family == AF_INET && ai->ai_next
+ && ai->ai_next->ai_family == AF_INET6)
+ {
+ a= ai;
+ ai= ai->ai_next;
+ a->ai_next= ai->ai_next;
+ ai->ai_next= a;
+ }
+
for (a= ai; a != NULL; a= a->ai_next)
{
ip_sock= mysql_socket_socket(key_socket_tcpip, a->ai_family,