[Pkg-privacy-commits] [onioncat] 58/340: introduced setup structure and connect log
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:04:24 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 50f0dc9750d8fdea5c57f1a98c4ed97ec55553aa
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date: Thu Jul 17 13:49:32 2008 +0000
introduced setup structure and connect log
git-svn-id: http://www.cypherpunk.at/svn/onioncat/trunk@227 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
ChangeLog | 3 +
TODO | 3 +
configure | 20 +++---
man/man1/ocat.1 | 75 ++++++++++++++++++++++
src/Makefile.am | 2 +-
src/ocat.c | 89 +++++++++++++-------------
src/ocat.h | 58 +++++++++++++----
src/ocatlog.c | 71 ++++++++++++++++-----
src/ocatpeer.c | 2 +-
src/ocatroute.c | 189 +++++++++++++++++++++++--------------------------------
src/ocatthread.c | 2 +-
src/ocattun.c | 15 ++---
12 files changed, 330 insertions(+), 199 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c5069ad..20476de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+* version 0.1.9
+ - connect log => $HOME/.ocat/connect_log
+
* version 0.1.8
- port numbers changed to 8060 for local and virtual hidden service port
- port number of controller interface changed to 8066
diff --git a/TODO b/TODO
index 3270f9c..a9ab182 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,6 @@
+* forward multicasting packets (ff00::/8)
+* IPv4 forwarding + routing
+* tun-header packet dependent
* create some kind of connection log
* frame checking may be improved
* improve getopt() -- currently many things are hardcoded
diff --git a/configure b/configure
index 1f69316..3dd505b 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.61 for onioncat 0.1.8.
+# Generated by GNU Autoconf 2.61 for onioncat 0.1.9.
#
# Report bugs to <rahra at cypherpunk.at>.
#
@@ -574,8 +574,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package.
PACKAGE_NAME='onioncat'
PACKAGE_TARNAME='onioncat'
-PACKAGE_VERSION='0.1.8'
-PACKAGE_STRING='onioncat 0.1.8'
+PACKAGE_VERSION='0.1.9'
+PACKAGE_STRING='onioncat 0.1.9'
PACKAGE_BUGREPORT='rahra at cypherpunk.at'
ac_subst_vars='SHELL
@@ -1166,7 +1166,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures onioncat 0.1.8 to adapt to many kinds of systems.
+\`configure' configures onioncat 0.1.9 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1232,7 +1232,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of onioncat 0.1.8:";;
+ short | recursive ) echo "Configuration of onioncat 0.1.9:";;
esac
cat <<\_ACEOF
@@ -1315,7 +1315,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-onioncat configure 0.1.8
+onioncat configure 0.1.9
generated by GNU Autoconf 2.61
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1329,7 +1329,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by onioncat $as_me 0.1.8, which was
+It was created by onioncat $as_me 0.1.9, which was
generated by GNU Autoconf 2.61. Invocation command line was
$ $0 $@
@@ -2019,7 +2019,7 @@ fi
# Define the identity of the package.
PACKAGE='onioncat'
- VERSION='0.1.8'
+ VERSION='0.1.9'
cat >>confdefs.h <<_ACEOF
@@ -4244,7 +4244,7 @@ exec 6>&1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by onioncat $as_me 0.1.8, which was
+This file was extended by onioncat $as_me 0.1.9, which was
generated by GNU Autoconf 2.61. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -4297,7 +4297,7 @@ Report bugs to <bug-autoconf at gnu.org>."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
-onioncat config.status 0.1.8
+onioncat config.status 0.1.9
configured by $0, generated by GNU Autoconf 2.61,
with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
diff --git a/man/man1/ocat.1 b/man/man1/ocat.1
new file mode 100644
index 0000000..38d55ce
--- /dev/null
+++ b/man/man1/ocat.1
@@ -0,0 +1,75 @@
+.\" Copyright 2008 Bernhard R. Fischer, Daniel Haslinger.
+.\"
+.\" This file is part of OnionCat.
+.\"
+.\" OnionCat is free software: you can redistribute it and/or modify
+.\" it under the terms of the GNU General Public License as published by
+.\" the Free Software Foundation, version 3 of the License.
+.\"
+.\" OnionCat is distributed in the hope that it will be useful,
+.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
+.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+.\" GNU General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public License
+.\" along with OnionCat. If not, see <http://www.gnu.org/licenses/>.
+.\"
+.TH OCAT 1 2008-06-23 "ocat" "OnionCat User's Manual"
+.SH NAME
+ocat \- OnionCat creates a transparent IPv6 layer on top of TOR's hidden services.
+.SH SYNOPSIS
+.B ocat
+-i \fIonion_id (1st form)\fR
+.br
+.B ocat
+-o \fIIPv6_address (2nd form)\fR
+.br
+.B ocat
+[\fIOPTION\fR] \fIonion_id (3rd form)\fR
+.br
+.SH DESCRIPTION
+OnionCat creates a transparent IPv6 layer on top of TOR's hidden services. It
+transmits any kind of IP-based data transparently through the TOR network on a
+location hidden basis. You can think of it as a point-to-multipoint VPN
+between hidden services.
+
+OnionCat is a stand-alone application which runs in userland and is a connector
+between TOR and the local OS. Any protocol which is based on IP can be
+transmitted. Of course, UDP and TCP (and probably ICMP) are the most important
+ones but all other protocols can also be forwarded through it.
+
+.TP
+\fB\-T\fR tun_dev
+tun device file to open for creation of tun interface, defaults to
+/dev/net/tun. Setup of a tun device needs root permissions. ocat automatically
+changes userid after the tun device is set up correctly.
+.TP
+\fB\-u\fR username
+username under which ocat should run. The uid is changed as soon as possible
+after tun device setup.
+
+.SH FILES
+$HOME/.ocat/connect_log
+.SH AUTHOR
+Written by Bernhard R. Fischer.
+Conecption by Bernhard R. Fischer and Daniel Haslinger.
+.SH "SEE ALSO"
+OnionCat project page http://www.abenteuerland.at/onioncat/
+
+TOR project homepage http://www.torproject.org/
+.SH COPYRIGHT
+Copyright 2008 Bernhard R. Fischer, Daniel Haslinger.
+
+This file is part of OnionCat.
+
+OnionCat is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 3 of the License.
+
+OnionCat is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with OnionCat. If not, see <http://www.gnu.org/licenses/>.
diff --git a/src/Makefile.am b/src/Makefile.am
index ddabf01..d182bc8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
bin_PROGRAMS = ocat
-ocat_SOURCES = ocat.c ocatlog.c ocatroute.c ocatthread.c ocattun.c ocatv6conv.c ocatcompat.c ocatpeer.c
+ocat_SOURCES = ocat.c ocatlog.c ocatroute.c ocatthread.c ocattun.c ocatv6conv.c ocatcompat.c ocatpeer.c ocatsetup.c
include_HEADERS = ocat.h strlcpy.c strlcat.c
diff --git a/src/ocat.c b/src/ocat.c
index 8de5a54..6f834c7 100644
--- a/src/ocat.c
+++ b/src/ocat.c
@@ -36,19 +36,12 @@
#include "ocat.h"
-int tunfd_[2] = {0, 1};
-
-extern int debug_level_;
-char *usrname_ = OCAT_UNAME;
-char onion_url_[ONION_NAME_SIZE];
-struct in6_addr ocat_addr_;
-
-
void usage(const char *s)
{
fprintf(stderr,
"%s (c) Bernhard R. Fischer -- compiled %s %s\n"
"usage: %s [OPTIONS] <onion_hostname>\n"
+ " -a create connect log at \"$HOME/%s/%s\" (default = %d)\n"
" -h display usage message\n"
" -C disable local controller interface\n"
" -d <n> set debug level to n, default = %d\n"
@@ -59,39 +52,44 @@ void usage(const char *s)
" -s <port> set hidden service virtual port, default = %d\n"
" -t <port> set tor SOCKS port, default = %d\n"
#ifndef WITHOUT_TUN
- " -p test tun header and exit\n"
+ " -p test tun header and exit (debug feature only)\n"
" -T <tun_device> path to tun character device, default = \"%s\"\n"
#endif
" -u <user> change UID to user, default = \"%s\"\n"
- " -v validate packets from sockets, default = %d\n"
- , PACKAGE_STRING, __DATE__, __TIME__, s, debug_level_, ocat_listen_port_, ocat_dest_port_, tor_socks_port_,
+ " -v validate packets from sockets, default = %d (validation not mature)\n"
+ , PACKAGE_STRING, __DATE__, __TIME__, s,
+ // option defaults start here
+ OCAT_DIR, OCAT_CONNECT_LOG, setup.create_clog, setup.debug_level, setup.ocat_listen_port, setup.ocat_dest_port, setup.tor_socks_port,
#ifndef WITHOUT_TUN
TUN_DEV,
#endif
- OCAT_UNAME, vrec_);
+ OCAT_UNAME, setup.vrec);
}
int main(int argc, char *argv[])
{
- char tunname[IFNAMSIZ] = "", /*onion[ONION_NAME_SIZE],*/ *s, ip6addr[INET6_ADDRSTRLEN];
- //struct in6_addr addr;
+ char tunname[IFNAMSIZ] = "", *s, ip6addr[INET6_ADDRSTRLEN];
int c, runasroot = 0;
struct passwd *pwd;
- int urlconv = 0, test_only = 0, controller = 1;
+ int urlconv = 0;
if (argc < 2)
usage(argv[0]), exit(1);
- while ((c = getopt(argc, argv, "Cd:hriopl:t:T:s:u:")) != -1)
+ while ((c = getopt(argc, argv, "aCd:hriopl:t:T:s:u:")) != -1)
switch (c)
{
+ case 'a':
+ setup.create_clog = 1;
+ break;
+
case 'C':
- controller = 0;
+ setup.controller = 0;
break;
case 'd':
- debug_level_ = atoi(optarg);
+ setup.debug_level = atoi(optarg);
break;
case 'i':
@@ -99,7 +97,7 @@ int main(int argc, char *argv[])
break;
case 'l':
- ocat_listen_port_ = atoi(optarg);
+ setup.ocat_listen_port = atoi(optarg);
break;
case 'o':
@@ -108,19 +106,20 @@ int main(int argc, char *argv[])
case 'r':
runasroot = 1;
+ setup.usrname = "root";
break;
case 's':
- ocat_dest_port_ = atoi(optarg);
+ setup.ocat_dest_port = atoi(optarg);
break;
case 't':
- tor_socks_port_ = atoi(optarg);
+ setup.tor_socks_port = atoi(optarg);
break;
#ifndef WITHOUT_TUN
case 'p':
- test_only = 1;
+ setup.test_only = 1;
break;
case 'T':
@@ -129,11 +128,11 @@ int main(int argc, char *argv[])
#endif
case 'u':
- usrname_ = optarg;
+ setup.usrname = optarg;
break;
case 'v':
- vrec_ = 1;
+ setup.vrec = 1;
break;
case 'h':
@@ -150,25 +149,25 @@ int main(int argc, char *argv[])
if (urlconv == 2)
{
- if (inet_pton(AF_INET6, argv[optind], &ocat_addr_) <= 0)
+ if (inet_pton(AF_INET6, argv[optind], &setup.ocat_addr) <= 0)
log_msg(L_ERROR, "%s", strerror(errno)), exit(1);
- if (!has_tor_prefix(&ocat_addr_))
+ if (!has_tor_prefix(&setup.ocat_addr))
log_msg(L_ERROR, "address does not have TOR prefix"), exit(1);
- ipv6tonion(&ocat_addr_, onion_url_);
- printf("%s.onion\n", onion_url_);
+ ipv6tonion(&setup.ocat_addr, setup.onion_url);
+ printf("%s.onion\n", setup.onion_url);
exit(0);
}
// convert parameter to IPv6 address
- strncpy(onion_url_, argv[optind], ONION_NAME_SIZE);
- if ((s = strchr(onion_url_, '.')))
+ strncpy(setup.onion_url, argv[optind], ONION_NAME_SIZE);
+ if ((s = strchr(setup.onion_url, '.')))
*s = '\0';
- if (strlen(onion_url_) != 16)
+ if (strlen(setup.onion_url) != 16)
log_msg(L_ERROR, "parameter seems not to be valid onion hostname"), exit(1);
- if (oniontipv6(onion_url_, &ocat_addr_) == -1)
+ if (oniontipv6(setup.onion_url, &setup.ocat_addr) == -1)
log_msg(L_ERROR, "parameter seems not to be valid onion hostname"), exit(1);
- inet_ntop(AF_INET6, &ocat_addr_, ip6addr, INET6_ADDRSTRLEN);
+ inet_ntop(AF_INET6, &setup.ocat_addr, ip6addr, INET6_ADDRSTRLEN);
if (urlconv == 1)
{
@@ -180,16 +179,16 @@ int main(int argc, char *argv[])
#ifndef WITHOUT_TUN
// create TUN device
- tunfd_[0] = tunfd_[1] = tun_alloc(tunname, ocat_addr_);
+ setup.tunfd[0] = setup.tunfd[1] = tun_alloc(tunname, setup.ocat_addr);
#ifdef TEST_TUN_HDR
test_tun_hdr();
- if (test_only)
+ if (setup.test_only)
exit(0);
#endif
#endif
log_msg(L_NOTICE, "local IP is %s on %s", ip6addr, tunname);
- log_msg(L_DEBUG, "tun frameheader = 0x%08x", ntohl(fhd_key_));
+ log_debug("tun frameheader = 0x%08x", ntohl(setup.fhd_key));
// start socket receiver thread
run_ocat_thread("receiver", socket_receiver, NULL);
@@ -198,26 +197,30 @@ int main(int argc, char *argv[])
// starting socket cleaner
run_ocat_thread("cleaner", socket_cleaner, NULL);
+ // getting passwd info for user
+ errno = 0;
+ if (!(pwd = getpwnam(setup.usrname)))
+ log_msg(L_FATAL, "can't get information for user \"%s\": \"%s\"", setup.usrname, errno ? strerror(errno) : "user not found"), exit(1);
+
if (!runasroot && !getuid())
{
- errno = 0;
- if (!(pwd = getpwnam(usrname_)))
- log_msg(L_FATAL, "can't get information for user \"%s\": \"%s\"", usrname_, errno ? strerror(errno) : "user not found"), exit(1);
-
- log_msg(L_NOTICE, "running as root, changing uid/gid to %s (uid %d/gid %d)", usrname_, pwd->pw_uid, pwd->pw_gid);
+ log_msg(L_NOTICE, "running as root, changing uid/gid to %s (uid %d/gid %d)", setup.usrname, pwd->pw_uid, pwd->pw_gid);
if (setgid(pwd->pw_gid))
log_msg(L_ERROR, "could not change gid: \"%s\"", strerror(errno)), exit(1);
if (setuid(pwd->pw_uid))
log_msg(L_ERROR, "could not change uid: \"%d\"", strerror(errno)), exit(1);
}
- log_msg(L_DEBUG, "uid/gid = %d/%d", getuid(), getgid());
+ log_debug("uid/gid = %d/%d", getuid(), getgid());
+
+ if (setup.create_clog)
+ open_connect_log(pwd->pw_dir);
// create socks connector thread
run_ocat_thread("connector", socks_connector, NULL);
// start packet dequeuer
run_ocat_thread("dequeuer", packet_dequeuer, NULL);
// start controller socket thread
- if (controller)
+ if (setup.controller)
run_ocat_thread("controller", ocat_controller, NULL);
// start forwarding packets from tunnel
diff --git a/src/ocat.h b/src/ocat.h
index cde1f84..9197981 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -46,6 +46,8 @@
#define OCAT_UNAME "tor"
#define OCAT_UID 112
#define OCAT_URL "http://www.abenteuerland.at/onioncat/"
+#define OCAT_DIR ".ocat"
+#define OCAT_CONNECT_LOG "connect_log"
//! Maximum frame (packet) size, should be able to keep one maximum size ipv6-packet: 2^16 + 40 + 4
#define FRAME_SIZE 65580
@@ -59,11 +61,15 @@
#define MAX_IDLE_TIME 120
#define CLEANER_WAKEUP 10
+//! log flags. word is considered as 16 bit, lower byte for level, upper byte for additional flags.
+#define L_LEVEL_MASK 0x00ff
+#define L_FLAG_MASK 0xff00
#define L_INFO 0
#define L_NOTICE 1
#define L_ERROR 2
#define L_FATAL 3
#define L_DEBUG 4
+#define L_FCONN (1 << 15)
#define E_SOCKS_SOCK -1
#define E_SOCKS_CONN -2
@@ -84,6 +90,35 @@
#define SOCKS_CONNECTING 1
#define SOCKS_MAX_RETRY 3
+struct OcatSetup
+{
+ //! frame header of local OS in network byte order
+ //! it is initialized in ocattun.c
+ uint32_t fhd_key;
+ //! TCP port of SOCKS port of local Tor proxy
+ uint16_t tor_socks_port;
+ //! reload port of OnionCat listening for connections
+ uint16_t ocat_listen_port;
+ //! virtual port of OnionCat hidden service
+ uint16_t ocat_dest_port;
+ //! local port of controller interface
+ uint16_t ocat_ctrl_port;
+ //! enable packet validation
+ int vrec;
+ //! file descriptors of TUN device (usually tunfd[0] == tunfd[1])
+ int tunfd[2];
+ int debug_level;
+ char *usrname;
+ char onion_url[ONION_NAME_SIZE];
+ struct in6_addr ocat_addr;
+ int create_clog;
+ int runasroot;
+ int urlconv;
+ int test_only;
+ int controller;
+ char *ocat_dir;
+ char *tun_dev;
+};
typedef struct PacketQueue
{
@@ -190,29 +225,27 @@ struct ip6_hdr
#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
#endif
-extern uint16_t tor_socks_port_;
-extern uint16_t ocat_listen_port_;
-extern uint16_t ocat_dest_port_;
-extern int vrec_;
-
#ifndef WITHOUT_TUN
#define TUN_DEV "/dev/net/tun"
extern char *tun_dev_;
-extern uint32_t fhd_key_;
+//extern uint32_t fhd_key_;
#endif
extern pthread_mutex_t thread_mutex_;
extern OcatThread_t *octh_;
-extern char *usrname_;
/* ocat.c */
-//extern int tunfd_[2];
-extern int tunfd_[];
-extern char onion_url_[];
-extern struct in6_addr ocat_addr_;
+//extern int tunfd_[];
/* ocatlog.c */
+int open_connect_log(const char*);
void log_msg(int, const char *, ...);
+#define DEBUG
+#ifdef DEBUG
+#define log_debug(x...) log_msg(L_DEBUG, ## x)
+#else
+#define log_debug(x...)
+#endif
/* ocatv6conv.c */
char *ipv6tonion(const struct in6_addr *, char *);
@@ -259,5 +292,8 @@ OcatPeer_t *search_peer(const struct in6_addr *);
OcatPeer_t *get_empty_peer(void);
void delete_peer(OcatPeer_t *);
+/* ocatsetup.c */
+extern struct OcatSetup setup;
+
#endif
diff --git a/src/ocatlog.c b/src/ocatlog.c
index d540c67..6164491 100644
--- a/src/ocatlog.c
+++ b/src/ocatlog.c
@@ -25,42 +25,85 @@
#include <errno.h>
#include <time.h>
#include <pthread.h>
+#include <sys/stat.h>
#include "ocat.h"
#define TIMESTRLEN 64
+#define CBUFLEN 1024
-int debug_level_ = 4;
static pthread_mutex_t log_mutex_ = PTHREAD_MUTEX_INITIALIZER;
static const char *flty_[] = {"info", "notice", "error", "fatal", "debug"};
+//! FILE pointer to connect log
+static FILE *clog_ = NULL;
-void log_msg(int lf, const char *fmt, ...)
+int open_connect_log(const char *dir)
+{
+ char buf[CBUFLEN];
+
+ if (clog_)
+ return 0;
+
+ strlcpy(buf, dir, CBUFLEN);
+ strlcat(buf, "/", CBUFLEN);
+ strlcat(buf, setup.ocat_dir, CBUFLEN);
+
+ log_debug("creating ocat log dir \"%s\"", buf);
+ if (mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP) && (errno != EEXIST))
+ {
+ log_msg(L_ERROR, "could not create ocat directory \"%s\": \"%s\"", buf, strerror(errno));
+ return -1;
+ }
+
+ strlcat(buf, "/", CBUFLEN);
+ strlcat(buf, OCAT_CONNECT_LOG, CBUFLEN);
+
+ log_debug("opening connect log \"%s\"", buf);
+ if (!(clog_ = fopen(buf, "a")))
+ {
+ log_msg(L_ERROR, "could not open connect log \"%s\": \"%s\"", buf, strerror(errno));
+ return -1;
+ }
+ log_msg(L_INFO | L_FCONN, "connect log started");
+ return 0;
+}
+
+
+void vlog_msgf(FILE *out, int lf, const char *fmt, va_list ap)
{
struct tm *tm;
time_t t;
- FILE *out = stderr;
char timestr[TIMESTRLEN] = "";
- va_list ap;
const OcatThread_t *th = get_thread();
+ int level = lf & L_LEVEL_MASK;
- if (debug_level_ < lf || lf < 0)
+ if (setup.debug_level < level)
return;
t = time(NULL);
- tm = localtime(&t);
- if (tm)
- //strftime(timestr, 32, "%c", tm);
+ if ((tm = localtime(&t)))
strftime(timestr, TIMESTRLEN, "%a, %d %b %Y %H:%M:%S %z", tm);
- pthread_mutex_lock(&log_mutex_);
- fprintf(out, "%s [%d:%-*s:%6s] ", timestr, th->id, THREAD_NAME_LEN - 1, th->name, flty_[lf]);
+ (void) pthread_mutex_lock(&log_mutex_);
+ fprintf(out, "%s [%d:%-*s:%6s] ", timestr, th->id, THREAD_NAME_LEN - 1, th->name, flty_[level]);
+ vfprintf(out, fmt, ap);
+ fprintf(out, "\n");
+ (void) pthread_mutex_unlock(&log_mutex_);
+}
+
+
+void log_msg(int lf, const char *fmt, ...)
+{
+ va_list ap;
va_start(ap, fmt);
- vfprintf(out, fmt, ap);
+ vlog_msgf(stderr, lf, fmt, ap);
+ if (clog_ && (lf & L_FCONN))
+ {
+ vlog_msgf(clog_, lf, fmt, ap);
+ (void) fflush(clog_);
+ }
va_end(ap);
-
- fprintf(out, "\n");
- pthread_mutex_unlock(&log_mutex_);
}
diff --git a/src/ocatpeer.c b/src/ocatpeer.c
index 2c489f1..5daff47 100644
--- a/src/ocatpeer.c
+++ b/src/ocatpeer.c
@@ -98,7 +98,7 @@ OcatPeer_t *get_empty_peer(void)
return NULL;
}
- peer->fraghdr = fhd_key_;
+ peer->fraghdr = setup.fhd_key;
if ((rc = pthread_mutex_init(&peer->mutex, NULL)))
{
log_msg(L_FATAL, "cannot init new peer mutex: \"%s\"", strerror(rc));
diff --git a/src/ocatroute.c b/src/ocatroute.c
index fdbcf0c..0987ec8 100644
--- a/src/ocatroute.c
+++ b/src/ocatroute.c
@@ -65,20 +65,7 @@ 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;
-// frame header of local OS in network byte order
-// it is initialized in ocattun.c
-uint32_t fhd_key_ = 0;
-
-uint16_t tor_socks_port_ = TOR_SOCKS_PORT;
-uint16_t ocat_listen_port_ = OCAT_LISTEN_PORT;
-uint16_t ocat_dest_port_ = OCAT_DEST_PORT;
-uint16_t ocat_ctrl_port_ = OCAT_CTRL_PORT;
-
-int vrec_ = 0;
-
-#ifdef SNDBUF
-int snd_buf_size_ = 0;
-#endif
+//int vrec_ = 0;
int forward_packet(const struct in6_addr *addr, const char *buf, int buflen)
@@ -93,29 +80,13 @@ int forward_packet(const struct in6_addr *addr, const char *buf, int buflen)
if (!peer)
{
- log_msg(L_DEBUG, "no peer for forwarding");
+ log_debug("no peer for forwarding");
return E_FWD_NOPEER;
}
- log_msg(L_DEBUG, "forwarding %d bytes to TCP fd %d", buflen, peer->tcpfd);
-
-#ifdef SNDBUF
- if (ioctl(peer->tcpfd, TIOCOUTQ, &len) != -1)
- {
- if (snd_buf_size_ - len < buflen)
- {
- log_msg(L_ERROR, "OUTQ too less space, dropping packet");
- unlock_peer(peer);
- return E_FWD_NOBUF;
- }
- }
- else
- log_msg(L_ERROR, "could not get OUTQ size: \"%s\"", strerror(errno));
+ log_debug("forwarding %d bytes to TCP fd %d", buflen, peer->tcpfd);
- if ((len = write(peer->tcpfd, buf, buflen)) == -1)
-#else
if ((len = send(peer->tcpfd, buf, buflen, MSG_DONTWAIT)) == -1)
-#endif
{
log_msg(L_ERROR, "could not write %d bytes to peer %d: \"%s\", dropping", buflen, peer->tcpfd, strerror(errno));
}
@@ -139,7 +110,7 @@ void queue_packet(const struct in6_addr *addr, const char *buf, int buflen)
{
PacketQueue_t *queue;
- log_msg(L_DEBUG, "copying packet to heap for queue");
+ log_debug("copying packet to heap for queue");
if (!(queue = malloc(sizeof(PacketQueue_t) + buflen)))
{
log_msg(L_ERROR, "%s for packet to queue", strerror(errno));
@@ -152,11 +123,11 @@ void queue_packet(const struct in6_addr *addr, const char *buf, int buflen)
memcpy(queue->data, buf, buflen);
queue->time = time(NULL);
- log_msg(L_DEBUG, "queuing packet");
+ log_debug("queuing packet");
pthread_mutex_lock(&queue_mutex_);
queue->next = queue_;
queue_ = queue;
- log_msg(L_DEBUG, "waking up dequeuer");
+ log_debug("waking up dequeuer");
pthread_cond_signal(&queue_cond_);
pthread_mutex_unlock(&queue_mutex_);
}
@@ -191,19 +162,19 @@ void *packet_dequeuer(void *p)
}
#endif
ts.tv_sec += DEQUEUER_WAKEUP;
- log_msg(L_DEBUG, "timed conditional wait...");
+ log_debug("timed conditional wait...");
rc = pthread_cond_timedwait(&queue_cond_, &queue_mutex_, &ts);
}
else
{
- log_msg(L_DEBUG, "conditional wait...");
+ log_debug("conditional wait...");
rc = pthread_cond_wait(&queue_cond_, &queue_mutex_);
}
if (rc)
log_msg(L_FATAL, "woke up: \"%s\"", strerror(rc));
- log_msg(L_DEBUG, "starting dequeuing");
+ log_debug("starting dequeuing");
for (queue = &queue_; *queue; /*queue = &(*queue)->next*/)
{
rc = forward_packet(&(*queue)->addr, (*queue)->data, (*queue)->psize);
@@ -215,7 +186,7 @@ void *packet_dequeuer(void *p)
fqueue = *queue;
*queue = (*queue)->next;
free(fqueue);
- log_msg(L_DEBUG, "packet dequeued, delay = %d", delay);
+ log_debug("packet dequeued, delay = %d", delay);
continue;
}
queue = &(*queue)->next;
@@ -251,7 +222,7 @@ int validate_frame(const struct ip6_hdr *ihd, int len)
if ((ihd->ip6_vfc & 0xf0) != 0x60)
{
hex_code_header((char*) ihd, len > IP6HLEN ? IP6HLEN : len, hexbuf);
- log_msg(L_DEBUG, "header \"%s\"", hexbuf);
+ log_debug("header \"%s\"", hexbuf);
return 0;
}
@@ -268,7 +239,7 @@ int validate_frame(const struct ip6_hdr *ihd, int len)
#ifdef TEST_TUN_HDR
if (is_testping(&ihd->ip6_dst))
{
- log_msg(L_DEBUG, "test ping detected");
+ log_debug("test ping detected");
return 0;
}
#endif
@@ -278,7 +249,7 @@ int validate_frame(const struct ip6_hdr *ihd, int len)
void cleanup_socket(int fd, OcatPeer_t *peer)
{
- log_msg(L_NOTICE, "fd %d reached EOF, closing.", fd);
+ log_msg(L_NOTICE | L_FCONN, "fd %d reached EOF, closing.", fd);
close(fd);
lock_peers();
delete_peer(peer);
@@ -306,7 +277,7 @@ int handle_http(const OcatPeer_t *peer)
snprintf(response, BSTRLEN,
"HTTP/1.0 301 HTTP not possible\r\nLocation: %s\r\nDate: %s\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n"
"<html><body><h1>HTTP not possible!<br>OnionCat is running on this port at \"%s.onion\"</h1></body></html>\r\n",
- OCAT_URL, timestr, onion_url_
+ OCAT_URL, timestr, setup.onion_url
);
log_msg(L_INFO, "request seems to be HTTP");
if (send(peer->tcpfd, response, strlen(response), MSG_DONTWAIT) == -1)
@@ -356,7 +327,7 @@ void *socket_receiver(void *p)
}
unlock_peers();
- log_msg(L_DEBUG, "selecting...");
+ log_debug("selecting...");
if ((maxfd = select(maxfd + 1, &rset, NULL, NULL, NULL)) == -1)
{
log_msg(L_FATAL, "select encountered error: \"%s\", restarting", strerror(errno));
@@ -400,21 +371,21 @@ void *socket_receiver(void *p)
}
maxfd--;
- log_msg(L_DEBUG, "reading from %d", peer->tcpfd);
+ log_debug("reading from %d", peer->tcpfd);
// read/append data to peer's fragment buffer
if ((len = read(peer->tcpfd, peer->fragbuf + peer->fraglen, FRAME_SIZE - 4 - peer->fraglen)) == -1)
{
// this might happen on linux, see SELECT(2)
- log_msg(L_DEBUG, "spurious wakup of %d: \"%s\"", peer->tcpfd, strerror(errno));
+ log_debug("spurious wakup of %d: \"%s\"", peer->tcpfd, strerror(errno));
unlock_peer(peer);
continue;
}
- log_msg(L_DEBUG, "received %d bytes on %d", len, peer->tcpfd);
+ log_debug("received %d bytes on %d", len, peer->tcpfd);
// if len == 0 EOF reached => close session
if (!len)
{
- log_msg(L_NOTICE, "fd %d reached EOF, closing.", peer->tcpfd);
+ log_msg(L_NOTICE | L_FCONN, "fd %d reached EOF, closing.", peer->tcpfd);
close(peer->tcpfd);
unlock_peer(peer);
lock_peers();
@@ -438,7 +409,7 @@ void *socket_receiver(void *p)
#ifdef HANDLE_HTTP
if (handle_http(peer))
{
- log_msg(L_NOTICE, "closing %d due to HTTP.", peer->tcpfd);
+ log_msg(L_NOTICE | L_FCONN, "closing %d due to HTTP.", peer->tcpfd);
close(peer->tcpfd);
unlock_peer(peer);
lock_peers();
@@ -446,12 +417,12 @@ void *socket_receiver(void *p)
unlock_peers();
}
#endif
- log_msg(L_DEBUG, "FRAGBUF RESET!");
+ log_debug("FRAGBUF RESET!");
peer->fraglen = 0;
break;
}
- if (vrec_ && !plen)
+ if (setup.vrec && !plen)
{
log_msg(L_ERROR, "dropping frame");
break;
@@ -460,7 +431,7 @@ void *socket_receiver(void *p)
len = plen + IP6HLEN;
if (peer->fraglen < len)
{
- log_msg(L_DEBUG, "keeping %d bytes frag", peer->fraglen);
+ log_debug("keeping %d bytes frag", peer->fraglen);
break;
}
@@ -468,23 +439,23 @@ void *socket_receiver(void *p)
if (plen && !memcmp(&peer->addr, &in6addr_any, sizeof(struct in6_addr)))
{
memcpy(&peer->addr, &((struct ip6_hdr*)peer->fragbuf)->ip6_src, sizeof(struct in6_addr));
- log_msg(L_NOTICE, "incoming connection on %d from %s is now identified", peer->tcpfd,
+ log_msg(L_NOTICE | L_FCONN, "incoming connection on %d from %s is now identified", peer->tcpfd,
inet_ntop(AF_INET6, &peer->addr, addr, INET6_ADDRSTRLEN));
}
- log_msg(L_DEBUG, "writing to tun %d framesize %d + 4", tunfd_[1], len);
- if (write(tunfd_[1], &peer->fraghdr, len + 4) != (len + 4))
- log_msg(L_ERROR, "could not write %d bytes to tunnel %d", len + 4, tunfd_[1]);
+ log_debug("writing to tun %d framesize %d + 4", setup.tunfd[1], len);
+ if (write(setup.tunfd[1], &peer->fraghdr, len + 4) != (len + 4))
+ log_msg(L_ERROR, "could not write %d bytes to tunnel %d", len + 4, setup.tunfd[1]);
peer->fraglen -= len;
if (peer->fraglen)
{
- log_msg(L_DEBUG, "moving fragment. fragsize %d", peer->fraglen);
+ log_debug("moving fragment. fragsize %d", peer->fraglen);
memmove(peer->fragbuf, peer->fragbuf + len, FRAME_SIZE - 4 - len);
}
else
- log_msg(L_DEBUG, "fragbuf empty");
+ log_debug("fragbuf empty");
} // while (peer->fraglen >= IP6HLEN)
unlock_peer(peer);
} // while (maxfd)
@@ -496,23 +467,12 @@ void set_nonblock(int fd)
{
long flags;
-#ifdef SNDBUF
- if (!snd_buf_size_)
- {
- flags = sizeof(snd_buf_size_);
- if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &snd_buf_size_, (socklen_t*) &flags) == -1)
- log_msg(L_FATAL, "could not get TCP send buffer size: \"%s\"", strerror(errno));
- else
- log_msg(L_DEBUG, "SO_SNDBF = %d", snd_buf_size_);
- }
-#endif
-
if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
{
log_msg(L_ERROR, "could not get socket flags for %d: \"%s\"", fd, strerror(errno));
flags = 0;
}
- log_msg(L_DEBUG, "O_NONBLOCK currently is %x", flags & O_NONBLOCK);
+ log_debug("O_NONBLOCK currently is %x", flags & O_NONBLOCK);
if ((fcntl(fd, F_SETFL, flags | O_NONBLOCK)) == -1)
log_msg(L_ERROR, "could not set O_NONBLOCK for %d: \"%s\"", fd, strerror(errno));
@@ -523,7 +483,7 @@ int insert_peer(int fd, const struct in6_addr *addr, time_t dly)
{
OcatPeer_t *peer;
- log_msg(L_DEBUG, "inserting peer fd %d", fd);
+ log_msg(L_INFO | L_FCONN, "inserting peer fd %d", fd);
set_nonblock(fd);
@@ -551,7 +511,7 @@ int insert_peer(int fd, const struct in6_addr *addr, time_t dly)
unlock_peer(peer);
// wake up socket_receiver
- log_msg(L_DEBUG, "waking up socket_receiver");
+ log_debug("waking up socket_receiver");
if (write(lpfd_[1], &fd, 1) != 1)
log_msg(L_FATAL, "couldn't write to socket_receiver pipe: \"%s\"", strerror(errno));
@@ -620,6 +580,8 @@ int run_local_listeners(short port, int *sockfd, int (action_accept)(int))
struct sockaddr_in6 in6;
fd_set rset;
int maxfd, i;
+ socklen_t alen;
+ char iabuf[INET6_ADDRSTRLEN];
memset(&in, 0, sizeof(in));
memset(&in6, 0, sizeof(in6));
@@ -637,45 +599,50 @@ int run_local_listeners(short port, int *sockfd, int (action_accept)(int))
in6.sin6_len = sizeof(in6);
#endif
- log_msg(L_DEBUG, "creating IPv4 listener");
+ log_debug("creating IPv4 listener");
if ((sockfd[0] = create_listener((struct sockaddr*) &in, sizeof(in))) == -1)
log_msg(L_FATAL, "exiting"), exit(1);
- log_msg(L_DEBUG, "creating IPv6 listener");
+ log_debug("creating IPv6 listener");
if ((sockfd[1] = create_listener((struct sockaddr*) &in6, sizeof(in6))) == -1)
log_msg(L_FATAL, "exiting"), exit(1);
for (;;)
{
- log_msg(L_DEBUG, "setting up fd_set");
+ log_debug("setting up fd_set");
FD_ZERO(&rset);
FD_SET(sockfd[0], &rset);
FD_SET(sockfd[1], &rset);
maxfd = sockfd[0] > sockfd[1] ? sockfd[0] : sockfd[1];
- log_msg(L_DEBUG, "selecting locally (maxfd = %d)", maxfd);
+ log_debug("selecting locally (maxfd = %d)", maxfd);
if ((maxfd = select(maxfd + 1, &rset, NULL, NULL, NULL)) == -1)
{
- log_msg(L_DEBUG, "select returned: \"%s\"", strerror(errno));
+ log_debug("select returned: \"%s\"", strerror(errno));
continue;
}
- log_msg(L_DEBUG, "select returned %d fds ready", maxfd);
+ log_debug("select returned %d fds ready", maxfd);
for (i = 0; maxfd && (i < 2); i++)
{
- log_msg(L_DEBUG, "checking fd %d (maxfd = %d, i = %d)", sockfd[i], maxfd, i);
+ log_debug("checking fd %d (maxfd = %d, i = %d)", sockfd[i], maxfd, i);
if (!FD_ISSET(sockfd[i], &rset))
continue;
maxfd--;
- log_msg(L_DEBUG, "accepting connection on %d", sockfd[i]);
- if ((fd = accept(sockfd[i], NULL, NULL)) < 0)
+ alen = sizeof(in6);
+ log_debug("accepting connection on %d", sockfd[i]);
+ if ((fd = accept(sockfd[i], (struct sockaddr*) &in6, &alen)) < 0)
{
log_msg(L_ERROR, "error accepting connection on %d: \"%s\"", sockfd[i], strerror(errno));
// FIXME: there should be additional error handling!
continue;
}
- log_msg(L_NOTICE, "connection %d accepted on listener %d", fd, sockfd[i]);
+ inet_ntop(in6.sin6_family,
+ in6.sin6_family == AF_INET6 ? &in6.sin6_addr :
+ (void*) &((struct sockaddr_in*) &in6)->sin_addr,
+ iabuf, INET6_ADDRSTRLEN);
+ log_msg(L_NOTICE | L_FCONN, "connection %d accepted on listener %d from %s port %d", fd, sockfd[i], iabuf, ntohs(in6.sin6_port));
(void) action_accept(fd);
}
}
@@ -685,7 +652,7 @@ int run_local_listeners(short port, int *sockfd, int (action_accept)(int))
void *socket_acceptor(void *p)
{
- run_local_listeners(ocat_listen_port_, sockfd_, insert_anon_peer);
+ run_local_listeners(setup.ocat_listen_port, sockfd_, insert_anon_peer);
return NULL;
}
@@ -697,11 +664,11 @@ int socks_connect(const struct in6_addr *addr)
char buf[FRAME_SIZE], onion[ONION_NAME_SIZE];
SocksHdr_t *shdr = (SocksHdr_t*) buf;
- log_msg(L_DEBUG, "called");
+ log_debug("called");
memset(&in, 0, sizeof(in));
in.sin_family = AF_INET;
- in.sin_port = htons(tor_socks_port_);
+ in.sin_port = htons(setup.tor_socks_port);
in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
#ifdef HAVE_SIN_LEN
in.sin_len = sizeof(in);
@@ -723,31 +690,31 @@ int socks_connect(const struct in6_addr *addr)
return E_SOCKS_CONN;
}
- log_msg(L_DEBUG, "connected to TOR, doing SOCKS handshake");
+ log_debug("connected to TOR, doing SOCKS handshake");
shdr->ver = 4;
shdr->cmd = 1;
- shdr->port = htons(ocat_dest_port_);
+ shdr->port = htons(setup.ocat_dest_port);
shdr->addr.s_addr = htonl(0x00000001);
/*
strlcpy(buf + sizeof(SocksHdr_t), usrname_, strlen(usrname_) + 1);
strlcpy(buf + sizeof(SocksHdr_t) + strlen(usrname_) + 1, onion, sizeof(onion));
*/
- memcpy(buf + sizeof(SocksHdr_t), usrname_, strlen(usrname_) + 1);
- memcpy(buf + sizeof(SocksHdr_t) + strlen(usrname_) + 1, onion, strlen(onion) + 1);
- len = sizeof(SocksHdr_t) + strlen(usrname_) + strlen(onion) + 2;
+ memcpy(buf + sizeof(SocksHdr_t), setup.usrname, strlen(setup.usrname) + 1);
+ memcpy(buf + sizeof(SocksHdr_t) + strlen(setup.usrname) + 1, onion, strlen(onion) + 1);
+ len = sizeof(SocksHdr_t) + strlen(setup.usrname) + strlen(onion) + 2;
if (write(fd, shdr, len) != len)
// FIXME: there should be some additional error handling
log_msg(L_ERROR, "couldn't write %d bytes to SOCKS connection %d", len, fd);
- log_msg(L_DEBUG, "connect request sent");
+ log_debug("connect request sent");
if (read(fd, shdr, sizeof(SocksHdr_t)) < sizeof(SocksHdr_t))
{
- log_msg(L_ERROR, "short read, closing.");
+ log_msg(L_ERROR | L_FCONN, "short read, closing.");
close(fd);
return E_SOCKS_REQ;
}
- log_msg(L_DEBUG, "SOCKS response received");
+ log_debug("SOCKS response received");
if (shdr->ver || (shdr->cmd != 90))
{
@@ -755,7 +722,7 @@ int socks_connect(const struct in6_addr *addr)
close(fd);
return E_SOCKS_RQFAIL;
}
- log_msg(L_NOTICE, "connection to %s successfully opened on fd %d", onion, fd);
+ log_msg(L_NOTICE | L_FCONN, "connection to %s successfully opened on fd %d", onion, fd);
insert_peer(fd, addr, time(NULL) - t);
@@ -773,17 +740,17 @@ void socks_queue(const struct in6_addr *addr)
break;
if (!squeue)
{
- log_msg(L_DEBUG, "queueing new SOCKS connection request");
+ log_debug("queueing new SOCKS connection request");
if (!(squeue = calloc(1, sizeof(SocksQueue_t))))
log_msg(L_FATAL, "could not get memory for SocksQueue entry: \"%s\"", strerror(errno)), exit(1);
memcpy(&squeue->addr, addr, sizeof(struct in6_addr));
squeue->next = socks_queue_;
socks_queue_ = squeue;
- log_msg(L_DEBUG, "signalling connector");
+ log_debug("signalling connector");
pthread_cond_signal(&socks_queue_cond_);
}
else
- log_msg(L_DEBUG, "connection already exists, not queueing SOCKS connection");
+ log_debug("connection already exists, not queueing SOCKS connection");
pthread_mutex_unlock(&socks_queue_mutex_);
}
@@ -863,20 +830,20 @@ void packet_forwarder(void)
for (;;)
{
- if ((rlen = read(tunfd_[0], buf, FRAME_SIZE)) == -1)
+ if ((rlen = read(setup.tunfd[0], buf, FRAME_SIZE)) == -1)
{
rlen = errno;
- log_msg(L_DEBUG, "read from tun %d returned on error: \"%s\"", strerror(rlen));
+ log_debug("read from tun %d returned on error: \"%s\"", setup.tunfd[0], strerror(rlen));
if (rlen == EINTR)
{
- log_msg(L_DEBUG, "signal caught, exiting");
+ log_debug("signal caught, exiting");
return;
}
- log_msg(L_DEBUG, "restart reading");
+ log_debug("restart reading");
continue;
}
- log_msg(L_DEBUG, "received on tunfd %d, framesize %d + 4", tunfd_[0], rlen - 4);
+ log_debug("received on tunfd %d, framesize %d + 4", setup.tunfd[0], rlen - 4);
if (!validate_frame(ihd, rlen - 4))
{
@@ -889,7 +856,7 @@ void packet_forwarder(void)
{
log_msg(L_NOTICE, "establishing new socks peer");
socks_queue(&ihd->ip6_dst);
- log_msg(L_DEBUG, "queuing packet");
+ log_debug("queuing packet");
queue_packet(&ihd->ip6_dst, buf + 4, rlen - 4);
}
}
@@ -903,7 +870,7 @@ void *socket_cleaner(void *ptr)
for (;;)
{
sleep(CLEANER_WAKEUP);
- log_msg(L_DEBUG, "wakeup");
+ log_debug("wakeup");
lock_peers();
for (p = get_first_peer_ptr(); *p; p = &(*p)->next)
{
@@ -912,13 +879,13 @@ void *socket_cleaner(void *ptr)
{
peer = *p;
*p = peer->next;
- log_msg(L_NOTICE, "peer %d timed out, closing.", peer->tcpfd);
+ log_msg(L_NOTICE | L_FCONN, "peer %d timed out, closing.", peer->tcpfd);
close(peer->tcpfd);
unlock_peer(peer);
delete_peer(peer);
if (!(*p))
{
- log_msg(L_DEBUG, "last peer in list deleted, breaking loop");
+ log_debug("last peer in list deleted, breaking loop");
break;
}
}
@@ -959,7 +926,7 @@ void *ctrl_handler(void *p)
if ((rlen = pthread_detach(pthread_self())))
log_msg(L_ERROR, "thread couldn't self-detach: \"%s\"", strerror(rlen));
- log_msg(L_DEBUG, "thread detached");
+ log_debug("thread detached");
fd = (int) p;
if (!(ff = fdopen(fd, "r+")))
@@ -967,7 +934,7 @@ void *ctrl_handler(void *p)
log_msg(L_ERROR, "could not open %d for writing", fd);
return NULL;
}
- log_msg(L_DEBUG, "fd %d fdopen'ed", fd);
+ log_debug("fd %d fdopen'ed", fd);
for (;;)
{
@@ -1012,7 +979,7 @@ void *ctrl_handler(void *p)
for (peer = get_first_peer(); peer; peer = peer->next)
if (peer->tcpfd == cfd)
{
- log_msg(L_NOTICE, "close request for %d", cfd);
+ log_msg(L_NOTICE | L_FCONN, "close request for %d", cfd);
close(cfd);
delete_peer(peer);
break;
@@ -1051,7 +1018,7 @@ void *ctrl_handler(void *p)
}
}
- log_msg(L_NOTICE, "closing session %d", fd);
+ log_msg(L_NOTICE | L_FCONN, "closing session %d", fd);
if (fclose(ff) == EOF)
log_msg(L_ERROR, "error closing control stream: \"%s\"", strerror(errno));
// fclose also closes the fd according to the man page
@@ -1068,7 +1035,7 @@ int run_ctrl_handler(int fd)
void *ocat_controller(void *p)
{
- run_local_listeners(ocat_ctrl_port_, ctrlfd_, run_ctrl_handler);
+ run_local_listeners(setup.ocat_ctrl_port, ctrlfd_, run_ctrl_handler);
return NULL;
}
diff --git a/src/ocatthread.c b/src/ocatthread.c
index 8533f30..c4b7b67 100644
--- a/src/ocatthread.c
+++ b/src/ocatthread.c
@@ -116,7 +116,7 @@ int run_ocat_thread(const char *name, void *(*thfunc)(void*), void *parm)
th->entry = thfunc;
th->parm = parm;
- log_msg(L_DEBUG, "starting [%s]", name);
+ log_debug("starting [%s]", name);
if ((rc = pthread_create(&th->handle, NULL, thread_run, th)))
{
log_msg(L_FATAL, "could not start thread %s: \"%s\"", name, strerror(rc));
diff --git a/src/ocattun.c b/src/ocattun.c
index ea9d333..a3c63b2 100644
--- a/src/ocattun.c
+++ b/src/ocattun.c
@@ -60,7 +60,7 @@ int tun_alloc(char *dev, struct in6_addr addr)
char astr[INET6_ADDRSTRLEN];
char buf[FRAME_SIZE];
- log_msg(L_DEBUG, "opening tun \"%s\"", tun_dev_);
+ log_debug("opening tun \"%s\"", tun_dev_);
if( (fd = open(tun_dev_, O_RDWR)) < 0 )
perror("open tun"), exit(1);
inet_ntop(AF_INET6, &addr, astr, INET6_ADDRSTRLEN);
@@ -81,12 +81,13 @@ int tun_alloc(char *dev, struct in6_addr addr)
if (system(buf) == -1)
log_msg(L_ERROR, "could not exec \"%s\": \"%s\"", buf, strerror(errno));
// set tun frame header to ethertype IPv6
- fhd_key_ = htonl(0x86dd);
+ setup.fhd_key = htonl(0x86dd);
+ //setup.fhd_key = htonl(ETH_P_IPV6);
#else
// set tun frame header to address family AF_INET6 (FreeBSD = 0x1c, OpenBSD = 0x18)
- fhd_key_ = htonl(AF_INET6);
+ setup.fhd_key = htonl(AF_INET6);
#ifdef __FreeBSD__
@@ -100,7 +101,7 @@ int tun_alloc(char *dev, struct in6_addr addr)
#endif
sprintf(buf, "ifconfig tun0 inet6 %s/%d up", astr, TOR_PREFIX_LEN);
- log_msg(L_DEBUG, "setting IP on tun: \"%s\"", buf);
+ log_debug("setting IP on tun: \"%s\"", buf);
if (system(buf) == -1)
log_msg(L_ERROR, "could not exec \"%s\": \"%s\"", buf, strerror(errno));
@@ -138,7 +139,7 @@ void test_tun_hdr(void)
if (system(buf) == -1)
log_msg(L_FATAL, "[test_tun_hdr] test failed: \"%s\"", strerror(errno));
rlen = read(tunfd_[0], buf, FRAME_SIZE);
- log_msg(L_DEBUG, "[test_tun_hdr] read %d bytes from %d, head = 0x%08x", rlen, tunfd_[0], ntohl(*((uint32_t*)buf)));
+ log_debug("[test_tun_hdr] read %d bytes from %d, head = 0x%08x", rlen, tunfd_[0], ntohl(*((uint32_t*)buf)));
if ((buf[0] & 0xf0) == 0x60)
{
@@ -146,8 +147,8 @@ void test_tun_hdr(void)
return;
}
- fhd_key_ = *((uint32_t*)buf);
- log_msg(L_NOTICE, "[test_tun_hdr] using 0x%08x as local frame header", ntohl(fhd_key_));
+ setup.fhd_key = *((uint32_t*)buf);
+ log_msg(L_NOTICE, "[test_tun_hdr] using 0x%08x as local frame header", ntohl(setup.fhd_key));
}
#endif
--
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