Skip to content

Commit

Permalink
Add application_name_add_host setting
Browse files Browse the repository at this point in the history
  • Loading branch information
x4m authored and reshke committed Jan 20, 2020
1 parent 2bacfcb commit e773dbb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
8 changes: 7 additions & 1 deletion odyssey.conf
Expand Up @@ -435,7 +435,7 @@ database default {
# "session" - assign server connection to a client until it disconnects
# "transaction" - assign server connection to a client during a transaction lifetime
#
pool "session"
pool "transaction"

#
# Server pool size.
Expand Down Expand Up @@ -495,6 +495,12 @@ database default {
#
client_fwd_error yes

#
# Add client host name to application_name parameter
#

application_name_add_host yes

#
# Enable verbose mode for a specific route only.
#
Expand Down
7 changes: 7 additions & 0 deletions sources/config_reader.c
Expand Up @@ -67,6 +67,7 @@ enum
OD_LCLIENT_MAX_ROUTING,
OD_LCLIENT_LOGIN_TIMEOUT,
OD_LCLIENT_FWD_ERROR,
OD_LAPPLICATION_NAME_ADD_HOST,
OD_LTLS,
OD_LTLS_CA_FILE,
OD_LTLS_KEY_FILE,
Expand Down Expand Up @@ -153,6 +154,7 @@ od_config_keywords[] =
od_keyword("client_max_routing", OD_LCLIENT_MAX_ROUTING),
od_keyword("client_login_timeout", OD_LCLIENT_LOGIN_TIMEOUT),
od_keyword("client_fwd_error", OD_LCLIENT_FWD_ERROR),
od_keyword("application_name_add_host", OD_LAPPLICATION_NAME_ADD_HOST),
od_keyword("tls", OD_LTLS),
od_keyword("tls_ca_file", OD_LTLS_CA_FILE),
od_keyword("tls_key_file", OD_LTLS_KEY_FILE),
Expand Down Expand Up @@ -693,6 +695,11 @@ od_config_reader_route(od_config_reader_t *reader, char *db_name, int db_name_le
if (! od_config_reader_yes_no(reader, &route->client_fwd_error))
return -1;
continue;
/* application_name_add_host */
case OD_LAPPLICATION_NAME_ADD_HOST:
if (! od_config_reader_yes_no(reader, &route->application_name_add_host))
return -1;
continue;
/* pool */
case OD_LPOOL:
if (! od_config_reader_string(reader, &route->pool_sz))
Expand Down
16 changes: 16 additions & 0 deletions sources/frontend.c
Expand Up @@ -876,6 +876,20 @@ od_frontend_cleanup(od_client_t *client, char *context,
}
}

static void od_application_name_add_host(od_client_t *client) {
if (client == NULL || client->io.io == NULL)
return;
char app_name[KIWI_MAX_VAR_SIZE];
char peer_name[KIWI_MAX_VAR_SIZE];
kiwi_var_t *app_name_var = kiwi_vars_get(&client->vars, KIWI_VAR_APPLICATION_NAME);
if (app_name_var == NULL)
return;
od_getpeername(client->io.io, peer_name, sizeof(peer_name), 1, 0); //return code ignored

int length = od_snprintf(app_name, 256, "%.*s - %s", app_name_var->value_len, app_name_var->value, peer_name);
kiwi_var_set(app_name_var, KIWI_VAR_APPLICATION_NAME, app_name, length + 1); //return code ignored
}

void
od_frontend(void *arg)
{
Expand Down Expand Up @@ -1005,6 +1019,8 @@ od_frontend(void *arg)
case OD_ROUTER_OK:
{
od_route_t *route = client->route;
if (route->rule->application_name_add_host)
od_application_name_add_host(client);
if (instance->config.log_session) {
od_log(&instance->logger, "startup", client, NULL,
"route '%s.%s' to '%s.%s'",
Expand Down
1 change: 1 addition & 0 deletions sources/rules.h
Expand Up @@ -113,6 +113,7 @@ struct od_rule
int pool_rollback;
/* misc */
int client_fwd_error;
int application_name_add_host;
int client_max_set;
int client_max;
int log_debug;
Expand Down
4 changes: 3 additions & 1 deletion third_party/kiwi/kiwi/var.h
Expand Up @@ -7,6 +7,8 @@
* postgreSQL protocol interaction library.
*/

#define KIWI_MAX_VAR_SIZE 128

typedef struct kiwi_var kiwi_var_t;
typedef struct kiwi_vars kiwi_vars_t;

Expand All @@ -25,7 +27,7 @@ struct kiwi_var
kiwi_var_type_t type;
char *name;
int name_len;
char value[128];
char value[KIWI_MAX_VAR_SIZE];
int value_len;
};

Expand Down

0 comments on commit e773dbb

Please sign in to comment.