aboutsummaryrefslogtreecommitdiff
path: root/src/dns
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-01-25 15:22:01 +0000
committerChristian Grothoff <christian@grothoff.org>2013-01-25 15:22:01 +0000
commit07ab625068b62afc532a78534018f6579697a307 (patch)
treea240046783d7ab2e5134e5bc493c34f31b5b0df2 /src/dns
parentaf6fc96401b2d550293c8ce9ceb1b34ee46003d0 (diff)
downloadgnunet-07ab625068b62afc532a78534018f6579697a307.tar.gz
gnunet-07ab625068b62afc532a78534018f6579697a307.zip
remove DNS exit for mesh from gnunet-service-dns
Diffstat (limited to 'src/dns')
-rw-r--r--src/dns/Makefile.am1
-rw-r--r--src/dns/dns.conf.in8
-rw-r--r--src/dns/gnunet-service-dns.c272
3 files changed, 6 insertions, 275 deletions
diff --git a/src/dns/Makefile.am b/src/dns/Makefile.am
index 068d16fd9..345c1316c 100644
--- a/src/dns/Makefile.am
+++ b/src/dns/Makefile.am
@@ -75,7 +75,6 @@ gnunet_service_dns_SOURCES = \
75gnunet_service_dns_LDADD = \ 75gnunet_service_dns_LDADD = \
76 $(top_builddir)/src/dns/libgnunetdnsstub.la \ 76 $(top_builddir)/src/dns/libgnunetdnsstub.la \
77 $(top_builddir)/src/tun/libgnunettun.la \ 77 $(top_builddir)/src/tun/libgnunettun.la \
78 $(top_builddir)/src/mesh/libgnunetmesh.la \
79 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 78 $(top_builddir)/src/statistics/libgnunetstatistics.la \
80 $(top_builddir)/src/util/libgnunetutil.la \ 79 $(top_builddir)/src/util/libgnunetutil.la \
81 $(GN_LIBINTL) 80 $(GN_LIBINTL)
diff --git a/src/dns/dns.conf.in b/src/dns/dns.conf.in
index 84dc3aaa4..7944b410a 100644
--- a/src/dns/dns.conf.in
+++ b/src/dns/dns.conf.in
@@ -15,14 +15,6 @@ UNIX_MATCH_GID = YES
15# we never use it, even if @UNIXONLY@ is not set (just to be safe) 15# we never use it, even if @UNIXONLY@ is not set (just to be safe)
16@UNIXONLY@ PORT = 0 16@UNIXONLY@ PORT = 0
17 17
18# This option should be set to YES to allow the DNS service to
19# perform lookups against the locally configured DNS resolver.
20# (set to "NO" if no normal ISP is locally available and thus
21# requests for normal ".com"/".org"/etc. must be routed via
22# the GNUnet VPN (the GNUNET PT daemon then needs to be configured
23# to intercept and route DNS queries via mesh).
24PROVIDE_EXIT = YES
25
26# Name of the virtual interface we use to intercept DNS traffic. 18# Name of the virtual interface we use to intercept DNS traffic.
27IFNAME = gnunet-dns 19IFNAME = gnunet-dns
28 20
diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c
index 19c9d8eea..d1689f4d2 100644
--- a/src/dns/gnunet-service-dns.c
+++ b/src/dns/gnunet-service-dns.c
@@ -46,7 +46,6 @@
46#include "gnunet_dns_service.h" 46#include "gnunet_dns_service.h"
47#include "gnunet_dnsparser_lib.h" 47#include "gnunet_dnsparser_lib.h"
48#include "gnunet_dnsstub_lib.h" 48#include "gnunet_dnsstub_lib.h"
49#include "gnunet_mesh_service.h"
50#include "gnunet_statistics_service.h" 49#include "gnunet_statistics_service.h"
51#include "gnunet_tun_lib.h" 50#include "gnunet_tun_lib.h"
52 51
@@ -198,50 +197,6 @@ struct RequestRecord
198 197
199 198
200/** 199/**
201 * State we keep for each DNS tunnel that terminates at this node.
202 */
203struct TunnelState
204{
205
206 /**
207 * Associated MESH tunnel.
208 */
209 struct GNUNET_MESH_Tunnel *tunnel;
210
211 /**
212 * Active request for sending a reply.
213 */
214 struct GNUNET_MESH_TransmitHandle *th;
215
216 /**
217 * DNS reply ready for transmission.
218 */
219 char *reply;
220
221 /**
222 * Socket we are using to transmit this request (must match if we receive
223 * a response).
224 */
225 struct GNUNET_DNSSTUB_RequestSocket *rs;
226
227 /**
228 * Number of bytes in 'reply'.
229 */
230 size_t reply_length;
231
232 /**
233 * Original DNS request ID as used by the client.
234 */
235 uint16_t original_id;
236
237 /**
238 * DNS request ID that we used for forwarding.
239 */
240 uint16_t my_id;
241};
242
243
244/**
245 * Global return value from 'main'. 200 * Global return value from 'main'.
246 */ 201 */
247static int global_ret; 202static int global_ret;
@@ -282,11 +237,6 @@ static struct ClientRecord *clients_tail;
282static struct GNUNET_SERVER_NotificationContext *nc; 237static struct GNUNET_SERVER_NotificationContext *nc;
283 238
284/** 239/**
285 * Array of all open requests from tunnels.
286 */
287static struct TunnelState *tunnels[UINT16_MAX + 1];
288
289/**
290 * Array of all open requests. 240 * Array of all open requests.
291 */ 241 */
292static struct RequestRecord requests[UINT16_MAX + 1]; 242static struct RequestRecord requests[UINT16_MAX + 1];
@@ -297,12 +247,6 @@ static struct RequestRecord requests[UINT16_MAX + 1];
297static uint64_t request_id_gen; 247static uint64_t request_id_gen;
298 248
299/** 249/**
300 * Handle to the MESH service (for receiving DNS queries), or NULL
301 * if we are not a DNS exit.
302 */
303static struct GNUNET_MESH_Handle *mesh;
304
305/**
306 * Handle to the DNS Stub resolver. 250 * Handle to the DNS Stub resolver.
307 */ 251 */
308static struct GNUNET_DNSSTUB_Context *dnsstub; 252static struct GNUNET_DNSSTUB_Context *dnsstub;
@@ -355,11 +299,6 @@ cleanup_task (void *cls GNUNET_UNUSED,
355 GNUNET_DNSSTUB_stop (dnsstub); 299 GNUNET_DNSSTUB_stop (dnsstub);
356 dnsstub = NULL; 300 dnsstub = NULL;
357 } 301 }
358 if (NULL != mesh)
359 {
360 GNUNET_MESH_disconnect(mesh);
361 mesh = NULL;
362 }
363} 302}
364 303
365 304
@@ -747,53 +686,6 @@ client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
747 686
748 687
749/** 688/**
750 * We got a reply from DNS for a request of a MESH tunnel. Send it
751 * via the tunnel (after changing the request ID back).
752 *
753 * @param cls the 'struct TunnelState'
754 * @param size number of bytes available in buf
755 * @param buf where to copy the reply
756 * @return number of bytes written to buf
757 */
758static size_t
759transmit_reply_to_mesh (void *cls,
760 size_t size,
761 void *buf)
762{
763 struct TunnelState *ts = cls;
764 size_t off;
765 size_t ret;
766 char *cbuf = buf;
767 struct GNUNET_MessageHeader hdr;
768 struct GNUNET_TUN_DnsHeader dns;
769
770 ts->th = NULL;
771 GNUNET_assert (ts->reply != NULL);
772 if (size == 0)
773 return 0;
774 ret = sizeof (struct GNUNET_MessageHeader) + ts->reply_length;
775 GNUNET_assert (ret <= size);
776 hdr.size = htons (ret);
777 hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET);
778 memcpy (&dns, ts->reply, sizeof (dns));
779 dns.id = ts->original_id;
780 off = 0;
781 memcpy (&cbuf[off], &hdr, sizeof (hdr));
782 off += sizeof (hdr);
783 memcpy (&cbuf[off], &dns, sizeof (dns));
784 off += sizeof (dns);
785 memcpy (&cbuf[off], &ts->reply[sizeof (dns)], ts->reply_length - sizeof (dns));
786 off += ts->reply_length - sizeof (dns);
787 GNUNET_free (ts->reply);
788 ts->reply = NULL;
789 ts->reply_length = 0;
790 GNUNET_assert (ret == off);
791 return ret;
792}
793
794
795
796/**
797 * Callback called from DNSSTUB resolver when a resolution 689 * Callback called from DNSSTUB resolver when a resolution
798 * succeeded. 690 * succeeded.
799 * 691 *
@@ -809,47 +701,18 @@ process_dns_result (void *cls,
809 size_t r) 701 size_t r)
810{ 702{
811 struct RequestRecord *rr; 703 struct RequestRecord *rr;
812 struct TunnelState *ts;
813 704
814 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
815 "Processing DNS result from stub resolver\n"); 706 "Processing DNS result from stub resolver\n");
816 GNUNET_assert (NULL == cls); 707 GNUNET_assert (NULL == cls);
817 /* Handle case that this is a reply to a request from a MESH DNS tunnel */
818 ts = tunnels[dns->id];
819 if ( (NULL == ts) ||
820 (ts->rs != rs) )
821 ts = NULL; /* DNS responder address missmatch */
822 if (NULL != ts)
823 {
824 LOG (GNUNET_ERROR_TYPE_DEBUG,
825 "Got a response from the stub resolver for DNS request received via MESH!\n");
826 tunnels[dns->id] = NULL;
827 GNUNET_free_non_null (ts->reply);
828 ts->reply = GNUNET_malloc (r);
829 ts->reply_length = r;
830 memcpy (ts->reply, dns, r);
831 if (NULL != ts->th)
832 GNUNET_MESH_notify_transmit_ready_cancel (ts->th);
833 ts->th = GNUNET_MESH_notify_transmit_ready (ts->tunnel,
834 GNUNET_NO,
835 GNUNET_TIME_UNIT_FOREVER_REL,
836 NULL,
837 sizeof (struct GNUNET_MessageHeader) + r,
838 &transmit_reply_to_mesh,
839 ts);
840 }
841 /* Handle case that this is a reply to a local request (intercepted from TUN interface) */
842 rr = &requests[dns->id]; 708 rr = &requests[dns->id];
843 if ( (rr->phase != RP_INTERNET_DNS) || 709 if ( (rr->phase != RP_INTERNET_DNS) ||
844 (rr->rs != rs) ) 710 (rr->rs != rs) )
845 { 711 {
846 if (NULL == ts) 712 /* unexpected / bogus reply */
847 { 713 GNUNET_STATISTICS_update (stats,
848 /* unexpected / bogus reply */ 714 gettext_noop ("# External DNS response discarded (no matching request)"),
849 GNUNET_STATISTICS_update (stats, 715 1, GNUNET_NO);
850 gettext_noop ("# External DNS response discarded (no matching request)"),
851 1, GNUNET_NO);
852 }
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
854 "Received DNS reply that does not match any pending request. Dropping.\n"); 717 "Received DNS reply that does not match any pending request. Dropping.\n");
855 return; 718 return;
@@ -1152,109 +1015,6 @@ process_helper_messages (void *cls GNUNET_UNUSED, void *client,
1152 1015
1153 1016
1154/** 1017/**
1155 * Process a request via mesh to perform a DNS query.
1156 *
1157 * @param cls closure, NULL
1158 * @param tunnel connection to the other end
1159 * @param tunnel_ctx pointer to our 'struct TunnelState *'
1160 * @param sender who sent the message
1161 * @param message the actual message
1162 * @param atsi performance data for the connection
1163 * @return GNUNET_OK to keep the connection open,
1164 * GNUNET_SYSERR to close it (signal serious error)
1165 */
1166static int
1167receive_dns_request (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1168 void **tunnel_ctx,
1169 const struct GNUNET_PeerIdentity *sender GNUNET_UNUSED,
1170 const struct GNUNET_MessageHeader *message,
1171 const struct GNUNET_ATS_Information *atsi GNUNET_UNUSED)
1172{
1173 struct TunnelState *ts = *tunnel_ctx;
1174 const struct GNUNET_TUN_DnsHeader *dns;
1175 size_t mlen = ntohs (message->size);
1176 size_t dlen = mlen - sizeof (struct GNUNET_MessageHeader);
1177 char buf[dlen] GNUNET_ALIGN;
1178 struct GNUNET_TUN_DnsHeader *dout;
1179
1180 if (dlen < sizeof (struct GNUNET_TUN_DnsHeader))
1181 {
1182 GNUNET_break_op (0);
1183 return GNUNET_SYSERR;
1184 }
1185 dns = (const struct GNUNET_TUN_DnsHeader *) &message[1];
1186 ts->original_id = dns->id;
1187 if (tunnels[ts->my_id] == ts)
1188 tunnels[ts->my_id] = NULL;
1189 ts->my_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1190 UINT16_MAX + 1);
1191 tunnels[ts->my_id] = ts;
1192 memcpy (buf, dns, dlen);
1193 dout = (struct GNUNET_TUN_DnsHeader *) buf;
1194 dout->id = ts->my_id;
1195 ts->rs = GNUNET_DNSSTUB_resolve2 (dnsstub,
1196 buf, dlen,
1197 &process_dns_result,
1198 NULL);
1199 if (NULL == ts->rs)
1200 return GNUNET_SYSERR;
1201 return GNUNET_OK;
1202}
1203
1204
1205/**
1206 * Callback from GNUNET_MESH for new tunnels.
1207 *
1208 * @param cls closure
1209 * @param tunnel new handle to the tunnel
1210 * @param initiator peer that started the tunnel
1211 * @param ats performance information for the tunnel
1212 * @return initial tunnel context for the tunnel
1213 */
1214static void *
1215accept_dns_tunnel (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1216 const struct GNUNET_PeerIdentity *initiator GNUNET_UNUSED,
1217 const struct GNUNET_ATS_Information *ats GNUNET_UNUSED)
1218{
1219 struct TunnelState *ts = GNUNET_malloc (sizeof (struct TunnelState));
1220
1221 GNUNET_STATISTICS_update (stats,
1222 gettext_noop ("# Inbound MESH tunnels created"),
1223 1, GNUNET_NO);
1224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1225 "Received inbound tunnel from `%s'\n",
1226 GNUNET_i2s (initiator));
1227 ts->tunnel = tunnel;
1228 return ts;
1229}
1230
1231
1232/**
1233 * Function called by mesh whenever an inbound tunnel is destroyed.
1234 * Should clean up any associated state.
1235 *
1236 * @param cls closure (set from GNUNET_MESH_connect)
1237 * @param tunnel connection to the other end (henceforth invalid)
1238 * @param tunnel_ctx place where local state associated
1239 * with the tunnel is stored
1240 */
1241static void
1242destroy_dns_tunnel (void *cls GNUNET_UNUSED,
1243 const struct GNUNET_MESH_Tunnel *tunnel,
1244 void *tunnel_ctx)
1245{
1246 struct TunnelState *ts = tunnel_ctx;
1247
1248 if (tunnels[ts->my_id] == ts)
1249 tunnels[ts->my_id] = NULL;
1250 if (NULL != ts->th)
1251 GNUNET_MESH_notify_transmit_ready_cancel (ts->th);
1252 GNUNET_free_non_null (ts->reply);
1253 GNUNET_free (ts);
1254}
1255
1256
1257/**
1258 * @param cls closure 1018 * @param cls closure
1259 * @param server the initialized server 1019 * @param server the initialized server
1260 * @param cfg_ configuration to use 1020 * @param cfg_ configuration to use
@@ -1298,9 +1058,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1298 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, 1058 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
1299 cls); 1059 cls);
1300 dns_exit = NULL; 1060 dns_exit = NULL;
1301 if ( (GNUNET_YES == 1061 if ( ( (GNUNET_OK !=
1302 GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT")) &&
1303 ( (GNUNET_OK !=
1304 GNUNET_CONFIGURATION_get_value_string (cfg, "dns", 1062 GNUNET_CONFIGURATION_get_value_string (cfg, "dns",
1305 "DNS_EXIT", 1063 "DNS_EXIT",
1306 &dns_exit)) || 1064 &dns_exit)) ||
@@ -1308,7 +1066,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1308 (1 != inet_pton (AF_INET6, dns_exit, &dns_exit6)) ) ) ) 1066 (1 != inet_pton (AF_INET6, dns_exit, &dns_exit6)) ) ) )
1309 { 1067 {
1310 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "dns", "DNS_EXIT", 1068 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "dns", "DNS_EXIT",
1311 _("need a valid IPv4 or IPv6 address\n")); 1069 _("need a valid IPv4 or IPv6 address\n"));
1312 GNUNET_free_non_null (dns_exit); 1070 GNUNET_free_non_null (dns_exit);
1313 dns_exit = NULL; 1071 dns_exit = NULL;
1314 } 1072 }
@@ -1365,24 +1123,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1365 } 1123 }
1366 helper_argv[5] = ipv4mask; 1124 helper_argv[5] = ipv4mask;
1367 helper_argv[6] = NULL; 1125 helper_argv[6] = NULL;
1368
1369 if (NULL != dns_exit)
1370 {
1371 static struct GNUNET_MESH_MessageHandler mesh_handlers[] = {
1372 {&receive_dns_request, GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET, 0},
1373 {NULL, 0, 0}
1374 };
1375 static GNUNET_MESH_ApplicationType mesh_types[] = {
1376 GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER,
1377 GNUNET_APPLICATION_TYPE_END
1378 };
1379 mesh = GNUNET_MESH_connect (cfg,
1380 NULL,
1381 &accept_dns_tunnel,
1382 &destroy_dns_tunnel,
1383 mesh_handlers,
1384 mesh_types);
1385 }
1386 hijacker = GNUNET_HELPER_start (GNUNET_NO, 1126 hijacker = GNUNET_HELPER_start (GNUNET_NO,
1387 "gnunet-helper-dns", 1127 "gnunet-helper-dns",
1388 helper_argv, 1128 helper_argv,