msg_info ("abnormally closing connection from backend: %s:%s, "
"error: %e",
bk_conn->mirror->name,
- rspamd_inet_address_to_string (rspamd_upstream_addr (bk_conn->up)),
+ rspamd_inet_address_to_string (rspamd_upstream_addr_cur (bk_conn->up)),
err);
fuzzy_mirror_close_connection (bk_conn);
}
conn->sock = rspamd_inet_address_connect (
- rspamd_upstream_addr (conn->up),
+ rspamd_upstream_addr_next (conn->up),
SOCK_STREAM, TRUE);
if (conn->sock == -1) {
void *serv;
struct rdns_upstream_elt *elt;
- addr = rspamd_upstream_addr (up);
+ addr = rspamd_upstream_addr_next (up);
if (r->cfg) {
serv = rdns_resolver_add_server (r->r, rspamd_inet_address_to_string (addr),
0);
session->up = up;
- addr = rspamd_upstream_addr (up);
+ addr = rspamd_upstream_addr_next (up);
g_assert (addr != NULL);
session->ctx = rspamd_redis_pool_connect (backend->pool,
backend->dbname, backend->password,
0);
session->up = up;
- addr = rspamd_upstream_addr (up);
+ addr = rspamd_upstream_addr_next (up);
g_assert (addr != NULL);
session->ctx = rspamd_redis_pool_connect (backend->pool,
backend->dbname, backend->password,
0);
session->up = up;
- addr = rspamd_upstream_addr (up);
+ addr = rspamd_upstream_addr_next (up);
g_assert (addr != NULL);
session->ctx = rspamd_redis_pool_connect (backend->pool,
backend->dbname, backend->password,
0);
session->up = up;
- addr = rspamd_upstream_addr (up);
+ addr = rspamd_upstream_addr_next (up);
g_assert (addr != NULL);
session->ctx = rspamd_redis_pool_connect (backend->pool,
backend->dbname, backend->password,
0);
g_assert (cbdata->selected != NULL);
- addr = rspamd_upstream_addr (cbdata->selected);
+ addr = rspamd_upstream_addr_next (cbdata->selected);
g_assert (addr != NULL);
if (rspamd_inet_address_get_af (addr) == AF_UNIX) {
rt->stcf = stcf;
rt->redis_object_expanded = object_expanded;
- addr = rspamd_upstream_addr (up);
+ addr = rspamd_upstream_addr_next (up);
g_assert (addr != NULL);
if (rspamd_inet_address_get_af (addr) == AF_UNIX) {
}
}
- addr = rspamd_upstream_addr (up);
+ addr = rspamd_upstream_addr_next (up);
g_assert (addr != NULL);
if (rspamd_inet_address_get_af (addr) == AF_UNIX) {
rt->task = task;
rt->ctx = ctx;
- addr = rspamd_upstream_addr (up);
+ addr = rspamd_upstream_addr_next (up);
g_assert (addr != NULL);
if (rspamd_inet_address_get_af (addr) == AF_UNIX) {
}
rspamd_inet_addr_t*
-rspamd_upstream_addr (struct upstream *up)
+rspamd_upstream_addr_next (struct upstream *up)
{
guint idx, next_idx;
struct upstream_addr_elt *e1, *e2;
return e2->addr;
}
+rspamd_inet_addr_t*
+rspamd_upstream_addr_cur (const struct upstream *up)
+{
+ return g_ptr_array_index (up->addrs.addr, up->addrs.cur);
+}
+
const gchar*
rspamd_upstream_name (struct upstream *up)
{
GFreeFunc free_func,
gpointer ud);
+/**
+ * Returns the next IP address of the upstream (internal rotation)
+ * @param up
+ * @return
+ */
+rspamd_inet_addr_t* rspamd_upstream_addr_next (struct upstream *up);
+
/**
* Returns the current IP address of the upstream
* @param up
* @return
*/
-rspamd_inet_addr_t* rspamd_upstream_addr (struct upstream *up);
+rspamd_inet_addr_t* rspamd_upstream_addr_cur (const struct upstream *up);
/**
* Add custom address for an upstream (ownership of addr is transferred to upstream)
struct upstream *up = lua_check_upstream (L);
if (up) {
- rspamd_lua_ip_push (L, rspamd_upstream_addr (up));
+ rspamd_lua_ip_push (L, rspamd_upstream_addr_next (up));
}
else {
lua_pushnil (L);
msg_err_task ("got error on IO with server %s(%s), on %s, %d, %s",
rspamd_upstream_name (session->server),
rspamd_inet_address_to_string_pretty (
- rspamd_upstream_addr (session->server)),
+ rspamd_upstream_addr_cur (session->server)),
session->state == 1 ? "read" : "write",
errno,
strerror (errno));
msg_err_task ("got IO timeout with server %s(%s), after %d retransmits",
rspamd_upstream_name (session->server),
rspamd_inet_address_to_string_pretty (
- rspamd_upstream_addr (session->server)),
+ rspamd_upstream_addr_cur (session->server)),
session->retransmits);
rspamd_upstream_fail (session->server, FALSE);
if (session->item) {
msg_err_task ("got error in IO with server %s(%s), %d, %s",
rspamd_upstream_name (session->server),
rspamd_inet_address_to_string_pretty (
- rspamd_upstream_addr (session->server)),
+ rspamd_upstream_addr_cur (session->server)),
errno, strerror (errno));
rspamd_upstream_fail (session->server, FALSE);
}
"after %d retransmits",
rspamd_upstream_name (session->server),
rspamd_inet_address_to_string_pretty (
- rspamd_upstream_addr (session->server)),
+ rspamd_upstream_addr_cur (session->server)),
session->retransmits);
if (session->session) {
selected = rspamd_upstream_get (rule->servers, RSPAMD_UPSTREAM_ROUND_ROBIN,
NULL, 0);
if (selected) {
- addr = rspamd_upstream_addr (selected);
+ addr = rspamd_upstream_addr_next (selected);
if ((sock = rspamd_inet_address_connect (addr, SOCK_DGRAM, TRUE)) == -1) {
msg_warn_task ("cannot connect to %s(%s), %d, %s",
rspamd_upstream_name (selected),
while ((selected = rspamd_upstream_get (rule->servers,
RSPAMD_UPSTREAM_SEQUENTIAL, NULL, 0))) {
/* Create UDP socket */
- addr = rspamd_upstream_addr (selected);
+ addr = rspamd_upstream_addr_next (selected);
if ((sock = rspamd_inet_address_connect (addr,
SOCK_DGRAM, TRUE)) == -1) {
while ((selected = rspamd_upstream_get (rule->servers,
RSPAMD_UPSTREAM_SEQUENTIAL, NULL, 0))) {
/* Create UDP socket */
- addr = rspamd_upstream_addr (selected);
+ addr = rspamd_upstream_addr_next (selected);
if ((sock = rspamd_inet_address_connect (addr,
SOCK_DGRAM, TRUE)) == -1) {
task = param->task;
msg_err_surbl ("connection with http server %s terminated incorrectly: %e",
- rspamd_inet_address_to_string (rspamd_upstream_addr (param->redirector)),
+ rspamd_inet_address_to_string (
+ rspamd_upstream_addr_cur (param->redirector)),
err);
rspamd_upstream_fail (param->redirector, FALSE);
rspamd_session_remove_event (param->task->s, free_redirector_session,
RSPAMD_UPSTREAM_ROUND_ROBIN, url->host, url->hostlen);
if (selected) {
- s = rspamd_inet_address_connect (rspamd_upstream_addr (selected),
+ s = rspamd_inet_address_connect (rspamd_upstream_addr_next (selected),
SOCK_STREAM, TRUE);
}
msg_info_session ("abnormally closing connection from backend: %s:%s, "
"error: %e",
bk_conn->name,
- rspamd_inet_address_to_string (rspamd_upstream_addr (bk_conn->up)),
+ rspamd_inet_address_to_string (
+ rspamd_upstream_addr_cur (bk_conn->up)),
err);
if (err) {
bk_conn->parser_from_ref, msg->body_buf.begin, msg->body_buf.len)) {
msg_warn_session ("cannot parse results from the mirror backend %s:%s",
bk_conn->name,
- rspamd_inet_address_to_string (rspamd_upstream_addr (bk_conn->up)));
+ rspamd_inet_address_to_string (
+ rspamd_upstream_addr_cur (bk_conn->up)));
bk_conn->err = "cannot parse ucl";
}
}
bk_conn->backend_sock = rspamd_inet_address_connect (
- rspamd_upstream_addr (bk_conn->up),
+ rspamd_upstream_addr_next (bk_conn->up),
SOCK_STREAM, TRUE);
if (bk_conn->backend_sock == -1) {
if (m->local ||
rspamd_inet_address_is_local (
- rspamd_upstream_addr (bk_conn->up), FALSE)) {
+ rspamd_upstream_addr_cur (bk_conn->up), FALSE)) {
if (session->fname) {
rspamd_http_message_add_header (msg, "File", session->fname);
session = bk_conn->s;
msg_info_session ("abnormally closing connection from backend: %s, error: %e,"
" retries left: %d",
- rspamd_inet_address_to_string (rspamd_upstream_addr (session->master_conn->up)),
+ rspamd_inet_address_to_string (
+ rspamd_upstream_addr_cur (session->master_conn->up)),
err,
session->ctx->max_retries - session->retries);
session->retries ++;
msg_info_session ("retry connection to: %s"
" retries left: %d",
rspamd_inet_address_to_string (
- rspamd_upstream_addr (session->master_conn->up)),
+ rspamd_upstream_addr_cur (session->master_conn->up)),
session->ctx->max_retries - session->retries);
}
}
}
session->master_conn->backend_sock = rspamd_inet_address_connect (
- rspamd_upstream_addr (session->master_conn->up),
+ rspamd_upstream_addr_next (session->master_conn->up),
SOCK_STREAM, TRUE);
if (session->master_conn->backend_sock == -1) {
msg_err_session ("cannot connect upstream: %s(%s)",
host ? hostbuf : "default",
- rspamd_inet_address_to_string (rspamd_upstream_addr (
- session->master_conn->up)));
+ rspamd_inet_address_to_string (
+ rspamd_upstream_addr_cur (
+ session->master_conn->up)));
rspamd_upstream_fail (session->master_conn->up, TRUE);
session->retries ++;
goto retry;
if (backend->local ||
rspamd_inet_address_is_local (
- rspamd_upstream_addr (session->master_conn->up), FALSE)) {
+ rspamd_upstream_addr_cur (
+ session->master_conn->up), FALSE)) {
if (session->fname) {
rspamd_http_message_add_header (msg, "File", session->fname);
rspamd_parse_inet_address (&paddr, "::1", 0);
g_assert (rspamd_upstream_add_addr (up, paddr));
/* Rewind to start */
- addr = rspamd_upstream_addr (up);
- addr = rspamd_upstream_addr (up);
+ addr = rspamd_upstream_addr_next (up);
+ addr = rspamd_upstream_addr_next (up);
/* cur should be zero here */
- addr = rspamd_upstream_addr (up);
- next_addr = rspamd_upstream_addr (up);
+ addr = rspamd_upstream_addr_next (up);
+ next_addr = rspamd_upstream_addr_next (up);
g_assert (rspamd_inet_address_get_af (addr) == AF_INET);
g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET);
- next_addr = rspamd_upstream_addr (up);
+ next_addr = rspamd_upstream_addr_next (up);
g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET6);
- next_addr = rspamd_upstream_addr (up);
+ next_addr = rspamd_upstream_addr_next (up);
g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET);
- next_addr = rspamd_upstream_addr (up);
+ next_addr = rspamd_upstream_addr_next (up);
g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET);
- next_addr = rspamd_upstream_addr (up);
+ next_addr = rspamd_upstream_addr_next (up);
g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET6);
/* Test errors with IPv6 */
rspamd_upstream_fail (up, TRUE);
/* Now we should have merely IPv4 addresses in rotation */
- addr = rspamd_upstream_addr (up);
+ addr = rspamd_upstream_addr_next (up);
for (i = 0; i < 256; i++) {
- next_addr = rspamd_upstream_addr (up);
+ next_addr = rspamd_upstream_addr_next (up);
g_assert (rspamd_inet_address_get_af (addr) == AF_INET);
g_assert (rspamd_inet_address_get_af (next_addr) == AF_INET);
g_assert (rspamd_inet_address_compare (addr, next_addr) != 0);