[Pkg-privacy-commits] [onioncat] 76/241: replaced setup by CNF() and setup_

Intrigeri intrigeri at moszumanska.debian.org
Wed Aug 26 16:16:32 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 2f702acd2152d7be89179e1c973dbebe9018b5a4
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date:   Thu Nov 27 11:31:46 2008 +0000

    replaced setup by CNF() and setup_
    
    git-svn-id: https://www.cypherpunk.at/svn/onioncat/trunk@365 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
 src/ocat.c          | 129 ++++++++++++++--------------
 src/ocat.h          |  19 ++++-
 src/ocateth.c       |   8 +-
 src/ocatipv4route.c |   2 +-
 src/ocatlog.c       |   6 +-
 src/ocatpeer.c      |   2 +-
 src/ocatroute.c     | 241 ++++++++--------------------------------------------
 src/ocatsetup.c     | 134 ++++++++++++++++-------------
 src/ocatsocks.c     |  10 +--
 src/ocattun.c       |  22 ++---
 10 files changed, 216 insertions(+), 357 deletions(-)

diff --git a/src/ocat.c b/src/ocat.c
index ee3a360..83fc762 100644
--- a/src/ocat.c
+++ b/src/ocat.c
@@ -65,31 +65,31 @@ void usage(const char *s)
          "   -4                    enable IPv4 support (default = %d)\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.pid_file,
-         setup.ocat_dest_port, setup.tor_socks_port, 
+         OCAT_DIR, OCAT_CONNECT_LOG, CNF(create_clog), CNF(debug_level), CNF(ocat_listen_port),
+         CNF(pid_file),
+         CNF(ocat_dest_port), CNF(tor_socks_port), 
 #ifndef WITHOUT_TUN
          TUN_DEV,
 #endif
-         OCAT_UNAME, setup.ipv4_enable
+         OCAT_UNAME, CNF(ipv4_enable)
             );
 }
 
 
 void open_logfile(void)
 {
-   if (setup.logfn)
+   if (CNF(logfn))
    {
-      if ((setup.logf = fopen(setup.logfn, "a")))
+      if ((CNF(logf) = fopen(CNF(logfn), "a")))
       {
-         log_debug("logfile %s opened", setup.logfn);
-         if (setvbuf(setup.logf, NULL, _IOLBF, 0))
+         log_debug("logfile %s opened", CNF(logfn));
+         if (setvbuf(CNF(logf), NULL, _IOLBF, 0))
             log_msg(L_ERROR, "could not setup line buffering: %s", strerror(errno));
-         fflush(setup.logf);
+         fflush(CNF(logf));
          return;
       }
-      setup.logf = stderr;
-      log_msg(L_ERROR, "could not open logfile %s: %s. Defaulting to stderr", setup.logfn, strerror(errno));
+      CNF(logf) = stderr;
+      log_msg(L_ERROR, "could not open logfile %s: %s. Defaulting to stderr", CNF(logfn), strerror(errno));
    }
 }
 
@@ -98,15 +98,15 @@ int mk_pid_file(void)
 {
    FILE *f;
 
-   if (!(f = fopen(setup.pid_file, "w")))
+   if (!(f = fopen(CNF(pid_file), "w")))
    {
-      log_msg(L_ERROR, "could not create pid_file %s: %s", setup.pid_file, strerror(errno));
+      log_msg(L_ERROR, "could not create pid_file %s: %s", CNF(pid_file), strerror(errno));
       return -1;
    }
 
    fprintf(f, "%d\n", getpid());
    fclose(f);
-   log_debug("pid_file %s created, pid = %d", setup.pid_file, getpid());
+   log_debug("pid_file %s created, pid = %d", CNF(pid_file), getpid());
 
    return 0;
 }
