aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2011-07-27 07:28:19 +0000
committerPhilipp Tölke <toelke@in.tum.de>2011-07-27 07:28:19 +0000
commit2bafcee957905f901c23507d9542e5e2d75a17d9 (patch)
tree339fb5c51b6ddae5474182afde14e55da90027ca /src/vpn
parente8fac5ff0ff5dece01bdfd51a57a2af7b4117d52 (diff)
downloadgnunet-2bafcee957905f901c23507d9542e5e2d75a17d9.tar.gz
gnunet-2bafcee957905f901c23507d9542e5e2d75a17d9.zip
fix a bug in -dns exposed by kernel 2.6.39.3
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-service-dns.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c
index c0ef1411d..e876940c8 100644
--- a/src/vpn/gnunet-service-dns.c
+++ b/src/vpn/gnunet-service-dns.c
@@ -126,6 +126,13 @@ hijack (void *cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskCon
126 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 126 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
127 return; 127 return;
128 128
129 if (0 == dnsoutport)
130 {
131 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Delaying the hijacking, port is still %d!\n", dnsoutport);
132 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
133 return;
134 }
135
129 char port_s[6]; 136 char port_s[6];
130 char *virt_dns; 137 char *virt_dns;
131 struct GNUNET_OS_Process *proc; 138 struct GNUNET_OS_Process *proc;
@@ -378,6 +385,7 @@ receive_mesh_query (void *cls __attribute__((unused)),
378 /* TODO: read from config */ 385 /* TODO: read from config */
379 inet_pton(AF_INET, "8.8.8.8", &dest.sin_addr); 386 inet_pton(AF_INET, "8.8.8.8", &dest.sin_addr);
380 387
388 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Querying for remote, id=%d\n", ntohs(dns->s.id));
381 query_states[dns->s.id].tunnel = tunnel; 389 query_states[dns->s.id].tunnel = tunnel;
382 query_states[dns->s.id].valid = GNUNET_YES; 390 query_states[dns->s.id].valid = GNUNET_YES;
383 391
@@ -863,25 +871,26 @@ out:
863static void read_response (void *cls, 871static void read_response (void *cls,
864 const struct GNUNET_SCHEDULER_TaskContext *tc); 872 const struct GNUNET_SCHEDULER_TaskContext *tc);
865 873
866static void 874static int
867open_port () 875open_port ()
868{ 876{
869 struct sockaddr_in addr; 877 struct sockaddr_in addr;
870 878
871 dnsout = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0); 879 dnsout = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0);
872 if (dnsout == NULL) 880 if (dnsout == NULL)
873 return; 881 return GNUNET_SYSERR;
874 memset (&addr, 0, sizeof (struct sockaddr_in)); 882 memset (&addr, 0, sizeof (struct sockaddr_in));
875 883
884 addr.sin_family = AF_INET;
876 int err = GNUNET_NETWORK_socket_bind (dnsout, 885 int err = GNUNET_NETWORK_socket_bind (dnsout,
877 (struct sockaddr *) &addr, 886 (struct sockaddr *) &addr,
878 sizeof (struct sockaddr_in)); 887 sizeof (struct sockaddr_in));
879 888
880 if (err != GNUNET_YES) 889 if (err != GNUNET_OK)
881 { 890 {
882 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 891 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
883 "Could not bind a port, exiting\n"); 892 "Could not bind a port: %m\n");
884 return; 893 return GNUNET_SYSERR;
885 } 894 }
886 895
887 /* Read the port we bound to */ 896 /* Read the port we bound to */
@@ -891,8 +900,12 @@ open_port ()
891 900
892 dnsoutport = htons (addr.sin_port); 901 dnsoutport = htons (addr.sin_port);
893 902
903 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to port %d.\n", dnsoutport);
904
894 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout, 905 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout,
895 &read_response, NULL); 906 &read_response, NULL);
907
908 return GNUNET_YES;
896} 909}
897 910
898/** 911/**
@@ -917,8 +930,8 @@ read_response (void *cls
917 if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len)) 930 if (0 != ioctl (GNUNET_NETWORK_get_fd (dnsout), FIONREAD, &len))
918 { 931 {
919 unhijack (dnsoutport); 932 unhijack (dnsoutport);
920 open_port (); 933 if (GNUNET_YES == open_port ())
921 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL); 934 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
922 return; 935 return;
923 } 936 }
924#else 937#else
@@ -937,15 +950,18 @@ read_response (void *cls
937 if (r < 0) 950 if (r < 0)
938 { 951 {
939 unhijack (dnsoutport); 952 unhijack (dnsoutport);
940 open_port (); 953 if (GNUNET_YES == open_port ())
941 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL); 954 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, hijack, NULL);
942 return; 955 return;
943 } 956 }
944 957
958 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d\n", ntohs(dns->s.id));
959
945 if (query_states[dns->s.id].valid == GNUNET_YES) 960 if (query_states[dns->s.id].valid == GNUNET_YES)
946 { 961 {
947 if (query_states[dns->s.id].tunnel != NULL) 962 if (query_states[dns->s.id].tunnel != NULL)
948 { 963 {
964 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answer to query %d for a remote peer!\n", ntohs(dns->s.id));
949 /* This response should go through a tunnel */ 965 /* This response should go through a tunnel */
950 uint32_t *c = GNUNET_malloc (4 + sizeof(struct GNUNET_MESH_Tunnel*) + r); 966 uint32_t *c = GNUNET_malloc (4 + sizeof(struct GNUNET_MESH_Tunnel*) + r);
951 *c = r; 967 *c = r;
@@ -1271,6 +1287,12 @@ run (void *cls,
1271 1287
1272 static GNUNET_MESH_ApplicationType *apptypes; 1288 static GNUNET_MESH_ApplicationType *apptypes;
1273 1289
1290 if (GNUNET_YES != open_port ())
1291 {
1292 GNUNET_SCHEDULER_shutdown();
1293 return;
1294 }
1295
1274 if (GNUNET_YES == 1296 if (GNUNET_YES ==
1275 GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT")) 1297 GNUNET_CONFIGURATION_get_value_yesno (cfg_, "dns", "PROVIDE_EXIT"))
1276 apptypes = (GNUNET_MESH_ApplicationType[]) 1298 apptypes = (GNUNET_MESH_ApplicationType[])
@@ -1295,8 +1317,6 @@ run (void *cls,
1295 1317
1296 dht = GNUNET_DHT_connect (cfg, 1024); 1318 dht = GNUNET_DHT_connect (cfg, 1024);
1297 1319
1298 open_port ();
1299
1300 GNUNET_SCHEDULER_add_now (publish_names, NULL); 1320 GNUNET_SCHEDULER_add_now (publish_names, NULL);
1301 1321
1302 GNUNET_SERVER_add_handlers (server, handlers); 1322 GNUNET_SERVER_add_handlers (server, handlers);