Bug #25939 Allow to specify source bind address for client (and replication slave)
Submitted: 30 Jan 2007 11:40 Modified: 29 Mar 2011 12:55
Reporter: Domas Mituzas Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Replication Severity:S4 (Feature request)
Version:any OS:Any
Assigned to: Magnus Blåudd CPU Architecture:Any

[30 Jan 2007 11:40] Domas Mituzas
Description:
mysql command line client does not allow to bind a source ip for it's client connections.
same issue is with mysqld replication connections - they all come from default source ip, instead of specified bind-address. 

How to repeat:
-

Suggested fix:
-
[30 Jan 2007 11:42] Domas Mituzas
WL#3126 WL#3127
[18 May 2007 10:15] Bernd Ocklin
The following function bound_connect() included in client.c will fix the problem in 5.1. It uses the command line bind-address parameter which is never for anything anyway.

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <netdb.h>

/*
 * Connect.
 */
int bound_connect(int                     fd,
            const struct sockaddr   *serv_addr,
            socklen_t               serv_addr_size)
{
    socklen_t               addr_size;
    union
    {
        struct  sockaddr        sa;
        struct  sockaddr_in     sin;
    }                           addr = { };
    struct sockaddr_in      *sin = (struct sockaddr_in *)serv_addr;
    int                     ret = 0;
    
   
    /* Get sockname */
    addr_size = sizeof(addr);
    ret = getsockname(fd, &addr.sa, &addr_size);

    if (!ret)
    {
        /* hope it is not already bound */
        if ((addr.sin.sin_family == AF_INET) && (my_bind_addr_str != NULL))
  {
    ret = inet_pton(AF_INET,
                       my_bind_addr_str,
                       &addr.sin.sin_addr);
  }
        if((ret > 0) &&
            (sin != NULL) &&
            (serv_addr_size >= sizeof(*sin)) &&
            (sin->sin_family == AF_INET))
        {
            ret = bind(fd, &addr.sa, sizeof(addr.sin));
            
            if (ret)
            {
                return (-1);
            }
        }
    }

    return (connect(fd, serv_addr, serv_addr_size));
}
[18 May 2007 10:22] Bernd Ocklin
Forgot to mention that it should replace connect() functions in my_connect().
[5 Sep 2007 0:59] Stewart Smith
I have updated all the test results (again) due to merges into the telco tree and am about ready (as in hopefully today) to send off the patch series for final review.

I'm now convinced that the best thing to do to somebody you don't like is to make them add a column to SHOW SLAVE STATUS and then fix the test case results.
[12 Oct 2007 5:31] Stewart Smith
pushed into telco-6.3
[22 Oct 2007 13:41] Jon Stephens
Bugfix documented in mysql-5.1.22-ndb-6.3.4 changelog.

Syntax additions for executable startup and CHANGE MASTER statement documented in 5.1/5.2 Manual.
[22 Oct 2007 14:19] Domas Mituzas
When is it going to be added to mainstream versions?
[13 May 2008 12:44] Domas Mituzas
It is WL#3127 - and is scheduled to be merged into 6.0.
[13 May 2008 12:45] Domas Mituzas
Patches are at: 
http://mysql.bkbits.net:8080/mysql-5.1-telco/?PAGE=search&EXPR=WL3127&SEARCH=ChangeSet+com...
[5 Aug 2010 20:57] Hartmut Holzgraefe
Hi Magnus, Lars,

any news as of when we'll finally see this in a main line releases?
[12 Aug 2010 7:43] Magnus Blåudd
Part 1 for MySQL C API and the mysql* clients is ready but need testcase. Part 2 for allowing the replication slave to define which bind_address to use when connecting to master is in progress.
[25 Oct 2010 8:21] Magnus Blåudd
Support for bind-address has been added to MySQL C API and mysql* clients in next-mr
[29 Nov 2010 17:04] Luis Soares
Support for bind-address has been added to MySQL C API and mysql* clients.
Replication slave supports it as well. For details check WL#3126 and WL#3127.
[29 Nov 2010 17:47] Luis Soares
The patch is actually queued in development trees. Moving from
Documenting to patch-queued.
[27 Feb 2011 14:14] MySQL Verification Team
see bug #60216
[29 Mar 2011 12:55] Jon Stephens
Already documented as supported in 5.6.1+.

Closed.
[26 Apr 2011 6:33] MySQL Verification Team
http://dev.mysql.com/doc/refman/5.6/en/mysql-command-options.html

"--bind-address=ip_address

On a computer having multiple network interfaces, this option can be used to select which interface is employed when connecting to the MySQL server.

This option is supported beginning with MySQL 5.6.1. 
"