aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2010-10-26 13:55:55 +0000
committerPhilipp Tölke <toelke@in.tum.de>2010-10-26 13:55:55 +0000
commit8441a5c3976e209805c862081d0987a74a7bb929 (patch)
treec9fe4811d16bd072f99dc127cbef37f604280d9e /src
parent3900beb1ed0370041bccbe84643d84a6f5204475 (diff)
downloadgnunet-8441a5c3976e209805c862081d0987a74a7bb929.tar.gz
gnunet-8441a5c3976e209805c862081d0987a74a7bb929.zip
Restart the hijack, if the tun was down
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_protocols.h4
-rw-r--r--src/vpn/gnunet-daemon-vpn.c27
-rw-r--r--src/vpn/gnunet-service-dns.c9
3 files changed, 37 insertions, 3 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index bf696c743..0bcd59838 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -693,6 +693,10 @@ extern "C"
693 * Type of messages the local service-dns responds with 693 * Type of messages the local service-dns responds with
694 */ 694 */
695#define GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS 206 695#define GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS 206
696/**
697 * Type of messages to instruct the local service-dns to rehijack the dns
698 */
699#define GNUNET_MESSAGE_TYPE_REHIJACK 207
696 700
697 701
698/** 702/**
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c
index 5be4f9378..227bcd9ae 100644
--- a/src/vpn/gnunet-daemon-vpn.c
+++ b/src/vpn/gnunet-daemon-vpn.c
@@ -53,6 +53,7 @@ struct vpn_cls {
53 struct GNUNET_SCHEDULER_Handle *sched; 53 struct GNUNET_SCHEDULER_Handle *sched;
54 54
55 struct GNUNET_CLIENT_Connection *dns_connection; 55 struct GNUNET_CLIENT_Connection *dns_connection;
56 unsigned char restart_hijack;
56 57
57 pid_t helper_pid; 58 pid_t helper_pid;
58 59
@@ -67,6 +68,8 @@ struct vpn_cls {
67 68
68static struct vpn_cls mycls; 69static struct vpn_cls mycls;
69 70
71size_t send_query(void* cls, size_t size, void* buf);
72
70static void cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) { 73static void cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) {
71 GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); 74 GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
72 PLIBC_KILL(mycls.helper_pid, SIGTERM); 75 PLIBC_KILL(mycls.helper_pid, SIGTERM);
@@ -108,7 +111,11 @@ static void restart_helper(void* cls, const struct GNUNET_SCHEDULER_TaskContext*
108 PLIBC_KILL(mycls.helper_pid, SIGKILL); 111 PLIBC_KILL(mycls.helper_pid, SIGKILL);
109 GNUNET_OS_process_wait(mycls.helper_pid); 112 GNUNET_OS_process_wait(mycls.helper_pid);
110 113
111 // 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 114 /* Tell the dns-service to rehijack the dns-port
115 * The routing-table gets flushed if an interface disappears.
116 */
117 mycls.restart_hijack = 1;
118 GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, sizeof(struct GNUNET_MessageHeader), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL);
112 119
113 GNUNET_DISK_pipe_close(mycls.helper_in); 120 GNUNET_DISK_pipe_close(mycls.helper_in);
114 GNUNET_DISK_pipe_close(mycls.helper_out); 121 GNUNET_DISK_pipe_close(mycls.helper_out);
@@ -202,8 +209,20 @@ static void helper_write(void* cls, const struct GNUNET_SCHEDULER_TaskContext* t
202 209
203size_t send_query(void* cls, size_t size, void* buf) 210size_t send_query(void* cls, size_t size, void* buf)
204{ 211{
212 size_t len;
213 if (mycls.restart_hijack == 1)
214 {
215 mycls.restart_hijack = 0;
216 GNUNET_assert(sizeof(struct GNUNET_MessageHeader) >= size);
217 struct GNUNET_MessageHeader* hdr = buf;
218 len = sizeof(struct GNUNET_MessageHeader);
219 hdr->size = htons(len);
220 hdr->type = htons(GNUNET_MESSAGE_TYPE_REHIJACK);
221 }
222 else
223 {
205 struct query_packet_list* query = mycls.head; 224 struct query_packet_list* query = mycls.head;
206 size_t len = ntohs(query->pkt.hdr.size); 225 len = ntohs(query->pkt.hdr.size);
207 226
208 GNUNET_assert(len <= size); 227 GNUNET_assert(len <= size);
209 228
@@ -212,8 +231,9 @@ size_t send_query(void* cls, size_t size, void* buf)
212 GNUNET_CONTAINER_DLL_remove (mycls.head, mycls.tail, query); 231 GNUNET_CONTAINER_DLL_remove (mycls.head, mycls.tail, query);
213 232
214 GNUNET_free(query); 233 GNUNET_free(query);
234 }
215 235
216 if (mycls.head != NULL) { 236 if (mycls.head != NULL || mycls.restart_hijack == 1) {
217 GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, ntohs(mycls.head->pkt.hdr.size), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL); 237 GNUNET_CLIENT_notify_transmit_ready(mycls.dns_connection, ntohs(mycls.head->pkt.hdr.size), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &send_query, NULL);
218 } 238 }
219 239
@@ -360,6 +380,7 @@ run (void *cls,
360 mycls.sched = sched; 380 mycls.sched = sched;
361 mycls.mst = GNUNET_SERVER_mst_create(&message_token, NULL); 381 mycls.mst = GNUNET_SERVER_mst_create(&message_token, NULL);
362 mycls.cfg = cfg; 382 mycls.cfg = cfg;
383 mycls.restart_hijack = 0;
363 GNUNET_SCHEDULER_add_now (sched, &reconnect_to_service_dns, NULL); 384 GNUNET_SCHEDULER_add_now (sched, &reconnect_to_service_dns, NULL);
364 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); 385 GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
365 GNUNET_SCHEDULER_add_now (sched, start_helper_and_schedule, NULL); 386 GNUNET_SCHEDULER_add_now (sched, start_helper_and_schedule, NULL);
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c
index 0c688db34..4849749c0 100644
--- a/src/vpn/gnunet-service-dns.c
+++ b/src/vpn/gnunet-service-dns.c
@@ -135,6 +135,14 @@ void receive_dht(void *cls,
135} 135}
136 136
137/** 137/**
138 * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS
139 */
140void rehijack(void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) {
141 unhijack(mycls.dnsoutport);
142 hijack(mycls.dnsoutport);
143}
144
145/**
138 * This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket 146 * This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket
139 */ 147 */
140void receive_query(void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) 148void receive_query(void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message)
@@ -337,6 +345,7 @@ run (void *cls,
337 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 345 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
338 /* callback, cls, type, size */ 346 /* callback, cls, type, size */
339 {&receive_query, NULL, GNUNET_MESSAGE_TYPE_LOCAL_QUERY_DNS, 0}, 347 {&receive_query, NULL, GNUNET_MESSAGE_TYPE_LOCAL_QUERY_DNS, 0},
348 {&rehijack, NULL, GNUNET_MESSAGE_TYPE_REHIJACK, sizeof(struct GNUNET_MessageHeader)},
340 {NULL, NULL, 0, 0} 349 {NULL, NULL, 0, 0}
341 }; 350 };
342 351