@@ -148,24 +148,24 @@ int main(int argc, char *argv[])
       switch (c)
       {
          case 'a':
-            setup.create_clog = 1;
+            CNF(create_clog) = 1;
             break;
 
          case 'b':
-            setup.daemon = 1;
+            CNF(daemon) = 1;
             break;
 
          case 'C':
-            setup.controller = 0;
+            CNF(controller) = 0;
             break;
 
          case 'd':
-            setup.debug_level = atoi(optarg);
+            CNF(debug_level) = atoi(optarg);
             break;
 
          case 'f':
-            setup.config_file = optarg;
-            setup.config_read = 0;
+            CNF(config_file) = optarg;
+            CNF(config_read) = 0;
             break;
 
          case 'i':
@@ -173,11 +173,11 @@ int main(int argc, char *argv[])
             break;
 
          case 'l':
-            setup.ocat_listen_port = atoi(optarg);
+            CNF(ocat_listen_port) = atoi(optarg);
             break;
 
          case 'L':
-            setup.logfn = optarg;
+            CNF(logfn) = optarg;
             break;
 
          case 'o':
@@ -185,24 +185,24 @@ int main(int argc, char *argv[])
             break;
 
          case 'p':
-            setup.use_tap = 1;
+            CNF(use_tap) = 1;
             break;
 
          case 'P':
-            setup.pid_file = optarg;
+            CNF(pid_file) = optarg;
             break;
 
          case 'r':
             runasroot = 1;
-            setup.usrname = "root";
+            CNF(usrname) = "root";
             break;
 
          case 's':
-            setup.ocat_dest_port = atoi(optarg);
+            CNF(ocat_dest_port) = atoi(optarg);
             break;
 
          case 't':
-            setup.tor_socks_port = atoi(optarg);
+            CNF(tor_socks_port) = atoi(optarg);
             break;
 
 #ifndef WITHOUT_TUN
@@ -212,11 +212,11 @@ int main(int argc, char *argv[])
 #endif
 
          case 'u':
-            setup.usrname = optarg;
+            CNF(usrname) = optarg;
             break;
 
          case '4':
-            setup.ipv4_enable = 1;
+            CNF(ipv4_enable) = 1;
             break;
 
          case 'h':
@@ -233,74 +233,74 @@ int main(int argc, char *argv[])
 
    if (urlconv == 2)
    {
-      if ((c = inet_pton(AF_INET6, argv[optind], &setup.ocat_addr)) < 0)
+      if ((c = inet_pton(AF_INET6, argv[optind], &CNF(ocat_addr))) < 0)
          log_msg(L_ERROR, "inet_pton failed: %s", strerror(errno)), exit(1);
       else if (!c)
          log_msg(L_ERROR, "%s is not a valid IPv6 address", argv[optind]), exit(1);
-      if (!has_tor_prefix(&setup.ocat_addr))
+      if (!has_tor_prefix(&CNF(ocat_addr)))
          log_msg(L_ERROR, "address does not have TOR prefix"), exit(1);
-      ipv6tonion(&setup.ocat_addr, setup.onion_url);
-      printf("%s.onion\n", setup.onion_url);
+      ipv6tonion(&CNF(ocat_addr), CNF(onion_url));
+      printf("%s.onion\n", CNF(onion_url));
       exit(0);
    }
 
    // convert parameter to IPv6 address
-   strncpy(setup.onion_url, argv[optind], ONION_NAME_SIZE);
-   if ((s = strchr(setup.onion_url, '.')))
+   strncpy(CNF(onion_url), argv[optind], ONION_NAME_SIZE);
+   if ((s = strchr(CNF(onion_url), '.')))
          *s = '\0';
-   if (strlen(setup.onion_url) != 16)
+   if (strlen(CNF(onion_url)) != 16)
       log_msg(L_ERROR, "parameter seems not to be valid onion hostname"), exit(1);
-   if (oniontipv6(setup.onion_url, &setup.ocat_addr) == -1)
+   if (oniontipv6(CNF(onion_url), &CNF(ocat_addr)) == -1)
       log_msg(L_ERROR, "parameter seems not to be valid onion hostname"), exit(1);
-   if (setup.ipv4_enable)
-      oniontipv4(setup.onion_url, &setup.ocat_addr4, ntohl(setup.ocat_addr4_mask));
+   if (CNF(ipv4_enable))
+      oniontipv4(CNF(onion_url), &CNF(ocat_addr4), ntohl(CNF(ocat_addr4_mask)));
 
-   inet_ntop(AF_INET6, &setup.ocat_addr, ip6addr, INET6_ADDRSTRLEN);
+   inet_ntop(AF_INET6, &CNF(ocat_addr), ip6addr, INET6_ADDRSTRLEN);
 
    if (urlconv == 1)
    {
       printf("%s\n", ip6addr);
-      if (setup.ipv4_enable)
-         printf("%s\n", inet_ntoa(setup.ocat_addr4));
+      if (CNF(ipv4_enable))
+         printf("%s\n", inet_ntoa(CNF(ocat_addr4)));
       exit(0);
    }
 
    log_msg(L_NOTICE, "%s (c) Bernhard R. Fischer -- compiled %s %s", PACKAGE_STRING, __DATE__, __TIME__);
 
 #if 0
-   if (setup.config_file)
+   if (CNF(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_NOTICE, "reading config file %s", CNF(config_file));
+      if ((c = open(CNF(config_file), O_RDONLY)) == -1)
          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);
+   memcpy(&CNF(ocat_hwaddr[3]), &CNF(ocat_addr.s6_addr[13]), 3);
+   if (CNF(use_tap));
    {
       log_msg(L_NOTICE, "MAC address %02x:%02x:%02x:%02x:%02x:%02x",
-            setup.ocat_hwaddr[0], setup.ocat_hwaddr[1], setup.ocat_hwaddr[2], setup.ocat_hwaddr[3], setup.ocat_hwaddr[4], setup.ocat_hwaddr[5]);
-      /*if (pipe(setup.icmpv6fd) == -1)
+            CNF(ocat_hwaddr[0]), CNF(ocat_hwaddr[1]), CNF(ocat_hwaddr[2]), CNF(ocat_hwaddr[3]), CNF(ocat_hwaddr[4]), CNF(ocat_hwaddr[5]));
+      /*if (pipe(CNF(icmpv6fd)) == -1)
          log_msg(L_FATAL, "cannot create multicast pipe: %s", strerror(errno)), exit(1);
       run_ocat_thread("icmpv6", icmpv6_handler, NULL);*/
    }
 
 #ifndef WITHOUT_TUN
    // create TUN device
-   setup.tunfd[0] = setup.tunfd[1] = tun_alloc(tunname, setup.ocat_addr);
+   CNF(tunfd[0]) = CNF(tunfd[1]) = tun_alloc(tunname, CNF(ocat_addr));
 #endif
 
    log_msg(L_NOTICE, "IPv6 address %s", ip6addr);
    log_msg(L_NOTICE, "TUN/TAP device %s", tunname);
-   if (setup.ipv4_enable)
-      log_msg(L_NOTICE, "IP address %s", inet_ntoa(setup.ocat_addr4));
+   if (CNF(ipv4_enable))
+      log_msg(L_NOTICE, "IP address %s", inet_ntoa(CNF(ocat_addr4)));
  
-   log_debug("tun frameheader v6 = 0x%08x, v4 = 0x%08x", ntohl(setup.fhd_key[IPV6_KEY]), ntohl(setup.fhd_key[IPV4_KEY]));
+   log_debug("tun frameheader v6 = 0x%08x, v4 = 0x%08x", ntohl(CNF(fhd_key[IPV6_KEY])), ntohl(CNF(fhd_key[IPV4_KEY])));
 
    // daemonize of required
-   if (setup.daemon)
+   if (CNF(daemon))
       background();
 
    // start socket receiver thread
@@ -312,15 +312,15 @@ int main(int argc, char *argv[])
 
    // 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 (!(pwd = getpwnam(CNF(usrname))))
+      log_msg(L_FATAL, "can't get information for user \"%s\": \"%s\"", CNF(usrname), errno ? strerror(errno) : "user not found"), exit(1);
 
    // create pid_file
    mk_pid_file();
 
    if (!runasroot && !getuid())
    {
-      log_msg(L_NOTICE, "running as root, changing uid/gid to %s (uid %d/gid %d)", setup.usrname, pwd->pw_uid, pwd->pw_gid);
+      log_msg(L_NOTICE, "running as root, changing uid/gid to %s (uid %d/gid %d)", CNF(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))
@@ -331,7 +331,7 @@ int main(int argc, char *argv[])
    // opening logfile
    open_logfile();
 
-   if (setup.create_clog)
+   if (CNF(create_clog))
       open_connect_log(pwd->pw_dir);
 
    // create socks connector thread
@@ -341,14 +341,19 @@ int main(int argc, char *argv[])
    run_ocat_thread("dequeuer", packet_dequeuer, NULL);
 #endif
    // start controller socket thread
-   if (setup.controller)
+   if (CNF(controller))
       run_ocat_thread("controller", ocat_controller, NULL);
 
+   // 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);
+
    // reading config file
-   if (setup.config_file)
+   if (CNF(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_NOTICE, "reading config file %s", CNF(config_file));
+      if ((c = open(CNF(config_file), O_RDONLY)) == -1)
          log_msg(L_ERROR, "error opening file: %s", strerror(errno)), exit(1);
       ctrl_handler((void*) c);
    }
diff --git a/src/ocat.h b/src/ocat.h
index 8ab2772..f1facd1 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -38,6 +38,7 @@
 #include <sys/endian.h>
 #endif
 #include <net/ethernet.h>
+#include <syslog.h>
 
 #ifndef ETHERTYPE_IPV6
 #define ETHERTYPE_IPV6 0x86dd
@@ -54,6 +55,8 @@
 #define TOR_PREFIX4 {0x0a000000}
 #define TOR_PREFIX4_MASK 0xff000000
 #endif
+//! Len of an .onion-URL (without ".onion" and '\0')
+#define ONION_URL_LEN 16
 #define MAXPEERS 1024
 //! Local listening port for incoming connections from TOR.
 #define OCAT_LISTEN_PORT 8060
@@ -87,6 +90,7 @@
 //! 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
 #define L_FLAG_MASK 0xff00
@@ -96,6 +100,9 @@
 #define L_FATAL 3
 #define L_DEBUG 4
 #define L_FCONN (1 << 15)
+*/
+
+#define LOG_FCONN 0x80
 
 #define E_SOCKS_SOCK -1
 #define E_SOCKS_CONN -2
@@ -132,6 +139,8 @@
 #define IPV4_KEY 0
 #define IPV6_KEY 1
 
+
+
 struct OcatSetup
 {
    //! frame header of local OS in network byte order
@@ -166,11 +175,15 @@ struct OcatSetup
    char *config_file;
    int config_read;
    int use_tap;
+   //! local OnionCat MAC address
    uint8_t ocat_hwaddr[ETH_ALEN];
    char *pid_file;
    char *logfn;
    FILE *logf;
    int daemon;
+   //! hardcoded permanent peers
+#define ROOT_PEERS 1
+   struct in6_addr root_peer[ROOT_PEERS];
 };
 
 #ifdef PACKET_QUEUE
@@ -327,7 +340,7 @@ extern OcatThread_t *octh_;
 int open_connect_log(const char*);
 void log_msg(int, const char *, ...);
 #ifdef DEBUG
-#define log_debug(x...) log_msg(L_DEBUG, ## x)
+#define log_debug(x...) log_msg(LOG_DEBUG, ## x)
 #else
 #define log_debug(x...)
 #endif
@@ -357,7 +370,6 @@ void *ocat_controller(void *);
 void *ctrl_handler(void *);
 int insert_peer(int, const SocksQueue_t *, time_t);
 
-
 /* ocatthread.c */
 const OcatThread_t *init_ocat_thread(const char *);
 int run_ocat_thread(const char *, void *(*)(void*), void*);
@@ -383,7 +395,8 @@ OcatPeer_t *get_empty_peer(void);
 void delete_peer(OcatPeer_t *);
 
 /* ocatsetup.c */
-extern struct OcatSetup setup;
+#define CNF(x) setup_.x
+extern struct OcatSetup setup_;
 void print_setup_struct(FILE *);
 void init_setup(void);
 
diff --git a/src/ocateth.c b/src/ocateth.c
index b2e8cf0..ef0891f 100644
--- a/src/ocateth.c
+++ b/src/ocateth.c
@@ -347,7 +347,7 @@ int ndp_solicit(char *buf, int rlen)
          return -1;
       }
    memcpy(eh->ether_dhost, eh->ether_shost, ETH_ALEN);
-   memcpy(eh->ether_shost, setup.ocat_hwaddr, ETH_ALEN);
+   memcpy(eh->ether_shost, CNF(ocat_hwaddr), ETH_ALEN);
 
    // init ip6 header
    memcpy(&ip6->ip6_dst, &ip6->ip6_src, sizeof(struct in6_addr));
@@ -359,14 +359,14 @@ int ndp_solicit(char *buf, int rlen)
    nda->nd_na_hdr.icmp6_cksum = 0;
    nda->nd_na_flags_reserved = ND_NA_FLAG_SOLICITED;
    ohd->nd_opt_type = ND_OPT_TARGET_LINKADDR;
-   memcpy(ohd + 1, setup.ocat_hwaddr, ETH_ALEN);
+   memcpy(ohd + 1, CNF(ocat_hwaddr), ETH_ALEN);
 
    ckb = malloc_ckbuf(&ip6->ip6_src, &ip6->ip6_dst, ntohs(ip6->ip6_plen), IPPROTO_ICMPV6, icmp6);
    nda->nd_na_hdr.icmp6_cksum = checksum(ckb, ntohs(ip6->ip6_plen) + sizeof(struct ip6_psh));
    free_ckbuf(ckb);
 
-   log_debug("writing %d bytes to tunfd %d", rlen, setup.tunfd[1]);
-   if (write(setup.tunfd[1], buf, rlen) < rlen)
+   log_debug("writing %d bytes to tunfd %d", rlen, CNF(tunfd[1]));
+   if (write(CNF(tunfd[1]), buf, rlen) < rlen)
       log_msg(L_ERROR, "short write");
 
    return 0;
diff --git a/src/ocatipv4route.c b/src/ocatipv4route.c
index 775131c..54a46c4 100644
--- a/src/ocatipv4route.c
+++ b/src/ocatipv4route.c
@@ -198,7 +198,7 @@ int parse_route(const char *rs)
    if (!has_tor_prefix(&route.gw))
       return E_RT_NOTORGW;
 
-   if (IN6_ARE_ADDR_EQUAL(&route.gw, &setup.ocat_addr))
+   if (IN6_ARE_ADDR_EQUAL(&route.gw, &CNF(ocat_addr)))
       return E_RT_GWSELF;
 
    route.netmask = ntohl(route.netmask);
diff --git a/src/ocatlog.c b/src/ocatlog.c
index ece4851..d89934e 100644
--- a/src/ocatlog.c
+++ b/src/ocatlog.c
@@ -47,7 +47,7 @@ int open_connect_log(const char *dir)
 
    strlcpy(buf, dir, CBUFLEN);
    strlcat(buf, "/", CBUFLEN);
-   strlcat(buf, setup.ocat_dir, CBUFLEN);
+   strlcat(buf, CNF(ocat_dir), CBUFLEN);
 
    log_debug("creating ocat log dir \"%s\"", buf);
    if (mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP) && (errno != EEXIST))
