MySQL 9.1.0
Source Code Documentation
violite.h File Reference

Vio Lite. More...

#include "my_config.h"
#include <stddef.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <string>
#include "my_inttypes.h"
#include "my_psi_config.h"
#include "mysql/components/services/bits/my_io_bits.h"
#include "mysql/components/services/bits/my_thread_bits.h"
#include "mysql/components/services/bits/mysql_socket_bits.h"
#include "mysql/psi/mysql_socket.h"
#include <signal.h>
#include <atomic>
#include <optional>
#include <openssl/opensslv.h>
#include <openssl/err.h>
#include <openssl/ssl.h>

Go to the source code of this file.

Classes

struct  st_VioSSLFd
 
struct  Vio
 

Macros

#define USE_PPOLL_IN_VIO
 
#define MYSQL_VIO   Vio *
 
#define VIO_SOCKET_ERROR   ((size_t)-1)
 
#define VIO_SOCKET_WANT_READ   ((size_t)-2)
 
#define VIO_SOCKET_WANT_WRITE   ((size_t)-3)
 
#define VIO_LOCALHOST   1 /* a localhost connection */
 
#define VIO_BUFFERED_READ   2 /* use buffered read */
 
#define VIO_READ_BUFFER_SIZE   16384 /* size of read buffer */
 
#define HANDLE   void *
 
#define VIO_DESCRIPTION_SIZE   30 /* size of description */
 
#define DES_cblock   des_cblock
 
#define DES_key_schedule   des_key_schedule
 
#define DES_set_key_unchecked(k, ks)   des_set_key_unchecked((k), *(ks))
 
#define DES_ede3_cbc_encrypt(i, o, l, k1, k2, k3, iv, e)    des_ede3_cbc_encrypt((i), (o), (l), *(k1), *(k2), *(k3), (iv), (e))
 
#define HEADER_DES_LOCL_H   dummy_something
 
#define vio_delete(vio)   (vio)->viodelete(vio)
 
#define vio_errno(vio)   (vio)->vioerrno(vio)
 
#define vio_read(vio, buf, size)   ((vio)->read)(vio, buf, size)
 
#define vio_write(vio, buf, size)   ((vio)->write)(vio, buf, size)
 
#define vio_fastsend(vio)   (vio)->fastsend(vio)
 
#define vio_keepalive(vio, set_keep_alive)    (vio)->viokeepalive(vio, set_keep_alive)
 
#define vio_should_retry(vio)   (vio)->should_retry(vio)
 
#define vio_was_timeout(vio)   (vio)->was_timeout(vio)
 
#define vio_shutdown(vio)   ((vio)->vioshutdown)(vio)
 
#define vio_peer_addr(vio, buf, prt, buflen)    (vio)->peer_addr(vio, buf, prt, buflen)
 
#define vio_io_wait(vio, event, timeout)   (vio)->io_wait(vio, event, timeout)
 
#define vio_is_connected(vio)   (vio)->is_connected(vio)
 
#define vio_is_blocking(vio)   (vio)->is_blocking(vio)
 
#define vio_set_blocking(vio, val)   (vio)->set_blocking(vio, val)
 
#define vio_set_blocking_flag(vio, val)   (vio)->set_blocking_flag(vio, val)
 
#define SSL_handle   SSL *
 

Typedefs

typedef Vio Vio
 

Enumerations

enum  enum_vio_type : int {
  NO_VIO_TYPE = 0 , VIO_TYPE_TCPIP = 1 , VIO_TYPE_SOCKET = 2 , VIO_TYPE_NAMEDPIPE = 3 ,
  VIO_TYPE_SSL = 4 , VIO_TYPE_SHARED_MEMORY = 5 , VIO_TYPE_LOCAL = 6 , VIO_TYPE_PLUGIN = 7 ,
  FIRST_VIO_TYPE = VIO_TYPE_TCPIP , LAST_VIO_TYPE = VIO_TYPE_PLUGIN
}
 
enum  enum_vio_io_event { VIO_IO_EVENT_READ , VIO_IO_EVENT_WRITE , VIO_IO_EVENT_CONNECT }
 VIO I/O events. More...
 
