[Pkg-privacy-commits] [onioncat] 102/340: fixed fatal socks queue memory bug disable self connections at root nodes
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:04:29 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch debian
in repository onioncat.
commit 74978cf7095e36971276f074702c31a62df66134
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date: Fri Dec 19 23:37:55 2008 +0000
fixed fatal socks queue memory bug
disable self connections at root nodes
git-svn-id: http://www.cypherpunk.at/svn/onioncat/trunk@397 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
ChangeLog | 2 ++
src/ocat.c | 3 +-
src/ocat.h | 7 +++-
src/ocatctrl.c | 9 +++--
src/ocateth.c | 5 ++-
src/ocatroute.c | 16 +++++----
src/ocatsocks.c | 101 +++++++++++++++++++++++++++++++++++++++++---------------
7 files changed, 105 insertions(+), 38 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 39d7a7c..ff4544e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,6 @@
* version
+ - disabled self connections to root nodes
+ - fatal memory error in SOCKS queue fixed
- bugfix in ether_ntoa_r()
- variable for uptime implemented
- routing is setup correctly on MACOSX with TUN dev
diff --git a/src/ocat.c b/src/ocat.c
index f30dfb1..a0b1931 100644
--- a/src/ocat.c
+++ b/src/ocat.c
@@ -336,7 +336,8 @@ int main(int argc, char *argv[])
// initiate connections to permanent root peers
log_debug("connecting root peers");
for (c = 0; c < ROOT_PEERS; c++)
- socks_queue(&CNF(root_peer[c]), 1);
+ if (!IN6_ARE_ADDR_EQUAL(&CNF(root_peer[c]), &CNF(ocat_addr)))
+ socks_queue(CNF(root_peer[c]), 1);
// reading config file
if (CNF(config_file))
diff --git a/src/ocat.h b/src/ocat.h
index 1cbfd3e..7836e58 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -126,6 +126,7 @@
//! Maximum frame (packet) size, should be able to keep one maximum size ipv6-packet: 2^16 + 40 + 4
#define FRAME_SIZE 65580
#define ONION_NAME_SIZE 23
+#define ONION_NAME_LEN ONION_NAME_SIZE
#define DEQUEUER_WAKEUP 3
//! maximum number a packet stays in queue
@@ -185,6 +186,9 @@
//! retry-delay if connection to TOR's SOCKS port fails
#define TOR_SOCKS_CONN_TIMEOUT 30
+//! copy an IPv6 address from b to a
+#define IN6_ADDR_COPY(a,b) *((struct in6_addr*)a)=*(struct in6_addr*)b
+
#define IPV4_KEY 0
#define IPV6_KEY 1
@@ -499,7 +503,8 @@ char *ether_ntoa_r(const struct ether_addr *, char *);
#endif
/* ocatsocks.c */
-void socks_queue(const struct in6_addr *, int);
+void socks_queue(struct in6_addr, int);
+void print_socks_queue(FILE *);
/* ocatlibe.c */
void oe_close(int);
diff --git a/src/ocatctrl.c b/src/ocatctrl.c
index 66fd6a5..43db30a 100644
--- a/src/ocatctrl.c
+++ b/src/ocatctrl.c
@@ -219,9 +219,9 @@ void *ctrl_handler(void *p)
else
{
if (!(s = strtok_r(NULL, " \t\r\n", &tokbuf)))
- socks_queue(&in6, 0);
+ socks_queue(in6, 0);
else if (!strcmp(s, "perm"))
- socks_queue(&in6, 1);
+ socks_queue(in6, 1);
else
fprintf(ff, "ERR unknown param \"%s\"\n", s);
}
@@ -233,6 +233,10 @@ void *ctrl_handler(void *p)
{
print_mac_tbl(ff);
}
+ else if (!strcmp(buf, "queue"))
+ {
+ print_socks_queue(ff);
+ }
else if (!strcmp(buf, "setup"))
{
print_setup_struct(ff);
@@ -258,6 +262,7 @@ void *ctrl_handler(void *p)
" ............. connect to a hidden service. if \"perm\" is set,\n"
" ............. connection will stay open forever\n"
"macs ........... show MAC address table\n"
+ "queue .......... list pending SOCKS connections\n"
"setup .......... show internal setup struct\n"
"version ........ show version\n"
);
diff --git a/src/ocateth.c b/src/ocateth.c
index 632fa4b..65eada7 100644
--- a/src/ocateth.c
+++ b/src/ocateth.c
@@ -34,7 +34,10 @@ static pthread_mutex_t mac_mutex_ = PTHREAD_MUTEX_INITIALIZER;
/*! Pseudo header for IPv6 checksum calculation.
* RFC2460 8.1, (RFC1885 2.3) RFC2463, RFC1071. */
/* RFC2461, rfc2462, RFC2464 ipv6 ethernet enc.
- * 2373 addrassng ipv6 */
+ * 2373 addrassng ipv6
+ * RFC2461 is obsoleted by RFC4861
+ * RFC4862 IPv6 Stateless Address Autoconfiguration
+ */
/* IPv6 Ethernet Multicast: (MAC) 33:33:xx:xx:xx:xx, xx -> 4 lowest order bytes of IPv6 destination
* Solicited-Node address: (IPv6) FF02:0:0:0:0:1:ffxx:xxxx, -> xx -> 3 lowest order bytes of IPv6 destination (RFC4291)
diff --git a/src/ocatroute.c b/src/ocatroute.c
index 72e8c6f..6a89f21 100644
--- a/src/ocatroute.c
+++ b/src/ocatroute.c
@@ -99,7 +99,8 @@ void queue_packet(const struct in6_addr *addr, const char *buf, int buflen)
return;
}
- memcpy(&queue->addr, addr, sizeof(struct in6_addr));
+ //memcpy(&queue->addr, addr, sizeof(struct in6_addr));
+ IN6_ADDR_COPY(&queue->addr, addr);
queue->psize = buflen;
queue->data = ((char*)queue) + sizeof(PacketQueue_t);
memcpy(queue->data, buf, buflen);
@@ -363,7 +364,7 @@ void *socket_receiver(void *p)
if (peer->perm)
{
log_debug("reconnection permanent peer");
- socks_queue(&peer->addr, 1);
+ socks_queue(peer->addr, 1);
}
unlock_peer(peer);
@@ -573,7 +574,8 @@ int insert_peer(int fd, const SocksQueue_t *sq, /*const struct in6_addr *addr,*/
peer->sdelay = dly;
if (sq)
{
- memcpy(&peer->addr, &sq->addr, sizeof(struct in6_addr));
+ //memcpy(&peer->addr, &sq->addr, sizeof(struct in6_addr));
+ IN6_ADDR_COPY(&peer->addr, &sq->addr);
peer->dir = PEER_OUTGOING;
peer->perm = sq->perm;
}
@@ -832,7 +834,7 @@ void packet_forwarder(void)
if (forward_packet(dest, buf + 4, rlen - 4) == E_FWD_NOPEER)
{
log_debug("adding destination to SOCKS queue");
- socks_queue(dest, 0);
+ socks_queue(*dest, 0);
#ifdef PACKET_QUEUE
log_debug("queuing packet");
queue_packet(dest, buf + 4, rlen - 4);
@@ -848,8 +850,10 @@ int send_keepalive(OcatPeer_t *peer)
int len;
memset(&hdr, 0, sizeof(hdr));
- memcpy(&hdr.ip6_dst, &peer->addr, sizeof(struct in6_addr));
- memcpy(&hdr.ip6_src, &CNF(ocat_addr), sizeof(struct in6_addr));
+ //memcpy(&hdr.ip6_dst, &peer->addr, sizeof(struct in6_addr));
+ IN6_ADDR_COPY(&hdr.ip6_dst, &peer->addr);
+ //memcpy(&hdr.ip6_src, &CNF(ocat_addr), sizeof(struct in6_addr));
+ IN6_ADDR_COPY(&hdr.ip6_src, &CNF(ocat_addr));
hdr.ip6_vfc = 0x60;
hdr.ip6_nxt = IPPROTO_NONE;
hdr.ip6_hops = 1;
diff --git a/src/ocatsocks.c b/src/ocatsocks.c
index d672baf..935330e 100644
--- a/src/ocatsocks.c
+++ b/src/ocatsocks.c
@@ -121,20 +121,20 @@ int socks_connect(const SocksQueue_t *sq)
}
-void socks_queue(const struct in6_addr *addr, int perm)
+void socks_queue(struct in6_addr addr, int perm)
{
SocksQueue_t *squeue;
pthread_mutex_lock(&socks_queue_mutex_);
for (squeue = socks_queue_; squeue; squeue = squeue->next)
- if (IN6_ARE_ADDR_EQUAL(&squeue->addr, addr))
+ if (IN6_ARE_ADDR_EQUAL(&squeue->addr, &addr))
break;
if (!squeue)
{
log_debug("queueing new SOCKS connection request");
if (!(squeue = calloc(1, sizeof(SocksQueue_t))))
log_msg(LOG_EMERG, "could not get memory for SocksQueue entry: \"%s\"", strerror(errno)), exit(1);
- memcpy(&squeue->addr, addr, sizeof(struct in6_addr));
+ IN6_ADDR_COPY(&squeue->addr, &addr);
squeue->perm = perm;
squeue->next = socks_queue_;
socks_queue_ = squeue;
@@ -147,18 +147,37 @@ void socks_queue(const struct in6_addr *addr, int perm)
}
+/*! Remove SocksQueue_t element from SOCKS queue.
+ * @param sq Pointer to element to remove.
+ */
+void socks_unqueue(SocksQueue_t *squeue)
+{
+ SocksQueue_t **sq;
+
+ for (sq = &socks_queue_; *sq; sq = &(*sq)->next)
+ if (*sq == squeue)
+ {
+ *sq = (*sq)->next;
+ log_debug("freeing SOCKS queue element at %p", squeue);
+ free(squeue);
+ break;
+ }
+}
+
+
void *socks_connector(void *p)
{
OcatPeer_t *peer;
- SocksQueue_t **squeue, *sq;
+ SocksQueue_t *squeue;
int i, rc, ps, run = 1;
- char thn[THREAD_NAME_LEN] = "cn:", on[17];
+ char thn[THREAD_NAME_LEN] = "cn:", on[ONION_NAME_LEN];
if ((rc = pthread_detach(pthread_self())))
- log_msg(LOG_ERR, "couldn't detach: \"%s\"", rc);
+ log_msg(LOG_ERR, "couldn't detach: \"%s\"", strerror(rc));
pthread_mutex_lock(&socks_queue_mutex_);
socks_thread_cnt_++;
+ log_debug("%d connector threads running", socks_thread_cnt_);
pthread_mutex_unlock(&socks_queue_mutex_);
while (run)
@@ -166,48 +185,48 @@ void *socks_connector(void *p)
pthread_mutex_lock(&socks_queue_mutex_);
for (;;)
{
- for (squeue = &socks_queue_; *squeue; squeue = &(*squeue)->next)
- if (!(*squeue)->state)
+ for (squeue = socks_queue_; squeue; squeue = squeue->next)
+ if (!squeue->state)
+ {
+ log_debug("unhandled queue entry found");
break;
- if (*squeue)
+ }
+
+ if (squeue)
break;
- pthread_cond_wait(&socks_queue_cond_, &socks_queue_mutex_);
- }
- /*
- do
- {
+ log_debug("waiting for new queue entry");
pthread_cond_wait(&socks_queue_cond_, &socks_queue_mutex_);
- for (squeue = &socks_queue_; *squeue; squeue = &(*squeue)->next)
- if (!(*squeue)->state)
- break;
}
- while (!(*squeue));
- */
// spawn spare thread if there is no one left
- (*squeue)->state = SOCKS_CONNECTING;
+ log_debug("change queue element state to CONNECTING");
+ squeue->state = SOCKS_CONNECTING;
socks_connect_cnt_++;
if (socks_thread_cnt_ <= socks_connect_cnt_)
+ {
+ log_debug("spawning new connector threads");
run_ocat_thread("connector", socks_connector, NULL);
+ }
pthread_mutex_unlock(&socks_queue_mutex_);
// changing thread name
- ipv6tonion(&(*squeue)->addr, on);
+ log_debug("changing thread name");
+ ipv6tonion(&squeue->addr, on);
strlcat(thn, on, THREAD_NAME_LEN);
set_thread_name(thn);
// search for existing peer
lock_peers();
- peer = search_peer(&(*squeue)->addr);
+ peer = search_peer(&squeue->addr);
unlock_peers();
// connect via SOCKS if no peer exists
if (!peer)
- for (i = 0, ps = -1; ((i < SOCKS_MAX_RETRY) || (*squeue)->perm) && ps < 0; i++)
+ for (i = 0, ps = -1; ((i < SOCKS_MAX_RETRY) || squeue->perm) && ps < 0; i++)
{
log_debug("%d. SOCKS connection attempt", i + 1);
- ps = socks_connect(*squeue);
+ ps = socks_connect(squeue);
}
else
log_msg(LOG_INFO, "peer already exists, ignoring");
@@ -215,15 +234,15 @@ void *socks_connector(void *p)
// remove request from queue after connect
log_debug("removing destination from SOCKS queue");
pthread_mutex_lock(&socks_queue_mutex_);
- sq = *squeue;
- *squeue = (*squeue)->next;
- free(sq);
+
+ socks_unqueue(squeue);
socks_connect_cnt_--;
// if there are more threads then pending connections
// terminate thread
if (socks_connect_cnt_ < socks_thread_cnt_ - 1)
{
+ log_debug("going to terminate connector thread");
socks_thread_cnt_--;
run = 0;
}
@@ -232,3 +251,31 @@ void *socks_connector(void *p)
return NULL;
}
+
+void print_socks_queue(FILE *f)
+{
+ int i;
+ char addrstr[INET6_ADDRSTRLEN];
+ SocksQueue_t *squeue;
+
+ pthread_mutex_lock(&socks_queue_mutex_);
+
+ for (squeue = socks_queue_, i = 0; squeue; squeue = squeue->next, i++)
+ {
+ if (!inet_ntop(AF_INET6, &squeue->addr, addrstr, INET6_ADDRSTRLEN))
+ {
+ log_msg(LOG_ERR, "inet_ntop returned NULL pointer: \"%s\"", strerror(errno));
+ strlcpy(addrstr, "ERROR", INET6_ADDRSTRLEN);
+ }
+ fprintf(f, "%d %s %s(%d) %s(%d)\n",
+ i,
+ addrstr,
+ squeue->state == SOCKS_CONNECTING ? "CONNECTING" : "QUEUED",
+ squeue->state,
+ squeue->perm ? "PERMANENT" : "TEMPORARY",
+ squeue->perm);
+ }
+
+ pthread_mutex_unlock(&socks_queue_mutex_);
+}
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onioncat.git
More information about the Pkg-privacy-commits
mailing list