diff options
author | Roger Dingledine <arma@torproject.org> | 2003-10-07 23:04:31 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2003-10-07 23:04:31 +0000 |
commit | c42d928b30629af8db66078221f9ad7a4379177f (patch) | |
tree | a6011a95a93434d7c3bf9d6d65999d28018ecb2f /src/or | |
parent | 3b2943d8453c9ae9144665913ee8fd833d92cde2 (diff) | |
download | tor-c42d928b30629af8db66078221f9ad7a4379177f.tar tor-c42d928b30629af8db66078221f9ad7a4379177f.tar.gz |
pull exit policies from config into desc_routerinfo
svn:r557
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/routers.c | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/src/or/routers.c b/src/or/routers.c index c0dfb800d..34f73ea25 100644 --- a/src/or/routers.c +++ b/src/or/routers.c @@ -33,6 +33,7 @@ static char *eat_whitespace(char *s); static char *eat_whitespace_no_nl(char *s); static char *find_whitespace(char *s); static void router_free_exit_policy(routerinfo_t *router); +static int router_add_exit_policy_from_string(routerinfo_t *router, char *s); static int router_add_exit_policy(routerinfo_t *router, directory_token_t *tok); static int router_resolve_directory(directory_t *dir); @@ -946,8 +947,37 @@ static void router_free_exit_policy(routerinfo_t *router) { } } -int router_add_exit_policy_from_string(routerinfo_t *router, - char *s) +void router_add_exit_policy_from_config(routerinfo_t *router) { + char *s = options.ExitPolicy, *e; + int last=0; + + if(!s) { + log_fn(LOG_INFO,"No exit policy configured. Ok."); + return; /* nothing to see here */ + } + if(!*s) { + log_fn(LOG_INFO,"Exit policy is empty. Ok."); + return; /* nothing to see here */ + } + + for(;;) { + e = strchr(s,','); + if(!e) + last = 1; + else + *e = 0; + log_fn(LOG_DEBUG,"Adding new entry '%s'",s); + if(router_add_exit_policy_from_string(router,s) < 0) + log_fn(LOG_WARNING,"Malformed exit policy %s; skipping.", s); + if(last) + return; + s = e+1; + } +} + +static int +router_add_exit_policy_from_string(routerinfo_t *router, + char *s) { directory_token_t tok; char *tmp, *cp; @@ -1048,11 +1078,12 @@ int router_compare_to_exit_policy(connection_t *conn) { assert(tmpe->address); assert(tmpe->port); + log_fn(LOG_DEBUG,"Considering exit policy %s:%s",tmpe->address, tmpe->port); if(inet_aton(tmpe->address,&in) == 0) { /* malformed IP. reject. */ log_fn(LOG_WARNING,"Malformed IP %s in exit policy. Rejecting.",tmpe->address); return -1; } - if(conn->addr == ntohl(in.s_addr) && + if((!strcmp(tmpe->address,"*") || conn->addr == ntohl(in.s_addr)) && (!strcmp(tmpe->port,"*") || atoi(tmpe->port) == conn->port)) { log_fn(LOG_INFO,"Address '%s' matches '%s' and port '%s' matches '%d'. %s.", tmpe->address, conn->address, @@ -1107,7 +1138,8 @@ int router_rebuild_descriptor(void) { ri->link_pkey = crypto_pk_dup_key(get_link_key()); ri->identity_pkey = crypto_pk_dup_key(get_identity_key()); ri->bandwidth = options.TotalBandwidth; - ri->exit_policy = NULL; /* XXX implement this. */ + ri->exit_policy = NULL; /* zero it out first */ + router_add_exit_policy_from_config(ri); if (desc_routerinfo) routerinfo_free(desc_routerinfo); desc_routerinfo = ri; |