enum  enum_ssl_init_error {
  SSL_INITERR_NOERROR = 0 , SSL_INITERR_CERT , SSL_INITERR_KEY , SSL_INITERR_NOMATCH ,
  SSL_INITERR_BAD_PATHS , SSL_INITERR_CIPHERS , SSL_INITERR_MEMFAIL , SSL_INITERR_NO_USABLE_CTX ,
  SSL_INITERR_DHFAIL , SSL_TLS_VERSION_INVALID , SSL_FIPS_MODE_INVALID , SSL_FIPS_MODE_FAILED ,
  SSL_INITERR_ECDHFAIL , SSL_INITERR_X509_VERIFY_PARAM , SSL_INITERR_INVALID_CERTIFICATES , SSL_INITERR_LASTERR
}
 
enum  SSL_type {
  SSL_TYPE_NOT_SPECIFIED = -1 , SSL_TYPE_NONE , SSL_TYPE_ANY , SSL_TYPE_X509 ,
  SSL_TYPE_SPECIFIED
}
 

Functions

void init_vio_psi_keys ()
 
void get_vio_type_name (enum enum_vio_type vio_type, const char **str, int *len)
 Convert a vio type to a printable string. More...
 
MYSQL_VIO vio_new (my_socket sd, enum enum_vio_type type, uint flags)
 
MYSQL_VIO mysql_socket_vio_new (MYSQL_SOCKET mysql_socket, enum enum_vio_type type, uint flags)
 
void vio_delete (MYSQL_VIO vio)
 
int vio_shutdown (MYSQL_VIO vio)
 
bool vio_reset (MYSQL_VIO vio, enum enum_vio_type type, my_socket sd, void *ssl, uint flags)
 
bool vio_is_blocking (Vio *vio)
 
int vio_set_blocking (Vio *vio, bool set_blocking_mode)
 
int vio_set_blocking_flag (Vio *vio, bool set_blocking_flag)
 
size_t vio_read (MYSQL_VIO vio, uchar *buf, size_t size)
 
size_t vio_read_buff (MYSQL_VIO vio, uchar *buf, size_t size)
 
size_t vio_write (MYSQL_VIO vio, const uchar *buf, size_t size)
 
int vio_fastsend (MYSQL_VIO vio)
 
int vio_keepalive (MYSQL_VIO vio, bool onoff)
 
bool vio_should_retry (MYSQL_VIO vio)
 
bool vio_was_timeout (MYSQL_VIO vio)
 
void vio_description (MYSQL_VIO vio, char *buf)
 
enum enum_vio_type vio_type (const MYSQL_VIO vio)
 
int vio_errno (MYSQL_VIO vio)
 
my_socket vio_fd (MYSQL_VIO vio)
 
bool vio_peer_addr (MYSQL_VIO vio, char *buf, uint16 *port, size_t buflen)
 
int vio_io_wait (MYSQL_VIO vio, enum enum_vio_io_event event, int timeout)
 
bool vio_is_connected (MYSQL_VIO vio)
 
ssize_t vio_pending (MYSQL_VIO vio)
 
int vio_timeout (MYSQL_VIO vio, uint which, int timeout_sec)
 
bool vio_socket_connect (MYSQL_VIO vio, struct sockaddr *addr, socklen_t len, bool nonblocking, int timeout, bool *connect_done=nullptr)
 
bool vio_get_normalized_ip_string (const struct sockaddr *addr, size_t addr_length, char *ip_string, size_t ip_string_size)
 Return the normalized IP address string for a sock-address. More...
 
bool vio_is_no_name_error (int err_code)
 Checks if the error code, returned by vio_getnameinfo(), means it was the "No-name" error. More...
 
int vio_getnameinfo (const struct sockaddr *sa, char *hostname, size_t hostname_size, char *port, size_t port_size, int flags)
 This is a wrapper for the system getnameinfo(), because different OS differ in the getnameinfo() implementation: More...
 
const char * sslGetErrString (enum enum_ssl_init_error err)
 
int sslaccept (struct st_VioSSLFd *, MYSQL_VIO, long timeout, unsigned long *errptr)
 
int sslconnect (struct st_VioSSLFd *, MYSQL_VIO, long timeout, SSL_SESSION *session, unsigned long *errptr, SSL **ssl, const char *sni_servername)
 
struct st_VioSSLFdnew_VioSSLConnectorFd (const char *key_file, const char *cert_file, const char *ca_file, const char *ca_path, const char *cipher, const char *ciphersuites, enum enum_ssl_init_error *error, const char *crl_file, const char *crl_path, const long ssl_ctx_flags, const char *server_host)
 
long process_tls_version (const char *tls_version)
 
