summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2008-12-29 07:15:24 +0000
committerChristian Pointner <equinox@anytun.org>2008-12-29 07:15:24 +0000
commit2cfb754f6abf441cbcf4e639cd26c060b3e4cc95 (patch)
tree3f35835b3c1667ddf395f3a67b0e0123f92ddeae
parentimproved signal handling (diff)
fixed build for OpenBSD (no tun device yet)
-rw-r--r--src/Makefile2
-rw-r--r--src/bsd/tun.c157
-rw-r--r--src/datatypes.h8
-rw-r--r--src/plain_packet.c2
-rw-r--r--src/udp.c1
-rw-r--r--src/udp.h1
6 files changed, 166 insertions, 5 deletions
diff --git a/src/Makefile b/src/Makefile
index ca86085..6a5280f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -36,7 +36,7 @@ TARGET=$(shell uname -s)
CC = gcc
CCFLAGS = -g -O2
LD = gcc
-LDFLAGS = -g -Wall -O2 -lgcrypt -lgpg-error
+LDFLAGS = -g -Wall -O2 #-lgcrypt -lgpg-error
ifeq ($(TARGET),Linux)
LDFLAGS += -ldl
diff --git a/src/bsd/tun.c b/src/bsd/tun.c
new file mode 100644
index 0000000..b34c50d
--- /dev/null
+++ b/src/bsd/tun.c
@@ -0,0 +1,157 @@
+/*
+ * ľ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 "tun.h"
+
+#include "tun_helper.h"
+
+#include "log.h"
+
+void tun_init(tun_device_t** dev, const char* dev_name, const char* dev_type, const char* ifcfg_lp, const char* ifcfg_rnmp)
+{
+ if(!dev)
+ return;
+
+ *dev = malloc(sizeof(tun_device_t));
+ if(!*dev)
+ return;
+
+ tun_conf(*dev, dev_name, dev_type, ifcfg_lp, ifcfg_rnmp, 1400);
+
+
+ if(ifcfg_lp && ifcfg_rnmp)
+ tun_do_ifconfig(*dev);
+}
+
+void tun_init_post(tun_device_t* dev)
+{
+// nothing yet
+}
+
+void tun_close(tun_device_t** dev)
+{
+ if(!dev || !(*dev))
+ return;
+
+ if((*dev)->fd_ > 0)
+ close((*dev)->fd_);
+
+ if((*dev)->actual_name_)
+ free((*dev)->actual_name_);
+
+ if((*dev)->local_)
+ free((*dev)->local_);
+
+ if((*dev)->remote_netmask_)
+ free((*dev)->remote_netmask_);
+
+ free(*dev);
+ *dev = NULL;
+}
+
+int tun_read(tun_device_t* dev, u_int8_t* buf, u_int32_t len)
+{
+/* if(!dev || dev->fd_ < 0) */
+/* return -1; */
+
+/* if(dev->with_pi_) */
+/* { */
+/* struct iovec iov[2]; */
+/* struct tun_pi tpi; */
+
+/* iov[0].iov_base = &tpi; */
+/* iov[0].iov_len = sizeof(tpi); */
+/* iov[1].iov_base = buf; */
+/* iov[1].iov_len = len; */
+/* return(tun_fix_return(readv(dev->fd_, iov, 2), sizeof(tpi))); */
+/* } */
+/* else */
+/* return(read(dev->fd_, buf, len)); */
+ return -1;
+}
+
+int tun_write(tun_device_t* dev, u_int8_t* buf, u_int32_t len)
+{
+/* if(!dev || dev->fd_ < 0) */
+/* return -1; */
+
+/* if(dev->with_pi_) */
+/* { */
+/* struct iovec iov[2]; */
+/* struct tun_pi tpi; */
+/* struct iphdr *hdr = (struct iphdr *)buf; */
+
+/* tpi.flags = 0; */
+/* if(hdr->version == 4) */
+/* tpi.proto = htons(ETH_P_IP); */
+/* else */
+/* tpi.proto = htons(ETH_P_IPV6); */
+
+/* iov[0].iov_base = &tpi; */
+/* iov[0].iov_len = sizeof(tpi); */
+/* iov[1].iov_base = buf; */
+/* iov[1].iov_len = len; */
+/* return(tun_fix_return(writev(dev->fd_, iov, 2), sizeof(tpi))); */
+/* } */
+/* else */
+/* return(write(dev->fd_, buf, len)); */
+ return -1;
+}
+
+void tun_do_ifconfig(tun_device_t* dev)
+{
+/* if(!dev || !dev->actual_name_ || !dev->local_ || !dev->remote_netmask_) */
+/* return; */
+
+/* char* command = NULL; */
+/* if(dev->type_ == TYPE_TUN) */
+/* asprintf(&command, "/sbin/ifconfig %s %s pointopoint %s mtu %d", dev->actual_name_, dev->local_, dev->remote_netmask_, dev->mtu_); */
+/* else */
+/* asprintf(&command, "/sbin/ifconfig %s %s netmask %s mtu %d", dev->actual_name_, dev->local_, dev->remote_netmask_, dev->mtu_); */
+
+/* if(!command) { */
+/* log_printf(ERR, "Execution of ifconfig failed"); */
+/* return; */
+/* } */
+
+/* int result = system(command); */
+/* if(result == -1) */
+/* log_printf(ERR, "Execution of ifconfig failed"); */
+/* else */
+/* log_printf(NOTICE, "ifconfig returned %d", WEXITSTATUS(result)); */
+
+/* free(command); */
+}
diff --git a/src/datatypes.h b/src/datatypes.h
index df3de45..6d22d59 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -41,10 +41,10 @@ typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
typedef uint64_t u_int64_t;
-typedef int8_t int8_t;
-typedef int16_t int16_t;
-typedef int32_t int32_t;
-typedef int64_t int64_t;
+// typedef int8_t int8_t;
+// typedef int16_t int16_t;
+// typedef int32_t int32_t;
+// typedef int64_t int64_t;
typedef u_int32_t window_size_t;
diff --git a/src/plain_packet.c b/src/plain_packet.c
index d11a710..6eca0af 100644
--- a/src/plain_packet.c
+++ b/src/plain_packet.c
@@ -38,6 +38,8 @@
#include <stdlib.h>
#include <string.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
#include <netinet/ip.h>
void plain_packet_init(plain_packet_t* packet)
diff --git a/src/udp.c b/src/udp.c
index 493d772..6ae7066 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -41,6 +41,7 @@
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
+#include <netinet/in.h>
void udp_init(udp_socket_t** sock, const char* local_addr, const char* port)
{
diff --git a/src/udp.h b/src/udp.h
index e7d4875..4873483 100644
--- a/src/udp.h
+++ b/src/udp.h
@@ -35,6 +35,7 @@
#ifndef _UDP_H_
#define _UDP_H_
+#include <sys/types.h>
#include <sys/socket.h>
typedef struct sockaddr_storage udp_endpoint_t;