[Pkg-privacy-commits] [onioncat] 72/340: (*) packet queue disabled by default and configurable by configure-script (*) keepalive activated for permanent connections (*) connections configurable by config file
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:04:26 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 533e4b94ce2bfae47118f90f81e7dec7d1853603
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date: Fri Oct 31 07:47:05 2008 +0000
(*) packet queue disabled by default and configurable by configure-script
(*) keepalive activated for permanent connections
(*) connections configurable by config file
git-svn-id: http://www.cypherpunk.at/svn/onioncat/trunk@344 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
config.h.in | 3 +++
configure | 10 +++++++++
configure.ac | 1 +
src/ocat.c | 13 +++++++++++
src/ocat.h | 8 ++++++-
src/ocatroute.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++--------
6 files changed, 95 insertions(+), 10 deletions(-)
diff --git a/config.h.in b/config.h.in
index 3f01aee..84200bf 100644
--- a/config.h.in
+++ b/config.h.in
@@ -87,6 +87,9 @@
/* enable packet logging */
#undef PACKET_LOG
+/* enable packet queue */
+#undef PACKET_QUEUE
+
/* Version number of package */
#undef VERSION
diff --git a/configure b/configure
index 44155ca..cdcf02c 100755
--- a/configure
+++ b/configure
@@ -1242,6 +1242,7 @@ Optional Features:
--enable-debug enable debugging
--enable-packet-log enable packet logging
--enable-handle-http enable handling of accidental HTTP requests
+ --enable-packet-queue enable queueuing of packets while connecting setup
--disable-dependency-tracking speeds up one-time build
--enable-dependency-tracking do not reject slow dependency extractors
@@ -2202,6 +2203,15 @@ _ACEOF
fi
+# Check whether --enable-packet-queue was given.
+if test "${enable_packet_queue+set}" = set; then
+ enableval=$enable_packet_queue;
+cat >>confdefs.h <<\_ACEOF
+#define PACKET_QUEUE
+_ACEOF
+
+fi
+
# Checks for programs.
ac_ext=c
diff --git a/configure.ac b/configure.ac
index c5d6a4b..92d5290 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,6 +12,7 @@ AC_SUBST([CFLAGS], [-Wall])
AC_ARG_ENABLE([debug], AC_HELP_STRING([--enable-debug], [enable debugging]), AC_DEFINE([DEBUG], [], [enable debugging]))
AC_ARG_ENABLE([packet-log], AC_HELP_STRING([--enable-packet-log], [enable packet logging]), AC_DEFINE([PACKET_LOG], [], [enable packet logging]))
AC_ARG_ENABLE([handle-http], AC_HELP_STRING([--enable-handle-http], [enable handling of accidental HTTP requests]), AC_DEFINE([HANDLE_HTTP], [], [enable handling of accidental HTTP requests]))
+AC_ARG_ENABLE([packet-queue], AC_HELP_STRING([--enable-packet-queue], [enable queueuing of packets while connecting setup]), AC_DEFINE([PACKET_QUEUE], [], [enable packet queue]))
# Checks for programs.
AC_PROG_CC
diff --git a/src/ocat.c b/src/ocat.c
index c9a5b9a..57552de 100644
--- a/src/ocat.c
+++ b/src/ocat.c
@@ -192,6 +192,7 @@ int main(int argc, char *argv[])
log_msg(L_NOTICE, "%s (c) Bernhard R. Fischer -- compiled %s %s", PACKAGE_STRING, __DATE__, __TIME__);
+#if 0
if (setup.config_file)
{
log_msg(L_NOTICE, "reading config file %s", setup.config_file);
@@ -199,6 +200,7 @@ int main(int argc, char *argv[])
log_msg(L_ERROR, "error opening file: %s", strerror(errno)), exit(1);
ctrl_handler((void*) c);
}
+#endif
memcpy(&setup.ocat_hwaddr[3], &setup.ocat_addr.s6_addr[13], 3);
if (setup.use_tap);
@@ -249,12 +251,23 @@ int main(int argc, char *argv[])
// create socks connector thread
run_ocat_thread("connector", socks_connector, NULL);
+#ifdef PACKET_QUEUE
// start packet dequeuer
run_ocat_thread("dequeuer", packet_dequeuer, NULL);
+#endif
// start controller socket thread
if (setup.controller)
run_ocat_thread("controller", ocat_controller, NULL);
+ // reading config file
+ if (setup.config_file)
+ {
+ log_msg(L_NOTICE, "reading config file %s", setup.config_file);
+ if ((c = open(setup.config_file, O_RDONLY)) == -1)
+ log_msg(L_ERROR, "error opening file: %s", strerror(errno)), exit(1);
+ ctrl_handler((void*) c);
+ }
+
// start forwarding packets from tunnel
log_msg(L_NOTICE, "starting packet forwarder");
packet_forwarder();
diff --git a/src/ocat.h b/src/ocat.h
index de9f65e..609c198 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -82,7 +82,9 @@
//! # of secs after a cleaner wakeup occurs
#define CLEANER_WAKEUP 10
//! # of secs after stats output is generated
-#define STAT_WAKEUP (600/CLEANER_WAKEUP)
+#define STAT_WAKEUP 600
+//! keepalive time
+#define KEEPALIVE_TIME (MAX_IDLE_TIME/2)
//! log flags. word is considered as 16 bit, lower byte for level, upper byte for additional flags.
#define L_LEVEL_MASK 0x00ff
@@ -166,6 +168,7 @@ struct OcatSetup
uint8_t ocat_hwaddr[ETH_ALEN];
};
+#ifdef PACKET_QUEUE
typedef struct PacketQueue
{
struct PacketQueue *next;
@@ -174,6 +177,7 @@ typedef struct PacketQueue
time_t time;
void *data;
} PacketQueue_t;
+#endif
typedef struct SocksHdr
{
@@ -338,7 +342,9 @@ int tun_alloc(char *, struct in6_addr);
void init_peers(void);
void *socket_receiver(void *);
void packet_forwarder(void);
+#ifdef PACKET_QUEUE
void *packet_dequeuer(void *);
+#endif
void *socket_acceptor(void *);
void *socks_connector(void *);
void *socket_cleaner(void *);
diff --git a/src/ocatroute.c b/src/ocatroute.c
index 41ff14f..d8499ef 100644
--- a/src/ocatroute.c
+++ b/src/ocatroute.c
@@ -68,11 +68,14 @@ static int ctrlfd_[2];
// file descriptors of socket_receiver pipe
// used for internal communication
static int lpfd_[2];
+
+#ifdef PACKET_QUEUE
// packet queue pointer
static PacketQueue_t *queue_ = NULL;
// mutex and condition variable for packet queue
static pthread_mutex_t queue_mutex_ = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t queue_cond_ = PTHREAD_COND_INITIALIZER;
+#endif
// SOCKS connector queue vars
static SocksQueue_t *socks_queue_ = NULL;
@@ -120,6 +123,7 @@ int forward_packet(const struct in6_addr *addr, const char *buf, int buflen)
}
+#ifdef PACKET_QUEUE
void queue_packet(const struct in6_addr *addr, const char *buf, int buflen)
{
PacketQueue_t *queue;
@@ -205,6 +209,7 @@ void *packet_dequeuer(void *p)
pthread_mutex_unlock(&queue_mutex_);
}
}
+#endif
/*! Check if source and destination address has
@@ -995,29 +1000,63 @@ void packet_forwarder(void)
{
log_debug("adding destination to SOCKS queue");
socks_queue(dest, 0);
+#ifdef PACKET_QUEUE
log_debug("queuing packet");
queue_packet(dest, buf + 4, rlen - 4);
+#endif
}
}
}
+int send_keepalive(const OcatPeer_t *peer)
+{
+ struct ip6_hdr hdr;
+ int len;
+
+ memset(&hdr, 0, sizeof(hdr));
+ memcpy(&hdr.ip6_dst, &peer->addr, sizeof(struct in6_addr));
+ memcpy(&hdr.ip6_src, &setup.ocat_addr, sizeof(struct in6_addr));
+ hdr.ip6_vfc = 0x60;
+ hdr.ip6_nxt = IPPROTO_NONE;
+ hdr.ip6_hops = 1;
+
+ log_debug("sending %d bytes keepalive to fd %d", sizeof(hdr), peer->tcpfd);
+
+ if ((len = send(peer->tcpfd, &hdr, sizeof(hdr), MSG_DONTWAIT)) == -1)
+ {
+ log_msg(L_ERROR, "could not send keepalive: %s", strerror(errno));
+ return -1;
+ }
+ if (len != sizeof(hdr))
+ {
+ log_msg(L_ERROR, "sending of %d bytes keepalive truncated to %d", sizeof(hdr), len);
+ return -1;
+ }
+ return 0;
+}
+
+
void *socket_cleaner(void *ptr)
{
OcatPeer_t *peer, **p;
- int cnt;
+ int stat_wup = 0;
+ time_t act_time;
- for (cnt = STAT_WAKEUP; ; cnt--)
+ for (;;)
{
- if (!cnt)
- {
- cnt = STAT_WAKEUP;
- log_msg(L_NOTICE, "stats: ...");
- }
-
sleep(CLEANER_WAKEUP);
log_debug("wakeup");
+ act_time = time(NULL);
+
+ // stats output
+ if (act_time - stat_wup >= STAT_WAKEUP)
+ {
+ stat_wup = act_time;
+ log_msg(L_NOTICE, "stats: ... (not implemented yet)");
+ }
+
// cleanup MAC table
mac_cleanup();
@@ -1026,7 +1065,20 @@ void *socket_cleaner(void *ptr)
for (p = get_first_peer_ptr(); *p; p = &(*p)->next)
{
lock_peer(*p);
- if ((*p)->state && !(*p)->perm && (*p)->time + MAX_IDLE_TIME < time(NULL))
+
+ // handle permanent connections
+ if ((*p)->perm)
+ {
+ // sending keepalive
+ if (act_time - (*p)->time >= KEEPALIVE_TIME)
+ {
+ send_keepalive(*p);
+ (*p)->time = act_time;
+ }
+ unlock_peer(*p);
+ }
+ // handle temporary connections
+ else if ((*p)->state && act_time - (*p)->time >= MAX_IDLE_TIME)
{
peer = *p;
*p = peer->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