Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

[patch 2/6] WL3126 TCP address binding for mysql client library

From: <stewart(at)mysql.com>
Date: Fri Jun 01 2007 - 04:27:53 EDT


Allow binding of client to address

  • client/client_priv.h 1.51 vs edited ===== Index: telco-new/client/client_priv.h
    • telco-new.orig/client/client_priv.h 2007-05-31 20:32:13.466181500 +1000 +++ telco-new/client/client_priv.h 2007-05-31 20:32:21.334673250 +1000
      @@ -74,6 +74,7 @@ enum options_client
      OPT_SLAP_PRE_QUERY, OPT_SLAP_POST_QUERY, OPT_MYSQL_REPLACE_INTO, OPT_BASE64_OUTPUT, OPT_SERVER_ID, + OPT_BIND_ADDRESS, OPT_FIX_TABLE_NAMES, OPT_FIX_DB_NAMES, OPT_SSL_VERIFY_SERVER_CERT, OPT_DEBUG_INFO, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE, OPT_WRITE_BINLOG, OPT_MAX_CLIENT_OPTION Index: telco-new/client/mysql.cc
    • telco-new.orig/client/mysql.cc 2007-05-31 20:32:13.474182000 +1000 +++ telco-new/client/mysql.cc 2007-05-31 20:36:03.192538500 +1000
      @@ -143,6 +143,7 @@ static my_bool column_types_flag;
      static ulong opt_max_allowed_packet, opt_net_buffer_length; static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0; static my_string opt_mysql_unix_port=0; +static char *opt_bind_addr = NULL; static int connect_flag=CLIENT_INTERACTIVE; static char *current_host,*current_db,*current_user=0,*opt_password=0, *current_prompt=0, *delimiter_str= 0,
      @@ -594,6 +595,9 @@ static struct my_option my_long_options[
      0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"batch", 'B', "Don't use history file. Disable interactive behavior. (Enables --silent)", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.", + (gptr*) &opt_bind_addr, (gptr*) &opt_bind_addr, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"character-sets-dir", OPT_CHARSETS_DIR, "Directory where character sets are.", (gptr*) &charsets_dir, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
      @@ -3238,6 +3242,10 @@ sql_real_connect(char *host,char *databa
      mysql_options(&mysql,MYSQL_OPT_CONNECT_TIMEOUT, (char*) &timeout); } + if (opt_bind_addr) + { + mysql_options(&mysql,MYSQL_OPT_BIND,opt_bind_addr); + } if (opt_compress) mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS); if (opt_secure_auth) Index: telco-new/client/mysqladmin.cc
    • telco-new.orig/client/mysqladmin.cc 2007-05-31 20:32:13.478182250 +1000 +++ telco-new/client/mysqladmin.cc 2007-05-31 20:36:17.513433500 +1000
      @@ -43,6 +43,7 @@ static my_bool option_force=0,interrupte
      tty_password= 0, info_flag= 0, opt_nobeep; static uint tcp_port = 0, option_wait = 0, option_silent=0, nr_iterations, opt_count_iterations= 0; +static char *opt_bind_addr = NULL; static ulong opt_connect_timeout, opt_shutdown_timeout; static my_string unix_port=0; #ifdef LATER_HAVE_NDBCLUSTER_DB
      @@ -130,6 +131,9 @@ static struct my_option my_long_options[
      {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif + {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.", + (gptr*) &opt_bind_addr, (gptr*) &opt_bind_addr, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"count", 'c', "Number of iterations to make. This works with -i (--sleep) only.", (gptr*) &nr_iterations, (gptr*) &nr_iterations, 0, GET_UINT,
      @@ -328,6 +332,10 @@ int main(int argc,char *argv[])
      VOID(signal(SIGINT,endprog)); /* Here if abort */ VOID(signal(SIGTERM,endprog)); /* Here if abort */
+  if (opt_bind_addr)
+  {
+       mysql_options(&mysql,MYSQL_OPT_BIND,opt_bind_addr);
+  }
   if (opt_compress)
     mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
   if (opt_connect_timeout)
Index: telco-new/client/mysqlbinlog.cc
  • telco-new.orig/client/mysqlbinlog.cc 2007-05-31 20:32:13.486182750 +1000 +++ telco-new/client/mysqlbinlog.cc 2007-05-31 20:35:00.568624750 +1000
    @@ -73,6 +73,7 @@ static int port= 0;
    static const char* sock= 0; static const char* user = 0; static char* pass = 0; +static char *opt_bind_addr = NULL; static char *charset= 0;

 static ulonglong start_position, stop_position;
@@ -702,6 +703,9 @@ static struct my_option my_long_options[

    "should not be applied on production systems.",     (gptr*) &opt_base64_output, (gptr*) &opt_base64_output, 0, GET_BOOL,     NO_ARG, 0, 0, 0, 0, 0, 0},

+   {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.",
+    (gptr*) &opt_bind_addr, (gptr*) &opt_bind_addr, 0, GET_STR,
+    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   /*
     mysqlbinlog needs charsets knowledge, to be able to convert a charset
     number found in binlog to a charset name (to be able to print things

@@ -988,6 +992,10 @@ static MYSQL* safe_connect()
 
   if (opt_protocol)
     mysql_options(local_mysql, MYSQL_OPT_PROTOCOL, (char*) &opt_protocol);
+  if (opt_bind_addr)
+  {
+       mysql_options(local_mysql,MYSQL_OPT_BIND,opt_bind_addr);
+ }

   if (!mysql_real_connect(local_mysql, host, user, pass, 0, port, sock, 0))    {
     char errmsg[256];
Index: telco-new/client/mysqlcheck.c


  • telco-new.orig/client/mysqlcheck.c 2007-05-31 20:32:13.494183250 +1000 +++ telco-new/client/mysqlcheck.c 2007-05-31 20:35:45.747448250 +1000
    @@ -48,6 +48,7 @@ static char *shared_memory_base_name=0;
    #endif static uint opt_protocol=0; static CHARSET_INFO *charset_info= &my_charset_latin1; +static char *opt_bind_addr = NULL;

 enum operations { DO_CHECK, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE, DO_UPGRADE };  

@@ -71,6 +72,9 @@ static struct my_option my_long_options[

    "If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked, if corrupted ones were found.",     (gptr*) &opt_auto_repair, (gptr*) &opt_auto_repair, 0, GET_BOOL, NO_ARG, 0,     0, 0, 0, 0, 0},

+  {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.",
+   (gptr*) &opt_bind_addr, (gptr*) &opt_bind_addr, 0, GET_STR,
+   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},

   {"character-sets-dir", OPT_CHARSETS_DIR,     "Directory where character sets are.", (gptr*) &charsets_dir,     (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -709,6 +713,10 @@ static int dbConnect(char *host, char *u
 #endif

   if (opt_protocol)
     mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
+  if (opt_bind_addr)
+  {
+       mysql_options(&mysql_connection,MYSQL_OPT_BIND,opt_bind_addr);
+ }
 #ifdef HAVE_SMEM
   if (shared_memory_base_name)
     mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name); Index: telco-new/client/mysqldump.c
  • telco-new.orig/client/mysqldump.c 2007-05-31 20:32:13.498183500 +1000 +++ telco-new/client/mysqldump.c 2007-05-31 20:35:22.077969000 +1000
    @@ -117,6 +117,7 @@ static ulong opt_compatible_mode= 0;
    #define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1 #define MYSQL_OPT_MASTER_DATA_COMMENTED_SQL 2 static uint opt_mysql_port= 0, opt_master_data; +static char *opt_bind_addr = NULL; static my_string opt_mysql_unix_port=0; static int first_error=0; static DYNAMIC_STRING extended_row;
    @@ -207,6 +208,9 @@ static struct my_option my_long_options[
    {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif + {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.", + (gptr*) &opt_bind_addr, (gptr*) &opt_bind_addr, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"character-sets-dir", OPT_CHARSETS_DIR, "Directory where character sets are.", (gptr*) &charsets_dir, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
    @@ -1076,6 +1080,10 @@ static int connect_to_db(char *host, cha
    #endif if (opt_protocol) mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol); + if (opt_bind_addr) + { + mysql_options(&mysql_connection,MYSQL_OPT_BIND,opt_bind_addr); + } #ifdef HAVE_SMEM if (shared_memory_base_name) mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name); Index: telco-new/client/mysqlimport.c
  • telco-new.orig/client/mysqlimport.c 2007-05-31 20:32:13.502183750 +1000 +++ telco-new/client/mysqlimport.c 2007-05-31 20:32:21.406677750 +1000
    @@ -57,6 +57,7 @@ static char *opt_password=0, *current_us
    *escaped=0, *opt_columns=0, *default_charset= (char*) MYSQL_DEFAULT_CHARSET_NAME; static uint opt_mysql_port= 0, opt_protocol= 0; +static char *opt_bind_addr = NULL; static my_string opt_mysql_unix_port=0; static longlong opt_ignore_lines= -1; static CHARSET_INFO *charset_info= &my_charset_latin1;
    @@ -72,6 +73,9 @@ static struct my_option my_long_options[
    {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, #endif + {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.", + (gptr*) &opt_bind_addr, (gptr*) &opt_bind_addr, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"character-sets-dir", OPT_CHARSETS_DIR, "Directory where character sets are.", (gptr*) &charsets_dir, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
    @@ -408,6 +412,8 @@ static MYSQL *db_connect(char *host, cha
    #endif if (opt_protocol) mysql_options(mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol); + if (opt_bind_addr) + mysql_options(mysql,MYSQL_OPT_BIND,opt_bind_addr); #ifdef HAVE_SMEM if (shared_memory_base_name) mysql_options(mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name); Index: telco-new/client/mysqlshow.c
  • telco-new.orig/client/mysqlshow.c 2007-05-31 20:32:13.514184500 +1000 +++ telco-new/client/mysqlshow.c 2007-05-31 20:35:34.618752750 +1000
    @@ -36,6 +36,7 @@ static char *default_charset= (char*) MY
    static char *shared_memory_base_name=0; #endif static uint opt_protocol=0; +static char *opt_bind_addr = NULL;
Do you need help?X

 static void get_options(int *argc,char ***argv);  static uint opt_mysql_port=0;
@@ -113,6 +114,10 @@ int main(int argc, char **argv)
 #endif

   if (opt_protocol)
     mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
+  if (opt_bind_addr)
+  {
+       mysql_options(&mysql,MYSQL_OPT_BIND,opt_bind_addr);
+ }
 #ifdef HAVE_SMEM
   if (shared_memory_base_name)
     mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
@@ -160,6 +165,9 @@ static struct my_option my_long_options[

   {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",     0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},  #endif

+  {"bind-address", OPT_BIND_ADDRESS, "IP address to bind to.",
+   (gptr*) &opt_bind_addr, (gptr*) &opt_bind_addr, 0, GET_STR,
+   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},

   {"character-sets-dir", 'c', "Directory where character sets are.",     (gptr*) &charsets_dir, (gptr*) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0,     0, 0, 0, 0, 0},
Index: telco-new/include/mysql.h


  • telco-new.orig/include/mysql.h 2007-05-31 20:32:13.538186000 +1000 +++ telco-new/include/mysql.h 2007-05-31 20:32:21.446680250 +1000
    @@ -161,7 +161,7 @@ enum mysql_option
    MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT, MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, - MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, + MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, MYSQL_OPT_BIND, MYSQL_OPT_SSL_VERIFY_SERVER_CERT };

@@ -201,6 +201,8 @@ struct st_mysql_options {
 #endif
   enum mysql_option methods_to_use;
   char *client_ip;
+ char *bind_name;
+

   /* Refuse client connecting to server if it uses old (pre-4.1.1) protocol */    my_bool secure_auth;
   /* 0 - never report, 1 - always report (default) */ Index: telco-new/sql-common/client.c


  • telco-new.orig/sql-common/client.c 2007-05-31 20:32:13.546186500 +1000 +++ telco-new/sql-common/client.c 2007-05-31 22:06:17.786929500 +1000
    @@ -1984,6 +1984,49 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
    ER(net->last_errno),socket_errno); goto error; } + if (mysql->options.bind_name) { + /* TODOs for client bind: + - check error codes + - don't use socket for localhost if this option is given + */ + in_addr_t bind_addr; + bind_addr = inet_addr(mysql->options.bind_name); + if (bind_addr == INADDR_NONE) + { + int tmp_errno; + struct hostent tmp_hostent,*hp; + char buff2[GETHOSTBYNAME_BUFF_SIZE]; + hp = my_gethostbyname_r(mysql->options.bind_name, &tmp_hostent, + buff2, sizeof(buff2), &tmp_errno); + if (!hp) + { + my_gethostbyname_r_free(); + net->last_errno=CR_UNKNOWN_HOST; + strmov(net->sqlstate, unknown_sqlstate); + my_snprintf(net->last_error, sizeof(net->last_error)-1, + ER(CR_UNKNOWN_HOST), mysql->options.bind_name, tmp_errno); + goto error; + } + memcpy(&bind_addr, hp->h_addr, + min(sizeof(sock_addr.sin_addr), (size_t) hp->h_length)); + my_gethostbyname_r_free(); + } + if (bind_addr != INADDR_NONE) { + struct sockaddr_in IPaddr; + bzero((char*) &IPaddr, sizeof(IPaddr)); + IPaddr.sin_family = AF_INET; + IPaddr.sin_addr.s_addr = bind_addr; + IPaddr.sin_port = 0; + if (bind(sock, &IPaddr, sizeof(IPaddr))) { + net->last_errno=CR_IPSOCK_ERROR; + strmov(net->sqlstate, unknown_sqlstate); + my_snprintf(net->last_error, sizeof(net->last_error)-1, + ER(CR_IPSOCK_ERROR), mysql->options.bind_name, errno); + goto error; + } + } + } + net->vio= vio_new(sock, VIO_TYPE_TCPIP, VIO_BUFFERED_READ); bzero((char*) &sock_addr,sizeof(sock_addr)); sock_addr.sin_family = AF_INET;
    @@ -3031,6 +3074,9 @@ mysql_options(MYSQL *mysql,enum mysql_op
    case MYSQL_OPT_RECONNECT: mysql->reconnect= *(my_bool *) arg; break; + case MYSQL_OPT_BIND: + mysql->options.bind_name= my_strdup(arg, MYF(MY_WME)); + break; case MYSQL_OPT_SSL_VERIFY_SERVER_CERT: if (*(my_bool*) arg) mysql->options.client_flag|= CLIENT_SSL_VERIFY_SERVER_CERT;
--
Stewart Smith

-- 
MySQL Code Commits Mailing List
For list archives: 
http://lists.mysql.com/commits
To unsubscribe:    
http://lists.mysql.com/commits?unsub=lists@pantek.com
Received on Fri Jun 1 04:35:37 2007

This archive was generated by hypermail 2.1.8 : Fri Jun 01 2007 - 04:40:02 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library