[or-cvs] port is now kept in host order except in sin_port
Roger Dingledine
arma at seul.org
Sat Aug 24 07:55:51 UTC 2002
Update of /home/or/cvsroot/src/or
In directory moria.seul.org:/home/arma/work/onion/cvs/src/or
Modified Files:
circuit.c command.c connection.c connection_ap.c
connection_exit.c connection_or.c onion.c routers.c
Log Message:
port is now kept in host order except in sin_port
Index: circuit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuit.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- circuit.c 24 Aug 2002 04:59:21 -0000 1.11
+++ circuit.c 24 Aug 2002 07:55:49 -0000 1.12
@@ -131,7 +131,7 @@
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;
Index: command.c
===================================================================
RCS file: /home/or/cvsroot/src/or/command.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- command.c 19 Jul 2002 18:48:28 -0000 1.9
+++ command.c 24 Aug 2002 07:55:49 -0000 1.10
@@ -113,7 +113,7 @@
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));
Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- connection.c 23 Aug 2002 03:35:44 -0000 1.13
+++ connection.c 24 Aug 2002 07:55:49 -0000 1.14
@@ -262,7 +262,7 @@
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 @@
#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
Index: connection_ap.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_ap.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- connection_ap.c 22 Aug 2002 07:30:03 -0000 1.8
+++ connection_ap.c 24 Aug 2002 07:55:49 -0000 1.9
@@ -125,7 +125,7 @@
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 @@
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 @@
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 @@
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;
Index: connection_exit.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_exit.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- connection_exit.c 18 Jul 2002 06:37:58 -0000 1.8
+++ connection_exit.c 24 Aug 2002 07:55:49 -0000 1.9
@@ -47,7 +47,7 @@
/* 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 @@
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 @@
}
/* 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);
Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_or.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- connection_or.c 24 Aug 2002 06:58:25 -0000 1.9
+++ connection_or.c 24 Aug 2002 07:55:49 -0000 1.10
@@ -57,7 +57,7 @@
/* 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 @@
/* 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 @@
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 @@
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 @@
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 @@
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 @@
*(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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
/* 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 @@
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 @@
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 @@
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 @@
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.");
Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- onion.c 24 Aug 2002 04:59:21 -0000 1.10
+++ onion.c 24 Aug 2002 07:55:49 -0000 1.11
@@ -41,7 +41,7 @@
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 @@
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 @@
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 @@
}
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 @@
{
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)
Index: routers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routers.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- routers.c 24 Aug 2002 04:59:21 -0000 1.7
+++ routers.c 24 Aug 2002 07:55:49 -0000 1.8
@@ -40,8 +40,9 @@
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 @@
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);
More information about the tor-commits
mailing list