[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Implement RedirectExit.
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv8788/src/or
Modified Files:
config.c connection_edge.c
Log Message:
Implement RedirectExit.
Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.178
retrieving revision 1.179
diff -u -d -r1.178 -r1.179
--- config.c 16 Oct 2004 22:56:46 -0000 1.178
+++ config.c 17 Oct 2004 01:57:34 -0000 1.179
@@ -38,6 +38,7 @@
static int parse_redirect_line(or_options_t *options,
struct config_line_t *line);
+
/** Helper: Read a list of configuration options from the command line. */
static struct config_line_t *
config_get_commandlines(int argc, char **argv)
@@ -483,9 +484,10 @@
config_free_lines(options->NodeFamilies);
config_free_lines(options->RedirectExit);
if (options->RedirectExitList) {
- SMARTLIST_FOREACH(options->RedirectExitList,exit_redirect_t *, p, tor_free(p));
+ SMARTLIST_FOREACH(options->RedirectExitList,
+ exit_redirect_t *, p, tor_free(p));
smartlist_free(options->RedirectExitList);
- options->RedirectExitList = NULL;
+ options->RedirectExitList = NULL;
}
if (options->FirewallPorts) {
SMARTLIST_FOREACH(options->FirewallPorts, char *, cp, tor_free(cp));
Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.213
retrieving revision 1.214
diff -u -d -r1.213 -r1.214
--- connection_edge.c 14 Oct 2004 02:47:08 -0000 1.213
+++ connection_edge.c 17 Oct 2004 01:57:34 -0000 1.214
@@ -599,7 +599,7 @@
conn->socks_request->command = SOCKS_COMMAND_CONNECT;
conn->address = tor_strdup("(local bridge)");
- conn->addr = ntohs(0);
+ conn->addr = 0;
conn->port = 0;
if(connection_add(conn) < 0) { /* no space, forget it */
@@ -882,6 +882,8 @@
*/
void connection_exit_connect(connection_t *conn) {
unsigned char connected_payload[4];
+ uint32_t addr;
+ uint16_t port;
if (!connection_edge_is_rendezvous_stream(conn) &&
router_compare_to_my_exit_policy(conn) == ADDR_POLICY_REJECTED) {
@@ -892,8 +894,24 @@
return;
}
+ addr = conn->addr;
+ port = conn->port;
+ SMARTLIST_FOREACH(options.RedirectExitList, exit_redirect_t *, r,
+ {
+ if ((addr&r->mask)==(r->addr&r->mask) &&
+ (r->port_min <= port) && (port <= r->port_max)) {
+ struct in_addr in;
+ addr = r->addr_dest;
+ port = r->port_dest;
+ in.s_addr = htonl(addr);
+ log_fn(LOG_DEBUG, "Redirecting connection from %s:%d to %s:%d",
+ conn->address, conn->port, inet_ntoa(in), port);
+ break;
+ }
+ });
+
log_fn(LOG_DEBUG,"about to try connecting");
- switch(connection_connect(conn, conn->address, conn->addr, conn->port)) {
+ switch(connection_connect(conn, conn->address, addr, port)) {
case -1:
connection_edge_end(conn, END_STREAM_REASON_CONNECTFAILED, conn->cpath_layer);
circuit_detach_stream(circuit_get_by_conn(conn), conn);
@@ -922,6 +940,7 @@
connection_edge_send_command(conn, circuit_get_by_conn(conn), RELAY_COMMAND_CONNECTED,
NULL, 0, conn->cpath_layer);
} else { /* normal stream */
+ /* This must be the original address, not the redirected address. */
*(uint32_t*)connected_payload = htonl(conn->addr);
connection_edge_send_command(conn, circuit_get_by_conn(conn), RELAY_COMMAND_CONNECTED,
connected_payload, 4, conn->cpath_layer);