aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ReleaseNotes2
-rw-r--r--changes/bug152963
-rw-r--r--changes/bug155154
-rw-r--r--changes/feature154715
-rw-r--r--changes/ticket1471010
-rw-r--r--changes/ticket154316
-rw-r--r--src/common/address.c99
-rw-r--r--src/common/address.h3
-rw-r--r--src/common/compat.c20
-rw-r--r--src/common/compat.h10
-rw-r--r--src/common/util.c18
-rw-r--r--src/or/control.c2
-rw-r--r--src/or/control.h23
-rw-r--r--src/or/or.h3
-rw-r--r--src/or/rendcommon.c1
-rw-r--r--src/or/rendmid.c13
-rw-r--r--src/test/test_address.c176
-rw-r--r--src/test/test_controller_events.c99
18 files changed, 449 insertions, 48 deletions
diff --git a/ReleaseNotes b/ReleaseNotes
index 6c91262811..18bb8f20f5 100644
--- a/ReleaseNotes
+++ b/ReleaseNotes
@@ -858,6 +858,8 @@ Changes in version 0.2.6.6 - 2015-03-24
- Refactor our generic strmap and digestmap types into a single
implementation, so that we can add a new digest256map
type trivially.
+
+ o Documentation:
- Add a doc/TUNING document with tips for handling large numbers of
TCP connections when running busy Tor relay. Update the warning
message to point to this file when running out of sockets
diff --git a/changes/bug15296 b/changes/bug15296
new file mode 100644
index 0000000000..5230a419c1
--- /dev/null
+++ b/changes/bug15296
@@ -0,0 +1,3 @@
+ o Minor bugfixes (hidden service):
+ - Remove an extraneous newline character from the end of hidden
+ service descriptors. Fixes bug 15296; bugfix on 0.2.0.10-alpha.
diff --git a/changes/bug15515 b/changes/bug15515
new file mode 100644
index 0000000000..dda7c2fcd8
--- /dev/null
+++ b/changes/bug15515
@@ -0,0 +1,4 @@
+ o Minor features (DoS-resistance):
+ - Make it harder for attackers to overwhelm hidden services with
+ introductions, by blocking multiple introduction requests on the
+ same circuit. Resolves ticket #15515.
diff --git a/changes/feature15471 b/changes/feature15471
new file mode 100644
index 0000000000..594adf0f54
--- /dev/null
+++ b/changes/feature15471
@@ -0,0 +1,5 @@
+ o Minor features (pluggable transports):
+ - When launching managed pluggable transports on linux systems,
+ attempt to have the kernel deliver a SIGTERM on tor exit if
+ the pluggable transport process is still running. Resolves
+ ticket 15471.
diff --git a/changes/ticket14710 b/changes/ticket14710
new file mode 100644
index 0000000000..2b6cb2060f
--- /dev/null
+++ b/changes/ticket14710
@@ -0,0 +1,10 @@
+ o Code simplification and refactoring:
+ - Move the hacky fallback code out of get_interface_address6()
+ into separate function and get it covered with unit-tests. Resolves
+ ticket 14710.
+
+ o Minor bugfixes:
+ - When attempting to use fallback technique for network interface
+ lookup, disregard loopback and multicast addresses since they are
+ unsuitable for public communications.
+
diff --git a/changes/ticket15431 b/changes/ticket15431
new file mode 100644
index 0000000000..ea6821afdf
--- /dev/null
+++ b/changes/ticket15431
@@ -0,0 +1,6 @@
+ o Minor features (testing):
+ - Add unit tests for control_event_is_interesting().
+ Add a compile-time check that the number of events doesn't exceed
+ the capacity of control_event_t.event_mask.
+ Closes ticket 15431, checks for bugs similar to 13085.
+ Patch by "teor".
diff --git a/src/common/address.c b/src/common/address.c
index 42a116a91e..6bd107889a 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -1504,47 +1504,22 @@ tor_addr_is_multicast(const tor_addr_t *a)
return 0;
}
-/** Set *<b>addr</b> to the IP address (if any) of whatever interface
- * connects to the Internet. This address should only be used in checking
- * whether our address has changed. Return 0 on success, -1 on failure.
+/** Attempt to retrieve IP address of current host by utilizing some
+ * UDP socket trickery. Only look for address of given <b>family</b>.
+ * Set result to *<b>addr</b>. Return 0 on success, -1 on failure.
*/
-MOCK_IMPL(int,
-get_interface_address6,(int severity, sa_family_t family, tor_addr_t *addr))
+STATIC int
+get_interface_address6_via_udp_socket_hack(int severity,
+ sa_family_t family,
+ tor_addr_t *addr)
{
- /* XXX really, this function should yield a smartlist of addresses. */
- smartlist_t *addrs;
- int sock=-1, r=-1;
struct sockaddr_storage my_addr, target_addr;
+ int sock=-1, r=-1;
socklen_t addr_len;
- tor_assert(addr);
-
- /* Try to do this the smart way if possible. */
- if ((addrs = get_interface_addresses_raw(severity))) {
- int rv = -1;
- SMARTLIST_FOREACH_BEGIN(addrs, tor_addr_t *, a) {
- if (family != AF_UNSPEC && family != tor_addr_family(a))
- continue;
- if (tor_addr_is_loopback(a) ||
- tor_addr_is_multicast(a))
- continue;
- tor_addr_copy(addr, a);
- rv = 0;
-
- /* If we found a non-internal address, declare success. Otherwise,
- * keep looking. */
- if (!tor_addr_is_internal(a, 0))
- break;
- } SMARTLIST_FOREACH_END(a);
-
- SMARTLIST_FOREACH(addrs, tor_addr_t *, a, tor_free(a));
- smartlist_free(addrs);
- return rv;
- }
-
- /* Okay, the smart way is out. */
memset(addr, 0, sizeof(tor_addr_t));
memset(&target_addr, 0, sizeof(target_addr));
+
/* Don't worry: no packets are sent. We just need to use a real address
* on the actual Internet. */
if (family == AF_INET6) {
@@ -1566,6 +1541,7 @@ get_interface_address6,(int severity, sa_family_t family, tor_addr_t *addr))
} else {
return -1;
}
+
if (sock < 0) {
int e = tor_socket_errno(-1);
log_fn(severity, LD_NET, "unable to create socket: %s",
@@ -1573,27 +1549,74 @@ get_interface_address6,(int severity, sa_family_t family, tor_addr_t *addr))
goto err;
}
- if (connect(sock,(struct sockaddr *)&target_addr, addr_len) < 0) {
+ if (tor_connect_socket(sock,(struct sockaddr *)&target_addr,
+ addr_len) < 0) {
int e = tor_socket_errno(sock);
log_fn(severity, LD_NET, "connect() failed: %s", tor_socket_strerror(e));
goto err;
}
- if (getsockname(sock,(struct sockaddr*)&my_addr, &addr_len)) {
+ if (tor_getsockname(sock,(struct sockaddr*)&my_addr, &addr_len)) {
int e = tor_socket_errno(sock);
log_fn(severity, LD_NET, "getsockname() to determine interface failed: %s",
tor_socket_strerror(e));
goto err;
}
- tor_addr_from_sockaddr(addr, (struct sockaddr*)&my_addr, NULL);
- r=0;
+ if (tor_addr_from_sockaddr(addr, (struct sockaddr*)&my_addr, NULL) == 0) {
+ if (tor_addr_is_loopback(addr) || tor_addr_is_multicast(addr)) {
+ log_fn(severity, LD_NET, "Address that we determined via UDP socket"
+ " magic is unsuitable for public comms.");
+ } else {
+ r=0;
+ }
+ }
+
err:
if (sock >= 0)
tor_close_socket(sock);
return r;
}
+/** Set *<b>addr</b> to the IP address (if any) of whatever interface
+ * connects to the Internet. This address should only be used in checking
+ * whether our address has changed. Return 0 on success, -1 on failure.
+ */
+MOCK_IMPL(int,
+get_interface_address6,(int severity, sa_family_t family, tor_addr_t *addr))
+{
+ /* XXX really, this function should yield a smartlist of addresses. */
+ smartlist_t *addrs;
+ tor_assert(addr);
+
+ /* Try to do this the smart way if possible. */
+ if ((addrs = get_interface_addresses_raw(severity))) {
+ int rv = -1;
+ SMARTLIST_FOREACH_BEGIN(addrs, tor_addr_t *, a) {
+ if (family != AF_UNSPEC && family != tor_addr_family(a))
+ continue;
+ if (tor_addr_is_loopback(a) ||
+ tor_addr_is_multicast(a))
+ continue;
+
+ tor_addr_copy(addr, a);
+ rv = 0;
+
+ /* If we found a non-internal address, declare success. Otherwise,
+ * keep looking. */
+ if (!tor_addr_is_internal(a, 0))
+ break;
+ } SMARTLIST_FOREACH_END(a);
+
+ SMARTLIST_FOREACH(addrs, tor_addr_t *, a, tor_free(a));
+ smartlist_free(addrs);
+ return rv;
+ }
+
+ /* Okay, the smart way is out. */
+ return get_interface_address6_via_udp_socket_hack(severity,family,addr);
+}
+
/* ======
* IPv4 helpers
* XXXX024 IPv6 deprecate some of these.
diff --git a/src/common/address.h b/src/common/address.h
index df835e917a..cd80615f93 100644
--- a/src/common/address.h
+++ b/src/common/address.h
@@ -274,6 +274,9 @@ tor_addr_port_t *tor_addr_port_new(const tor_addr_t *addr, uint16_t port);
#ifdef ADDRESS_PRIVATE
STATIC smartlist_t *get_interface_addresses_raw(int severity);
+STATIC int get_interface_address6_via_udp_socket_hack(int severity,
+ sa_family_t family,
+ tor_addr_t *addr);
#ifdef HAVE_IFADDRS_TO_SMARTLIST
STATIC smartlist_t *ifaddrs_to_smartlist(const struct ifaddrs *ifa);
diff --git a/src/common/compat.c b/src/common/compat.c
index 1788e32ee3..8da7ef3f69 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -1156,12 +1156,20 @@ mark_socket_open(tor_socket_t s)
/** @} */
/** As socket(), but counts the number of open sockets. */
-tor_socket_t
-tor_open_socket(int domain, int type, int protocol)
+MOCK_IMPL(tor_socket_t,
+tor_open_socket,(int domain, int type, int protocol))
{
return tor_open_socket_with_extensions(domain, type, protocol, 1, 0);
}
+/** Mockable wrapper for connect(). */
+MOCK_IMPL(tor_socket_t,
+tor_connect_socket,(tor_socket_t socket,const struct sockaddr *address,
+ socklen_t address_len))
+{
+ return connect(socket,address,address_len);
+}
+
/** As socket(), but creates a nonblocking socket and
* counts the number of open sockets. */
tor_socket_t
@@ -1308,6 +1316,14 @@ get_n_open_sockets(void)
return n;
}
+/** Mockable wrapper for getsockname(). */
+MOCK_IMPL(int,
+tor_getsockname,(tor_socket_t socket, struct sockaddr *address,
+ socklen_t *address_len))
+{
+ return getsockname(socket, address, address_len);
+}
+
/** Turn <b>socket</b> into a nonblocking socket. Return 0 on success, -1
* on failure.
*/
diff --git a/src/common/compat.h b/src/common/compat.h
index 11b41cded9..5189b7e056 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -463,7 +463,8 @@ int tor_close_socket(tor_socket_t s);
tor_socket_t tor_open_socket_with_extensions(
int domain, int type, int protocol,
int cloexec, int nonblock);
-tor_socket_t tor_open_socket(int domain, int type, int protocol);
+MOCK_DECL(tor_socket_t,
+tor_open_socket,(int domain, int type, int protocol));
tor_socket_t tor_open_socket_nonblocking(int domain, int type, int protocol);
tor_socket_t tor_accept_socket(tor_socket_t sockfd, struct sockaddr *addr,
socklen_t *len);
@@ -474,8 +475,15 @@ tor_socket_t tor_accept_socket_with_extensions(tor_socket_t sockfd,
struct sockaddr *addr,
socklen_t *len,
int cloexec, int nonblock);
+MOCK_DECL(tor_socket_t,
+tor_connect_socket,(tor_socket_t socket,const struct sockaddr *address,
+ socklen_t address_len));
int get_n_open_sockets(void);
+MOCK_DECL(int,
+tor_getsockname,(tor_socket_t socket, struct sockaddr *address,
+ socklen_t *address_len));
+
#define tor_socket_send(s, buf, len, flags) send(s, buf, len, flags)
#define tor_socket_recv(s, buf, len, flags) recv(s, buf, len, flags)
diff --git a/src/common/util.c b/src/common/util.c
index 7096e24bcc..7379da674d 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -95,6 +95,9 @@
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
+#if defined(HAVE_SYS_PRCTL_H) && defined(__linux__)
+#include <sys/prctl.h>
+#endif
#ifdef __clang_analyzer__
#undef MALLOC_ZERO_WORKS
@@ -4214,6 +4217,15 @@ tor_spawn_background(const char *const filename, const char **argv,
if (0 == pid) {
/* In child */
+#if defined(HAVE_SYS_PRCTL_H) && defined(__linux__)
+ /* Attempt to have the kernel issue a SIGTERM if the parent
+ * goes away. Certain attributes of the binary being execve()ed
+ * will clear this during the execve() call, but it's better
+ * than nothing.
+ */
+ prctl(PR_SET_PDEATHSIG, SIGTERM);
+#endif
+
child_state = CHILD_STATE_DUPOUT;
/* Link child stdout to the write end of the pipe */
@@ -4258,8 +4270,10 @@ tor_spawn_background(const char *const filename, const char **argv,
does not modify the arguments */
if (env)
execve(filename, (char *const *) argv, env->unixoid_environment_block);
- else
- execvp(filename, (char *const *) argv);
+ else {
+ static char *new_env[] = { NULL };
+ execve(filename, (char *const *) argv, new_env);
+ }
/* If we got here, the exec or open(/dev/null) failed */
diff --git a/src/or/control.c b/src/or/control.c
index 34d539bcc4..5ec97bd9af 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -72,7 +72,7 @@ static int disable_log_messages = 0;
/** Macro: true if any control connection is interested in events of type
* <b>e</b>. */
#define EVENT_IS_INTERESTING(e) \
- (!! (global_event_mask & (((uint64_t)1)<<(e))))
+ (!! (global_event_mask & EVENT_MASK_(e)))
/** If we're using cookie-type authentication, how long should our cookies be?
*/
diff --git a/src/or/control.h b/src/or/control.h
index 47a601817a..dbb80b1f20 100644
--- a/src/or/control.h
+++ b/src/or/control.h
@@ -123,6 +123,7 @@ void control_free_all(void);
* because it is used both as a list of v0 event types, and as indices
* into the bitfield to determine which controllers want which events.
*/
+/* This bitfield has no event zero 0x0000 */
#define EVENT_MIN_ 0x0001
#define EVENT_CIRCUIT_STATUS 0x0001
#define EVENT_STREAM_STATUS 0x0002
@@ -158,9 +159,29 @@ void control_free_all(void);
#define EVENT_TRANSPORT_LAUNCHED 0x0020
#define EVENT_HS_DESC 0x0021
#define EVENT_MAX_ 0x0021
-/* If EVENT_MAX_ ever hits 0x003F, we need to make the mask into a
+
+/* sizeof(control_connection_t.event_mask) in bits, currently a uint64_t */
+#define EVENT_CAPACITY_ 0x0040
+
+/* If EVENT_MAX_ ever hits 0x0040, we need to make the mask into a
* different structure, as it can only handle a maximum left shift of 1<<63. */
+#if EVENT_MAX_ >= EVENT_CAPACITY_
+#error control_connection_t.event_mask has an event greater than its capacity
+#endif
+
+#define EVENT_MASK_(e) (((uint64_t)1)<<(e))
+
+#define EVENT_MASK_NONE_ ((uint64_t)0x0)
+
+#define EVENT_MASK_ABOVE_MIN_ ((~((uint64_t)0x0)) << EVENT_MIN_)
+#define EVENT_MASK_BELOW_MAX_ ((~((uint64_t)0x0)) \
+ >> (EVENT_CAPACITY_ - EVENT_MAX_ \
+ - EVENT_MIN_))
+
+#define EVENT_MASK_ALL_ (EVENT_MASK_ABOVE_MIN_ \
+ & EVENT_MASK_BELOW_MAX_)
+
/* Used only by control.c and test.c */
STATIC size_t write_escaped_data(const char *data, size_t len, char **out);
STATIC size_t read_escaped_data(const char *data, size_t len, char **out);
diff --git a/src/or/or.h b/src/or/or.h
index f75e776730..2f0a7789ad 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3181,6 +3181,9 @@ typedef struct or_circuit_t {
* to the specification? */
unsigned int remaining_relay_early_cells : 4;
+ /* We have already received an INTRODUCE1 cell on this circuit. */
+ unsigned int already_received_introduce1 : 1;
+
/** True iff this circuit was made with a CREATE_FAST cell. */
unsigned int is_first_hop : 1;
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index 866f4fb026..174f1c4b04 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -646,7 +646,6 @@ rend_encode_v2_descriptors(smartlist_t *descs_out,
rend_encoded_v2_service_descriptor_free(enc);
goto err;
}
- desc_str[written++] = '\n';
desc_str[written++] = 0;
/* Check if we can parse our own descriptor. */
if (!rend_desc_v2_is_parsable(enc)) {
diff --git a/src/or/rendmid.c b/src/or/rendmid.c
index 9f6ff86c47..f85562e042 100644
--- a/src/or/rendmid.c
+++ b/src/or/rendmid.c
@@ -149,6 +149,19 @@ rend_mid_introduce(or_circuit_t *circ, const uint8_t *request,
goto err;
}
+ /* We have already done an introduction on this circuit but we just
+ received a request for another one. We block it since this might
+ be an attempt to DoS a hidden service (#15515). */
+ if (circ->already_received_introduce1) {
+ log_fn(LOG_PROTOCOL_WARN, LD_REND,
+ "Blocking multiple introductions on the same circuit. "
+ "Someone might be trying to attack a hidden service through "
+ "this relay.");
+ goto err;
+ }
+
+ circ->already_received_introduce1 = 1;
+
/* We could change this to MAX_HEX_NICKNAME_LEN now that 0.0.9.x is
* obsolete; however, there isn't much reason to do so, and we're going
* to revise this protocol anyway.
diff --git a/src/test/test_address.c b/src/test/test_address.c
index 424a6352b0..317119c52f 100644
--- a/src/test/test_address.c
+++ b/src/test/test_address.c
@@ -130,8 +130,8 @@ test_address_ifaddrs_to_smartlist(void *arg)
ipv6_sockaddr = tor_malloc(sizeof(struct sockaddr_in6));
ipv6_sockaddr->sin6_family = AF_INET6;
ipv6_sockaddr->sin6_port = 0;
- inet_pton(AF_INET6, "2001:db8:8714:3a90::12",
- &(ipv6_sockaddr->sin6_addr));
+ tor_inet_pton(AF_INET6, "2001:db8:8714:3a90::12",
+ &(ipv6_sockaddr->sin6_addr));
ifa = tor_malloc(sizeof(struct ifaddrs));
ifa_ipv4 = tor_malloc(sizeof(struct ifaddrs));
@@ -452,10 +452,182 @@ test_address_get_if_addrs_ioctl(void *arg)
#endif
+#define FAKE_SOCKET_FD (42)
+
+static tor_socket_t
+fake_open_socket(int domain, int type, int protocol)
+{
+ (void)domain;
+ (void)type;
+ (void)protocol;
+
+ return FAKE_SOCKET_FD;
+}
+
+static int last_connected_socket_fd = 0;
+
+static int connect_retval = 0;
+
+static tor_socket_t
+pretend_to_connect(tor_socket_t socket, const struct sockaddr *address,
+ socklen_t address_len)
+{
+ (void)address;
+ (void)address_len;
+
+ last_connected_socket_fd = socket;
+
+ return connect_retval;
+}
+
+static struct sockaddr *mock_addr = NULL;
+
+static int
+fake_getsockname(tor_socket_t socket, struct sockaddr *address,
+ socklen_t *address_len)
+{
+ socklen_t bytes_to_copy = 0;
+ (void) socket;
+
+ if (!mock_addr)
+ return -1;
+
+ if (mock_addr->sa_family == AF_INET) {
+ bytes_to_copy = sizeof(struct sockaddr_in);
+ } else if (mock_addr->sa_family == AF_INET6) {
+ bytes_to_copy = sizeof(struct sockaddr_in6);
+ } else {
+ return -1;
+ }
+
+ if (*address_len < bytes_to_copy) {
+ return -1;
+ }
+
+ memcpy(address,mock_addr,bytes_to_copy);
+ *address_len = bytes_to_copy;
+
+ return 0;
+}
+
+static void
+test_address_udp_socket_trick_whitebox(void *arg)
+{
+ int hack_retval;
+ tor_addr_t *addr_from_hack = tor_malloc_zero(sizeof(tor_addr_t));
+ struct sockaddr_in6 *mock_addr6;
+ struct sockaddr_in6 *ipv6_to_check =
+ tor_malloc_zero(sizeof(struct sockaddr_in6));
+
+ (void)arg;
+
+ MOCK(tor_open_socket,fake_open_socket);
+ MOCK(tor_connect_socket,pretend_to_connect);
+ MOCK(tor_getsockname,fake_getsockname);
+
+ mock_addr = tor_malloc_zero(sizeof(struct sockaddr_storage));
+ sockaddr_in_from_string("23.32.246.118",(struct sockaddr_in *)mock_addr);
+
+ hack_retval =
+ get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
+ AF_INET, addr_from_hack);
+
+ tt_int_op(hack_retval,==,0);
+ tt_assert(tor_addr_eq_ipv4h(addr_from_hack, 0x1720f676));
+
+ /* Now, lets do an IPv6 case. */
+ memset(mock_addr,0,sizeof(struct sockaddr_storage));
+
+ mock_addr6 = (struct sockaddr_in6 *)mock_addr;
+ mock_addr6->sin6_family = AF_INET6;
+ mock_addr6->sin6_port = 0;
+ tor_inet_pton(AF_INET6,"2001:cdba::3257:9652",&(mock_addr6->sin6_addr));
+
+ hack_retval =
+ get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
+ AF_INET6, addr_from_hack);
+
+ tt_int_op(hack_retval,==,0);
+
+ tor_addr_to_sockaddr(addr_from_hack,0,(struct sockaddr *)ipv6_to_check,
+ sizeof(struct sockaddr_in6));
+
+ tt_assert(sockaddr_in6_are_equal(mock_addr6,ipv6_to_check));
+
+ UNMOCK(tor_open_socket);
+ UNMOCK(tor_connect_socket);
+ UNMOCK(tor_getsockname);
+
+ done:
+ tor_free(ipv6_to_check);
+ tor_free(mock_addr);
+ tor_free(addr_from_hack);
+ return;
+}
+
+static void
+test_address_udp_socket_trick_blackbox(void *arg)
+{
+ /* We want get_interface_address6_via_udp_socket_hack() to yield
+ * the same valid address that get_interface_address6() returns.
+ * If the latter is unable to find a valid address, we want
+ * _hack() to fail and return-1.
+ *
+ * Furthermore, we want _hack() never to crash, even if
+ * get_interface_addresses_raw() is returning NULL.
+ */
+
+ tor_addr_t addr4;
+ tor_addr_t addr4_to_check;
+ tor_addr_t addr6;
+ tor_addr_t addr6_to_check;
+ int retval, retval_reference;
+
+ (void)arg;
+
+ retval_reference = get_interface_address6(LOG_DEBUG,AF_INET,&addr4);
+ retval = get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
+ AF_INET,
+ &addr4_to_check);
+
+ tt_int_op(retval,==,retval_reference);
+ tt_assert( (retval == -1 && retval_reference == -1) ||
+ (tor_addr_compare(&addr4,&addr4_to_check,CMP_EXACT) == 0) );
+
+ //[XXX: Skipping the AF_INET6 case because bug #12377 makes it fail.]
+ (void)addr6_to_check;
+ (void)addr6;
+#if 0
+ retval_reference = get_interface_address6(LOG_DEBUG,AF_INET6,&addr6);
+ retval = get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
+ AF_INET6,
+ &addr6_to_check);
+
+ tt_int_op(retval,==,retval_reference);
+ tt_assert( (retval == -1 && retval_reference == -1) ||
+ (tor_addr_compare(&addr6,&addr6_to_check,CMP_EXACT) == 0) );
+
+#endif
+
+ /* When family is neither AF_INET nor AF_INET6, we want _hack to
+ * fail and return -1.
+ */
+
+ retval = get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
+ AF_INET+AF_INET6,&addr4);
+
+ tt_assert(retval == -1);
+
+ done:
+ return;
+}
+
#define ADDRESS_TEST(name, flags) \
{ #name, test_address_ ## name, flags, NULL, NULL }
struct testcase_t address_tests[] = {
+ ADDRESS_TEST(udp_socket_trick_whitebox, TT_FORK),
+ ADDRESS_TEST(udp_socket_trick_blackbox, TT_FORK),
#ifdef HAVE_IFADDRS_TO_SMARTLIST
ADDRESS_TEST(get_if_addrs_ifaddrs, TT_FORK),
ADDRESS_TEST(ifaddrs_to_smartlist, 0),
diff --git a/src/test/test_controller_events.c b/src/test/test_controller_events.c
index e36314da45..bd91aecd94 100644
--- a/src/test/test_controller_events.c
+++ b/src/test/test_controller_events.c
@@ -293,6 +293,104 @@ test_cntev_format_cell_stats(void *arg)
tor_free(n_chan);
}
+static void
+test_cntev_event_mask(void *arg)
+{
+ unsigned int test_event, selected_event;
+ (void)arg;
+
+ /* Check that nothing is interesting when no events are set */
+ control_testing_set_global_event_mask(EVENT_MASK_NONE_);
+
+ /* Check that nothing is interesting between EVENT_MIN_ and EVENT_MAX_ */
+ for (test_event = EVENT_MIN_; test_event <= EVENT_MAX_; test_event++)
+ tt_assert(!control_event_is_interesting(test_event));
+
+ /* Check that nothing is interesting outside EVENT_MIN_ to EVENT_MAX_
+ * This will break if control_event_is_interesting() checks its arguments */
+ for (test_event = 0; test_event < EVENT_MIN_; test_event++)
+ tt_assert(!control_event_is_interesting(test_event));
+ for (test_event = EVENT_MAX_ + 1;
+ test_event < EVENT_CAPACITY_;
+ test_event++)
+ tt_assert(!control_event_is_interesting(test_event));
+
+ /* Check that all valid events are interesting when all events are set */
+ control_testing_set_global_event_mask(EVENT_MASK_ALL_);
+
+ /* Check that everything is interesting between EVENT_MIN_ and EVENT_MAX_ */
+ for (test_event = EVENT_MIN_; test_event <= EVENT_MAX_; test_event++)
+ tt_assert(control_event_is_interesting(test_event));
+
+ /* Check that nothing is interesting outside EVENT_MIN_ to EVENT_MAX_
+ * This will break if control_event_is_interesting() checks its arguments */
+ for (test_event = 0; test_event < EVENT_MIN_; test_event++)
+ tt_assert(!control_event_is_interesting(test_event));
+ for (test_event = EVENT_MAX_ + 1;
+ test_event < EVENT_CAPACITY_;
+ test_event++)
+ tt_assert(!control_event_is_interesting(test_event));
+
+ /* Check that only that event is interesting when a single event is set */
+ for (selected_event = EVENT_MIN_;
+ selected_event <= EVENT_MAX_;
+ selected_event++) {
+ control_testing_set_global_event_mask(EVENT_MASK_(selected_event));
+
+ /* Check that only this event is interesting
+ * between EVENT_MIN_ and EVENT_MAX_ */
+ for (test_event = EVENT_MIN_; test_event <= EVENT_MAX_; test_event++) {
+ if (test_event == selected_event) {
+ tt_assert(control_event_is_interesting(test_event));
+ } else {
+ tt_assert(!control_event_is_interesting(test_event));
+ }
+ }
+
+ /* Check that nothing is interesting outside EVENT_MIN_ to EVENT_MAX_
+ * This will break if control_event_is_interesting checks its arguments */
+ for (test_event = 0; test_event < EVENT_MIN_; test_event++)
+ tt_assert(!control_event_is_interesting(test_event));
+ for (test_event = EVENT_MAX_ + 1;
+ test_event < EVENT_CAPACITY_;
+ test_event++)
+ tt_assert(!control_event_is_interesting(test_event));
+ }
+
+ /* Check that only that event is not-interesting
+ * when a single event is un-set */
+ for (selected_event = EVENT_MIN_;
+ selected_event <= EVENT_MAX_;
+ selected_event++) {
+ control_testing_set_global_event_mask(
+ EVENT_MASK_ALL_
+ & ~(EVENT_MASK_(selected_event))
+ );
+
+ /* Check that only this event is not-interesting
+ * between EVENT_MIN_ and EVENT_MAX_ */
+ for (test_event = EVENT_MIN_; test_event <= EVENT_MAX_; test_event++) {
+ if (test_event == selected_event) {
+ tt_assert(!control_event_is_interesting(test_event));
+ } else {
+ tt_assert(control_event_is_interesting(test_event));
+ }
+ }
+
+ /* Check that nothing is interesting outside EVENT_MIN_ to EVENT_MAX_
+ * This will break if control_event_is_interesting checks its arguments */
+ for (test_event = 0; test_event < EVENT_MIN_; test_event++)
+ tt_assert(!control_event_is_interesting(test_event));
+ for (test_event = EVENT_MAX_ + 1;
+ test_event < EVENT_CAPACITY_;
+ test_event++)
+ tt_assert(!control_event_is_interesting(test_event));
+ }
+
+ done:
+ ;
+}
+
#define TEST(name, flags) \
{ #name, test_cntev_ ## name, flags, 0, NULL }
@@ -302,6 +400,7 @@ struct testcase_t controller_event_tests[] = {
TEST(sum_up_cell_stats, 0),
TEST(append_cell_stats, 0),
TEST(format_cell_stats, 0),
+ TEST(event_mask, 0),
END_OF_TESTCASES
};