diff options
Diffstat (limited to 'src/vpn/gnunet-daemon-vpn.c')
-rw-r--r-- | src/vpn/gnunet-daemon-vpn.c | 111 |
1 files changed, 59 insertions, 52 deletions
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 1191dffe1..cc8001eae 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c | |||
@@ -183,7 +183,7 @@ collect_mappings (void *cls | |||
183 | /* FIXME! GNUNET_MESH_close_tunnel(me->tunnel); */ | 183 | /* FIXME! GNUNET_MESH_close_tunnel(me->tunnel); */ |
184 | 184 | ||
185 | GNUNET_assert (GNUNET_YES == | 185 | GNUNET_assert (GNUNET_YES == |
186 | GNUNET_CONTAINER_multihashmap_remove (hashmap, &me->hash, me)); | 186 | GNUNET_CONTAINER_multihashmap_remove (hashmap, &me->hash, me)); |
187 | 187 | ||
188 | GNUNET_free (me); | 188 | GNUNET_free (me); |
189 | } | 189 | } |
@@ -282,21 +282,22 @@ send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
282 | { | 282 | { |
283 | struct GNUNET_MESH_Tunnel **tunnel = cls; | 283 | struct GNUNET_MESH_Tunnel **tunnel = cls; |
284 | 284 | ||
285 | struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(*tunnel); | 285 | struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data (*tunnel); |
286 | |||
286 | ts->th = NULL; | 287 | ts->th = NULL; |
287 | 288 | ||
288 | if (NULL != buf) | 289 | if (NULL != buf) |
289 | { | 290 | { |
290 | struct GNUNET_MessageHeader *hdr = | 291 | struct GNUNET_MessageHeader *hdr = |
291 | (struct GNUNET_MessageHeader *) (tunnel + 1); | 292 | (struct GNUNET_MessageHeader *) (tunnel + 1); |
292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 293 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
293 | "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf, | 294 | "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf, |
294 | size); | 295 | size); |
295 | GNUNET_assert (size >= ntohs (hdr->size)); | 296 | GNUNET_assert (size >= ntohs (hdr->size)); |
296 | memcpy (buf, hdr, ntohs (hdr->size)); | 297 | memcpy (buf, hdr, ntohs (hdr->size)); |
297 | size = ntohs (hdr->size); | 298 | size = ntohs (hdr->size); |
298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n"); | 299 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n"); |
299 | } | 300 | } |
300 | else | 301 | else |
301 | size = 0; | 302 | size = 0; |
302 | 303 | ||
@@ -307,9 +308,7 @@ send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
307 | GNUNET_CONTAINER_DLL_remove (ts->head, ts->tail, element); | 308 | GNUNET_CONTAINER_DLL_remove (ts->head, ts->tail, element); |
308 | 309 | ||
309 | ts->th = | 310 | ts->th = |
310 | GNUNET_MESH_notify_transmit_ready (*tunnel, | 311 | GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42, |
311 | GNUNET_NO, | ||
312 | 42, | ||
313 | GNUNET_TIME_relative_divide | 312 | GNUNET_TIME_relative_divide |
314 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 313 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
315 | (const struct GNUNET_PeerIdentity *) | 314 | (const struct GNUNET_PeerIdentity *) |
@@ -330,12 +329,14 @@ port_in_ports (uint64_t ports, uint16_t port) | |||
330 | { | 329 | { |
331 | uint16_t *ps = (uint16_t *) & ports; | 330 | uint16_t *ps = (uint16_t *) & ports; |
332 | 331 | ||
333 | return ports == 0 || ps[0] == port || ps[1] == port || ps[2] == port || ps[3] == port; | 332 | return ports == 0 || ps[0] == port || ps[1] == port || ps[2] == port || |
333 | ps[3] == port; | ||
334 | } | 334 | } |
335 | 335 | ||
336 | void | 336 | void |
337 | send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, | 337 | send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, |
338 | const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) | 338 | const struct GNUNET_ATS_Information *atsi |
339 | __attribute__ ((unused))) | ||
339 | { | 340 | { |
340 | /* peer == NULL means that all peers in this request are connected */ | 341 | /* peer == NULL means that all peers in this request are connected */ |
341 | if (peer == NULL) | 342 | if (peer == NULL) |
@@ -347,18 +348,16 @@ send_pkt_to_peer (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
347 | GNUNET_assert (NULL != tunnel); | 348 | GNUNET_assert (NULL != tunnel); |
348 | GNUNET_assert (NULL != *tunnel); | 349 | GNUNET_assert (NULL != *tunnel); |
349 | 350 | ||
350 | struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data(*tunnel); | 351 | struct tunnel_state *ts = GNUNET_MESH_tunnel_get_data (*tunnel); |
352 | |||
351 | if (NULL == ts->th) | 353 | if (NULL == ts->th) |
352 | { | 354 | { |
353 | ts->th = | 355 | ts->th = |
354 | GNUNET_MESH_notify_transmit_ready (*tunnel, | 356 | GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42, |
355 | GNUNET_NO, | ||
356 | 42, | ||
357 | GNUNET_TIME_relative_divide | 357 | GNUNET_TIME_relative_divide |
358 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 358 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
359 | (const struct GNUNET_PeerIdentity *) | 359 | (const struct GNUNET_PeerIdentity *) |
360 | NULL, | 360 | NULL, ntohs (hdr->size), |
361 | ntohs (hdr->size), | ||
362 | send_pkt_to_peer_notify_callback, | 361 | send_pkt_to_peer_notify_callback, |
363 | cls); | 362 | cls); |
364 | } | 363 | } |
@@ -574,7 +573,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
574 | 573 | ||
575 | list = | 574 | list = |
576 | GNUNET_malloc (htons (pkt->hdr.size) + | 575 | GNUNET_malloc (htons (pkt->hdr.size) + |
577 | sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); | 576 | sizeof (struct answer_packet_list) - |
577 | sizeof (struct answer_packet)); | ||
578 | 578 | ||
579 | memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); | 579 | memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); |
580 | 580 | ||
@@ -622,8 +622,9 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
622 | char *name = (char *) (map_entry + 1); | 622 | char *name = (char *) (map_entry + 1); |
623 | 623 | ||
624 | list = | 624 | list = |
625 | GNUNET_malloc (sizeof(struct answer_packet_list) - sizeof(struct answer_packet) + offset + 2 + | 625 | GNUNET_malloc (sizeof (struct answer_packet_list) - |
626 | ntohs (namelen)); | 626 | sizeof (struct answer_packet) + offset + 2 + |
627 | ntohs (namelen)); | ||
627 | 628 | ||
628 | struct answer_packet *rpkt = &list->pkt; | 629 | struct answer_packet *rpkt = &list->pkt; |
629 | 630 | ||
@@ -641,7 +642,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
641 | { | 642 | { |
642 | list = | 643 | list = |
643 | GNUNET_malloc (htons (pkt->hdr.size) + | 644 | GNUNET_malloc (htons (pkt->hdr.size) + |
644 | sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); | 645 | sizeof (struct answer_packet_list) - |
646 | sizeof (struct answer_packet)); | ||
645 | memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); | 647 | memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); |
646 | } | 648 | } |
647 | else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA) | 649 | else if (pkt->subtype == GNUNET_DNS_ANSWER_TYPE_REMOTE_AAAA) |
@@ -701,7 +703,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
701 | 703 | ||
702 | list = | 704 | list = |
703 | GNUNET_malloc (htons (pkt->hdr.size) + | 705 | GNUNET_malloc (htons (pkt->hdr.size) + |
704 | sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); | 706 | sizeof (struct answer_packet_list) - |
707 | sizeof (struct answer_packet)); | ||
705 | 708 | ||
706 | memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); | 709 | memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); |
707 | } | 710 | } |
@@ -763,7 +766,8 @@ process_answer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
763 | 766 | ||
764 | list = | 767 | list = |
765 | GNUNET_malloc (htons (pkt->hdr.size) + | 768 | GNUNET_malloc (htons (pkt->hdr.size) + |
766 | sizeof(struct answer_packet_list) - sizeof(struct answer_packet)); | 769 | sizeof (struct answer_packet_list) - |
770 | sizeof (struct answer_packet)); | ||
767 | 771 | ||
768 | memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); | 772 | memcpy (&list->pkt, pkt, htons (pkt->hdr.size)); |
769 | } | 773 | } |
@@ -852,12 +856,12 @@ add_additional_port (struct map_entry *me, uint16_t port) | |||
852 | } | 856 | } |
853 | 857 | ||
854 | static int | 858 | static int |
855 | receive_udp_back (void *cls __attribute__ ((unused)), | 859 | receive_udp_back (void *cls |
856 | struct GNUNET_MESH_Tunnel *tunnel, | 860 | __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, |
857 | void **tunnel_ctx, | 861 | void **tunnel_ctx, const struct GNUNET_PeerIdentity *sender, |
858 | const struct GNUNET_PeerIdentity *sender, | ||
859 | const struct GNUNET_MessageHeader *message, | 862 | const struct GNUNET_MessageHeader *message, |
860 | const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) | 863 | const struct GNUNET_ATS_Information *atsi |
864 | __attribute__ ((unused))) | ||
861 | { | 865 | { |
862 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 866 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
863 | struct remote_addr *s = (struct remote_addr *) desc; | 867 | struct remote_addr *s = (struct remote_addr *) desc; |
@@ -1029,12 +1033,13 @@ receive_udp_back (void *cls __attribute__ ((unused)), | |||
1029 | } | 1033 | } |
1030 | 1034 | ||
1031 | static int | 1035 | static int |
1032 | receive_tcp_back (void *cls __attribute__ ((unused)), | 1036 | receive_tcp_back (void *cls |
1033 | struct GNUNET_MESH_Tunnel *tunnel, | 1037 | __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, |
1034 | void **tunnel_ctx, | 1038 | void **tunnel_ctx, const struct GNUNET_PeerIdentity *sender |
1035 | const struct GNUNET_PeerIdentity *sender __attribute__ ((unused)), | 1039 | __attribute__ ((unused)), |
1036 | const struct GNUNET_MessageHeader *message, | 1040 | const struct GNUNET_MessageHeader *message, |
1037 | const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) | 1041 | const struct GNUNET_ATS_Information *atsi |
1042 | __attribute__ ((unused))) | ||
1038 | { | 1043 | { |
1039 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 1044 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
1040 | struct remote_addr *s = (struct remote_addr *) desc; | 1045 | struct remote_addr *s = (struct remote_addr *) desc; |
@@ -1046,9 +1051,10 @@ receive_tcp_back (void *cls __attribute__ ((unused)), | |||
1046 | ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - | 1051 | ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - |
1047 | sizeof (GNUNET_HashCode); | 1052 | sizeof (GNUNET_HashCode); |
1048 | 1053 | ||
1049 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet back, addrlen = %d\n", s->addrlen); | 1054 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1055 | "Received TCP-Packet back, addrlen = %d\n", s->addrlen); | ||
1050 | 1056 | ||
1051 | if (ntohs(message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK || | 1057 | if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK || |
1052 | ts->addrlen == 16) | 1058 | ts->addrlen == 16) |
1053 | { | 1059 | { |
1054 | size_t size = pktlen + sizeof (struct ip6_tcp) - 1; | 1060 | size_t size = pktlen + sizeof (struct ip6_tcp) - 1; |
@@ -1195,7 +1201,7 @@ receive_tcp_back (void *cls __attribute__ ((unused)), | |||
1195 | tmp = pkt4->ip_hdr.dadr; | 1201 | tmp = pkt4->ip_hdr.dadr; |
1196 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); | 1202 | sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4); |
1197 | 1203 | ||
1198 | tmp = (0x06 << 16) | (0xffff & pktlen); // 0x06 for TCP? | 1204 | tmp = (0x06 << 16) | (0xffff & pktlen); // 0x06 for TCP? |
1199 | 1205 | ||
1200 | tmp = htonl (tmp); | 1206 | tmp = htonl (tmp); |
1201 | 1207 | ||
@@ -1213,22 +1219,21 @@ receive_tcp_back (void *cls __attribute__ ((unused)), | |||
1213 | return GNUNET_OK; | 1219 | return GNUNET_OK; |
1214 | } | 1220 | } |
1215 | 1221 | ||
1216 | static void* new_tunnel(void* cls, | 1222 | static void * |
1217 | struct GNUNET_MESH_Tunnel *tunnel, | 1223 | new_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel, |
1218 | const struct GNUNET_PeerIdentity *initiator, | 1224 | const struct GNUNET_PeerIdentity *initiator, |
1219 | const struct GNUNET_ATS_Information *atsi) | 1225 | const struct GNUNET_ATS_Information *atsi) |
1220 | { | 1226 | { |
1221 | /* Why should anyone open an inbound tunnel to vpn? */ | 1227 | /* Why should anyone open an inbound tunnel to vpn? */ |
1222 | GNUNET_break(0); | 1228 | GNUNET_break (0); |
1223 | return NULL; | 1229 | return NULL; |
1224 | } | 1230 | } |
1225 | 1231 | ||
1226 | static void cleaner(void *cls, | 1232 | static void |
1227 | const struct GNUNET_MESH_Tunnel *tunnel, | 1233 | cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, void *tunnel_ctx) |
1228 | void *tunnel_ctx) | ||
1229 | { | 1234 | { |
1230 | /* Why should anyone open an inbound tunnel to vpn? */ | 1235 | /* Why should anyone open an inbound tunnel to vpn? */ |
1231 | GNUNET_break(0); | 1236 | GNUNET_break (0); |
1232 | } | 1237 | } |
1233 | 1238 | ||
1234 | /** | 1239 | /** |
@@ -1255,7 +1260,9 @@ run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfilep | |||
1255 | GNUNET_APPLICATION_TYPE_END | 1260 | GNUNET_APPLICATION_TYPE_END |
1256 | }; | 1261 | }; |
1257 | 1262 | ||
1258 | mesh_handle = GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers, types); | 1263 | mesh_handle = |
1264 | GNUNET_MESH_connect (cfg_, 42, NULL, new_tunnel, cleaner, handlers, | ||
1265 | types); | ||
1259 | cfg = cfg_; | 1266 | cfg = cfg_; |
1260 | restart_hijack = 0; | 1267 | restart_hijack = 0; |
1261 | hashmap = GNUNET_CONTAINER_multihashmap_create (65536); | 1268 | hashmap = GNUNET_CONTAINER_multihashmap_create (65536); |