struct st_VioSSLFdnew_VioSSLAcceptorFd (const char *key_file, const char *cert_file, const char *ca_file, const char *ca_path, const char *cipher, const char *ciphersuites, enum enum_ssl_init_error *error, const char *crl_file, const char *crl_path, const long ssl_ctx_flags)
 
void free_vio_ssl_acceptor_fd (struct st_VioSSLFd *fd)
 
void vio_ssl_end ()
 
void ssl_start (void)
 
void vio_end (void)
 

Detailed Description

Vio Lite.

Purpose: include file for Vio that will work with C and C++.

Macro Definition Documentation

◆ DES_cblock

#define DES_cblock   des_cblock

◆ DES_ede3_cbc_encrypt

#define DES_ede3_cbc_encrypt (   i,
  o,
  l,
  k1,
  k2,
  k3,
  iv,
 
)     des_ede3_cbc_encrypt((i), (o), (l), *(k1), *(k2), *(k3), (iv), (e))

◆ DES_key_schedule

#define DES_key_schedule   des_key_schedule

◆ DES_set_key_unchecked

#define DES_set_key_unchecked (   k,
  ks 
)    des_set_key_unchecked((k), *(ks))

◆ HANDLE

#define HANDLE   void *

◆ HEADER_DES_LOCL_H

#define HEADER_DES_LOCL_H   dummy_something

◆ MYSQL_VIO

#define MYSQL_VIO   Vio *

◆ SSL_handle

#define SSL_handle   SSL *

◆ USE_PPOLL_IN_VIO

#define USE_PPOLL_IN_VIO

◆ VIO_BUFFERED_READ

#define VIO_BUFFERED_READ   2 /* use buffered read */

◆ vio_delete

#define vio_delete (   vio)    (vio)->viodelete(vio)

◆ VIO_DESCRIPTION_SIZE

#define VIO_DESCRIPTION_SIZE   30 /* size of description */

◆ vio_errno

#define vio_errno (   vio)    (vio)->vioerrno(vio)

◆ vio_fastsend

#define vio_fastsend (   vio)    (vio)->fastsend(vio)

◆ vio_io_wait

#define vio_io_wait (   vio,
  event,
  timeout 
)    (vio)->io_wait(vio, event, timeout)

◆ vio_is_blocking

#define vio_is_blocking (   vio)    (vio)->is_blocking(vio)

◆ vio_is_connected

#define vio_is_connected (   vio)    (vio)->is_connected(vio)

◆ vio_keepalive

#define vio_keepalive (   vio,
  set_keep_alive 
)     (vio)->viokeepalive(vio, set_keep_alive)

◆ VIO_LOCALHOST

#define VIO_LOCALHOST   1 /* a localhost connection */

◆ vio_peer_addr

#define vio_peer_addr (   vio,
  buf,
  prt,
  buflen 
)     (vio)->peer_addr(vio, buf, prt, buflen)

◆ vio_read

#define vio_read (   vio,
  buf,
  size 
)    ((vio)->read)(vio, buf, size)

◆ VIO_READ_BUFFER_SIZE

#define VIO_READ_BUFFER_SIZE   16384 /* size of read buffer */

◆ vio_set_blocking

#define vio_set_blocking (   vio,
  val 
)    (vio)->set_blocking(vio, val)

◆ vio_set_blocking_flag

#define vio_set_blocking_flag (   vio,
  val 
)    (vio)->set_blocking_flag(vio, val)

◆ vio_should_retry

#define vio_should_retry (   vio)    (vio)->should_retry(vio)

◆ vio_shutdown

#define vio_shutdown (   vio)    ((vio)->vioshutdown)(vio)

◆ VIO_SOCKET_ERROR

#define VIO_SOCKET_ERROR   ((size_t)-1)

◆ VIO_SOCKET_WANT_READ

#define VIO_SOCKET_WANT_READ   ((size_t)-2)

◆ VIO_SOCKET_WANT_WRITE

#define VIO_SOCKET_WANT_WRITE   ((size_t)-3)

◆ vio_was_timeout

#define vio_was_timeout (   vio)    (vio)->was_timeout(vio)

◆ vio_write

#define vio_write (   vio,
  buf,
  size 
)    ((vio)->write)(vio, buf, size)

Typedef Documentation

◆ Vio

typedef Vio Vio

Enumeration Type Documentation

◆ enum_ssl_init_error

