r9309@totoro: nickm | 2006-11-13 19:05:41 -0500

Whitespace fixes, and clean up code from last natd patch.


svn:r8947
This commit is contained in:
Nick Mathewson 2006-11-14 00:06:45 +00:00
parent 1913cb915e
commit 0f6402f17b
4 changed files with 27 additions and 16 deletions

View file

@ -2100,18 +2100,19 @@ options_validate(or_options_t *old_options, or_options_t *options,
int is_socks = i==0; int is_socks = i==0;
int is_trans = i==1; int is_trans = i==1;
config_line_t *line, *opt, *old; config_line_t *line, *opt, *old;
const char *tp = is_socks ? "SOCKS proxy" : const char *tp;
is_trans ? "transparent proxy"
: "natd proxy";
if (is_socks) { if (is_socks) {
opt = options->SocksListenAddress; opt = options->SocksListenAddress;
old = old_options ? old_options->SocksListenAddress : NULL; old = old_options ? old_options->SocksListenAddress : NULL;
tp = "SOCKS proxy";
} else if (is_trans) { } else if (is_trans) {
opt = options->TransListenAddress; opt = options->TransListenAddress;
old = old_options ? old_options->TransListenAddress : NULL; old = old_options ? old_options->TransListenAddress : NULL;
tp = "transparent proxy";
} else { } else {
opt = options->NatdListenAddress; opt = options->NatdListenAddress;
old = old_options ? old_options->NatdListenAddress : NULL; old = old_options ? old_options->NatdListenAddress : NULL;
tp = "natd proxy";
} }
for (line = opt; line; line = line->next) { for (line = opt; line; line = line->next) {

View file

@ -1479,7 +1479,8 @@ connection_ap_process_transparent(edge_connection_t *conn)
if (connection_ap_get_original_destination(conn, socks) < 0) { if (connection_ap_get_original_destination(conn, socks) < 0) {
log_warn(LD_APP,"Fetching original destination failed. Closing."); log_warn(LD_APP,"Fetching original destination failed. Closing.");
connection_mark_unattached_ap(conn, END_STREAM_REASON_CANT_FETCH_ORIG_DEST); connection_mark_unattached_ap(conn,
END_STREAM_REASON_CANT_FETCH_ORIG_DEST);
return -1; return -1;
} }
/* we have the original destination */ /* we have the original destination */
@ -1509,7 +1510,7 @@ connection_ap_process_natd(edge_connection_t *conn)
{ {
char tmp_buf[36], *tbuf, *daddr; char tmp_buf[36], *tbuf, *daddr;
size_t tlen = 30; size_t tlen = 30;
int err; int err, port_ok;
socks_request_t *socks; socks_request_t *socks;
or_options_t *options = get_options(); or_options_t *options = get_options();
@ -1532,27 +1533,34 @@ connection_ap_process_natd(edge_connection_t *conn)
return -1; return -1;
} }
if (strncmp(tmp_buf, "[DEST ", 6)) { if (strcmpstart(tmp_buf, "[DEST ")) {
log_warn(LD_APP,"Natd handshake failed. Closing. tmp_buf = '%s'", tmp_buf); log_warn(LD_APP,"Natd handshake was ill-formed; closing. The client "
"said: '%s'",
escaped(tmp_buf));
connection_mark_unattached_ap(conn, END_STREAM_REASON_INVALID_NATD_DEST); connection_mark_unattached_ap(conn, END_STREAM_REASON_INVALID_NATD_DEST);
return -1; return -1;
} }
tbuf = &tmp_buf[0] + 6; daddr = tbuf = &tmp_buf[0] + 6; /* after end of "[DEST " */
daddr = tbuf; while (*tbuf != '\0' && *tbuf != ' ')
while (tbuf[0] != '\0' && tbuf[0] != ' ')
tbuf++; tbuf++;
tbuf[0] = '\0'; *tbuf = '\0';
tbuf++; tbuf++;
/* pretend that a socks handshake completed so we don't try to /* pretend that a socks handshake completed so we don't try to
* send a socks reply down a natd conn */ * send a socks reply down a natd conn */
strlcpy(socks->address, daddr, sizeof(socks->address));
socks->port = (uint16_t) tor_parse_long(tbuf, 10, 1, 65535, &port_ok, NULL);
if (!port_ok) {
log_warn(LD_APP,"Natd handshake failed; port '%s' is ill-formed or out "
"of range.", escaped(tbuf));
connection_mark_unattached_ap(conn, END_STREAM_REASON_INVALID_NATD_DEST);
return -1;
}
socks->command = SOCKS_COMMAND_CONNECT; socks->command = SOCKS_COMMAND_CONNECT;
socks->has_finished = 1; socks->has_finished = 1;
strlcpy(socks->address, daddr, sizeof(socks->address));
socks->port = atoi(tbuf);
control_event_stream_status(conn, STREAM_EVENT_NEW, 0); control_event_stream_status(conn, STREAM_EVENT_NEW, 0);
if (options->LeaveStreamsUnattached) { if (options->LeaveStreamsUnattached) {

View file

@ -1333,7 +1333,8 @@ extern uint64_t buf_total_used;
extern uint64_t buf_total_alloc; extern uint64_t buf_total_alloc;
extern uint64_t rephist_total_alloc; extern uint64_t rephist_total_alloc;
extern uint32_t rephist_total_num; extern uint32_t rephist_total_num;
void dump_distinct_digests_xx(int severity); // xxxx0124 remove // xxxx0124 remove
void dump_distinct_digests_xx(int severity);
/** /**
* Write current memory usage information to the log. * Write current memory usage information to the log.

View file

@ -703,7 +703,8 @@ void dump_distinct_digests_xx(int severity);
static digestmap_t *verified_digests_tmp = NULL; // XXXX0124 remove me. static digestmap_t *verified_digests_tmp = NULL; // XXXX0124 remove me.
// remove me too. // remove me too.
void void
dump_distinct_digests_xx(int severity) { dump_distinct_digests_xx(int severity)
{
if (!verified_digests_tmp) if (!verified_digests_tmp)
verified_digests_tmp = digestmap_new(); verified_digests_tmp = digestmap_new();
log(severity, LD_GENERAL, "%d *distinct* router digests verified", log(severity, LD_GENERAL, "%d *distinct* router digests verified",