From 329e01c484e59ef1308c39bbd99b341d4ff60b21 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Tue, 20 Jul 2010 22:21:59 +0000 Subject: [PATCH] Changed the communication between the vpn-helper and the daemon to use GNUNET_MessageHeaders --- src/include/gnunet_protocols.h | 5 +++++ src/vpn/gnunet-daemon-vpn.c | 16 +++++++++------- src/vpn/gnunet-vpn-helper-p.h | 6 ++---- src/vpn/gnunet-vpn-helper.c | 26 ++++++++++++++------------ src/vpn/gnunet-vpn-packet.h | 9 +++++---- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 54f515c60..e62abdb29 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -610,6 +610,11 @@ extern "C" #define GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE 173 +/** + * Type of messages between the gnunet-vpn-helper and the daemon + */ +#define GNUNET_MESSAGE_TYPE_VPN_HELPER 185 + /** * Type used to match 'all' message types. */ 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 @@ #include "gnunet-vpn-helper-p.h" #include "gnunet-vpn-packet.h" #include "gnunet-vpn-pretty-print.h" +#include "gnunet_common.h" +#include "gnunet_protocols.h" /* #include "gnunet_template_service.h" */ /** @@ -86,15 +88,15 @@ static void restart_helper(void* cls, const struct GNUNET_SCHEDULER_TaskContext* static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) { struct vpn_cls* mycls = (struct vpn_cls*) cls; - struct suid_packet_header hdr = { .size = 0 }; + struct GNUNET_MessageHeader hdr = { .size = 0, .type = 0 }; int r = 0; if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) return; - while (r < sizeof(struct suid_packet_header)) { - int t = GNUNET_DISK_file_read(mycls->fh_from_helper, &hdr, sizeof(struct suid_packet_header)); + while (r < sizeof(struct GNUNET_MessageHeader)) { + int t = GNUNET_DISK_file_read(mycls->fh_from_helper, &hdr, sizeof(struct GNUNET_MessageHeader)); if (t<=0) { fprintf(stderr, "Read error for header: %m\n"); 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 r += t; } - struct suid_packet *pkt = (struct suid_packet*) GNUNET_malloc(ntohl(hdr.size)); + struct suid_packet *pkt = (struct suid_packet*) GNUNET_malloc(ntohs(hdr.size)); - memcpy(pkt, &hdr, sizeof(struct suid_packet_header)); + memcpy(pkt, &hdr, sizeof(struct GNUNET_MessageHeader)); - while (r < ntohl(pkt->hdr.size)) { - int t = GNUNET_DISK_file_read(mycls->fh_from_helper, (unsigned char*)pkt + r, ntohl(pkt->hdr.size) - r); + while (r < ntohs(pkt->hdr.size)) { + int t = GNUNET_DISK_file_read(mycls->fh_from_helper, (unsigned char*)pkt + r, ntohs(pkt->hdr.size) - r); if (t<=0) { fprintf(stderr, "Read error for data: %m\n"); 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 @@ #ifndef GN_VPN_HELPER_P_H #define GN_VPN_HELPER_P_H -struct suid_packet_header { - uint32_t size; -}; +#include "gnunet_common.h" struct suid_packet { - struct suid_packet_header hdr; + struct GNUNET_MessageHeader hdr; unsigned char data[1]; }; 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 @@ #include #include -#include "gnunet-vpn-helper-p.h" #include "gnunet-vpn-tun.h" +#include "gnunet_common.h" +#include "gnunet_protocols.h" +#include "gnunet-vpn-helper-p.h" #ifndef _LINUX_IN6_H // This is in linux/include/net/ipv6.h. @@ -168,7 +170,7 @@ outer: if (FD_ISSET(0, &fds_r) && write_fd_possible) { write_fd_possible = 0; struct suid_packet *pkt = (struct suid_packet*) buf; - r = read(0, buf, sizeof(struct suid_packet_header)); + r = read(0, buf, sizeof(struct GNUNET_MessageHeader)); if (r <= 0) { fprintf(stderr, "read-error: %m\n"); shutdown(fd_tun, SHUT_WR); @@ -176,8 +178,8 @@ outer: wri=0; goto outer; } - while (r < ntohl(pkt->hdr.size)) { - int t = read(0, buf + r, ntohl(pkt->hdr.size) - r); + while (r < ntohs(pkt->hdr.size)) { + int t = read(0, buf + r, ntohs(pkt->hdr.size) - r); if (r < 0) { fprintf(stderr, "read-error: %m\n"); shutdown(fd_tun, SHUT_WR); @@ -188,8 +190,8 @@ outer: r += t; } r = 0; - while (r < ntohl(pkt->hdr.size) - sizeof(struct suid_packet_header)) { - int t = write(fd_tun, pkt->data, ntohl(pkt->hdr.size) - sizeof(struct suid_packet_header) - r); + while (r < ntohs(pkt->hdr.size) - sizeof(struct GNUNET_MessageHeader)) { + int t = write(fd_tun, pkt->data, ntohs(pkt->hdr.size) - sizeof(struct GNUNET_MessageHeader) - r); if (t < 0) { fprintf(stderr, "write-error 3: %m\n"); shutdown(fd_tun, SHUT_WR); @@ -209,10 +211,10 @@ outer: rea = 0; goto outer; } - struct suid_packet_header hdr = { .size = htonl(r + sizeof(struct suid_packet_header))}; + struct GNUNET_MessageHeader hdr = { .size = htons(r + sizeof(struct GNUNET_MessageHeader)), .type = htons(GNUNET_MESSAGE_TYPE_VPN_HELPER) }; r = 0; - while(r < sizeof(struct suid_packet_header)) { - int t = write(1, &hdr, sizeof(struct suid_packet_header) - r); + while(r < sizeof(struct GNUNET_MessageHeader)) { + int t = write(1, &hdr, sizeof(struct GNUNET_MessageHeader) - r); if (t < 0) { fprintf(stderr, "write-error 2: %m\n"); shutdown(fd_tun, SHUT_RD); @@ -222,10 +224,10 @@ outer: } r += t; } - while(r < ntohl(hdr.size)) { - int t = write(1, buf, ntohl(hdr.size) - r); + while(r < ntohs(hdr.size)) { + int t = write(1, buf, ntohs(hdr.size) - r); if (t < 0) { - fprintf(stderr, "write-error 1: %m, written %d/%d\n", r, ntohl(hdr.size)); + fprintf(stderr, "write-error 1: %m, written %d/%d\n", r, ntohs(hdr.size)); shutdown(fd_tun, SHUT_RD); shutdown(1, SHUT_WR); 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 @@ #define _GNTUN_PACKET_H_ #include "gnunet-vpn-helper-p.h" +#include "gnunet_common.h" // Headers struct pkt_tun { @@ -83,14 +84,14 @@ struct dns_record { // Complete Packets struct ip6_pkt { - struct suid_packet_header shdr; + struct GNUNET_MessageHeader shdr; struct pkt_tun tun; struct ip6_hdr ip6_hdr; unsigned char data[1]; }; struct ip6_tcp { - struct suid_packet_header shdr; + struct GNUNET_MessageHeader shdr; struct pkt_tun tun; struct ip6_hdr ip6_hdr; struct tcp_pkt tcp_hdr; @@ -98,7 +99,7 @@ struct ip6_tcp { }; struct ip6_udp { - struct suid_packet_header shdr; + struct GNUNET_MessageHeader shdr; struct pkt_tun tun; struct ip6_hdr ip6_hdr; struct udp_pkt udp_hdr; @@ -106,7 +107,7 @@ struct ip6_udp { }; struct ip6_udp_dns { - struct suid_packet_header shdr; + struct GNUNET_MessageHeader shdr; struct pkt_tun tun; struct ip6_hdr ip6_hdr; struct udp_pkt udp_hdr; -- 2.25.1