gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r13402 - in gnunet/src: include vpn


From: gnunet
Subject: [GNUnet-SVN] r13402 - in gnunet/src: include vpn
Date: Tue, 26 Oct 2010 15:55:55 +0200

Author: toelke
Date: 2010-10-26 15:55:55 +0200 (Tue, 26 Oct 2010)
New Revision: 13402

Modified:
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/vpn/gnunet-daemon-vpn.c
   gnunet/src/vpn/gnunet-service-dns.c
Log:
Restart the hijack, if the tun was down

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2010-10-26 13:55:55 UTC (rev 
13401)
+++ gnunet/src/include/gnunet_protocols.h       2010-10-26 13:55:55 UTC (rev 
13402)
@@ -693,6 +693,10 @@
  * Type of messages the local service-dns responds with
  */
 #define GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS 206
+/**
+ * Type of messages to instruct the local service-dns to rehijack the dns
+ */
+#define GNUNET_MESSAGE_TYPE_REHIJACK 207
 
 
 /**

Modified: gnunet/src/vpn/gnunet-daemon-vpn.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn.c  2010-10-26 13:55:55 UTC (rev 13401)
+++ gnunet/src/vpn/gnunet-daemon-vpn.c  2010-10-26 13:55:55 UTC (rev 13402)
@@ -53,6 +53,7 @@
        struct GNUNET_SCHEDULER_Handle *sched;
 
        struct GNUNET_CLIENT_Connection *dns_connection;
+       unsigned char restart_hijack;
 
        pid_t helper_pid;
 
@@ -67,6 +68,8 @@
 
 static struct vpn_cls mycls;
 
+size_t send_query(void* cls, size_t size, void* buf);
+
 static void cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* 
tskctx) {
   GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
   PLIBC_KILL(mycls.helper_pid, SIGTERM);
@@ -108,7 +111,11 @@
        PLIBC_KILL(mycls.helper_pid, SIGKILL);
        GNUNET_OS_process_wait(mycls.helper_pid);
 
-       // FIXME: send msg to service-dns -- the hijacker has to be started 
again, too, the routing table is flushed if it depends on one interface
+       /* Tell the dns-service to rehijack the dns-port
+        * The routing-table gets flushed if an interface disappears.
+        */
+       mycls.restart_hijack = 1;
+       GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, sizeof(struct 
GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, 
NULL);
 
        GNUNET_DISK_pipe_close(mycls.helper_in);
        GNUNET_DISK_pipe_close(mycls.helper_out);
@@ -202,8 +209,20 @@
 
 size_t send_query(void* cls, size_t size, void* buf)
 {
+  size_t len;
+  if (mycls.restart_hijack == 1)
+    {
+      mycls.restart_hijack = 0;
+      GNUNET_assert(sizeof(struct GNUNET_MessageHeader) >= size);
+      struct GNUNET_MessageHeader* hdr = buf;
+      len = sizeof(struct GNUNET_MessageHeader);
+      hdr->size = htons(len);
+      hdr->type = htons(GNUNET_MESSAGE_TYPE_REHIJACK);
+    }
+  else
+    {
        struct query_packet_list* query = mycls.head;
-       size_t len = ntohs(query->pkt.hdr.size);
+       len = ntohs(query->pkt.hdr.size);
 
        GNUNET_assert(len <= size);
 
@@ -212,8 +231,9 @@
        GNUNET_CONTAINER_DLL_remove (mycls.head, mycls.tail, query);
 
        GNUNET_free(query);
+    }
 
-       if (mycls.head != NULL) {
+       if (mycls.head != NULL || mycls.restart_hijack == 1) {
                GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, 
ntohs(mycls.head->pkt.hdr.size), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, 
&send_query, NULL);
        }
 
@@ -360,6 +380,7 @@
   mycls.sched = sched;
   mycls.mst = GNUNET_SERVER_mst_create(&message_token, NULL);
   mycls.cfg = cfg;
+  mycls.restart_hijack = 0;
   GNUNET_SCHEDULER_add_now (sched, &reconnect_to_service_dns, NULL);
   GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, 
cls); 
   GNUNET_SCHEDULER_add_now (sched, start_helper_and_schedule, NULL);

Modified: gnunet/src/vpn/gnunet-service-dns.c
===================================================================
--- gnunet/src/vpn/gnunet-service-dns.c 2010-10-26 13:55:55 UTC (rev 13401)
+++ gnunet/src/vpn/gnunet-service-dns.c 2010-10-26 13:55:55 UTC (rev 13402)
@@ -135,6 +135,14 @@
 }
 
 /**
+ * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS
+ */
+void rehijack(void *cls, struct GNUNET_SERVER_Client *client, const struct 
GNUNET_MessageHeader *message) {
+    unhijack(mycls.dnsoutport);
+    hijack(mycls.dnsoutport);
+}
+
+/**
  * This receives the dns-payload from the daemon-vpn and sends it on over the 
udp-socket
  */
 void receive_query(void *cls, struct GNUNET_SERVER_Client *client, const 
struct GNUNET_MessageHeader *message)
@@ -337,6 +345,7 @@
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
          /* callback, cls, type, size */
     {&receive_query, NULL, GNUNET_MESSAGE_TYPE_LOCAL_QUERY_DNS, 0},
+    {&rehijack, NULL, GNUNET_MESSAGE_TYPE_REHIJACK, sizeof(struct 
GNUNET_MessageHeader)},
     {NULL, NULL, 0, 0}
   };
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]