@@ -78,7 +78,7 @@ void vlog_msgf(FILE *out, int lf, const char *fmt, va_list ap)
    const OcatThread_t *th = get_thread();
    int level = lf & L_LEVEL_MASK;
 
-   if (setup.debug_level < level)
+   if (CNF(debug_level) < level)
       return;
 
    t = time(NULL);
@@ -98,7 +98,7 @@ void log_msg(int lf, const char *fmt, ...)
    va_list ap;
 
    va_start(ap, fmt);
-   vlog_msgf(setup.logf, lf, fmt, ap);
+   vlog_msgf(CNF(logf), lf, fmt, ap);
    va_end(ap);
    if (clog_ && (lf & L_FCONN))
    {
diff --git a/src/ocatpeer.c b/src/ocatpeer.c
index 41e17d0..5a0b5bc 100644
--- a/src/ocatpeer.c
+++ b/src/ocatpeer.c
@@ -100,7 +100,7 @@ OcatPeer_t *get_empty_peer(void)
    }
 
    peer->tunhdr = (uint32_t*) peer->_fragbuf;
-   peer->fragbuf = &peer->_fragbuf[setup.fhd_key_len];
+   peer->fragbuf = &peer->_fragbuf[CNF(fhd_key_len)];
    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 418877f..6c900dd 100644
