diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-02-23 14:37:27 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-02-23 14:37:27 +0000 |
commit | ee86574d474f4d58a9836c1991b86da562311d27 (patch) | |
tree | 467c79bdb417b26e8d9a2708265cd1ba848237d6 /src/client | |
parent | 46ca7a84233f88918faf06d8fe5ef3b5d18ba2d3 (diff) | |
download | rspamd-ee86574d474f4d58a9836c1991b86da562311d27.tar.gz rspamd-ee86574d474f4d58a9836c1991b86da562311d27.zip |
[Feature] Use controller port by default when connecting to local IP
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/rspamc.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c index bcc302f95..ff5f23819 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -1594,13 +1594,6 @@ rspamc_process_input (struct event_base *ev_base, struct rspamc_command *cmd, p = strrchr (p, ':'); - if (p != NULL) { - port = strtoul (p + 1, NULL, 10); - } - else { - port = cmd->is_controller ? DEFAULT_CONTROL_PORT : DEFAULT_PORT; - } - if (!hostbuf) { if (p != NULL) { hostbuf = g_malloc (p - connect_str + 1); @@ -1611,6 +1604,27 @@ rspamc_process_input (struct event_base *ev_base, struct rspamc_command *cmd, } } + if (p != NULL) { + port = strtoul (p + 1, NULL, 10); + } + else { + /* + * If we connect to localhost, 127.0.0.1 or ::1, then try controller + * port first + */ + + if (strcmp (hostbuf, "localhost") == 0 || + strcmp (hostbuf, "127.0.0.1") == 0 || + strcmp (hostbuf, "::1") == 0 || + strcmp (hostbuf, "[::1]") == 0) { + port = DEFAULT_CONTROL_PORT; + } + else { + port = cmd->is_controller ? DEFAULT_CONTROL_PORT : DEFAULT_PORT; + } + + } + conn = rspamd_client_init (ev_base, hostbuf, port, timeout, key); if (conn != NULL) { |