summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--anytun.cpp92
-rw-r--r--buffer.cpp31
-rw-r--r--buffer.h5
-rw-r--r--datatypes.h2
-rw-r--r--package.cpp34
-rw-r--r--package.h65
7 files changed, 182 insertions, 52 deletions
diff --git a/Makefile b/Makefile
index c84e63f..c94b0e0 100644
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,7 @@ OPENVPNDEPS = openvpn/tun.o \
-OBJS = anytun.o tunDevice.o buffer.o cypher.o authAlgo.o $(OPENVPNDEPS)
+OBJS = anytun.o tunDevice.o buffer.o package.o cypher.o authAlgo.o $(OPENVPNDEPS)
EXECUTABLE = anytun
all: $(EXECUTABLE)
@@ -45,6 +45,9 @@ tunDevice.o: tunDevice.cpp tunDevice.h
buffer.o: buffer.cpp buffer.h
$(C++) $(CCFLAGS) $< -c
+package.o: package.cpp package.h buffer.h
+ $(C++) $(CCFLAGS) $< -c
+
cypher.o: cypher.cpp cypher.h buffer.h
$(C++) $(CCFLAGS) $< -c
diff --git a/anytun.cpp b/anytun.cpp
index 966c3a8..72040c4 100644
--- a/anytun.cpp
+++ b/anytun.cpp
@@ -42,59 +42,61 @@ int main(int argc, char* argv[])
{
std::cout << "anytun - secure anycast tunneling protocol" << std::endl;
-// u_int8_t test[100];
-// for(int i=0;i<100;++i)
-// test[i] = i;
+// Buffer test(25);
+// for(unsigned int i=0; i<test.getLength(); ++i)
+// test[i] = i+1;
-// Buffer a(test, 100);
-// Buffer b(a);
+// std::cout << "test[0-" << test.getLength() << "]: '" << std::hex;
+// for(unsigned int i=0; i<test.getLength(); ++i)
+// std::cout << (int)test[i] << ",";
+// std::cout << std::dec << std::endl;
-// Buffer c;
-// c = b;
-// c.resize(500);
-
-// for(unsigned int i=0;i<c.getLength();++i)
-// c[i] = i;
+// test.resizeFront(1);
+
+// std::cout << "test[0-" << test.getLength() << "]: '" << std::hex;
+// for(unsigned int i=0; i<test.getLength(); ++i)
+// std::cout << (int)test[i] << ",";
+// std::cout << std::dec << std::endl;
- TunDevice* dev;
- dev = new TunDevice("tun", "192.168.200.1", "192.168.201.1");
- std::cout << "dev created (opened)" << std::endl;
- std::cout << "dev opened - actual name is '" << dev->getActualName() << "'" << std::endl;
- std::cout << "dev type is '" << dev->getType() << "'" << std::endl;
+// TunDevice* dev;
+// dev = new TunDevice("tun", "192.168.200.1", "192.168.201.1");
+// std::cout << "dev created (opened)" << std::endl;
+// std::cout << "dev opened - actual name is '" << dev->getActualName() << "'" << std::endl;
+// std::cout << "dev type is '" << dev->getType() << "'" << std::endl;
- sleep(10);
+// sleep(10);
- Buffer inBuf(2000);
+// Buffer inBuf(2000);
- while(1)
- {
- short revents = dev->read(inBuf);
- if(revents & POLLIN)
- std::cout << "POLLIN,";
- else if(revents & POLLRDNORM)
- std::cout << "POLLRDNORM,";
- else if(revents & POLLRDBAND)
- std::cout << "POLLRDBAND,";
- else if(revents & POLLPRI)
- std::cout << "POLLPRI,";
- else if(revents & POLLOUT)
- std::cout << "POLLOUT,";
- else if(revents & POLLWRNORM)
- std::cout << "POLLWRNORM,";
- else if(revents & POLLWRBAND)
- std::cout << "POLLWRBAND,";
- else if(revents & POLLERR)
- std::cout << "POLLERR,";
- else if(revents & POLLHUP)
- std::cout << "POLLHUP,";
- else if(revents & POLLNVAL)
- std::cout << "POLLNVAL,";
- std::cout << std::endl;
- }
+// while(1)
+// {
+// short revents = dev->read(inBuf);
+// if(revents & POLLIN)
+// std::cout << "POLLIN,";
+// else if(revents & POLLRDNORM)
+// std::cout << "POLLRDNORM,";
+// else if(revents & POLLRDBAND)
+// std::cout << "POLLRDBAND,";
+// else if(revents & POLLPRI)
+// std::cout << "POLLPRI,";
+// else if(revents & POLLOUT)
+// std::cout << "POLLOUT,";
+// else if(revents & POLLWRNORM)
+// std::cout << "POLLWRNORM,";
+// else if(revents & POLLWRBAND)
+// std::cout << "POLLWRBAND,";
+// else if(revents & POLLERR)
+// std::cout << "POLLERR,";
+// else if(revents & POLLHUP)
+// std::cout << "POLLHUP,";
+// else if(revents & POLLNVAL)
+// std::cout << "POLLNVAL,";
+// std::cout << std::endl;
+// }
- delete dev;
- std::cout << "dev destroyed" << std::endl;
+// delete dev;
+// std::cout << "dev destroyed" << std::endl;
// dev = new TunDevice("tap", "192.168.202.1", "255.255.255.0");
// std::cout << "dev created (opened)" << std::endl;
diff --git a/buffer.cpp b/buffer.cpp
index 3f6fe7c..1b194bd 100644
--- a/buffer.cpp
+++ b/buffer.cpp
@@ -85,7 +85,7 @@ void Buffer::operator=(const Buffer &src)
length_ = 0;
}
-u_int32_t Buffer::resize(u_int32_t new_length)
+u_int32_t Buffer::resizeFront(u_int32_t new_length)
{
if(length_ == new_length)
return length_;
@@ -96,7 +96,34 @@ u_int32_t Buffer::resize(u_int32_t new_length)
if(buf_)
{
- std::memcpy(tmp, buf_, length_);
+ u_int8_t *src=buf_, *dest=tmp;
+ if(length_ < new_length)
+ dest = &dest[new_length - length_];
+ else
+ src = &src[length_ - new_length];
+ u_int32_t len = length_ < new_length ? length_ : new_length;
+ std::memcpy(dest, src, len);
+ delete[] buf_;
+ }
+
+ length_ = new_length;
+ buf_ = tmp;
+ return length_;
+}
+
+u_int32_t Buffer::resizeBack(u_int32_t new_length)
+{
+ if(length_ == new_length)
+ return length_;
+
+ u_int8_t *tmp = new u_int8_t[new_length];
+ if(!tmp)
+ return length_;
+
+ if(buf_)
+ {
+ u_int32_t len = length_ < new_length ? length_ : new_length;
+ std::memcpy(tmp, buf_, len);
delete[] buf_;
}
diff --git a/buffer.h b/buffer.h
index 9856f97..be46910 100644
--- a/buffer.h
+++ b/buffer.h
@@ -39,11 +39,12 @@ public:
Buffer();
Buffer(u_int32_t length);
Buffer(u_int8_t* data, u_int32_t length);
- ~Buffer();
+ virtual ~Buffer();
Buffer(const Buffer &src);
void operator=(const Buffer &src);
- u_int32_t resize(u_int32_t new_length);
+ u_int32_t resizeFront(u_int32_t new_length);
+ u_int32_t resizeBack(u_int32_t new_length);
u_int32_t getLength() const;
u_int8_t* getBuf();
u_int8_t& operator[](u_int32_t index);
diff --git a/datatypes.h b/datatypes.h
index 74c5713..af08549 100644
--- a/datatypes.h
+++ b/datatypes.h
@@ -45,8 +45,6 @@ typedef unsigned long long u_int64_t;
typedef u_int32_t seq_nr_t;
typedef u_int16_t sender_id_t;
-typedef u_int8_t padding_t;
-typedef u_int8_t pad_cnt_t;
typedef u_int16_t payload_type_t;
typedef u_int32_t auth_tag_t;
diff --git a/package.cpp b/package.cpp
new file mode 100644
index 0000000..b008a67
--- /dev/null
+++ b/package.cpp
@@ -0,0 +1,34 @@
+/*
+ * anytun
+ *
+ * The secure anycast tunneling protocol (satp) defines a protocol used
+ * for communication between any combination of unicast and anycast
+ * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
+ * mode and allows tunneling of every ETHER TYPE protocol (e.g.
+ * ethernet, ip, arp ...). satp directly includes cryptography and
+ * message authentication based on the methodes used by SRTP. It is
+ * intended to deliver a generic, scaleable and secure solution for
+ * tunneling and relaying of packets of any protocol.
+ *
+ *
+ * Copyright (C) 2007 anytun.org <satp@wirdorange.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 this program (see the file COPYING included with this
+ * distribution); if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "datatypes.h"
+
+#include "package.h"
+
diff --git a/package.h b/package.h
new file mode 100644
index 0000000..53f71f5
--- /dev/null
+++ b/package.h
@@ -0,0 +1,65 @@
+/*
+ * anytun
+ *
+ * The secure anycast tunneling protocol (satp) defines a protocol used
+ * for communication between any combination of unicast and anycast
+ * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
+ * mode and allows tunneling of every ETHER TYPE protocol (e.g.
+ * ethernet, ip, arp ...). satp directly includes cryptography and
+ * message authentication based on the methodes used by SRTP. It is
+ * intended to deliver a generic, scaleable and secure solution for
+ * tunneling and relaying of packets of any protocol.
+ *
+ *
+ * Copyright (C) 2007 anytun.org <satp@wirdorange.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program 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 this program (see the file COPYING included with this
+ * distribution); if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _PACKAGE_H_
+#define _PACKAGE_H_
+
+#include "datatypes.h"
+#include "buffer.h"
+
+class Package : public Buffer
+{
+public:
+ Package() {}
+ Package(const Buffer &src) {}
+
+ bool hasHeader() const;
+ Package& withHeader(bool b);
+ seq_nr_t getSeqNr() const;
+ sender_id_t getSenderId() const;
+ Package& setHeader(seq_nr_t seq_nr, sender_id_t sender_id);
+
+ bool hasPayloadType() const;
+ Package& withPayloadType(bool b);
+ payload_type_t getPayloadType() const;
+ Package& setPayloadType(payload_type_t payload_type);
+
+ bool hasAuthTag() const;
+ Package& withAuthTag(bool b);
+ auth_tag_t getAuthTag() const;
+ Package& setAuthTag(auth_tag_t auth_tag);
+
+private:
+ bool has_header_;
+ bool has_payload_type_;
+ bool has_auth_tag_;
+};
+
+#endif