--- a/src/ocatroute.c
+++ b/src/ocatroute.c
@@ -255,7 +255,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, setup.onion_url
+         OCAT_URL, timestr, CNF(onion_url)
          );
    log_msg(L_INFO, "request seems to be HTTP");
    if (send(peer->tcpfd, response, strlen(response), MSG_DONTWAIT) == -1)
@@ -393,7 +393,7 @@ void *socket_receiver(void *p)
                }
 
                len = ntohs(((struct ip6_hdr*)peer->fragbuf)->ip6_plen) + IP6HLEN;
-               *peer->tunhdr = setup.fhd_key[IPV6_KEY];
+               *peer->tunhdr = CNF(fhd_key[IPV6_KEY]);
             }
             // incoming packet seems to be IPv4
             else if ((peer->fragbuf[0] & 0xf0) == 0x40)
@@ -425,7 +425,7 @@ void *socket_receiver(void *p)
                }
 
                len = IPPKTLEN(peer->fragbuf);
-               *peer->tunhdr = setup.fhd_key[IPV4_KEY];
+               *peer->tunhdr = CNF(fhd_key[IPV4_KEY]);
             }
             else
             {
@@ -435,13 +435,11 @@ void *socket_receiver(void *p)
             }
 
             // set IP address if it is not set yet and frame is valid
