diff options
author | Roger Dingledine <arma@torproject.org> | 2002-08-24 07:55:49 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2002-08-24 07:55:49 +0000 |
commit | b8b8ab2fd6753c3f8b1e20e43047e29b5e44aea1 (patch) | |
tree | 2e72985b0977fbd95ca50020c334c8ca35d86ee8 /src | |
parent | c040bbe053b53ed368a4fe2836ca401c87845090 (diff) | |
download | tor-b8b8ab2fd6753c3f8b1e20e43047e29b5e44aea1.tar.gz tor-b8b8ab2fd6753c3f8b1e20e43047e29b5e44aea1.zip |
port is now kept in host order except in sin_port
svn:r82
Diffstat (limited to 'src')
-rw-r--r-- | src/or/circuit.c | 2 | ||||
-rw-r--r-- | src/or/command.c | 2 | ||||
-rw-r--r-- | src/or/connection.c | 4 | ||||
-rw-r--r-- | src/or/connection_ap.c | 10 | ||||
-rw-r--r-- | src/or/connection_exit.c | 8 | ||||
-rw-r--r-- | src/or/connection_or.c | 42 | ||||
-rw-r--r-- | src/or/onion.c | 10 | ||||
-rw-r--r-- | src/or/routers.c | 11 |
8 files changed, 43 insertions, 46 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c index 626db44fde..1da22e960d 100644 --- a/src/or/circuit.c +++ b/src/or/circuit.c @@ -131,7 +131,7 @@ int circuit_init(circuit_t *circ, int aci_type) { log(LOG_DEBUG,"circuit_init(): starting"); circ->n_addr = ol->addr; circ->n_port = ol->port; - log(LOG_DEBUG,"circuit_init(): Set port to %u.",ntohs(ol->port)); + log(LOG_DEBUG,"circuit_init(): Set port to %u.",ol->port); circ->p_f = ol->backf; log(LOG_DEBUG,"circuit_init(): Set BACKF to %u.",ol->backf); circ->n_f = ol->forwf; diff --git a/src/or/command.c b/src/or/command.c index 94c3ccc621..0e2d34c4b3 100644 --- a/src/or/command.c +++ b/src/or/command.c @@ -113,7 +113,7 @@ void command_process_create_cell(cell_t *cell, connection_t *conn) { circ->n_port = n_conn->port; circ->n_conn = n_conn; - log(LOG_DEBUG,"command_process_create_cell(): n_conn is %s:%u",n_conn->address,ntohs(n_conn->port)); + log(LOG_DEBUG,"command_process_create_cell(): n_conn is %s:%u",n_conn->address,n_conn->port); /* send the CREATE cells on to the next hop */ pad_onion(circ->onion,circ->onionlen, sizeof(onion_layer_t)); diff --git a/src/or/connection.c b/src/or/connection.c index 733c967343..6b5ccc4d1d 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -262,7 +262,7 @@ int retry_all_connections(int role, routerinfo_t **router_array, int rarray_len, for (i=0;i<rarray_len;i++) { router = router_array[i]; if(!connection_exact_get_by_addr_port(router->addr,router->or_port)) { /* not in the list */ - log(LOG_DEBUG,"retry_all_connections(): connecting to OR %s:%u.",router->address,ntohs(router->or_port)); + log(LOG_DEBUG,"retry_all_connections(): connecting to OR %s:%u.",router->address,router->or_port); connection_or_connect_as_or(router, prkey, &local); } } @@ -517,7 +517,7 @@ int connection_encrypt_cell_header(cell_t *cellp, connection_t *conn) { #endif if(crypto_cipher_encrypt(conn->f_crypto, (char *)cellp, 8, newheader)) { - log(LOG_ERR,"Could not encrypt data for connection %s:%u.",conn->address,ntohs(conn->port)); + log(LOG_ERR,"Could not encrypt data for connection %s:%u.",conn->address,conn->port); return -1; } #if 0 diff --git a/src/or/connection_ap.c b/src/or/connection_ap.c index 99c0932e85..9d96ae85b3 100644 --- a/src/or/connection_ap.c +++ b/src/or/connection_ap.c @@ -125,7 +125,7 @@ int ap_handshake_process_ss(connection_t *conn) { if(connection_fetch_from_buf(conn->dest_port,conn->dest_port_len,conn) < 0) return -1; - log(LOG_DEBUG,"ap_handshake_process_ss(): Read dest_port (network order) '%s'.",conn->dest_port); + log(LOG_DEBUG,"ap_handshake_process_ss(): Read dest_port '%s'.",conn->dest_port); conn->dest_port_received = conn->dest_port_len; } @@ -202,7 +202,7 @@ int ap_handshake_establish_circuit(connection_t *conn, unsigned int *route, int circ->cpathlen = routelen; log(LOG_DEBUG,"ap_handshake_establish_circuit(): Looking for firsthop '%s:%u'", - firsthop->address,ntohs(firsthop->or_port)); + firsthop->address,firsthop->or_port); n_conn = connection_twin_get_by_addr_port(firsthop->addr,firsthop->or_port); if(!n_conn) { /* not currently connected */ circ->n_addr = firsthop->addr; @@ -257,7 +257,7 @@ int ap_handshake_send_onion(connection_t *ap_conn, connection_t *n_conn, circuit circ->n_aci = get_unique_aci_by_addr_port(circ->n_addr, circ->n_port, ACI_TYPE_BOTH); circ->n_conn = n_conn; - log(LOG_DEBUG,"ap_handshake_send_onion(): n_conn is %s:%u",n_conn->address,ntohs(n_conn->port)); + log(LOG_DEBUG,"ap_handshake_send_onion(): n_conn is %s:%u",n_conn->address,n_conn->port); /* deliver the onion as one or more create cells */ cell.command = CELL_CREATE; @@ -267,9 +267,7 @@ int ap_handshake_send_onion(connection_t *ap_conn, connection_t *n_conn, circuit tmpbuf = malloc(tmpbuflen); if(!tmpbuf) return -1; - circ->onionlen = htonl(circ->onionlen); - memcpy(tmpbuf,&circ->onionlen,4); - circ->onionlen = ntohl(circ->onionlen); + *(uint32_t*)tmpbuf = htonl(circ->onionlen); memcpy(tmpbuf+4, circ->onion, circ->onionlen); dataleft = tmpbuflen; diff --git a/src/or/connection_exit.c b/src/or/connection_exit.c index c2ebca5673..cbae5512e3 100644 --- a/src/or/connection_exit.c +++ b/src/or/connection_exit.c @@ -47,7 +47,7 @@ int connection_exit_finished_flushing(connection_t *conn) { /* the connect has finished. */ log(LOG_DEBUG,"connection_exit_finished_flushing() : Connection to %s:%u established.", - conn->address,ntohs(conn->port)); + conn->address,conn->port); conn->state = EXIT_CONN_STATE_OPEN; if(connection_wants_to_flush(conn)) /* in case there are any queued data cells */ @@ -125,10 +125,10 @@ int connection_exit_process_data_cell(cell_t *cell, connection_t *conn) { memset((void *)&dest_addr,0,sizeof(dest_addr)); dest_addr.sin_family = AF_INET; - dest_addr.sin_port = conn->port; + dest_addr.sin_port = htons(conn->port); memcpy((void *)&dest_addr.sin_addr, &conn->addr, sizeof(uint32_t)); - log(LOG_DEBUG,"connection_exit_process_data_cell(): Connecting to %s:%u.",conn->address,ntohs(conn->port)); + log(LOG_DEBUG,"connection_exit_process_data_cell(): Connecting to %s:%u.",conn->address,conn->port); if(connect(s,(struct sockaddr *)&dest_addr,sizeof(dest_addr)) < 0){ if(errno != EINPROGRESS){ @@ -148,7 +148,7 @@ int connection_exit_process_data_cell(cell_t *cell, connection_t *conn) { } /* it succeeded. we're connected. */ - log(LOG_DEBUG,"connection_exit_process_data_cell(): Connection to %s:%u established.",conn->address,ntohs(conn->port)); + log(LOG_DEBUG,"connection_exit_process_data_cell(): Connection to %s:%u established.",conn->address,conn->port); conn->s = s; connection_set_poll_socket(conn); diff --git a/src/or/connection_or.c b/src/or/connection_or.c index 127bd23ccb..89c061f98e 100644 --- a/src/or/connection_or.c +++ b/src/or/connection_or.c @@ -57,7 +57,7 @@ int connection_or_finished_flushing(connection_t *conn) { /* the connect has finished. */ log(LOG_DEBUG,"connection_or_finished_flushing() : OP connection to router %s:%u established.", - conn->address,ntohs(conn->port)); + conn->address,conn->port); return or_handshake_op_send_keys(conn); case OR_CONN_STATE_OP_SENDING_KEYS: @@ -75,7 +75,7 @@ int connection_or_finished_flushing(connection_t *conn) { /* the connect has finished. */ log(LOG_DEBUG,"connection_or_finished_flushing() : OR connection to router %s:%u established.", - conn->address,ntohs(conn->port)); + conn->address,conn->port); return or_handshake_client_send_auth(conn); case OR_CONN_STATE_CLIENT_SENDING_AUTH: @@ -171,10 +171,10 @@ connection_t *connection_or_connect(routerinfo_t *router, crypto_pk_env_t *prkey memset((void *)&router_addr,0,sizeof(router_addr)); router_addr.sin_family = AF_INET; - router_addr.sin_port = port; + router_addr.sin_port = htons(port); router_addr.sin_addr.s_addr = router->addr; - log(LOG_DEBUG,"connection_or_connect() : Trying to connect to %s:%u.",inet_ntoa(*(struct in_addr *)&router->addr),ntohs(port)); + log(LOG_DEBUG,"connection_or_connect() : Trying to connect to %s:%u.",inet_ntoa(*(struct in_addr *)&router->addr),port); if(connect(s,(struct sockaddr *)&router_addr,sizeof(router_addr)) < 0){ if(errno != EINPROGRESS){ @@ -206,7 +206,7 @@ connection_t *connection_or_connect(routerinfo_t *router, crypto_pk_env_t *prkey return NULL; } - log(LOG_DEBUG,"connection_or_connect() : Connection to router %s:%u established.",router->address,ntohs(port)); + log(LOG_DEBUG,"connection_or_connect() : Connection to router %s:%u established.",router->address,port); *result = 2; /* connection finished */ return(conn); @@ -224,7 +224,7 @@ connection_t *connection_or_connect_as_op(routerinfo_t *router, crypto_pk_env_t assert(router && prkey && local); - if(router->addr == local->sin_addr.s_addr && router->or_port == local->sin_port) { + if(router->addr == local->sin_addr.s_addr && router->or_port == ntohs(local->sin_port)) { /* this is me! don't connect to me. */ return NULL; } @@ -343,7 +343,7 @@ connection_t *connection_or_connect_as_or(routerinfo_t *router, crypto_pk_env_t assert(router && prkey && local); - if(router->addr == local->sin_addr.s_addr && router->or_port == local->sin_port) { + if(router->addr == local->sin_addr.s_addr && router->or_port == ntohs(local->sin_port)) { /* this is me! don't connect to me. */ log(LOG_DEBUG,"connection_or_connect_as_or(): This is me. Skipping."); return NULL; @@ -390,7 +390,7 @@ int or_handshake_client_send_auth(connection_t *conn) { *(uint32_t*)buf = htonl(conn->local.sin_addr.s_addr); /* local address */ *(uint16_t*)(buf+4) = conn->local.sin_port; /* local port, already network order */ *(uint32_t*)(buf+6) = htonl(conn->addr); /* remote address */ - *(uint16_t*)(buf+10) = conn->port; /* remote port, already network order */ + *(uint16_t*)(buf+10) = htons(conn->port); /* remote port */ memcpy(buf+12,conn->f_crypto->key,8); /* keys */ memcpy(buf+20,conn->b_crypto->key,8); *(uint32_t *)(buf+28) = htonl(conn->bandwidth); /* max link utilisation */ @@ -400,7 +400,7 @@ int or_handshake_client_send_auth(connection_t *conn) { retval = crypto_pk_public_encrypt(conn->pkey, buf, 36, cipher,RSA_PKCS1_PADDING); if (retval == -1) /* error */ { - log(LOG_ERR,"Public-key encryption failed during authentication to %s:%u.",conn->address,ntohs(conn->port)); + log(LOG_ERR,"Public-key encryption failed during authentication to %s:%u.",conn->address,conn->port); log(LOG_DEBUG,"or_handshake_client_send_auth() : Reason : %s.",crypto_perror()); return -1; } @@ -453,7 +453,7 @@ int or_handshake_client_process_auth(connection_t *conn) { if (retval == -1) { log(LOG_ERR,"Public-key decryption failed during authentication to %s:%u.", - conn->address,ntohs(conn->port)); + conn->address,conn->port); log(LOG_DEBUG,"or_handshake_client_process_auth() : Reason : %s.", crypto_perror()); return -1; @@ -461,7 +461,7 @@ int or_handshake_client_process_auth(connection_t *conn) { else if (retval != 44) { log(LOG_ERR,"Received an incorrect response from router %s:%u during authentication.", - conn->address,ntohs(conn->port)); + conn->address,conn->port); return -1; } log(LOG_DEBUG,"or_handshake_client_process_auth() : Decrypted response."); @@ -469,11 +469,11 @@ int or_handshake_client_process_auth(connection_t *conn) { if ( (ntohl(*(uint32_t*)buf) != conn->local.sin_addr.s_addr) || /* local address */ (*(uint16_t*)(buf+4) != conn->local.sin_port) || /* local port, keep network order */ (ntohl(*(uint32_t*)(buf+6)) != conn->addr) || /* remote address */ - (*(uint16_t*)(buf+10) != conn->port) || /* remote port, keep network order */ + (ntohs(*(uint16_t*)(buf+10)) != conn->port) || /* remote port */ (memcmp(conn->f_crypto->key, buf+12, 8)) || /* keys */ (memcmp(conn->b_crypto->key, buf+20, 8)) ) { /* incorrect response */ - log(LOG_ERR,"Router %s:%u failed to authenticate. Either the key I have is obsolete or they're doing something they're not supposed to.",conn->address,ntohs(conn->port)); + log(LOG_ERR,"Router %s:%u failed to authenticate. Either the key I have is obsolete or they're doing something they're not supposed to.",conn->address,conn->port); return -1; } @@ -492,7 +492,7 @@ int or_handshake_client_process_auth(connection_t *conn) { retval = crypto_pk_public_encrypt(conn->pkey, buf, 20, cipher,RSA_PKCS1_PADDING); if (retval == -1) /* error */ { - log(LOG_ERR,"Public-key encryption failed during authentication to %s:%u.",conn->address,ntohs(conn->port)); + log(LOG_ERR,"Public-key encryption failed during authentication to %s:%u.",conn->address,conn->port); log(LOG_DEBUG,"or_handshake_client_process_auth() : Reason : %s.",crypto_perror()); return -1; } @@ -574,7 +574,7 @@ int or_handshake_server_process_auth(connection_t *conn) { /* identify the router */ addr = ntohl(*(uint32_t*)buf); /* save the IP address */ - port = *(uint16_t*)(buf+4); /* save the port *IN NETWORK ORDER* */ + port = ntohs(*(uint16_t*)(buf+4)); /* save the port */ router = router_get_by_addr_port(addr,port); if (!router) @@ -583,7 +583,7 @@ int or_handshake_server_process_auth(connection_t *conn) { return -1; } log(LOG_DEBUG,"or_handshake_server_process_auth() : Router identified as %s:%u.", - router->address,ntohs(router->or_port)); + router->address,router->or_port); if(connection_exact_get_by_addr_port(addr,port)) { log(LOG_DEBUG,"or_handshake_server_process_auth(): That router is already connected. Dropping."); @@ -624,7 +624,7 @@ int or_handshake_server_process_auth(connection_t *conn) { retval = crypto_pk_public_encrypt(conn->pkey, buf, 44, cipher,RSA_PKCS1_PADDING); if (retval == -1) /* error */ { - log(LOG_ERR,"Public-key encryption failed during authentication to %s:%u.",conn->address,ntohs(conn->port)); + log(LOG_ERR,"Public-key encryption failed during authentication to %s:%u.",conn->address,conn->port); log(LOG_DEBUG,"or_handshake_server_process_auth() : Reason : %s.",crypto_perror()); return -1; } @@ -677,7 +677,7 @@ int or_handshake_server_process_nonce(connection_t *conn) { if (retval == -1) { log(LOG_ERR,"Public-key decryption failed during authentication to %s:%u.", - conn->address,ntohs(conn->port)); + conn->address,conn->port); log(LOG_DEBUG,"or_handshake_server_process_nonce() : Reason : %s.", crypto_perror()); return -1; @@ -685,19 +685,19 @@ int or_handshake_server_process_nonce(connection_t *conn) { else if (retval != 20) { log(LOG_ERR,"Received an incorrect response from router %s:%u during authentication.", - conn->address,ntohs(conn->port)); + conn->address,conn->port); return -1; } log(LOG_DEBUG,"or_handshake_server_process_nonce() : Response decrypted."); /* check validity */ if ((ntohl(*(uint32_t*)buf) != conn->addr) || /* remote address */ - (*(uint16_t*)(buf+4) != conn->port) || /* remote port, network order */ + (ntohs(*(uint16_t*)(buf+4)) != conn->port) || /* remote port */ (ntohl(*(uint32_t*)(buf+6)) != conn->local.sin_addr.s_addr) || /* local address */ (*(uint16_t*)(buf+10) != conn->local.sin_port) || /* local port, network order */ (memcmp(conn->nonce,buf+12,8))) /* nonce */ { - log(LOG_ERR,"Router %s:%u failed to authenticate. Either the key I have is obsolete or they're doing something they're not supposed to.",conn->address,ntohs(conn->port)); + log(LOG_ERR,"Router %s:%u failed to authenticate. Either the key I have is obsolete or they're doing something they're not supposed to.",conn->address,conn->port); return -1; } log(LOG_DEBUG,"or_handshake_server_process_nonce() : Response valid. Authentication complete."); diff --git a/src/or/onion.c b/src/or/onion.c index 9e79d97cd0..b414989092 100644 --- a/src/or/onion.c +++ b/src/or/onion.c @@ -41,7 +41,7 @@ int process_onion(circuit_t *circ, connection_t *conn) { return -1; } - aci_type = decide_aci_type(conn->local.sin_addr.s_addr, conn->local.sin_port, + aci_type = decide_aci_type(conn->local.sin_addr.s_addr, ntohs(conn->local.sin_port), ((onion_layer_t *)circ->onion)->addr,((onion_layer_t *)circ->onion)->port); if(circuit_init(circ, aci_type) < 0) { @@ -200,7 +200,7 @@ unsigned char *create_onion(routerinfo_t **rarray, int rarray_len, unsigned int for (retval=0; retval<routelen;retval++) { - log(LOG_DEBUG,"create_onion() : %u : %s:%u, %u/%u",routelen-retval,inet_ntoa(*((struct in_addr *)&((rarray[route[retval]])->addr))),ntohs((rarray[route[retval]])->or_port),(rarray[route[retval]])->pkey,crypto_pk_keysize((rarray[route[retval]])->pkey)); + log(LOG_DEBUG,"create_onion() : %u : %s:%u, %u/%u",routelen-retval,inet_ntoa(*((struct in_addr *)&((rarray[route[retval]])->addr))),(rarray[route[retval]])->or_port,(rarray[route[retval]])->pkey,crypto_pk_keysize((rarray[route[retval]])->pkey)); } layer = (onion_layer_t *)(buf + *len - 128); /* pointer to innermost layer */ @@ -210,7 +210,7 @@ unsigned char *create_onion(routerinfo_t **rarray, int rarray_len, unsigned int router = rarray[route[i]]; log(LOG_DEBUG,"create_onion() : %u",router); - log(LOG_DEBUG,"create_onion() : This router is %s:%u",inet_ntoa(*((struct in_addr *)&router->addr)),ntohs(router->or_port)); + log(LOG_DEBUG,"create_onion() : This router is %s:%u",inet_ntoa(*((struct in_addr *)&router->addr)),router->or_port); log(LOG_DEBUG,"create_onion() : Key pointer = %u.",router->pkey); log(LOG_DEBUG,"create_onion() : Key size = %u.",crypto_pk_keysize(router->pkey)); @@ -252,7 +252,7 @@ unsigned char *create_onion(routerinfo_t **rarray, int rarray_len, unsigned int } return NULL; } - log(LOG_DEBUG,"create_onion() : Onion layer %u built : %u, %u, %u, %s, %u.",i+1,layer->zero,layer->backf,layer->forwf,inet_ntoa(*((struct in_addr *)&layer->addr)),ntohs(layer->port)); + log(LOG_DEBUG,"create_onion() : Onion layer %u built : %u, %u, %u, %s, %u.",i+1,layer->zero,layer->backf,layer->forwf,inet_ntoa(*((struct in_addr *)&layer->addr)),layer->port); /* build up the crypt_path */ if (cpath) @@ -452,7 +452,7 @@ unsigned char *encrypt_onion(onion_layer_t *onion, uint32_t onionlen, crypto_pk_ { memset((void *)iv,0,8); - log(LOG_DEBUG,"Onion layer : %u, %u, %u, %s, %u.",onion->zero,onion->backf,onion->forwf,inet_ntoa(*((struct in_addr *)&onion->addr)),ntohs(onion->port)); + log(LOG_DEBUG,"Onion layer : %u, %u, %u, %s, %u.",onion->zero,onion->backf,onion->forwf,inet_ntoa(*((struct in_addr *)&onion->addr)),onion->port); /* allocate space for tmpbuf */ tmpbuf = (unsigned char *)malloc(onionlen); if (!tmpbuf) diff --git a/src/or/routers.c b/src/or/routers.c index 6430ea0894..3b893fb5ca 100644 --- a/src/or/routers.c +++ b/src/or/routers.c @@ -40,8 +40,9 @@ static int router_is_me(uint32_t or_address, uint16_t or_listenport, uint16_t my while(addr) { if (!memcmp((void *)&or_address, (void *)addr, sizeof(uint32_t))) { /* addresses match */ - if (or_listenport == htons(my_or_listenport)) /* ports also match */ - return 1; +/* FIXME one's a string, one's a uint32_t? does this make sense? */ + if (or_listenport == my_or_listenport) /* ports also match */ + return 1; } addr = localhost->h_addr_list[i++]; @@ -194,10 +195,8 @@ routerinfo_t **getrouters(char *routerfile, int *len, uint16_t or_listenport) if ((*token != '\0') && (*errtest == '\0')) /* conversion was successful */ { /* FIXME patch from RD. We should make it actually read these. */ - router->op_port = htons(router->or_port + 10); - router->ap_port = htons(router->or_port + 20); - /* convert port to network format */ - router->or_port = htons(router->or_port); + router->op_port = router->or_port + 10; + router->ap_port = router->or_port + 20; /* read min bandwidth */ token = (char *)strtok(NULL,OR_ROUTERLIST_SEPCHARS); |