diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-12 19:08:42 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-12 19:08:42 +0000 |
commit | 074d28ebc2c4b5ab952e74b9a815e0a55c26110a (patch) | |
tree | 452b73366ec4ba53eab3ebd7e054946ef28068b2 /src | |
parent | 548833c06eb83565a79166a0921e428bd88af2bd (diff) | |
download | rspamd-074d28ebc2c4b5ab952e74b9a815e0a55c26110a.tar.gz rspamd-074d28ebc2c4b5ab952e74b9a815e0a55c26110a.zip |
Fix sorting order and unit test for upstreams.
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/addr.c | 25 | ||||
-rw-r--r-- | src/libutil/addr.h | 8 | ||||
-rw-r--r-- | src/libutil/upstream.c | 9 | ||||
-rw-r--r-- | src/main.c | 2 |
4 files changed, 30 insertions, 14 deletions
diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 19eda5a13..c2bb3db9c 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -349,6 +349,12 @@ rspamd_parse_inet_address (rspamd_inet_addr_t **target, const char *src) if (src[0] == '/' || src[0] == '.') { return rspamd_parse_unix_path (target, src); } + else if (inet_pton (AF_INET, src, &su.s4.sin_addr) == 1) { + addr = rspamd_inet_addr_create (AF_INET); + memcpy (&addr->u.in.addr.s4.sin_addr, &su.s4.sin_addr, + sizeof (struct in_addr)); + ret = TRUE; + } else if (ipv6_status == RSPAMD_IPV6_SUPPORTED && inet_pton (AF_INET6, src, &su.s6.sin6_addr) == 1) { addr = rspamd_inet_addr_create (AF_INET6); @@ -356,12 +362,6 @@ rspamd_parse_inet_address (rspamd_inet_addr_t **target, const char *src) sizeof (struct in6_addr)); ret = TRUE; } - else if (inet_pton (AF_INET, src, &su.s4.sin_addr) == 1) { - addr = rspamd_inet_addr_create (AF_INET6); - memcpy (&addr->u.in.addr.s4.sin_addr, &su.s4.sin_addr, - sizeof (struct in_addr)); - ret = TRUE; - } if (ret && target) { *target = addr; @@ -918,8 +918,8 @@ rspamd_inet_address_compare (const rspamd_inet_addr_t *a1, g_assert (a2 != NULL); if (a1->af != a2->af) { - return (rspamd_inet_address_af_order (a1) - - rspamd_inet_address_af_order (a2)); + return (rspamd_inet_address_af_order (a2) - + rspamd_inet_address_af_order (a1)); } else { switch (a1->af) { @@ -940,6 +940,15 @@ rspamd_inet_address_compare (const rspamd_inet_addr_t *a1, return 0; } +gint +rspamd_inet_address_compare_ptr (const gpointer a1, + const gpointer a2) +{ + const rspamd_inet_addr_t **i1 = a1, **i2 = a2; + + return rspamd_inet_address_compare (*i1, *i2); +} + rspamd_inet_addr_t * rspamd_inet_address_copy (const rspamd_inet_addr_t *addr) { diff --git a/src/libutil/addr.h b/src/libutil/addr.h index dd5b6adb6..1ea0ab8b5 100644 --- a/src/libutil/addr.h +++ b/src/libutil/addr.h @@ -197,6 +197,14 @@ gint rspamd_inet_address_compare (const rspamd_inet_addr_t *a1, const rspamd_inet_addr_t *a2); /** + * Utility function to compare addresses by in g_ptr_array + * @param a1 + * @param a2 + * @return + */ +gint rspamd_inet_address_compare_ptr (const gpointer a1, + const gpointer a2); +/** * Performs deep copy of rspamd inet addr * @param addr * @return diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c index 6c962c357..6aa447042 100644 --- a/src/libutil/upstream.c +++ b/src/libutil/upstream.c @@ -130,12 +130,12 @@ rspamd_upstream_af_to_weight (const rspamd_inet_addr_t *addr) static gint rspamd_upstream_addr_sort_func (gconstpointer a, gconstpointer b) { - const rspamd_inet_addr_t *ip1 = (const rspamd_inet_addr_t *)a, - *ip2 = (const rspamd_inet_addr_t *)b; + const rspamd_inet_addr_t **ip1 = (const rspamd_inet_addr_t **)a, + **ip2 = (const rspamd_inet_addr_t **)b; gint w1, w2; - w1 = rspamd_upstream_af_to_weight (ip1); - w2 = rspamd_upstream_af_to_weight (ip2); + w1 = rspamd_upstream_af_to_weight (*ip1); + w2 = rspamd_upstream_af_to_weight (*ip2); return w2 - w1; } @@ -381,7 +381,6 @@ rspamd_upstream_dtor (struct upstream *up) rspamd_mutex_free (up->lock); g_free (up->name); - g_free (up->addrs.addr); g_slice_free1 (sizeof (*up), up); } diff --git a/src/main.c b/src/main.c index 0864ab395..373c01695 100644 --- a/src/main.c +++ b/src/main.c @@ -576,7 +576,7 @@ create_listen_socket (GPtrArray *addrs, guint cnt, gint listen_type) gint fd; guint i; - g_ptr_array_sort (addrs, (GCompareFunc)rspamd_inet_address_compare); + g_ptr_array_sort (addrs, rspamd_inet_address_compare_ptr); for (i = 0; i < cnt; i ++) { fd = rspamd_inet_address_listen (g_ptr_array_index (addrs, i), listen_type, TRUE); |