Enumerator
SSL_INITERR_NOERROR 
SSL_INITERR_CERT 
SSL_INITERR_KEY 
SSL_INITERR_NOMATCH 
SSL_INITERR_BAD_PATHS 
SSL_INITERR_CIPHERS 
SSL_INITERR_MEMFAIL 
SSL_INITERR_NO_USABLE_CTX 
SSL_INITERR_DHFAIL 
SSL_TLS_VERSION_INVALID 
SSL_FIPS_MODE_INVALID 
SSL_FIPS_MODE_FAILED 
SSL_INITERR_ECDHFAIL 
SSL_INITERR_X509_VERIFY_PARAM 
SSL_INITERR_INVALID_CERTIFICATES 
SSL_INITERR_LASTERR 

◆ enum_vio_io_event

VIO I/O events.

Enumerator
VIO_IO_EVENT_READ 
VIO_IO_EVENT_WRITE 
VIO_IO_EVENT_CONNECT 

◆ enum_vio_type

enum enum_vio_type : int
Enumerator
NO_VIO_TYPE 

Type of the connection is unknown.

VIO_TYPE_TCPIP 

Used in case of TCP/IP connections.

VIO_TYPE_SOCKET 

Used for Unix Domain socket connections.

Unix only.

VIO_TYPE_NAMEDPIPE 

Used for named pipe connections.

Windows only.

VIO_TYPE_SSL 

Used in case of SSL connections.

VIO_TYPE_SHARED_MEMORY 

Used for shared memory connections.

Windows only.

VIO_TYPE_LOCAL 

Used internally by the prepared statements.

VIO_TYPE_PLUGIN 

Implicitly used by plugins that doesn't support any other VIO_TYPE.

FIRST_VIO_TYPE 
LAST_VIO_TYPE 

◆ SSL_type

enum SSL_type
Enumerator
SSL_TYPE_NOT_SPECIFIED 
SSL_TYPE_NONE 
SSL_TYPE_ANY 
SSL_TYPE_X509 
SSL_TYPE_SPECIFIED 

Function Documentation

◆ free_vio_ssl_acceptor_fd()

void free_vio_ssl_acceptor_fd ( struct st_VioSSLFd fd)

◆ get_vio_type_name()

void get_vio_type_name ( enum enum_vio_type  vio_type,
const char **  str,
int *  len 
)

Convert a vio type to a printable string.

Parameters
vio_typethe type
[out]strthe string
[out]lenthe string length

◆ init_vio_psi_keys()

void init_vio_psi_keys ( )

◆ mysql_socket_vio_new()

MYSQL_VIO mysql_socket_vio_new ( MYSQL_SOCKET  mysql_socket,
enum enum_vio_type  type,
uint  flags 
)

◆ new_VioSSLAcceptorFd()

struct st_VioSSLFd * new_VioSSLAcceptorFd ( const char *  key_file,
const char *  cert_file,
const char *  ca_file,
const char *  ca_path,
const char *  cipher,
const char *  ciphersuites,
enum enum_ssl_init_error error,
const char *  crl_file,
const char *  crl_path,
const long  ssl_ctx_flags 
)

◆ new_VioSSLConnectorFd()

struct st_VioSSLFd * new_VioSSLConnectorFd ( const char *  key_file,
const char *  cert_file,
const char *  ca_file,
const char *  ca_path,
const char *  cipher,
const char *  ciphersuites,
enum enum_ssl_init_error error,
const char *  crl_file,
const char *  crl_path,
const long  ssl_ctx_flags,
const char *  server_host 
)

◆ process_tls_version()

long process_tls_version ( const char *  tls_version)

◆ ssl_start()

void ssl_start ( void  )

◆ sslaccept()

int sslaccept ( struct st_VioSSLFd ,
MYSQL_VIO  ,
long  timeout,
unsigned long *  errptr 
)

◆ sslconnect()

int sslconnect ( struct st_VioSSLFd ,
MYSQL_VIO  ,
long  timeout,
SSL_SESSION *  session,
unsigned long *  errptr,
SSL **  ssl,
const char *  sni_servername 
)

◆ sslGetErrString()

const char * sslGetErrString ( enum enum_ssl_init_error  err)

◆ vio_delete()

void vio_delete ( MYSQL_VIO  vio)

◆ vio_description()

void vio_description ( MYSQL_VIO  vio,
char *  buf 
)

◆ vio_end()

void vio_end ( void  )

◆ vio_errno()

int vio_errno ( MYSQL_VIO  vio)

◆ vio_fastsend()

int vio_fastsend ( MYSQL_VIO  vio)

◆ vio_fd()

