[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Add function to check that addr_policy_t is okay; change st...
- To: or-cvs@freehaven.net
- Subject: [or-cvs] Add function to check that addr_policy_t is okay; change st...
- From: nickm@seul.org (Nick Mathewson)
- Date: Fri, 3 Dec 2004 20:14:39 -0500 (EST)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Fri, 03 Dec 2004 20:15:06 -0500
- Reply-to: or-dev@freehaven.net
- Sender: owner-or-cvs@freehaven.net
Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv4171/src/or
Modified Files:
config.c connection_edge.c directory.c or.h router.c
routerlist.c routerparse.c test.c
Log Message:
Add function to check that addr_policy_t is okay; change struct addr_policy_t to addr_policy_t.
Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.279
retrieving revision 1.280
diff -u -d -r1.279 -r1.280
--- config.c 3 Dec 2004 23:53:35 -0000 1.279
+++ config.c 4 Dec 2004 01:14:35 -0000 1.280
@@ -1130,7 +1130,7 @@
int i;
int result = 0;
struct config_line_t *cl;
- struct addr_policy_t *addr_policy=NULL;
+ addr_policy_t *addr_policy=NULL;
if (options->ORPort < 0 || options->ORPort > 65535) {
log(LOG_WARN, "ORPort option out of bounds.");
@@ -1975,9 +1975,9 @@
*/
int
config_parse_addr_policy(struct config_line_t *cfg,
- struct addr_policy_t **dest)
+ addr_policy_t **dest)
{
- struct addr_policy_t **nextp;
+ addr_policy_t **nextp;
smartlist_t *entries;
int r = 0;
@@ -2012,8 +2012,8 @@
/** Release all storage held by <b>p</b> */
void
-addr_policy_free(struct addr_policy_t *p) {
- struct addr_policy_t *e;
+addr_policy_free(addr_policy_t *p) {
+ addr_policy_t *e;
while (p) {
e = p;
Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.251
retrieving revision 1.252
diff -u -d -r1.251 -r1.252
--- connection_edge.c 30 Nov 2004 09:02:25 -0000 1.251
+++ connection_edge.c 4 Dec 2004 01:14:35 -0000 1.252
@@ -13,7 +13,7 @@
#include "or.h"
#include "tree.h"
-static struct addr_policy_t *socks_policy = NULL;
+static addr_policy_t *socks_policy = NULL;
/* List of exit_redirect_t */
static smartlist_t *redirect_exit_list = NULL;
@@ -1045,7 +1045,7 @@
void
parse_socks_policy(void)
{
- struct addr_policy_t *n;
+ addr_policy_t *n;
if (socks_policy) {
addr_policy_free(socks_policy);
socks_policy = NULL;
Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.177
retrieving revision 1.178
diff -u -d -r1.177 -r1.178
--- directory.c 29 Nov 2004 22:25:30 -0000 1.177
+++ directory.c 4 Dec 2004 01:14:36 -0000 1.178
@@ -51,7 +51,7 @@
/********* START VARIABLES **********/
-static struct addr_policy_t *dir_policy = NULL;
+static addr_policy_t *dir_policy = NULL;
#if 0 /* commented out for now, since for now what clients send is
different from what servers want to receive */
@@ -74,7 +74,7 @@
void
parse_dir_policy(void)
{
- struct addr_policy_t *n;
+ addr_policy_t *n;
if (dir_policy) {
addr_policy_free(dir_policy);
dir_policy = NULL;
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.502
retrieving revision 1.503
diff -u -d -r1.502 -r1.503
--- or.h 30 Nov 2004 16:07:20 -0000 1.502
+++ or.h 4 Dec 2004 01:14:36 -0000 1.503
@@ -582,7 +582,7 @@
#define ADDR_POLICY_REJECT 2
/** A linked list of policy rules */
-struct addr_policy_t {
+typedef struct addr_policy_t {
char policy_type; /**< One of ADDR_POLICY_ACCEPT or ADDR_POLICY_REJECT. */
char *string; /**< String representation of this rule. */
uint32_t addr; /**< Base address to accept or reject. */
@@ -592,7 +592,7 @@
uint16_t prt_max; /**< Highest port number to accept/reject. */
struct addr_policy_t *next; /**< Next rule in list. */
-};
+} addr_policy_t;
/** Information about another onion router in the network. */
typedef struct {
@@ -619,7 +619,7 @@
uint32_t bandwidthburst; /**< How large is this OR's token bucket? */
/** How many bytes/s is this router known to handle? */
uint32_t bandwidthcapacity;
- struct addr_policy_t *exit_policy; /**< What streams will this OR permit
+ addr_policy_t *exit_policy; /**< What streams will this OR permit
* to exit? */
long uptime; /**< How many seconds the router claims to have been up */
/* local info */
@@ -1124,8 +1124,8 @@
int init_from_config(int argc, char **argv);
int config_init_logs(or_options_t *options, int validate_only);
int config_parse_addr_policy(struct config_line_t *cfg,
- struct addr_policy_t **dest);
-void addr_policy_free(struct addr_policy_t *p);
+ addr_policy_t **dest);
+void addr_policy_free(addr_policy_t *p);
int config_option_is_recognized(const char *key);
struct config_line_t *config_get_assigned_option(or_options_t *options,
const char *key);
@@ -1595,7 +1595,7 @@
int router_load_routerlist_from_directory(const char *s,crypto_pk_env_t *pkey,
int check_version);
int router_compare_addr_to_addr_policy(uint32_t addr, uint16_t port,
- struct addr_policy_t *policy);
+ addr_policy_t *policy);
#define ADDR_POLICY_ACCEPTED 0
#define ADDR_POLICY_REJECTED -1
#define ADDR_POLICY_UNKNOWN 1
@@ -1682,12 +1682,13 @@
running_routers_t *router_parse_runningrouters(const char *str);
routerinfo_t *router_parse_entry_from_string(const char *s, const char *end);
int router_add_exit_policy_from_string(routerinfo_t *router, const char *s);
-struct addr_policy_t *router_parse_addr_policy_from_string(const char *s);
+addr_policy_t *router_parse_addr_policy_from_string(const char *s);
int check_software_version_against_directory(const char *directory,
int ignoreversion);
int tor_version_parse(const char *s, tor_version_t *out);
int tor_version_as_new_as(const char *platform, const char *cutoff);
int tor_version_compare(tor_version_t *a, tor_version_t *b);
+void assert_addr_policy_ok(addr_policy_t *t);
#endif
Index: router.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -d -r1.134 -r1.135
--- router.c 2 Dec 2004 04:31:52 -0000 1.134
+++ router.c 4 Dec 2004 01:14:36 -0000 1.135
@@ -454,7 +454,7 @@
* rule, then append the default exit policy as well.
*/
static void router_add_exit_policy_from_config(routerinfo_t *router) {
- struct addr_policy_t *ep;
+ addr_policy_t *ep;
struct config_line_t default_policy;
config_parse_addr_policy(get_options()->ExitPolicy, &router->exit_policy);
@@ -627,7 +627,7 @@
size_t onion_pkeylen, identity_pkeylen;
size_t written;
int result=0;
- struct addr_policy_t *tmpe;
+ addr_policy_t *tmpe;
char *bandwidth_usage;
char *family_line;
#ifdef DEBUG_ROUTER_DUMP_ROUTER_TO_STRING
Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.195
retrieving revision 1.196
diff -u -d -r1.195 -r1.196
--- routerlist.c 1 Dec 2004 03:48:13 -0000 1.195
+++ routerlist.c 4 Dec 2004 01:14:36 -0000 1.196
@@ -684,7 +684,7 @@
routerinfo_t *routerinfo_copy(const routerinfo_t *router)
{
routerinfo_t *r;
- struct addr_policy_t **e, *tmp;
+ addr_policy_t **e, *tmp;
r = tor_malloc(sizeof(routerinfo_t));
memcpy(r, router, sizeof(routerinfo_t));
@@ -698,8 +698,8 @@
r->identity_pkey = crypto_pk_dup_key(r->identity_pkey);
e = &r->exit_policy;
while (*e) {
- tmp = tor_malloc(sizeof(struct addr_policy_t));
- memcpy(tmp,*e,sizeof(struct addr_policy_t));
+ tmp = tor_malloc(sizeof(addr_policy_t));
+ memcpy(tmp,*e,sizeof(addr_policy_t));
*e = tmp;
(*e)->string = tor_strdup((*e)->string);
e = & ((*e)->next);
@@ -942,14 +942,14 @@
* unknown).
*/
int router_compare_addr_to_addr_policy(uint32_t addr, uint16_t port,
- struct addr_policy_t *policy)
+ addr_policy_t *policy)
{
int maybe_reject = 0;
int maybe_accept = 0;
int match = 0;
int maybe = 0;
struct in_addr in;
- struct addr_policy_t *tmpe;
+ addr_policy_t *tmpe;
for (tmpe=policy; tmpe; tmpe=tmpe->next) {
// log_fn(LOG_DEBUG,"Considering exit policy %s", tmpe->string);
Index: routerparse.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerparse.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -d -r1.92 -r1.93
--- routerparse.c 4 Dec 2004 00:25:54 -0000 1.92
+++ routerparse.c 4 Dec 2004 01:14:36 -0000 1.93
@@ -125,7 +125,7 @@
/* static function prototypes */
static int router_add_exit_policy(routerinfo_t *router,directory_token_t *tok);
-static struct addr_policy_t *router_parse_addr_policy(directory_token_t *tok);
+static addr_policy_t *router_parse_addr_policy(directory_token_t *tok);
static int router_get_hash_impl(const char *s, char *digest,
const char *start_str, const char *end_str);
static void token_free(directory_token_t *tok);
@@ -968,13 +968,13 @@
/** Parse the exit policy in the string <b>s</b> and return it.
*/
-struct addr_policy_t *
+addr_policy_t *
router_parse_addr_policy_from_string(const char *s)
{
directory_token_t *tok = NULL;
const char *cp;
char *tmp;
- struct addr_policy_t *r;
+ addr_policy_t *r;
size_t len, idx;
/* *s might not end with \n, so we need to extend it with one. */
@@ -1009,7 +1009,7 @@
int
router_add_exit_policy_from_string(routerinfo_t *router, const char *s)
{
- struct addr_policy_t *newe, *tmpe;
+ addr_policy_t *newe, *tmpe;
newe = router_parse_addr_policy_from_string(s);
if (!newe)
return -1;
@@ -1023,7 +1023,7 @@
static int
router_add_exit_policy(routerinfo_t *router,directory_token_t *tok)
{
- struct addr_policy_t *newe, **tmpe;
+ addr_policy_t *newe, **tmpe;
newe = router_parse_addr_policy(tok);
if (!newe)
return -1;
@@ -1036,10 +1036,10 @@
/** Given a K_ACCEPT or K_REJECT token and a router, create and return
* a new exit_policy_t corresponding to the token. */
-static struct addr_policy_t *
+static addr_policy_t *
router_parse_addr_policy(directory_token_t *tok) {
- struct addr_policy_t *newe;
+ addr_policy_t *newe;
struct in_addr in;
char *arg, *address;
@@ -1049,7 +1049,7 @@
return NULL;
arg = tok->args[0];
- newe = tor_malloc_zero(sizeof(struct addr_policy_t));
+ newe = tor_malloc_zero(sizeof(addr_policy_t));
newe->string = tor_malloc(8+strlen(arg));
// tor_snprintf(newe->string, 8+strlen(arg), "%s %s",
@@ -1079,6 +1079,30 @@
return NULL;
}
+void
+assert_addr_policy_ok(addr_policy_t *t)
+{
+ addr_policy_t *t2;
+ while (t) {
+ tor_assert(t->policy_type == ADDR_POLICY_REJECT ||
+ t->policy_type == ADDR_POLICY_ACCEPT);
+ tor_assert(t->prt_min <= t->prt_max);
+ t2 = router_parse_addr_policy_from_string(t->string);
+ tor_assert(t2);
+ tor_assert(t2->policy_type == t->policy_type);
+ tor_assert(t2->addr == t->addr);
+ tor_assert(t2->msk == t->msk);
+ tor_assert(t2->prt_min == t->prt_min);
+ tor_assert(t2->prt_max == t->prt_max);
+ tor_assert(!strcmp(t2->string, t->string));
+ tor_assert(t2->next == NULL);
+ addr_policy_free(t2);
+
+ t = t->next;
+ }
+
+}
+
/*
* Low-level tokenizer for router descriptors and directories.
*/
Index: test.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/test.c,v
retrieving revision 1.156
retrieving revision 1.157
diff -u -d -r1.156 -r1.157
--- test.c 30 Nov 2004 03:44:10 -0000 1.156
+++ test.c 4 Dec 2004 01:14:36 -0000 1.157
@@ -940,7 +940,7 @@
routerinfo_t r1, r2;
crypto_pk_env_t *pk1 = NULL, *pk2 = NULL, *pk3 = NULL;
routerinfo_t *rp1 = NULL, *rp2 = NULL;
- struct addr_policy_t ex1, ex2;
+ addr_policy_t ex1, ex2;
routerlist_t *dir1 = NULL, *dir2 = NULL;
tor_version_t ver1;
char *bw_lines = NULL;