Changed the communication between the vpn-helper and the daemon to use GNUNET_Message...
authorPhilipp Tölke <toelke@in.tum.de>
Tue, 20 Jul 2010 22:21:59 +0000 (22:21 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Tue, 20 Jul 2010 22:21:59 +0000 (22:21 +0000)
src/include/gnunet_protocols.h
src/vpn/gnunet-daemon-vpn.c
src/vpn/gnunet-vpn-helper-p.h
src/vpn/gnunet-vpn-helper.c
src/vpn/gnunet-vpn-packet.h

index 54f515c606efd17ce2f4e3e5ba1bcc62086e015b..e62abdb2955bf983f7f4d07729ceb1fdcff20e54 100644 (file)
@@ -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.
  */
index 4f1cd9f60c489379211950a7140b8e7f25d30111..9f8ffb6834ed9e4e4b97613a851c9a31188702b7 100644 (file)
@@ -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);
index 664c40389652d98cdfe9642faf86e15f8282f465..d48755df34a91daeb470fc566ad333dcd7924a02 100644 (file)
@@ -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];
 };
 
index 92af307dd380452df5f0d466eb876920c164827d..1d0b1ad28821f2f69c22094fe7fc71f17eea76b5 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 
-#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;
index 89b75ba35b379bd6bd7491f675d642d6fdbe5e00..4ba6f2528e22d1c379943de97ddfcdb8ba0b9c6b 100644 (file)
@@ -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;