[Pkg-privacy-commits] [onioncat] 11/340: add simpler tun header test

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:04:20 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 5ab88446688e36235dd051461a96afccfb16d93b
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date:   Fri Feb 8 10:59:10 2008 +0000

    add simpler tun header test
    
    git-svn-id: http://www.cypherpunk.at/svn/onioncat/trunk@126 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
 TODO        |  1 +
 ocat.c      | 12 ++++++++++--
 ocat.h      |  7 +++++++
 ocatroute.c | 18 ++++++++++--------
 ocattun.c   | 29 +++++++++++++++++++++++++++++
 5 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/TODO b/TODO
index 36d0da1..29a6064 100644
--- a/TODO
+++ b/TODO
@@ -4,5 +4,6 @@
 //* garbage collector for session cleanup
 * improve getopt() -- currently many things are hardcoded
 //* packets received on sockets should be validated (Ethertype, ip)
+* improve tun header test (check for src and dst ip)
 * licence
 
diff --git a/ocat.c b/ocat.c
index 989be2b..4881500 100644
--- a/ocat.c
+++ b/ocat.c
@@ -48,6 +48,7 @@ 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"
          "   -T <tun_device>       path to tun character device\n"
 #endif
          "   -v                    validate packets from sockets, default = %d\n"
@@ -62,12 +63,12 @@ int main(int argc, char *argv[])
    int c, runasroot = 0;
    uid_t uid = 504;
    gid_t gid = 504;
-   int urlconv = 0;
+   int urlconv = 0, test_only = 0;
 
    if (argc < 2)
       usage(argv[0]), exit(1);
 
-   while ((c = getopt(argc, argv, "d:hriol:t:T:s:")) != -1)
+   while ((c = getopt(argc, argv, "d:hriopl:t:T:s:")) != -1)
       switch (c)
       {
          case 'd':
@@ -99,6 +100,10 @@ int main(int argc, char *argv[])
             break;
 
 #ifndef WITHOUT_TUN
+         case 'p':
+            test_only = 1;
+            break;
+
          case 'T':
             tun_dev_ = optarg;
             break;
@@ -150,6 +155,9 @@ int main(int argc, char *argv[])
 #ifndef WITHOUT_TUN
    // create TUN device
    tunfd_[0] = tunfd_[1] = tun_alloc(tunname, addr);
+   test_tun_hdr();
+   if (test_only)
+      exit(0);
 #endif
    log_msg(L_NOTICE, "[main] local IP is %s on %s", ip6addr, tunname);
    // start socket receiver thread
diff --git a/ocat.h b/ocat.h
index ee4f9ea..88c74cc 100644
--- a/ocat.h
+++ b/ocat.h
@@ -72,6 +72,12 @@ typedef struct OnionPeer
    int dir;
 } OnionPeer_t;
 
+typedef struct OcatHdr
+{
+   struct ip6_hdrctl oh_ip6hdrctl;
+   char oh_srcid[10];
+} OcatHdr_t;
+
 extern uint16_t tor_socks_port_;
 extern uint16_t ocat_listen_port_;
 extern uint16_t ocat_dest_port_;
@@ -81,6 +87,7 @@ extern int tunfd_[2];
 #ifndef WITHOUT_TUN
 #define TUN_DEV "/dev/net/tun"
 extern char *tun_dev_;
+extern uint32_t fhd_key_;
 #endif
 
 /* ocatlog.c */
diff --git a/ocatroute.c b/ocatroute.c
index c43c463..85e191e 100644
--- a/ocatroute.c
+++ b/ocatroute.c
@@ -40,8 +40,8 @@ static PacketQueue_t *queue_ = NULL;
 static pthread_mutex_t queue_mutex_ = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t queue_cond_ = PTHREAD_COND_INITIALIZER;
 
-// frame header of local OS
-static uint32_t fhd_key_;
+// frame header of local OS in network byte order
+uint32_t fhd_key_ = 0;
 
 uint16_t tor_socks_port_ = TOR_SOCKS_PORT;
 uint16_t ocat_listen_port_ = OCAT_LISTEN_PORT;
@@ -53,12 +53,6 @@ int vrec_ = 0;
 void init_peers(void)
 {
    memset(peer_, 0, sizeof(OnionPeer_t) * MAXPEERS);
-   // FIXME: this initialization should done somewhere else
-#ifdef linux
-   fhd_key_ = htonl(0x86dd);
-#else
-   fhd_key_ = htonl(0x1c);
-#endif
 }
 
 
@@ -96,6 +90,14 @@ void delete_peer(OnionPeer_t *peer)
 }
 
 
+void mk_ocat_frame(const struct in6_addr *addr, const struct ip6_hdr *ihd, OcatHdr_t *ohd)
+{
+   memcpy(ohd, ihd, sizeof(struct ip6_hdrctl));
+   memcpy(ohd->oh_srcid, (char*)addr + 6, 10);
+   memcpy(ohd + 1, ihd + 1, ihd->ip6_plen);
+}
+
+
 void rewrite_framehdr(char *buf, int len)
 {
    uint32_t *fhd = (uint32_t*) buf;
diff --git a/ocattun.c b/ocattun.c
index 57a145a..8638f11 100644
--- a/ocattun.c
+++ b/ocattun.c
@@ -124,5 +124,34 @@ int tun_alloc(char *dev, struct in6_addr addr)
    return fd;
 }              
  
+
+void test_tun_hdr(void)
+{
+   struct in6_addr addr;
+   char addrstr[INET6_ADDRSTRLEN];
+   char buf[FRAME_SIZE];
+   int rlen;
+
+   if (oniontipv6("aaaaaaaaaaaaaaab", &addr) == -1)
+      log_msg(L_FATAL, "[test_tun_hdr] this should never happen..."), exit(1);
+
+   inet_ntop(AF_INET6, &addr, addrstr, INET6_ADDRSTRLEN);
+   sprintf(buf, "ping6 -c 1 -w 1 %s >/dev/null 2>&1", addrstr);
+   log_msg(L_NOTICE, "[test_tun_hdr] testing tun header: \"%s\"", buf);
+   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)));
+
+   if ((buf[0] & 0xf0) == 0x60)
+   {
+      log_msg(L_NOTICE, "[test_tun_hdr] tun doesn't seem to have any frame header");
+      return;
+   }
+   
+   fhd_key_ = *((uint32_t*)buf);
+   log_msg(L_NOTICE, "[test_tun_hdr] using 0x%08x as local frame header", ntohl(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