handle ipv6 in socks5 requests.

svn:r16476
This commit is contained in:
Nick Mathewson 2008-08-08 16:41:59 +00:00
parent 22259a0877
commit a8ddac96d8
2 changed files with 18 additions and 9 deletions

View File

@ -186,14 +186,14 @@ R d Do we want to maintain our own set of entryguards that we use as
- Teach resolving code how to handle ipv6. - Teach resolving code how to handle ipv6.
. Teach exit policies about ipv6 (consider ipv4/ipv6 interaction!) . Teach exit policies about ipv6 (consider ipv4/ipv6 interaction!)
o Use IPv6 in connect/connected/failed-exitpolicy cells o Use IPv6 in connect/connected/failed-exitpolicy cells
- accept ipv6 from socks o accept ipv6 from socks
o Generate END_REASON_EXITPOLICY cells right o Generate END_REASON_EXITPOLICY cells right
. ... and parse them right . ... and parse them right
. Generate new BEGIN cell types and parse them right . Generate new BEGIN cell types and parse them right
- Detect availability of ipv6 - Detect availability of ipv6
- Advertise availability of ipv6. - Advertise availability of ipv6.
- Geoip support, if only to add a zone called "ipv6" - Geoip support, if only to add a zone called "ipv6"
-
- 118: Listen on and advertise multiple ports: - 118: Listen on and advertise multiple ports:
- Tor should be able to have a pool of outgoing IP addresses that it is - Tor should be able to have a pool of outgoing IP addresses that it is
able to rotate through. (maybe. Possible overlap with proposal 118.) able to rotate through. (maybe. Possible overlap with proposal 118.)

View File

@ -1309,7 +1309,8 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req,
int log_sockstype, int safe_socks) int log_sockstype, int safe_socks)
{ {
unsigned int len; unsigned int len;
char tmpbuf[INET_NTOA_BUF_LEN]; char tmpbuf[TOR_ADDR_BUF_LEN+1];
tor_addr_t destaddr;
uint32_t destip; uint32_t destip;
uint8_t socksver; uint8_t socksver;
enum {socks4, socks4a} socks4_prot = socks4a; enum {socks4, socks4a} socks4_prot = socks4a;
@ -1374,13 +1375,20 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req,
} }
switch (*(buf->head->data+3)) { /* address type */ switch (*(buf->head->data+3)) { /* address type */
case 1: /* IPv4 address */ case 1: /* IPv4 address */
case 4: /* IPv6 address */ {
const int is_v6 = *(buf->head->data+3) == 4;
const unsigned addrlen = is_v6 ? 16 : 4;
log_debug(LD_APP,"socks5: ipv4 address type"); log_debug(LD_APP,"socks5: ipv4 address type");
if (buf->datalen < 10) /* ip/port there? */ if (buf->datalen < 6+addrlen) /* ip/port there? */
return 0; /* not yet */ return 0; /* not yet */
destip = ntohl(*(uint32_t*)(buf->head->data+4)); if (is_v6)
in.s_addr = htonl(destip); tor_addr_from_ipv6_bytes(&destaddr, buf->head->data+4);
tor_inet_ntoa(&in,tmpbuf,sizeof(tmpbuf)); else
tor_addr_from_ipv4n(&destaddr, get_uint32(buf->head->data+4));
tor_addr_to_str(tmpbuf, &destaddr, sizeof(tmpbuf), 1);
if (strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) { if (strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
log_warn(LD_APP, log_warn(LD_APP,
"socks5 IP takes %d bytes, which doesn't fit in %d. " "socks5 IP takes %d bytes, which doesn't fit in %d. "
@ -1389,8 +1397,8 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req,
return -1; return -1;
} }
strlcpy(req->address,tmpbuf,sizeof(req->address)); strlcpy(req->address,tmpbuf,sizeof(req->address));
req->port = ntohs(*(uint16_t*)(buf->head->data+8)); req->port = ntohs(get_uint16(buf->head->data+4+addrlen));
buf_remove_from_front(buf, 10); buf_remove_from_front(buf, 6+addrlen);
if (req->command != SOCKS_COMMAND_RESOLVE_PTR && if (req->command != SOCKS_COMMAND_RESOLVE_PTR &&
!addressmap_have_mapping(req->address) && !addressmap_have_mapping(req->address) &&
!have_warned_about_unsafe_socks) { !have_warned_about_unsafe_socks) {
@ -1410,6 +1418,7 @@ fetch_from_buf_socks(buf_t *buf, socks_request_t *req,
return -1; return -1;
} }
return 1; return 1;
}
case 3: /* fqdn */ case 3: /* fqdn */
log_debug(LD_APP,"socks5: fqdn address type"); log_debug(LD_APP,"socks5: fqdn address type");
if (req->command == SOCKS_COMMAND_RESOLVE_PTR) { if (req->command == SOCKS_COMMAND_RESOLVE_PTR) {