summaryrefslogtreecommitdiff
path: root/src/or/policies.c
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2018-05-03 17:07:29 +0200
committerrl1987 <rl1987@sdf.lonestar.org>2018-05-05 16:12:00 +0200
commitb00d17aa9e312e37fa05a4e3f05fedb28b67155d (patch)
treebd12d698dd20b776afe33b3b3ecaaf4b9a34b74c /src/or/policies.c
parentf36656cada48a2d9f51c857d8477a8060cb89b9d (diff)
downloadtor-b00d17aa9e312e37fa05a4e3f05fedb28b67155d.tar.gz
tor-b00d17aa9e312e37fa05a4e3f05fedb28b67155d.zip
Improve GETCONF exit-policy/* error handling
This will yield different error codes for transient and permament errors. Furthermore, Tor will give human readable error messages to controller.
Diffstat (limited to 'src/or/policies.c')
-rw-r--r--src/or/policies.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/or/policies.c b/src/or/policies.c
index e0dbb021c6..15176a97e4 100644
--- a/src/or/policies.c
+++ b/src/or/policies.c
@@ -2999,11 +2999,13 @@ getinfo_helper_policies(control_connection_t *conn,
smartlist_free(private_policy_strings);
} else if (!strcmp(question, "exit-policy/reject-private/relay")) {
const or_options_t *options = get_options();
- const routerinfo_t *me = router_get_my_routerinfo();
+ const routerinfo_t *me = NULL;
+
+ int err = router_get_my_routerinfo_with_err((routerinfo_t **)&me);
if (!me) {
- *errmsg = "router_get_my_routerinfo returned NULL";
- return -1;
+ *errmsg = routerinfo_errno_to_string(err);
+ return routerinfo_err_is_transient(err) ? -1 : 0;
}
if (!options->ExitPolicyRejectPrivate &&
@@ -3038,11 +3040,12 @@ getinfo_helper_policies(control_connection_t *conn,
SMARTLIST_FOREACH(configured_addresses, tor_addr_t *, a, tor_free(a));
smartlist_free(configured_addresses);
} else if (!strcmpstart(question, "exit-policy/")) {
- const routerinfo_t *me = router_get_my_routerinfo();
-
int include_ipv4 = 0;
int include_ipv6 = 0;
+ const routerinfo_t *me = NULL;
+ int err = router_get_my_routerinfo_with_err((routerinfo_t **)&me);
+
if (!strcmp(question, "exit-policy/ipv4")) {
include_ipv4 = 1;
} else if (!strcmp(question, "exit-policy/ipv6")) {
@@ -3054,12 +3057,14 @@ getinfo_helper_policies(control_connection_t *conn,
}
if (!me) {
- *errmsg = "router_get_my_routerinfo returned NULL";
- return -1;
+ *errmsg = routerinfo_errno_to_string(err);
+ return routerinfo_err_is_transient(err) ? -1 : 0;
+ } else {
+ *answer = router_dump_exit_policy_to_string(me,include_ipv4,
+ include_ipv6);
}
-
- *answer = router_dump_exit_policy_to_string(me,include_ipv4,include_ipv6);
}
+
return 0;
}