aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/vpn
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-daemon-exit.c121
-rw-r--r--src/vpn/gnunet-daemon-vpn-dns.c8
-rw-r--r--src/vpn/gnunet-daemon-vpn-helper.c109
-rw-r--r--src/vpn/gnunet-daemon-vpn.c59
-rw-r--r--src/vpn/gnunet-dns-parser.c4
-rw-r--r--src/vpn/gnunet-helper-vpn-api.c19
-rw-r--r--src/vpn/gnunet-helper-vpn.c49
-rw-r--r--src/vpn/gnunet-service-dns.c174
8 files changed, 254 insertions, 289 deletions
diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c
index de906af3b..324c136b0 100644
--- a/src/vpn/gnunet-daemon-exit.c
+++ b/src/vpn/gnunet-daemon-exit.c
@@ -522,8 +522,7 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen,
522 * Receive packets from the helper-process 522 * Receive packets from the helper-process
523 */ 523 */
524static void 524static void
525message_token (void *cls __attribute__ ((unused)), 525message_token (void *cls __attribute__ ((unused)), void *client
526 void *client
527 __attribute__ ((unused)), 526 __attribute__ ((unused)),
528 const struct GNUNET_MessageHeader *message) 527 const struct GNUNET_MessageHeader *message)
529{ 528{
@@ -612,8 +611,8 @@ read_service_conf (void *cls __attribute__ ((unused)), const char *section)
612 "TCP_REDIRECTS", &cpy))) 611 "TCP_REDIRECTS", &cpy)))
613 goto next; 612 goto next;
614 613
615 for (redirect = strtok (cpy, " "); redirect != NULL; redirect = strtok 614 for (redirect = strtok (cpy, " "); redirect != NULL;
616 (NULL, " ")) 615 redirect = strtok (NULL, " "))
617 { 616 {
618 if (NULL == (hostname = strstr (redirect, ":"))) 617 if (NULL == (hostname = strstr (redirect, ":")))
619 { 618 {
@@ -654,8 +653,7 @@ read_service_conf (void *cls __attribute__ ((unused)), const char *section)
654 char *ip4addr; 653 char *ip4addr;
655 654
656 GNUNET_assert (GNUNET_OK == 655 GNUNET_assert (GNUNET_OK ==
657 GNUNET_CONFIGURATION_get_value_string (cfg, 656 GNUNET_CONFIGURATION_get_value_string (cfg, "exit",
658 "exit",
659 "IPV4ADDR", 657 "IPV4ADDR",
660 &ip4addr)); 658 &ip4addr));
661 GNUNET_assert (1 == inet_pton (AF_INET, ip4addr, serv->v4.ip4address)); 659 GNUNET_assert (1 == inet_pton (AF_INET, ip4addr, serv->v4.ip4address));
@@ -668,8 +666,7 @@ read_service_conf (void *cls __attribute__ ((unused)), const char *section)
668 char *ip6addr; 666 char *ip6addr;
669 667
670 GNUNET_assert (GNUNET_OK == 668 GNUNET_assert (GNUNET_OK ==
671 GNUNET_CONFIGURATION_get_value_string (cfg, 669 GNUNET_CONFIGURATION_get_value_string (cfg, "exit",
672 "exit",
673 "IPV6ADDR", 670 "IPV6ADDR",
674 &ip6addr)); 671 &ip6addr));
675 GNUNET_assert (1 == inet_pton (AF_INET6, ip6addr, serv->v6.ip6address)); 672 GNUNET_assert (1 == inet_pton (AF_INET6, ip6addr, serv->v6.ip6address));
@@ -774,13 +771,10 @@ start_helper_and_schedule (void *cls,
774 * When the helper dies, this function will be called again with the 771 * When the helper dies, this function will be called again with the
775 * helper_handle as cls. 772 * helper_handle as cls.
776 */ 773 */
777 helper_handle = start_helper (ifname, 774 helper_handle =
778 ipv6addr, 775 start_helper (ifname, ipv6addr, ipv6prefix, ipv4addr, ipv4mask,
779 ipv6prefix, 776 "exit-gnunet", start_helper_and_schedule, message_token,
780 ipv4addr, 777 NULL);
781 ipv4mask,
782 "exit-gnunet",
783 start_helper_and_schedule, message_token, NULL);
784 778
785 GNUNET_free (ipv6addr); 779 GNUNET_free (ipv6addr);
786 GNUNET_free (ipv6prefix); 780 GNUNET_free (ipv6prefix);
@@ -822,11 +816,11 @@ prepare_ipv4_packet (ssize_t len, ssize_t pktlen, void *payload,
822 char *ipv4mask; 816 char *ipv4mask;
823 817
824 GNUNET_assert (GNUNET_OK == 818 GNUNET_assert (GNUNET_OK ==
825 GNUNET_CONFIGURATION_get_value_string (cfg, "exit", 819 GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV4ADDR",
826 "IPV4ADDR", &ipv4addr)); 820 &ipv4addr));
827 GNUNET_assert (GNUNET_OK == 821 GNUNET_assert (GNUNET_OK ==
828 GNUNET_CONFIGURATION_get_value_string (cfg, "exit", 822 GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV4MASK",
829 "IPV4MASK", &ipv4mask)); 823 &ipv4mask));
830 inet_pton (AF_INET, ipv4addr, &tmp); 824 inet_pton (AF_INET, ipv4addr, &tmp);
831 inet_pton (AF_INET, ipv4mask, &tmp2); 825 inet_pton (AF_INET, ipv4mask, &tmp2);
832 GNUNET_free (ipv4addr); 826 GNUNET_free (ipv4addr);
@@ -910,8 +904,8 @@ prepare_ipv6_packet (ssize_t len, ssize_t pktlen, void *payload,
910 unsigned long long ipv6prefix; 904 unsigned long long ipv6prefix;
911 905
912 GNUNET_assert (GNUNET_OK == 906 GNUNET_assert (GNUNET_OK ==
913 GNUNET_CONFIGURATION_get_value_string (cfg, "exit", 907 GNUNET_CONFIGURATION_get_value_string (cfg, "exit", "IPV6ADDR",
914 "IPV6ADDR", &ipv6addr)); 908 &ipv6addr));
915 GNUNET_assert (GNUNET_OK == 909 GNUNET_assert (GNUNET_OK ==
916 GNUNET_CONFIGURATION_get_value_number (cfg, "exit", 910 GNUNET_CONFIGURATION_get_value_number (cfg, "exit",
917 "IPV6PREFIX", 911 "IPV6PREFIX",
@@ -987,9 +981,10 @@ prepare_ipv6_packet (ssize_t len, ssize_t pktlen, void *payload,
987 * The messages are one GNUNET_HashCode for the service followed by a struct tcp_pkt 981 * The messages are one GNUNET_HashCode for the service followed by a struct tcp_pkt
988 */ 982 */
989static int 983static int
990receive_tcp_service (void *cls __attribute__ ((unused)), 984receive_tcp_service (void *cls
991 struct GNUNET_MESH_Tunnel *tunnel, 985 __attribute__ ((unused)),
992 void **tunnel_ctx __attribute__ ((unused)), 986 struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx
987 __attribute__ ((unused)),
993 const struct GNUNET_PeerIdentity *sender 988 const struct GNUNET_PeerIdentity *sender
994 __attribute__ ((unused)), 989 __attribute__ ((unused)),
995 const struct GNUNET_MessageHeader *message, 990 const struct GNUNET_MessageHeader *message,
@@ -999,9 +994,9 @@ receive_tcp_service (void *cls __attribute__ ((unused)),
999 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet\n"); 994 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet\n");
1000 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); 995 GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1);
1001 struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); 996 struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1);
1002 unsigned int pkt_len = ntohs (message->size) - sizeof (struct 997 unsigned int pkt_len =
1003 GNUNET_MessageHeader) 998 ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
1004 - sizeof (GNUNET_HashCode); 999 sizeof (GNUNET_HashCode);
1005 1000
1006 /** Get the configuration from the services-hashmap. 1001 /** Get the configuration from the services-hashmap.
1007 * 1002 *
@@ -1018,8 +1013,8 @@ receive_tcp_service (void *cls __attribute__ ((unused)),
1018 1013
1019 if (NULL == serv) 1014 if (NULL == serv)
1020 { 1015 {
1021 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1016 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "No service found for TCP dpt %d!\n",
1022 "No service found for TCP dpt %d!\n", *tcp_desc); 1017 *tcp_desc);
1023 return GNUNET_YES; 1018 return GNUNET_YES;
1024 } 1019 }
1025 1020
@@ -1045,7 +1040,8 @@ receive_tcp_service (void *cls __attribute__ ((unused)),
1045 state->hashmap = tcp_connections; 1040 state->hashmap = tcp_connections;
1046 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode)); 1041 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode));
1047 1042
1048 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + 1043 len =
1044 sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
1049 sizeof (struct ip6_hdr) + pkt_len; 1045 sizeof (struct ip6_hdr) + pkt_len;
1050 buf = alloca (len); 1046 buf = alloca (len);
1051 1047
@@ -1055,13 +1051,13 @@ receive_tcp_service (void *cls __attribute__ ((unused)),
1055 { 1051 {
1056 case 4: 1052 case 4:
1057 prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */ 1053 prepare_ipv4_packet (len, pkt_len, pkt, 0x06, /* TCP */
1058 &serv->v4.ip4address, 1054 &serv->v4.ip4address, tunnel, state,
1059 tunnel, state, (struct ip_pkt *) buf); 1055 (struct ip_pkt *) buf);
1060 break; 1056 break;
1061 case 6: 1057 case 6:
1062 prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */ 1058 prepare_ipv6_packet (len, pkt_len, pkt, 0x06, /* TCP */
1063 &serv->v6.ip6address, 1059 &serv->v6.ip6address, tunnel, state,
1064 tunnel, state, (struct ip6_pkt *) buf); 1060 (struct ip6_pkt *) buf);
1065 1061
1066 break; 1062 break;
1067 default: 1063 default:
@@ -1094,9 +1090,10 @@ receive_tcp_service (void *cls __attribute__ ((unused)),
1094} 1090}
1095 1091
1096static int 1092static int
1097receive_tcp_remote (void *cls __attribute__ ((unused)), 1093receive_tcp_remote (void *cls
1098 struct GNUNET_MESH_Tunnel *tunnel, 1094 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
1099 void **tunnel_ctx __attribute__ ((unused)), 1095 void **tunnel_ctx
1096 __attribute__ ((unused)),
1100 const struct GNUNET_PeerIdentity *sender 1097 const struct GNUNET_PeerIdentity *sender
1101 __attribute__ ((unused)), 1098 __attribute__ ((unused)),
1102 const struct GNUNET_MessageHeader *message, 1099 const struct GNUNET_MessageHeader *message,
@@ -1120,7 +1117,8 @@ receive_tcp_remote (void *cls __attribute__ ((unused)),
1120 state->hashmap = tcp_connections; 1117 state->hashmap = tcp_connections;
1121 memcpy (&state->remote, s, sizeof (struct remote_addr)); 1118 memcpy (&state->remote, s, sizeof (struct remote_addr));
1122 1119
1123 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + 1120 len =
1121 sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
1124 sizeof (struct ip6_hdr) + pkt_len; 1122 sizeof (struct ip6_hdr) + pkt_len;
1125 buf = alloca (len); 1123 buf = alloca (len);
1126 1124
@@ -1169,9 +1167,10 @@ receive_tcp_remote (void *cls __attribute__ ((unused)),
1169} 1167}
1170 1168
1171static int 1169static int
1172receive_udp_remote (void *cls __attribute__ ((unused)), 1170receive_udp_remote (void *cls
1173 struct GNUNET_MESH_Tunnel *tunnel, 1171 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
1174 void **tunnel_ctx __attribute__ ((unused)), 1172 void **tunnel_ctx
1173 __attribute__ ((unused)),
1175 const struct GNUNET_PeerIdentity *sender 1174 const struct GNUNET_PeerIdentity *sender
1176 __attribute__ ((unused)), 1175 __attribute__ ((unused)),
1177 const struct GNUNET_MessageHeader *message, 1176 const struct GNUNET_MessageHeader *message,
@@ -1185,8 +1184,7 @@ receive_udp_remote (void *cls __attribute__ ((unused)),
1185 size_t len; 1184 size_t len;
1186 1185
1187 GNUNET_assert (ntohs (pkt->len) == 1186 GNUNET_assert (ntohs (pkt->len) ==
1188 ntohs (message->size) - 1187 ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
1189 sizeof (struct GNUNET_MessageHeader) -
1190 sizeof (GNUNET_HashCode)); 1188 sizeof (GNUNET_HashCode));
1191 1189
1192 /* Prepare the state. 1190 /* Prepare the state.
@@ -1201,7 +1199,8 @@ receive_udp_remote (void *cls __attribute__ ((unused)),
1201 state->type = REMOTE; 1199 state->type = REMOTE;
1202 memcpy (&state->remote, s, sizeof (struct remote_addr)); 1200 memcpy (&state->remote, s, sizeof (struct remote_addr));
1203 1201
1204 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + 1202 len =
1203 sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
1205 sizeof (struct ip6_hdr) + ntohs (pkt->len); 1204 sizeof (struct ip6_hdr) + ntohs (pkt->len);
1206 buf = alloca (len); 1205 buf = alloca (len);
1207 1206
@@ -1249,9 +1248,10 @@ receive_udp_remote (void *cls __attribute__ ((unused)),
1249 * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt 1248 * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt
1250 */ 1249 */
1251static int 1250static int
1252receive_udp_service (void *cls __attribute__ ((unused)), 1251receive_udp_service (void *cls
1253 struct GNUNET_MESH_Tunnel *tunnel, 1252 __attribute__ ((unused)),
1254 void **tunnel_ctx __attribute__ ((unused)), 1253 struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx
1254 __attribute__ ((unused)),
1255 const struct GNUNET_PeerIdentity *sender 1255 const struct GNUNET_PeerIdentity *sender
1256 __attribute__ ((unused)), 1256 __attribute__ ((unused)),
1257 const struct GNUNET_MessageHeader *message, 1257 const struct GNUNET_MessageHeader *message,
@@ -1262,8 +1262,7 @@ receive_udp_service (void *cls __attribute__ ((unused)),
1262 struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); 1262 struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
1263 1263
1264 GNUNET_assert (ntohs (pkt->len) == 1264 GNUNET_assert (ntohs (pkt->len) ==
1265 ntohs (message->size) - 1265 ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
1266 sizeof (struct GNUNET_MessageHeader) -
1267 sizeof (GNUNET_HashCode)); 1266 sizeof (GNUNET_HashCode));
1268 1267
1269 /* Get the configuration from the hashmap */ 1268 /* Get the configuration from the hashmap */
@@ -1277,8 +1276,8 @@ receive_udp_service (void *cls __attribute__ ((unused)),
1277 1276
1278 if (NULL == serv) 1277 if (NULL == serv)
1279 { 1278 {
1280 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1279 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "No service found for UDP dpt %d!\n",
1281 "No service found for UDP dpt %d!\n", *udp_desc); 1280 *udp_desc);
1282 return GNUNET_YES; 1281 return GNUNET_YES;
1283 } 1282 }
1284 1283
@@ -1304,7 +1303,8 @@ receive_udp_service (void *cls __attribute__ ((unused)),
1304 state->hashmap = udp_connections; 1303 state->hashmap = udp_connections;
1305 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode)); 1304 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode));
1306 1305
1307 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + 1306 len =
1307 sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
1308 sizeof (struct ip6_hdr) + ntohs (pkt->len); 1308 sizeof (struct ip6_hdr) + ntohs (pkt->len);
1309 buf = alloca (len); 1309 buf = alloca (len);
1310 1310
@@ -1314,13 +1314,13 @@ receive_udp_service (void *cls __attribute__ ((unused)),
1314 { 1314 {
1315 case 4: 1315 case 4:
1316 prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ 1316 prepare_ipv4_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
1317 &serv->v4.ip4address, 1317 &serv->v4.ip4address, tunnel, state,
1318 tunnel, state, (struct ip_pkt *) buf); 1318 (struct ip_pkt *) buf);
1319 break; 1319 break;
1320 case 6: 1320 case 6:
1321 prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */ 1321 prepare_ipv6_packet (len, ntohs (pkt->len), pkt, 0x11, /* UDP */
1322 &serv->v6.ip6address, 1322 &serv->v6.ip6address, tunnel, state,
1323 tunnel, state, (struct ip6_pkt *) buf); 1323 (struct ip6_pkt *) buf);
1324 1324
1325 break; 1325 break;
1326 default: 1326 default:
@@ -1410,9 +1410,7 @@ connect_to_mesh ()
1410 * @param cfg_ configuration 1410 * @param cfg_ configuration
1411 */ 1411 */
1412static void 1412static void
1413run (void *cls, 1413run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfile
1414 char *const *args __attribute__ ((unused)),
1415 const char *cfgfile
1416 __attribute__ ((unused)), const struct GNUNET_CONFIGURATION_Handle *cfg_) 1414 __attribute__ ((unused)), const struct GNUNET_CONFIGURATION_Handle *cfg_)
1417{ 1415{
1418 cfg = cfg_; 1416 cfg = cfg_;
@@ -1454,10 +1452,7 @@ main (int argc, char *const *argv)
1454 }; 1452 };
1455 1453
1456 return (GNUNET_OK == 1454 return (GNUNET_OK ==
1457 GNUNET_PROGRAM_run (argc, 1455 GNUNET_PROGRAM_run (argc, argv, "exit", gettext_noop ("help text"),
1458 argv,
1459 "exit",
1460 gettext_noop ("help text"),
1461 options, &run, NULL)) ? ret : 1; 1456 options, &run, NULL)) ? ret : 1;
1462} 1457}
1463 1458
diff --git a/src/vpn/gnunet-daemon-vpn-dns.c b/src/vpn/gnunet-daemon-vpn-dns.c
index d6f842e34..9ee81011e 100644
--- a/src/vpn/gnunet-daemon-vpn-dns.c
+++ b/src/vpn/gnunet-daemon-vpn-dns.c
@@ -120,7 +120,8 @@ send_query (void *cls __attribute__ ((unused)), size_t size, void *buf)
120 * Connect to the service-dns 120 * Connect to the service-dns
121 */ 121 */
122void 122void
123connect_to_service_dns (void *cls __attribute__ ((unused)), 123connect_to_service_dns (void *cls
124 __attribute__ ((unused)),
124 const struct GNUNET_SCHEDULER_TaskContext *tc) 125 const struct GNUNET_SCHEDULER_TaskContext *tc)
125{ 126{
126 conn_task = GNUNET_SCHEDULER_NO_TASK; 127 conn_task = GNUNET_SCHEDULER_NO_TASK;
@@ -167,8 +168,9 @@ dns_answer_handler (void *cls
167 { 168 {
168 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO); 169 GNUNET_CLIENT_disconnect (dns_connection, GNUNET_NO);
169 dns_connection = NULL; 170 dns_connection = NULL;
170 conn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 171 conn_task =
171 &connect_to_service_dns, NULL); 172 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
173 &connect_to_service_dns, NULL);
172 return; 174 return;
173 } 175 }
174 176
diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c
index 65e92b8f9..71fdefc0a 100644
--- a/src/vpn/gnunet-daemon-vpn-helper.c
+++ b/src/vpn/gnunet-daemon-vpn-helper.c
@@ -122,13 +122,10 @@ start_helper_and_schedule (void *cls,
122 * When the helper dies, this function will be called again with the 122 * When the helper dies, this function will be called again with the
123 * helper_handle as cls. 123 * helper_handle as cls.
124 */ 124 */
125 helper_handle = start_helper (ifname, 125 helper_handle =
126 ipv6addr, 126 start_helper (ifname, ipv6addr, ipv6prefix, ipv4addr, ipv4mask,
127 ipv6prefix, 127 "vpn-gnunet", start_helper_and_schedule, message_token,
128 ipv4addr, 128 NULL);
129 ipv4mask,
130 "vpn-gnunet",
131 start_helper_and_schedule, message_token, NULL);
132 129
133 GNUNET_free (ipv6addr); 130 GNUNET_free (ipv6addr);
134 GNUNET_free (ipv6prefix); 131 GNUNET_free (ipv6prefix);
@@ -230,16 +227,15 @@ helper_write (void *cls
230 /* if more packets are available, reschedule */ 227 /* if more packets are available, reschedule */
231 if (answer_proc_head != NULL) 228 if (answer_proc_head != NULL)
232 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 229 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
233 helper_handle->fh_to_helper, 230 helper_handle->fh_to_helper, &helper_write,
234 &helper_write, NULL); 231 NULL);
235} 232}
236 233
237/** 234/**
238 * Receive packets from the helper-process 235 * Receive packets from the helper-process
239 */ 236 */
240void 237void
241message_token (void *cls __attribute__ ((unused)), 238message_token (void *cls __attribute__ ((unused)), void *client
242 void *client
243 __attribute__ ((unused)), 239 __attribute__ ((unused)),
244 const struct GNUNET_MessageHeader *message) 240 const struct GNUNET_MessageHeader *message)
245{ 241{
@@ -274,17 +270,17 @@ message_token (void *cls __attribute__ ((unused)),
274 270
275 size_t size = 271 size_t size =
276 sizeof (struct GNUNET_MESH_Tunnel *) + 272 sizeof (struct GNUNET_MESH_Tunnel *) +
277 sizeof (struct GNUNET_MessageHeader) + 273 sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) +
278 sizeof (GNUNET_HashCode) + ntohs (pkt6->ip6_hdr.paylgth); 274 ntohs (pkt6->ip6_hdr.paylgth);
279 275
280 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size); 276 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
281 struct GNUNET_MessageHeader *hdr = 277 struct GNUNET_MessageHeader *hdr =
282 (struct GNUNET_MessageHeader *) (cls + 1); 278 (struct GNUNET_MessageHeader *) (cls + 1);
283 GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1); 279 GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1);
284 280
285 hdr->size = htons (sizeof (struct GNUNET_MessageHeader) + 281 hdr->size =
286 sizeof (GNUNET_HashCode) + 282 htons (sizeof (struct GNUNET_MessageHeader) +
287 ntohs (pkt6->ip6_hdr.paylgth)); 283 sizeof (GNUNET_HashCode) + ntohs (pkt6->ip6_hdr.paylgth));
288 284
289 GNUNET_MESH_ApplicationType app_type; 285 GNUNET_MESH_ApplicationType app_type;
290 286
@@ -295,21 +291,19 @@ message_token (void *cls __attribute__ ((unused)),
295 /* This is a mapping to a gnunet-service */ 291 /* This is a mapping to a gnunet-service */
296 memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode)); 292 memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode));
297 293
298 if (0x11 == pkt6->ip6_hdr.nxthdr 294 if (0x11 == pkt6->ip6_hdr.nxthdr &&
299 && (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) 295 (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) &&
300 && (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt) 296 (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt) ||
301 || testBit (me->additional_ports, 297 testBit (me->additional_ports, ntohs (pkt6_udp->udp_hdr.dpt))))
302 ntohs (pkt6_udp->udp_hdr.dpt))))
303 { 298 {
304 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP); 299 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
305 300
306 memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len)); 301 memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len));
307 302
308 } 303 }
309 else if (0x06 == pkt6->ip6_hdr.nxthdr 304 else if (0x06 == pkt6->ip6_hdr.nxthdr &&
310 && (me->desc. 305 (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP))
311 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP)) && 306 && (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)))
312 (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)))
313 { 307 {
314 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP); 308 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
315 309
@@ -323,10 +317,10 @@ message_token (void *cls __attribute__ ((unused)),
323 GNUNET_TIME_UNIT_FOREVER_REL, 317 GNUNET_TIME_UNIT_FOREVER_REL,
324 1, 318 1,
325 (struct 319 (struct
326 GNUNET_PeerIdentity 320 GNUNET_PeerIdentity *)
327 *) &me->desc.peer, 321 &me->desc.peer,
328 send_pkt_to_peer, 322 send_pkt_to_peer, NULL,
329 NULL, cls); 323 cls);
330 me->tunnel = *cls; 324 me->tunnel = *cls;
331 } 325 }
332 else if (NULL != cls) 326 else if (NULL != cls)
@@ -364,11 +358,12 @@ message_token (void *cls __attribute__ ((unused)),
364 } 358 }
365 if (me->tunnel == NULL && NULL != cls) 359 if (me->tunnel == NULL && NULL != cls)
366 { 360 {
367 *cls = GNUNET_MESH_peer_request_connect_by_type (mesh_handle, 361 *cls =
368 GNUNET_TIME_UNIT_FOREVER_REL, 362 GNUNET_MESH_peer_request_connect_by_type (mesh_handle,
369 app_type, 363 GNUNET_TIME_UNIT_FOREVER_REL,
370 send_pkt_to_peer, 364 app_type,
371 NULL, cls); 365 send_pkt_to_peer,
366 NULL, cls);
372 me->tunnel = *cls; 367 me->tunnel = *cls;
373 if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type) 368 if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type)
374 udp_tunnel = *cls; 369 udp_tunnel = *cls;
@@ -400,8 +395,8 @@ message_token (void *cls __attribute__ ((unused)),
400 /* ICMPv6 */ 395 /* ICMPv6 */
401 pkt6_icmp = (struct ip6_icmp *) pkt6; 396 pkt6_icmp = (struct ip6_icmp *) pkt6;
402 /* If this packet is an icmp-echo-request and a mapping exists, answer */ 397 /* If this packet is an icmp-echo-request and a mapping exists, answer */
403 if (pkt6_icmp->icmp_hdr.type == 0x80 398 if (pkt6_icmp->icmp_hdr.type == 0x80 &&
404 && (key = address6_mapping_exists (pkt6->ip6_hdr.dadr)) != NULL) 399 (key = address6_mapping_exists (pkt6->ip6_hdr.dadr)) != NULL)
405 { 400 {
406 GNUNET_free (key); 401 GNUNET_free (key);
407 pkt6_icmp = GNUNET_malloc (ntohs (pkt6->shdr.size)); 402 pkt6_icmp = GNUNET_malloc (ntohs (pkt6->shdr.size));
@@ -442,8 +437,7 @@ message_token (void *cls __attribute__ ((unused)),
442 GNUNET_assert (head != NULL); 437 GNUNET_assert (head != NULL);
443 438
444 if (dns_connection != NULL) 439 if (dns_connection != NULL)
445 GNUNET_CLIENT_notify_transmit_ready (dns_connection, 440 GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
446 len,
447 GNUNET_TIME_UNIT_FOREVER_REL, 441 GNUNET_TIME_UNIT_FOREVER_REL,
448 GNUNET_YES, &send_query, NULL); 442 GNUNET_YES, &send_query, NULL);
449 } 443 }
@@ -470,9 +464,8 @@ message_token (void *cls __attribute__ ((unused)),
470 464
471 size_t size = 465 size_t size =
472 sizeof (struct GNUNET_MESH_Tunnel *) + 466 sizeof (struct GNUNET_MESH_Tunnel *) +
473 sizeof (struct GNUNET_MessageHeader) + 467 sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) +
474 sizeof (GNUNET_HashCode) + ntohs (pkt->ip_hdr.tot_lngth) - 468 ntohs (pkt->ip_hdr.tot_lngth) - 4 * pkt->ip_hdr.hdr_lngth;
475 4 * pkt->ip_hdr.hdr_lngth;
476 469
477 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size); 470 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
478 struct GNUNET_MessageHeader *hdr = 471 struct GNUNET_MessageHeader *hdr =
@@ -493,20 +486,19 @@ message_token (void *cls __attribute__ ((unused)),
493 /* This is a mapping to a gnunet-service */ 486 /* This is a mapping to a gnunet-service */
494 memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode)); 487 memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode));
495 488
496 if (0x11 == pkt->ip_hdr.proto 489 if (0x11 == pkt->ip_hdr.proto &&
497 && (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) 490 (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) &&
498 && (port_in_ports (me->desc.ports, pkt_udp->udp_hdr.dpt) 491 (port_in_ports (me->desc.ports, pkt_udp->udp_hdr.dpt) ||
499 || testBit (me->additional_ports, 492 testBit (me->additional_ports, ntohs (pkt_udp->udp_hdr.dpt))))
500 ntohs (pkt_udp->udp_hdr.dpt))))
501 { 493 {
502 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP); 494 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
503 495
504 memcpy (hc + 1, &pkt_udp->udp_hdr, ntohs (pkt_udp->udp_hdr.len)); 496 memcpy (hc + 1, &pkt_udp->udp_hdr, ntohs (pkt_udp->udp_hdr.len));
505 497
506 } 498 }
507 else if (0x06 == pkt->ip_hdr.proto 499 else if (0x06 == pkt->ip_hdr.proto &&
508 && (me->desc.service_type & 500 (me->desc.
509 htonl (GNUNET_DNS_SERVICE_TYPE_TCP)) && 501 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP)) &&
510 (port_in_ports (me->desc.ports, pkt_tcp->tcp_hdr.dpt))) 502 (port_in_ports (me->desc.ports, pkt_tcp->tcp_hdr.dpt)))
511 { 503 {
512 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP); 504 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
@@ -523,10 +515,10 @@ message_token (void *cls __attribute__ ((unused)),
523 GNUNET_TIME_UNIT_FOREVER_REL, 515 GNUNET_TIME_UNIT_FOREVER_REL,
524 1, 516 1,
525 (struct 517 (struct
526 GNUNET_PeerIdentity 518 GNUNET_PeerIdentity *)
527 *) &me->desc.peer, 519 &me->desc.peer,
528 send_pkt_to_peer, 520 send_pkt_to_peer, NULL,
529 NULL, cls); 521 cls);
530 me->tunnel = *cls; 522 me->tunnel = *cls;
531 } 523 }
532 else if (NULL != cls) 524 else if (NULL != cls)
@@ -563,11 +555,12 @@ message_token (void *cls __attribute__ ((unused)),
563 } 555 }
564 if (me->tunnel == NULL && NULL != cls) 556 if (me->tunnel == NULL && NULL != cls)
565 { 557 {
566 *cls = GNUNET_MESH_peer_request_connect_by_type (mesh_handle, 558 *cls =
567 GNUNET_TIME_UNIT_FOREVER_REL, 559 GNUNET_MESH_peer_request_connect_by_type (mesh_handle,
568 app_type, 560 GNUNET_TIME_UNIT_FOREVER_REL,
569 send_pkt_to_peer, 561 app_type,
570 NULL, cls); 562 send_pkt_to_peer,
563 NULL, cls);
571 me->tunnel = *cls; 564 me->tunnel = *cls;
572 } 565 }
573 else if (NULL != cls) 566 else if (NULL != cls)
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c
index 3673b72c6..301ba90be 100644
--- a/src/vpn/gnunet-daemon-vpn.c
+++ b/src/vpn/gnunet-daemon-vpn.c
@@ -332,8 +332,7 @@ port_in_ports (uint64_t ports, uint16_t port)
332} 332}
333 333
334void 334void
335send_pkt_to_peer (void *cls, 335send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer,
336 const struct GNUNET_PeerIdentity *peer,
337 const struct GNUNET_TRANSPORT_ATS_Information *atsi 336 const struct GNUNET_TRANSPORT_ATS_Information *atsi
338 __attribute__ ((unused))) 337 __attribute__ ((unused)))
339{ 338{
@@ -429,8 +428,8 @@ new_ip6addr_remote (unsigned char *buf, unsigned char *addr, char addrlen)
429 unsigned long long ipv6prefix; 428 unsigned long long ipv6prefix;
430 429
431 GNUNET_assert (GNUNET_OK == 430 GNUNET_assert (GNUNET_OK ==
432 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", 431 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6ADDR",
433 "IPV6ADDR", &ipv6addr)); 432 &ipv6addr));
434 GNUNET_assert (GNUNET_OK == 433 GNUNET_assert (GNUNET_OK ==
435 GNUNET_CONFIGURATION_get_value_number (cfg, "vpn", 434 GNUNET_CONFIGURATION_get_value_number (cfg, "vpn",
436 "IPV6PREFIX", 435 "IPV6PREFIX",
@@ -458,11 +457,11 @@ new_ip4addr_remote (unsigned char *buf, unsigned char *addr, char addrlen)
458 char *ipv4mask; 457 char *ipv4mask;
459 458
460 GNUNET_assert (GNUNET_OK == 459 GNUNET_assert (GNUNET_OK ==
461 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", 460 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR",
462 "IPV4ADDR", &ipv4addr)); 461 &ipv4addr));
463 GNUNET_assert (GNUNET_OK == 462 GNUNET_assert (GNUNET_OK ==
464 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", 463 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4MASK",
465 "IPV4MASK", &ipv4mask)); 464 &ipv4mask));
466 uint32_t mask; 465 uint32_t mask;
467 466
468 inet_pton (AF_INET, ipv4addr, buf); 467 inet_pton (AF_INET, ipv4addr, buf);
@@ -568,9 +567,9 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
568 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value, 567 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
569 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 568 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
570 569
571 value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value, 570 value->heap_node =
572 GNUNET_TIME_absolute_get 571 GNUNET_CONTAINER_heap_insert (heap, value,
573 ().abs_value); 572 GNUNET_TIME_absolute_get ().abs_value);
574 if (GNUNET_CONTAINER_heap_get_size (heap) > max_mappings) 573 if (GNUNET_CONTAINER_heap_get_size (heap) > max_mappings)
575 GNUNET_SCHEDULER_add_now (collect_mappings, NULL); 574 GNUNET_SCHEDULER_add_now (collect_mappings, NULL);
576 } 575 }
@@ -696,9 +695,9 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
696 { 695 {
697 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value, 696 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
698 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 697 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
699 value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value, 698 value->heap_node =
700 GNUNET_TIME_absolute_get 699 GNUNET_CONTAINER_heap_insert (heap, value,
701 ().abs_value); 700 GNUNET_TIME_absolute_get ().abs_value);
702 if (GNUNET_CONTAINER_heap_get_size (heap) > max_mappings) 701 if (GNUNET_CONTAINER_heap_get_size (heap) > max_mappings)
703 GNUNET_SCHEDULER_add_now (collect_mappings, NULL); 702 GNUNET_SCHEDULER_add_now (collect_mappings, NULL);
704 } 703 }
@@ -722,8 +721,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
722 unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset); 721 unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset);
723 722
724 new_ip4addr_remote (c, pkt->addr, pkt->addrsize); 723 new_ip4addr_remote (c, pkt->addr, pkt->addrsize);
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New mapping to %d.%d.%d.%d\n", 724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New mapping to %d.%d.%d.%d\n", c[0],
726 c[0], c[1], c[2], c[3]); 725 c[1], c[2], c[3]);
727 unsigned char *k = (unsigned char *) &key; 726 unsigned char *k = (unsigned char *) &key;
728 727
729 /* 728 /*
@@ -755,9 +754,9 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
755 { 754 {
756 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value, 755 GNUNET_CONTAINER_multihashmap_put (hashmap, &key, value,
757 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 756 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
758 value->heap_node = GNUNET_CONTAINER_heap_insert (heap, value, 757 value->heap_node =
759 GNUNET_TIME_absolute_get 758 GNUNET_CONTAINER_heap_insert (heap, value,
760 ().abs_value); 759 GNUNET_TIME_absolute_get ().abs_value);
761 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
762 "Mapping is saved in the hashmap with key %08x.\n", 761 "Mapping is saved in the hashmap with key %08x.\n",
763 *((uint32_t *) (&key))); 762 *((uint32_t *) (&key)));
@@ -860,7 +859,8 @@ add_additional_port (struct map_entry *me, uint16_t port)
860static int 859static int
861receive_udp_back (void *cls 860receive_udp_back (void *cls
862 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, 861 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
863 void **tunnel_ctx __attribute__ ((unused)), 862 void **tunnel_ctx
863 __attribute__ ((unused)),
864 const struct GNUNET_PeerIdentity *sender 864 const struct GNUNET_PeerIdentity *sender
865 __attribute__ ((unused)), 865 __attribute__ ((unused)),
866 const struct GNUNET_MessageHeader *message, 866 const struct GNUNET_MessageHeader *message,
@@ -931,8 +931,8 @@ receive_udp_back (void *cls
931 GNUNET_assert (me != NULL); 931 GNUNET_assert (me != NULL);
932 if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK) 932 if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
933 { 933 {
934 GNUNET_assert (me->desc. 934 GNUNET_assert (me->
935 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)); 935 desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP));
936 if (!port_in_ports (me->desc.ports, pkt6->udp_hdr.spt) && 936 if (!port_in_ports (me->desc.ports, pkt6->udp_hdr.spt) &&
937 !testBit (me->additional_ports, ntohs (pkt6->udp_hdr.spt))) 937 !testBit (me->additional_ports, ntohs (pkt6->udp_hdr.spt)))
938 { 938 {
@@ -1109,8 +1109,8 @@ receive_tcp_back (void *cls
1109 1109
1110 GNUNET_assert (me != NULL); 1110 GNUNET_assert (me != NULL);
1111 if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK) 1111 if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
1112 GNUNET_assert (me->desc. 1112 GNUNET_assert (me->
1113 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP)); 1113 desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP));
1114 1114
1115 pkt6->tcp_hdr.crc = 0; 1115 pkt6->tcp_hdr.crc = 0;
1116 uint32_t sum = 0; 1116 uint32_t sum = 0;
@@ -1228,10 +1228,8 @@ receive_tcp_back (void *cls
1228 * @param cfg_ configuration 1228 * @param cfg_ configuration
1229 */ 1229 */
1230static void 1230static void
1231run (void *cls, 1231run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfilep
1232 char *const *args __attribute__ ((unused)), 1232 __attribute__ ((unused)), const struct GNUNET_CONFIGURATION_Handle *cfg_)
1233 const char *cfgfilep __attribute__ ((unused)),
1234 const struct GNUNET_CONFIGURATION_Handle *cfg_)
1235{ 1233{
1236 static const struct GNUNET_MESH_MessageHandler handlers[] = { 1234 static const struct GNUNET_MESH_MessageHandler handlers[] = {
1237 {receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK, 0}, 1235 {receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK, 0},
@@ -1274,10 +1272,7 @@ main (int argc, char *const *argv)
1274 }; 1272 };
1275 1273
1276 return (GNUNET_OK == 1274 return (GNUNET_OK ==
1277 GNUNET_PROGRAM_run (argc, 1275 GNUNET_PROGRAM_run (argc, argv, "vpn", gettext_noop ("help text"),
1278 argv,
1279 "vpn",
1280 gettext_noop ("help text"),
1281 options, &run, NULL)) ? ret : 1; 1276 options, &run, NULL)) ? ret : 1;
1282} 1277}
1283 1278
diff --git a/src/vpn/gnunet-dns-parser.c b/src/vpn/gnunet-dns-parser.c
index 70551af52..df0e63ed7 100644
--- a/src/vpn/gnunet-dns-parser.c
+++ b/src/vpn/gnunet-dns-parser.c
@@ -51,8 +51,8 @@ parse_dns_name (char *d, const unsigned char *src, unsigned short idx)
51 */ 51 */
52static unsigned short 52static unsigned short
53parse_dns_record (unsigned char *data, /*{{{ */ 53parse_dns_record (unsigned char *data, /*{{{ */
54 struct dns_record **dst, 54 struct dns_record **dst, unsigned short count,
55 unsigned short count, unsigned short idx) 55 unsigned short idx)
56{ 56{
57 int i; 57 int i;
58 unsigned short _idx; 58 unsigned short _idx;
diff --git a/src/vpn/gnunet-helper-vpn-api.c b/src/vpn/gnunet-helper-vpn-api.c
index 16bfcbd2e..379e75765 100644
--- a/src/vpn/gnunet-helper-vpn-api.c
+++ b/src/vpn/gnunet-helper-vpn-api.c
@@ -74,8 +74,9 @@ helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tsdkctx)
74 stop_helper (handle); 74 stop_helper (handle);
75 75
76 /* Restart the helper */ 76 /* Restart the helper */
77 shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 77 shs_task =
78 handle->restart_task, handle); 78 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
79 handle->restart_task, handle);
79 return; 80 return;
80 } 81 }
81 82
@@ -86,8 +87,9 @@ helper_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tsdkctx)
86 stop_helper (handle); 87 stop_helper (handle);
87 88
88 /* Restart the helper */ 89 /* Restart the helper */
89 shs_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 90 shs_task =
90 handle->restart_task, handle); 91 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
92 handle->restart_task, handle);
91 return; 93 return;
92 94
93 } 95 }
@@ -104,12 +106,9 @@ cleanup_helper (struct GNUNET_VPN_HELPER_Handle *handle)
104} 106}
105 107
106struct GNUNET_VPN_HELPER_Handle * 108struct GNUNET_VPN_HELPER_Handle *
107start_helper (const char *ifname, 109start_helper (const char *ifname, const char *ipv6addr, const char *ipv6prefix,
108 const char *ipv6addr, 110 const char *ipv4addr, const char *ipv4mask,
109 const char *ipv6prefix, 111 const char *process_name, GNUNET_SCHEDULER_Task restart_task,
110 const char *ipv4addr,
111 const char *ipv4mask, const char *process_name,
112 GNUNET_SCHEDULER_Task restart_task,
113 GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls) 112 GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls)
114{ 113{
115 struct GNUNET_VPN_HELPER_Handle *handle = 114 struct GNUNET_VPN_HELPER_Handle *handle =
diff --git a/src/vpn/gnunet-helper-vpn.c b/src/vpn/gnunet-helper-vpn.c
index 698c46f1d..ed97770cf 100644
--- a/src/vpn/gnunet-helper-vpn.c
+++ b/src/vpn/gnunet-helper-vpn.c
@@ -81,8 +81,8 @@ init_tun (char *dev)
81 81
82 if (-1 == (fd = open ("/dev/net/tun", O_RDWR))) 82 if (-1 == (fd = open ("/dev/net/tun", O_RDWR)))
83 { 83 {
84 fprintf (stderr, 84 fprintf (stderr, "Error opening `%s': %s\n", "/dev/net/tun",
85 "Error opening `%s': %s\n", "/dev/net/tun", strerror (errno)); 85 strerror (errno));
86 return -1; 86 return -1;
87 } 87 }
88 88
@@ -100,9 +100,8 @@ init_tun (char *dev)
100 100
101 if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr)) 101 if (-1 == ioctl (fd, TUNSETIFF, (void *) &ifr))
102 { 102 {
103 fprintf (stderr, 103 fprintf (stderr, "Error with ioctl on `%s': %s\n", "/dev/net/tun",
104 "Error with ioctl on `%s': %s\n", 104 strerror (errno));
105 "/dev/net/tun", strerror (errno));
106 close (fd); 105 close (fd);
107 return -1; 106 return -1;
108 } 107 }
@@ -132,8 +131,8 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
132 memset (&sa6, 0, sizeof (struct sockaddr_in6)); 131 memset (&sa6, 0, sizeof (struct sockaddr_in6));
133 if (1 != inet_pton (AF_INET6, address, sa6.sin6_addr.s6_addr)) 132 if (1 != inet_pton (AF_INET6, address, sa6.sin6_addr.s6_addr))
134 { 133 {
135 fprintf (stderr, 134 fprintf (stderr, "Failed to parse address `%s': %s\n", address,
136 "Failed to parse address `%s': %s\n", address, strerror (errno)); 135 strerror (errno));
137 exit (1); 136 exit (1);
138 } 137 }
139 138
@@ -165,8 +164,8 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
165 */ 164 */
166 if (-1 == ioctl (fd, SIOCSIFADDR, &ifr6)) 165 if (-1 == ioctl (fd, SIOCSIFADDR, &ifr6))
167 { 166 {
168 fprintf (stderr, 167 fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
169 "ioctl failed at line %d: %s\n", __LINE__, strerror (errno)); 168 strerror (errno));
170 exit (1); 169 exit (1);
171 } 170 }
172 171
@@ -175,8 +174,8 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
175 */ 174 */
176 if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr)) 175 if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr))
177 { 176 {
178 fprintf (stderr, 177 fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
179 "ioctl failed at line %d: %s\n", __LINE__, strerror (errno)); 178 strerror (errno));
180 exit (1); 179 exit (1);
181 } 180 }
182 181
@@ -186,8 +185,8 @@ set_address6 (const char *dev, const char *address, unsigned long prefix_len)
186 ifr.ifr_flags |= IFF_UP | IFF_RUNNING; 185 ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
187 if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr)) 186 if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr))
188 { 187 {
189 fprintf (stderr, 188 fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
190 "ioctl failed at line %d: %s\n", __LINE__, strerror (errno)); 189 strerror (errno));
191 exit (1); 190 exit (1);
192 } 191 }
193 192
@@ -224,8 +223,8 @@ set_address4 (const char *dev, const char *address, const char *mask)
224 */ 223 */
225 if (1 != inet_pton (AF_INET, address, &addr->sin_addr.s_addr)) 224 if (1 != inet_pton (AF_INET, address, &addr->sin_addr.s_addr))
226 { 225 {
227 fprintf (stderr, 226 fprintf (stderr, "Failed to parse address `%s': %s\n", address,
228 "Failed to parse address `%s': %s\n", address, strerror (errno)); 227 strerror (errno));
229 exit (1); 228 exit (1);
230 } 229 }
231 230
@@ -253,8 +252,8 @@ set_address4 (const char *dev, const char *address, const char *mask)
253 addr = (struct sockaddr_in *) &(ifr.ifr_netmask); 252 addr = (struct sockaddr_in *) &(ifr.ifr_netmask);
254 if (1 != inet_pton (AF_INET, mask, &addr->sin_addr.s_addr)) 253 if (1 != inet_pton (AF_INET, mask, &addr->sin_addr.s_addr))
255 { 254 {
256 fprintf (stderr, 255 fprintf (stderr, "Failed to parse address `%s': %s\n", mask,
257 "Failed to parse address `%s': %s\n", mask, strerror (errno)); 256 strerror (errno));
258 exit (1); 257 exit (1);
259 } 258 }
260 259
@@ -263,8 +262,8 @@ set_address4 (const char *dev, const char *address, const char *mask)
263 */ 262 */
264 if (-1 == ioctl (fd, SIOCSIFNETMASK, &ifr)) 263 if (-1 == ioctl (fd, SIOCSIFNETMASK, &ifr))
265 { 264 {
266 fprintf (stderr, 265 fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
267 "ioctl failed at line %d: %s\n", __LINE__, strerror (errno)); 266 strerror (errno));
268 exit (1); 267 exit (1);
269 } 268 }
270 269
@@ -273,8 +272,8 @@ set_address4 (const char *dev, const char *address, const char *mask)
273 */ 272 */
274 if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr)) 273 if (-1 == ioctl (fd, SIOCGIFFLAGS, &ifr))
275 { 274 {
276 fprintf (stderr, 275 fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
277 "ioctl failed at line %d: %s\n", __LINE__, strerror (errno)); 276 strerror (errno));
278 exit (1); 277 exit (1);
279 } 278 }
280 279
@@ -284,8 +283,8 @@ set_address4 (const char *dev, const char *address, const char *mask)
284 ifr.ifr_flags |= IFF_UP | IFF_RUNNING; 283 ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
285 if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr)) 284 if (-1 == ioctl (fd, SIOCSIFFLAGS, &ifr))
286 { 285 {
287 fprintf (stderr, 286 fprintf (stderr, "ioctl failed at line %d: %s\n", __LINE__,
288 "ioctl failed at line %d: %s\n", __LINE__, strerror (errno)); 287 strerror (errno));
289 exit (1); 288 exit (1);
290 } 289 }
291 290
@@ -545,8 +544,8 @@ main (int argc, char **argv)
545 if (0 != setresuid (uid, uid, uid)) 544 if (0 != setresuid (uid, uid, uid))
546 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); 545 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
547 if (SIG_ERR == signal (SIGPIPE, SIG_IGN)) 546 if (SIG_ERR == signal (SIGPIPE, SIG_IGN))
548 fprintf (stderr, 547 fprintf (stderr, "Failed to protect against SIGPIPE: %s\n",
549 "Failed to protect against SIGPIPE: %s\n", strerror (errno)); 548 strerror (errno));
550 run (fd_tun); 549 run (fd_tun);
551 close (fd_tun); 550 close (fd_tun);
552 return 0; 551 return 0;
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c
index 9959e9564..a267cab0d 100644
--- a/src/vpn/gnunet-service-dns.c
+++ b/src/vpn/gnunet-service-dns.c
@@ -146,11 +146,10 @@ hijack (void *cls
146 146
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacking, port is %d\n", dnsoutport); 147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacking, port is %d\n", dnsoutport);
148 snprintf (port_s, 6, "%d", dnsoutport); 148 snprintf (port_s, 6, "%d", dnsoutport);
149 if (NULL != (proc = GNUNET_OS_start_process (NULL, 149 if (NULL !=
150 NULL, 150 (proc =
151 "gnunet-helper-hijack-dns", 151 GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-hijack-dns",
152 "gnunet-hijack-dns", 152 "gnunet-hijack-dns", port_s, virt_dns, NULL)))
153 port_s, virt_dns, NULL)))
154 GNUNET_OS_process_close (proc); 153 GNUNET_OS_process_close (proc);
155 GNUNET_free (virt_dns); 154 GNUNET_free (virt_dns);
156} 155}
@@ -175,11 +174,11 @@ unhijack (unsigned short port)
175 174
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "unHijacking, port is %d\n", port); 175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "unHijacking, port is %d\n", port);
177 snprintf (port_s, 6, "%d", port); 176 snprintf (port_s, 6, "%d", port);
178 if (NULL != (proc = GNUNET_OS_start_process (NULL, 177 if (NULL !=
179 NULL, 178 (proc =
180 "gnunet-helper-hijack-dns", 179 GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-hijack-dns",
181 "gnunet-hijack-dns", 180 "gnunet-hijack-dns", "-d", port_s, virt_dns,
182 "-d", port_s, virt_dns, NULL))) 181 NULL)))
183 GNUNET_OS_process_close (proc); 182 GNUNET_OS_process_close (proc);
184 GNUNET_free (virt_dns); 183 GNUNET_free (virt_dns);
185} 184}
@@ -204,8 +203,7 @@ send_answer (void *cls, size_t size, void *buf)
204 203
205 /* When more data is to be sent, reschedule */ 204 /* When more data is to be sent, reschedule */
206 if (head != NULL) 205 if (head != NULL)
207 GNUNET_SERVER_notify_transmit_ready (cls, 206 GNUNET_SERVER_notify_transmit_ready (cls, ntohs (head->pkt.hdr.size),
208 ntohs (head->pkt.hdr.size),
209 GNUNET_TIME_UNIT_FOREVER_REL, 207 GNUNET_TIME_UNIT_FOREVER_REL,
210 &send_answer, cls); 208 &send_answer, cls);
211 209
@@ -371,19 +369,20 @@ send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
371 369
372 struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; 370 struct tunnel_cls *cls_ = (struct tunnel_cls *) cls;
373 371
374 cls_->tunnel = GNUNET_MESH_peer_request_connect_by_type (mesh_handle, 372 cls_->tunnel =
375 GNUNET_TIME_UNIT_HOURS, 373 GNUNET_MESH_peer_request_connect_by_type (mesh_handle,
376 GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, 374 GNUNET_TIME_UNIT_HOURS,
377 mesh_connect, 375 GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER,
378 NULL, cls_); 376 mesh_connect, NULL, cls_);
379 377
380 remote_pending[cls_->dns.s.id] = cls_; 378 remote_pending[cls_->dns.s.id] = cls_;
381} 379}
382 380
383static int 381static int
384receive_mesh_query (void *cls __attribute__ ((unused)), 382receive_mesh_query (void *cls
385 struct GNUNET_MESH_Tunnel *tunnel, 383 __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel,
386 void **ctx __attribute__ ((unused)), 384 void **ctx
385 __attribute__ ((unused)),
387 const struct GNUNET_PeerIdentity *sender 386 const struct GNUNET_PeerIdentity *sender
388 __attribute__ ((unused)), 387 __attribute__ ((unused)),
389 const struct GNUNET_MessageHeader *message, 388 const struct GNUNET_MessageHeader *message,
@@ -404,8 +403,7 @@ receive_mesh_query (void *cls __attribute__ ((unused)),
404 query_states[dns->s.id].tunnel = tunnel; 403 query_states[dns->s.id].tunnel = tunnel;
405 query_states[dns->s.id].valid = GNUNET_YES; 404 query_states[dns->s.id].valid = GNUNET_YES;
406 405
407 GNUNET_NETWORK_socket_sendto (dnsout, 406 GNUNET_NETWORK_socket_sendto (dnsout, dns,
408 dns,
409 ntohs (message->size) - 407 ntohs (message->size) -
410 sizeof (struct GNUNET_MessageHeader), 408 sizeof (struct GNUNET_MessageHeader),
411 (struct sockaddr *) &dest, sizeof dest); 409 (struct sockaddr *) &dest, sizeof dest);
@@ -414,9 +412,10 @@ receive_mesh_query (void *cls __attribute__ ((unused)),
414} 412}
415 413
416static int 414static int
417receive_mesh_answer (void *cls __attribute__ ((unused)), 415receive_mesh_answer (void *cls
418 struct GNUNET_MESH_Tunnel *tunnel, 416 __attribute__ ((unused)),
419 void **ctx __attribute__ ((unused)), 417 struct GNUNET_MESH_Tunnel *tunnel, void **ctx
418 __attribute__ ((unused)),
420 const struct GNUNET_PeerIdentity *sender, 419 const struct GNUNET_PeerIdentity *sender,
421 const struct GNUNET_MessageHeader *message, 420 const struct GNUNET_MessageHeader *message,
422 const struct GNUNET_TRANSPORT_ATS_Information *atsi 421 const struct GNUNET_TRANSPORT_ATS_Information *atsi
@@ -426,8 +425,8 @@ receive_mesh_answer (void *cls __attribute__ ((unused)),
426 struct dns_pkt *dns = (struct dns_pkt *) (message + 1); 425 struct dns_pkt *dns = (struct dns_pkt *) (message + 1);
427 426
428 /* They sent us a packet we were not waiting for */ 427 /* They sent us a packet we were not waiting for */
429 if (remote_pending[dns->s.id] == NULL 428 if (remote_pending[dns->s.id] == NULL ||
430 || remote_pending[dns->s.id]->tunnel != tunnel) 429 remote_pending[dns->s.id]->tunnel != tunnel)
431 return GNUNET_OK; 430 return GNUNET_OK;
432 431
433 GNUNET_free (remote_pending[dns->s.id]); 432 GNUNET_free (remote_pending[dns->s.id]);
@@ -526,8 +525,7 @@ receive_mesh_answer (void *cls __attribute__ ((unused)),
526 525
527 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); 526 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
528 527
529 GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, 528 GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client, len,
530 len,
531 GNUNET_TIME_UNIT_FOREVER_REL, 529 GNUNET_TIME_UNIT_FOREVER_REL,
532 &send_answer, 530 &send_answer,
533 query_states[dns->s.id].client); 531 query_states[dns->s.id].client);
@@ -561,8 +559,8 @@ send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
561 559
562 size_t len = sizeof (struct answer_packet) - 1 + sizeof (struct dns_static) + 74 /* this is the length of a reverse ipv6-lookup */ 560 size_t len = sizeof (struct answer_packet) - 1 + sizeof (struct dns_static) + 74 /* this is the length of a reverse ipv6-lookup */
563 + sizeof (struct dns_query_line) + 2 /* To hold the pointer (as defined in RFC1035) to the name */ 561 + sizeof (struct dns_query_line) + 2 /* To hold the pointer (as defined in RFC1035) to the name */
564 + sizeof (struct dns_record_line) - 1 562 + sizeof (struct dns_record_line) - 1 -
565 - 2 /* We do not know the lenght of the answer yet */ ; 563 2 /* We do not know the lenght of the answer yet */ ;
566 564
567 struct answer_packet_list *answer = 565 struct answer_packet_list *answer =
568 GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *)); 566 GNUNET_malloc (len + 2 * sizeof (struct answer_packet_list *));
@@ -619,8 +617,7 @@ send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
619 617
620 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); 618 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
621 619
622 GNUNET_SERVER_notify_transmit_ready (query_states[id].client, 620 GNUNET_SERVER_notify_transmit_ready (query_states[id].client, len,
623 len,
624 GNUNET_TIME_UNIT_FOREVER_REL, 621 GNUNET_TIME_UNIT_FOREVER_REL,
625 &send_answer, query_states[id].client); 622 &send_answer, query_states[id].client);
626} 623}
@@ -629,9 +626,9 @@ send_rev_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
629 * Receive a block from the dht. 626 * Receive a block from the dht.
630 */ 627 */
631static void 628static void
632receive_dht (void *cls, 629receive_dht (void *cls, struct GNUNET_TIME_Absolute exp
633 struct GNUNET_TIME_Absolute exp __attribute__ ((unused)), 630 __attribute__ ((unused)), const GNUNET_HashCode * key
634 const GNUNET_HashCode * key __attribute__ ((unused)), 631 __attribute__ ((unused)),
635 const struct GNUNET_PeerIdentity *const *get_path 632 const struct GNUNET_PeerIdentity *const *get_path
636 __attribute__ ((unused)), 633 __attribute__ ((unused)),
637 const struct GNUNET_PeerIdentity *const *put_path 634 const struct GNUNET_PeerIdentity *const *put_path
@@ -654,8 +651,7 @@ receive_dht (void *cls,
654 const struct GNUNET_DNS_Record *rec = data; 651 const struct GNUNET_DNS_Record *rec = data;
655 652
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 "Got block of size %d, peer: %08x, desc: %08x\n", 654 "Got block of size %d, peer: %08x, desc: %08x\n", size,
658 size,
659 *((unsigned int *) &rec->peer), 655 *((unsigned int *) &rec->peer),
660 *((unsigned int *) &rec->service_descriptor)); 656 *((unsigned int *) &rec->service_descriptor));
661 657
@@ -676,8 +672,8 @@ receive_dht (void *cls,
676 672
677 memcpy (&answer->pkt.service_descr.service_descriptor, 673 memcpy (&answer->pkt.service_descr.service_descriptor,
678 &rec->service_descriptor, sizeof (GNUNET_HashCode)); 674 &rec->service_descriptor, sizeof (GNUNET_HashCode));
679 memcpy (&answer->pkt.service_descr.service_type, 675 memcpy (&answer->pkt.service_descr.service_type, &rec->service_type,
680 &rec->service_type, sizeof (answer->pkt.service_descr.service_type)); 676 sizeof (answer->pkt.service_descr.service_type));
681 memcpy (&answer->pkt.service_descr.ports, &rec->ports, 677 memcpy (&answer->pkt.service_descr.ports, &rec->ports,
682 sizeof (answer->pkt.service_descr.ports)); 678 sizeof (answer->pkt.service_descr.ports));
683 679
@@ -730,8 +726,7 @@ receive_dht (void *cls,
730 726
731 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); 727 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
732 728
733 GNUNET_SERVER_notify_transmit_ready (query_states[id].client, 729 GNUNET_SERVER_notify_transmit_ready (query_states[id].client, len,
734 len,
735 GNUNET_TIME_UNIT_FOREVER_REL, 730 GNUNET_TIME_UNIT_FOREVER_REL,
736 &send_answer, query_states[id].client); 731 &send_answer, query_states[id].client);
737 732
@@ -742,8 +737,8 @@ receive_dht (void *cls,
742 * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS 737 * This receives a GNUNET_MESSAGE_TYPE_REHIJACK and rehijacks the DNS
743 */ 738 */
744static void 739static void
745rehijack (void *cls __attribute__ ((unused)), 740rehijack (void *cls
746 struct GNUNET_SERVER_Client *client, 741 __attribute__ ((unused)), struct GNUNET_SERVER_Client *client,
747 const struct GNUNET_MessageHeader *message __attribute__ ((unused))) 742 const struct GNUNET_MessageHeader *message __attribute__ ((unused)))
748{ 743{
749 unhijack (dnsoutport); 744 unhijack (dnsoutport);
@@ -756,8 +751,8 @@ rehijack (void *cls __attribute__ ((unused)),
756 * This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket 751 * This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket
757 */ 752 */
758static void 753static void
759receive_query (void *cls __attribute__ ((unused)), 754receive_query (void *cls
760 struct GNUNET_SERVER_Client *client, 755 __attribute__ ((unused)), struct GNUNET_SERVER_Client *client,
761 const struct GNUNET_MessageHeader *message) 756 const struct GNUNET_MessageHeader *message)
762{ 757{
763 struct query_packet *pkt = (struct query_packet *) message; 758 struct query_packet *pkt = (struct query_packet *) message;
@@ -788,21 +783,18 @@ receive_query (void *cls __attribute__ ((unused)),
788 GNUNET_CRYPTO_hash (pdns->queries[0]->name, pdns->queries[0]->namelen, 783 GNUNET_CRYPTO_hash (pdns->queries[0]->name, pdns->queries[0]->namelen,
789 &key); 784 &key);
790 785
791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting with key %08x, len is %d\n",
792 "Getting with key %08x, len is %d\n",
793 *((unsigned int *) &key), pdns->queries[0]->namelen); 787 *((unsigned int *) &key), pdns->queries[0]->namelen);
794 788
795 struct receive_dht_cls *cls = 789 struct receive_dht_cls *cls =
796 GNUNET_malloc (sizeof (struct receive_dht_cls)); 790 GNUNET_malloc (sizeof (struct receive_dht_cls));
797 cls->id = dns->s.id; 791 cls->id = dns->s.id;
798 792
799 cls->handle = GNUNET_DHT_get_start (dht, 793 cls->handle =
800 GNUNET_TIME_UNIT_MINUTES, 794 GNUNET_DHT_get_start (dht, GNUNET_TIME_UNIT_MINUTES,
801 GNUNET_BLOCK_TYPE_DNS, 795 GNUNET_BLOCK_TYPE_DNS, &key,
802 &key, 796 DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL,
803 DEFAULT_GET_REPLICATION, 797 0, NULL, 0, receive_dht, cls);
804 GNUNET_DHT_RO_NONE,
805 NULL, 0, NULL, 0, receive_dht, cls);
806 798
807 goto outfree; 799 goto outfree;
808 } 800 }
@@ -881,8 +873,8 @@ receive_query (void *cls __attribute__ ((unused)),
881 873
882 if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes)) 874 if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes))
883 { 875 {
884 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 876 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error parsing 'VIRTDNS': %s; %m!\n",
885 "Error parsing 'VIRTDNS': %s; %m!\n", virt_dns); 877 virt_dns);
886 exit (1); 878 exit (1);
887 } 879 }
888 880
@@ -923,8 +915,7 @@ receive_query (void *cls __attribute__ ((unused)),
923 dest.sin_port = htons (53); 915 dest.sin_port = htons (53);
924 dest.sin_addr.s_addr = pkt->orig_to; 916 dest.sin_addr.s_addr = pkt->orig_to;
925 917
926 GNUNET_NETWORK_socket_sendto (dnsout, 918 GNUNET_NETWORK_socket_sendto (dnsout, dns,
927 dns,
928 ntohs (pkt->hdr.size) - 919 ntohs (pkt->hdr.size) -
929 sizeof (struct query_packet) + 1, 920 sizeof (struct query_packet) + 1,
930 (struct sockaddr *) &dest, sizeof dest); 921 (struct sockaddr *) &dest, sizeof dest);
@@ -963,8 +954,9 @@ open_port ()
963 /* Read the port we bound to */ 954 /* Read the port we bound to */
964 socklen_t addrlen = sizeof (struct sockaddr_in); 955 socklen_t addrlen = sizeof (struct sockaddr_in);
965 956
966 err = getsockname (GNUNET_NETWORK_get_fd (dnsout), 957 err =
967 (struct sockaddr *) &addr, &addrlen); 958 getsockname (GNUNET_NETWORK_get_fd (dnsout), (struct sockaddr *) &addr,
959 &addrlen);
968 960
969 dnsoutport = htons (addr.sin_port); 961 dnsoutport = htons (addr.sin_port);
970 962
@@ -1010,9 +1002,7 @@ read_response (void *cls
1010 unsigned char buf[len]; 1002 unsigned char buf[len];
1011 struct dns_pkt *dns = (struct dns_pkt *) buf; 1003 struct dns_pkt *dns = (struct dns_pkt *) buf;
1012 1004
1013 r = GNUNET_NETWORK_socket_recvfrom (dnsout, 1005 r = GNUNET_NETWORK_socket_recvfrom (dnsout, buf, sizeof (buf),
1014 buf,
1015 sizeof (buf),
1016 (struct sockaddr *) &addr, &addrlen); 1006 (struct sockaddr *) &addr, &addrlen);
1017 1007
1018 if (r < 0) 1008 if (r < 0)
@@ -1093,16 +1083,15 @@ read_response (void *cls
1093 1083
1094 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); 1084 GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer);
1095 1085
1096 GNUNET_SERVER_notify_transmit_ready (query_states 1086 GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id].client,
1097 [dns->s.id].client, len, 1087 len, GNUNET_TIME_UNIT_FOREVER_REL,
1098 GNUNET_TIME_UNIT_FOREVER_REL,
1099 &send_answer, 1088 &send_answer,
1100 query_states[dns->s.id].client); 1089 query_states[dns->s.id].client);
1101 } 1090 }
1102 } 1091 }
1103 } 1092 }
1104 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1093 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, dnsout,
1105 dnsout, &read_response, NULL); 1094 &read_response, NULL);
1106} 1095}
1107 1096
1108 1097
@@ -1113,7 +1102,8 @@ read_response (void *cls
1113 * @param tc unused 1102 * @param tc unused
1114 */ 1103 */
1115static void 1104static void
1116cleanup_task (void *cls __attribute__ ((unused)), 1105cleanup_task (void *cls
1106 __attribute__ ((unused)),
1117 const struct GNUNET_SCHEDULER_TaskContext *tc) 1107 const struct GNUNET_SCHEDULER_TaskContext *tc)
1118{ 1108{
1119 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); 1109 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN));
@@ -1236,23 +1226,18 @@ publish_name (const char *name, uint64_t ports, uint32_t service_type,
1236 (GNUNET_TIME_UNIT_HOURS, 2)); 1226 (GNUNET_TIME_UNIT_HOURS, 2));
1237 1227
1238 /* Sign the block */ 1228 /* Sign the block */
1239 if (GNUNET_OK != GNUNET_CRYPTO_rsa_sign (my_private_key, 1229 if (GNUNET_OK !=
1240 &data.purpose, &data.signature)) 1230 GNUNET_CRYPTO_rsa_sign (my_private_key, &data.purpose, &data.signature))
1241 { 1231 {
1242 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n"); 1232 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not sign DNS_Record\n");
1243 return; 1233 return;
1244 } 1234 }
1245 1235
1246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting with key %08x, size = %d\n",
1247 "Putting with key %08x, size = %d\n",
1248 *((unsigned int *) &data.service_descriptor), size); 1237 *((unsigned int *) &data.service_descriptor), size);
1249 1238
1250 GNUNET_DHT_put (dht, 1239 GNUNET_DHT_put (dht, &data.service_descriptor, DEFAULT_PUT_REPLICATION,
1251 &data.service_descriptor, 1240 GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_DNS, size,
1252 DEFAULT_PUT_REPLICATION,
1253 GNUNET_DHT_RO_NONE,
1254 GNUNET_BLOCK_TYPE_DNS,
1255 size,
1256 (char *) &data, 1241 (char *) &data,
1257 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), 1242 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS),
1258 GNUNET_TIME_UNIT_MINUTES, NULL, NULL); 1243 GNUNET_TIME_UNIT_MINUTES, NULL, NULL);
@@ -1276,14 +1261,14 @@ publish_iterate (void *cls __attribute__ ((unused)), const char *section)
1276 char *udp_redirects, *tcp_redirects, *alternative_names, *alternative_name, 1261 char *udp_redirects, *tcp_redirects, *alternative_names, *alternative_name,
1277 *keyfile; 1262 *keyfile;
1278 1263
1279 GNUNET_CONFIGURATION_get_value_string (cfg, section, 1264 GNUNET_CONFIGURATION_get_value_string (cfg, section, "UDP_REDIRECTS",
1280 "UDP_REDIRECTS", &udp_redirects); 1265 &udp_redirects);
1281 GNUNET_CONFIGURATION_get_value_string (cfg, section, "TCP_REDIRECTS", 1266 GNUNET_CONFIGURATION_get_value_string (cfg, section, "TCP_REDIRECTS",
1282 &tcp_redirects); 1267 &tcp_redirects);
1283 1268
1284 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", 1269 if (GNUNET_OK !=
1285 "HOSTKEY", 1270 GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY",
1286 &keyfile)) 1271 &keyfile))
1287 { 1272 {
1288 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not read keyfile-value\n"); 1273 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not read keyfile-value\n");
1289 if (keyfile != NULL) 1274 if (keyfile != NULL)
@@ -1310,8 +1295,7 @@ publish_iterate (void *cls __attribute__ ((unused)), const char *section)
1310 1295
1311 publish_name (section, ports, service_type, my_private_key); 1296 publish_name (section, ports, service_type, my_private_key);
1312 1297
1313 GNUNET_CONFIGURATION_get_value_string (cfg, section, 1298 GNUNET_CONFIGURATION_get_value_string (cfg, section, "ALTERNATIVE_NAMES",
1314 "ALTERNATIVE_NAMES",
1315 &alternative_names); 1299 &alternative_names);
1316 for (alternative_name = strtok (alternative_names, " "); 1300 for (alternative_name = strtok (alternative_names, " ");
1317 alternative_name != NULL; alternative_name = strtok (NULL, " ")) 1301 alternative_name != NULL; alternative_name = strtok (NULL, " "))
@@ -1335,7 +1319,8 @@ publish_iterate (void *cls __attribute__ ((unused)), const char *section)
1335 * Publish a DNS-record in the DHT. 1319 * Publish a DNS-record in the DHT.
1336 */ 1320 */
1337static void 1321static void
1338publish_names (void *cls __attribute__ ((unused)), 1322publish_names (void *cls
1323 __attribute__ ((unused)),
1339 const struct GNUNET_SCHEDULER_TaskContext *tc) 1324 const struct GNUNET_SCHEDULER_TaskContext *tc)
1340{ 1325{
1341 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1326 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -1352,8 +1337,7 @@ publish_names (void *cls __attribute__ ((unused)),
1352 * @param cfg_ configuration to use 1337 * @param cfg_ configuration to use
1353 */ 1338 */
1354static void 1339static void
1355run (void *cls, 1340run (void *cls, struct GNUNET_SERVER_Handle *server,
1356 struct GNUNET_SERVER_Handle *server,
1357 const struct GNUNET_CONFIGURATION_Handle *cfg_) 1341 const struct GNUNET_CONFIGURATION_Handle *cfg_)
1358{ 1342{
1359 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 1343 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -1401,8 +1385,8 @@ run (void *cls,
1401 GNUNET_SCHEDULER_add_now (publish_names, NULL); 1385 GNUNET_SCHEDULER_add_now (publish_names, NULL);
1402 1386
1403 GNUNET_SERVER_add_handlers (server, handlers); 1387 GNUNET_SERVER_add_handlers (server, handlers);
1404 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1388 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task,
1405 &cleanup_task, cls); 1389 cls);
1406} 1390}
1407 1391
1408/** 1392/**
@@ -1416,8 +1400,6 @@ int
1416main (int argc, char *const *argv) 1400main (int argc, char *const *argv)
1417{ 1401{
1418 return (GNUNET_OK == 1402 return (GNUNET_OK ==
1419 GNUNET_SERVICE_run (argc, 1403 GNUNET_SERVICE_run (argc, argv, "dns", GNUNET_SERVICE_OPTION_NONE,
1420 argv, 1404 &run, NULL)) ? 0 : 1;
1421 "dns",
1422 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
1423} 1405}