my_socket vio_fd ( MYSQL_VIO  vio)

◆ vio_get_normalized_ip_string()

bool vio_get_normalized_ip_string ( const struct sockaddr addr,
size_t  addr_length,
char *  ip_string,
size_t  ip_string_size 
)

Return the normalized IP address string for a sock-address.

The idea is to return an IPv4-address for an IPv4-mapped and IPv4-compatible IPv6 address.

The function writes the normalized IP address to the given buffer. The buffer should have enough space, otherwise error flag is returned. The system constant INET6_ADDRSTRLEN can be used to reserve buffers of the right size.

Parameters
[in]addrsockaddr object (AF_INET or AF_INET6).
[in]addr_lengthlength of the addr.
[out]ip_stringbuffer to write normalized IP address.
[in]ip_string_sizesize of the ip_string.
Returns
Error status.
Return values
truein case of error (the ip_string buffer is not enough).
falseon success.

◆ vio_getnameinfo()

int vio_getnameinfo ( const struct sockaddr sa,
char *  hostname,
size_t  hostname_size,
char *  port,
size_t  port_size,
int  flags 
)

This is a wrapper for the system getnameinfo(), because different OS differ in the getnameinfo() implementation:

  • Solaris 10 requires that the 2nd argument (salen) must match the actual size of the struct sockaddr_storage passed to it;
  • Mac OS X has sockaddr_in::sin_len and sockaddr_in6::sin6_len and requires them to be filled.

◆ vio_io_wait()

int vio_io_wait ( MYSQL_VIO  vio,
enum enum_vio_io_event  event,
int  timeout 
)

◆ vio_is_blocking()

bool vio_is_blocking ( Vio vio)

◆ vio_is_connected()

bool vio_is_connected ( MYSQL_VIO  vio)

◆ vio_is_no_name_error()

bool vio_is_no_name_error ( int  err_code)

Checks if the error code, returned by vio_getnameinfo(), means it was the "No-name" error.

Windows-specific note: getnameinfo() returns WSANO_DATA instead of EAI_NODATA or EAI_NONAME when no reverse mapping is available at the host (i.e. Windows can't get hostname by IP-address). This error should be treated as EAI_NONAME.

Returns
if the error code is actually EAI_NONAME.
Return values
trueif the error code is EAI_NONAME.
falseotherwise.

◆ vio_keepalive()

int vio_keepalive ( MYSQL_VIO  vio,
bool  onoff 
)

◆ vio_new()

MYSQL_VIO vio_new ( my_socket  sd,
enum enum_vio_type  type,
uint  flags 
)

◆ vio_peer_addr()

bool vio_peer_addr ( MYSQL_VIO  vio,
char *  buf,
uint16 port,
size_t  buflen 
)

◆ vio_pending()

ssize_t vio_pending ( MYSQL_VIO  vio)

◆ vio_read()

size_t vio_read ( MYSQL_VIO  vio,
uchar buf,
size_t  size 
)

◆ vio_read_buff()

size_t vio_read_buff ( MYSQL_VIO  vio,
uchar buf,
size_t  size 
)

◆ vio_reset()

bool vio_reset ( MYSQL_VIO  vio,
enum enum_vio_type  type,
my_socket  sd,
void *  ssl,
uint  flags 
)

◆ vio_set_blocking()

int vio_set_blocking ( Vio vio,
bool  set_blocking_mode 
)

◆ vio_set_blocking_flag()

int vio_set_blocking_flag ( Vio vio,
bool  set_blocking_flag 
)

◆ vio_should_retry()

bool vio_should_retry ( MYSQL_VIO  vio)

◆ vio_shutdown()

int vio_shutdown ( MYSQL_VIO  vio)

◆ vio_socket_connect()

bool vio_socket_connect ( MYSQL_VIO  vio,
struct sockaddr addr,
socklen_t  len,
bool  nonblocking,
int  timeout,
bool *  connect_done = nullptr 
)

◆ vio_ssl_end()

void vio_ssl_end ( )

◆ vio_timeout()

int vio_timeout ( MYSQL_VIO  vio,
uint  which,
int  timeout_sec 
)

◆ vio_type()

enum enum_vio_type vio_type ( const MYSQL_VIO  vio)

◆ vio_was_timeout()

bool vio_was_timeout ( MYSQL_VIO  vio)

◆ vio_write()

size_t vio_write ( MYSQL_VIO  vio,
const uchar buf,
size_t  size 
)