aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2010-07-20 19:53:46 +0000
committerPhilipp Tölke <toelke@in.tum.de>2010-07-20 19:53:46 +0000
commit588e30f786318fc9df2ce6655e2e75b49d861b87 (patch)
tree26621721288a5f515b33b2f82e56d5299e264bcf /src/vpn
parentfb5687d53b36893140f420b448c2587d6e1a621b (diff)
downloadgnunet-588e30f786318fc9df2ce6655e2e75b49d861b87.tar.gz
gnunet-588e30f786318fc9df2ce6655e2e75b49d861b87.zip
remove unsused files
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/debug.c13
-rw-r--r--src/vpn/debug.h7
-rw-r--r--src/vpn/tcp.c146
-rw-r--r--src/vpn/tcp.h8
-rw-r--r--src/vpn/test.c53
-rw-r--r--src/vpn/udp.c22
-rw-r--r--src/vpn/udp.h8
7 files changed, 0 insertions, 257 deletions
diff --git a/src/vpn/debug.c b/src/vpn/debug.c
deleted file mode 100644
index 900a4bd00..000000000
--- a/src/vpn/debug.c
+++ /dev/null
@@ -1,13 +0,0 @@
1#include <stdio.h>
2#include <stdarg.h>
3#include <stdlib.h>
4
5#include "debug.h"
6
7void debug(int lvl, int es, char* msg, ...) {
8 va_list ap;
9 va_start(ap, msg);
10 vprintf(msg, ap);
11 va_end(ap);
12 if (es != 0) exit(es);
13}
diff --git a/src/vpn/debug.h b/src/vpn/debug.h
deleted file mode 100644
index 8f3e71813..000000000
--- a/src/vpn/debug.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#ifndef _GNTUN_DEBUG_H_
2#define _GNTUN_DEBUG_H_
3
4/* exits with status exit if != 0; */
5extern void debug(int lvl, int exit, char* msg, ...);
6
7#endif
diff --git a/src/vpn/tcp.c b/src/vpn/tcp.c
deleted file mode 100644
index cd40f280a..000000000
--- a/src/vpn/tcp.c
+++ /dev/null
@@ -1,146 +0,0 @@
1#include "debug.h"
2#include "packet.h"
3#include "tcp.h"
4
5#include <errno.h>
6#include <netinet/in.h>
7#include <netinet/ip.h>
8#include <signal.h>
9#include <stdlib.h>
10#include <arpa/inet.h>
11#include <string.h>
12#include <sys/socket.h>
13#include <sys/types.h>
14#include <unistd.h>
15
16struct le {
17 int spt, dpt;
18
19 unsigned char sadr[16];
20 unsigned char dadr[16];
21
22 int socket;
23
24 struct le* next;
25};
26
27static struct le* le_head = 0;
28
29static int look_for_child(struct ip6_tcp* pkt) {
30 struct le* cur;
31
32 for(cur = le_head; cur != 0; cur = cur->next) {
33 if (cur->spt == pkt->data.spt &&/*{{{*/
34 cur->dpt == pkt->data.spt &&
35 cur->sadr[0] == pkt->hdr.sadr[0] &&
36 cur->sadr[1] == pkt->hdr.sadr[1] &&
37 cur->sadr[2] == pkt->hdr.sadr[2] &&
38 cur->sadr[3] == pkt->hdr.sadr[3] &&
39 cur->sadr[4] == pkt->hdr.sadr[4] &&
40 cur->sadr[5] == pkt->hdr.sadr[5] &&
41 cur->sadr[6] == pkt->hdr.sadr[6] &&
42 cur->sadr[7] == pkt->hdr.sadr[7] &&
43 cur->sadr[8] == pkt->hdr.sadr[8] &&
44 cur->sadr[9] == pkt->hdr.sadr[9] &&
45 cur->sadr[10] == pkt->hdr.sadr[10] &&
46 cur->sadr[11] == pkt->hdr.sadr[11] &&
47 cur->sadr[12] == pkt->hdr.sadr[12] &&
48 cur->sadr[13] == pkt->hdr.sadr[13] &&
49 cur->sadr[14] == pkt->hdr.sadr[14] &&
50 cur->sadr[15] == pkt->hdr.sadr[15] &&
51
52 cur->dadr[0] == pkt->hdr.dadr[0] &&
53 cur->dadr[1] == pkt->hdr.dadr[1] &&
54 cur->dadr[2] == pkt->hdr.dadr[2] &&
55 cur->dadr[3] == pkt->hdr.dadr[3] &&
56 cur->dadr[4] == pkt->hdr.dadr[4] &&
57 cur->dadr[5] == pkt->hdr.dadr[5] &&
58 cur->dadr[6] == pkt->hdr.dadr[6] &&
59 cur->dadr[7] == pkt->hdr.dadr[7] &&
60 cur->dadr[8] == pkt->hdr.dadr[8] &&
61 cur->dadr[9] == pkt->hdr.dadr[9] &&
62 cur->dadr[10] == pkt->hdr.dadr[10] &&
63 cur->dadr[11] == pkt->hdr.dadr[11] &&
64 cur->dadr[12] == pkt->hdr.dadr[12] &&
65 cur->dadr[13] == pkt->hdr.dadr[13] &&
66 cur->dadr[14] == pkt->hdr.dadr[14] &&
67 cur->dadr[15] == pkt->hdr.dadr[15])/*}}}*/
68 return cur->socket;
69 }
70 return -1;
71}
72
73static struct le* new_le() {{{
74 struct le* res = (struct le*) malloc(sizeof(struct le));
75
76 struct le** cur;
77
78 for(cur = &le_head; *cur != 0; cur = &((*cur)->next)) {}
79
80 *cur = res;
81
82 return res;
83}}}
84
85static int nat(struct ip6_tcp* pkt) {{{
86 unsigned char adr1[] = { 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
87 unsigned char adr2[] = { 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03};
88
89 if (strncmp((char*)adr1, (char*)pkt->hdr.dadr, 16)) {
90 int sock = socket(AF_INET, SOCK_STREAM, 0);
91 struct sockaddr_in info;
92 memset(&info, 0, sizeof(info));
93
94 info.sin_family = AF_INET;
95 info.sin_port = pkt->data.dpt;
96 inet_pton(AF_INET, "94.142.241.111", &info.sin_addr.s_addr);
97
98 connect(sock, (const struct sockaddr*)&info, sizeof(info));
99 return sock;
100 } else if (strncmp((char*)adr2, (char*)pkt->hdr.dadr, 16)) {
101 int sock = socket(AF_INET6, SOCK_STREAM, 0);
102
103 struct sockaddr_in6 info;
104 memset(&info, 0, sizeof(info));
105
106 info.sin6_family = AF_INET6;
107 info.sin6_port = pkt->data.dpt;
108
109 inet_pton(AF_INET6, "2a02:898:17:8000::42", info.sin6_addr.s6_addr);
110
111 connect(sock, (const struct sockaddr*)&info, sizeof(info));
112
113 return sock;
114 }
115 return -1;
116}}}
117
118void handle_tcp(struct ip6_tcp* pkt) {
119 signal(SIGCHLD, SIG_IGN);
120
121 int fd = look_for_child(pkt);
122
123 if (fd == -1) {
124 struct le* le = new_le();
125 le->spt = pkt->data.spt;
126 le->dpt = pkt->data.dpt;
127
128 memcpy(le->sadr, pkt->hdr.sadr, 16);
129 memcpy(le->dadr, pkt->hdr.dadr, 16);
130
131 le->socket = nat(pkt);
132 fd = le->socket;
133 }
134
135 int size = payload((&pkt->hdr)) - pkt->data.off;
136
137 int w = 0;
138 while (size > 0) {
139 w = write(fd, pkt->data.data, size - w);
140 if (w < 0) {
141 debug(1, 0, "writing: %s\n", strerror(errno));
142 } else {
143 size -= w;
144 }
145 }
146}
diff --git a/src/vpn/tcp.h b/src/vpn/tcp.h
deleted file mode 100644
index c933b1b4c..000000000
--- a/src/vpn/tcp.h
+++ /dev/null
@@ -1,8 +0,0 @@
1#ifndef _GNTUN_TCP_H_
2#define _GNTUN_TCP_H_
3
4#include "packet.h"
5
6extern void handle_tcp(struct ip6_tcp*);
7
8#endif
diff --git a/src/vpn/test.c b/src/vpn/test.c
deleted file mode 100644
index b24397c71..000000000
--- a/src/vpn/test.c
+++ /dev/null
@@ -1,53 +0,0 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <sys/socket.h>
4#include <string.h>
5
6#include <linux/if.h>
7
8#include "packet.h"
9#include "tun.h"
10#include "debug.h"
11#include "pretty-print.h"
12#include "tcp.h"
13#include "udp.h"
14#include <arpa/inet.h>
15
16
17int main(int c, char** v) {
18 char dev[IFNAMSIZ];
19 memset(dev, 0, IFNAMSIZ);
20 int fd = init_tun(dev);
21
22 debug(1, 0, "Initialized the interface %s.\n", dev);
23
24 struct pkt_tun* pkt;
25
26 for(;;) {
27 printf("read %d bytes from socket, ", recv_pkt(fd, &pkt));
28 switch (ntohs(pkt->type)) {
29 case 0x86dd:
30 printf("parsing ipv6:\n");
31 struct ip6_pkt* pkt6 = parse_ip6(pkt);
32 pkt_printf(pkt6);
33 struct ip6_tcp* pkt6_tcp;
34 struct ip6_udp* pkt6_udp;
35 switch(pkt6->hdr.nxthdr) {
36 case 0x06:
37 pkt6_tcp = parse_ip6_tcp(pkt6);
38 pkt_printf_ip6tcp(pkt6_tcp);
39 handle_tcp(pkt6_tcp);
40 break;
41 case 0x11:
42 pkt6_udp = parse_ip6_udp(pkt6);
43 pkt_printf_ip6udp(pkt6_udp);
44 handle_udp(pkt6_udp);
45 break;
46 }
47 break;
48 default:
49 printf("unknown/unimplemented packet-type\n");
50 break;
51 }
52 }
53}
diff --git a/src/vpn/udp.c b/src/vpn/udp.c
deleted file mode 100644
index 4a7cb94ed..000000000
--- a/src/vpn/udp.c
+++ /dev/null
@@ -1,22 +0,0 @@
1#include "debug.h"
2#include "packet.h"
3#include "udp.h"
4
5#include "pretty-print.h"
6
7#include <errno.h>
8#include <netinet/in.h>
9#include <netinet/ip.h>
10#include <stdlib.h>
11#include <arpa/inet.h>
12#include <string.h>
13#include <sys/socket.h>
14#include <sys/types.h>
15#include <unistd.h>
16
17void handle_udp(struct ip6_udp* pkt) {
18 if (ntohs(pkt->data.dpt) == 53) { //TODO check for dadr, too
19 pkt_printf_ip6dns((struct ip6_udp_dns*)pkt);
20 return;
21 }
22}
diff --git a/src/vpn/udp.h b/src/vpn/udp.h
deleted file mode 100644
index ab285d6c8..000000000
--- a/src/vpn/udp.h
+++ /dev/null
@@ -1,8 +0,0 @@
1#ifndef _GNTUN_UDP_H_
2#define _GNTUN_UDP_H_
3
4#include "packet.h"
5
6extern void handle_udp(struct ip6_udp*);
7
8#endif