Skip to content

Commit

Permalink
[#479] Remove buffer_size from configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperpedersen committed Oct 30, 2024
1 parent fe1693d commit 4a82850
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 92 deletions.
1 change: 0 additions & 1 deletion doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ The available keys and their accepted values are reported in the table below.
| tls_key_file | | String | No | Private key file for TLS. This file must be owned by either the user running pgagroal or root. Additionally permissions must be at least `0640` when owned by root or `0600` otherwise. |
| tls_ca_file | | String | No | Certificate Authority (CA) file for TLS. This file must be owned by either the user running pgagroal or root. |
| libev | `auto` | String | No | Select the [libev](http://software.schmorp.de/pkg/libev.html) backend to use. Valid options: `auto`, `select`, `poll`, `epoll`, `iouring`, `devpoll` and `port` |
| buffer_size | 65535 | Int | No | The network buffer size (`SO_RCVBUF` and `SO_SNDBUF`) |
| keep_alive | on | Bool | No | Have `SO_KEEPALIVE` on sockets |
| nodelay | on | Bool | No | Have `TCP_NODELAY` on sockets |
| non_blocking | off | Bool | No | Have `O_NONBLOCK` on sockets |
Expand Down
3 changes: 0 additions & 3 deletions doc/man/pgagroal.conf.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ tls_ca_file
libev
The libev backend to use. Valid options: auto, select, poll, epoll, iouring, devpoll and port. Default is auto

buffer_size
The network buffer size (SO_RCVBUF and SO_SNDBUF). Default is 65535

keep_alive
Have SO_KEEPALIVE on sockets. Default is on

Expand Down
1 change: 0 additions & 1 deletion doc/manual/user-02-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ The available keys and their accepted values are reported in the table below.
| tls_key_file | | String | No | Private key file for TLS. This file must be owned by either the user running pgagroal or root. Additionally permissions must be at least `0640` when owned by root or `0600` otherwise. |
| tls_ca_file | | String | No | Certificate Authority (CA) file for TLS. This file must be owned by either the user running pgagroal or root. |
| libev | `auto` | String | No | Select the [libev](http://software.schmorp.de/pkg/libev.html) backend to use. Valid options: `auto`, `select`, `poll`, `epoll`, `iouring`, `devpoll` and `port` |
| buffer_size | 65535 | Int | No | The network buffer size (`SO_RCVBUF` and `SO_SNDBUF`) |
| keep_alive | on | Bool | No | Have `SO_KEEPALIVE` on sockets |
| nodelay | on | Bool | No | Have `TCP_NODELAY` on sockets |
| non_blocking | off | Bool | No | Have `O_NONBLOCK` on sockets |
Expand Down
4 changes: 2 additions & 2 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ main(int argc, char** argv)
else
{
/* Remote connection */
if (pgagroal_connect(host, atoi(port), &socket, config->keep_alive, config->non_blocking, &config->buffer_size, config->nodelay))
if (pgagroal_connect(host, atoi(port), &socket, config->keep_alive, config->non_blocking, config->nodelay))
{
/* Remote connection */
l_port = strtol(port, NULL, 10);
Expand All @@ -572,7 +572,7 @@ main(int argc, char** argv)
goto done;
}

if (pgagroal_connect(host, (int)l_port, &socket, config->keep_alive, config->non_blocking, &config->buffer_size, config->nodelay))
if (pgagroal_connect(host, (int)l_port, &socket, config->keep_alive, config->non_blocking, config->nodelay))
{
warnx("No route to host: %s:%ld\n", host, l_port);
goto done;
Expand Down
7 changes: 0 additions & 7 deletions src/include/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ extern "C" {
void
pgagroal_memory_init(void);

/**
* Set the size of the local message structure
* @param size The size
*/
void
pgagroal_memory_size(size_t size);

/**
* Get the message structure
* @return The structure
Expand Down
15 changes: 2 additions & 13 deletions src/include/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ extern "C" {
* @param fds The resulting descriptors
* @param length The resulting length of descriptors
* @param non_blocking Use non blocking
* @param buffer_size Socket buffer size
* @param no_delay Use NODELAY
* @param backlog the number of backlogs
* @return 0 upon success, otherwise 1
*/
int
pgagroal_bind(const char* hostname, int port, int** fds, int* length, bool no_blocking, int* buffer_size, bool no_delay, int backlog);
pgagroal_bind(const char* hostname, int port, int** fds, int* length, bool no_blocking, bool no_delay, int backlog);

/**
* Bind a Unix Domain Socket
Expand Down Expand Up @@ -77,12 +76,11 @@ pgagroal_remove_unix_socket(const char* directory, const char* file);
* @param fd The resulting descriptor
* @param keep_alive Use keep alive
* @param non_blocking Use non blocking
* @param buffer_size Socket buffer size
* @param no_delay Use NODELAY
* @return 0 upon success, otherwise 1
*/
int
pgagroal_connect(const char* hostname, int port, int* fd, bool keep_alive, bool non_blocking, int* buffer_size, bool no_delay);
pgagroal_connect(const char* hostname, int port, int* fd, bool keep_alive, bool non_blocking, bool no_delay);

/**
* Connect to a Unix Domain Socket
Expand Down Expand Up @@ -135,15 +133,6 @@ pgagroal_get_address(struct sockaddr* sa, char* address, size_t length);
int
pgagroal_tcp_nodelay(int fd);

/**
* Set the configured socket buffer size to a descriptor
* @param fd The descriptor
* @param buffer_size Socket buffer size
* @return 0 upon success, otherwise 1
*/
int
pgagroal_socket_buffers(int fd, int* buffer_size);

/**
* Apply O_NONBLOCK to a descriptor
* @param fd The descriptor
Expand Down
8 changes: 3 additions & 5 deletions src/include/pgagroal.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ extern "C" {

#define MAX_PROCESS_TITLE_LENGTH 256

#define MAX_BUFFER_SIZE 65535
#define DEFAULT_BUFFER_SIZE 65535
#define SECURITY_BUFFER_SIZE 1024
#define HTTP_BUFFER_SIZE 1024
#define DEFAULT_BUFFER_SIZE 131072
#define SECURITY_BUFFER_SIZE 1024
#define HTTP_BUFFER_SIZE 1024

#define MAX_USERNAME_LENGTH 128
#define MAX_DATABASE_LENGTH 256
Expand Down Expand Up @@ -536,7 +535,6 @@ struct main_configuration
char pidfile[MAX_PATH]; /**< File containing the PID */

char libev[MISC_LENGTH]; /**< Name of libev mode */
int buffer_size; /**< Socket buffer size */
bool keep_alive; /**< Use keep alive */
bool nodelay; /**< Use NODELAY */
bool non_blocking; /**< Use non blocking */
Expand Down
17 changes: 0 additions & 17 deletions src/libpgagroal/configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ pgagroal_init_configuration(void* shm)
config->disconnect_client = 0;
config->disconnect_client_force = false;

config->buffer_size = DEFAULT_BUFFER_SIZE;
config->keep_alive = true;
config->nodelay = true;
config->non_blocking = false;
Expand Down Expand Up @@ -2664,7 +2663,6 @@ transfer_configuration(struct main_configuration* config, struct main_configurat

/* libev */
restart_string("libev", config->libev, reload->libev, true);
config->buffer_size = reload->buffer_size;
config->keep_alive = reload->keep_alive;
config->nodelay = reload->nodelay;
config->non_blocking = reload->non_blocking;
Expand Down Expand Up @@ -3680,10 +3678,6 @@ pgagroal_write_config_value(char* buffer, char* config_key, size_t buffer_size)
{
return to_string(buffer, config->unix_socket_dir, buffer_size);
}
else if (!strncmp(key, "buffer_size", MISC_LENGTH))
{
return to_int(buffer, config->buffer_size);
}
else if (!strncmp(key, "keep_alive", MISC_LENGTH))
{
return to_bool(buffer, config->keep_alive);
Expand Down Expand Up @@ -4653,17 +4647,6 @@ pgagroal_apply_main_configuration(struct main_configuration* config,
}
memcpy(config->libev, value, max);
}
else if (key_in_section("buffer_size", section, key, true, &unknown))
{
if (as_int(value, &config->buffer_size))
{
unknown = true;
}
if (config->buffer_size > MAX_BUFFER_SIZE)
{
config->buffer_size = MAX_BUFFER_SIZE;
}
}
else if (key_in_section("keep_alive", section, key, true, &unknown))
{
if (as_bool(value, &config->keep_alive))
Expand Down
17 changes: 2 additions & 15 deletions src/libpgagroal/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,10 @@ static void* data = NULL;
void
pgagroal_memory_init(void)
{
struct main_configuration* config;

#ifdef DEBUG
assert(shmem != NULL);
#endif

config = (struct main_configuration*)shmem;

pgagroal_memory_size(config->buffer_size);
}

/**
*
*/
void
pgagroal_memory_size(size_t size)
{
pgagroal_memory_destroy();

message = (struct message*)calloc(1, sizeof(struct message));
Expand All @@ -77,15 +64,15 @@ pgagroal_memory_size(size_t size)
goto error;
}

data = calloc(1, size);
data = calloc(1, DEFAULT_BUFFER_SIZE);
if (data == NULL)
{
goto error;
}

message->kind = 0;
message->length = 0;
message->max_length = size;
message->max_length = DEFAULT_BUFFER_SIZE;
message->data = data;

return;
Expand Down
14 changes: 8 additions & 6 deletions src/libpgagroal/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ static int bind_host(const char* hostname, int port, int** fds, int* length, boo
*
*/
int
pgagroal_bind(const char* hostname, int port, int** fds, int* length, bool non_blocking, int* buffer_size, bool no_delay, int backlog)
pgagroal_bind(const char* hostname, int port, int** fds, int* length, bool non_blocking, bool no_delay, int backlog)
{
int default_buffer_size = DEFAULT_BUFFER_SIZE;
struct ifaddrs* ifaddr, * ifa;
struct sockaddr_in* sa4;
struct sockaddr_in6* sa6;
Expand Down Expand Up @@ -98,7 +99,7 @@ pgagroal_bind(const char* hostname, int port, int** fds, int* length, bool non_b
inet_ntop(AF_INET6, &sa6->sin6_addr, addr, sizeof(addr));
}

if (bind_host(addr, port, &new_fds, &new_length, non_blocking, buffer_size, no_delay, backlog))
if (bind_host(addr, port, &new_fds, &new_length, non_blocking, &default_buffer_size, no_delay, backlog))
{
free(new_fds);
continue;
Expand Down Expand Up @@ -135,7 +136,7 @@ pgagroal_bind(const char* hostname, int port, int** fds, int* length, bool non_b
return 0;
}

return bind_host(hostname, port, fds, length, non_blocking, buffer_size, no_delay, backlog);
return bind_host(hostname, port, fds, length, non_blocking, &default_buffer_size, no_delay, backlog);
}

/**
Expand Down Expand Up @@ -228,8 +229,9 @@ pgagroal_remove_unix_socket(const char* directory, const char* file)
*
*/
int
pgagroal_connect(const char* hostname, int port, int* fd, bool keep_alive, bool non_blocking, int* buffer_size, bool no_delay)
pgagroal_connect(const char* hostname, int port, int* fd, bool keep_alive, bool non_blocking, bool no_delay)
{
int default_buffer_size = DEFAULT_BUFFER_SIZE;
struct addrinfo hints = {0};
struct addrinfo* servinfo = NULL;
struct addrinfo* p = NULL;
Expand Down Expand Up @@ -294,7 +296,7 @@ pgagroal_connect(const char* hostname, int port, int* fd, bool keep_alive, bool
}
}

if (setsockopt(*fd, SOL_SOCKET, SO_RCVBUF, buffer_size, optlen) == -1)
if (setsockopt(*fd, SOL_SOCKET, SO_RCVBUF, &default_buffer_size, optlen) == -1)
{
error = errno;
pgagroal_disconnect(*fd);
Expand All @@ -303,7 +305,7 @@ pgagroal_connect(const char* hostname, int port, int* fd, bool keep_alive, bool
continue;
}

if (setsockopt(*fd, SOL_SOCKET, SO_SNDBUF, buffer_size, optlen) == -1)
if (setsockopt(*fd, SOL_SOCKET, SO_SNDBUF, &default_buffer_size, optlen) == -1)
{
error = errno;
pgagroal_disconnect(*fd);
Expand Down
2 changes: 1 addition & 1 deletion src/libpgagroal/pipeline_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ session_periodic(void)
}
else
{
ret = pgagroal_connect(config->servers[server].host, config->servers[server].port, &socket, config->keep_alive, config->non_blocking, &config->buffer_size, config->nodelay);
ret = pgagroal_connect(config->servers[server].host, config->servers[server].port, &socket, config->keep_alive, config->non_blocking, config->nodelay);
}

if (ret == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/libpgagroal/pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pgagroal_get_connection(char* username, char* database, bool reuse, bool transac
}
else
{
ret = pgagroal_connect(config->servers[server].host, config->servers[server].port, &fd, config->keep_alive, config->non_blocking, &config->buffer_size, config->nodelay);
ret = pgagroal_connect(config->servers[server].host, config->servers[server].port, &fd, config->keep_alive, config->non_blocking, config->nodelay);
}

if (ret)
Expand Down
6 changes: 2 additions & 4 deletions src/libpgagroal/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ pgagroal_authenticate(int client_fd, char* address, int* slot, SSL** client_ssl,
}
else
{
ret = pgagroal_connect(config->servers[server].host, config->servers[server].port, &server_fd, config->keep_alive, config->non_blocking, &config->buffer_size, config->nodelay);
ret = pgagroal_connect(config->servers[server].host, config->servers[server].port, &server_fd, config->keep_alive, config->non_blocking, config->nodelay);
}

if (ret)
Expand Down Expand Up @@ -869,8 +869,6 @@ pgagroal_remote_management_scram_sha256(char* username, char* password, int serv
struct message* sasl_final = NULL;
struct message* msg = NULL;

pgagroal_memory_size(DEFAULT_BUFFER_SIZE);

if (pgagroal_get_home_directory() == NULL)
{
goto error;
Expand Down Expand Up @@ -4695,7 +4693,7 @@ auth_query_get_connection(char* username, char* password, char* database, int* s
}
else
{
ret = pgagroal_connect(config->servers[server].host, config->servers[server].port, server_fd, config->keep_alive, config->non_blocking, &config->buffer_size, config->nodelay);
ret = pgagroal_connect(config->servers[server].host, config->servers[server].port, server_fd, config->keep_alive, config->non_blocking, config->nodelay);
}

if (ret)
Expand Down
18 changes: 9 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ main(int argc, char** argv)
/* Bind main socket */
if (!has_main_sockets)
{
if (pgagroal_bind(config->common.host, config->common.port, &main_fds, &main_fds_length, config->non_blocking, &config->buffer_size, config->nodelay, config->backlog))
if (pgagroal_bind(config->common.host, config->common.port, &main_fds, &main_fds_length, config->non_blocking, config->nodelay, config->backlog))
{
pgagroal_log_fatal("pgagroal: Could not bind to %s:%d", config->common.host, config->common.port);
#ifdef HAVE_LINUX
Expand Down Expand Up @@ -1050,7 +1050,7 @@ main(int argc, char** argv)
if (config->common.metrics > 0)
{
/* Bind metrics socket */
if (pgagroal_bind(config->common.host, config->common.metrics, &metrics_fds, &metrics_fds_length, config->non_blocking, &config->buffer_size, config->nodelay, config->backlog))
if (pgagroal_bind(config->common.host, config->common.metrics, &metrics_fds, &metrics_fds_length, config->non_blocking, config->nodelay, config->backlog))
{
pgagroal_log_fatal("pgagroal: Could not bind to %s:%d", config->common.host, config->common.metrics);
#ifdef HAVE_LINUX
Expand All @@ -1074,7 +1074,7 @@ main(int argc, char** argv)
if (config->management > 0)
{
/* Bind management socket */
if (pgagroal_bind(config->common.host, config->management, &management_fds, &management_fds_length, config->non_blocking, &config->buffer_size, config->nodelay, config->backlog))
if (pgagroal_bind(config->common.host, config->management, &management_fds, &management_fds_length, config->non_blocking, config->nodelay, config->backlog))
{
pgagroal_log_fatal("pgagroal: Could not bind to %s:%d", config->common.host, config->management);
#ifdef HAVE_LINUX
Expand Down Expand Up @@ -1249,7 +1249,7 @@ accept_main_cb(struct ev_loop* loop, struct ev_io* watcher, int revents)
main_fds = NULL;
main_fds_length = 0;

if (pgagroal_bind(config->common.host, config->common.port, &main_fds, &main_fds_length, config->non_blocking, &config->buffer_size, config->nodelay, config->backlog))
if (pgagroal_bind(config->common.host, config->common.port, &main_fds, &main_fds_length, config->non_blocking, config->nodelay, config->backlog))
{
pgagroal_log_fatal("pgagroal: Could not bind to %s:%d", config->common.host, config->common.port);
exit(1);
Expand Down Expand Up @@ -1631,7 +1631,7 @@ accept_metrics_cb(struct ev_loop* loop, struct ev_io* watcher, int revents)
metrics_fds = NULL;
metrics_fds_length = 0;

if (pgagroal_bind(config->common.host, config->common.metrics, &metrics_fds, &metrics_fds_length, config->non_blocking, &config->buffer_size, config->nodelay, config->backlog))
if (pgagroal_bind(config->common.host, config->common.metrics, &metrics_fds, &metrics_fds_length, config->non_blocking, config->nodelay, config->backlog))
{
pgagroal_log_fatal("pgagroal: Could not bind to %s:%d", config->common.host, config->common.metrics);
exit(1);
Expand Down Expand Up @@ -1707,7 +1707,7 @@ accept_management_cb(struct ev_loop* loop, struct ev_io* watcher, int revents)
management_fds = NULL;
management_fds_length = 0;

if (pgagroal_bind(config->common.host, config->management, &management_fds, &management_fds_length, config->non_blocking, &config->buffer_size, config->nodelay, config->backlog))
if (pgagroal_bind(config->common.host, config->management, &management_fds, &management_fds_length, config->non_blocking, config->nodelay, config->backlog))
{
pgagroal_log_fatal("pgagroal: Could not bind to %s:%d", config->common.host, config->management);
exit(1);
Expand Down Expand Up @@ -2034,7 +2034,7 @@ reload_configuration(void)
main_fds = NULL;
main_fds_length = 0;

if (pgagroal_bind(config->common.host, config->common.port, &main_fds, &main_fds_length, config->non_blocking, &config->buffer_size, config->nodelay, config->backlog))
if (pgagroal_bind(config->common.host, config->common.port, &main_fds, &main_fds_length, config->non_blocking, config->nodelay, config->backlog))
{
pgagroal_log_fatal("pgagroal: Could not bind to %s:%d", config->common.host, config->common.port);
goto error;
Expand All @@ -2056,7 +2056,7 @@ reload_configuration(void)
metrics_fds_length = 0;

/* Bind metrics socket */
if (pgagroal_bind(config->common.host, config->common.metrics, &metrics_fds, &metrics_fds_length, config->non_blocking, &config->buffer_size, config->nodelay, config->backlog))
if (pgagroal_bind(config->common.host, config->common.metrics, &metrics_fds, &metrics_fds_length, config->non_blocking, config->nodelay, config->backlog))
{
pgagroal_log_fatal("pgagroal: Could not bind to %s:%d", config->common.host, config->common.metrics);
goto error;
Expand All @@ -2078,7 +2078,7 @@ reload_configuration(void)
management_fds_length = 0;

/* Bind management socket */
if (pgagroal_bind(config->common.host, config->management, &management_fds, &management_fds_length, config->non_blocking, &config->buffer_size, config->nodelay, config->backlog))
if (pgagroal_bind(config->common.host, config->management, &management_fds, &management_fds_length, config->non_blocking, config->nodelay, config->backlog))
{
pgagroal_log_fatal("pgagroal: Could not bind to %s:%d", config->common.host, config->management);
goto error;
Expand Down
Loading

0 comments on commit 4a82850

Please sign in to comment.