aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2010-07-20 22:21:59 +0000
committerPhilipp Tölke <toelke@in.tum.de>2010-07-20 22:21:59 +0000
commit329e01c484e59ef1308c39bbd99b341d4ff60b21 (patch)
tree806f469ee6044953130379bca1cfa9e20af63b09 /src/vpn
parent7a77cfe5da48dacd3ceb27ee0f8dfc86dc3ce0d6 (diff)
downloadgnunet-329e01c484e59ef1308c39bbd99b341d4ff60b21.tar.gz
gnunet-329e01c484e59ef1308c39bbd99b341d4ff60b21.zip
Changed the communication between the vpn-helper and the daemon to use GNUNET_MessageHeaders
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-daemon-vpn.c16
-rw-r--r--src/vpn/gnunet-vpn-helper-p.h6
-rw-r--r--src/vpn/gnunet-vpn-helper.c26
-rw-r--r--src/vpn/gnunet-vpn-packet.h9
4 files changed, 30 insertions, 27 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c
index 4f1cd9f60..9f8ffb683 100644
--- a/src/vpn/gnunet-daemon-vpn.c
+++ b/src/vpn/gnunet-daemon-vpn.c
@@ -30,6 +30,8 @@
30#include "gnunet-vpn-helper-p.h" 30#include "gnunet-vpn-helper-p.h"
31#include "gnunet-vpn-packet.h" 31#include "gnunet-vpn-packet.h"
32#include "gnunet-vpn-pretty-print.h" 32#include "gnunet-vpn-pretty-print.h"
33#include "gnunet_common.h"
34#include "gnunet_protocols.h"
33/* #include "gnunet_template_service.h" */ 35/* #include "gnunet_template_service.h" */
34 36
35/** 37/**
@@ -86,15 +88,15 @@ static void restart_helper(void* cls, const struct GNUNET_SCHEDULER_TaskContext*
86 88
87static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) { 89static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) {
88 struct vpn_cls* mycls = (struct vpn_cls*) cls; 90 struct vpn_cls* mycls = (struct vpn_cls*) cls;
89 struct suid_packet_header hdr = { .size = 0 }; 91 struct GNUNET_MessageHeader hdr = { .size = 0, .type = 0 };
90 92
91 int r = 0; 93 int r = 0;
92 94
93 if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) 95 if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)
94 return; 96 return;
95 97
96 while (r < sizeof(struct suid_packet_header)) { 98 while (r < sizeof(struct GNUNET_MessageHeader)) {
97 int t = GNUNET_DISK_file_read(mycls->fh_from_helper, &hdr, sizeof(struct suid_packet_header)); 99 int t = GNUNET_DISK_file_read(mycls->fh_from_helper, &hdr, sizeof(struct GNUNET_MessageHeader));
98 if (t<=0) { 100 if (t<=0) {
99 fprintf(stderr, "Read error for header: %m\n"); 101 fprintf(stderr, "Read error for header: %m\n");
100 GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, cls); 102 GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, cls);
@@ -103,12 +105,12 @@ static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* ts
103 r += t; 105 r += t;
104 } 106 }
105 107
106 struct suid_packet *pkt = (struct suid_packet*) GNUNET_malloc(ntohl(hdr.size)); 108 struct suid_packet *pkt = (struct suid_packet*) GNUNET_malloc(ntohs(hdr.size));
107 109
108 memcpy(pkt, &hdr, sizeof(struct suid_packet_header)); 110 memcpy(pkt, &hdr, sizeof(struct GNUNET_MessageHeader));
109 111
110 while (r < ntohl(pkt->hdr.size)) { 112 while (r < ntohs(pkt->hdr.size)) {
111 int t = GNUNET_DISK_file_read(mycls->fh_from_helper, (unsigned char*)pkt + r, ntohl(pkt->hdr.size) - r); 113 int t = GNUNET_DISK_file_read(mycls->fh_from_helper, (unsigned char*)pkt + r, ntohs(pkt->hdr.size) - r);
112 if (t<=0) { 114 if (t<=0) {
113 fprintf(stderr, "Read error for data: %m\n"); 115 fprintf(stderr, "Read error for data: %m\n");
114 GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, cls); 116 GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, cls);
diff --git a/src/vpn/gnunet-vpn-helper-p.h b/src/vpn/gnunet-vpn-helper-p.h
index 664c40389..d48755df3 100644
--- a/src/vpn/gnunet-vpn-helper-p.h
+++ b/src/vpn/gnunet-vpn-helper-p.h
@@ -1,12 +1,10 @@
1#ifndef GN_VPN_HELPER_P_H 1#ifndef GN_VPN_HELPER_P_H
2#define GN_VPN_HELPER_P_H 2#define GN_VPN_HELPER_P_H
3 3
4struct suid_packet_header { 4#include "gnunet_common.h"
5 uint32_t size;
6};
7 5
8struct suid_packet { 6struct suid_packet {
9 struct suid_packet_header hdr; 7 struct GNUNET_MessageHeader hdr;
10 unsigned char data[1]; 8 unsigned char data[1];
11}; 9};
12 10
diff --git a/src/vpn/gnunet-vpn-helper.c b/src/vpn/gnunet-vpn-helper.c
index 92af307dd..1d0b1ad28 100644
--- a/src/vpn/gnunet-vpn-helper.c
+++ b/src/vpn/gnunet-vpn-helper.c
@@ -40,8 +40,10 @@
40#include <stdio.h> 40#include <stdio.h>
41#include <unistd.h> 41#include <unistd.h>
42 42
43#include "gnunet-vpn-helper-p.h"
44#include "gnunet-vpn-tun.h" 43#include "gnunet-vpn-tun.h"
44#include "gnunet_common.h"
45#include "gnunet_protocols.h"
46#include "gnunet-vpn-helper-p.h"
45 47
46#ifndef _LINUX_IN6_H 48#ifndef _LINUX_IN6_H
47// This is in linux/include/net/ipv6.h. 49// This is in linux/include/net/ipv6.h.
@@ -168,7 +170,7 @@ outer:
168 if (FD_ISSET(0, &fds_r) && write_fd_possible) { 170 if (FD_ISSET(0, &fds_r) && write_fd_possible) {
169 write_fd_possible = 0; 171 write_fd_possible = 0;
170 struct suid_packet *pkt = (struct suid_packet*) buf; 172 struct suid_packet *pkt = (struct suid_packet*) buf;
171 r = read(0, buf, sizeof(struct suid_packet_header)); 173 r = read(0, buf, sizeof(struct GNUNET_MessageHeader));
172 if (r <= 0) { 174 if (r <= 0) {
173 fprintf(stderr, "read-error: %m\n"); 175 fprintf(stderr, "read-error: %m\n");
174 shutdown(fd_tun, SHUT_WR); 176 shutdown(fd_tun, SHUT_WR);
@@ -176,8 +178,8 @@ outer:
176 wri=0; 178 wri=0;
177 goto outer; 179 goto outer;
178 } 180 }
179 while (r < ntohl(pkt->hdr.size)) { 181 while (r < ntohs(pkt->hdr.size)) {
180 int t = read(0, buf + r, ntohl(pkt->hdr.size) - r); 182 int t = read(0, buf + r, ntohs(pkt->hdr.size) - r);
181 if (r < 0) { 183 if (r < 0) {
182 fprintf(stderr, "read-error: %m\n"); 184 fprintf(stderr, "read-error: %m\n");
183 shutdown(fd_tun, SHUT_WR); 185 shutdown(fd_tun, SHUT_WR);
@@ -188,8 +190,8 @@ outer:
188 r += t; 190 r += t;
189 } 191 }
190 r = 0; 192 r = 0;
191 while (r < ntohl(pkt->hdr.size) - sizeof(struct suid_packet_header)) { 193 while (r < ntohs(pkt->hdr.size) - sizeof(struct GNUNET_MessageHeader)) {
192 int t = write(fd_tun, pkt->data, ntohl(pkt->hdr.size) - sizeof(struct suid_packet_header) - r); 194 int t = write(fd_tun, pkt->data, ntohs(pkt->hdr.size) - sizeof(struct GNUNET_MessageHeader) - r);
193 if (t < 0) { 195 if (t < 0) {
194 fprintf(stderr, "write-error 3: %m\n"); 196 fprintf(stderr, "write-error 3: %m\n");
195 shutdown(fd_tun, SHUT_WR); 197 shutdown(fd_tun, SHUT_WR);
@@ -209,10 +211,10 @@ outer:
209 rea = 0; 211 rea = 0;
210 goto outer; 212 goto outer;
211 } 213 }
212 struct suid_packet_header hdr = { .size = htonl(r + sizeof(struct suid_packet_header))}; 214 struct GNUNET_MessageHeader hdr = { .size = htons(r + sizeof(struct GNUNET_MessageHeader)), .type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER) };
213 r = 0; 215 r = 0;
214 while(r < sizeof(struct suid_packet_header)) { 216 while(r < sizeof(struct GNUNET_MessageHeader)) {
215 int t = write(1, &hdr, sizeof(struct suid_packet_header) - r); 217 int t = write(1, &hdr, sizeof(struct GNUNET_MessageHeader) - r);
216 if (t < 0) { 218 if (t < 0) {
217 fprintf(stderr, "write-error 2: %m\n"); 219 fprintf(stderr, "write-error 2: %m\n");
218 shutdown(fd_tun, SHUT_RD); 220 shutdown(fd_tun, SHUT_RD);
@@ -222,10 +224,10 @@ outer:
222 } 224 }
223 r += t; 225 r += t;
224 } 226 }
225 while(r < ntohl(hdr.size)) { 227 while(r < ntohs(hdr.size)) {
226 int t = write(1, buf, ntohl(hdr.size) - r); 228 int t = write(1, buf, ntohs(hdr.size) - r);
227 if (t < 0) { 229 if (t < 0) {
228 fprintf(stderr, "write-error 1: %m, written %d/%d\n", r, ntohl(hdr.size)); 230 fprintf(stderr, "write-error 1: %m, written %d/%d\n", r, ntohs(hdr.size));
229 shutdown(fd_tun, SHUT_RD); 231 shutdown(fd_tun, SHUT_RD);
230 shutdown(1, SHUT_WR); 232 shutdown(1, SHUT_WR);
231 rea = 0; 233 rea = 0;
diff --git a/src/vpn/gnunet-vpn-packet.h b/src/vpn/gnunet-vpn-packet.h
index 89b75ba35..4ba6f2528 100644
--- a/src/vpn/gnunet-vpn-packet.h
+++ b/src/vpn/gnunet-vpn-packet.h
@@ -2,6 +2,7 @@
2#define _GNTUN_PACKET_H_ 2#define _GNTUN_PACKET_H_
3 3
4#include "gnunet-vpn-helper-p.h" 4#include "gnunet-vpn-helper-p.h"
5#include "gnunet_common.h"
5 6
6// Headers 7// Headers
7struct pkt_tun { 8struct pkt_tun {
@@ -83,14 +84,14 @@ struct dns_record {
83 84
84// Complete Packets 85// Complete Packets
85struct ip6_pkt { 86struct ip6_pkt {
86 struct suid_packet_header shdr; 87 struct GNUNET_MessageHeader shdr;
87 struct pkt_tun tun; 88 struct pkt_tun tun;
88 struct ip6_hdr ip6_hdr; 89 struct ip6_hdr ip6_hdr;
89 unsigned char data[1]; 90 unsigned char data[1];
90}; 91};
91 92
92struct ip6_tcp { 93struct ip6_tcp {
93 struct suid_packet_header shdr; 94 struct GNUNET_MessageHeader shdr;
94 struct pkt_tun tun; 95 struct pkt_tun tun;
95 struct ip6_hdr ip6_hdr; 96 struct ip6_hdr ip6_hdr;
96 struct tcp_pkt tcp_hdr; 97 struct tcp_pkt tcp_hdr;
@@ -98,7 +99,7 @@ struct ip6_tcp {
98}; 99};
99 100
100struct ip6_udp { 101struct ip6_udp {
101 struct suid_packet_header shdr; 102 struct GNUNET_MessageHeader shdr;
102 struct pkt_tun tun; 103 struct pkt_tun tun;
103 struct ip6_hdr ip6_hdr; 104 struct ip6_hdr ip6_hdr;
104 struct udp_pkt udp_hdr; 105 struct udp_pkt udp_hdr;
@@ -106,7 +107,7 @@ struct ip6_udp {
106}; 107};
107 108
108struct ip6_udp_dns { 109struct ip6_udp_dns {
109 struct suid_packet_header shdr; 110 struct GNUNET_MessageHeader shdr;
110 struct pkt_tun tun; 111 struct pkt_tun tun;
111 struct ip6_hdr ip6_hdr; 112 struct ip6_hdr ip6_hdr;
112 struct udp_pkt udp_hdr; 113 struct udp_pkt udp_hdr;