summaryrefslogtreecommitdiff
path: root/src/or/routers.c
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2003-04-08 06:44:38 +0000
committerRoger Dingledine <arma@torproject.org>2003-04-08 06:44:38 +0000
commitcdf6ea201fc5868fe10f095093862431fa92b03a (patch)
tree2f287973c24fddd897c9af08e2fedd1b69d6813e /src/or/routers.c
parent79b77b421d6e6b82de46cca841d30808bba89322 (diff)
downloadtor-cdf6ea201fc5868fe10f095093862431fa92b03a.tar.gz
tor-cdf6ea201fc5868fe10f095093862431fa92b03a.zip
put most of the remaining exit policy stuff in
route selection still doesn't pay attention to exit policies though svn:r227
Diffstat (limited to 'src/or/routers.c')
-rw-r--r--src/or/routers.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/or/routers.c b/src/or/routers.c
index b3613a24a0..8adda7c9aa 100644
--- a/src/or/routers.c
+++ b/src/or/routers.c
@@ -563,15 +563,18 @@ static void router_add_exit_policy(routerinfo_t *router, char *string) {
memset(newe,0,sizeof(struct exit_policy_t));
newe->string = strdup(string);
- if(!strncasecmp(string,"reject ",strlen("reject "))) {
+ n = find_whitespace(string);
+ *n = 0;
+
+ if(!strcasecmp(string,"reject")) {
newe->policy_type = EXIT_POLICY_REJECT;
- } else if(!strncasecmp(string,"accept ",strlen("accept "))) {
+ } else if(!strcasecmp(string,"accept")) {
newe->policy_type = EXIT_POLICY_ACCEPT;
} else {
goto policy_read_failed;
}
- string = eat_whitespace(string + strlen("reject "));
+ string = eat_whitespace(n+1);
if(!*string) {
goto policy_read_failed;
}
@@ -615,6 +618,38 @@ policy_read_failed:
}
+/* Return 0 if my exit policy says to allow connection to conn.
+ * Else return -1.
+ */
+int router_compare_to_exit_policy(connection_t *conn) {
+ struct exit_policy_t *tmpe;
+
+ if(!my_routerinfo) {
+ log(LOG_WARNING, "router_compare_to_exit_policy(): my_routerinfo undefined! Rejected.");
+ return -1;
+ }
+
+ for(tmpe=my_routerinfo->exit_policy; tmpe; tmpe=tmpe->next) {
+ assert(tmpe->address);
+ assert(tmpe->port);
+
+ /* Totally ignore the address field of the exit policy, for now. */
+
+ if(!strcmp(tmpe->port,"*") || atoi(tmpe->port) == conn->port) {
+ log(LOG_INFO,"router_compare_to_exit_policy(): Port '%s' matches '%d'. %s.",
+ tmpe->port, conn->port,
+ tmpe->policy_type == EXIT_POLICY_ACCEPT ? "Accepting" : "Rejecting");
+ if(tmpe->policy_type == EXIT_POLICY_ACCEPT)
+ return 0;
+ else
+ return -1;
+ }
+ }
+
+ return 0; /* accept all by default. */
+
+}
+
/*
Local Variables:
mode:c