Uploaded image for project: 'MariaDB MaxScale'
  1. MariaDB MaxScale
  2. MXS-257

filters not always intercept 'USE db' calls

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Not a Bug
    • Affects Version/s: None
    • Fix Version/s: 1.3.0
    • Component/s: Plugin
    • Labels:
      None

      Description

      In my filter, I would like to know when users connect to which DB. Currently, Maxscale allows clients to specify DB to connect to in the handshake reply, and the filter is not being called.

      This leads to inconsistent behavior of the filter: if the user specifies a database in the connection string, the filter does not know about it, but if database is not specified, and USE db is issued later, that goes through the filter.

      A quick solution to this is to remove the GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB bit from the capabilities. This will force the clients to call USE db explicitly after connecting, regardless of the connection string supplied by the user.

      An alternative would be to let the filter know somehow that a database has been selected.

      I'm using this patch for the first alternative:

      diff --git a/server/modules/protocol/mysql_client.c b/server/modules/protocol/mysql_client.c
      index abdb442..58292e7 100644
      --- a/server/modules/protocol/mysql_client.c
      +++ b/server/modules/protocol/mysql_client.c
      @@ -320,6 +320,7 @@ MySQLSendHandshake(DCB* dcb)
       
               mysql_server_capabilities_one[0] &= ~GW_MYSQL_CAPABILITIES_COMPRESS;
               mysql_server_capabilities_one[0] &= ~GW_MYSQL_CAPABILITIES_SSL;
      +        mysql_server_capabilities_one[0] &= ~GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB;
       
               memcpy(mysql_handshake_payload, mysql_server_capabilities_one, sizeof(mysql_server_capabilities_one));
               mysql_handshake_payload = mysql_handshake_payload + sizeof(mysql_server_capabilities_one);
      @@ -392,7 +393,7 @@ MySQLSendHandshake(DCB* dcb)
       static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
              MySQLProtocol *protocol = NULL;
              /* int compress = -1; */
      -       int connect_with_db = -1;
      +       int connect_with_db = 0;
              uint8_t *client_auth_packet = GWBUF_DATA(queue);
              int client_auth_packet_size = 0;
              char *username =  NULL;
      @@ -442,9 +443,11 @@ static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
       
              memcpy(&protocol->client_capabilities, client_auth_packet + 4, 4);
       
      +        /*
              connect_with_db =
                       GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB & gw_mysql_get_byte4(
                               (uint32_t *)&protocol->client_capabilities);
      +        */
               /*
              compress =
                       GW_MYSQL_CAPABILITIES_COMPRESS & gw_mysql_get_byte4(

        Attachments

          Activity

            People

            Assignee:
            markus makela markus makela
            Reporter:
            yhager Yuval Hager
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: