[Pkg-privacy-commits] [onioncat] 63/241: cleanups
Intrigeri
intrigeri at moszumanska.debian.org
Wed Aug 26 16:16:28 UTC 2015
This is an automated email from the git hooks/post-receive script.
intrigeri pushed a commit to branch upstream-master
in repository onioncat.
commit d204cf60dd3495ab4923ba06642193d1e5fa3881
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date: Fri Sep 12 16:08:32 2008 +0000
cleanups
git-svn-id: https://www.cypherpunk.at/svn/onioncat/trunk@279 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
ChangeLog | 1 +
src/ocat.h | 2 +-
src/ocatipv4route.c | 25 ++++++++-----------------
src/ocatroute.c | 41 +++++++++++++++--------------------------
src/ocatthread.c | 4 ++--
5 files changed, 27 insertions(+), 46 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 20476de..82b7658 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
* version 0.1.9
- connect log => $HOME/.ocat/connect_log
+ - IPv4 awareness
* version 0.1.8
- port numbers changed to 8060 for local and virtual hidden service port
diff --git a/src/ocat.h b/src/ocat.h
index 12fb0c8..a045324 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -282,7 +282,7 @@ extern OcatThread_t *octh_;
/* ocatlog.c */
int open_connect_log(const char*);
void log_msg(int, const char *, ...);
-#define DEBUG
+//#define DEBUG
#ifdef DEBUG
#define log_debug(x...) log_msg(L_DEBUG, ## x)
#else
diff --git a/src/ocatipv4route.c b/src/ocatipv4route.c
index 3d305d3..154d605 100644
--- a/src/ocatipv4route.c
+++ b/src/ocatipv4route.c
@@ -46,7 +46,7 @@ static IPv4Route_t *rroot_ = NULL;
static pthread_mutex_t route_mutex_ = PTHREAD_MUTEX_INITIALIZER;
-int ipv4_add_route__(IPv4Route_t *route, IPv4Route_t **root, uint32_t cur_nm)
+int ipv4_add_route(IPv4Route_t *route, IPv4Route_t **root, uint32_t cur_nm)
{
if (!(*root))
{
@@ -85,20 +85,7 @@ int ipv4_add_route__(IPv4Route_t *route, IPv4Route_t **root, uint32_t cur_nm)
cur_nm >>= 1;
cur_nm |= 0x80000000;
- //return ipv4_add_route(&(*root)->next[((route->dest & cur_nm) & ~(cur_nm << 1)) != 0], cur_nm, route);
- return ipv4_add_route__(route, &(*root)->next[BRANCH(route->dest, cur_nm)], cur_nm);
-}
-
-
-int ipv4_add_route(IPv4Route_t *route)
-{
- int r;
-
- pthread_mutex_lock(&route_mutex_);
- r = ipv4_add_route__(route, &rroot_, 0);
- pthread_mutex_unlock(&route_mutex_);
-
- return r;
+ return ipv4_add_route(route, &(*root)->next[BRANCH(route->dest, cur_nm)], cur_nm);
}
@@ -116,7 +103,6 @@ IPv4Route_t *ipv4_lookup_route__(uint32_t ip, IPv4Route_t *route, uint32_t cur_n
if (route->next[BRANCH(ip, cur_nm)])
return ipv4_lookup_route__(ip, route->next[BRANCH(ip, cur_nm)], cur_nm);
- //if (ip & (cur_nm << 1) == route->dest)
if (memcmp(&route->gw, &in6addr_any, sizeof(struct in6_addr)))
return route;
@@ -179,6 +165,7 @@ int parse_route(const char *rs)
{
char buf[strlen(rs) + 1], *s, *b;
IPv4Route_t route;
+ int r;
if (!rs)
return E_RT_NULLPTR;
@@ -207,6 +194,10 @@ int parse_route(const char *rs)
route.netmask = ntohl(route.netmask);
route.dest = ntohl(route.dest);
- return ipv4_add_route(&route);
+ pthread_mutex_lock(&route_mutex_);
+ r = ipv4_add_route(&route, &rroot_, 0);
+ pthread_mutex_unlock(&route_mutex_);
+
+ return r;
}
diff --git a/src/ocatroute.c b/src/ocatroute.c
index d5d669b..d5d5e9f 100644
--- a/src/ocatroute.c
+++ b/src/ocatroute.c
@@ -50,6 +50,13 @@
#include "ocat.h"
+#ifdef HAVE_STRUCT_IPHDR
+#define IPPKTLEN(x) ntohs(((struct iphdr*) (x))->tot_len)
+#define IPHDLEN sizeof(struct iphdr)
+#else
+#define IPPKTLEN(x) ntohs(((struct ip*) (x))->ip_len)
+#define IPHDLEN sizeof(struct ip)
+#endif
// file descriptor of tcp listener
static int sockfd_[2];
@@ -71,8 +78,6 @@ static int socks_thread_cnt_ = 0;
static pthread_mutex_t socks_queue_mutex_ = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t socks_queue_cond_ = PTHREAD_COND_INITIALIZER;
-//int vrec_ = 0;
-
int forward_packet(const struct in6_addr *addr, const char *buf, int buflen)
{
@@ -152,9 +157,6 @@ void *packet_dequeuer(void *p)
pthread_mutex_lock(&queue_mutex_);
if (timed)
{
-#ifdef USE_CLOCK_GETTIME
- clock_gettime(CLOCK_REALTIME, &ts);
-#else
// replaced clock_gettime() due to portability issues
if (gettimeofday(&tv, NULL) == -1)
{
@@ -166,7 +168,6 @@ void *packet_dequeuer(void *p)
ts.tv_sec = tv.tv_sec;
ts.tv_nsec = tv.tv_usec * 1000;
}
-#endif
ts.tv_sec += DEQUEUER_WAKEUP;
log_debug("timed conditional wait...");
rc = pthread_cond_timedwait(&queue_cond_, &queue_mutex_, &ts);
@@ -416,21 +417,13 @@ void *socket_receiver(void *p)
#endif
log_debug("identified IPv4 packet");
-#ifdef HAVE_STRUCT_IPHDR
- if ((peer->fraglen < sizeof(struct iphdr)) || (peer->fraglen < ntohs(((struct iphdr*) peer->fragbuf)->tot_len)))
-#else
- if ((peer->fraglen < sizeof(struct ip)) || (peer->fraglen < ntohs(((struct ip*) peer->fragbuf)->ip_len)))
-#endif
+ if ((peer->fraglen < IPHDLEN) || (peer->fraglen < IPPKTLEN(peer->fragbuf)))
{
log_debug("keeping %d bytes frag", peer->fraglen);
break;
}
-#ifdef HAVE_STRUCT_IPHDR
- len = ntohs(((struct iphdr*) peer->fragbuf)->tot_len);
-#else
- len = ntohs(((struct ip*) peer->fragbuf)->ip_len);
-#endif
+ len = IPPKTLEN(peer->fragbuf);
peer->fraghdr = setup.fhd_key[IPV4_KEY];
}
else
@@ -516,7 +509,7 @@ int insert_peer(int fd, const struct in6_addr *addr, time_t dly)
{
OcatPeer_t *peer;
- log_msg(L_INFO | L_FCONN, "inserting peer fd %d", fd);
+ log_msg(L_NOTICE | L_FCONN, "inserting peer fd %d to active peer list", fd);
set_nonblock(fd);
@@ -596,7 +589,7 @@ int create_listener(struct sockaddr *addr, int sock_len)
return -1;
}
- log_msg(L_NOTICE, "created listener, fd = %d", fd);
+ log_debug("created listener, fd = %d", fd);
return fd;
}
@@ -710,7 +703,7 @@ int socks_connect(const struct in6_addr *addr)
ipv6tonion(addr, onion);
strlcat(onion, ".onion", sizeof(onion));
- log_msg(L_NOTICE, "trying to connecto to \"%s\" [%s]", onion, inet_ntop(AF_INET6, addr, buf, FRAME_SIZE));
+ log_msg(L_NOTICE, "trying to connect to \"%s\" [%s]", onion, inet_ntop(AF_INET6, addr, buf, FRAME_SIZE));
if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
return E_SOCKS_SOCK;
@@ -833,7 +826,7 @@ void *socks_connector(void *p)
log_msg(L_NOTICE, "peer already exists, ignoring");
// remove request from queue after connect
- log_msg(L_NOTICE, "removing from SOCKS queue");
+ log_debug("removing destination from SOCKS queue");
pthread_mutex_lock(&socks_queue_mutex_);
sq = *squeue;
*squeue = (*squeue)->next;
@@ -895,11 +888,7 @@ void packet_forwarder(void)
}
else if (*((uint32_t*) buf) == setup.fhd_key[IPV4_KEY])
{
-#ifdef HAVE_STRUCT_IPHDR
- if (((rlen - 4) < sizeof(struct iphdr)))
-#else
- if (((rlen - 4) < sizeof(struct ip)))
-#endif
+ if (((rlen - 4) < IPHDLEN))
{
log_debug("IPv4 packet too short (%d bytes). dropping", rlen - 4);
continue;
@@ -925,7 +914,7 @@ void packet_forwarder(void)
// now forward either directly or to the queue
if (forward_packet(dest, buf + 4, rlen - 4) == E_FWD_NOPEER)
{
- log_msg(L_NOTICE, "establishing new socks peer");
+ log_debug("adding destination to SOCKS queue");
socks_queue(dest);
log_debug("queuing packet");
queue_packet(dest, buf + 4, rlen - 4);
diff --git a/src/ocatthread.c b/src/ocatthread.c
index c4b7b67..5e4c32b 100644
--- a/src/ocatthread.c
+++ b/src/ocatthread.c
@@ -75,9 +75,9 @@ void *thread_run(void *p)
(void) init_ocat_thread(((OcatThread_t *)p)->name);
// call thread entry function
- log_msg(L_NOTICE, "running");
+ log_debug("starting thread");
r = ((OcatThread_t*)p)->entry(((OcatThread_t*)p)->parm);
- log_msg(L_NOTICE, "terminating");
+ log_debug("terminating thread");
pthread_mutex_lock(&thread_mutex_);
for (tl = &octh_; *tl; tl = &(*tl)->next)
--
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