aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/vpn/Makefile.am4
-rw-r--r--src/vpn/gnunet-helper-vpn.c124
-rw-r--r--src/vpn/gnunet-vpn-helper-p.h12
-rw-r--r--src/vpn/gnunet-vpn-tun.c39
-rw-r--r--src/vpn/gnunet-vpn-tun.h11
5 files changed, 95 insertions, 95 deletions
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am
index 9100fd900..f1b0e1df7 100644
--- a/src/vpn/Makefile.am
+++ b/src/vpn/Makefile.am
@@ -26,9 +26,7 @@ bin_PROGRAMS = \
26 26
27 27
28gnunet_helper_vpn_SOURCES = \ 28gnunet_helper_vpn_SOURCES = \
29 gnunet-helper-vpn.c \ 29 gnunet-helper-vpn.c
30 gnunet-vpn-helper-p.h \
31 gnunet-vpn-tun.h gnunet-vpn-tun.c
32 30
33gnunet_helper_hijack_dns_SOURCES = \ 31gnunet_helper_hijack_dns_SOURCES = \
34 gnunet-helper-hijack-dns.c 32 gnunet-helper-hijack-dns.c
diff --git a/src/vpn/gnunet-helper-vpn.c b/src/vpn/gnunet-helper-vpn.c
index c2ebe6c7b..25a9492eb 100644
--- a/src/vpn/gnunet-helper-vpn.c
+++ b/src/vpn/gnunet-helper-vpn.c
@@ -26,36 +26,100 @@
26 * @author Philipp Tölke 26 * @author Philipp Tölke
27 */ 27 */
28#include <platform.h> 28#include <platform.h>
29#include <linux/if_tun.h>
29 30
30#include "gnunet-vpn-tun.h" 31/**
32 * Need 'struct GNUNET_MessageHeader'.
33 */
31#include "gnunet_common.h" 34#include "gnunet_common.h"
32#include "gnunet_protocols.h"
33#include "gnunet-vpn-helper-p.h"
34 35
35#ifndef _LINUX_IN6_H 36/**
37 * Need VPN message types.
38 */
39#include "gnunet_protocols.h"
36 40
37#define MAX_SIZE (65535 - sizeof(struct GNUNET_MessageHeader)) 41/**
42 * Maximum size of a GNUnet message (GNUNET_SERVER_MAX_MESSAGE_SIZE)
43 */
44#define MAX_SIZE 65536
38 45
39// This is in linux/include/net/ipv6.h. 46#ifndef _LINUX_IN6_H
40struct in6_ifreq 47/**
48 * This is in linux/include/net/ipv6.h, but not always exported...
49 */
50struct in6_ifreq
41{ 51{
42 struct in6_addr ifr6_addr; 52 struct in6_addr ifr6_addr;
43 uint32_t ifr6_prefixlen; 53 uint32_t ifr6_prefixlen;
44 unsigned int ifr6_ifindex; 54 unsigned int ifr6_ifindex;
45}; 55};
46
47#endif 56#endif
48 57
58
59struct suid_packet
60{
61 struct GNUNET_MessageHeader hdr;
62 unsigned char data[1];
63}
64
49static int running = 1; 65static int running = 1;
50 66
51static void 67static void
52term (int sig) 68term (int sig)
53{ 69{
54 fprintf (stderr, "Got SIGTERM...\n"); 70 fprintf (stderr,
71 "Got SIGTERM...\n");
55 if (sig == SIGTERM) 72 if (sig == SIGTERM)
56 running = 0; 73 running = 0;
57} 74}
58 75
76
77/**
78 * Creates a tun-interface called dev;
79 * @param dev is asumed to point to a char[IFNAMSIZ]
80 * if *dev == '\0', uses the name supplied by the kernel
81 * @return the fd to the tun or -1 on error
82 */
83static int
84init_tun (char *dev)
85{
86 struct ifreq ifr;
87 int fd;
88
89 if (NULL == dev)
90 {
91 errno = EINVAL;
92 return -1;
93 }
94
95 if (-1 == (fd = open("/dev/net/tun", O_RDWR)))
96 {
97 fprintf (stderr,
98 "Error opening `%s': %s\n",
99 "/dev/net/tun",
100 strerror(errno));
101 return -1;
102 }
103
104 memset(&ifr, 0, sizeof(ifr));
105 ifr.ifr_flags = IFF_TUN;
106
107 if ('\0' == *dev)
108 strncpy(ifr.ifr_name, dev, IFNAMSIZ);
109
110 if (-1 == ioctl(fd, TUNSETIFF, (void *) &ifr))
111 {
112 fprintf (stderr,
113 "Error with ioctl on `%s': %s\n",
114 "/dev/net/tun",
115 strerror(errno));
116 close(fd);
117 return -1;
118 }
119 strcpy(dev, ifr.ifr_name);
120 return fd;
121}
122
59/** 123/**
60 * @brief Sets the IPv6-Address given in address on the interface dev 124 * @brief Sets the IPv6-Address given in address on the interface dev
61 * 125 *
@@ -65,7 +129,7 @@ term (int sig)
65 */ 129 */
66static void 130static void
67set_address6 (char *dev, char *address, unsigned long prefix_len) 131set_address6 (char *dev, char *address, unsigned long prefix_len)
68{ /* {{{ */ 132{
69 int fd = socket (AF_INET6, SOCK_DGRAM, 0); 133 int fd = socket (AF_INET6, SOCK_DGRAM, 0);
70 134
71 if (fd < 0) 135 if (fd < 0)
@@ -111,9 +175,9 @@ set_address6 (char *dev, char *address, unsigned long prefix_len)
111 ifr.ifr_flags |= IFF_UP | IFF_RUNNING; 175 ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
112 (void) ioctl (fd, SIOCSIFFLAGS, &ifr); 176 (void) ioctl (fd, SIOCSIFFLAGS, &ifr);
113 close (fd); 177 close (fd);
114} /* }}} */ 178}
179
115 180
116static void
117/** 181/**
118 * @brief Sets the IPv4-Address given in address on the interface dev 182 * @brief Sets the IPv4-Address given in address on the interface dev
119 * 183 *
@@ -121,8 +185,9 @@ static void
121 * @param address the IPv4-Address 185 * @param address the IPv4-Address
122 * @param mask the netmask 186 * @param mask the netmask
123 */ 187 */
188static void
124set_address4 (char *dev, char *address, char *mask) 189set_address4 (char *dev, char *address, char *mask)
125{ /* {{{ */ 190{
126 int fd = 0; 191 int fd = 0;
127 struct sockaddr_in *addr; 192 struct sockaddr_in *addr;
128 struct ifreq ifr; 193 struct ifreq ifr;
@@ -175,7 +240,8 @@ set_address4 (char *dev, char *address, char *mask)
175 ifr.ifr_flags |= IFF_UP | IFF_RUNNING; 240 ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
176 (void) ioctl (fd, SIOCSIFFLAGS, &ifr); 241 (void) ioctl (fd, SIOCSIFFLAGS, &ifr);
177 close (fd); 242 close (fd);
178} /* }}} */ 243}
244
179 245
180/** 246/**
181 * @brief sets the socket to nonblocking 247 * @brief sets the socket to nonblocking
@@ -186,22 +252,20 @@ static void
186setnonblocking (int fd) 252setnonblocking (int fd)
187{ /*{{{ */ 253{ /*{{{ */
188 int opts; 254 int opts;
255 opts = fcntl(fd,F_GETFL);
256 if (opts < 0) {
257 perror("fcntl(F_GETFL)");
258 }
259 opts = (opts | O_NONBLOCK);
260 if (fcntl(fd,F_SETFL,opts) < 0) {
261 perror("fcntl(F_SETFL)");
262 }
263 return;
264}
189 265
190 opts = fcntl (fd, F_GETFL);
191 if (opts < 0)
192 {
193 perror ("fcntl(F_GETFL)");
194 }
195 opts = (opts | O_NONBLOCK);
196 if (fcntl (fd, F_SETFL, opts) < 0)
197 {
198 perror ("fcntl(F_SETFL)");
199 }
200 return;
201} /*}}} */
202 266
203int 267int
204main (int argc, char **argv) 268main(int argc, char** argv)
205{ 269{
206 unsigned char buf[MAX_SIZE]; 270 unsigned char buf[MAX_SIZE];
207 271
diff --git a/src/vpn/gnunet-vpn-helper-p.h b/src/vpn/gnunet-vpn-helper-p.h
deleted file mode 100644
index fa3546123..000000000
--- a/src/vpn/gnunet-vpn-helper-p.h
+++ /dev/null
@@ -1,12 +0,0 @@
1#ifndef GN_VPN_HELPER_P_H
2#define GN_VPN_HELPER_P_H
3
4#include "platform.h"
5#include "gnunet_common.h"
6
7struct suid_packet {
8 struct GNUNET_MessageHeader hdr;
9 unsigned char data[1];
10};
11
12#endif
diff --git a/src/vpn/gnunet-vpn-tun.c b/src/vpn/gnunet-vpn-tun.c
deleted file mode 100644
index 07def09c7..000000000
--- a/src/vpn/gnunet-vpn-tun.c
+++ /dev/null
@@ -1,39 +0,0 @@
1#include "platform.h"
2#include <linux/if_tun.h>
3
4/**
5 * Creates a tun-interface called dev;
6 * dev is asumed to point to a char[IFNAMSIZ]
7 * if *dev == 0, uses the name supplied by the kernel
8 * returns the fd to the tun or -1
9 */
10int init_tun(char *dev) {{{
11 if (!dev) {
12 errno = EINVAL;
13 return -1;
14 }
15
16 struct ifreq ifr;
17 int fd, err;
18
19 if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) {
20 fprintf(stderr, "opening /dev/net/tun: %s\n", strerror(errno));
21 return -1;
22 }
23
24 memset(&ifr, 0, sizeof(ifr));
25
26 ifr.ifr_flags = IFF_TUN;
27
28 if (*dev)
29 strncpy(ifr.ifr_name, dev, IFNAMSIZ);
30
31 if ((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){
32 close(fd);
33 fprintf(stderr, "ioctl'ing /dev/net/tun: %s\n", strerror(errno));
34 return err;
35 }
36
37 strcpy(dev, ifr.ifr_name);
38 return fd;
39}}}
diff --git a/src/vpn/gnunet-vpn-tun.h b/src/vpn/gnunet-vpn-tun.h
deleted file mode 100644
index 3ba61771a..000000000
--- a/src/vpn/gnunet-vpn-tun.h
+++ /dev/null
@@ -1,11 +0,0 @@
1#ifndef _GNTUN_TUN_H_
2#define _GNTUN_TUN_H_
3
4/**
5 * Creates a tun-interface called dev;
6 * if *dev == 0, uses the name supplied by the kernel
7 * returns the fd to the tun or -1
8 */
9int init_tun(char *dev);
10
11#endif