summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-12-28 10:08:58 +0000
committerChristian Pointner <equinox@anytun.org>2008-12-28 10:08:58 +0000
commit93c4454143a511409efd692e3687d295e3db9314 (patch)
treec6a2a8eee705bf0921f757f36e8636d964f233a8 /src
parentsome cleanup (diff)
added plain packet
Diffstat (limited to 'src')
-rw-r--r--src/Makefile4
-rw-r--r--src/plain_packet.c107
-rw-r--r--src/plain_packet.h67
-rw-r--r--src/uanytun.c123
4 files changed, 275 insertions, 26 deletions
diff --git a/src/Makefile b/src/Makefile
index 881f1ff..37cd8bf 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -49,6 +49,7 @@ OBJS = log.o \
signal.o \
tun.o \
udp.o \
+ plain_packet.o \
uanytun.o
EXECUTABLE = uanytun
@@ -73,6 +74,9 @@ tun.o: tun.c tun.h
udp.o: udp.c udp.h
$(CC) $(CCFLAGS) $< -c
+plain_packet.o: plain_packet.c plain_packet.h
+ $(CC) $(CCFLAGS) $< -c
+
distclean: clean
find . -name *.o -exec rm -f {} \;
find . -name "*.\~*" -exec rm -rf {} \;
diff --git a/src/plain_packet.c b/src/plain_packet.c
new file mode 100644
index 0000000..1ef05fe
--- /dev/null
+++ b/src/plain_packet.c
@@ -0,0 +1,107 @@
+/*
+ * ľAnytun
+ *
+ * ľAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
+ * featured implementation ľAnytun has no support for multiple connections
+ * or synchronisation. It is a small single threaded implementation intended
+ * to act as a client on small platforms.
+ * 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-2008 Christian Pointner <equinox@anytun.org>
+ *
+ * This file is part of ľAnytun.
+ *
+ * ľAnytun is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * ľAnytun 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 ľAnytun. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "datatypes.h"
+
+#include "plain_packet.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+void plain_packet_init(plain_packet_t* packet)
+{
+ if(!packet)
+ return;
+
+ memset (packet, 0, sizeof(*packet));
+}
+
+u_int8_t* plain_packet_get_packet(plain_packet_t* packet)
+{
+ if(!packet)
+ return NULL;
+
+ return packet->data.buf_;
+}
+
+u_int32_t plain_packet_get_length(plain_packet_t* packet)
+{
+ if(!packet)
+ return 0;
+
+ return (packet->payload_length_ + sizeof(payload_type_t));
+}
+
+u_int8_t* plain_packet_get_payload(plain_packet_t* packet)
+{
+ if(!packet)
+ return NULL;
+
+ return (packet->data.buf_ + sizeof(payload_type_t));
+}
+
+u_int32_t plain_packet_get_payload_length(plain_packet_t* packet)
+{
+ if(!packet)
+ return 0;
+
+ return packet->payload_length_;
+}
+
+void plain_packet_set_payload_length(plain_packet_t* packet, u_int32_t len)
+{
+ if(!packet)
+ return;
+
+ if(len > PLAIN_PACKET_SIZE_MAX || (len + sizeof(payload_type_t)) > PLAIN_PACKET_SIZE_MAX)
+ len = PLAIN_PACKET_SIZE_MAX - sizeof(payload_type_t);
+
+ packet->payload_length_ = len;
+}
+
+payload_type_t plain_packet_get_type(plain_packet_t* packet)
+{
+ if(!packet)
+ return 0;
+
+ return packet->data.payload_type_;
+}
+
+void plain_packet_set_type(plain_packet_t* packet, payload_type_t type)
+{
+ if(!packet)
+ return;
+
+ packet->data.payload_type_ = type;
+}
diff --git a/src/plain_packet.h b/src/plain_packet.h
new file mode 100644
index 0000000..ac1c56f
--- /dev/null
+++ b/src/plain_packet.h
@@ -0,0 +1,67 @@
+/*
+ * ľAnytun
+ *
+ * ľAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
+ * featured implementation ľAnytun has no support for multiple connections
+ * or synchronisation. It is a small single threaded implementation intended
+ * to act as a client on small platforms.
+ * 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-2008 Christian Pointner <equinox@anytun.org>
+ *
+ * This file is part of ľAnytun.
+ *
+ * ľAnytun is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * ľAnytun 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 ľAnytun. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _PLAIN_PACKET_H_
+#define _PLAIN_PACKET_H_
+
+#define PLAIN_PACKET_SIZE_MAX 1600
+
+#define PAYLOAD_TYPE_TAP 0x6558
+#define PAYLOAD_TYPE_TUN 0x0000
+#define PAYLOAD_TYPE_TUN4 0x0800
+#define PAYLOAD_TYPE_TUN6 0x86DD
+
+struct plain_packet_struct {
+ u_int32_t payload_length_;
+ union __attribute__ ((__packed__)) {
+ u_int8_t buf_[PLAIN_PACKET_SIZE_MAX];
+ payload_type_t payload_type_;
+ } data;
+};
+typedef struct plain_packet_struct plain_packet_t;
+
+void plain_packet_init(plain_packet_t* packet);
+
+u_int8_t* plain_packet_get_packet(plain_packet_t* packet);
+u_int32_t plain_packet_get_length(plain_packet_t* packet);
+
+u_int8_t* plain_packet_get_payload(plain_packet_t* packet);
+u_int32_t plain_packet_get_payload_length(plain_packet_t* packet);
+void plain_packet_set_payload_length(plain_packet_t* packet, u_int32_t len);
+
+payload_type_t plain_packet_get_type(plain_packet_t* packet);
+void plain_packet_set_type(plain_packet_t* packet, payload_type_t type);
+
+
+#endif
diff --git a/src/uanytun.c b/src/uanytun.c
index 567a103..a546287 100644
--- a/src/uanytun.c
+++ b/src/uanytun.c
@@ -43,6 +43,8 @@
#include "tun.h"
#include "udp.h"
+#include "plain_packet.h"
+
#include "daemon.h"
#include "sysexec.h"
@@ -52,9 +54,10 @@ void main_loop(tun_device_t* dev, udp_socket_t* sock)
u_int8_t buf[1600];
int len = 0;
+ udp_endpoint_t remote;
unsigned int cnt = 0;
+
while(cnt < 5) {
- udp_endpoint_t remote;
len = udp_read(sock, buf, 1600, &remote);
if(memcmp(&remote, &(sock->remote_end_), sizeof(remote))) {
@@ -71,45 +74,113 @@ void main_loop(tun_device_t* dev, udp_socket_t* sock)
}
}
+void print_hex_dump(const u_int8_t* buf, u_int32_t len)
+{
+ u_int32_t i;
+
+ for(i=0; i < len; i++) {
+ printf("%02X ", buf[i]);
+ if(!((i+1)%8))
+ printf(" ");
+ if(!((i+1)%16))
+ printf("\n");
+ }
+ printf("\n");
+}
+
int main(int argc, char* argv[])
{
log_init("uanytun", DAEMON);
signal_init();
+ plain_packet_t packet;
+ plain_packet_init(&packet);
+
+ printf("packet length: %d\n", plain_packet_get_length(&packet));
+ printf("packet: \n");
+ print_hex_dump(plain_packet_get_packet(&packet), plain_packet_get_length(&packet));
+ printf("\npayload type: 0x%04X\n", plain_packet_get_type(&packet));
+ printf("payload length: %d\n", plain_packet_get_payload_length(&packet));
+ printf("payload: \n");
+ print_hex_dump(plain_packet_get_payload(&packet), plain_packet_get_payload_length(&packet));
+ printf("\n\n");
+
+
+ plain_packet_set_payload_length(&packet, 20);
+
+
+ printf("packet length: %d\n", plain_packet_get_length(&packet));
+ printf("packet: \n");
+ print_hex_dump(plain_packet_get_packet(&packet), plain_packet_get_length(&packet));
+ printf("\npayload type: 0x%04X\n", plain_packet_get_type(&packet));
+ printf("payload length: %d\n", plain_packet_get_payload_length(&packet));
+ printf("payload: \n");
+ print_hex_dump(plain_packet_get_payload(&packet), plain_packet_get_payload_length(&packet));
+ printf("\n\n");
+
+ u_int32_t i;
+
+ for(i=0; i<plain_packet_get_payload_length(&packet); i++)
+ plain_packet_get_payload(&packet)[i] = (u_int8_t)i;
+ plain_packet_set_type(&packet, PAYLOAD_TYPE_TUN6);
+
+ printf("packet length: %d\n", plain_packet_get_length(&packet));
+ printf("packet: \n");
+ print_hex_dump(plain_packet_get_packet(&packet), plain_packet_get_length(&packet));
+ printf("\npayload type: 0x%04X\n", plain_packet_get_type(&packet));
+ printf("payload length: %d\n", plain_packet_get_payload_length(&packet));
+ printf("payload: \n");
+ print_hex_dump(plain_packet_get_payload(&packet), plain_packet_get_payload_length(&packet));
+ printf("\n\n");
+
+ plain_packet_set_payload_length(&packet, 18);
+ plain_packet_set_type(&packet, PAYLOAD_TYPE_TAP);
+
+ printf("packet length: %d\n", plain_packet_get_length(&packet));
+ printf("packet: \n");
+ print_hex_dump(plain_packet_get_packet(&packet), plain_packet_get_length(&packet));
+ printf("\npayload type: 0x%04X\n", plain_packet_get_type(&packet));
+ printf("payload length: %d\n", plain_packet_get_payload_length(&packet));
+ printf("payload: \n");
+ print_hex_dump(plain_packet_get_payload(&packet), plain_packet_get_payload_length(&packet));
+ printf("\n\n");
+
+
+
// chrootAndDrop("/var/run/", "nobody");
// daemonize();
// log_printf(INFO, "running in background now");
- tun_device_t* dev;
- tun_init(&dev, NULL, "tun", "192.168.23.1", "192.168.23.2");
- if(!dev) {
- log_printf(ERR, "error on tun_init");
- exit(-1);
- }
+/* tun_device_t* dev; */
+/* tun_init(&dev, NULL, "tun", "192.168.23.1", "192.168.23.2"); */
+/* if(!dev) { */
+/* log_printf(ERR, "error on tun_init"); */
+/* exit(-1); */
+/* } */
/* int ret = exec_script("post-up.sh", dev->actual_name_); */
/* log_printf(NOTICE, "post-up script returned %d", ret); */
- udp_socket_t* sock;
- udp_init(&sock, NULL, "4444");
- if(!sock) {
- log_printf(ERR, "error on udp_init");
- exit(-1);
- }
- char* local_string = udp_get_local_end_string(sock);
- log_printf(INFO, "listening on: %s", local_string);
- free(local_string);
-
- udp_set_remote(sock, "1.2.3.4", "4444");
- char* remote_string = udp_get_remote_end_string(sock);
- log_printf(INFO, "set remote end to: %s", remote_string);
- free(remote_string);
-
- main_loop(dev, sock);
-
- tun_close(&dev);
- udp_close(&sock);
+/* udp_socket_t* sock; */
+/* udp_init(&sock, NULL, "4444"); */
+/* if(!sock) { */
+/* log_printf(ERR, "error on udp_init"); */
+/* exit(-1); */
+/* } */
+/* char* local_string = udp_get_local_end_string(sock); */
+/* log_printf(INFO, "listening on: %s", local_string); */
+/* free(local_string); */
+
+/* udp_set_remote(sock, "1.2.3.4", "4444"); */
+/* char* remote_string = udp_get_remote_end_string(sock); */
+/* log_printf(INFO, "set remote end to: %s", remote_string); */
+/* free(remote_string); */
+
+/* main_loop(dev, sock); */
+
+/* tun_close(&dev); */
+/* udp_close(&sock); */
return 0;
}