aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-01 23:39:24 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-01 23:39:24 +0000
commit402a25de1ef93133c9879706071081405ade61f6 (patch)
tree96763797649dd4bff0b7f8b2010a0589f8179dcb /src/vpn
parent3e73780b201b600dd8dd8725f5a628d62d9c4f51 (diff)
downloadgnunet-402a25de1ef93133c9879706071081405ade61f6.tar.gz
gnunet-402a25de1ef93133c9879706071081405ade61f6.zip
first quick hack to extract an initial DNS service API
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/Makefile.am2
-rw-r--r--src/vpn/gnunet-daemon-vpn-dns.c203
-rw-r--r--src/vpn/gnunet-daemon-vpn-dns.h88
-rw-r--r--src/vpn/gnunet-daemon-vpn-helper.c36
-rw-r--r--src/vpn/gnunet-daemon-vpn.c21
-rw-r--r--src/vpn/gnunet-daemon-vpn.h6
6 files changed, 24 insertions, 332 deletions
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am
index dfba44f0a..13928dba3 100644
--- a/src/vpn/Makefile.am
+++ b/src/vpn/Makefile.am
@@ -35,7 +35,6 @@ gnunet_helper_vpn_SOURCES = \
35gnunet_daemon_vpn_SOURCES = \ 35gnunet_daemon_vpn_SOURCES = \
36 gnunet-daemon-vpn.c gnunet-daemon-vpn.h \ 36 gnunet-daemon-vpn.c gnunet-daemon-vpn.h \
37 gnunet-daemon-vpn-helper.c gnunet-daemon-vpn-helper.h \ 37 gnunet-daemon-vpn-helper.c gnunet-daemon-vpn-helper.h \
38 gnunet-daemon-vpn-dns.c gnunet-daemon-vpn-dns.h \
39 gnunet-helper-vpn-api.c gnunet-helper-vpn-api.h \ 38 gnunet-helper-vpn-api.c gnunet-helper-vpn-api.h \
40 gnunet-vpn-checksum.c gnunet-vpn-checksum.h 39 gnunet-vpn-checksum.c gnunet-vpn-checksum.h
41gnunet_daemon_vpn_LDADD = \ 40gnunet_daemon_vpn_LDADD = \
@@ -44,6 +43,7 @@ gnunet_daemon_vpn_LDADD = \
44 $(top_builddir)/src/util/libgnunetutil.la \ 43 $(top_builddir)/src/util/libgnunetutil.la \
45 $(top_builddir)/src/mesh/libgnunetmesh.la \ 44 $(top_builddir)/src/mesh/libgnunetmesh.la \
46 $(top_builddir)/src/dns/libgnunetdnsparser.la \ 45 $(top_builddir)/src/dns/libgnunetdnsparser.la \
46 $(top_builddir)/src/dns/libgnunetdns.la \
47 $(GN_LIBINTL) 47 $(GN_LIBINTL)
48 48
49gnunet_daemon_exit_SOURCES = \ 49gnunet_daemon_exit_SOURCES = \
diff --git a/src/vpn/gnunet-daemon-vpn-dns.c b/src/vpn/gnunet-daemon-vpn-dns.c
deleted file mode 100644
index b24d802f7..000000000
--- a/src/vpn/gnunet-daemon-vpn-dns.c
+++ /dev/null
@@ -1,203 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file vpn/gnunet-daemon-vpn-dns.c
23 * @brief
24 * @author Philipp Toelke
25 */
26#include <platform.h>
27#include <gnunet_common.h>
28#include <gnunet_client_lib.h>
29#include <gnunet_os_lib.h>
30#include <gnunet_mesh_service.h>
31#include <gnunet_protocols.h>
32#include <gnunet_server_lib.h>
33#include <gnunet_container_lib.h>
34#include <block_dns.h>
35
36#include "gnunet-daemon-vpn-dns.h"
37#include "gnunet-daemon-vpn.h"
38#include "gnunet-daemon-vpn-helper.h"
39#include "gnunet-vpn-packet.h"
40
41struct query_packet_list *head;
42struct query_packet_list *tail;
43struct GNUNET_CLIENT_Connection *dns_connection;
44unsigned char restart_hijack;
45struct answer_packet_list *answer_proc_head;
46struct answer_packet_list *answer_proc_tail;
47
48struct GNUNET_CLIENT_TransmitHandle *dns_transmit_handle;
49
50/**
51 * Callback called by notify_transmit_ready; sends dns-queries or rehijack-messages
52 * to the service-dns
53 * {{{
54 */
55size_t
56send_query (void *cls GNUNET_UNUSED, size_t size, void *buf)
57{
58 size_t len;
59
60 dns_transmit_handle = NULL;
61
62 /*
63 * Send the rehijack-message
64 */
65 if (restart_hijack == 1)
66 {
67 restart_hijack = 0;
68 /*
69 * The message is just a header
70 */
71 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) <= size);
72 struct GNUNET_MessageHeader *hdr = buf;
73
74 len = sizeof (struct GNUNET_MessageHeader);
75 hdr->size = htons (len);
76 hdr->type = htons (GNUNET_MESSAGE_TYPE_REHIJACK);
77 }
78 else if (head != NULL)
79 {
80 struct query_packet_list *query = head;
81
82 len = ntohs (query->pkt.hdr.size);
83
84 GNUNET_assert (len <= size);
85
86 memcpy (buf, &query->pkt.hdr, len);
87
88 GNUNET_CONTAINER_DLL_remove (head, tail, query);
89
90 GNUNET_free (query);
91 }
92 else
93 {
94 GNUNET_break (0);
95 len = 0;
96 }
97
98 /*
99 * Check whether more data is to be sent
100 */
101 if (head != NULL)
102 {
103 dns_transmit_handle =
104 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
105 ntohs (head->pkt.hdr.size),
106 GNUNET_TIME_UNIT_FOREVER_REL,
107 GNUNET_YES, &send_query, NULL);
108 }
109 else if (restart_hijack == 1)
110 {
111 dns_transmit_handle =
112 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
113 sizeof (struct
114 GNUNET_MessageHeader),
115 GNUNET_TIME_UNIT_FOREVER_REL,
116 GNUNET_YES, &send_query, NULL);
117 }
118
119 return len;
120}
121
122/* }}} */
123
124
125/**
126 * Connect to the service-dns
127 */
128void
129connect_to_service_dns (void *cls GNUNET_UNUSED,
130 const struct GNUNET_SCHEDULER_TaskContext *tc)
131{
132 conn_task = GNUNET_SCHEDULER_NO_TASK;
133 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
134 return;
135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to service-dns\n");
136 GNUNET_assert (dns_connection == NULL);
137 dns_connection = GNUNET_CLIENT_connect ("dns", cfg);
138 /* This would most likely be a misconfiguration */
139 GNUNET_assert (NULL != dns_connection);
140 GNUNET_CLIENT_receive (dns_connection, &dns_answer_handler, NULL,
141 GNUNET_TIME_UNIT_FOREVER_REL);
142
143 /* We might not yet be connected. Yay, mps. */
144 if (NULL == dns_connection)
145 return;
146
147 /* If a packet is already in the list, schedule to send it */
148 if (dns_transmit_handle == NULL && head != NULL)
149 dns_transmit_handle =
150 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
151 ntohs (head->pkt.hdr.size),
152 GNUNET_TIME_UNIT_FOREVER_REL,
153 GNUNET_YES, &send_query, NULL);
154 else if (dns_transmit_handle == NULL && restart_hijack == 1)
155 {
156 dns_transmit_handle =
157 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
158 sizeof (struct
159 GNUNET_MessageHeader),
160 GNUNET_TIME_UNIT_FOREVER_REL,
161 GNUNET_YES, &send_query, NULL);
162 }
163}
164
165/**
166 * This receives packets from the service-dns and schedules process_answer to
167 * handle it
168 */
169void
170dns_answer_handler (void *cls GNUNET_UNUSED,
171 const struct GNUNET_MessageHeader *msg)
172{
173 /* the service disconnected, reconnect after short wait */
174 if (msg == NULL)
175 {
176 if (dns_transmit_handle != NULL)
177 GNUNET_CLIENT_notify_transmit_ready_cancel (dns_transmit_handle);
178 dns_transmit_handle = NULL;
179 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
180 dns_connection = NULL;
181 conn_task =
182 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
183 &connect_to_service_dns, NULL);
184 return;
185 }
186
187 /* the service did something strange, reconnect immediately */
188 if (msg->type != htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_RESPONSE_DNS))
189 {
190 GNUNET_break (0);
191 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
192 dns_connection = NULL;
193 conn_task = GNUNET_SCHEDULER_add_now (&connect_to_service_dns, NULL);
194 return;
195 }
196 void *pkt = GNUNET_malloc (ntohs (msg->size));
197
198 memcpy (pkt, msg, ntohs (msg->size));
199
200 GNUNET_SCHEDULER_add_now (process_answer, pkt);
201 GNUNET_CLIENT_receive (dns_connection, &dns_answer_handler, NULL,
202 GNUNET_TIME_UNIT_FOREVER_REL);
203}
diff --git a/src/vpn/gnunet-daemon-vpn-dns.h b/src/vpn/gnunet-daemon-vpn-dns.h
deleted file mode 100644
index 0cd0d8b26..000000000
--- a/src/vpn/gnunet-daemon-vpn-dns.h
+++ /dev/null
@@ -1,88 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file vpn/gnunet-daemon-vpn-dns.h
23 * @brief
24 * @author Philipp Toelke
25 */
26#ifndef GNUNET_DAEMON_VPN_DNS_H
27#define GNUNET_DAEMON_VPN_DNS_H
28
29/**
30 * a list of outgoing dns-query-packets
31 */
32extern struct query_packet_list *head;
33
34/**
35 * The last element of the list of outgoing dns-query-packets
36 */
37extern struct query_packet_list *tail;
38
39/**
40 * Callback called by notify_transmit_ready; sends dns-queries or rehijack-messages
41 * to the service-dns
42 */
43size_t
44send_query (void *cls, size_t size, void *buf);
45
46/**
47 * Connect to the service-dns
48 */
49void
50connect_to_service_dns (void *cls,
51 const struct GNUNET_SCHEDULER_TaskContext *tc);
52
53/**
54 * This receives packets from the service-dns and schedules process_answer to
55 * handle it
56 */
57void
58dns_answer_handler (void *cls, const struct GNUNET_MessageHeader *msg);
59
60/**
61 * The connection to the service-dns
62 */
63extern struct GNUNET_CLIENT_Connection *dns_connection;
64
65/**
66 * A flag to show that the service-dns has to rehijack the outbound dns-packets
67 *
68 * This gets set when the helper restarts as the routing-tables are flushed when
69 * the interface vanishes.
70 */
71extern unsigned char restart_hijack;
72
73/**
74 * A list of processed dns-responses.
75 *
76 * "processed" means that the packet is complete and can be sent out via udp
77 * directly
78 */
79extern struct answer_packet_list *answer_proc_head;
80
81/**
82 * The last element of the list of processed dns-responses.
83 */
84extern struct answer_packet_list *answer_proc_tail;
85
86extern GNUNET_SCHEDULER_TaskIdentifier conn_task;
87
88#endif /* end of include guard: GNUNET-DAEMON-VPN-DNS_H */
diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c
index 8f295506a..984b126e7 100644
--- a/src/vpn/gnunet-daemon-vpn-helper.c
+++ b/src/vpn/gnunet-daemon-vpn-helper.c
@@ -34,8 +34,8 @@
34#include <block_dns.h> 34#include <block_dns.h>
35#include <gnunet_configuration_lib.h> 35#include <gnunet_configuration_lib.h>
36#include <gnunet_applications.h> 36#include <gnunet_applications.h>
37#include <gnunet_dns_service.h>
37 38
38#include "gnunet-daemon-vpn-dns.h"
39#include "gnunet-daemon-vpn.h" 39#include "gnunet-daemon-vpn.h"
40#include "gnunet-daemon-vpn-helper.h" 40#include "gnunet-daemon-vpn-helper.h"
41#include "gnunet-vpn-packet.h" 41#include "gnunet-vpn-packet.h"
@@ -137,15 +137,7 @@ start_helper_and_schedule (void *cls,
137 /* Tell the dns-service to rehijack the dns-port 137 /* Tell the dns-service to rehijack the dns-port
138 * The routing-table gets flushed if an interface disappears. 138 * The routing-table gets flushed if an interface disappears.
139 */ 139 */
140 restart_hijack = 1; 140 GNUNET_DNS_restart_hijack (dns_handle);
141 if (NULL != dns_connection && dns_transmit_handle == NULL)
142 dns_transmit_handle =
143 GNUNET_CLIENT_notify_transmit_ready (dns_connection,
144 sizeof (struct
145 GNUNET_MessageHeader),
146 GNUNET_TIME_UNIT_FOREVER_REL,
147 GNUNET_YES, &send_query, NULL);
148
149 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 141 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
150 helper_handle->fh_to_helper, &helper_write, 142 helper_handle->fh_to_helper, &helper_write,
151 NULL); 143 NULL);
@@ -361,17 +353,7 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
361 query->pkt.src_port = pkt6_udp->udp_hdr.spt; 353 query->pkt.src_port = pkt6_udp->udp_hdr.spt;
362 memcpy (query->pkt.data, pkt6_udp->data, 354 memcpy (query->pkt.data, pkt6_udp->data,
363 ntohs (pkt6_udp->udp_hdr.len) - 8); 355 ntohs (pkt6_udp->udp_hdr.len) - 8);
364 356 GNUNET_DNS_queue_request (dns_handle, query);
365 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, query);
366
367 GNUNET_assert (head != NULL);
368
369 if (dns_connection != NULL && dns_transmit_handle == NULL)
370 dns_transmit_handle =
371 GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
372 GNUNET_TIME_UNIT_FOREVER_REL,
373 GNUNET_YES, &send_query,
374 NULL);
375 break; 357 break;
376 } 358 }
377 /* fall through */ 359 /* fall through */
@@ -559,16 +541,8 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
559 query->pkt.addrlen = 4; 541 query->pkt.addrlen = 4;
560 query->pkt.src_port = udp->udp_hdr.spt; 542 query->pkt.src_port = udp->udp_hdr.spt;
561 memcpy (query->pkt.data, udp->data, ntohs (udp->udp_hdr.len) - 8); 543 memcpy (query->pkt.data, udp->data, ntohs (udp->udp_hdr.len) - 8);
562 544
563 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, query); 545 GNUNET_DNS_queue_request (dns_handle, query);
564
565 GNUNET_assert (head != NULL);
566
567 if (dns_connection != NULL && dns_transmit_handle == NULL)
568 dns_transmit_handle =
569 GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
570 GNUNET_TIME_UNIT_FOREVER_REL,
571 GNUNET_YES, &send_query, NULL);
572 } 546 }
573 else 547 else
574 { 548 {
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c
index 6b65b709e..86f08d19c 100644
--- a/src/vpn/gnunet-daemon-vpn.c
+++ b/src/vpn/gnunet-daemon-vpn.c
@@ -36,7 +36,7 @@
36#include "gnunet_constants.h" 36#include "gnunet_constants.h"
37#include <block_dns.h> 37#include <block_dns.h>
38#include "gnunet-daemon-vpn-helper.h" 38#include "gnunet-daemon-vpn-helper.h"
39#include "gnunet-daemon-vpn-dns.h" 39#include "gnunet_dns_service.h"
40#include "gnunet-daemon-vpn.h" 40#include "gnunet-daemon-vpn.h"
41#include "gnunet-vpn-checksum.h" 41#include "gnunet-vpn-checksum.h"
42 42
@@ -45,6 +45,13 @@ struct GNUNET_MESH_Handle *mesh_handle;
45struct GNUNET_CONTAINER_MultiHashMap *hashmap; 45struct GNUNET_CONTAINER_MultiHashMap *hashmap;
46static struct GNUNET_CONTAINER_Heap *heap; 46static struct GNUNET_CONTAINER_Heap *heap;
47 47
48struct GNUNET_DNS_Handle *dns_handle;
49
50struct answer_packet_list *answer_proc_head;
51
52struct answer_packet_list *answer_proc_tail;
53
54
48struct tunnel_notify_queue 55struct tunnel_notify_queue
49{ 56{
50 struct tunnel_notify_queue *next; 57 struct tunnel_notify_queue *next;
@@ -87,12 +94,7 @@ cleanup (void *cls GNUNET_UNUSED,
87 cleanup_helper (helper_handle); 94 cleanup_helper (helper_handle);
88 95
89 /* close the connection to the service-dns */ 96 /* close the connection to the service-dns */
90 if (dns_connection != NULL) 97 GNUNET_DNS_disconnect (dns_handle);
91 {
92 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
93 dns_connection = NULL;
94 }
95
96 if (mesh_handle != NULL) 98 if (mesh_handle != NULL)
97 { 99 {
98 GNUNET_MESH_disconnect (mesh_handle); 100 GNUNET_MESH_disconnect (mesh_handle);
@@ -1258,13 +1260,14 @@ run (void *cls, char *const *args GNUNET_UNUSED,
1258 GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers, 1260 GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers,
1259 types); 1261 types);
1260 cfg = cfg_; 1262 cfg = cfg_;
1261 restart_hijack = 0;
1262 hashmap = GNUNET_CONTAINER_multihashmap_create (65536); 1263 hashmap = GNUNET_CONTAINER_multihashmap_create (65536);
1263 heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1264 heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1264 GNUNET_CONFIGURATION_get_value_number (cfg, "vpn", "MAX_MAPPINGg", 1265 GNUNET_CONFIGURATION_get_value_number (cfg, "vpn", "MAX_MAPPINGg",
1265 &max_mappings); 1266 &max_mappings);
1266 udp_connections = GNUNET_CONTAINER_multihashmap_create (65536); 1267 udp_connections = GNUNET_CONTAINER_multihashmap_create (65536);
1267 conn_task = GNUNET_SCHEDULER_add_now (connect_to_service_dns, NULL); 1268 dns_handle = GNUNET_DNS_connect (cfg,
1269 &process_answer,
1270 NULL);
1268 shs_task = 1271 shs_task =
1269 GNUNET_SCHEDULER_add_after (conn_task, start_helper_and_schedule, NULL); 1272 GNUNET_SCHEDULER_add_after (conn_task, start_helper_and_schedule, NULL);
1270 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); 1273 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
diff --git a/src/vpn/gnunet-daemon-vpn.h b/src/vpn/gnunet-daemon-vpn.h
index c8bf91ebb..35520a277 100644
--- a/src/vpn/gnunet-daemon-vpn.h
+++ b/src/vpn/gnunet-daemon-vpn.h
@@ -28,6 +28,12 @@
28 28
29#include "gnunet_dns_service.h" 29#include "gnunet_dns_service.h"
30 30
31extern struct answer_packet_list *answer_proc_head;
32
33extern struct answer_packet_list *answer_proc_tail;
34
35extern struct GNUNET_DNS_Handle *dns_handle;
36
31/** 37/**
32 * This gets scheduled with cls pointing to an answer_packet and does everything 38 * This gets scheduled with cls pointing to an answer_packet and does everything
33 * needed in order to send it to the helper. 39 * needed in order to send it to the helper.