-            //if (!memcmp(&peer->addr, &in6addr_any, sizeof(struct in6_addr)))
-            //if (IN6_ARE_ADDR_EQUAL(&peer->addr, &in6addr_any))
             if (IN6_IS_ADDR_UNSPECIFIED(&peer->addr))
             {
-               if (*peer->tunhdr == setup.fhd_key[IPV6_KEY])
+               if (*peer->tunhdr == CNF(fhd_key[IPV6_KEY]))
                   memcpy(&peer->addr, &((struct ip6_hdr*)peer->fragbuf)->ip6_src, sizeof(struct in6_addr));
-               else if (*peer->tunhdr == setup.fhd_key[IPV4_KEY])
+               else if (*peer->tunhdr == CNF(fhd_key[IPV4_KEY]))
                {
                   // check if there is a route back
 #ifdef HAVE_STRUCT_IPHDR
@@ -465,14 +463,14 @@ void *socket_receiver(void *p)
             if (!drop)
             {
                // write directly on TUN device
-               if (!setup.use_tap)
+               if (!CNF(use_tap))
                {
-                  log_debug("writing to tun %d framesize %d + 4", setup.tunfd[1], len);
-                  if (write(setup.tunfd[1], peer->tunhdr, len + 4) != (len + 4))
-                     log_msg(L_ERROR, "could not write %d bytes to tunnel %d", len + 4, setup.tunfd[1]);
+                  log_debug("writing to tun %d framesize %d + 4", CNF(tunfd[1]), len);
+                  if (write(CNF(tunfd[1]), peer->tunhdr, len + 4) != (len + 4))
+                     log_msg(L_ERROR, "could not write %d bytes to tunnel %d", len + 4, CNF(tunfd[1]));
                }
                // create ethernet header and handle MAC on TAP device
-               else if (*peer->tunhdr == setup.fhd_key[IPV6_KEY])
+               else if (*peer->tunhdr == CNF(fhd_key[IPV6_KEY]))
                {
                   log_debug("creating ethernet header");
 
@@ -485,15 +483,15 @@ void *socket_receiver(void *p)
                   {
                      *((uint32_t*) buf) = *peer->tunhdr;
                      memcpy(buf + 4 + sizeof(struct ether_header), peer->fragbuf, len);
-                     memcpy(eh->ether_shost, setup.ocat_hwaddr, ETH_ALEN);
+                     memcpy(eh->ether_shost, CNF(ocat_hwaddr), ETH_ALEN);
 
-                     if (*peer->tunhdr == setup.fhd_key[IPV6_KEY])
+                     if (*peer->tunhdr == CNF(fhd_key[IPV6_KEY]))
                         eh->ether_type = htons(ETHERTYPE_IPV6);
-                     else if (*peer->tunhdr == setup.fhd_key[IPV4_KEY])
+                     else if (*peer->tunhdr == CNF(fhd_key[IPV4_KEY]))
                         eh->ether_type = htons(ETHERTYPE_IP);
 
-                     if (write(setup.tunfd[1], buf, len + 4 + sizeof(struct ether_header)) != (len + 4 + sizeof(struct ether_header)))
-                        log_msg(L_ERROR, "could not write %d bytes to tunnel %d", len + 4 + sizeof(struct ether_header), setup.tunfd[1]);
+                     if (write(CNF(tunfd[1]), buf, len + 4 + sizeof(struct ether_header)) != (len + 4 + sizeof(struct ether_header)))
+                        log_msg(L_ERROR, "could not write %d bytes to tunnel %d", len + 4 + sizeof(struct ether_header), CNF(tunfd[1]));
                   }
                }
                else
@@ -715,180 +713,11 @@ int run_local_listeners(short port, int *sockfd, int (action_accept)(int))
 
 void *socket_acceptor(void *p)
 {
-   run_local_listeners(setup.ocat_listen_port, sockfd_, insert_anon_peer);
+   run_local_listeners(CNF(ocat_listen_port), sockfd_, insert_anon_peer);
    return NULL;
 }
 
 
-#if 0
-int socks_connect(const SocksQueue_t *sq)
-//int socks_connect(const struct in6_addr *addr)
-{
-   struct sockaddr_in in;
-   int fd, t, len;
-   char buf[FRAME_SIZE], onion[ONION_NAME_SIZE];
-   SocksHdr_t *shdr = (SocksHdr_t*) buf;
-
-   log_debug("called");
-
-   memset(&in, 0, sizeof(in));
-   in.sin_family = AF_INET;
-   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);
-#endif
-
-   ipv6tonion(&sq->addr, onion);
-   strlcat(onion, ".onion", sizeof(onion));
-
-   log_msg(L_NOTICE, "trying to connect to \"%s\" [%s]", onion, inet_ntop(AF_INET6, &sq->addr, buf, FRAME_SIZE));
-
-   if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
-      return E_SOCKS_SOCK;
-
-   t = time(NULL);
-   if (connect(fd, (struct sockaddr*) &in, sizeof(in)) == -1)
-   {
-      log_msg(L_ERROR, "connect() to TOR failed: \"%s\"", strerror(errno));
-      oe_close(fd);
-      return E_SOCKS_CONN;
-   }
-
-   log_debug("connected to TOR, doing SOCKS handshake");
-
-   shdr->ver = 4;
-   shdr->cmd = 1;
-   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), 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_debug("connect request sent");
-
-   if (read(fd, shdr, sizeof(SocksHdr_t)) < sizeof(SocksHdr_t))
-   {
-      log_msg(L_ERROR | L_FCONN, "short read, closing.");
-      oe_close(fd);
-      return E_SOCKS_REQ;
-   }
-   log_debug("SOCKS response received");
-
-   if (shdr->ver || (shdr->cmd != 90))
-   {
-      log_msg(L_ERROR, "request failed, reason = %d", shdr->cmd);
-      oe_close(fd);
-      return E_SOCKS_RQFAIL;
-   }
-   log_msg(L_NOTICE | L_FCONN, "connection to %s successfully opened on fd %d", onion, fd);
-
-   insert_peer(fd, sq, time(NULL) - t);
-
-   return fd;
-}
-
-
-void socks_queue(const struct in6_addr *addr, int perm)
-{
-   SocksQueue_t *squeue;
-
-   pthread_mutex_lock(&socks_queue_mutex_);
-   for (squeue = socks_queue_; squeue; squeue = squeue->next)
-      //if (!memcmp(&squeue->addr, addr, sizeof(struct in6_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(L_FATAL, "could not get memory for SocksQueue entry: \"%s\"", strerror(errno)), exit(1);
-      memcpy(&squeue->addr, addr, sizeof(struct in6_addr));
-      squeue->perm = perm;
-      squeue->next = socks_queue_;
-      socks_queue_ = squeue;
-      log_debug("signalling connector");
-      pthread_cond_signal(&socks_queue_cond_);
-   }
-   else
-      log_debug("connection already exists, not queueing SOCKS connection");
-   pthread_mutex_unlock(&socks_queue_mutex_);
-}
-
-
-void *socks_connector(void *p)
-{
-   OcatPeer_t *peer;
-   SocksQueue_t **squeue, *sq;
-   int i, rc, ps, run = 1;
-
-   if ((rc = pthread_detach(pthread_self())))
-      log_msg(L_ERROR, "couldn't detach: \"%s\"", rc);
-
-   pthread_mutex_lock(&socks_queue_mutex_);
-   socks_thread_cnt_++;
-   pthread_mutex_unlock(&socks_queue_mutex_);
-
-   while (run)
-   {
-      pthread_mutex_lock(&socks_queue_mutex_);
-      do
-      {
-         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;
-      socks_connect_cnt_++;
-      if (socks_thread_cnt_ <= socks_connect_cnt_)
-         run_ocat_thread("connector", socks_connector, NULL);
-      pthread_mutex_unlock(&socks_queue_mutex_);
-
-      // search for existing peer
-      lock_peers();
-      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 && ps < 0; i++)
-            ps = socks_connect(*squeue);
-            //ps = socks_connect(&(*squeue)->addr);
-      else
-         log_msg(L_NOTICE, "peer already exists, ignoring");
-
-      // 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_connect_cnt_--;
-
-      // if there are more threads then pending connections
-      // terminate thread
-      if (socks_connect_cnt_ < socks_thread_cnt_ - 1)
-      {
-         socks_thread_cnt_--;
-         run = 0;
-      }
-      pthread_mutex_unlock(&socks_queue_mutex_);
-   }
-   return NULL;
-}
-#endif
-
-
 void packet_forwarder(void)
 {
    char buf[FRAME_SIZE];
@@ -906,10 +735,10 @@ void packet_forwarder(void)
 
    for (;;)
    {
-      if ((rlen = read(setup.tunfd[0], buf, FRAME_SIZE)) == -1)
+      if ((rlen = read(CNF(tunfd[0]), buf, FRAME_SIZE)) == -1)
       {
          rlen = errno;
-         log_debug("read from tun %d returned on error: \"%s\"", setup.tunfd[0], strerror(rlen));
+         log_debug("read from tun %d returned on error: \"%s\"", CNF(tunfd[0]), strerror(rlen));
          if (rlen == EINTR)
          {
             log_debug("signal caught, exiting");
@@ -919,7 +748,7 @@ void packet_forwarder(void)
          continue;
       }
 
-      log_debug("received on tunfd %d, framesize %d + 4", setup.tunfd[0], rlen - 4);
+      log_debug("received on tunfd %d, framesize %d + 4", CNF(tunfd[0]), rlen - 4);
 
 #ifdef PACKET_LOG
       if ((pktlog != -1) && (write(pktlog, buf, rlen) == -1))
@@ -927,16 +756,16 @@ void packet_forwarder(void)
 #endif
 
       // just to be on the safe side but this should never happen
-      if ((!setup.use_tap && (rlen < 4)) || (setup.use_tap && (rlen < 4 + sizeof(struct ether_header))))
+      if ((!CNF(use_tap) && (rlen < 4)) || (CNF(use_tap) && (rlen < 4 + sizeof(struct ether_header))))
       {
          log_msg(L_ERROR, "frame effektively too short (rlen = %d)", rlen);
          continue;
       }
 
       // in case of TAP device handle ethernet header
-      if (setup.use_tap)
+      if (CNF(use_tap))
       {
-         if (!memcmp(eh->ether_dhost, setup.ocat_hwaddr, ETH_ALEN))
+         if (!memcmp(eh->ether_dhost, CNF(ocat_hwaddr), ETH_ALEN))
             // remove ethernet header from buffer
             // FIXME: it would be better to adjust pointers instead of moving data
             memmove(eh, eh + 1, rlen - 4 - sizeof(struct ether_header));
@@ -949,7 +778,7 @@ void packet_forwarder(void)
          }
       }
 
-      if (*((uint32_t*) buf) == setup.fhd_key[IPV6_KEY])
+      if (*((uint32_t*) buf) == CNF(fhd_key[IPV6_KEY]))
       {
          if (((rlen - 4) < IP6HLEN))
          {
@@ -965,7 +794,7 @@ void packet_forwarder(void)
 
          dest = &((struct ip6_hdr*) &buf[4])->ip6_dst;
       }
-      else if (*((uint32_t*) buf) == setup.fhd_key[IPV4_KEY])
+      else if (*((uint32_t*) buf) == CNF(fhd_key[IPV4_KEY]))
       {
          if (((rlen - 4) < IPHDLEN))
          {
@@ -1011,7 +840,7 @@ int send_keepalive(const OcatPeer_t *peer)
 
    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));
+   memcpy(&hdr.ip6_src, &CNF(ocat_addr), sizeof(struct in6_addr));
    hdr.ip6_vfc = 0x60;
    hdr.ip6_nxt = IPPROTO_NONE;
    hdr.ip6_hops = 1;
@@ -1116,7 +945,7 @@ void *ctrl_handler(void *p)
    log_debug("thread detached");
 
    fd = (int) p;
-   if (setup.config_read)
+   if (CNF(config_read))
    {
       if (!(ff = fdopen(fd, "r+")))
       {
@@ -1131,18 +960,18 @@ void *ctrl_handler(void *p)
       if (!(ff = fdopen(fd, "r")))
       {
          log_msg(L_ERROR, "could not open %d for reading: %s", fd, strerror(errno));
-         setup.config_read = 1;
+         CNF(config_read) = 1;
          return NULL;
       }
       log_debug("fd %d fdopen'ed", fd);
-      fo = setup.logf;
-      //setup.config_read = 1;
+      fo = CNF(logf);
+      //CNF(config_read = 1;
    }
 
    for (;;)
    {
-      if (setup.config_read)
-         fprintf(fo, "%s> ", setup.onion_url);
+      if (CNF(config_read))
+         fprintf(fo, "%s> ", CNF(onion_url));
 
       c = getc(ff);
       if (c == EOF)
@@ -1317,15 +1146,15 @@ void *ctrl_handler(void *p)
       }
    }
 
-   if (setup.config_read)
+   if (CNF(config_read))
       fprintf(fo, "Good bye!\n");
    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
 
-   if (!setup.config_read)
-      setup.config_read = 1;
+   if (!CNF(config_read))
+      CNF(config_read) = 1;
 
    return NULL;
 }
@@ -1339,7 +1168,7 @@ int run_ctrl_handler(int fd)
 
 void *ocat_controller(void *p)
 {
-   run_local_listeners(setup.ocat_ctrl_port, ctrlfd_, run_ctrl_handler);
+   run_local_listeners(CNF(ocat_ctrl_port), ctrlfd_, run_ctrl_handler);
    return NULL;
 }
 
diff --git a/src/ocatsetup.c b/src/ocatsetup.c
index e67841e..0fd5b54 100644
--- a/src/ocatsetup.c
+++ b/src/ocatsetup.c
@@ -15,7 +15,7 @@
  * along with OnionCat. If not, see <http://www.gnu.org/licenses/>.
  */
 
-/*! ocatsetup.c
+/*! ocatsetup_.c
  *  This file contains the global settings structure.
  *
  *  @author Bernhard Fischer <rahra _at_ cypherpunk at>
@@ -30,7 +30,8 @@
 
 #include "ocat.h"
 
-struct OcatSetup setup = {
+struct OcatSetup setup_ =
+{
    // fhd_keys
    {0, 0},
    // fhd_key_len
@@ -45,13 +46,17 @@ struct OcatSetup setup = {
    {0x00, 0x00, 0x6c, 0x00, 0x00, 0x00},   // ocat_hwaddr (OnionCat MAC address)
    PID_FILE,
    NULL, NULL,                             // logfile
-   0                                       // daemon
+   0,                                      // daemon
+   {
+      {{{0xfd, 0x87, 0xd8, 0x7e, 0xeb, 0x43,
+           0xed, 0xb1, 0x8, 0xe4, 0x35, 0x88, 0xe5, 0x46, 0x35, 0xca}}} // initial permanent peer "5wyqrzbvrdsumnok"
+   }
 };
 
 
 void init_setup(void)
 {
-   setup.logf = stderr;
+   setup_.logf = stderr;
 }
 
 
@@ -59,74 +64,81 @@ void init_setup(void)
 
 void print_setup_struct(FILE *f)
 {
-   char ip[_SB], nm[_SB], ip6[_SB], hw[_SB], logf[_SB];
+   char ip[_SB], nm[_SB], ip6[_SB], hw[_SB], logf[_SB], rp[ROOT_PEERS][_SB];
+   int i;
 
-   inet_ntop(AF_INET, &setup.ocat_addr4, ip, _SB);
-   inet_ntop(AF_INET, &setup.ocat_addr4_mask, nm, _SB);
-   inet_ntop(AF_INET6, &setup.ocat_addr, ip6, _SB);
-   mac_hw2str(setup.ocat_hwaddr, hw);
+   inet_ntop(AF_INET, &setup_.ocat_addr4, ip, _SB);
+   inet_ntop(AF_INET, &setup_.ocat_addr4_mask, nm, _SB);
+   inet_ntop(AF_INET6, &setup_.ocat_addr, ip6, _SB);
+   mac_hw2str(setup_.ocat_hwaddr, hw);
+   for (i = 0; i < ROOT_PEERS; i++)
+      inet_ntop(AF_INET6, &setup_.root_peer[i], rp[i], _SB);
 
-   if (setup.logf == stderr)
+   if (setup_.logf == stderr)
       strcpy(logf, "stderr");
    else
-      sprintf(logf, "%p", setup.logf);
+      sprintf(logf, "%p", setup_.logf);
 
    fprintf(f,
-         "fhd_key[]        = [IPV4(%d) => 0x%04x, IPV6(%d) => 0x%04x]\n"
-         "fhd_key_len      = %d\n"
-         "tor_socks_port   = %d\n"
-         "ocat_listen_port = %d\n"
-         "ocat_dest_port   = %d\n"
-         "ocat_ctrl_port   = %d\n"
-         "tunfd[]          = [(0) => %d, (1) => %d]\n"
-         "debug_level      = %d\n"
-         "usrname          = \"%s\"\n"
-         "onion_url        = \"%s\"\n"
-         "ocat_addr        = %s\n"
-         "create_clog      = %d\n"
-         "runasroot        = %d\n"
-         "controller       = %d\n"
-         "ocat_dir         = \"%s\"\n"
-         "tun_dev          = \"%s\"\n"
-         "ipv4_enable      = %d\n"
-         "ocat_addr4       = %s\n"
-         "ocat_addr4_mask  = %s\n"
-         "config_file      = \"%s\"\n"
-         "config_read      = %d\n"
-         "use_tap          = %d\n"
-         "ocat_hwaddr      = %s\n"
-         "pid_file         = \"%s\"\n"
-         "logfn            = \"%s\"\n"
-         "logf             = %s\n"
-         "daemon           = %d\n",
-
-         IPV4_KEY, ntohl(setup.fhd_key[IPV4_KEY]), IPV6_KEY, ntohl(setup.fhd_key[IPV6_KEY]),
-         setup.fhd_key_len,
-         setup.tor_socks_port,
-         setup.ocat_listen_port,
-         setup.ocat_dest_port,
-         setup.ocat_ctrl_port,
-         setup.tunfd[0], setup.tunfd[1],
-         setup.debug_level,
-         setup.usrname,
-         setup.onion_url,
+         "fhd_key[IPV4(%d)]  = 0x%04x\n"
+         "fhd_key[IPV6(%d)]  = 0x%04x\n"
+         "fhd_key_len       = %d\n"
+         "tor_socks_port    = %d\n"
+         "ocat_listen_port  = %d\n"
+         "ocat_dest_port    = %d\n"
+         "ocat_ctrl_port    = %d\n"
+         "tunfd[0]          = %d\n"
+         "tunfd[1]          = %d\n"
+         "debug_level       = %d\n"
+         "usrname           = \"%s\"\n"
+         "onion_url         = \"%s\"\n"
+         "ocat_addr         = %s\n"
+         "create_clog       = %d\n"
+         "runasroot         = %d\n"
+         "controller        = %d\n"
+         "ocat_dir          = \"%s\"\n"
+         "tun_dev           = \"%s\"\n"
+         "ipv4_enable       = %d\n"
+         "ocat_addr4        = %s\n"
+         "ocat_addr4_mask   = %s\n"
+         "config_file       = \"%s\"\n"
+         "config_read       = %d\n"
+         "use_tap           = %d\n"
+         "ocat_hwaddr       = %s\n"
+         "pid_file          = \"%s\"\n"
+         "logfn             = \"%s\"\n"
+         "logf              = %s\n"
+         "daemon            = %d\n"
+         "root_peer[0]      = %s\n",
+ 
+         IPV4_KEY, ntohl(setup_.fhd_key[IPV4_KEY]), IPV6_KEY, ntohl(setup_.fhd_key[IPV6_KEY]),
+         setup_.fhd_key_len,
+         setup_.tor_socks_port,
+         setup_.ocat_listen_port,
+         setup_.ocat_dest_port,
+         setup_.ocat_ctrl_port,
+         setup_.tunfd[0], setup_.tunfd[1],
+         setup_.debug_level,
+         setup_.usrname,
+         setup_.onion_url,
          ip6,
-         setup.create_clog,
-         setup.runasroot,
-         setup.controller,
-         setup.ocat_dir,
-         setup.tun_dev,
-         setup.ipv4_enable,
+         setup_.create_clog,
+         setup_.runasroot,
+         setup_.controller,
+         setup_.ocat_dir,
+         setup_.tun_dev,
+         setup_.ipv4_enable,
          ip,
          nm,
-         setup.config_file,
-         setup.config_read,
-         setup.use_tap,
+         setup_.config_file,
+         setup_.config_read,
+         setup_.use_tap,
          hw,
-         setup.pid_file,
-         setup.logfn,
+         setup_.pid_file,
+         setup_.logfn,
          logf,
-         setup.daemon
+         setup_.daemon,
+         rp[0]
          );
 }
 
diff --git a/src/ocatsocks.c b/src/ocatsocks.c
index 40336f0..8892f54 100644
--- a/src/ocatsocks.c
+++ b/src/ocatsocks.c
@@ -70,7 +70,7 @@ int socks_connect(const SocksQueue_t *sq)
 
    memset(&in, 0, sizeof(in));
    in.sin_family = AF_INET;
-   in.sin_port = htons(setup.tor_socks_port);
+   in.sin_port = htons(CNF(tor_socks_port));
    in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
 #ifdef HAVE_SIN_LEN
    in.sin_len = sizeof(in);
@@ -96,15 +96,15 @@ int socks_connect(const SocksQueue_t *sq)
 
    shdr->ver = 4;
    shdr->cmd = 1;
-   shdr->port = htons(setup.ocat_dest_port);
+   shdr->port = htons(CNF(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), 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;
+   memcpy(buf + sizeof(SocksHdr_t), CNF(usrname), strlen(CNF(usrname)) + 1);
+   memcpy(buf + sizeof(SocksHdr_t) + strlen(CNF(usrname)) + 1, onion, strlen(onion) + 1);
+   len = sizeof(SocksHdr_t) + strlen(CNF(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);
diff --git a/src/ocattun.c b/src/ocattun.c
index ab713f8..26982f2 100644
--- a/src/ocattun.c
+++ b/src/ocattun.c
@@ -61,18 +61,18 @@ int tun_alloc(char *dev, struct in6_addr addr)
    char astr[INET6_ADDRSTRLEN];
    char astr4[INET_ADDRSTRLEN];
    char buf[FRAME_SIZE];
-   struct in_addr netmask = {setup.ocat_addr4_mask};
+   struct in_addr netmask = {CNF(ocat_addr4_mask)};
 
 	log_debug("opening tun \"%s\"", tun_dev_);
    if ((fd = open(tun_dev_, O_RDWR)) < 0)
       log_msg(L_FATAL, "could not open tundev %s: %s", tun_dev_, strerror(errno)), exit(1);
    inet_ntop(AF_INET6, &addr, astr, INET6_ADDRSTRLEN);
-   inet_ntop(AF_INET, &setup.ocat_addr4, astr4, INET_ADDRSTRLEN);
+   inet_ntop(AF_INET, &CNF(ocat_addr4), astr4, INET_ADDRSTRLEN);
 
 #ifdef __linux__
 
    memset(&ifr, 0, sizeof(ifr));
-   if (setup.use_tap)
+   if (CNF(use_tap))
       ifr.ifr_flags = IFF_TAP;
    else
       ifr.ifr_flags = IFF_TUN;
@@ -83,7 +83,7 @@ int tun_alloc(char *dev, struct in6_addr addr)
    if (ioctl(fd, TUNSETIFF, (void *) &ifr) < 0)
       log_msg(L_FATAL, "could not set TUNSETIFF: %s", strerror(errno)), exit(1);
    strlcpy(dev, ifr.ifr_name, IFNAMSIZ);
-   if (!setup.use_tap)
+   if (!CNF(use_tap))
    {
       sprintf(buf, "ifconfig %s add %s/%d up", dev, astr, TOR_PREFIX_LEN);
       log_msg(L_NOTICE, "configuring tun IP: \"%s\"", buf);
@@ -98,14 +98,14 @@ int tun_alloc(char *dev, struct in6_addr addr)
       */
 
    // set tun frame header to ethertype IPv6
-   setup.fhd_key[IPV6_KEY] = htonl(ETHERTYPE_IPV6);
-   setup.fhd_key[IPV4_KEY] = htonl(ETHERTYPE_IP);
+   CNF(fhd_key[IPV6_KEY]) = htonl(ETHERTYPE_IPV6);
+   CNF(fhd_key[IPV4_KEY]) = htonl(ETHERTYPE_IP);
 
 #else
 
    // set tun frame header to address family AF_INET6 (FreeBSD = 0x1c, OpenBSD = 0x18)
-   setup.fhd_key[IPV6_KEY] = htonl(AF_INET6);
-   setup.fhd_key[IPV4_KEY] = htonl(AF_INET);
+   CNF(fhd_key[IPV6_KEY]) = htonl(AF_INET6);
+   CNF(fhd_key[IPV4_KEY]) = htonl(AF_INET);
 
 #ifdef __FreeBSD__
 
@@ -118,7 +118,7 @@ int tun_alloc(char *dev, struct in6_addr addr)
 
 #endif
 
-   if (!setup.use_tap)
+   if (!CNF(use_tap))
    {
       sprintf(buf, "ifconfig tun0 inet6 %s/%d up", astr, TOR_PREFIX_LEN);
       log_debug("setting IP on tun: \"%s\"", buf);
@@ -129,7 +129,7 @@ int tun_alloc(char *dev, struct in6_addr addr)
 #endif
 
    // setting up IPv4 address
-   if (setup.ipv4_enable && !setup.use_tap)
+   if (CNF(ipv4_enable) && !CNF(use_tap))
    {
       sprintf(buf, "ifconfig %s %s netmask %s", dev, astr4, inet_ntoa(netmask));
       log_msg(L_NOTICE, "configuring tun IP: \"%s\"", buf);
@@ -138,7 +138,7 @@ int tun_alloc(char *dev, struct in6_addr addr)
    }
 
    // bring up tap device
-   if (setup.use_tap)
+   if (CNF(use_tap))
    {
        sprintf(buf, "ifconfig %s up", dev);
       log_msg(L_NOTICE, "bringing up TAP device \"%s\"", buf);

-- 
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